TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Extract URLs Relative and/or Absolute yy044

1 pointsby textmodeover 1 year ago
<p><pre><code> &#x2F;* experimental usage: [host=example.com] yy044 [ar] *&#x2F; int fileno (FILE *); int x,y,absolute,relative,omit,proto; int setenv (const char *, const char *, int); int fprintf(FILE *__restrict, const char *__restrict, ...); size_t strlen (const char *); http https:&#x2F;&#x2F;|http:&#x2F;&#x2F; js javascript: %option nounput noinput noyywrap %% href=[^{http}{js}\&quot;&#x27;][^\&quot;&#x27;\40&gt;]+ puts(&quot;yy044&quot;); href=[\&quot;&#x27;][^{http}{js}][^\&quot;&#x27;\40&gt;]+ { omit=0;proto=0; if(yytext[6]==46)omit++; if(yytext[7]==47)proto++; if(!omit)if(relative) { y=0;for(x=6;x&lt;yyleng;x++) { if(yytext[x]){yytext[y]=yytext[x];y++;}; } if(proto)fwrite(&quot;https:&quot;,1,6,yyout); if(!proto)if(getenv(&quot;host&quot;)||getenv(&quot;Host&quot;))fwrite(&quot;https:&#x2F;&#x2F;&quot;,1,8,yyout); if(!proto)if(getenv(&quot;host&quot;)){fwrite(getenv(&quot;host&quot;),1,strlen(getenv(&quot;host&quot;)),yyout);goto x;}; if(!proto)if(getenv(&quot;Host&quot;)){fwrite(getenv(&quot;Host&quot;),1,strlen(getenv(&quot;Host&quot;)),yyout);goto x;}; x: fwrite(yytext,1,yyleng-6,yyout); putc(10,stdout); } } &#x2F;* javascript:void(0) #blah *&#x2F; &quot;https:&#x2F;&#x2F;&quot;[^\40&lt;&gt;\43\42\47|\r\n]+ { if(absolute) if(yyleng&gt;8) { y=0;for(x=0;x&lt;yyleng;x++){if(yytext[x])yytext[y]=yytext[x];y++;}; fwrite(yytext,1,yyleng,yyout); putc(10,stdout); } } &quot;http:&#x2F;&#x2F;&quot;[^\40&lt;&gt;\43\42\47|\r\n]+ { if(absolute) if(yyleng&gt;7) { y=0;for(x=0;x&lt;yyleng;x++){if(yytext[x])yytext[y]=yytext[x];y++;}; fwrite(yytext,1,yyleng,yyout); putc(10,stdout); } } &#x2F;* href=https:&#x2F;&#x2F;x&#x2F;http:&#x2F;&#x2F; *&#x2F; .|\n %% int main(int argc,char* argv[]) { absolute++;relative++; if(argc)if(argv[1]) { if(argv[1][0]==97)relative--; if(argv[1][0]==114)absolute--; } yylex(); exit(0); }</code></pre>

1 comment

textmodeover 1 year ago
Normally I use yy030 but I have been experimenting with this instead.<p>Seems to be slightly faster and smaller than similar programs from html-xml-utils.<p><a href="https:&#x2F;&#x2F;www.w3.org&#x2F;Tools&#x2F;HTML-XML-utils&#x2F;man1&#x2F;" rel="nofollow noreferrer">https:&#x2F;&#x2F;www.w3.org&#x2F;Tools&#x2F;HTML-XML-utils&#x2F;man1&#x2F;</a><p>Compile:<p><pre><code> links -no-connect -dump https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=38727772 \ |sed &#x27;1,4d;77,$d;s&#x2F;[ ]\{6\}&#x2F;&#x2F;&#x27; \ |flex -8Cem;cc -O3 -std=c89 -W -Wall -pipe lex.yy.c -static -o yy044 strip -s yy044 </code></pre> Example usage:<p><pre><code> # NB. not a real cookie curl -H &quot;cookie=user=santa&amp;K7RGzmUtAoKv9OIRMfQ9bfwYpiDEuypp&quot; -siA &quot;&quot; \ https:&#x2F;&#x2F;news.ycombinator.com \ |host=news.ycombinator.com&#x2F; yy044 r \ |sed -n &#x27;s&#x2F;&amp;amp;&#x2F;\&amp;&#x2F;g;&#x2F;vote&#x2F;p&#x27;</code></pre>