©2004 by Marc J. Rochkind. All rights reserved. Portions marked "Open Source" may be copied under license.

 

Main Page   Modules   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

common/mkmacrostr.c

Go to the documentation of this file.
00001 /*
00002     Convert macro values to strings - compiler
00003     AUP2, Sec. 5.08 (not in book)
00004 
00005     Copyright 2003 by Marc J. Rochkind. All rights reserved.
00006     May be copied only for purposes and under conditions described
00007     on the Web page www.basepath.com/aup/copyright.htm.
00008 
00009     The Example Files are provided "as is," without any warranty;
00010     without even the implied warranty of merchantability or fitness
00011     for a particular purpose. The author and his publisher are not
00012     responsible for any damages, direct or incidental, resulting
00013     from the use or non-use of these Example Files.
00014 
00015     The Example Files may contain defects, and some contain deliberate
00016     coding mistakes that were included for educational reasons.
00017     You are responsible for determining if and how the Example Files
00018     are to be used.
00019 
00020 */
00021 #include "defs.h"
00022 
00023 int main(int argc, char *argv[])
00024 {
00025     FILE *in, *out;
00026     char *file, s[100], cat[100], *macro, *desc;
00027     int len;
00028 
00029     if (argc < 2)
00030         file = "/aup/common/macrostr.txt";
00031     else
00032         file = argv[1];
00033     ec_null( in = fopen(file, "r") )
00034     ec_null( out = fopen("/aup/common/macrostr.incl", "w") )
00035     while (fgets(s, sizeof(s), in) != NULL) {
00036         for (len = strlen(s); len > 0 && isspace((int)s[len - 1]); len--)
00037             ;
00038         s[len] = '\0';
00039         if (s[0] == '#') {
00040             fprintf(out, "%s\n", s);
00041             continue;
00042         }
00043         if (s[len - 1] == ':') {
00044             strcpy(cat, s);
00045             cat[len - 1] = '\0';
00046         }
00047         else {
00048             macro = strtok(s, " \t");
00049             if (macro == NULL)
00050                 continue;
00051             desc = strtok(NULL, "\t");
00052             if (desc == NULL)
00053                 desc = "";
00054             else
00055                 while (isspace((int)*desc))
00056                     desc++;
00057             fprintf(out, "{\"%s\", (intptr_t)%s, \"%s\", \"%s\"},\n",
00058               cat, macro, macro, desc);
00059         }
00060     }
00061     exit(EXIT_SUCCESS);
00062 
00063 EC_CLEANUP_BGN
00064     exit(EXIT_FAILURE);
00065 EC_CLEANUP_END
00066 }

Generated on Fri Apr 23 10:57:03 2004 for AUP2 Example Source by doxygen 1.3.1