home *** CD-ROM | disk | FTP | other *** search
/ Serving the Web / ServingTheWeb1995.disc1of1.iso / linux / slacksrce / d / libc / libc-4.6 / libc-4 / libc-linux / locale / numeric / mknumeric.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-18  |  1.4 KB  |  85 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5. #include <getopt.h>
  6. #include <locale.h>
  7. #include <localeinfo.h>
  8.  
  9. #include "mknumeric.h"
  10.  
  11. extern int yyparse (void);
  12.  
  13. unsigned char *codename;
  14.  
  15. struct numeric_info ninfo =
  16. {
  17.   "",                /* char *decimal_point */
  18.   "",                /* char *thousands_sep */
  19.   ""                /* char *grouping */
  20. };
  21.  
  22. int
  23. main (int argc, char *argv[])
  24. {
  25.   int i;
  26.   unsigned char *outname = "LC_NUMERIC";
  27.  
  28.   while ((i = getopt (argc, argv, "o:")) != EOF)
  29.     {
  30.       switch (i)
  31.     {
  32.     case 'o':
  33.       outname = optarg;
  34.       break;
  35.     }
  36.     }
  37.  
  38.   if (argc - optind > 1)
  39.     {
  40.       (void) fprintf (stderr, "Usage: %s [-o out_file_name] [file]\n", argv[0]);
  41.       return 3;
  42.     }
  43.   else if ((argc - optind) == 1)
  44.     {
  45.       if (freopen (argv[optind], "r", stdin) == NULL)
  46.     {
  47.       perror (argv[optind]);
  48.       return 2;
  49.     }
  50.     }
  51.  
  52.   if (yyparse ())
  53.     return 1;
  54.  
  55.   return !write_out (outname);
  56. }
  57.  
  58. void
  59. write_str (char *str, FILE * ofp)
  60. {
  61.   short int slen = strlen (str) + 1;
  62.  
  63.   (void) fwrite (&slen, sizeof (slen), 1, ofp);
  64.   (void) fwrite (str, sizeof (char), slen, ofp);
  65. }
  66.  
  67. int
  68. write_out (outname)
  69.      unsigned char *outname;
  70. {
  71.   FILE *ofp = fopen (outname, "w");
  72.  
  73.   if (ofp == NULL)
  74.     return 0;
  75.  
  76.   write_str (ninfo.decimal_point, ofp);
  77.   write_str (ninfo.thousands_sep, ofp);
  78.   write_str (ninfo.grouping, ofp);
  79. #ifndef NOGUARD
  80.   (void) fwrite (codename, sizeof (unsigned char), strlen (codename) + 1, ofp);
  81. #endif
  82.   (void) fclose (ofp);
  83.   return 1;
  84. }
  85.