#!sh # HPUX_ID: @(#)27.3 85/06/27 # @(#)findmsg.sh 27.3 85/05/21 # Findmsg(1) is an Native Language Support (NLS) tool designed to extract # string literals from C source programs which have already been # prelocalized. # # Generally a program which does not use the message catalog facility is # processed by findstr which locates string literals which may need to be # translated. See findstr(1). After the set of strings has been reduced # to those which must be translated, insertmsg(1) is used to produce a # program (with an "nl_" prepended to the name) which makes use of message # catalogs. This updated C source file will usually replace the original # source file of the program, particularly if it is intended for the # international market. See insertmsg(1). A listing of the actual # messages to be translated and put into a catalog is also produced by # insertmsg(1). This text may be maintained separately. However for # convenience, findmsg(1) will extract the text from the C source file # which has been updated to use the catalog facility. This is particular # useful if the program must be modified heavily after the findstr(1)/ # insertmsg(1) processing has occurred. # # Once the message catalog facility has been incorporated into the # program, findstr(1) and insertmsg(1) need not be used again. Findmsg(1) # allows the string literal messages to be extracted from the original C # source code rather than requiring you to separately maintain the message # catalog source file produced by insertmsg(1). In either case, the text # may be used as input to gencat(1) which prepares the text for # installation with other message catalogs. # # A line which defines the set number into which messages will be placed # must appear before any actual messages. This will be of the form: # # #define NL_SETN 1 # # Although the set number may be any integer from 1 to 255. This number # will be written to standard out along with the declaration that it is # the number of a set. # # Findmsg(1) then expects to encounter several lines containing string # literals to have nl_msg and a pair of double quotes (") in the same # line. Currently there are four identified cases which need to be # handled: # # 1) printf(nl_msg(1, "message")); # # 2) #define NLSMESS "message" /* nl_msg 1 */ # # 3) char nlsmess[] = "message" /* nl_msg 1 */ # # 4) char *nlsmess[] = { # "message", /* nl_msg 1 */ # 0 # }; # # In each of the latter three cases, there are executable lines elsewhere # which contain nl_msg in an executable form, along with the necessary # reference. # # The result of this program is written to stdout. It is the message file # in a from ready to create the message catalog. # # $set 1 # 1 message1\n # 2 message two\n # # Typically findmsg(1) is invoke as: # # findmsg stuff.c >stuff.msg # # Bugs: # 1) Findmsg will handle only one message per line. # 2) Findmsg requires that the entire message reside on a single line # along with the nl_msg key word. return=0 for i do if [ $# -ge 2 ] then echo "$ ==============" echo "$ $i" echo "$ ==============" fi awk '$1 ~ /#define/ && $2 ~ /NL_SETN/ {a = index($0, "#define"); if (a == 1) {printf "$set %s\n", $3}} /nl_msg/ && /".*"/ {a = index($0, "nl_msg"); b = index(substr($0, a, 14), ","); if (b == 0) {b = index(substr($0, a, 15), "*/")}; c = substr($0, a+7, b-7-1); d = index($0, "\""); while (substr($0, d-1, 1) == "\\") {d1 = index(substr($0, d+1, length($0)-d), "\""); if (d1 == 0 ) {printf ("findmsg: cannot locate first double quote\n"); exit(1);} d += d1}; e = index(substr($0, d+1, length($0)-d), "\""); while (substr($0, d+e-1, 1) == "\\") {e1 = index(substr($0, d+e+1, length($0)-d-e), "\""); if (e1 == 0 ) {printf ("findmsg: cannot locate second double quote\n"); exit(1);} e += e1}; f = substr($0, d+1, e-1); if (a < d+1 || a > d+e) {printf "%s %s\n", c, f}}' $i return=`expr $return + $?` done exit $return