-/* Generated by re2c 0.14.3 on Wed Jul 29 12:29:18 2015 */
+/* Generated by re2c 0.14.3 on Wed Jul 29 14:24:46 2015 */
#include <stdio.h>
#include "src/conf/msg.h"
namespace re2c
{
-parse_opts_t parse_opts (int argc, char ** argv, Opt & opts)
+static inline bool next (char * & arg, char ** & argv)
{
- if (argc == 1)
- {
- usage ();
- return EXIT_FAIL;
- }
+ arg = *++argv;
+ return arg != NULL;
+}
+parse_opts_t parse_opts (char ** argv, Opt & opts)
+{
#define YYCTYPE char
YYCTYPE * YYCURSOR;
YYCTYPE * YYMARKER;
opt:
- YYCURSOR = *++argv;
- if (YYCURSOR == NULL)
+ if (!next (YYCURSOR, argv))
{
goto end;
}
// all remaining arguments are non-options
// so they must be input files
// re2c expects exactly one input file
- for (const char * f = *++argv; f; f = *++argv)
+ for (char * f; next (f, argv);)
{
if (!opts.source (f))
{
yy137:
++YYCURSOR;
if ((yych = *YYCURSOR) <= 0x00) goto yy155;
- { *argv = YYCURSOR; goto opt_output; }
+ { *argv = YYCURSOR; goto opt_output; }
yy139:
++YYCURSOR;
{ opts.reusable (); goto opt_short; }
yy143:
++YYCURSOR;
if ((yych = *YYCURSOR) <= 0x00) goto yy153;
- { *argv = YYCURSOR; goto opt_header; }
+ { *argv = YYCURSOR; goto opt_header; }
yy145:
++YYCURSOR;
{ if (!opts.unicode ()) { error_encoding (); return EXIT_FAIL; } goto opt_short; }
{ if (!opts.utf_16 ()) { error_encoding (); return EXIT_FAIL; } goto opt_short; }
yy153:
++YYCURSOR;
- { YYCURSOR = *++argv; goto opt_header; }
+ { if (!next (YYCURSOR, argv)) { error_arg ("-t, --type-header"); return EXIT_FAIL; } goto opt_header; }
yy155:
++YYCURSOR;
- { YYCURSOR = *++argv; goto opt_output; }
+ { if (!next (YYCURSOR, argv)) { error_arg ("-o, --output"); return EXIT_FAIL; } goto opt_output; }
}
yych = *++YYCURSOR;
if (yych >= 0x01) goto yy177;
++YYCURSOR;
- { YYCURSOR = *++argv; goto opt_header; }
+ { if (!next (YYCURSOR, argv)) { error_arg ("-t, --type-header"); return EXIT_FAIL; } goto opt_header; }
yy231:
yych = *++YYCURSOR;
if (yych == 'n') goto yy272;
yych = *++YYCURSOR;
if (yych >= 0x01) goto yy177;
++YYCURSOR;
- { YYCURSOR = *++argv; goto opt_output; }
+ { if (!next (YYCURSOR, argv)) { error_arg ("-o, --output"); return EXIT_FAIL; } goto opt_output; }
yy299:
yych = *++YYCURSOR;
if (yych == '-') goto yy311;
opt_encoding_policy:
- YYCURSOR = *++argv;
+ if (!next (YYCURSOR, argv))
+ {
+ error_arg ("--encoding-policy");
+ return EXIT_FAIL;
+ }
{
YYCTYPE yych;
opt_input:
- YYCURSOR = *++argv;
+ if (!next (YYCURSOR, argv))
+ {
+ error_arg ("--input");
+ return EXIT_FAIL;
+ }
{
YYCTYPE yych;
opt_empty_class:
- YYCURSOR = *++argv;
+ if (!next (YYCURSOR, argv))
+ {
+ error_arg ("--empty-class");
+ return EXIT_FAIL;
+ }
{
YYCTYPE yych;
error ("only one of switches -e, -w, -x, -u and -8 must be set");
}
+void error_arg (const char * option)
+{
+ error ("expected argument to option %s", option);
+}
+
void warning (const char * type, uint32_t line, bool error, const char * fmt, ...)
{
static const char * msg = error ? "error" : "warning";
void error (const char * fmt, ...) RE2C_GXX_ATTRIBUTE ((format (printf, 1, 2)));
void error_encoding ();
+void error_arg (const char * option);
void warning (const char * type, uint32_t line, bool error, const char * fmt, ...) RE2C_GXX_ATTRIBUTE ((format (printf, 4, 5)));
void usage ();
void vernum ();
EXIT_FAIL
};
-parse_opts_t parse_opts (int argc, char ** argv, Opt & opts);
+parse_opts_t parse_opts (char ** argv, Opt & opts);
} // namespace re2c
namespace re2c
{
-parse_opts_t parse_opts (int argc, char ** argv, Opt & opts)
+static inline bool next (char * & arg, char ** & argv)
{
- if (argc == 1)
- {
- usage ();
- return EXIT_FAIL;
- }
+ arg = *++argv;
+ return arg != NULL;
+}
+parse_opts_t parse_opts (char ** argv, Opt & opts)
+{
#define YYCTYPE char
YYCTYPE * YYCURSOR;
YYCTYPE * YYMARKER;
*/
opt:
- YYCURSOR = *++argv;
- if (YYCURSOR == NULL)
+ if (!next (YYCURSOR, argv))
{
goto end;
}
// all remaining arguments are non-options
// so they must be input files
// re2c expects exactly one input file
- for (const char * f = *++argv; f; f = *++argv)
+ for (char * f; next (f, argv);)
{
if (!opts.source (f))
{
"w" { if (!opts.wide_chars ()) { error_encoding (); return EXIT_FAIL; } goto opt_short; }
"x" { if (!opts.utf_16 ()) { error_encoding (); return EXIT_FAIL; } goto opt_short; }
"8" { if (!opts.utf_8 ()) { error_encoding (); return EXIT_FAIL; } goto opt_short; }
- "o" end { YYCURSOR = *++argv; goto opt_output; }
- "o" { *argv = YYCURSOR; goto opt_output; }
- "t" end { YYCURSOR = *++argv; goto opt_header; }
- "t" { *argv = YYCURSOR; goto opt_header; }
+ "o" end { if (!next (YYCURSOR, argv)) { error_arg ("-o, --output"); return EXIT_FAIL; } goto opt_output; }
+ "o" { *argv = YYCURSOR; goto opt_output; }
+ "t" end { if (!next (YYCURSOR, argv)) { error_arg ("-t, --type-header"); return EXIT_FAIL; } goto opt_header; }
+ "t" { *argv = YYCURSOR; goto opt_header; }
"1" { goto opt_short; } // deprecated
*/
"wide-chars" end { if (!opts.wide_chars ()) { error_encoding (); return EXIT_FAIL; } goto opt; }
"utf-16" end { if (!opts.utf_16 ()) { error_encoding (); return EXIT_FAIL; } goto opt; }
"utf-8" end { if (!opts.utf_8 ()) { error_encoding (); return EXIT_FAIL; } goto opt; }
- "output" end { YYCURSOR = *++argv; goto opt_output; }
- "type-header" end { YYCURSOR = *++argv; goto opt_header; }
+ "output" end { if (!next (YYCURSOR, argv)) { error_arg ("-o, --output"); return EXIT_FAIL; } goto opt_output; }
+ "type-header" end { if (!next (YYCURSOR, argv)) { error_arg ("-t, --type-header"); return EXIT_FAIL; } goto opt_header; }
"encoding-policy" end { goto opt_encoding_policy; }
"input" end { goto opt_input; }
"empty-class" end { goto opt_empty_class; }
*/
opt_encoding_policy:
- YYCURSOR = *++argv;
+ if (!next (YYCURSOR, argv))
+ {
+ error_arg ("--encoding-policy");
+ return EXIT_FAIL;
+ }
/*!re2c
*
{
*/
opt_input:
- YYCURSOR = *++argv;
+ if (!next (YYCURSOR, argv))
+ {
+ error_arg ("--input");
+ return EXIT_FAIL;
+ }
/*!re2c
*
{
*/
opt_empty_class:
- YYCURSOR = *++argv;
+ if (!next (YYCURSOR, argv))
+ {
+ error_arg ("--empty-class");
+ return EXIT_FAIL;
+ }
/*!re2c
*
{
using namespace re2c;
-int main(int argc, char *argv[])
+int main(int, char *argv[])
{
Opt opts;
- switch (parse_opts (argc, argv, opts))
+ switch (parse_opts (argv, opts))
{
case OK: break;
case EXIT_OK: return 0;