Generating a Table of Character Strings

 Wedit allows you to automatically generate string tables, either in the .rc format, or in a plain table format. All of your current C source files will be scanned for character strings.

 The basic idea is to replace all occurrences of

      ShowError("File not found");

by

      ShowError(GetRcString(354));

or

      ShowError(StringTable[354]);

 This

  1. Simplifies the translation of your software into another language
  2. Separates programming from the writing of error messages
  3. Reduces the total size of the program in memory because the character strings use memory only when they are used and total memory size of your executable diminishes.

 

 

You can reach this dialog box by choosing the ‘Strings’ item in the ‘Utils’ menu bar.

 

This dialog box allows you to view and control the generation process.

'Renum' option

This option allows you to renumber the integers used for identifying each string. If you want to include the strings in another table, this option is essential.

The following dialog box is displayed:

Here you can change either the starting number or the increment to be added to each string. If you want to have one numeric identifier for a string altering the sequence, go to the 'Edit' option below.

'Edit' option

This option is active only when a character string is selected. It will change the configuration for a particular character string. You can change the number or the symbolic name you will use for the string that is selected.

Exclude:

If you do not want to include a character string and leave it this way in the source, select the string and press the exclude button.

You have two options for generating the string table. The first is to generate it in the STRINGTABLE rc format; the second is to generate it in a normal character string table.

The generation of a string table in the .rc format leads to the following dialog box:

 

You reach this dialog box when you click the ‘rc’ button in the ‘Strings’ dialog box. You reach the ‘Strings’ dialog box by selecting the ‘Strings’ menu item in the ‘Utils’ menu bar.

You should enter:

           The name of the output file

           The name of the function that will return a character string at runtime

           If you want to have the symbolic names (#defines) or the numbers in your source file

The resulting file looks like this:

STRINGTABLE

BEGIN

     STR_0000,"Aucun"

     STR_0001,"Champ <libellé> est obligatoire"

     STR_0002,"Champ <nom> est obligatoire"

     STR_0003,"*"

          ...

     STR_0034,"   "

     STR_0035,"%7d "

     STR_0036,"   --   "

END

In the source file, instead of (for example):

sprintf(msg,"%s exists already",tamponalloc);

We have

sprintf(msg,GetStringFromRc(STR_0008),tamponalloc);

                             /* %s exists already */

The generation of a table is functionally equivalent.

You enter:

1.    The name of the output file. If this file exists already and it is a table string file that was previously generated by Wedit, the new definitions will be appended to the end of the file. Automatic renumeration will occur to avoid destroying the definitions of previously existing strings.

2.    The ‘Name of the table’ entry field is the variable name that will be used in your program text to access this table. You should use names that avoid conflicts with any other identifier in your program.

Alternatively, you can name a function that will return the character string given an index. This option is active if you choose the ‘Function’ radio button at the left. If not a straight index will be used.