Making HTTP clients for use with netcat-like programs, part 1 of 22 points·by textmode·5년 전·0 comments # make config parser (yy018) # source code for 018.l is below flex -8iCrfa 018.l; cc -Wall -std=c89 -static -o yy018 lex.yy.c; # create a config (ua.txt) # format is name: "value" # no indent, must be left-justified cat > ua.txt httpVersion="1.0" Host: "" Connection: "close" User-Agent: "CERN-LineMode/2.15 libwww/2.17b3" ^D save as "018.l" int setenv (const char *, const char *, int); int fileno(FILE *); #define jmp (yy_start) = 1 + 2 * #define X(x) fputs(x,stdout) #define Y(x,y) fprintf(stdout,x,y) #define Y2(x,y) fprintf(stderr,x,y) int xxyy() { setenv("value",yytext,1); Y("\40\40\40if(0==setenv(\"%s\",",getenv("name")); Y("%s,0))",getenv("value")); Y("Y(\"%s: %%s\\r\\n\",",getenv("name")); Y("getenv(\"%s\"));\n",getenv("name")); return 0; } int lineno=1; %option noinput nounput noyywrap %s xa xc %% \n lineno++; ^[\40\11]+ { Y2("yy018: error: remove %d ",yyleng); Y2("leading spaces/tabs from line %d\n",lineno); yyterminate(); } ^"Host"[: ] setenv("name","Host",1);jmp xc; ^[^\40\11\":\n]* setenv("name",yytext,1);jmp xa; <xa>[\"][^\"]*[\"] { if(yyleng>2)xxyy(); else if(yyleng==2&&yytext[0]=='\"'&&yytext[1]=='\"') { setenv("value",yytext,1); Y("\40\40\40if(getenv(\"%s\"))",getenv("name")); Y("Y(\"%s: %%s\\r\\n\",",getenv("name")); Y("getenv(\"%s\"));\n",getenv("name")); };} <xc>[\"][^\"]*[\"] xxyy(); \n|. %% int main(){yylex();return 0;}0 commentsPost comment—