Changeset affa29 in git


Ignore:
Timestamp:
Mar 30, 2000, 8:31:29 AM (24 years ago)
Author:
Kai Krüger <krueger@…>
Branches:
(u'fieker-DuVal', '117eb8c30fc9e991c4decca4832b1d19036c4c65')(u'spielwiese', '648d28f488f6ff08f5607ff229b9ad9e4a5b93c2')
Children:
014db190caff72bde1fe859653957b0785e638a0
Parents:
b583ae9d01fefeb8ac48ed37894cdabf6e905260
Message:
Added command-line-options


git-svn-id: file:///usr/local/Singular/svn/trunk@4234 2c84dea3-7e68-4137-9b89-c4e89433aadc
File:
1 edited

Legend:

Unmodified
Added
Removed
  • modules/modgen/main.cc

    rb583ae raffa29  
    99#include <string.h>
    1010#include <limits.h>
     11#include <unistd.h>
     12#include <getopt.h>
    1113
    1214#include "modgen.h"
    1315#include "stype.h"
    1416
    15 int trace=1;
    1617/*
    1718 *    Syntax of a module file:
     
    6566extern int yyparse (void);
    6667extern void init_type_conv();
     68int debug = 0;
     69int trace = 0;
     70int do_create_makefile = 1;
     71
     72static struct option long_options[] =
     73{
     74  {"debug", 0, 0, 'd'},
     75  {"verbose", 0, 0, 'v'},
     76  {"nocreate-makefile", 0, 0, 'm'},
     77  {"help", 0, 0, '?'},
     78  {0, 0, 0, 0}
     79};
     80
     81void usage(char *name)
     82{
     83  int i;
     84  printf("usage: %s [args] filename\n", name);
     85  for(i=0; long_options[i].name != NULL; i++)
     86    printf("\t-%c (--%s) %s\n", long_options[i].val,
     87           long_options[i].name, "");
     88 
     89}
    6790
    6891main( int argc, char *argv[] )
    6992{
    7093  int i;
    71  
    72   if ( argc > 1 )
    73      yyin = fopen( argv[1], "rb" );
     94  int c;
     95  int option_index = 0;
     96
     97  while( (c=getopt_long (argc, argv, "dmv",
     98                         long_options, &option_index))>=0) {
     99    switch (c)
     100    {
     101        case 'd' : debug++; break;
     102        case 'v' : trace=1; break;
     103        case 'm' : do_create_makefile = 0; break;
     104         
     105        case '?' : usage(argv[0]);
     106          return 0;
     107          break;
     108         
     109        default:
     110          printf ("?? getopt returned character code 0%o ??\n", c);
     111    }
     112  }
     113
     114  if (optind < argc) yyin = fopen( argv[optind], "rb" );
    74115  else {
    75116    printf("no filename given\n");
    76     printf("usage: %s <filename>.mod\n", argv[0]);
     117    usage(argv[0]);
    77118    return 1;
    78119  }
    79120 
    80   if(init_modgen(&module_def, argv[1])) return 1;
     121  if(init_modgen(&module_def, argv[optind])) return 1;
    81122  init_type_conv();
    82123  do {
    83124      i=yyparse();
    84       if(i)printf("NEXT LOOP at line %d (%s) %d\n", yylineno, yytext, i);
    85       else printf("FINISH? (%d)\n", i);
     125      if(!i) printf("FINISH? (%d)\n", i);
     126      else
     127        if(debug)printf("NEXT LOOP at line %d (%s) %d\n", yylineno, yytext, i);
    86128  }
    87129  while (!i);
    88   printf("ENDE\n");
     130  if(trace)printf("files for module '%s' created.\n", argv[optind]);
    89131 
    90132  //fflush(module_def.fmtfp);
Note: See TracChangeset for help on using the changeset viewer.