996
|
1 <HTML>
|
|
2 <HEAD>
|
|
3 <TITLE>CLC-INTERCAL Reference</TITLE>
|
|
4 </HEAD>
|
|
5 <BODY>
|
|
6 <H1>CLC-INTERCAL Reference</H1>
|
|
7 <H2>... INTERcal NETworking</H2>
|
|
8
|
|
9 <P>
|
|
10 Table of contents:
|
|
11 <UL>
|
|
12 <LI><A HREF="index.html">Parent directory</A>
|
|
13 <LI><A HREF="#compiling">Compiling a program with INTERNET
|
|
14 support</A>
|
|
15 <LI><A HREF="#using">Using INTERNET</A>
|
|
16 <LI><A HREF="#internals">Internals - or how you can interface
|
|
17 to INTERNET enabled INTERCAL programs from other languages</A>
|
|
18 </UL>
|
|
19 </P>
|
|
20
|
|
21 <H2><A NAME="compiling">Compiling a program with INTERNET support</A></H2>
|
|
22
|
|
23 <P>
|
|
24 Starting with CLC-INTERCAL 1.-94.-2, INTERNET is provided as a
|
|
25 separate package, CLC-INTERCAL-INET. The rest of this chapter
|
|
26 assumes that you have installed that package.
|
|
27 </P>
|
|
28
|
|
29 <P>
|
|
30 INTERNET is a standard compiler extension, so programs must include the
|
|
31 appropriate compile option to use it.
|
|
32 </P>
|
|
33
|
|
34 <P>
|
|
35 The command-line compiler tool,
|
|
36 <I>sick</I>, automatically enables the INTERNET extension if the program
|
|
37 suffix includes the letter "r" (for remote - the letter "i"
|
|
38 was already used to indicate that the program is an INTERCAL program).
|
|
39 Alternatively, if you are not relying on <I>sick</I>'s guesses and
|
|
40 are specifying a list of preloads yourself, just add <I>-pinternet</I>
|
|
41 to your command line.
|
|
42 </P>
|
|
43
|
|
44 <P>
|
|
45 Using the INTERCAL Calculator, INTERCALC, you can easily add INTERNET
|
|
46 support by selecting "internet" from the Options menu or by
|
|
47 adding <I>-ointernet</I> to the command line.
|
|
48 </P>
|
|
49
|
|
50 <P>
|
|
51 The <I>internet</I> compiler object, which implements this extension,
|
|
52 extends the compiler's syntax to include the STEAL, SMUGGLE and CASE
|
|
53 statements; it also informs the runtime that the program should be
|
|
54 listening for theft requests, and start a theft server if required:
|
|
55 this is described below in the <A HREF="#internals">internals</A>
|
|
56 section.
|
|
57 </P>
|
|
58
|
|
59 <H2><A NAME="using">Using INTERNET</A></H2>
|
|
60
|
|
61 <P>
|
|
62 Once you've enabled INTERNET support, using it is a simple matter of
|
|
63 using STEAL, SMUGGLE or CASE statements as required; in this context,
|
|
64 IGNORE and REMEMBER are also useful to allow/disallow access to
|
|
65 your registers from other programs using STEAL and SMUGGLE. Details
|
|
66 on these statements can be found in <A HREF="statements.html">the
|
|
67 chapter about statements</A>.
|
|
68 </P>
|
|
69
|
|
70 <P>
|
|
71 Here is a simple example of an INTERNET program acting as a server:
|
|
72 <PRE>
|
|
73 DO IGNORE @1
|
|
74 (1) PLEASE COME FROM (1)
|
|
75 </PRE>
|
|
76 It may seem rather pointless, but in fact this program will wait
|
|
77 for network connections to SMUGGLE its standard write filehandle
|
|
78 (normally stored in register @1). The filehandle can not be stolen,
|
|
79 because it is ignored. The second statement is automatically caught
|
|
80 by the runtime, which recognises an infinite loop when it sees one,
|
|
81 and replaced with whatever is internally necessary to wait for a
|
|
82 network connection: in other words, the busy wait specified by the
|
|
83 COME FROM statement is replaced by an operating system specific
|
|
84 wait for network connections, which does not consume any CPU until
|
|
85 you try to SMUGGLE the standard write.
|
|
86 </P>
|
|
87
|
|
88 <P>
|
|
89 A client could do the following, after initialising the .1 register
|
|
90 to contain the server's process ID, and the :1 register to contain
|
|
91 the server's IP address:
|
|
92 <PRE>
|
|
93 DO SMUGGLE @1 ON .1 FROM :1
|
|
94 DO WRITE IN .2
|
|
95 </PRE>
|
|
96 what happens here is that one line of input is obtained from the
|
|
97 <I>server</I>'s standard read, and used in the <I>client</I> to
|
|
98 assign a value to .2. The server and the client could be in completely
|
|
99 different networks.
|
|
100 </P>
|
|
101
|
|
102 <P>
|
|
103 Note that this example would still work, once,
|
|
104 if the server did not IGNORE @1 and the client used STEAL instead
|
|
105 of SMUGGLE, however this would prevent a second client from using
|
|
106 the same mechanism, because the server would no longer have the
|
|
107 standard read filehandle available after the first client stole it.
|
|
108 </P>
|
|
109
|
|
110 <P>
|
|
111 We can develop this example a bit further. The server could use the
|
|
112 system call interface to open a temporary file somewhere on the
|
|
113 server, and make it available for smuggling to give other INTERCAL
|
|
114 programs a chance to access the same file - even if they don't have
|
|
115 access to the computer where the server runs. This program should
|
|
116 be compiled with both the <I>internet</I> and <I>syscall</I>
|
|
117 extensions, perhaps by giving it suffix <I>.rsi</I>:
|
|
118 <PRE>
|
|
119 PLEASE ,10 <- #18
|
|
120 DO ,10 SUB #1 <- #95
|
|
121 DO ,10 SUB #2 <- #91
|
|
122 DO ,10 SUB #3 <- #93
|
|
123 PLEASE ,10 SUB #4 <- #95
|
|
124 DO ,10 SUB #5 <- #95
|
|
125 DO ,10 SUB #6 <- #80
|
|
126 DO ,10 SUB #7 <- #92
|
|
127 PLEASE ,10 SUB #8 <- #86
|
|
128 DO ,10 SUB #9 <- #91
|
|
129 DO ,10 SUB #10 <- #93
|
|
130 DO ,10 SUB #11 <- #95
|
|
131 PLEASE ,10 SUB #12 <- #95
|
|
132 DO ,10 SUB #13 <- #69
|
|
133 DO ,10 SUB #14 <- #65
|
|
134 DO ,10 SUB #15 <- #74
|
|
135 PLEASE ,10 SUB #16 <- #94
|
|
136 DO ,10 SUB #17 <- #65
|
|
137 DO ,10 SUB #18 <- #74
|
|
138 DO :10 <- #117
|
|
139 (666) PLEASE .10 <- #3
|
|
140 DO IGNORE @10
|
|
141 (1) DO COME FROM (1)
|
|
142 </PRE>
|
|
143 The first part, from the start to the line with label (666),
|
|
144 opens a file <CODE>/tmp/server</CODE> for reading and writing;
|
|
145 the file name is stored in ,10 and the required access mode
|
|
146 in :10, then system call #3 does the rest. The file will be
|
|
147 associated with class variable @10. All the server has to do
|
|
148 at this point is IGNORE @10 and wait for it to be smuggled.
|
|
149 </P>
|
|
150
|
|
151 <P>
|
|
152 A client could SMUGGLE @10 and just do normal file operations
|
|
153 on it (using READ OUT, WRITE IN, and system call #4 and #5
|
|
154 to perform seeks). Any changes made to the underlying file
|
|
155 will be visible to other clients, as well as any user on the
|
|
156 server computer who has access to the underlying file.
|
|
157 The implementation of the client is left as an exercise to
|
|
158 the reader.
|
|
159 </P>
|
|
160
|
|
161 <H2><A NAME="internals">Internals</A></H2>
|
|
162
|
|
163 <P>
|
|
164 This section will document the underlying protocol used to
|
|
165 STEAL and SMUGGLE variables, as well as executing CASE statements;
|
|
166 it will also show how programs written in other languages can
|
|
167 communicate with INTERCAL programs using the INTERNET.
|
|
168 </P>
|
|
169
|
|
170 <P>
|
|
171 It's just unfortunate that this section hasn't been written yet.
|
|
172 </P>
|
|
173 </BODY>
|
|
174 </HTML>
|
|
175
|