Options

Unix command (sed) for convert Dictionary to SetDefinition

edited November 2006 in Vanilla 1.0 Help
Developers of extension, this message is for you.

Hello community (it's my first message :)),
I made a command (for Unix-Like users) for convert your extension(s) from the old system (Dictionary) to the new (SetDefinition).

Original file 'default.php' (mix " with ' and multiple spaces or no space near the '=' for example)
$Context->Dictionary["Test_1"] = "Blabla 1";
$Context->Dictionary['Test_2'] = 'Blabla 2';
$Context->Dictionary["Test_3"] = 'Blabla 3';
$Context->Dictionary['Test_4'] = "Blabla 4";
$Context->Dictionary["Test_5"]="Blabla 5";
$Context->Dictionary["Test_6"]*multiple_spaces_here*=*multiple_spaces_here*"Blabla 6";
$Context->Dictionary['Test_7'] = $Variable = 'Blabla 7';
File 'default_with_SetDefinition.php' generated after to have started the command
(default.php has not been modified !)
$Context->SetDefinition('Test_1', 'Blabla 1');
$Context->SetDefinition('Test_2', 'Blabla 2');
$Context->SetDefinition('Test_3', 'Blabla 3');
$Context->SetDefinition('Test_4', 'Blabla 4');
$Context->SetDefinition('Test_5', 'Blabla 5');
$Context->SetDefinition('Test_6', 'Blabla 6');
$Context->SetDefinition('Test_7', 'Blabla 7');
--> The command
quote="\(\"\|'\)" && space="[[:blank:]]*" && sed -e s/"\$Context->Dictionary\[$quote\(.*\)$quote\]${space}=.*${quote}\(.*\)${quote}"/"\$Context->SetDefinition('\\2', '\\5')"/g default.php > default_with_SetDefinition.php

Result : good and unique presentation and SetDefinition used. :)

Sorry for my bad english, I'm French.

Comments

  • Not to sound ungrateful or anything, but supposing someone had something like this?$Context->Dictionary['DiscussionFilters'] = $DiscussionFilters = 'Discussion Filters';
  • edited November 2006
    Info : If the EXACT pattern is not found in the current line, the line will be not modified, just skipped.
  • edited November 2006
    Works now with SirNot's line. :)
  • edited November 2006
    Oupssss, sorry !!
    Missing define "space" variable in the "new version".

    N.B. : New post for up (because missing element).
This discussion has been closed.