exstr
[options] fileExtract strings from C source files, so that they can be stored in a database and retrieved at application runtime using the gettxt
library function. With no options, exstr produces a grep-type list showing only filename and strings. exstr is one of several commands to use when customizing applications for international use.
Typical use involves three steps:
Specify -e
and the C source file, and redirect the output to a file. This creates a database of text strings and identifying information.
Edit this database by adding information that was previously returned by the mkmsgs command.
Specify -r
and the C source file, using the edited database as input. This replaces hardcoded text strings with calls to gettxt
. gettxt
lets you access translated versions of text strings. (The strings reside in a directory specified by environment variable LC_MESSAGES.)
-d
Use with -r
to give the gettxt
call a second argument, the original text string. This string is printed as the fallback in case the gettxt
call fails.
-e
Extract text strings from file. (-e
is not used with other options.) The information appears in this format:
file:line:field:msg_file:msg_num:string
file | C source file from the command line. |
line | Line number on which the string is found in file. |
field | Inline numerical position of the string's beginning. |
msg_file | Initially null, but later filled in when you edit the database. msg_file is the name of the list of message strings you create by running the mkmsgs command. |
msg_num | Initially null but filled in later. It corresponds to the order of the strings in msg_file. |
-r
Replace strings in the source file with calls to gettxt
.
Assume a C source file named proverbs.c:
main() { printf("Haste makes waste\n"); printf("A stitch in time\n"); }
First issue the command:
exstr -e proverbs.c > proverb.list
proverb.list might look something like this:
proverbs.c:3:8:::Haste makes waste\n proverbs.c:4:8:::A stitch in time\n
Run mkmsgs to create a message file (e.g., prov.US) that can be read by the gettxt
call. If the two previous proverb strings are listed ninth and tenth in prov.US, you would edit proverb.list as follows:
proverbs.c:3:8:prov.US:9:Haste makes waste\n proverbs.c:4:8:prov.US:10:A stitch in time\n
Finally, specify -r
to insert gettxt
calls:
exstr -rd proverbs.c < proverb.list > Prov.c
The internationalized version of your program, Prov.c, now looks like this:
extern char *gettxt(); main() { printf(gettxt("prov.US:9", "Haste makes waste\n")); printf(gettxt("prov.US:10", "A stitch in time\n")); }