home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / c-kermit / ckldef.c < prev    next >
C/C++ Source or Header  |  2020-01-01  |  2KB  |  85 lines

  1. /* C K L D E F
  2.  *    Process command line arguments, and produce a C-language header file
  3.  *    with the arguments #defined in it.  Can be used in lieu of the "normal"
  4.  *    -DSYMBOL construct found in most C compilers.
  5.  */
  6.  
  7. #include <string.h>
  8. #include <stdio.h>
  9.  
  10. #define CV char_varying
  11.  
  12. extern void s$parse_command (CV(32) *name, short *status, ...);
  13.  
  14. static CV(32) caller = "make_defines";
  15. static CV(40) file_def = "output:pathname,required";
  16. static CV(40) read_def = "switch(-read),=1";
  17. static CV(40) symb_def = "symbols:string(*)";
  18. static CV(3)  end_def = "end";
  19.  
  20. void
  21. ckldef (void)
  22. {
  23.   short status;
  24.   CV(256) out_path_cv;
  25.   char    out_path[257];
  26.   FILE    *out_file;
  27.   char    in_name[L_tmpnam];
  28.   FILE    *in_file;
  29.   short   i;
  30.   short   read_sw;
  31.   CV(256) *cvp;
  32.   char    buff[BUFSIZ];
  33.   char    *cp;
  34.  
  35.   struct arglist
  36.   {
  37.     short num_args;
  38.     short arg_length;
  39.     short array_bound;
  40.     CV(256) args[1];
  41.   } *arglistp;
  42.  
  43.   s$parse_command (&caller, &status,
  44.                    &file_def, &out_path_cv,
  45.                    &read_def, &read_sw,
  46.                    &symb_def, &arglistp,
  47.                    &end_def);
  48.  
  49.   if (status)
  50.     return;
  51.  
  52.   strcpy (out_path, &out_path_cv);
  53.   if (read_sw)
  54.   {
  55.     tmpnam (in_name);
  56.     rename (out_path, in_name);
  57.     in_file = fopen (in_name, "r");
  58.   }
  59.   out_file = fopen (out_path, "w+");
  60.   if (out_file == NULL)
  61.   {
  62.     fprintf (stderr, "Cannot open %s for write/create\n", out_path);
  63.     return;
  64.   }
  65.  
  66.   if (in_file)
  67.   {
  68.     while (NULL != (cp = fgets (buff, sizeof buff, in_file)))
  69.     {
  70.       if (buff[0] != '#')
  71.       {
  72.         fputs (buff, out_file);
  73.       }
  74.     }
  75.     fclose (in_file);
  76.     remove (in_name);
  77.   }
  78.  
  79.   if (arglistp && arglistp->num_args)
  80.     for (i = 0; i < arglistp->num_args; i++)
  81.       fprintf (out_file, "#define %v\n", &arglistp->args[i]);
  82.  
  83.   fclose (out_file);
  84. }
  85.