vsig.c 1.51 KB
/*
 * vsig.c -- Print vertical signals names as comments in tab file
 *
 */

#define MAIN

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>

#include "vsig.h"


extern FILE *yyin;
extern int EverynVecs;

#ifdef __linux__
FILE *Vecfp = 0; /* vector output file */
#else
FILE *Vecfp = stderr; /* vector output file */
#endif

#define OPTSTR          "uo:n:"


int main(int argc, char **argv)		/* Main entry */
{
   FILE *txtin = NULL;
   char *fname, *outfilename;
   int c;

   extern char *optarg;
   extern int optind, opterr;


   /*
    *  Parser Args
    */

   if(argc < 2)
   {
        printf("Usage: %s [-o outfile] [-n nvecs] infile\n", argv[0]);
        return (0);
   }

   while ((c = getopt(argc, argv, OPTSTR)) != -1) 
   {
      switch(c) {

      case 'o':
	if((Vecfp = fopen(optarg, "w")) == NULL)
	{
          perror(optarg);
          return (1);
	}
        outfilename = optarg;
	break;
      case 'n':
	EverynVecs = atoi(optarg);
	break;
      case 'u':
        printf("Usage: %s [-o outfile] [-n nvecs] infile\n", argv[0]);
        return (0);
        break;

      }
   }
#ifdef __linux__
   if (!Vecfp) Vecfp = stderr;
#endif

   if (optind < argc)
   {
      if ((txtin = fopen(argv[optind], "r")) == NULL)
      {
         perror(argv[optind]);
         return (1);
      }
   }

   yyin = txtin;

   /* create signal list and convert vectors */
   yyparse();

   /*
    * cleanup 
    */
   if (txtin) (void) fclose(txtin);
   if (Vecfp) (void) fclose(Vecfp);
   exit(0);
}

#undef MAIN