


_O_n_l_i_n_e _M_a_n_u_a_l             User Commands                  exstr(1)



NNNNAAAAMMMMEEEE
     exstr - extract strings from source files

SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
     eeeexxxxssssttttrrrr _f_i_l_e...
     eeeexxxxssssttttrrrr ----eeee _f_i_l_e...
     eeeexxxxssssttttrrrr ----rrrr [----dddd] _f_i_l_e...

DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
     The _e_x_s_t_r utility is used to extract strings from C-language
     source files and replace them by calls to the message
     retrieval function (see _g_e_t_t_x_t(3)).  This utility will
     extract all character strings surrounded by double quotes,
     not just strings used as arguments to the _p_r_i_n_t_f command or
     the _p_r_i_n_t_f routine.  In the first form, _e_x_s_t_r finds all
     strings in the source files and writes them on the standard
     output.  Each string is preceded by the source file name and
     a colon.  The meanings of the options are:

     ----eeee      Extract a list of strings from the named C-language
             source files, with positional information.  This
             list is produced on standard output in the following
             format:

                 _f_i_l_e:_l_i_n_e:_p_o_s_i_t_i_o_n:_m_s_g_f_i_l_e:_m_s_g_n_u_m:_s_t_r_i_n_g

                 _f_i_l_e      the name of a C-language source file
                 _l_i_n_e      line number in the file
                 _p_o_s_i_t_i_o_n  character position in the line
                 _m_s_g_f_i_l_e   null
                 _m_s_g_n_u_m    null
                 _s_t_r_i_n_g    the extracted text string

             Normally you would redirect this output into a file.
             Then you would edit this file to add the values you
             want to use for _m_s_g_f_i_l_e and _m_s_g_n_u_m:

                 _m_s_g_f_i_l_e   the file that contains the text
                           strings that will replace _s_t_r_i_n_g.  A
                           file with this name must be created
                           and installed in the appropriate place
                           by the _m_k_m_s_g_s(1) utility.

                 _m_s_g_n_u_m    the sequence number of the string in
                           _m_s_g_f_i_l_e.

             The next step is to use _e_x_s_t_r -_r to replace _s_t_r_i_n_gs
             in _f_i_l_e.

     ----rrrr      Replace strings in a C-language source file with
             function calls to the message retrieval function
             _g_e_t_t_x_t().

     ----dddd      This option is used together with the ----rrrr option.  If
             the message retrieval fails when _g_e_t_t_x_t() is invoked
             at run-time, then the extracted string is printed.

     You would use the capability provided by _e_x_s_t_r on an appli-
     cation program that needs to run in an international






     environment and have messages print in more than one
     language.  _e_x_s_t_r replaces text strings with function calls
     that point at strings in a message data base.  The data base
     used depends on the run-time value of the LC_MESSAGES
     environment variable.

     The first step is to use _e_x_s_t_r -_e to extract a list of
     strings and save it in a file.  Next, examine this list and
     determine which strings can be translated and subsequently
     retrieved by the message retrieval function.  Then, modify
     this file by deleting lines that can't be translated and,
     for lines that can be translated, by adding the message file
     names and the message numbers as the fourth (_m_s_g_f_i_l_e) and
     fifth (_m_s_g_n_u_m) entries on a line.  The message files named
     must have been created by _m_k_m_s_g_s(1) and exist in
     ////uuuussssrrrr////lllliiiibbbb////llllooooccccaaaalllleeee////_l_o_c_a_l_e////LLLLCCCC____MMMMEEEESSSSSSSSAAAAGGGGEEEESSSS.  (The directory _l_o_c_a_l_e
     corresponds to the language in which the text strings are
     written; see _s_e_t_l_o_c_a_l_e(3)).  The message numbers used must
     correspond to the sequence numbers of strings in the message
     files.

     Now use this modified file as input to _e_x_s_t_r -_r to produce a
     new version of the original C-language source file in which
     the strings have been replaced by calls to the message
     retrieval function _g_e_t_t_x_t().  The _m_s_g_f_i_l_e and _m_s_g_n_u_m fields
     are used to construct the first argument to _g_e_t_t_x_t().  The
     second argument to _g_e_t_t_x_t() is printed if the message
     retrieval fails at run-time.  This argument is the null
     string, unless the ----dddd option is used.

     This utility cannot replace strings in all instances. For
     example, a static initialized character string cannot be
     replaced by a function call.  A second example is that a
     string could be in a form of an escape sequence which could
     not be translated.  In order not to break existing code, the
     files created by invoking _e_x_s_t_r -_e must be examined and
     lines containing strings not replaceable by function calls
     must be deleted. In some cases the code may require modifi-
     cations so that strings can be extracted and replaced by
     calls to the message retrieval function.

