mkstr -- creates an error message file from C source


mkstr [-] messagefile prefix file...


mkstr is used to create files of error messages. Its use can make programs with large numbers of error diagnostics much smaller, and reduce system overhead in running the program as the error messages do not have to be constantly swapped in and out.

mkstr will process each specified file, placing a massaged version of the input file in a file whose name consists of the specified prefix and the original name. The optional dash (``-'') causes the error messages to be placed at the end of the specified message file for recompiling part of a large mkstred program.

A typical mkstr command line is:

mkstr pistrings xx *.c

This command causes all the error messages from the C source files in the current directory to be placed in the file pistrings and processed copies of the source for these files to be placed in files whose names are prefixed with xx.

To process the error messages in the source to the message file, mkstr keys on the string `error("' in the input stream. Each time it occurs, the C string starting at the `"' is placed in the message file followed by a null character and a newline character; the null character terminates the message so it can be easily used when retrieved, the newline character makes it possible to sensibly cat the error message file to see its contents. The massaged copy of the input file then contains a lseek pointer into the file which can be used to retrieve the message. For example, the command changes

error(``Error on reading'', a2, a3, a4);


error(m, a2, a3, a4);

where m is the seek position of the string in the resulting error message file. The programmer must create a routine error which opens the message file, reads the string, and prints it out.

The following example illustrates such a routine.

   char    efilname[] =  "/usr/lib/pi_strings";
   int     efil = -1;

error(a1, a2, a3, a4) int a1, a2, a3, a4; { char buf[256];

if (efil < 0) { efil = open(efilname, 0); if (efil < 0) { perror(efilname); exit(1); } } if (lseek(efil, (long) a1, 0) || read(efil, buf, 256) <= 0) { printf("Unable to find error msg "); printf("at seek address %d\n",a1); exit(1); } printf(buf, a2, a3, a4); }


All the arguments except the name of the file to be processed are optional.

See also

lseek(S), xstr(CP)

Standards conformance

This utility was developed at the University of California at Berkeley and is used with permission.
© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003