home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam    

exstr

exstr [options ] file

Extract 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:

  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

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

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

  3. 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")); 
    }


Previous: Reference: expr UNIX in a Nutshell: System V Edition Next: Reference: factor
Reference: expr Book Index Reference: factor

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










??????????????@Mail.ru