SourceGenerate examples

SourceGenerate can generate simple string lists, complex codes according to string items, escape/unescape strings, and very complex code fragments by running c code directly.
Here are steps to generate code for each of the types.

1. SimpleString: generate simple string lists. The following example shows using printf to print a changed string.
You can use any number of variables. You can also use very complex code.

2. StringItem: Generate code according to template.

There are two variables(@@ $$) defined in the source template. You can name them as you like.

For each row in string items, there are two sub strings corresponding to @@ and $$.
For the first line, @@ in template code ( msgr_@@, /* Request handler for message ID $$ */ ) will be replaced with msgr_set_regparams, $$ will be replaced with 0x10B.
After corresponding replacement, the first line will generate ( msgr_set_regparams, /* Request handler for message ID 0x10B */ ), the second line will generate msgr_request_regparams, /* Request handler for message ID 0x10C */, and so on.

3. SourceEscape: Generate escape/unescape string or code. Escape code is a code segment enclosed in double quotation marks, which can be directly used in your code.

3.1 Escape String

3.2 Escape Code

3.1 Unescape String

4. RunCScript: Open and run a C file to generate code.
You can write very complex code file. Note that the code file needs to have a main function and no syntax errors.

The following is the contents of a simple main. c file.

#include <stdio.h>

char *printCmd[]={
" msgr_set_regparams, /* Request handler for message ID 0x%X */\n",
" msgr_request_regparams, /* Request handler for message ID 0x%X */\n",
" msgr_set_power, /* Request handler for message ID 0x%X */\n",
" msgr_request_power, /* Request handler for message ID 0x%X */\n",
" msgr_event_ontemp, /* Request handler for message ID 0x%X */\n",
" msgr_set_config, /* Request handler for message ID 0x%X */\n",
" msgr_set_securityconfig, /* Request handler for message ID 0x%X */\n",
" msgr_set_visibility, /* Request handler for message ID 0x%X */\n",
" msgr_set_passphrase, /* Request handler for message ID 0x%X */\n",
" msgr_request_config, /* Request handler for message ID 0x%X */\n",
};
void main(){
int i, j;
for (i = 0; i < 10; i++){
j = i + 0x010B;
printf(printCmd[i], j);
}
}