home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / fontutils-0.6 / bpltobzr / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-07-27  |  4.2 KB  |  141 lines

  1. /* bpltobzr -- convert from the textual ``Bezier property list'' format
  2.    to the binary BZR format.
  3.  
  4. Copyright (C) 1992 Free Software Foundation, Inc.
  5.  
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #include "config.h"
  21.  
  22. #include "bzr.h"
  23. #define CMDLINE_NO_DPI /* Outline fonts are resolution-independent.  */
  24. #include "cmdline.h"
  25. #include "getopt.h"
  26. #include "report.h"
  27.  
  28. #include "main.h"
  29.  
  30. /* The input stream.  */
  31. FILE *bpl_file;
  32.  
  33. /* The name of the output file specified by the user.  (-output-file)  */
  34. static string output_name = NULL;
  35.  
  36. /* Says which characters we should process.  This is independent of the
  37.    ordering in the font file.  (-range)  */
  38. static int starting_char = 0;
  39. static int ending_char = MAX_CHARCODE;
  40.  
  41. /* This is defined in version.c.  */
  42. extern string version_string;
  43.  
  44. static string read_command_line (int, string []);
  45.  
  46. /* It would be nice if we could actually use Lisp to do this job.  The
  47.    problem is not parsing the input -- we get that essentially for free,
  48.    since property list syntax is Lisp syntax -- but in writing the
  49.    output.  I just couldn't see doing all the funky floating-point and
  50.    file manipulations from Elisp, when I already had them written in C.  */
  51.  
  52. int
  53. main (int argc, string argv[])
  54. {
  55.   extern int yyparse ();
  56.   int err;
  57.   string bpl_name = read_command_line (argc, argv);
  58.   
  59.   /* Add the default extensions and open the files.  */
  60.   bpl_name = extend_filename (bpl_name, "bpl");
  61.   bpl_file = xfopen (bpl_name, "r");
  62.   
  63.   if (output_name == NULL)
  64.     output_name = remove_suffix (basename (bpl_name));
  65.   output_name = extend_filename (output_name, "bzr");
  66.   if (!bzr_open_output_file (output_name))
  67.     FATAL_PERROR (output_name);
  68.   
  69.   /* Parse and convert the BPL file.  */
  70.   err = yyparse ();
  71.   
  72.   bzr_close_output_file ();
  73.   
  74.   exit (err);
  75. }
  76.  
  77. /* Reading the options.  */
  78.  
  79. /* This is defined in version.c.  */
  80. extern string version_string;
  81.  
  82. #define USAGE "Options:
  83. <font_name> should be a filename, e.g., `cmr10'.  Any extension is ignored." \
  84.   GETOPT_USAGE                                     \
  85. "help: print this message.
  86. output-file <filename>: output to <filename> (if it has a suffix) or to
  87.   <filename>.bzr (if it doesn't).
  88. range <char1>-<char2>: only work on characters between <char1> and
  89.   <char2> inclusive.
  90. verbose: print brief progress reports on stderr.
  91. version: print the version number of this program.
  92. "
  93.  
  94.  
  95. /* We return the name of the font to process.  */
  96.  
  97. static string
  98. read_command_line (int argc, string argv[])
  99. {
  100.   int g;   /* `getopt' return code.  */
  101.   int option_index;
  102.   boolean printed_version = false;
  103.   struct option long_options []
  104.     = { { "help",               0, 0, 0 },
  105.         { "output-file",    1, 0, 0 },
  106.         { "range",        1, 0, 0 },
  107.         { "verbose",            0, (int *) &verbose, 1 },
  108.         { "version",            0, (int *) &printed_version, 1 },
  109.         { 0, 0, 0, 0 } };
  110.  
  111.   while (true)
  112.     {
  113.       g = getopt_long_only (argc, argv, "", long_options, &option_index);
  114.  
  115.       if (g == EOF) break;
  116.       if (g == '?') exit (1);  /* Unknown option.  */
  117.   
  118.       assert (g == 0); /* We have no short option names.  */
  119.       
  120.       if (ARGUMENT_IS ("help"))
  121.         {
  122.           fprintf (stderr, "Usage: %s [options] <font_name>.\n", argv[0]);
  123.           fprintf (stderr, USAGE);
  124.           exit (0);
  125.         }
  126.         
  127.       else if (ARGUMENT_IS ("output-file"))
  128.         output_name = optarg;
  129.  
  130.       else if (ARGUMENT_IS ("range"))
  131.         GET_RANGE (optarg, starting_char, ending_char);
  132.         
  133.       else if (ARGUMENT_IS ("version"))
  134.         printf ("%s.\n", version_string);
  135.       
  136.       /* Else it was just a flag; getopt has already done the assignment.  */
  137.     }
  138.   
  139.   FINISH_COMMAND_LINE ();
  140. }
  141.