EEEEXXXXAAAAMMMMPPPPLLLLEEEESSSS
     The following examples show uses of _e_x_s_t_r.

     Assume that the file ffffoooooooo....cccc contains two strings:

          main()
          {
               printf("This is an example\n");
               printf("Hello world!\n");
          }

     The _e_x_s_t_r utility, invoked with the argument ffffoooooooo....cccc extracts
     strings from the named file and prints them on the standard
     output.

     eeeexxxxssssttttrrrr ffffoooooooo....cccc produces the following output:

          foo.c:This is an example\n
          foo.c:Hello world!\n






     eeeexxxxssssttttrrrr ----eeee ffffoooooooo....cccc >>>> ffffoooooooo....ssssttttrrrriiiinnnnggggssssoooouuuutttt produces the following out-
     put in the file ffffoooooooo....ssssttttrrrriiiinnnnggggssssoooouuuutttt:

          foo.c:3:8:::This is an example\n
          foo.c:4:8:::Hello world!\n

     You must edit ffffoooooooo....ssssttttrrrriiiinnnnggggssssoooouuuutttt to add the values you want to
     use for the _m_s_g_f_i_l_e and _m_s_g_n_u_m fields before these strings
     can be replaced by calls to the retrieval function.  If UUUUXXXX
     is the name of the message file, and the numbers 1111 and 2222
     represent the sequence number of the strings in the file,
     here is what ffffoooooooo....ssssttttrrrriiiinnnnggggssssoooouuuutttt looks like after you add this
     information:

          foo.c:3:8:UX:1:This is an example\n
          foo.c:4:8:UX:2:Hello world!\n

     The _e_x_s_t_r utility can now be invoked with the ----rrrr option to
     replace the strings in the source file by calls to the mes-
     sage retrieval function _g_e_t_t_x_t().

     eeeexxxxssssttttrrrr ----rrrr ffffoooooooo....cccc <<<<ffffoooooooo....ssssttttrrrriiiinnnnggggssssoooouuuutttt >>>>iiiinnnnttttllllffffoooooooo....cccc produces the fol-
     lowing output:

          extern char *gettxt();
          main()
          {
               printf(gettxt("UX:1", ""));
               printf(gettxt("UX:2", ""));
          }

     eeeexxxxssssttttrrrr ----rrrrdddd ffffoooooooo....cccc <<<<ffffoooooooo....ssssttttrrrriiiinnnnggggssssoooouuuutttt >>>>iiiinnnnttttllllffffoooooooo....cccc uses the
     extracted strings as a second argument to _g_e_t_t_x_t().

          extern char *gettxt();
          main()
          {
               printf(gettxt("UX:1", "This is an example\n"));
               printf(gettxt("UX:2", "Hello world!\n"));
          }

FFFFIIIILLLLEEEESSSS
     /usr/lib/locale/_l_o_c_a_l_e/LC_MESSAGES/*
          files created by _m_k_m_s_g_s(1)

SSSSEEEEEEEE AAAALLLLSSSSOOOO
     User Commands (1): gettxt, mkmsgs, printf, srchtxt
     Library Functions (3): gettxt, printf, setlocale

DDDDIIIIAAAAGGGGNNNNOOOOSSSSTTTTIIIICCCCSSSS
     The error messages produced by _e_x_s_t_r are intended to be
     self-explanatory.  They indicate errors in the command line
     or format errors encountered within the input file.

December 1990                                 TX User's Reference





