ref: c14d7f600d8c1d7c32221cf212f2f78acf970a5b
parent: e559f65d881492fe5acd291e206fbd3e9d8f9ede
author: Andrew Chambers <ac@acha.ninja>
date: Sun Apr 10 09:13:43 CDT 2022
Fix various compiler warnings, add YY_MAYBE_UNUSED.
--- a/compile.c
+++ b/compile.c
@@ -389,6 +389,9 @@
"#include <string.h>\n";
static char *preamble= "\
+#ifndef YY_MAYBE_UNUSED\n\
+#define YY_MAYBE_UNUSED __attribute__((unused))\n\
+#endif\n\
#ifndef YY_MALLOC\n\
#define YY_MALLOC(C, N) malloc(N)\n\
#endif\n\
@@ -499,7 +502,7 @@
#endif\n\
#endif\n\
\n\
-YY_LOCAL(int) yyrefill(yycontext *yy)\n\
+YY_LOCAL(int) YY_MAYBE_UNUSED yyrefill(yycontext *yy)\n\
{\n\
int yyn;\n\
while (yy->__buflen - yy->__pos < 512)\n\
@@ -517,7 +520,7 @@
return 1;\n\
}\n\
\n\
-YY_LOCAL(int) yymatchDot(yycontext *yy)\n\
+YY_LOCAL(int) YY_MAYBE_UNUSED yymatchDot(yycontext *yy)\n\
{\n\
if (yy->__pos >= yy->__limit && !yyrefill(yy)) return 0;\n\
++yy->__pos;\n\
@@ -524,7 +527,7 @@
return 1;\n\
}\n\
\n\
-YY_LOCAL(int) yymatchChar(yycontext *yy, int c)\n\
+YY_LOCAL(int) YY_MAYBE_UNUSED yymatchChar(yycontext *yy, int c)\n\
{\n\
if (yy->__pos >= yy->__limit && !yyrefill(yy)) return 0;\n\
if ((unsigned char)yy->__buf[yy->__pos] == c)\n\
@@ -537,7 +540,7 @@
return 0;\n\
}\n\
\n\
-YY_LOCAL(int) yymatchString(yycontext *yy, const char *s)\n\
+YY_LOCAL(int) YY_MAYBE_UNUSED yymatchString(yycontext *yy, const char *s)\n\
{\n\
int yysav= yy->__pos;\n\
while (*s)\n\
@@ -554,7 +557,7 @@
return 1;\n\
}\n\
\n\
-YY_LOCAL(int) yymatchClass(yycontext *yy, unsigned char *bits)\n\
+YY_LOCAL(int) YY_MAYBE_UNUSED yymatchClass(yycontext *yy, unsigned char *bits)\n\
{\n\
int c;\n\
if (yy->__pos >= yy->__limit && !yyrefill(yy)) return 0;\n\
@@ -569,7 +572,7 @@
return 0;\n\
}\n\
\n\
-YY_LOCAL(void) yyDo(yycontext *yy, yyaction action, int begin, int end)\n\
+YY_LOCAL(void) YY_MAYBE_UNUSED yyDo(yycontext *yy, yyaction action, int begin, int end)\n\
{\n\
while (yy->__thunkpos >= yy->__thunkslen)\n\
{\n\
@@ -582,7 +585,7 @@
++yy->__thunkpos;\n\
}\n\
\n\
-YY_LOCAL(int) yyText(yycontext *yy, int begin, int end)\n\
+YY_LOCAL(int) YY_MAYBE_UNUSED yyText(yycontext *yy, int begin, int end)\n\
{\n\
int yyleng= end - begin;\n\
if (yyleng <= 0)\n\
@@ -624,7 +627,7 @@
yy->__pos= yy->__thunkpos= 0;\n\
}\n\
\n\
-YY_LOCAL(int) yyAccept(yycontext *yy, int tp0)\n\
+YY_LOCAL(int) YY_MAYBE_UNUSED yyAccept(yycontext *yy, int tp0)\n\
{\n\
if (tp0)\n\
{\n\
@@ -639,7 +642,7 @@
return 1;\n\
}\n\
\n\
-YY_LOCAL(void) yyPush(yycontext *yy, char *text, int count)\n\
+YY_LOCAL(void) YY_MAYBE_UNUSED yyPush(yycontext *yy, char *text, int count)\n\
{\n\
yy->__val += count;\n\
while (yy->__valslen <= yy->__val - yy->__vals)\n\
@@ -650,12 +653,12 @@
yy->__val= yy->__vals + offset;\n\
}\n\
}\n\
-YY_LOCAL(void) yyPop(yycontext *yy, char *text, int count) { yy->__val -= count; }\n\
-YY_LOCAL(void) yySet(yycontext *yy, char *text, int count) { yy->__val[count]= yy->__; }\n\
+YY_LOCAL(void) YY_MAYBE_UNUSED yyPop(yycontext *yy, char *text, int count) { yy->__val -= count; }\n\
+YY_LOCAL(void) YY_MAYBE_UNUSED yySet(yycontext *yy, char *text, int count) { yy->__val[count]= yy->__; }\n\
\n\
#endif /* YY_PART */\n\
\n\
-#define YYACCEPT yyAccept(yy, yythunkpos0)\n\
+#define YYACCEPT yyAccept(yy, yythunkpos0)\n\
\n\
";
--- a/examples/basic.peg
+++ b/examples/basic.peg
@@ -109,7 +109,7 @@
| 'save'- s:string { save(s.string); }
| 'load'- s:string { load(s.string); }
| 'type'- s:string { type(s.string); }
-| 'dir'- { system("ls *.bas"); }
+| 'dir'- { if (system("ls *.bas")) fprintf(stderr, "dir failed\n") }
| 'help'- { fprintf(stderr, "%s", help); }
expr-list = ( e:string { printf("%s", e.string); }
@@ -327,10 +327,12 @@
else
{
int c, d;
+ c = d = 0;
while ((c= getc(f)) >= 0)
- putchar(d= c);
+ putchar(d= c);
fclose(f);
- if ('\n' != d && '\r' != d) putchar('\n');
+ if ('\n' != d && '\r' != d)
+ putchar('\n');
}
}
@@ -337,7 +339,8 @@
int input(void)
{
char line[32];
- fgets(line, sizeof(line), stdin);
+ if (!fgets(line, sizeof(line), stdin))
+ return 0;
return atoi(line);
}
--- a/peg.c
+++ b/peg.c
@@ -52,6 +52,9 @@
# define YY_LOCAL(T) static T
# define YY_RULE(T) static T
+#ifndef YY_MAYBE_UNUSED
+#define YY_MAYBE_UNUSED __attribute__((unused))
+#endif
#ifndef YY_MALLOC
#define YY_MALLOC(C, N) malloc(N)
#endif
@@ -162,7 +165,7 @@
#endif
#endif
-YY_LOCAL(int) yyrefill(yycontext *yy)
+YY_LOCAL(int) YY_MAYBE_UNUSED yyrefill(yycontext *yy)
{
int yyn;
while (yy->__buflen - yy->__pos < 512)
@@ -180,7 +183,7 @@
return 1;
}
-YY_LOCAL(int) yymatchDot(yycontext *yy)
+YY_LOCAL(int) YY_MAYBE_UNUSED yymatchDot(yycontext *yy)
{
if (yy->__pos >= yy->__limit && !yyrefill(yy)) return 0;
++yy->__pos;
@@ -187,7 +190,7 @@
return 1;
}
-YY_LOCAL(int) yymatchChar(yycontext *yy, int c)
+YY_LOCAL(int) YY_MAYBE_UNUSED yymatchChar(yycontext *yy, int c)
{
if (yy->__pos >= yy->__limit && !yyrefill(yy)) return 0;
if ((unsigned char)yy->__buf[yy->__pos] == c)
@@ -200,7 +203,7 @@
return 0;
}
-YY_LOCAL(int) yymatchString(yycontext *yy, const char *s)
+YY_LOCAL(int) YY_MAYBE_UNUSED yymatchString(yycontext *yy, const char *s)
{
int yysav= yy->__pos;
while (*s)
@@ -217,7 +220,7 @@
return 1;
}
-YY_LOCAL(int) yymatchClass(yycontext *yy, unsigned char *bits)
+YY_LOCAL(int) YY_MAYBE_UNUSED yymatchClass(yycontext *yy, unsigned char *bits)
{
int c;
if (yy->__pos >= yy->__limit && !yyrefill(yy)) return 0;
@@ -232,7 +235,7 @@
return 0;
}
-YY_LOCAL(void) yyDo(yycontext *yy, yyaction action, int begin, int end)
+YY_LOCAL(void) YY_MAYBE_UNUSED yyDo(yycontext *yy, yyaction action, int begin, int end)
{
while (yy->__thunkpos >= yy->__thunkslen)
{
@@ -245,7 +248,7 @@
++yy->__thunkpos;
}
-YY_LOCAL(int) yyText(yycontext *yy, int begin, int end)
+YY_LOCAL(int) YY_MAYBE_UNUSED yyText(yycontext *yy, int begin, int end)
{
int yyleng= end - begin;
if (yyleng <= 0)
@@ -287,7 +290,7 @@
yy->__pos= yy->__thunkpos= 0;
}
-YY_LOCAL(int) yyAccept(yycontext *yy, int tp0)
+YY_LOCAL(int) YY_MAYBE_UNUSED yyAccept(yycontext *yy, int tp0)
{
if (tp0)
{
@@ -302,7 +305,7 @@
return 1;
}
-YY_LOCAL(void) yyPush(yycontext *yy, char *text, int count)
+YY_LOCAL(void) YY_MAYBE_UNUSED yyPush(yycontext *yy, char *text, int count)
{
yy->__val += count;
while (yy->__valslen <= yy->__val - yy->__vals)
@@ -313,12 +316,12 @@
yy->__val= yy->__vals + offset;
}
}
-YY_LOCAL(void) yyPop(yycontext *yy, char *text, int count) { yy->__val -= count; }
-YY_LOCAL(void) yySet(yycontext *yy, char *text, int count) { yy->__val[count]= yy->__; }
+YY_LOCAL(void) YY_MAYBE_UNUSED yyPop(yycontext *yy, char *text, int count) { yy->__val -= count; }
+YY_LOCAL(void) YY_MAYBE_UNUSED yySet(yycontext *yy, char *text, int count) { yy->__val[count]= yy->__; }
#endif /* YY_PART */
-#define YYACCEPT yyAccept(yy, yythunkpos0)
+#define YYACCEPT yyAccept(yy, yythunkpos0)
YY_RULE(int) yy_comment(yycontext *yy); /* 39 */
YY_RULE(int) yy_space(yycontext *yy); /* 38 */