]> gcc.gnu.org Git - gcc.git/blame - gcc/m2/gm2-libs-ch/cgetopt.c
Year date changes for Modula-2 source tree.
[gcc.git] / gcc / m2 / gm2-libs-ch / cgetopt.c
CommitLineData
7401123f
GM
1/* getopt.c provide access to the C getopt library.
2
3d864fce 3Copyright (C) 2017-2022 Free Software Foundation, Inc.
7401123f
GM
4Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
5
6This file is part of GNU Modula-2.
7
8GNU Modula-2 is free software; you can redistribute it and/or modify
9it under the terms of the GNU General Public License as published by
10the Free Software Foundation; either version 3, or (at your option)
11any later version.
12
13GNU Modula-2 is distributed in the hope that it will be useful, but
14WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16General Public License for more details.
17
18Under Section 7 of GPL version 3, you are granted additional
19permissions described in the GCC Runtime Library Exception, version
203.1, as published by the Free Software Foundation.
21
22You should have received a copy of the GNU General Public License and
23a copy of the GCC Runtime Library Exception along with this program;
24see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
25<http://www.gnu.org/licenses/>. */
26
27#include "config.h"
28#include "system.h"
29#include "ansi-decl.h"
30
31char *cgetopt_optarg;
32int cgetopt_optind;
33int cgetopt_opterr;
34int cgetopt_optopt;
35
36
37char
38cgetopt_getopt (int argc, char *argv[], char *optstring)
39{
40 char r = getopt (argc, argv, optstring);
41
42 cgetopt_optarg = optarg;
43 cgetopt_optind = optind;
44 cgetopt_opterr = opterr;
45 cgetopt_optopt = optopt;
46
47 if (r == (char)-1)
48 return (char)0;
49 return r;
50}
51
52
53int
54cgetopt_cgetopt_long (int argc, char *argv[], char *optstring, const struct option *longopts,
55 int *longindex)
56{
57 int r = cgetopt_long (argc, argv, optstring, longopts, longindex);
58
59 cgetopt_optarg = optarg;
60 cgetopt_optind = optind;
61 cgetopt_opterr = opterr;
62 cgetopt_optopt = optopt;
63
64 return r;
65}
66
67
68int
69cgetopt_cgetopt_long_only (int argc, char *argv[], char *optstring,
70 const struct option *longopts, int *longindex)
71{
72 int r = cgetopt_long_only (argc, argv, optstring, longopts, longindex);
73
74 cgetopt_optarg = optarg;
75 cgetopt_optind = optind;
76 cgetopt_opterr = opterr;
77 cgetopt_optopt = optopt;
78
79 return r;
80}
81
82
83typedef struct cgetopt_Options_s {
84 struct option *cinfo;
85 unsigned int high;
86} cgetopt_Options;
87
88
89/* InitOptions a constructor for Options. */
90
91cgetopt_Options *
92cgetopt_InitOptions (void)
93{
94 cgetopt_Options *o = (cgetopt_Options *) malloc (sizeof (cgetopt_Options));
95 o->cinfo = (struct option *) malloc (sizeof (struct option));
96 o->high = 0;
97 return o;
98}
99
100
101/* KillOptions a deconstructor for Options. Returns NULL after freeing
102 up all allocated memory associated with o. */
103
104cgetopt_Options *
105cgetopt_KillOptions (cgetopt_Options *o)
106{
107 free (o->cinfo);
108 free (o);
109 return NULL;
110}
111
112
113/* SetOption set option[index] with {name, has_arg, flag, val}. */
114
115void
116cgetopt_SetOption (cgetopt_Options *o, unsigned int index,
117 char *name, unsigned int has_arg,
118 int *flag, int val)
119{
120 if (index > o->high)
121 {
122 o->cinfo = (struct option *) malloc (sizeof (struct option) * (index + 1));
123 o->high = index + 1;
124 }
125 o->cinfo[index].name = name;
126 o->cinfo[index].has_arg = has_arg;
127 o->cinfo[index].flag = flag;
128 o->cinfo[index].val = val;
129}
130
131
132/* GetLongOptionArray returns a pointer to the C array containing all
133 long options. */
134
135struct option *
136cgetopt_GetLongOptionArray (cgetopt_Options *o)
137{
138 return o->cinfo;
139}
140
141
142/* GNU Modula-2 linking fodder. */
143
144void
145_M2_cgetopt_init (void)
146{
147}
148
149
150void
151_M2_cgetopt_finish (void)
152{
153}
This page took 0.06658 seconds and 5 git commands to generate.