UNIX in a Nutshell: System V Edition

UNIX in a Nutshell: System V EditionSearch this book
Previous: Reference: exprChapter 2
UNIX Commands
Next: Reference: face
 

exstr

exstr [options] file

Extract strings from C source files, so that they can be stored in a database and retrieved at application run-time using the gettxt system call. 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:

  1. Specify -e and the C source file, and redirect the output to a file. This creates a database of text strings and identifying information.

  2. Edit this database by adding information that was previously returned by the mkmsgs command.

  3. 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.)

Options

-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

fileC source file from the command-line.
line

Line number on which the string is found in file

field

In-line 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 that 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.

-d

Use with -r to give the gettxt call a second argument, the original text string. This string will be printed as the fallback in case the gettxt call fails.

Example

Assume a C source file named proverbs.c:

main() {
     printf("Haste makes waste\n"); 
     printf("A stitch in time\n"); 
}

  1. 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

  2. Run mkmsgs to create a message file (e.g., prov.US) that can be read by the gettxt call. If the two proverbs strings above are listed ninth and tenth in prov.US, then 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

  3. Finally, specify -r to insert gettxt calls:

    % exstr -rd proverbs.c < proverb.list > Prov.c

    The international 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")); 
    }


Previous: Reference: exprUNIX in a Nutshell: System V EditionNext: Reference: face
Reference: exprBook IndexReference: face

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System