123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255 |
- #ifndef GETOPTV_SOURCE
- #define GETOPTV_SOURCE
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include "../tools/getoptv.h"
- #include "../tools/putoptv.h"
- #include "../tools/version.h"
- #include "../tools/error.h"
- char const * program_name = "program";
- char * optarg = (char *) (0);
- signed optopt = (char) (0);
- signed optind = 1;
- signed opterr = 1;
- signed optmin = 0;
- signed getoptv (int argc, char const * argv [], char const * optv [])
- {
- static char const * string;
- static char const * option;
- static signed count;
- signed index;
- if ((optind == 0) || (optind == 1))
- {
- for (program_name = string = * argv; * string; string++)
- {
- if ((* string == '/') || (* string == '\\'))
- {
- program_name = string + 1;
- }
- }
- string = (char *) (0);
- if (argc == optmin)
- {
- putoptv (optv);
- exit (0);
- }
- count = optind = 1;
- }
- while ((count < argc) || (string))
- {
- if (string)
- {
- if (*string)
- {
- optarg = (char *) (0);
- optopt = *string++;
- for (option = * optv; * option; option++)
- {
- if (optopt == GETOPTV_C_OPERAND)
- {
- continue;
- }
- if (*option == GETOPTV_C_OPERAND)
- {
- continue;
- }
- if (*option == optopt)
- {
- option++;
- if (*option != GETOPTV_C_OPERAND)
- {
- return (optopt);
- }
- if (*string)
- {
- optarg = (char *) (string);
- string = (char *) (0);
- return (optopt);
- }
- if (count < argc)
- {
- optarg = (char *)(argv [count]);
- for (index = count++; index > optind; index--)
- {
- argv [index] = argv [index - 1];
- }
- argv [optind++] = optarg;
- return (optopt);
- }
- if (opterr)
- {
- error (1, 0, "option '%c' needs an operand.", optopt);
- }
- if (** optv == GETOPTV_C_OPERAND)
- {
- return (GETOPTV_C_OPERAND);
- }
- return (GETOPTV_C_ILLEGAL);
- }
- }
- if (opterr)
- {
- error (1, 0, "option '%c' has no meaning.", optopt);
- }
- return (GETOPTV_C_ILLEGAL);
- }
- else
- {
- string = (char *) (0);
- }
- }
- if (count < argc)
- {
- string = argv [count];
- if (*string == GETOPTV_C_OPTION)
- {
- for (index = count; index > optind; index--)
- {
- argv [index] = argv [index - 1];
- }
- argv [optind++] = string++;
- if (*string == GETOPTV_C_VERSION)
- {
- version ();
- exit (0);
- }
- if (*string == GETOPTV_C_SUMMARY)
- {
- putoptv (optv);
- exit (0);
- }
- if (*string == GETOPTV_C_OPTION)
- {
- string++;
- if (!strcmp (string, ""))
- {
- optarg = (char *) (0);
- optopt = (char) (0);
- return (-1);
- }
- if (!strcmp (string, "version"))
- {
- version ();
- exit (0);
- }
- if (!strcmp (string, "help"))
- {
- putoptv (optv);
- exit (0);
- }
- optarg = (char *)(string);
- optopt = GETOPTV_C_OPTION;
- return (-1);
- }
- }
- else
- {
- string = (char *) (0);
- }
- count++;
- }
- }
- optarg = (char *) (0);
- optopt = (char) (0);
- return (-1);
- }
- #endif
|