Changeset 2bf04b in git for old_modgen


Ignore:
Timestamp:
Nov 12, 2015, 2:39:46 PM (8 years ago)
Author:
Hans Schoenemann <hannes@…>
Branches:
(u'spielwiese', '5b153614cbc72bfa198d75b1e9e33dab2645d9fe')
Children:
6da2d6765f8866f8426131bf3a097a5c051e956e
Parents:
412c61b77c65fd4adca8f6576d7f1a597459552e
Message:
format
Location:
old_modgen/modgen
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • old_modgen/modgen/getopt.c

    r412c61 r2bf04b  
    44   before changing it!
    55   Copyright (C) 1987,88,89,90,91,92,93,94,95,96,98,99,2000,2001
    6         Free Software Foundation, Inc.
     6           Free Software Foundation, Inc.
    77   This file is part of the GNU C Library.
    88
     
    6666/* This needs to come after some library #include
    6767   to get __GNU_LIBRARY__ defined.  */
    68 #ifdef  __GNU_LIBRARY__
     68#ifdef        __GNU_LIBRARY__
    6969/* Don't include stdlib.h for non-GNU C libraries because some of them
    7070   contain conflicting prototypes for getopt.  */
    7171# include <stdlib.h>
    7272# include <unistd.h>
    73 #endif  /* GNU C library.  */
     73#endif        /* GNU C library.  */
    7474
    7575#ifdef VMS
     
    8585#  include <libintl.h>
    8686#  ifndef _
    87 #   define _(msgid)     gettext (msgid)
     87#   define _(msgid)        gettext (msgid)
    8888#  endif
    8989# else
    90 #  define _(msgid)      (msgid)
     90#  define _(msgid)        (msgid)
    9191# endif
    9292#endif
     
    195195
    196196
    197 #ifdef  __GNU_LIBRARY__
     197#ifdef        __GNU_LIBRARY__
    198198/* We want to avoid inclusion of string.h with non-GNU libraries
    199199   because there are many ways it can cause trouble.
     
    201201   in GCC.  */
    202202# include <string.h>
    203 # define my_index       strchr
     203# define my_index        strchr
    204204#else
    205205
     
    225225    {
    226226      if (*str == chr)
    227         return (char *) str;
     227        return (char *) str;
    228228      str++;
    229229    }
     
    275275# ifdef USE_NONOPTION_FLAGS
    276276#  define SWAP_FLAGS(ch1, ch2) \
    277   if (nonoption_flags_len > 0)                                                \
    278     {                                                                         \
    279       char __tmp = __getopt_nonoption_flags[ch1];                             \
    280       __getopt_nonoption_flags[ch1] = __getopt_nonoption_flags[ch2];          \
    281       __getopt_nonoption_flags[ch2] = __tmp;                                  \
     277  if (nonoption_flags_len > 0)                                                      \
     278    {                                                                              \
     279      char __tmp = __getopt_nonoption_flags[ch1];                              \
     280      __getopt_nonoption_flags[ch1] = __getopt_nonoption_flags[ch2];              \
     281      __getopt_nonoption_flags[ch2] = __tmp;                                      \
    282282    }
    283283# else
    284284#  define SWAP_FLAGS(ch1, ch2)
    285285# endif
    286 #else   /* !_LIBC */
     286#else        /* !_LIBC */
    287287# define SWAP_FLAGS(ch1, ch2)
    288 #endif  /* _LIBC */
     288#endif        /* _LIBC */
    289289
    290290/* Exchange two adjacent subsequences of ARGV.
     
    322322    {
    323323      /* We must extend the array.  The user plays games with us and
    324         presents new arguments.  */
     324        presents new arguments.  */
    325325      char *new_str = malloc (top + 1);
    326326      if (new_str == NULL)
    327         nonoption_flags_len = nonoption_flags_max_len = 0;
     327        nonoption_flags_len = nonoption_flags_max_len = 0;
    328328      else
    329         {
    330           memset (__mempcpy (new_str, __getopt_nonoption_flags,
    331                              nonoption_flags_max_len),
    332                   '\0', top + 1 - nonoption_flags_max_len);
    333           nonoption_flags_max_len = top + 1;
    334           __getopt_nonoption_flags = new_str;
    335         }
     329        {
     330          memset (__mempcpy (new_str, __getopt_nonoption_flags,
     331                             nonoption_flags_max_len),
     332                  '\0', top + 1 - nonoption_flags_max_len);
     333          nonoption_flags_max_len = top + 1;
     334          __getopt_nonoption_flags = new_str;
     335        }
    336336    }
    337337#endif
     
    340340    {
    341341      if (top - middle > middle - bottom)
    342         {
    343           /* Bottom segment is the short one.  */
    344           int len = middle - bottom;
    345           register int i;
    346 
    347           /* Swap it with the top part of the top segment.  */
    348           for (i = 0; i < len; i++)
    349             {
    350               tem = argv[bottom + i];
    351               argv[bottom + i] = argv[top - (middle - bottom) + i];
    352               argv[top - (middle - bottom) + i] = tem;
    353               SWAP_FLAGS (bottom + i, top - (middle - bottom) + i);
    354             }
    355           /* Exclude the moved bottom segment from further swapping.  */
    356           top -= len;
    357         }
     342        {
     343          /* Bottom segment is the short one.  */
     344          int len = middle - bottom;
     345          register int i;
     346
     347          /* Swap it with the top part of the top segment.  */
     348          for (i = 0; i < len; i++)
     349            {
     350              tem = argv[bottom + i];
     351              argv[bottom + i] = argv[top - (middle - bottom) + i];
     352              argv[top - (middle - bottom) + i] = tem;
     353              SWAP_FLAGS (bottom + i, top - (middle - bottom) + i);
     354            }
     355          /* Exclude the moved bottom segment from further swapping.  */
     356          top -= len;
     357        }
    358358      else
    359         {
    360           /* Top segment is the short one.  */
    361           int len = top - middle;
    362           register int i;
    363 
    364           /* Swap it with the bottom part of the bottom segment.  */
    365           for (i = 0; i < len; i++)
    366             {
    367               tem = argv[bottom + i];
    368               argv[bottom + i] = argv[middle + i];
    369               argv[middle + i] = tem;
    370               SWAP_FLAGS (bottom + i, middle + i);
    371             }
    372           /* Exclude the moved top segment from further swapping.  */
    373           bottom += len;
    374         }
     359        {
     360          /* Top segment is the short one.  */
     361          int len = top - middle;
     362          register int i;
     363
     364          /* Swap it with the bottom part of the bottom segment.  */
     365          for (i = 0; i < len; i++)
     366            {
     367              tem = argv[bottom + i];
     368              argv[bottom + i] = argv[middle + i];
     369              argv[middle + i] = tem;
     370              SWAP_FLAGS (bottom + i, middle + i);
     371            }
     372          /* Exclude the moved top segment from further swapping.  */
     373          bottom += len;
     374        }
    375375    }
    376376
     
    424424    {
    425425      if (nonoption_flags_max_len == 0)
    426         {
    427           if (__getopt_nonoption_flags == NULL
    428               || __getopt_nonoption_flags[0] == '\0')
    429             nonoption_flags_max_len = -1;
    430           else
    431             {
    432               const char *orig_str = __getopt_nonoption_flags;
    433               int len = nonoption_flags_max_len = strlen (orig_str);
    434               if (nonoption_flags_max_len < argc)
    435                 nonoption_flags_max_len = argc;
    436               __getopt_nonoption_flags =
    437                 (char *) malloc (nonoption_flags_max_len);
    438               if (__getopt_nonoption_flags == NULL)
    439                 nonoption_flags_max_len = -1;
    440               else
    441                 memset (__mempcpy (__getopt_nonoption_flags, orig_str, len),
    442                         '\0', nonoption_flags_max_len - len);
    443             }
    444         }
     426        {
     427          if (__getopt_nonoption_flags == NULL
     428              || __getopt_nonoption_flags[0] == '\0')
     429            nonoption_flags_max_len = -1;
     430          else
     431            {
     432              const char *orig_str = __getopt_nonoption_flags;
     433              int len = nonoption_flags_max_len = strlen (orig_str);
     434              if (nonoption_flags_max_len < argc)
     435                nonoption_flags_max_len = argc;
     436              __getopt_nonoption_flags =
     437                (char *) malloc (nonoption_flags_max_len);
     438              if (__getopt_nonoption_flags == NULL)
     439                nonoption_flags_max_len = -1;
     440              else
     441                memset (__mempcpy (__getopt_nonoption_flags, orig_str, len),
     442                        '\0', nonoption_flags_max_len - len);
     443            }
     444        }
    445445      nonoption_flags_len = nonoption_flags_max_len;
    446446    }
     
    530530    {
    531531      if (optind == 0)
    532         optind = 1;     /* Don't scan ARGV[0], the program name.  */
     532        optind = 1;        /* Don't scan ARGV[0], the program name.  */
    533533      optstring = _getopt_initialize (argc, argv, optstring);
    534534      __getopt_initialized = 1;
     
    540540     is only used when the used in the GNU libc.  */
    541541#if defined _LIBC && defined USE_NONOPTION_FLAGS
    542 # define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0'       \
    543                       || (optind < nonoption_flags_len                        \
    544                           && __getopt_nonoption_flags[optind] == '1'))
     542# define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0'              \
     543                      || (optind < nonoption_flags_len                              \
     544                          && __getopt_nonoption_flags[optind] == '1'))
    545545#else
    546546# define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0')
     
    552552
    553553      /* Give FIRST_NONOPT & LAST_NONOPT rational values if OPTIND has been
    554         moved back by the user (who may also have changed the arguments).  */
     554        moved back by the user (who may also have changed the arguments).  */
    555555      if (last_nonopt > optind)
    556         last_nonopt = optind;
     556        last_nonopt = optind;
    557557      if (first_nonopt > optind)
    558         first_nonopt = optind;
     558        first_nonopt = optind;
    559559
    560560      if (ordering == PERMUTE)
    561         {
    562           /* If we have just processed some options following some non-options,
    563              exchange them so that the options come first.  */
    564 
    565           if (first_nonopt != last_nonopt && last_nonopt != optind)
    566             exchange ((char **) argv);
    567           else if (last_nonopt != optind)
    568             first_nonopt = optind;
    569 
    570           /* Skip any additional non-options
    571              and extend the range of non-options previously skipped.  */
    572 
    573           while (optind < argc && NONOPTION_P)
    574             optind++;
    575           last_nonopt = optind;
    576         }
     561        {
     562          /* If we have just processed some options following some non-options,
     563             exchange them so that the options come first.  */
     564
     565          if (first_nonopt != last_nonopt && last_nonopt != optind)
     566            exchange ((char **) argv);
     567          else if (last_nonopt != optind)
     568            first_nonopt = optind;
     569
     570          /* Skip any additional non-options
     571             and extend the range of non-options previously skipped.  */
     572
     573          while (optind < argc && NONOPTION_P)
     574            optind++;
     575          last_nonopt = optind;
     576        }
    577577
    578578      /* The special ARGV-element `--' means premature end of options.
    579         Skip it like a null option,
    580         then exchange with previous non-options as if it were an option,
    581         then skip everything else like a non-option.  */
     579        Skip it like a null option,
     580        then exchange with previous non-options as if it were an option,
     581        then skip everything else like a non-option.  */
    582582
    583583      if (optind != argc && !strcmp (argv[optind], "--"))
    584         {
    585           optind++;
    586 
    587           if (first_nonopt != last_nonopt && last_nonopt != optind)
    588             exchange ((char **) argv);
    589           else if (first_nonopt == last_nonopt)
    590             first_nonopt = optind;
    591           last_nonopt = argc;
    592 
    593           optind = argc;
    594         }
     584        {
     585          optind++;
     586
     587          if (first_nonopt != last_nonopt && last_nonopt != optind)
     588            exchange ((char **) argv);
     589          else if (first_nonopt == last_nonopt)
     590            first_nonopt = optind;
     591          last_nonopt = argc;
     592
     593          optind = argc;
     594        }
    595595
    596596      /* If we have done all the ARGV-elements, stop the scan
    597         and back over any non-options that we skipped and permuted.  */
     597        and back over any non-options that we skipped and permuted.  */
    598598
    599599      if (optind == argc)
    600         {
    601           /* Set the next-arg-index to point at the non-options
    602              that we previously skipped, so the caller will digest them.  */
    603           if (first_nonopt != last_nonopt)
    604             optind = first_nonopt;
    605           return -1;
    606         }
     600        {
     601          /* Set the next-arg-index to point at the non-options
     602             that we previously skipped, so the caller will digest them.  */
     603          if (first_nonopt != last_nonopt)
     604            optind = first_nonopt;
     605          return -1;
     606        }
    607607
    608608      /* If we have come to a non-option and did not permute it,
    609         either stop the scan or describe it to the caller and pass it by.  */
     609        either stop the scan or describe it to the caller and pass it by.  */
    610610
    611611      if (NONOPTION_P)
    612         {
    613           if (ordering == REQUIRE_ORDER)
    614             return -1;
    615           optarg = argv[optind++];
    616           return 1;
    617         }
     612        {
     613          if (ordering == REQUIRE_ORDER)
     614            return -1;
     615          optarg = argv[optind++];
     616          return 1;
     617        }
    618618
    619619      /* We have found another option-ARGV-element.
    620         Skip the initial punctuation.  */
     620        Skip the initial punctuation.  */
    621621
    622622      nextchar = (argv[optind] + 1
    623                   + (longopts != NULL && argv[optind][1] == '-'));
     623                  + (longopts != NULL && argv[optind][1] == '-'));
    624624    }
    625625
     
    641641  if (longopts != NULL
    642642      && (argv[optind][1] == '-'
    643           || (long_only && (argv[optind][2] || !my_index (optstring, argv[optind][1])))))
     643          || (long_only && (argv[optind][2] || !my_index (optstring, argv[optind][1])))))
    644644    {
    645645      char *nameend;
     
    652652
    653653      for (nameend = nextchar; *nameend && *nameend != '='; nameend++)
    654         /* Do nothing.  */ ;
     654        /* Do nothing.  */ ;
    655655
    656656      /* Test all long options for either exact match
    657         or abbreviated matches.  */
     657        or abbreviated matches.  */
    658658      for (p = longopts, option_index = 0; p->name; p++, option_index++)
    659         if (!strncmp (p->name, nextchar, nameend - nextchar))
    660           {
    661             if ((unsigned int) (nameend - nextchar)
    662                 == (unsigned int) strlen (p->name))
    663               {
    664                 /* Exact match found.  */
    665                 pfound = p;
    666                 indfound = option_index;
    667                 exact = 1;
    668                 break;
    669               }
    670             else if (pfound == NULL)
    671               {
    672                 /* First nonexact match found.  */
    673                 pfound = p;
    674                 indfound = option_index;
    675               }
    676             else if (long_only
    677                      || pfound->has_arg != p->has_arg
    678                      || pfound->flag != p->flag
    679                      || pfound->val != p->val)
    680               /* Second or later nonexact match found.  */
    681               ambig = 1;
    682           }
     659        if (!strncmp (p->name, nextchar, nameend - nextchar))
     660          {
     661            if ((unsigned int) (nameend - nextchar)
     662                == (unsigned int) strlen (p->name))
     663              {
     664                /* Exact match found.  */
     665                pfound = p;
     666                indfound = option_index;
     667                exact = 1;
     668                break;
     669              }
     670            else if (pfound == NULL)
     671              {
     672                /* First nonexact match found.  */
     673                pfound = p;
     674                indfound = option_index;
     675              }
     676            else if (long_only
     677                     || pfound->has_arg != p->has_arg
     678                     || pfound->flag != p->flag
     679                     || pfound->val != p->val)
     680              /* Second or later nonexact match found.  */
     681              ambig = 1;
     682          }
    683683
    684684      if (ambig && !exact)
    685         {
    686           if (print_errors)
    687             fprintf (stderr, _("%s: option `%s' is ambiguous\n"),
    688                      argv[0], argv[optind]);
    689           nextchar += strlen (nextchar);
    690           optind++;
    691           optopt = 0;
    692           return '?';
    693         }
     685        {
     686          if (print_errors)
     687            fprintf (stderr, _("%s: option `%s' is ambiguous\n"),
     688                     argv[0], argv[optind]);
     689          nextchar += strlen (nextchar);
     690          optind++;
     691          optopt = 0;
     692          return '?';
     693        }
    694694
    695695      if (pfound != NULL)
    696         {
    697           option_index = indfound;
    698           optind++;
    699           if (*nameend)
    700             {
    701               /* Don't test has_arg with >, because some C compilers don't
    702                 allow it to be used on enums.  */
    703               if (pfound->has_arg)
    704                 optarg = nameend + 1;
    705               else
    706                 {
    707                   if (print_errors)
    708                     {
    709                       if (argv[optind - 1][1] == '-')
    710                         /* --option */
    711                         fprintf (stderr,
    712                                 _("%s: option `--%s' doesn't allow an argument\n"),
    713                                 argv[0], pfound->name);
    714                       else
    715                         /* +option or -option */
    716                         fprintf (stderr,
    717                                 _("%s: option `%c%s' doesn't allow an argument\n"),
    718                                 argv[0], argv[optind - 1][0], pfound->name);
    719                     }
    720 
    721                   nextchar += strlen (nextchar);
    722 
    723                   optopt = pfound->val;
    724                   return '?';
    725                 }
    726             }
    727           else if (pfound->has_arg == 1)
    728             {
    729               if (optind < argc)
    730                 optarg = argv[optind++];
    731               else
    732                 {
    733                   if (print_errors)
    734                     fprintf (stderr,
    735                            _("%s: option `%s' requires an argument\n"),
    736                            argv[0], argv[optind - 1]);
    737                   nextchar += strlen (nextchar);
    738                   optopt = pfound->val;
    739                   return optstring[0] == ':' ? ':' : '?';
    740                 }
    741             }
    742           nextchar += strlen (nextchar);
    743           if (longind != NULL)
    744             *longind = option_index;
    745           if (pfound->flag)
    746             {
    747               *(pfound->flag) = pfound->val;
    748               return 0;
    749             }
    750           return pfound->val;
    751         }
     696        {
     697          option_index = indfound;
     698          optind++;
     699          if (*nameend)
     700            {
     701              /* Don't test has_arg with >, because some C compilers don't
     702                allow it to be used on enums.  */
     703              if (pfound->has_arg)
     704                optarg = nameend + 1;
     705              else
     706                {
     707                  if (print_errors)
     708                    {
     709                      if (argv[optind - 1][1] == '-')
     710                        /* --option */
     711                        fprintf (stderr,
     712                                _("%s: option `--%s' doesn't allow an argument\n"),
     713                                argv[0], pfound->name);
     714                      else
     715                        /* +option or -option */
     716                        fprintf (stderr,
     717                                _("%s: option `%c%s' doesn't allow an argument\n"),
     718                                argv[0], argv[optind - 1][0], pfound->name);
     719                    }
     720
     721                  nextchar += strlen (nextchar);
     722
     723                  optopt = pfound->val;
     724                  return '?';
     725                }
     726            }
     727          else if (pfound->has_arg == 1)
     728            {
     729              if (optind < argc)
     730                optarg = argv[optind++];
     731              else
     732                {
     733                  if (print_errors)
     734                    fprintf (stderr,
     735                           _("%s: option `%s' requires an argument\n"),
     736                           argv[0], argv[optind - 1]);
     737                  nextchar += strlen (nextchar);
     738                  optopt = pfound->val;
     739                  return optstring[0] == ':' ? ':' : '?';
     740                }
     741            }
     742          nextchar += strlen (nextchar);
     743          if (longind != NULL)
     744            *longind = option_index;
     745          if (pfound->flag)
     746            {
     747              *(pfound->flag) = pfound->val;
     748              return 0;
     749            }
     750          return pfound->val;
     751        }
    752752
    753753      /* Can't find it as a long option.  If this is not getopt_long_only,
    754         or the option starts with '--' or is not a valid short
    755         option, then it's an error.
    756         Otherwise interpret it as a short option.  */
     754        or the option starts with '--' or is not a valid short
     755        option, then it's an error.
     756        Otherwise interpret it as a short option.  */
    757757      if (!long_only || argv[optind][1] == '-'
    758           || my_index (optstring, *nextchar) == NULL)
    759         {
    760           if (print_errors)
    761             {
    762               if (argv[optind][1] == '-')
    763                 /* --option */
    764                 fprintf (stderr, _("%s: unrecognized option `--%s'\n"),
    765                         argv[0], nextchar);
    766               else
    767                 /* +option or -option */
    768                 fprintf (stderr, _("%s: unrecognized option `%c%s'\n"),
    769                         argv[0], argv[optind][0], nextchar);
    770             }
    771           nextchar = (char *) "";
    772           optind++;
    773           optopt = 0;
    774           return '?';
    775         }
     758          || my_index (optstring, *nextchar) == NULL)
     759        {
     760          if (print_errors)
     761            {
     762              if (argv[optind][1] == '-')
     763                /* --option */
     764                fprintf (stderr, _("%s: unrecognized option `--%s'\n"),
     765                        argv[0], nextchar);
     766              else
     767                /* +option or -option */
     768                fprintf (stderr, _("%s: unrecognized option `%c%s'\n"),
     769                        argv[0], argv[optind][0], nextchar);
     770            }
     771          nextchar = (char *) "";
     772          optind++;
     773          optopt = 0;
     774          return '?';
     775        }
    776776    }
    777777
     
    788788    if (temp == NULL || c == ':')
    789789      {
    790         if (print_errors)
    791           {
    792             if (posixly_correct)
    793               /* 1003.2 specifies the format of this message.  */
    794               fprintf (stderr, _("%s: illegal option -- %c\n"),
    795                        argv[0], c);
    796             else
    797               fprintf (stderr, _("%s: invalid option -- %c\n"),
    798                        argv[0], c);
    799           }
    800         optopt = c;
    801         return '?';
     790        if (print_errors)
     791          {
     792            if (posixly_correct)
     793              /* 1003.2 specifies the format of this message.  */
     794              fprintf (stderr, _("%s: illegal option -- %c\n"),
     795                       argv[0], c);
     796            else
     797              fprintf (stderr, _("%s: invalid option -- %c\n"),
     798                       argv[0], c);
     799          }
     800        optopt = c;
     801        return '?';
    802802      }
    803803    /* Convenience. Treat POSIX -W foo same as long option --foo */
    804804    if (temp[0] == 'W' && temp[1] == ';')
    805805      {
    806         char *nameend;
    807         const struct option *p;
    808         const struct option *pfound = NULL;
    809         int exact = 0;
    810         int ambig = 0;
    811         int indfound = 0;
    812         int option_index;
    813 
    814         /* This is an option that requires an argument.  */
    815         if (*nextchar != '\0')
    816           {
    817             optarg = nextchar;
    818             /* If we end this ARGV-element by taking the rest as an arg,
    819                we must advance to the next element now.  */
    820             optind++;
    821           }
    822         else if (optind == argc)
    823           {
    824             if (print_errors)
    825               {
    826                 /* 1003.2 specifies the format of this message.  */
    827                 fprintf (stderr, _("%s: option requires an argument -- %c\n"),
    828                         argv[0], c);
    829               }
    830             optopt = c;
    831             if (optstring[0] == ':')
    832               c = ':';
    833             else
    834               c = '?';
    835             return c;
    836           }
    837         else
    838           /* We already incremented `optind' once;
    839              increment it again when taking next ARGV-elt as argument.  */
    840           optarg = argv[optind++];
    841 
    842         /* optarg is now the argument, see if it's in the
    843            table of longopts.  */
    844 
    845         for (nextchar = nameend = optarg; *nameend && *nameend != '='; nameend++)
    846           /* Do nothing.  */ ;
    847 
    848         /* Test all long options for either exact match
    849            or abbreviated matches.  */
    850         for (p = longopts, option_index = 0; p->name; p++, option_index++)
    851           if (!strncmp (p->name, nextchar, nameend - nextchar))
    852             {
    853               if ((unsigned int) (nameend - nextchar) == strlen (p->name))
    854                 {
    855                   /* Exact match found.  */
    856                   pfound = p;
    857                   indfound = option_index;
    858                   exact = 1;
    859                   break;
    860                 }
    861               else if (pfound == NULL)
    862                 {
    863                   /* First nonexact match found.  */
    864                   pfound = p;
    865                   indfound = option_index;
    866                 }
    867               else
    868                 /* Second or later nonexact match found.  */
    869                 ambig = 1;
    870             }
    871         if (ambig && !exact)
    872           {
    873             if (print_errors)
    874               fprintf (stderr, _("%s: option `-W %s' is ambiguous\n"),
    875                        argv[0], argv[optind]);
    876             nextchar += strlen (nextchar);
    877             optind++;
    878             return '?';
    879           }
    880         if (pfound != NULL)
    881           {
    882             option_index = indfound;
    883             if (*nameend)
    884               {
    885                 /* Don't test has_arg with >, because some C compilers don't
    886                    allow it to be used on enums.  */
    887                 if (pfound->has_arg)
    888                   optarg = nameend + 1;
    889                 else
    890                   {
    891                     if (print_errors)
    892                       fprintf (stderr, _("\
     806        char *nameend;
     807        const struct option *p;
     808        const struct option *pfound = NULL;
     809        int exact = 0;
     810        int ambig = 0;
     811        int indfound = 0;
     812        int option_index;
     813
     814        /* This is an option that requires an argument.  */
     815        if (*nextchar != '\0')
     816          {
     817            optarg = nextchar;
     818            /* If we end this ARGV-element by taking the rest as an arg,
     819               we must advance to the next element now.  */
     820            optind++;
     821          }
     822        else if (optind == argc)
     823          {
     824            if (print_errors)
     825              {
     826                /* 1003.2 specifies the format of this message.  */
     827                fprintf (stderr, _("%s: option requires an argument -- %c\n"),
     828                        argv[0], c);
     829              }
     830            optopt = c;
     831            if (optstring[0] == ':')
     832              c = ':';
     833            else
     834              c = '?';
     835            return c;
     836          }
     837        else
     838          /* We already incremented `optind' once;
     839             increment it again when taking next ARGV-elt as argument.  */
     840          optarg = argv[optind++];
     841
     842        /* optarg is now the argument, see if it's in the
     843           table of longopts.  */
     844
     845        for (nextchar = nameend = optarg; *nameend && *nameend != '='; nameend++)
     846          /* Do nothing.  */ ;
     847
     848        /* Test all long options for either exact match
     849           or abbreviated matches.  */
     850        for (p = longopts, option_index = 0; p->name; p++, option_index++)
     851          if (!strncmp (p->name, nextchar, nameend - nextchar))
     852            {
     853              if ((unsigned int) (nameend - nextchar) == strlen (p->name))
     854                {
     855                  /* Exact match found.  */
     856                  pfound = p;
     857                  indfound = option_index;
     858                  exact = 1;
     859                  break;
     860                }
     861              else if (pfound == NULL)
     862                {
     863                  /* First nonexact match found.  */
     864                  pfound = p;
     865                  indfound = option_index;
     866                }
     867              else
     868                /* Second or later nonexact match found.  */
     869                ambig = 1;
     870            }
     871        if (ambig && !exact)
     872          {
     873            if (print_errors)
     874              fprintf (stderr, _("%s: option `-W %s' is ambiguous\n"),
     875                       argv[0], argv[optind]);
     876            nextchar += strlen (nextchar);
     877            optind++;
     878            return '?';
     879          }
     880        if (pfound != NULL)
     881          {
     882            option_index = indfound;
     883            if (*nameend)
     884              {
     885                /* Don't test has_arg with >, because some C compilers don't
     886                   allow it to be used on enums.  */
     887                if (pfound->has_arg)
     888                  optarg = nameend + 1;
     889                else
     890                  {
     891                    if (print_errors)
     892                      fprintf (stderr, _("\
    893893%s: option `-W %s' doesn't allow an argument\n"),
    894                                argv[0], pfound->name);
    895 
    896                     nextchar += strlen (nextchar);
    897                     return '?';
    898                   }
    899               }
    900             else if (pfound->has_arg == 1)
    901               {
    902                 if (optind < argc)
    903                   optarg = argv[optind++];
    904                 else
    905                   {
    906                     if (print_errors)
    907                       fprintf (stderr,
    908                                _("%s: option `%s' requires an argument\n"),
    909                                argv[0], argv[optind - 1]);
    910                     nextchar += strlen (nextchar);
    911                     return optstring[0] == ':' ? ':' : '?';
    912                   }
    913               }
    914             nextchar += strlen (nextchar);
    915             if (longind != NULL)
    916               *longind = option_index;
    917             if (pfound->flag)
    918               {
    919                 *(pfound->flag) = pfound->val;
    920                 return 0;
    921               }
    922             return pfound->val;
    923           }
    924           nextchar = NULL;
    925           return 'W';   /* Let the application handle it.   */
     894                               argv[0], pfound->name);
     895
     896                    nextchar += strlen (nextchar);
     897                    return '?';
     898                  }
     899              }
     900            else if (pfound->has_arg == 1)
     901              {
     902                if (optind < argc)
     903                  optarg = argv[optind++];
     904                else
     905                  {
     906                    if (print_errors)
     907                      fprintf (stderr,
     908                               _("%s: option `%s' requires an argument\n"),
     909                               argv[0], argv[optind - 1]);
     910                    nextchar += strlen (nextchar);
     911                    return optstring[0] == ':' ? ':' : '?';
     912                  }
     913              }
     914            nextchar += strlen (nextchar);
     915            if (longind != NULL)
     916              *longind = option_index;
     917            if (pfound->flag)
     918              {
     919                *(pfound->flag) = pfound->val;
     920                return 0;
     921              }
     922            return pfound->val;
     923          }
     924          nextchar = NULL;
     925          return 'W';        /* Let the application handle it.   */
    926926      }
    927927    if (temp[1] == ':')
    928928      {
    929         if (temp[2] == ':')
    930           {
    931             /* This is an option that accepts an argument optionally.  */
    932             if (*nextchar != '\0')
    933               {
    934                 optarg = nextchar;
    935                 optind++;
    936               }
    937             else
    938               optarg = NULL;
    939             nextchar = NULL;
    940           }
    941         else
    942           {
    943             /* This is an option that requires an argument.  */
    944             if (*nextchar != '\0')
    945               {
    946                 optarg = nextchar;
    947                 /* If we end this ARGV-element by taking the rest as an arg,
    948                    we must advance to the next element now.  */
    949                 optind++;
    950               }
    951             else if (optind == argc)
    952               {
    953                 if (print_errors)
    954                   {
    955                     /* 1003.2 specifies the format of this message.  */
    956                     fprintf (stderr,
    957                              _("%s: option requires an argument -- %c\n"),
    958                              argv[0], c);
    959                   }
    960                 optopt = c;
    961                 if (optstring[0] == ':')
    962                   c = ':';
    963                 else
    964                   c = '?';
    965               }
    966             else
    967               /* We already incremented `optind' once;
    968                 increment it again when taking next ARGV-elt as argument.  */
    969               optarg = argv[optind++];
    970             nextchar = NULL;
    971           }
     929        if (temp[2] == ':')
     930          {
     931            /* This is an option that accepts an argument optionally.  */
     932            if (*nextchar != '\0')
     933              {
     934                optarg = nextchar;
     935                optind++;
     936              }
     937            else
     938              optarg = NULL;
     939            nextchar = NULL;
     940          }
     941        else
     942          {
     943            /* This is an option that requires an argument.  */
     944            if (*nextchar != '\0')
     945              {
     946                optarg = nextchar;
     947                /* If we end this ARGV-element by taking the rest as an arg,
     948                   we must advance to the next element now.  */
     949                optind++;
     950              }
     951            else if (optind == argc)
     952              {
     953                if (print_errors)
     954                  {
     955                    /* 1003.2 specifies the format of this message.  */
     956                    fprintf (stderr,
     957                             _("%s: option requires an argument -- %c\n"),
     958                             argv[0], c);
     959                  }
     960                optopt = c;
     961                if (optstring[0] == ':')
     962                  c = ':';
     963                else
     964                  c = '?';
     965              }
     966            else
     967              /* We already incremented `optind' once;
     968                increment it again when taking next ARGV-elt as argument.  */
     969              optarg = argv[optind++];
     970            nextchar = NULL;
     971          }
    972972      }
    973973    return c;
     
    982982{
    983983  return _getopt_internal (argc, argv, optstring,
    984                            (const struct option *) 0,
    985                            (int *) 0,
    986                            0);
     984                           (const struct option *) 0,
     985                           (int *) 0,
     986                           0);
    987987}
    988988
    989 #endif  /* Not ELIDE_CODE.  */
     989#endif        /* Not ELIDE_CODE.  */
    990990
    991991
     
    10091009      c = getopt (argc, argv, "abc:d:0123456789");
    10101010      if (c == -1)
    1011         break;
     1011        break;
    10121012
    10131013      switch (c)
    1014         {
    1015         case '0':
    1016         case '1':
    1017         case '2':
    1018         case '3':
    1019         case '4':
    1020         case '5':
    1021         case '6':
    1022         case '7':
    1023         case '8':
    1024         case '9':
    1025           if (digit_optind != 0 && digit_optind != this_option_optind)
    1026             printf ("digits occur in two different argv-elements.\n");
    1027           digit_optind = this_option_optind;
    1028           printf ("option %c\n", c);
    1029           break;
    1030 
    1031         case 'a':
    1032           printf ("option a\n");
    1033           break;
    1034 
    1035         case 'b':
    1036           printf ("option b\n");
    1037           break;
    1038 
    1039         case 'c':
    1040           printf ("option c with value `%s'\n", optarg);
    1041           break;
    1042 
    1043         case '?':
    1044           break;
    1045 
    1046         default:
    1047           printf ("?? getopt returned character code 0%o ??\n", c);
    1048         }
     1014        {
     1015        case '0':
     1016        case '1':
     1017        case '2':
     1018        case '3':
     1019        case '4':
     1020        case '5':
     1021        case '6':
     1022        case '7':
     1023        case '8':
     1024        case '9':
     1025          if (digit_optind != 0 && digit_optind != this_option_optind)
     1026            printf ("digits occur in two different argv-elements.\n");
     1027          digit_optind = this_option_optind;
     1028          printf ("option %c\n", c);
     1029          break;
     1030
     1031        case 'a':
     1032          printf ("option a\n");
     1033          break;
     1034
     1035        case 'b':
     1036          printf ("option b\n");
     1037          break;
     1038
     1039        case 'c':
     1040          printf ("option c with value `%s'\n", optarg);
     1041          break;
     1042
     1043        case '?':
     1044          break;
     1045
     1046        default:
     1047          printf ("?? getopt returned character code 0%o ??\n", c);
     1048        }
    10491049    }
    10501050
     
    10531053      printf ("non-option ARGV-elements: ");
    10541054      while (optind < argc)
    1055         printf ("%s ", argv[optind++]);
     1055        printf ("%s ", argv[optind++]);
    10561056      printf ("\n");
    10571057    }
  • old_modgen/modgen/main.cc

    r412c61 r2bf04b  
    117117                   break;
    118118         default:
    119                    printf("\t-%c (--%s) %s\n", long_options[i].val,
    120                       long_options[i].name, "<argument>");
     119                   printf("\t-%c (--%s) %s\n", long_options[i].val,
     120                      long_options[i].name, "<argument>");
    121121      }
    122122    } else
     
    147147        case 'v' : trace=1; break;
    148148        case 'm' : do_create_makefile = 0; break;
    149         case 'i' : inst_dir=optarg; break;
    150         case 's' : do_create_srcdir = 0; break;
     149        case 'i' : inst_dir=optarg; break;
     150        case 's' : do_create_srcdir = 0; break;
    151151
    152152        case '?' : usage(argv[0]);
  • old_modgen/modgen/mod_grammar.y

    r412c61 r2bf04b  
    141141          fprintf(module_def.fmtfp, "%s", $1);
    142142          fprintf(module_def.fmtfp, "#line %d \"%s\"\n",
    143                                           yylineno, module_def.filename);
     143                                          yylineno, module_def.filename);
    144144          free($1);
    145145          write_mod_init(&module_def, module_def.fmtfp);
    146           initdone = 1;
     146          initdone = 1;
    147147        };
    148148
     
    154154sect1end:
    155155        codeline2 SECTEND
    156         {
    157           memset(&procedure_decl, 0, sizeof(procdef));
    158           if(debug>2)printf("End of section 1 (new=%d)\n", sectnum);
    159         }
    160         | SECTEND
    161156        {
    162157          memset(&procedure_decl, 0, sizeof(procdef));
    163158          if(debug>2)printf("End of section 1 (new=%d)\n", sectnum);
    164159        }
     160        | SECTEND
     161        {
     162          memset(&procedure_decl, 0, sizeof(procdef));
     163          if(debug>2)printf("End of section 1 (new=%d)\n", sectnum);
     164        }
    165165        ;
    166166
    167167codeline2: CODEPART
    168168        {
    169           if(initdone == 0) {
    170             write_mod_init(&module_def, module_def.fmtfp);
    171             initdone = 1;
    172           }
    173           fprintf(module_def.fmtfp, "#line %d \"%s\"\n",
    174                                     yylineno, module_def.filename);
     169          if(initdone == 0) {
     170            write_mod_init(&module_def, module_def.fmtfp);
     171            initdone = 1;
     172          }
     173          fprintf(module_def.fmtfp, "#line %d \"%s\"\n",
     174                                    yylineno, module_def.filename);
    175175          fprintf(module_def.fmtfp, "%s", $1);
    176176        }
     
    195195                  if(vt==VAR_VERSION)
    196196                    make_version($3.string, &module_def);
    197                   if(vt==VAR_MODULE)
    198                     make_module_name($3.string, &module_def);
     197                  if(vt==VAR_MODULE)
     198                    make_module_name($3.string, &module_def);
    199199                }
    200200                else {
     
    349349          if(debug>2)printf("SG-PROCDEF:\n");
    350350          write_singular_end(&module_def, &procedure_decl, yylineno);
    351           setup_proc(&module_def, &procedure_decl);
    352           write_helpfile_help(&module_def, &procedure_decl);
     351          setup_proc(&module_def, &procedure_decl);
     352          write_helpfile_help(&module_def, &procedure_decl);
    353353        }
    354354        | procdeclsg proccode procdeclexample
     
    358358          write_singular_end(&module_def, &procedure_decl, yylineno);
    359359          setup_proc(&module_def, &procedure_decl);
    360           write_helpfile_help(&module_def, &procedure_decl);
     360          write_helpfile_help(&module_def, &procedure_decl);
    361361        }
    362362;
     
    403403        {
    404404          if(debug>2)printf("PROCDEF:\n");
    405           write_helpfile_help(&module_def, &procedure_decl);
     405          write_helpfile_help(&module_def, &procedure_decl);
    406406        }
    407407        | procdecl proccode procdeclexample
    408408        {
    409409          if(debug>2)printf("PROCDEF mit example:\n");
    410           write_helpfile_help(&module_def, &procedure_decl);
     410          write_helpfile_help(&module_def, &procedure_decl);
    411411          fflush(module_def.fmtfp);
    412412        }
     
    717717        {
    718718          fprintf(module_def.modfp, "#line %d \"%s\"\n",
    719                                           yylineno, module_def.filename);
     719                                          yylineno, module_def.filename);
    720720          fprintf(module_def.modfp, "%s", $1);
    721721        }
    722722        | codeline CODEPART
    723723        {
    724           fprintf(module_def.modfp, "%s", $2);
     724          fprintf(module_def.modfp, "%s", $2);
    725725        }
    726726        ;
  • old_modgen/modgen/my_getopt.h

    r412c61 r2bf04b  
    3535#endif
    3636
    37 #ifdef  __cplusplus
     37#ifdef        __cplusplus
    3838extern "C" {
    3939#endif
     
    7777
    7878   The field `has_arg' is:
    79    no_argument          (or 0) if the option does not take an argument,
    80    required_argument    (or 1) if the option requires an argument,
    81    optional_argument    (or 2) if the option takes an optional argument.
     79   no_argument                (or 0) if the option does not take an argument,
     80   required_argument        (or 1) if the option requires an argument,
     81   optional_argument         (or 2) if the option takes an optional argument.
    8282
    8383   If the field `flag' is not NULL, it points to a variable that is set
     
    108108/* Names for the values of the `has_arg' field of `struct option'.  */
    109109
    110 # define no_argument            0
    111 # define required_argument      1
    112 # define optional_argument      2
    113 #endif  /* need getopt */
     110# define no_argument                0
     111# define required_argument        1
     112# define optional_argument        2
     113#endif        /* need getopt */
    114114
    115115
     
    149149# ifndef __need_getopt
    150150extern int getopt_long (int __argc, char *const *__argv, const char *__shortopts,
    151                         const struct option *__longopts, int *__longind);
     151                        const struct option *__longopts, int *__longind);
    152152extern int getopt_long_only (int __argc, char *const *__argv,
    153                              const char *__shortopts,
    154                              const struct option *__longopts, int *__longind);
     153                             const char *__shortopts,
     154                             const struct option *__longopts, int *__longind);
    155155
    156156/* Internal only.  Users should not call this directly.  */
    157157extern int _getopt_internal (int __argc, char *const *__argv,
    158                              const char *__shortopts,
    159                              const struct option *__longopts, int *__longind,
    160                              int __long_only);
     158                             const char *__shortopts,
     159                             const struct option *__longopts, int *__longind,
     160                             int __long_only);
    161161# endif
    162162#else /* not __STDC__ */
     
    170170#endif /* __STDC__ */
    171171
    172 #ifdef  __cplusplus
     172#ifdef        __cplusplus
    173173}
    174174#endif
  • old_modgen/modgen/scanner.l

    r412c61 r2bf04b  
    153153<COMMENT,COMMENTB,STRING,INITIAL><<EOF>>   {
    154154          printf( "EOF encountered inside an action\n");
    155           printf("ERRRRROOOOORRR\n");
     155          printf("ERRRRROOOOORRR\n");
    156156                 }
    157157
     
    224224        ^"/*"      push_state(YYSTATE, COMMENT, "COMMENT"); yymore();
    225225        "//".*{NL} ++yylineno; ACTION_ECHO;
    226         {BOOL}  { if(yyleng == 1) sscanf(yytext, "%d", &lvalp->i);
    227                   else {
    228                     if(strcasecmp(yytext, "yes")==0) lvalp->i = 1;
    229                     else lvalp->i = 0;
     226        {BOOL}  { if(yyleng == 1) sscanf(yytext, "%d", &lvalp->i);
     227                  else {
     228                    if(strcasecmp(yytext, "yes")==0) lvalp->i = 1;
     229                    else lvalp->i = 0;
    230230                  }
    231231                  return BOOLTOK; }
    232         ^"%{".*{NL} {
    233                 yylineno++;
    234                 push_state(YYSTATE, CODEBLOCK, "CODEBLOCK");
    235                 fprintf(module_def.fmtfp, "#line %d \"%s\"\n",
    236                                           yylineno, module_def.filename);
    237                 }
    238         ^"%modinitial".*{NL} {
    239                 yylineno++;
    240                 push_state(YYSTATE, MODINITIAL, "MODINITIAL");
    241                 fprintf(module_def.fmtfp, "#line %d \"%s\"\n",
    242                                           yylineno, module_def.filename);
    243                 }
    244         {WS}            /* discard */
     232        ^"%{".*{NL} {
     233                yylineno++;
     234                push_state(YYSTATE, CODEBLOCK, "CODEBLOCK");
     235                fprintf(module_def.fmtfp, "#line %d \"%s\"\n",
     236                                          yylineno, module_def.filename);
     237                }
     238        ^"%modinitial".*{NL} {
     239                yylineno++;
     240                push_state(YYSTATE, MODINITIAL, "MODINITIAL");
     241                fprintf(module_def.fmtfp, "#line %d \"%s\"\n",
     242                                                 yylineno, module_def.filename);
     243                }
     244        {WS}            /* discard */
    245245        {NL}    { yylineno++; }
    246246
     
    254254                }
    255255
    256         ^{NAME} {
    257                   lvalp->name = strdup(yytext);
     256        ^{NAME} {
     257                  lvalp->name = strdup(yytext);
    258258                  return NAME;
    259259                }
    260         {FILENAME} {
    261                   lvalp->name = strdup(yytext);
     260        {FILENAME} {
     261                  lvalp->name = strdup(yytext);
    262262                  return FILENAME;
    263263                }
    264            }
     264           }
    265265
    266266<CODEBLOCK>{
     
    269269
    270270                   yylineno++;
    271                    pop_state();
    272                    s = t = lvalp->name = dupyytext();
    273                    while (*yytext)
    274                    {
    275                      if (*yytext == '\\') yytext++;
    276                      *s++ = *yytext++;
    277                    }
    278                    if(s-t>2 && *(s-1)=='}' && *(s-2)=='%') *(s-2)='\0';
    279                    return MCCODETOK;
     271                   pop_state();
     272                   s = t = lvalp->name = dupyytext();
     273                   while (*yytext)
     274                   {
     275                     if (*yytext == '\\') yytext++;
     276                     *s++ = *yytext++;
     277                   }
     278                   if(s-t>2 && *(s-1)=='}' && *(s-2)=='%') *(s-2)='\0';
     279                   return MCCODETOK;
    280280                 }
    281281         {NL}    { yylineno++; yymore(); }
     
    284284<MODINITIAL>{
    285285           ^"%endinitial".*{NL} {
    286                    yylineno++;
    287                    pop_state();
     286                   yylineno++;
     287                   pop_state();
    288288                 }
    289289           .*{NL}  { yylineno++;
    290                    lvalp->name = yytext;
    291                    return CODEPART; }
     290                   lvalp->name = yytext;
     291                   return CODEPART; }
    292292       }
    293293<STRING>{
     
    299299                    char * s, *t;
    300300                    pop_state();
    301                     if(do_return) {
     301                    if(do_return) {
    302302                      s = t = lvalp->sv.string = dupyytext();
    303303                      while (*yytext)
     
    306306                        *s++ = *yytext++;
    307307                      }
    308                       *s++ = *yytext++;
    309                       do_return = 0;
    310                       return MSTRINGTOK;
     308                      *s++ = *yytext++;
     309                      do_return = 0;
     310                      return MSTRINGTOK;
    311311                    } else {
    312                       do_return = 0;
     312                      do_return = 0;
    313313                      yymore();
    314314                    }
    315                   }
    316         }
     315                  }
     316        }
    317317
    318318<COMMENT>{
     
    321321        {NL}          { yylineno++; yymore(); }
    322322        .             { yymore(); }
    323           }
     323          }
    324324
    325325<SECT2>{
     
    333333                  brace2 = 0; /* ( */
    334334                  brace3 = 0; /* [ */
    335                   push_state(YYSTATE, PROCDECL, "PROCDECL");
    336                   return PROCDECLTOK;
     335                  push_state(YYSTATE, PROCDECL, "PROCDECL");
     336                  return PROCDECLTOK;
    337337                }
    338338        example {
    339339#if DEBUG > 1
    340                   printf(">>>EXAMPLE\n");
     340                  printf(">>>EXAMPLE\n");
    341341#endif
    342342                  brace1 = 0; /* { */
    343343                  brace2 = 0; /* ( */
    344344                  brace3 = 0; /* [ */
    345                     push_state(YYSTATE, EXAMPLE, "EXAMPLE");
    346                         return EXAMPLETOK;
    347                 }
    348             static  { return STATICTOK; }
     345                    push_state(YYSTATE, EXAMPLE, "EXAMPLE");
     346                        return EXAMPLETOK;
     347                }
     348             static  { return STATICTOK; }
    349349        .       { printf("SG(%d) <<<'%s' ", yylineno, yytext); }
    350350       }
     
    358358        example {
    359359#if DEBUG > 1
    360                   printf(">>>EXAMPLE\n");
     360                  printf(">>>EXAMPLE\n");
    361361#endif
    362362                  brace1 = 0; /* { */
    363363                  brace2 = 0; /* ( */
    364364                  brace3 = 0; /* [ */
    365                   push_state(YYSTATE, EXAMPLE, "EXAMPLE");
    366                   return EXAMPLETOK;
    367                 }
    368         static  { return STATICTOK; }
    369         {NAME}  {
    370                    int i,tok;
     365                  push_state(YYSTATE, EXAMPLE, "EXAMPLE");
     366                  return EXAMPLETOK;
     367                }
     368        static  { return STATICTOK; }
     369        {NAME}  {
     370                   int i,tok;
    371371#if DEBUG > 1
    372                    printf("(%d) VAR: %s\n", yylineno, yytext);
    373 #endif
    374                    i = IsCmd(yytext, tok);
     372                   printf("(%d) VAR: %s\n", yylineno, yytext);
     373#endif
     374                   i = IsCmd(yytext, tok);
    375375#if DEBUG > 1
    376                    printf("Res=%d, %d => %s\n", i, tok,
    377                           i ? "VARTYPETOK" : "NAME");
    378 #endif
    379                    if(i) {
    380                      lvalp->tp.name = strdup(yytext);
    381                      lvalp->tp.typ = tok;
    382                      push_state(YYSTATE, PROCDECL, "PROCDECL");
    383                      return VARTYPETOK;
    384                    }
    385                    else {
    386                      //do_return++;
    387                      lvalp->name = strdup(yytext);
    388                      push_state(YYSTATE, PROCDECL, "PROCDECL");
    389                      return NAME;
    390                    }
     376                   printf("Res=%d, %d => %s\n", i, tok,
     377                          i ? "VARTYPETOK" : "NAME");
     378#endif
     379                   if(i) {
     380                     lvalp->tp.name = strdup(yytext);
     381                     lvalp->tp.typ = tok;
     382                     push_state(YYSTATE, PROCDECL, "PROCDECL");
     383                     return VARTYPETOK;
     384                   }
     385                   else {
     386                     //do_return++;
     387                     lvalp->name = strdup(yytext);
     388                     push_state(YYSTATE, PROCDECL, "PROCDECL");
     389                     return NAME;
     390                   }
    391391                 }
    392392        .       { printf("PR(%d) <<<'%s' ", yylineno, yytext); }
     
    397397        {WS}    /* ignore */
    398398        "{"     { brace1++;
    399                   switch_state(YYSTATE, CODEBLOCK2, "CODEBLOCK2");
    400                   return '{';
    401                 }
     399                  switch_state(YYSTATE, CODEBLOCK2, "CODEBLOCK2");
     400                  return '{';
     401                }
    402402        .       { printf("ERROR <<<'%s' ", yytext); }
    403403}
     
    406406        {NL}    { yylineno++; }
    407407        .*(\n?) { lvalp->name = yytext;
    408                   return CODEPART; }
     408                  return CODEPART; }
    409409
    410410        <<EOF>>  { sectnum = 0;
    411                    iseof=1;
    412                    lvalp->name = yytext;
    413                    return SECT4END;
     411                   iseof=1;
     412                   lvalp->name = yytext;
     413                   return SECT4END;
    414414                   /* yyterminate(); */
    415415                 }
     
    418418<PROCDECL>{
    419419         "{"     { brace1++;
    420                    switch_state(YYSTATE, CODEBLOCK2, "CODEBLOCK2");
    421                    return '{';
    422                 }
     420                   switch_state(YYSTATE, CODEBLOCK2, "CODEBLOCK2");
     421                   return '{';
     422                }
    423423         "/*"       push_state(YYSTATE, COMMENT, "COMMENT");yymore();
    424424         "//".*{NL}  ++yylineno; ACTION_ECHO;
    425425         "\""    { do_return++;
    426                    lvalp->sv.lineno = yylineno;
     426                   lvalp->sv.lineno = yylineno;
    427427                   push_state(YYSTATE, STRING, "string");
    428428                 }
    429         {BOOL}  { if(yyleng == 1) sscanf(yytext, "%d", &lvalp->i);
    430                    else {
    431                      if(strcasecmp(yytext, "yes")==0) lvalp->i = 1;
    432                      else lvalp->i = 0;
     429        {BOOL}  { if(yyleng == 1) sscanf(yytext, "%d", &lvalp->i);
     430                   else {
     431                     if(strcasecmp(yytext, "yes")==0) lvalp->i = 1;
     432                     else lvalp->i = 0;
    433433                   }
    434434                   return BOOLTOK; }
    435         {NUMBER} { sscanf(yytext, "%d", &lvalp->i); return NUMTOK; }
    436         {NAME}  {
    437                    int i,tok;
     435        {NUMBER} { sscanf(yytext, "%d", &lvalp->i); return NUMTOK; }
     436        {NAME}  {
     437                   int i,tok;
    438438#if DEBUG > 1
    439                    printf("(%d) VAR: %s\n", yylineno, yytext);
    440 #endif
    441                    i = IsCmd(yytext, tok);
     439                   printf("(%d) VAR: %s\n", yylineno, yytext);
     440#endif
     441                   i = IsCmd(yytext, tok);
    442442#if DEBUG > 1
    443                    printf("Res=%d, %d => %s\n", i, tok,
    444                           i ? "VARTYPETOK" : "NAME");
    445 #endif
    446                    if(i) {
    447                      lvalp->tp.name = strdup(yytext);
    448                      lvalp->tp.typ = tok;
    449                      return VARTYPETOK;
    450                    }
    451                    else {
    452                      //do_return++;
    453                      lvalp->name = strdup(yytext);
    454                      return NAME;
    455                    }
     443                   printf("Res=%d, %d => %s\n", i, tok,
     444                          i ? "VARTYPETOK" : "NAME");
     445#endif
     446                   if(i) {
     447                     lvalp->tp.name = strdup(yytext);
     448                     lvalp->tp.typ = tok;
     449                     return VARTYPETOK;
     450                   }
     451                   else {
     452                     //do_return++;
     453                     lvalp->name = strdup(yytext);
     454                     return NAME;
     455                   }
    456456                 }
    457457         {NL}    { yylineno++; }
    458         "("     { return '('; }
    459         ")"     { return ')'; }
    460         ","     { return ','; }
    461         "#"     { return '#'; }
    462         "="     { return '='; }
    463         ";"     { return ';'; }
     458        "("     { return '('; }
     459        ")"     { return ')'; }
     460        ","     { return ','; }
     461        "#"     { return '#'; }
     462        "="     { return '='; }
     463        ";"     { return ';'; }
    464464         .       { }
    465465
     
    471471                        lvalp->name = yytext;
    472472                        return CMTPART;
    473                         yymore();
     473                        yymore();
    474474                      }
    475475        "*"           yymore();
    476476        {NL}          { yylineno++; yymore(); }
    477477        .             { yymore(); }
    478           }
     478          }
    479479
    480480<CODEBLOCK2>{
     
    482482         "//".*{NL} { yylineno++; lvalp->name = yytext; return CODEPART; }
    483483         "\""    {
    484                    lvalp->sv.lineno = yylineno;
     484                   lvalp->sv.lineno = yylineno;
    485485                   push_state(YYSTATE, STRING, "string"); yymore();}
    486486         "{"     { brace1++; yymore();}
     
    489489                     char * s, *t;
    490490
    491                      pop_state();
     491                     pop_state();
    492492#if 0
    493                      s = t = lvalp->name = dupyytext();
    494                      while (*yytext)
    495                      {
    496                        if (*yytext == '\\') yytext++;
    497                        *s++ = *yytext++;
    498                      }
    499                      if(s-t>2 && *(s-1)=='}' && *(s-2)=='%') *(s-2)='\0';
     493                     s = t = lvalp->name = dupyytext();
     494                     while (*yytext)
     495                     {
     496                       if (*yytext == '\\') yytext++;
     497                       *s++ = *yytext++;
     498                     }
     499                     if(s-t>2 && *(s-1)=='}' && *(s-2)=='%') *(s-2)='\0';
    500500#else
    501501                     lvalp->name = yytext;
     
    504504                     printf("2 BRACE DOWN=%d\n", brace1);
    505505#endif
    506                      return MCODETOK;
     506                     return MCODETOK;
    507507                   } else {
    508508                     yymore();
    509                    }
     509                   }
    510510                 }
    511511         {NL}    { yylineno++; lvalp->name = yytext; return CODEPART; }
    512         "%" { push_state(YYSTATE, PROCCMDBLOCK, "PROCCMDBLOCK");
     512        "%" { push_state(YYSTATE, PROCCMDBLOCK, "PROCCMDBLOCK");
    513513               procedure_decl.flags.start_of_code = 1;
    514514               return '%'; }
     
    520520<PROCCMDBLOCK>{
    521521       {col}  { pop_state(); return ';'; }
    522         "("   { return '('; }
    523         ")"   { return ')'; }
    524         ","   { return ','; }
     522        "("   { return '('; }
     523        ")"   { return ')'; }
     524        ","   { return ','; }
    525525       {WS}   /* ignore */
    526526       {NAME} { lvalp->name = strdup(yytext); return NAME; }
Note: See TracChangeset for help on using the changeset viewer.