Making single-purpose utilities example: filter URLs from input

https://news.ycombinator.com/item?id=20120264
by textmode • 7 years ago
1 4 7 years ago
    /* ---
    Made for use with http clients as described in https://news.ycombinator.com/item?id=17689165 and https://news.ycombinator.com/item?id=17689152
    Assuming code below is saved as "030.l", one might compile program "yy030" with something like:
     flex -8iCrfa 030.l
     cc -pipe lex.yy.c -static -o yy030
     --- */


     #define p(x) fprintf(stdout,x,yytext);
     #define jmp BEGIN
    %s xa xb xc
     int e,b,c;
    xa "http://"|"https://"|"ftp://"
    %%
     /* non-printable */
    \200|\201|\204|\223|\224|\230|\231|\234|\235

    {xa} p("%s");jmp xa;
    <xa>[^ \n\r<>"#'|)\]\}]* p("%s\n");jmp 0;

     /* http:\/\/[^ \n\r<>"#'|]*    fprintf(stdout,"%s\n",yytext); */
     /* https:\/\/[^ \n\r<>"#'|]*    fprintf(stdout,"%s\n",yytext); */
     /* ftp:\/\/[^ \n\r<>"#'|]*    fprintf(stdout,"%s\n",yytext); */
    .|\n
    %%
    int main(){ yylex();}
    int yywrap()
    {
    }

Related Stories

Loading related stories...

Source preview

news.ycombinator.com