Skip to content

Commit

Permalink
reorder function/global variable declarations in tc.c
Browse files Browse the repository at this point in the history
  • Loading branch information
dongyx committed May 6, 2022
1 parent 00fc80c commit 8d5dcc1
Showing 1 changed file with 39 additions and 38 deletions.
77 changes: 39 additions & 38 deletions tc.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#include <stdio.h>

#define TOKSIZ 8

enum error { ESYS = 1, ESYNTAX };
enum state { SERR, SINIT, STXT, SCMD, SEXP, STERM };
enum token {
OPENCMD, /* <% */
OPENEXP, /* <%= */
Expand All @@ -15,7 +15,7 @@ enum token {
TXT, /* text */
END /* EOF */
};

enum state { SERR, SINIT, STXT, SCMD, SEXP, STERM };
enum state sttab[][8] = {
/* in/st ERR INIT TXT CMD EXP TERM */

Expand All @@ -28,15 +28,14 @@ enum state sttab[][8] = {
/* TXT */ { SERR, STXT, STXT, SCMD, SEXP, SERR },
/* END */ { SERR, STERM, STERM, SERR, SERR, SERR }
};

void entrtxt(enum state from, enum token in);
void entrcmd(enum state from, enum token in);
void entrexp(enum state from, enum token in);
void entrerr(enum state from, enum token in);
void exittxt(enum state to, enum token in);
void exitcmd(enum state to, enum token in);
void exitexp(enum state to, enum token in);

void trim(void);
void (*entrtab[])(enum state, enum token) = {
&entrerr, NULL, &entrtxt, &entrcmd, &entrexp, NULL
};
Expand All @@ -45,11 +44,15 @@ void (*exittab[])(enum state, enum token) = {
};

int cstack[TOKSIZ], cssize;
int popc(void);
int pushc(int c);

char token[TOKSIZ];
enum token gettok(void);
int dryread(char *s);

main()
{
enum token gettok();
enum state st, next;
enum token in;

Expand Down Expand Up @@ -115,14 +118,6 @@ void exittxt(enum state to, enum token in)
puts("'");
}

void trim(void)
{
fputs(
"|awk " "'NR>1{print p}{p=$0}END{printf(\"%s\",p)}'",
stdout
);
}

void exitcmd(enum state to, enum token in)
{
if (to == SCMD)
Expand All @@ -142,32 +137,10 @@ void exitexp(enum state to, enum token in)
putchar('\n');
}

pushc(int c)
{
return cstack[cssize++] = c;
}

popc(void)
void trim(void)
{
return cssize > 0 ? cstack[--cssize] : getchar();
}

dryread(char *s)
{
char *p, c;
int ret;

ret = 1;
p = s;
while (*p && (c = popc()) == *p)
p++;
if (*p) {
ret = 0;
pushc(c);
}
while (p != s)
pushc(*--p);
return ret;
fputs("|awk 'NR>1{print p}{p=$0}END{printf(\"%s\",p)}'",
stdout);
}

enum token gettok(void)
Expand Down Expand Up @@ -197,3 +170,31 @@ enum token gettok(void)
token[1] = '\0';
return token[0] == EOF ? END : TXT;
}

int pushc(int c)
{
return cstack[cssize++] = c;
}

int popc(void)
{
return cssize > 0 ? cstack[--cssize] : getchar();
}

int dryread(char *s)
{
char *p, c;
int ret;

ret = 1;
p = s;
while (*p && (c = popc()) == *p)
p++;
if (*p) {
ret = 0;
pushc(c);
}
while (p != s)
pushc(*--p);
return ret;
}

0 comments on commit 8d5dcc1

Please sign in to comment.