langtool.c

Go to the documentation of this file.
00001 /* Language stuff generator for win32.
00002  *
00003  * (C) 2003-2007 Anope Team
00004  * Contact us at info@anope.org
00005  *
00006  * Please read COPYING and README for furhter details.
00007  *
00008  * Based on the original code of Epona by Lara.
00009  * Based on the original code of Services by Andy Church. 
00010  * 
00011  * Written by Dominick Meglio <codemastr@unrealircd.com>
00012  *
00013  */
00014 
00015 #include <string.h>
00016 #include <stdio.h>
00017 
00018 char *strip(char *str)
00019 {
00020     char *c;
00021     if ((c = strchr(str,'\n')))
00022         *c = 0;
00023     if ((c = strchr(str,'\r')))
00024         *c = 0;
00025     return str;
00026 }
00027 
00028 int main(int argc, char *argv[])
00029 {
00030     if (argc < 2)
00031         exit(1);
00032 
00033     /* Build the index file */
00034     if (!strcmp(argv[1], "index"))
00035     {
00036         FILE *fd = fopen("en_us.l", "rb");
00037         FILE *fdout = fopen("index", "wb");
00038         char buf[1024];
00039         if (!fd || !fdout)
00040             exit(2);
00041 
00042         while (fgets(buf, 1023, fd))
00043         {
00044             if (isupper(*buf))
00045                 fprintf(fdout, "%s", buf);
00046         }
00047         fclose(fd);
00048         fclose(fdout);
00049     }
00050     /* Build the language.h file */
00051     else if (!strcmp(argv[1], "language.h"))
00052     {
00053         FILE *fd = fopen("index", "r");
00054         FILE *fdout = fopen("language.h", "w");
00055         char buf[1024];
00056         int i = 0;      
00057 
00058         if (!fd || !fdout)
00059             exit(2);
00060 
00061         fprintf(stderr, "Generating language.h... ");
00062 
00063         while (fgets(buf, 1023, fd)) {
00064             fprintf(fdout, "#define %-32s %d\n", strip(buf), i++);
00065         }
00066 
00067         fprintf(fdout, "#define NUM_STRINGS %d\n", i);
00068         fprintf(stderr, "%d strings\n", i);
00069         fclose(fd);
00070         fclose(fdout);
00071     }
00072     return 0;
00073             
00074 }

Generated on Sun Dec 30 09:26:45 2007 for Anope by  doxygen 1.5.1-20070107