]> Creatis software - clitk.git/blobdiff - utilities/gengetopt/yyerror.cc
Sync gengetopt cmake files with rtk
[clitk.git] / utilities / gengetopt / yyerror.cc
diff --git a/utilities/gengetopt/yyerror.cc b/utilities/gengetopt/yyerror.cc
new file mode 100644 (file)
index 0000000..ca06a2e
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+This file is licensed to you under the license specified in the included file
+`LICENSE'. Look there for further details.
+*/
+
+
+/*
+  Called by yyparse on error.
+ */
+
+#include "yyerror.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <iostream>
+
+extern int gengetopt_count_line;
+extern char * gengetopt_input_filename;
+
+extern int tokenpos;
+extern char linebuf[];
+extern char *yytext;
+
+using namespace std;
+
+void
+yyerror (const char *s)
+{
+  const char *source =
+    (gengetopt_input_filename ? gengetopt_input_filename : "gengetopt");
+
+  fprintf (stderr, "%s:%d: %s %s\n", source, gengetopt_count_line, s, yytext);
+
+  if (/*!linebuf || */!strlen(linebuf))
+    return;
+
+  fprintf (stderr, "%s:%d: %s\n", source, gengetopt_count_line, linebuf);
+  fprintf (stderr, "%s:%d: %*s\n", source, gengetopt_count_line,
+           tokenpos + 1, "^");
+}
+
+void
+yyerror (gengetopt_option *opt, const char *s)
+{
+  const char *source =
+    (opt->filename ? opt->filename : "gengetopt");
+
+  cerr << source << ":" << opt->linenum << ": " << s << endl;
+}