Skip to content
This repository has been archived by the owner on Jul 26, 2018. It is now read-only.

Commit

Permalink
Merge pull request #14 from tokuhirom/ansi-c
Browse files Browse the repository at this point in the history
Make the code as ANSI C compliant.
  • Loading branch information
nddrylliog committed Aug 4, 2013
2 parents 5c08455 + 68e5543 commit 6314594
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
30 changes: 15 additions & 15 deletions compile.c
Expand Up @@ -80,38 +80,38 @@ static char *yyqq(char* s) {
int sl = 0, dl = 0;
while (*s++) {
dl++; sl++;
if (*s==7||*s==8||*s==9||*s==11||*s==12||*s==13||*s==27||*s==34||*s=='%'||*s==92) { dl++; } // escape with '\'
else if (*s==10) { dl += 3; } // \n\^J
else if (*(signed char*)s<32) { dl += 4; } // octal \000
if (*s==7||*s==8||*s==9||*s==11||*s==12||*s==13||*s==27||*s==34||*s=='%'||*s==92) { dl++; } /* escape with '\' */
else if (*s==10) { dl += 3; } /* \n\^J */
else if (*(signed char*)s<32) { dl += 4; } /* octal \000 */
}
if (dl == sl) return d;
s = d;
dst = d = (char *)malloc(dl+1);
while (*s) {
if (*s == '"') {
*d++ = '\\'; *d++ = *s++;
} else if (*s == '%') { // '%' in printf
} else if (*s == '%') { /* '%' in printf */
*d++ = '%'; *d++ = *s++;
} else if (*s == '\n') { // \n\^J
} else if (*s == '\n') { /* \n\^J */
*d++ = '\\'; *d++ = 'n'; *d++ = '\\'; *d++ = 10; s++;
} else if (*s == '\t') { //ht
} else if (*s == '\t') { /* ht */
*d++ = '\\'; *d++ = 't'; s++;
} else if (*s == '\r') { //cr
} else if (*s == '\r') { /*cr */
*d++ = '\\'; *d++ = 'r'; s++;
} else if (*s == '\a') { //bel
} else if (*s == '\a') { /*bel*/
*d++ = '\\'; *d++ = 'a'; s++;
} else if (*s == '\b') { //bs
} else if (*s == '\b') { /*bs*/
*d++ = '\\'; *d++ = 'b'; s++;
} else if (*s == '\e') { //esc
} else if (*s == '\e') { /*esc*/
*d++ = '\\'; *d++ = 'e'; s++;
} else if (*s == '\f') { //ff
} else if (*s == '\f') { /*ff*/
*d++ = '\\'; *d++ = 'f'; s++;
} else if (*s == '\v') { //vt
} else if (*s == '\v') { /*vt*/
*d++ = '\\'; *d++ = 'v'; s++;
} else if (*s == 92) { // '\'
} else if (*s == 92) { /* '\' */
*d++ = '\\'; *d++ = *s++;
} else if (*(signed char*)s<32) {
sprintf(d,"\\%03o", *s); // octal \000
sprintf(d,"\\%03o", *s); /* octal \000 */
d += 4; s++;
} else {
*d++ = *s++;
Expand Down Expand Up @@ -511,7 +511,7 @@ static const char *preamble= "\
#define yydata G->data\n\
#define yy G->ss\n\
\n\
struct _yythunk; // forward declaration\n\
struct _yythunk; /* forward declaration */\n\
typedef void (*yyaction)(struct _GREG *G, char *yytext, int yyleng, struct _yythunk *thunkpos, YY_XTYPE YY_XVAR);\n\
typedef struct _yythunk { int begin, end; yyaction action; const char *name; struct _yythunk *next; } yythunk;\n\
\n\
Expand Down
2 changes: 1 addition & 1 deletion greg.c
Expand Up @@ -128,7 +128,7 @@ struct _GREG;
#define yydata G->data
#define yy G->ss

struct _yythunk; // forward declaration
struct _yythunk; /* forward declaration */
typedef void (*yyaction)(struct _GREG *G, char *yytext, int yyleng, struct _yythunk *thunkpos, YY_XTYPE YY_XVAR);
typedef struct _yythunk { int begin, end; yyaction action; const char *name; struct _yythunk *next; } yythunk;

Expand Down
11 changes: 10 additions & 1 deletion tree.c
Expand Up @@ -34,7 +34,16 @@ int actionCount= 0;
int ruleCount= 0;
int lastToken= -1;

static inline Node *_newNode(int type, int size)
#ifndef STATIC_INLINE
# if defined(__GNUC__) || defined(__cplusplus) || (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L))
/* # define STATIC_INLINE static inline */
# define STATIC_INLINE static
# else
# define STATIC_INLINE static
# endif
#endif /* STATIC_INLINE */

STATIC_INLINE Node *_newNode(int type, int size)
{
Node *node= (Node*)calloc(1, size);
node->type= type;
Expand Down

0 comments on commit 6314594

Please sign in to comment.