ZealOS/docs/Home/Net/Programs/Gopher.ZC.html
2021-12-11 06:10:58 -05:00

368 lines
34 KiB
HTML
Executable file

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=US-ASCII">
<meta name="generator" content="ZealOS V1.07">
<style type="text/css">
body {background-color:#1f1f1f;}
.cF0{color:#e3e3e3;background-color:#1f1f1f;}
.cF1{color:#4f84a6;background-color:#1f1f1f;}
.cF2{color:#73a255;background-color:#1f1f1f;}
.cF3{color:#297582;background-color:#1f1f1f;}
.cF4{color:#b34f4b;background-color:#1f1f1f;}
.cF5{color:#8a52c3;background-color:#1f1f1f;}
.cF6{color:#b7822f;background-color:#1f1f1f;}
.cF7{color:#444444;background-color:#1f1f1f;}
.cF8{color:#6d6d6d;background-color:#1f1f1f;}
.cF9{color:#94bfde;background-color:#1f1f1f;}
.cFA{color:#a1ce97;background-color:#1f1f1f;}
.cFB{color:#6db4be;background-color:#1f1f1f;}
.cFC{color:#e88e88;background-color:#1f1f1f;}
.cFD{color:#ca94e8;background-color:#1f1f1f;}
.cFE{color:#d4b475;background-color:#1f1f1f;}
.cFF{color:#1f1f1f;background-color:#1f1f1f;}
</style>
</head>
<body>
<pre style="font-family:monospace;font-size:12pt">
<a name="l1"></a><span class=cF2>/* Gopher client for TempleOS/Sockets</span><span class=cF0>
<a name="l2"></a></span><span class=cF2> by Declan Hoare 2020</span><span class=cF0>
<a name="l3"></a></span><span class=cF2> ported to ZealOS and modified by TomAwezome in 2021</span><span class=cF0>
<a name="l4"></a></span><span class=cF2> Public Domain - No Warranty */</span><span class=cF0>
<a name="l5"></a>
<a name="l6"></a>#</span><span class=cF1>define</span><span class=cF0> GOPHER_CLIENT_LOADED
<a name="l7"></a>
<a name="l8"></a>#</span><span class=cF1>ifndef</span><span class=cF0> GOPHER_ASSOCIATIONS
<a name="l9"></a>#</span><span class=cF1>define</span><span class=cF0> GOPHER_ASSOCIATIONS
<a name="l10"></a></span><span class=cF1>U8</span><span class=cF0> *gopher_associations[</span><span class=cFE>256</span><span class=cF0>];
<a name="l11"></a>#</span><span class=cF1>endif</span><span class=cF0>
<a name="l12"></a>
<a name="l13"></a></span><span class=cF9>I64</span><span class=cF0> GopherOpen(</span><span class=cF1>U8</span><span class=cF0> *host, </span><span class=cF9>U16</span><span class=cF0> port, </span><span class=cF1>U8</span><span class=cF0> *selector, </span><span class=cF1>U8</span><span class=cF0> *query)
<a name="l14"></a>{
<a name="l15"></a> </span><span class=cF1>U8</span><span class=cF0> *line;
<a name="l16"></a> </span><span class=cF9>I64</span><span class=cF0> sock;
<a name="l17"></a>
<a name="l18"></a> </span><span class=cF1>if</span><span class=cF0> (host == </span><span class=cF3>NULL</span><span class=cF0>)
<a name="l19"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l20"></a> </span><span class=cF1>return</span><span class=cF0> -</span><span class=cFE>1</span><span class=cF0>;
<a name="l21"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l22"></a>
<a name="l23"></a></span><span class=cF2>//</span><span class=cF0> </span><span class=cF2>sock = create_connection(host, port);</span><span class=cF0>
<a name="l24"></a> sock = TCPConnectionCreate(host, port);
<a name="l25"></a> </span><span class=cF1>if</span><span class=cF0> (sock &lt;= </span><span class=cFE>0</span><span class=cF0>)
<a name="l26"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l27"></a> </span><span class=cF5>PrintErr</span><span class=cF0>(</span><span class=cF6>&quot;Failed to connect to %s:%d\n&quot;</span><span class=cF0>, host, port);
<a name="l28"></a> </span><span class=cF1>return</span><span class=cF0> sock;
<a name="l29"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l30"></a>
<a name="l31"></a> </span><span class=cF1>if</span><span class=cF0> (query == </span><span class=cF3>NULL</span><span class=cF0>)
<a name="l32"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l33"></a> line = </span><span class=cF5>StrPrint</span><span class=cF0>(</span><span class=cF3>NULL</span><span class=cF0>, </span><span class=cF6>&quot;%s\r\n&quot;</span><span class=cF0>, selector);
<a name="l34"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l35"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l36"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l37"></a> line = </span><span class=cF5>StrPrint</span><span class=cF0>(</span><span class=cF3>NULL</span><span class=cF0>, </span><span class=cF6>&quot;%s\t%s\r\n&quot;</span><span class=cF0>, selector, query);
<a name="l38"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l39"></a>
<a name="l40"></a> sock(CTCPSocket *)-&gt;timeout = TCP_TIMEOUT;
<a name="l41"></a>
<a name="l42"></a></span><span class=cF2>//</span><span class=cF0> </span><span class=cF2>sendString(sock, line, 0);</span><span class=cF0>
<a name="l43"></a> TCPSocketSendString(sock, line);
<a name="l44"></a> </span><span class=cF5>Free</span><span class=cF0>(line);
<a name="l45"></a>
<a name="l46"></a> </span><span class=cF1>return</span><span class=cF0> sock;
<a name="l47"></a>}
<a name="l48"></a>
<a name="l49"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF9>I64</span><span class=cF0> GopherDl(</span><span class=cF1>U8</span><span class=cF0> *host, </span><span class=cF9>U16</span><span class=cF0> port = </span><span class=cFE>70</span><span class=cF0>, </span><span class=cF1>U8</span><span class=cF0> *selector, </span><span class=cF1>U8</span><span class=cF0> *query = </span><span class=cF3>NULL</span><span class=cF0>, </span><span class=cF1>U8</span><span class=cF0> *dest)
<a name="l50"></a>{
<a name="l51"></a> </span><span class=cF9>CFile</span><span class=cF0> *f;
<a name="l52"></a> </span><span class=cF1>U8</span><span class=cF0> buf[</span><span class=cF3>BLK_SIZE</span><span class=cF0>];
<a name="l53"></a> </span><span class=cF9>I64</span><span class=cF0> data_len = </span><span class=cFE>0</span><span class=cF0>, total_len = </span><span class=cFE>0</span><span class=cF0>, got, sock;
<a name="l54"></a>
<a name="l55"></a> </span><span class=cFB>progress4</span><span class=cF0> = </span><span class=cFE>0</span><span class=cF0>;
<a name="l56"></a> f = </span><span class=cF5>FOpen</span><span class=cF0>(dest, </span><span class=cF6>&quot;w&quot;</span><span class=cF0>);
<a name="l57"></a> </span><span class=cF1>if</span><span class=cF0> (!f)
<a name="l58"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l59"></a> </span><span class=cF5>PrintErr</span><span class=cF0>(</span><span class=cF6>&quot;Failed to open %s for writing\n&quot;</span><span class=cF0>, dest);
<a name="l60"></a> </span><span class=cF1>return</span><span class=cF0> -</span><span class=cFE>1</span><span class=cF0>;
<a name="l61"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l62"></a>
<a name="l63"></a> sock = GopherOpen(host, port, selector, query);
<a name="l64"></a> </span><span class=cF1>if</span><span class=cF0> (sock &lt;= </span><span class=cFE>0</span><span class=cF0>)
<a name="l65"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l66"></a> </span><span class=cF1>return</span><span class=cF0> sock;
<a name="l67"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l68"></a>
<a name="l69"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF3>TRUE</span><span class=cF0>)
<a name="l70"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l71"></a></span><span class=cF2>//</span><span class=cF0> </span><span class=cF2>got = recv(sock, buf + data_len, sizeof(buf) - data_len, 0);</span><span class=cF0>
<a name="l72"></a> got = TCPSocketReceive(sock, buf + data_len, </span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF0>buf</span><span class=cF7>)</span><span class=cF0> - data_len);
<a name="l73"></a> </span><span class=cF1>if</span><span class=cF0> (got &lt;= </span><span class=cFE>0</span><span class=cF0>)
<a name="l74"></a> {
<a name="l75"></a> </span><span class=cF1>if</span><span class=cF0> (got &lt; </span><span class=cFE>0</span><span class=cF0>)
<a name="l76"></a> </span><span class=cF5>PrintErr</span><span class=cF0>(</span><span class=cF6>&quot;Failed to receive TCP data\n&quot;</span><span class=cF0>);
<a name="l77"></a> </span><span class=cF1>if</span><span class=cF0> (data_len != </span><span class=cFE>0</span><span class=cF0> &amp;&amp; !</span><span class=cF5>FBlkWrite</span><span class=cF7>(</span><span class=cF0>f, buf</span><span class=cF7>)</span><span class=cF0>)
<a name="l78"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l79"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l80"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l81"></a> f-&gt;de.size = total_len;
<a name="l82"></a> </span><span class=cF5>FClose</span><span class=cF0>(f);
<a name="l83"></a> TCPSocketClose(sock);
<a name="l84"></a> </span><span class=cF1>return</span><span class=cF0> got;
<a name="l85"></a> }
<a name="l86"></a> data_len += got;
<a name="l87"></a> total_len += got;
<a name="l88"></a> </span><span class=cFB>progress4</span><span class=cF0> += got;
<a name="l89"></a> </span><span class=cF1>if</span><span class=cF0> (data_len == </span><span class=cF3>BLK_SIZE</span><span class=cF0>)
<a name="l90"></a> {
<a name="l91"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF5>FBlkWrite</span><span class=cF7>(</span><span class=cF0>f, buf</span><span class=cF7>)</span><span class=cF0>)
<a name="l92"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l93"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l94"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l95"></a> data_len = </span><span class=cFE>0</span><span class=cF0>;
<a name="l96"></a> }
<a name="l97"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l98"></a>
<a name="l99"></a> TCPSocketClose(sock);
<a name="l100"></a> </span><span class=cF5>PrintErr</span><span class=cF0>(</span><span class=cF6>&quot;Write failed, %s may be corrupted\n&quot;</span><span class=cF0>, dest);
<a name="l101"></a> </span><span class=cF5>FClose</span><span class=cF0>(f);
<a name="l102"></a> </span><span class=cF1>return</span><span class=cF0> -</span><span class=cFE>1</span><span class=cF0>;
<a name="l103"></a>
<a name="l104"></a>}
<a name="l105"></a>
<a name="l106"></a></span><span class=cF1>U0</span><span class=cF0> PrintEscaped(</span><span class=cF1>U8</span><span class=cF0> *txt, </span><span class=cF1>U8</span><span class=cF0> *backslashes = </span><span class=cF6>&quot;&quot;</span><span class=cF0>)
<a name="l107"></a>{
<a name="l108"></a> </span><span class=cF1>U8</span><span class=cF0> *cur;
<a name="l109"></a> </span><span class=cF9>U64</span><span class=cF0> offending;
<a name="l110"></a>
<a name="l111"></a> </span><span class=cF1>while</span><span class=cF0> (cur = </span><span class=cF5>StrFirstOcc</span><span class=cF7>(</span><span class=cF0>txt, </span><span class=cF6>&quot;$\\\&quot;&quot;</span><span class=cF7>)</span><span class=cF0>)
<a name="l112"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l113"></a> offending = *cur;
<a name="l114"></a> *cur = </span><span class=cFE>0</span><span class=cF0>;
<a name="l115"></a> </span><span class=cF1>if</span><span class=cF0> (offending == </span><span class=cF6>'$'</span><span class=cF0>)
<a name="l116"></a> {
<a name="l117"></a> </span><span class=cF6>&quot;%s$$&quot;</span><span class=cF0>, txt;
<a name="l118"></a> }
<a name="l119"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l120"></a> {
<a name="l121"></a> </span><span class=cF6>&quot;%s%s%c&quot;</span><span class=cF0>, txt, backslashes, offending;
<a name="l122"></a> }
<a name="l123"></a> txt = cur + </span><span class=cFE>1</span><span class=cF0>;
<a name="l124"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l125"></a>
<a name="l126"></a> </span><span class=cF6>&quot;%s&quot;</span><span class=cF0>, txt;
<a name="l127"></a>}
<a name="l128"></a>
<a name="l129"></a></span><span class=cF1>U8</span><span class=cF0> *GopherBasename(</span><span class=cF1>U8</span><span class=cF0> *selector)
<a name="l130"></a>{
<a name="l131"></a> </span><span class=cF1>U8</span><span class=cF0> *lastslash = </span><span class=cF5>StrLastOcc</span><span class=cF0>(selector, </span><span class=cF6>&quot;/&quot;</span><span class=cF0>), *result;
<a name="l132"></a>
<a name="l133"></a> </span><span class=cF1>if</span><span class=cF0> (lastslash == </span><span class=cF3>NULL</span><span class=cF0>)
<a name="l134"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l135"></a> result = selector;
<a name="l136"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l137"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l138"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l139"></a> result = lastslash + </span><span class=cFE>1</span><span class=cF0>;
<a name="l140"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l141"></a>
<a name="l142"></a> </span><span class=cF2>//BAD FOR FILENAMES: ? / | = % : ; * + &quot; &lt; &gt; space </span><span class=cF0>
<a name="l143"></a> result = </span><span class=cF5>StrReplace</span><span class=cF0>(result, </span><span class=cF6>&quot;?&quot;</span><span class=cF0>, </span><span class=cF6>&quot;&quot;</span><span class=cF0>);
<a name="l144"></a> result = </span><span class=cF5>StrReplace</span><span class=cF0>(result, </span><span class=cF6>&quot;/&quot;</span><span class=cF0>, </span><span class=cF6>&quot;&quot;</span><span class=cF0>,, </span><span class=cF3>TRUE</span><span class=cF0>);
<a name="l145"></a> result = </span><span class=cF5>StrReplace</span><span class=cF0>(result, </span><span class=cF6>&quot;|&quot;</span><span class=cF0>, </span><span class=cF6>&quot;&quot;</span><span class=cF0>,, </span><span class=cF3>TRUE</span><span class=cF0>);
<a name="l146"></a> result = </span><span class=cF5>StrReplace</span><span class=cF0>(result, </span><span class=cF6>&quot;=&quot;</span><span class=cF0>, </span><span class=cF6>&quot;&quot;</span><span class=cF0>,, </span><span class=cF3>TRUE</span><span class=cF0>);
<a name="l147"></a> result = </span><span class=cF5>StrReplace</span><span class=cF0>(result, </span><span class=cF6>&quot;%&quot;</span><span class=cF0>, </span><span class=cF6>&quot;&quot;</span><span class=cF0>,, </span><span class=cF3>TRUE</span><span class=cF0>);
<a name="l148"></a> result = </span><span class=cF5>StrReplace</span><span class=cF0>(result, </span><span class=cF6>&quot;:&quot;</span><span class=cF0>, </span><span class=cF6>&quot;&quot;</span><span class=cF0>,, </span><span class=cF3>TRUE</span><span class=cF0>);
<a name="l149"></a> result = </span><span class=cF5>StrReplace</span><span class=cF0>(result, </span><span class=cF6>&quot;;&quot;</span><span class=cF0>, </span><span class=cF6>&quot;&quot;</span><span class=cF0>,, </span><span class=cF3>TRUE</span><span class=cF0>);
<a name="l150"></a> result = </span><span class=cF5>StrReplace</span><span class=cF0>(result, </span><span class=cF6>&quot;*&quot;</span><span class=cF0>, </span><span class=cF6>&quot;&quot;</span><span class=cF0>,, </span><span class=cF3>TRUE</span><span class=cF0>);
<a name="l151"></a> result = </span><span class=cF5>StrReplace</span><span class=cF0>(result, </span><span class=cF6>&quot;+&quot;</span><span class=cF0>, </span><span class=cF6>&quot;&quot;</span><span class=cF0>,, </span><span class=cF3>TRUE</span><span class=cF0>);
<a name="l152"></a> result = </span><span class=cF5>StrReplace</span><span class=cF0>(result, </span><span class=cF6>&quot;\&quot;&quot;</span><span class=cF0>, </span><span class=cF6>&quot;&quot;</span><span class=cF0>,, </span><span class=cF3>TRUE</span><span class=cF0>);
<a name="l153"></a> result = </span><span class=cF5>StrReplace</span><span class=cF0>(result, </span><span class=cF6>&quot;&lt;&quot;</span><span class=cF0>, </span><span class=cF6>&quot;&quot;</span><span class=cF0>,, </span><span class=cF3>TRUE</span><span class=cF0>);
<a name="l154"></a> result = </span><span class=cF5>StrReplace</span><span class=cF0>(result, </span><span class=cF6>&quot;&gt;&quot;</span><span class=cF0>, </span><span class=cF6>&quot;&quot;</span><span class=cF0>,, </span><span class=cF3>TRUE</span><span class=cF0>);
<a name="l155"></a> result = </span><span class=cF5>StrReplace</span><span class=cF0>(result, </span><span class=cF6>&quot; &quot;</span><span class=cF0>, </span><span class=cF6>&quot;&quot;</span><span class=cF0>,, </span><span class=cF3>TRUE</span><span class=cF0>);
<a name="l156"></a>
<a name="l157"></a> </span><span class=cF5>SysLog</span><span class=cF0>(</span><span class=cF6>&quot;%s\n&quot;</span><span class=cF0>, result);
<a name="l158"></a>
<a name="l159"></a> </span><span class=cF1>return</span><span class=cF0> result;
<a name="l160"></a>}
<a name="l161"></a>
<a name="l162"></a></span><span class=cF1>U0</span><span class=cF0> GopherTextView(</span><span class=cF1>U8</span><span class=cF0> *host, </span><span class=cF9>U16</span><span class=cF0> port, </span><span class=cF1>U8</span><span class=cF0> *selector)
<a name="l163"></a>{
<a name="l164"></a> </span><span class=cF1>U8</span><span class=cF0> *basename;
<a name="l165"></a> </span><span class=cF1>U8</span><span class=cF0> *tmpname;
<a name="l166"></a>
<a name="l167"></a> </span><span class=cF5>DirMake</span><span class=cF0>(</span><span class=cF6>&quot;::/Tmp/Gopher&quot;</span><span class=cF0>);
<a name="l168"></a>
<a name="l169"></a> tmpname = </span><span class=cF5>StrNew</span><span class=cF0>(selector);
<a name="l170"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>StrLen</span><span class=cF7>(</span><span class=cF0>tmpname</span><span class=cF7>)</span><span class=cF0> &gt; </span><span class=cFE>22</span><span class=cF0>)
<a name="l171"></a> tmpname[</span><span class=cFE>21</span><span class=cF0>] = </span><span class=cFE>0</span><span class=cF0>; </span><span class=cF2>// too long, terminate it early</span><span class=cF0>
<a name="l172"></a> basename = </span><span class=cF5>ExtChange</span><span class=cF0>(GopherBasename</span><span class=cF7>(</span><span class=cF0>tmpname</span><span class=cF7>)</span><span class=cF0>, </span><span class=cF6>&quot;TXT&quot;</span><span class=cF0>);
<a name="l173"></a> </span><span class=cF5>Free</span><span class=cF0>(tmpname);
<a name="l174"></a> tmpname = </span><span class=cF5>StrPrint</span><span class=cF0>(</span><span class=cF3>NULL</span><span class=cF0>, </span><span class=cF6>&quot;::/Tmp/Gopher/%s&quot;</span><span class=cF0>, basename);
<a name="l175"></a> </span><span class=cF5>Free</span><span class=cF0>(basename);
<a name="l176"></a>
<a name="l177"></a> </span><span class=cF1>if</span><span class=cF0> (GopherDl</span><span class=cF7>(</span><span class=cF0>host, port, selector,, tmpname</span><span class=cF7>)</span><span class=cF0> == </span><span class=cFE>0</span><span class=cF0>)
<a name="l178"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l179"></a> </span><span class=cF5>SysLog</span><span class=cF0>(</span><span class=cF6>&quot;%s\n&quot;</span><span class=cF0>, tmpname);
<a name="l180"></a> </span><span class=cF5>Plain</span><span class=cF0>(tmpname);
<a name="l181"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l182"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l183"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l184"></a> </span><span class=cF5>PrintErr</span><span class=cF0>(</span><span class=cF6>&quot;Failed to download %s from %s:%d\n&quot;</span><span class=cF0>,
<a name="l185"></a> selector, host, port);
<a name="l186"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l187"></a> </span><span class=cF5>Free</span><span class=cF0>(tmpname);
<a name="l188"></a>}
<a name="l189"></a>
<a name="l190"></a></span><span class=cF1>U0</span><span class=cF0> GopherLine(</span><span class=cF1>U8</span><span class=cF0> *line)
<a name="l191"></a>{
<a name="l192"></a> </span><span class=cF9>U64</span><span class=cF0> type;
<a name="l193"></a> </span><span class=cF1>U8</span><span class=cF0> *display;
<a name="l194"></a> </span><span class=cF1>U8</span><span class=cF0> *selector;
<a name="l195"></a> </span><span class=cF1>U8</span><span class=cF0> *host = </span><span class=cF3>NULL</span><span class=cF0>;
<a name="l196"></a> </span><span class=cF9>U16</span><span class=cF0> port = </span><span class=cFE>0</span><span class=cF0>;
<a name="l197"></a>
<a name="l198"></a> </span><span class=cF1>if</span><span class=cF0> (*line == </span><span class=cFE>0</span><span class=cF0>)
<a name="l199"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l200"></a> </span><span class=cF6>&quot;\n&quot;</span><span class=cF0>;
<a name="l201"></a> </span><span class=cF1>return</span><span class=cF0>;
<a name="l202"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l203"></a> type = *line++;
<a name="l204"></a> display = line;
<a name="l205"></a>
<a name="l206"></a> line = </span><span class=cF5>StrFind</span><span class=cF0>(</span><span class=cF6>&quot;\t&quot;</span><span class=cF0>, line);
<a name="l207"></a> </span><span class=cF1>if</span><span class=cF0> (line)
<a name="l208"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l209"></a> *line = </span><span class=cFE>0</span><span class=cF0>;
<a name="l210"></a> line++;
<a name="l211"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l212"></a> selector = line;
<a name="l213"></a>
<a name="l214"></a> </span><span class=cF1>if</span><span class=cF0> (line)
<a name="l215"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l216"></a> line = </span><span class=cF5>StrFind</span><span class=cF0>(</span><span class=cF6>&quot;\t&quot;</span><span class=cF0>, line);
<a name="l217"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l218"></a> </span><span class=cF1>if</span><span class=cF0> (line)
<a name="l219"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l220"></a> *line = </span><span class=cFE>0</span><span class=cF0>;
<a name="l221"></a> line++;
<a name="l222"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l223"></a> host = line;
<a name="l224"></a>
<a name="l225"></a> </span><span class=cF1>if</span><span class=cF0> (line)
<a name="l226"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l227"></a> line = </span><span class=cF5>StrFind</span><span class=cF0>(</span><span class=cF6>&quot;\t&quot;</span><span class=cF0>, line);
<a name="l228"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l229"></a> </span><span class=cF1>if</span><span class=cF0> (line)
<a name="l230"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l231"></a> *line = </span><span class=cFE>0</span><span class=cF0>;
<a name="l232"></a> line++;
<a name="l233"></a> port = </span><span class=cF5>Str2I64</span><span class=cF0>(line);
<a name="l234"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l235"></a>
<a name="l236"></a> </span><span class=cF1>if</span><span class=cF0> (!*host)
<a name="l237"></a> </span><span class=cF1>return</span><span class=cF0>;
<a name="l238"></a>
<a name="l239"></a> </span><span class=cF1>switch</span><span class=cF0> (type)
<a name="l240"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l241"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF6>'3'</span><span class=cF0>:
<a name="l242"></a> </span><span class=cF5>PrintErr</span><span class=cF0>(</span><span class=cF6>&quot;&quot;</span><span class=cF0>);
<a name="l243"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF6>'i'</span><span class=cF0>:
<a name="l244"></a> PrintEscaped(display);
<a name="l245"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l246"></a> </span><span class=cF1>default</span><span class=cF0>:
<a name="l247"></a> </span><span class=cF6>&quot;$MA,\&quot;&quot;</span><span class=cF0>;
<a name="l248"></a> PrintEscaped(display, </span><span class=cF6>&quot;\\&quot;</span><span class=cF0>);
<a name="l249"></a> </span><span class=cF6>&quot;\&quot;,LM=\&quot;%s(\\\&quot;&quot;</span><span class=cF0>, gopher_associations[type];
<a name="l250"></a> PrintEscaped(host, </span><span class=cF6>&quot;\\\\\\&quot;</span><span class=cF0>);
<a name="l251"></a> </span><span class=cF6>&quot;\\\&quot;,%d,\\\&quot;&quot;</span><span class=cF0>, port;
<a name="l252"></a> PrintEscaped(selector, </span><span class=cF6>&quot;\\\\\\&quot;</span><span class=cF0>);
<a name="l253"></a> </span><span class=cF6>&quot;\\\&quot;);\\n\&quot;$&quot;</span><span class=cF0>;
<a name="l254"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l255"></a> </span><span class=cF6>&quot;\n&quot;</span><span class=cF0>;
<a name="l256"></a>}
<a name="l257"></a>
<a name="l258"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF9>I64</span><span class=cF0> GopherMenu(</span><span class=cF1>U8</span><span class=cF0> *host, </span><span class=cF9>U16</span><span class=cF0> port = </span><span class=cFE>70</span><span class=cF0>, </span><span class=cF1>U8</span><span class=cF0> *selector = </span><span class=cF6>&quot;/&quot;</span><span class=cF0>, </span><span class=cF1>U8</span><span class=cF0> *query = </span><span class=cF3>NULL</span><span class=cF0>)
<a name="l259"></a>{
<a name="l260"></a> </span><span class=cF9>I64</span><span class=cF0> sock, n;
<a name="l261"></a> </span><span class=cF1>U8</span><span class=cF0> buf[</span><span class=cFE>256</span><span class=cF0>];
<a name="l262"></a>
<a name="l263"></a> sock = GopherOpen(host, port, selector, query);
<a name="l264"></a> </span><span class=cF1>if</span><span class=cF0> (sock &lt;= </span><span class=cFE>0</span><span class=cF0>)
<a name="l265"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l266"></a> </span><span class=cF1>return</span><span class=cF0> sock;
<a name="l267"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l268"></a>
<a name="l269"></a> </span><span class=cF1>do</span><span class=cF0>
<a name="l270"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l271"></a></span><span class=cF2>//</span><span class=cF0> </span><span class=cF2>n = recvLine(sock, buf, sizeof(buf), 0);</span><span class=cF0>
<a name="l272"></a> n = TCPSocketReceiveLine(sock, buf, </span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF0>buf</span><span class=cF7>)</span><span class=cF0>);
<a name="l273"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>StrCompare</span><span class=cF7>(</span><span class=cF0>buf, </span><span class=cF6>&quot;.&quot;</span><span class=cF7>)</span><span class=cF0> == </span><span class=cFE>0</span><span class=cF0>)
<a name="l274"></a> {
<a name="l275"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l276"></a> }
<a name="l277"></a> GopherLine(buf);
<a name="l278"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l279"></a> </span><span class=cF1>while</span><span class=cF0> (n &gt; </span><span class=cFE>0</span><span class=cF0>);
<a name="l280"></a>
<a name="l281"></a></span><span class=cF2>//</span><span class=cF0> </span><span class=cF2>close(sock);</span><span class=cF0>
<a name="l282"></a> TCPSocketClose(sock);
<a name="l283"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cFE>0</span><span class=cF0>;
<a name="l284"></a>}
<a name="l285"></a>
<a name="l286"></a></span><span class=cF1>class</span><span class=cF0> CQueryForm
<a name="l287"></a>{
<a name="l288"></a> </span><span class=cF1>U8</span><span class=cF0> query[</span><span class=cFE>65</span><span class=cF0>] format </span><span class=cF6>&quot;$DA-P,A=\&quot;Query:%s\&quot;$&quot;</span><span class=cF0>;
<a name="l289"></a>};
<a name="l290"></a></span><span class=cF1>U0</span><span class=cF0> GopherQueryPrompt(</span><span class=cF1>U8</span><span class=cF0> *host, </span><span class=cF9>U16</span><span class=cF0> port, </span><span class=cF1>U8</span><span class=cF0> *selector)
<a name="l291"></a>{
<a name="l292"></a> CQueryForm form;
<a name="l293"></a>
<a name="l294"></a> form.query[</span><span class=cFE>0</span><span class=cF0>] = </span><span class=cFE>0</span><span class=cF0>;
<a name="l295"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>PopUpForm</span><span class=cF7>(</span><span class=cF0>&amp;form</span><span class=cF7>)</span><span class=cF0>)
<a name="l296"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l297"></a> GopherMenu(host, port, selector, form.query);
<a name="l298"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l299"></a>}
<a name="l300"></a>
<a name="l301"></a></span><span class=cF1>class</span><span class=cF0> CDlForm
<a name="l302"></a>{
<a name="l303"></a> </span><span class=cF1>U8</span><span class=cF0> name[</span><span class=cFE>256</span><span class=cF0>] format </span><span class=cF6>&quot;$DA-P,LEN=255,A=\&quot;FileName:%s\&quot;$&quot;</span><span class=cF0>;
<a name="l304"></a>};
<a name="l305"></a></span><span class=cF1>U0</span><span class=cF0> GopherDlPrompt(</span><span class=cF1>U8</span><span class=cF0> *host, </span><span class=cF9>U16</span><span class=cF0> port, </span><span class=cF1>U8</span><span class=cF0> *selector)
<a name="l306"></a>{
<a name="l307"></a> CDlForm form;
<a name="l308"></a> </span><span class=cF1>U8</span><span class=cF0> *basename;
<a name="l309"></a>
<a name="l310"></a> basename = GopherBasename(selector);
<a name="l311"></a> </span><span class=cF5>MemSet</span><span class=cF0>(form.name, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cFE>256</span><span class=cF0>);
<a name="l312"></a> </span><span class=cF5>MemCopy</span><span class=cF0>(form.name, basename,
<a name="l313"></a> </span><span class=cF5>MinI64</span><span class=cF7>(</span><span class=cF5>StrLen</span><span class=cF0>(basename), </span><span class=cF1>sizeof</span><span class=cF0>(form.name) - </span><span class=cFE>1</span><span class=cF7>)</span><span class=cF0>);
<a name="l314"></a> form.name[</span><span class=cFE>255</span><span class=cF0>] = </span><span class=cFE>0</span><span class=cF0>;
<a name="l315"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>PopUpForm</span><span class=cF7>(</span><span class=cF0>&amp;form</span><span class=cF7>)</span><span class=cF0>)
<a name="l316"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l317"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>StrLen</span><span class=cF7>(</span><span class=cF0>form.name</span><span class=cF7>)</span><span class=cF0> &gt;= </span><span class=cFE>26</span><span class=cF0>)
<a name="l318"></a> form.name[</span><span class=cFE>25</span><span class=cF0>] = </span><span class=cFE>0</span><span class=cF0>;
<a name="l319"></a> GopherDl(host, port, selector,, form.name);
<a name="l320"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l321"></a>}
<a name="l322"></a>
<a name="l323"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF9>I64</span><span class=cF0> Gopher(</span><span class=cF1>U8</span><span class=cF0> *hostname)
<a name="l324"></a>{
<a name="l325"></a> </span><span class=cF1>return</span><span class=cF0> GopherMenu(hostname);
<a name="l326"></a>}
<a name="l327"></a>
<a name="l328"></a></span><span class=cF5>MemSetI64</span><span class=cF0>(gopher_associations, </span><span class=cF6>&quot;GopherDlPrompt&quot;</span><span class=cF0>, </span><span class=cFE>256</span><span class=cF0>);
<a name="l329"></a>gopher_associations[</span><span class=cF6>'0'</span><span class=cF0>] = </span><span class=cF6>&quot;GopherTextView&quot;</span><span class=cF0>;
<a name="l330"></a>gopher_associations[</span><span class=cF6>'1'</span><span class=cF0>] = </span><span class=cF6>&quot;GopherMenu&quot;</span><span class=cF0>;
<a name="l331"></a>gopher_associations[</span><span class=cF6>'7'</span><span class=cF0>] = </span><span class=cF6>&quot;GopherQueryPrompt&quot;</span><span class=cF0>;
<a name="l332"></a></span><span class=cF2>/* Include this file from your Net/Load.ZC, then add more associations */</span><span class=cF0>
<a name="l333"></a>
<a name="l334"></a>
<a name="l335"></a></span><span class=cF5>DocMax</span><span class=cF0>;
<a name="l336"></a></span><span class=cF6>&quot;\n\nTry using Gopher to connect to a gopher server, for example:&quot;</span><span class=cF0>
<a name="l337"></a></span><span class=cF6>&quot;\n\n Gopher(\&quot;gopher.floodgap.com\&quot;);&quot;</span><span class=cF0>
<a name="l338"></a></span><span class=cF6>&quot;\n\n GopherMenu(\&quot;eyeblea.ch\&quot;,70,\&quot;/~zealos\&quot;);&quot;</span><span class=cF0>
<a name="l339"></a></span><span class=cF6>&quot;\n\n Gopher(\&quot;codevoid.de\&quot;);&quot;</span><span class=cF0>
<a name="l340"></a></span><span class=cF6>&quot;\n\n&quot;</span><span class=cF0>;</span></pre></body>
</html>