diff options
author | Taru Karttunen <taruti@taruti.net> | 2011-03-30 15:46:40 +0300 |
---|---|---|
committer | Taru Karttunen <taruti@taruti.net> | 2011-03-30 15:46:40 +0300 |
commit | e5888a1ffdae813d7575f5fb02275c6bb07e5199 (patch) | |
tree | d8d51eac403f07814b9e936eed0c9a79195e2450 /sys/src/ape/lib/l |
Import sources from 2011-03-30 iso image
Diffstat (limited to 'sys/src/ape/lib/l')
-rwxr-xr-x | sys/src/ape/lib/l/allprint.c | 38 | ||||
-rwxr-xr-x | sys/src/ape/lib/l/main.c | 12 | ||||
-rwxr-xr-x | sys/src/ape/lib/l/mkfile | 13 | ||||
-rwxr-xr-x | sys/src/ape/lib/l/reject.c | 57 | ||||
-rwxr-xr-x | sys/src/ape/lib/l/yyless.c | 26 | ||||
-rwxr-xr-x | sys/src/ape/lib/l/yywrap.c | 8 |
6 files changed, 154 insertions, 0 deletions
diff --git a/sys/src/ape/lib/l/allprint.c b/sys/src/ape/lib/l/allprint.c new file mode 100755 index 000000000..c0e8296be --- /dev/null +++ b/sys/src/ape/lib/l/allprint.c @@ -0,0 +1,38 @@ +#include <libl.h> +#include <stdio.h> + +extern FILE* yyout; + +int +printable(int c) +{ + return 040 < c && c < 0177; +} + +void +allprint(char c) +{ + + switch(c) { + case '\n': + fprintf(yyout,"\\n"); + break; + case '\t': + fprintf(yyout,"\\t"); + break; + case '\b': + fprintf(yyout,"\\b"); + break; + case ' ': + fprintf(yyout,"\\\bb"); + break; + default: + if(!printable(c)) + fprintf(yyout,"\\%-3o",c); + else + c = putc(c,yyout); + USED(c); + break; + } + return; +} diff --git a/sys/src/ape/lib/l/main.c b/sys/src/ape/lib/l/main.c new file mode 100755 index 000000000..48025e334 --- /dev/null +++ b/sys/src/ape/lib/l/main.c @@ -0,0 +1,12 @@ +#include <libl.h> +#include <stdlib.h> + +int yylex(void); + +void +main(int argc, char *argv[]) +{ + USED(argc); + yylex(); + exit(0); +} diff --git a/sys/src/ape/lib/l/mkfile b/sys/src/ape/lib/l/mkfile new file mode 100755 index 000000000..15c1e5c4a --- /dev/null +++ b/sys/src/ape/lib/l/mkfile @@ -0,0 +1,13 @@ +APE=/sys/src/ape +<$APE/config + +LIB=/$objtype/lib/ape/libl.a +OFILES=allprint.$O\ + main.$O\ + reject.$O\ + yyless.$O\ + yywrap.$O\ + +</sys/src/cmd/mksyslib + +CFLAGS=-c -D_RESEARCH_SOURCE diff --git a/sys/src/ape/lib/l/reject.c b/sys/src/ape/lib/l/reject.c new file mode 100755 index 000000000..0b2aa7c5d --- /dev/null +++ b/sys/src/ape/lib/l/reject.c @@ -0,0 +1,57 @@ +#include <libl.h> +#include <stdio.h> + +extern FILE* yyout; +extern FILE* yyin; +extern int yyprevious, *yyfnd; +extern char yyextra[]; +extern char yytext[]; +extern int yyleng; + +extern +struct +{ + int *yyaa, *yybb; + int *yystops; +} *yylstate [], **yylsp, **yyolsp; + +int yyback(int *p, int m); +int yyinput(void); +void yyoutput(int c); +void yyunput(int c); + +int +yyracc(int m) +{ + + yyolsp = yylsp; + if(yyextra[m]) { + while(yyback((*yylsp)->yystops, -m) != 1 && yylsp > yylstate) { + yylsp--; + yyunput(yytext[--yyleng]); + } + } + yyprevious = yytext[yyleng-1]; + yytext[yyleng] = 0; + return m; +} + +int +yyreject(void) +{ + for(; yylsp < yyolsp; yylsp++) + yytext[yyleng++] = yyinput(); + if(*yyfnd > 0) + return yyracc(*yyfnd++); + while(yylsp-- > yylstate) { + yyunput(yytext[yyleng-1]); + yytext[--yyleng] = 0; + if(*yylsp != 0 && (yyfnd = (*yylsp)->yystops) && *yyfnd > 0) + return yyracc(*yyfnd++); + } + if(yytext[0] == 0) + return 0; + yyoutput(yyprevious = yyinput()); + yyleng = 0; + return -1; +} diff --git a/sys/src/ape/lib/l/yyless.c b/sys/src/ape/lib/l/yyless.c new file mode 100755 index 000000000..9367919f3 --- /dev/null +++ b/sys/src/ape/lib/l/yyless.c @@ -0,0 +1,26 @@ +#include <libl.h> +#include <stdio.h> + +extern char yytext[]; +extern int yyleng; +extern int yyprevious; + +void yyunput(int c); + +void +yyless(int x) +{ + char *lastch, *ptr; + + lastch = yytext+yyleng; + if(x>=0 && x <= yyleng) + ptr = x + yytext; + else + ptr = (char*)x; + while(lastch > ptr) + yyunput(*--lastch); + *lastch = 0; + if (ptr >yytext) + yyprevious = *--lastch; + yyleng = ptr-yytext; +} diff --git a/sys/src/ape/lib/l/yywrap.c b/sys/src/ape/lib/l/yywrap.c new file mode 100755 index 000000000..772ee0ae5 --- /dev/null +++ b/sys/src/ape/lib/l/yywrap.c @@ -0,0 +1,8 @@ +#include <libl.h> +#include <stdio.h> + +int +yywrap(void) +{ + return 1; +} |