Initial Commit
[packages] / xemacs-packages / zenirc / src / zenirc-fortran.el
1 ;;; zenirc-fortran.el --- emulate F-BOT FORTRAN bot program with ZenIRC
2
3 ;; Copyright (C) 1993, 1994 Ben A. Mesander
4 ;; Copyright (C) 1997 Noah Friedman
5
6 ;; Author: Ben A. Mesander <ben@gnu.ai.mit.edu>
7 ;; Maintainer: ben@gnu.ai.mit.edu
8 ;; Keywords: extensions
9 ;; Created: 1993/06/03
10
11 ;; This program is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15 ;;
16 ;; This program is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 ;; GNU General Public License for more details.
20 ;;
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with this program; if not, you can either send email to this
23 ;; program's maintainer or write to: The Free Software Foundation,
24 ;; Inc.; 675 Massachusetts Avenue; Cambridge, MA 02139, USA.
25
26 ;;; Commentary:
27
28 ;; Example hook code to override something internal to zenirc.
29 ;; Also a good example of a server message hook.
30
31 ;; From ben@gnu.ai.mit.edu Tue May 11 08:12:27 1993
32 ;; Newsgroups: alt.irc
33 ;; From: ben@gnu.ai.mit.edu (Ben A. Mesander)
34 ;; Subject: Re: introducing ZENBOT 1.0!!!!  (Bot-lovers)
35 ;; Summary: FORTRAN BOTZ RULE!!!!!!111
36 ;; In-Reply-To: christian@hopper.Virginia.EDU's message of Mon, 10 May 1993 23:43:42 GMT
37 ;; Date: Tue, 11 May 1993 04:44:42 GMT
38 ;; Nntp-Posting-Host: gnu.ai.mit.edu
39 ;; Organization: The phedz.
40 ;;
41 ;; Hah. Leper.
42 ;;
43 ;; ircII bots are for weenies. Even C bots are slow on supercomputer
44 ;; architectures. On a Cray, FORTRAN is much faster than C, due to the
45 ;; architecture of the machine. Therefore I - piglet3 - the GENIUS
46 ;; MASTERMIND of IRC have written a FORTRAN bot. This bot is guaranteed
47 ;; to be faster than any C bot if run on a Cray II or above. I am sure
48 ;; the irCOPS want to keep this technology secret, but I - piglet3 - am
49 ;; going to reveal the SECRET OF FAST BOTS ON IRC RIGHT IN THIS POSTING!
50 ;;
51 ;; Unlike Christian's RESTRICTIVE licensing agreement, my bot is in the
52 ;; PUBLIC DOMAIN! If you want to use it and claim you wrote it, PLEASE DO!
53 ;;
54 ;; The source comes in three files, a Makefile (yes, Christian's bot had
55 ;; NO MAKEFILE! IT WAS HARD TO INSTALL!), a FORTRAN source code file, and
56 ;; a small C code interface to the UNIX operating system. Those of you
57 ;; running operating systems besides UNIX should have no trouble writing
58 ;; the network interface routines in FORTRAN instead of C.
59 ;;
60 ;; Future releases of this program will be installable via GNU Configure,
61 ;; thus making installation even easier. The FORTRAN-C calling interface
62 ;; is assumed to be BSD-style, for those of you who really want to compile
63 ;; it.
64 ;;
65 ;; ---Makefile---cut here---
66 ;; CC=gcc
67 ;; F77=f77
68 ;;
69 ;; bot: bot.o sock.o
70 ;;      $(F77) bot.o sock.o -o bot
71 ;;
72 ;; bot.o: bot.f
73 ;;      $(F77) -c bot.f
74 ;;
75 ;; sock.o: sock.c
76 ;;      $(CC) -c sock.c
77 ;; ---bot.f---cut here---
78 ;; CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
79 ;; C
80 ;; C FORTRAN BOT PROGRAM FOR IRC II
81 ;; C
82 ;; C BY BEN MESANDER
83 ;; C BEN@GNU.AI.MIT.EDU
84 ;; C
85 ;; C THIS PROGRAM IS IN THE PUBLIC DOMAIN
86 ;; CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
87 ;;
88 ;;       PROGRAM FBOT
89 ;;       CHARACTER*80 SERVER, CHANEL, NICK, NAME, USER, HOST
90 ;;
91 ;; C YOU MUST CUSTOMIZE THESE VARIABLES
92 ;;       NICK='F-BOT'
93 ;;       NAME='EXPERIMENTAL FORTRAN IRC-II BOT PROGRAM'
94 ;;       USER='BEN'
95 ;;       HOST='GNU.AI.MIT.EDU'
96 ;;
97 ;;       PRINT *,'ENTER NAME OF IRC-SERVER TO USE:'
98 ;;       READ(*,'(A)') SERVER
99 ;;       PRINT *,'ENTER NAME OF CHANNEL TO JOIN:'
100 ;;       READ(*,'(A)') CHANEL
101 ;;
102 ;;       I=OPSOCK(SERVER)
103 ;;       IF (I.EQ.1) THEN
104 ;;          PRINT *,'UNABLE TO CONNECT TO IRC-SERVER'
105 ;;          STOP
106 ;;       ENDIF
107 ;;
108 ;;       I=WRSOCK('NICK '//NICK)
109 ;;       IF (I.EQ.1) THEN
110 ;;          PRINT *,'UNABLE TO WRITE IRC-NICK TO SERVER'
111 ;;          STOP
112 ;;       ENDIF
113 ;;
114 ;;       I=WRSOCK('USER '//USER(1:INDEX(USER,' ')-1)//'@'//HOST(1:
115 ;;      +     INDEX(HOST,' ')-1)//' 1 1 :'//NAME)
116 ;;       IF (I.EQ.1) THEN
117 ;;          PRINT *,'UNABLE TO WRITE IRC-NAME TO SERVER'
118 ;;          STOP
119 ;;       ENDIF
120 ;;
121 ;;       CALL EATMTD()
122 ;;       CALL BOTTY(CHANEL,NICK,USER,HOST)
123 ;;       CALL CLSOCK()
124 ;;       STOP
125 ;;       END
126 ;;
127 ;;       SUBROUTINE EATMTD()
128 ;; C PURPOSE - TO EAT THE MOTD
129 ;;       CHARACTER*513 INLINE
130 ;;
131 ;;  10   CONTINUE
132 ;;       I=RDSOCK(INLINE)
133 ;;       IF (I.EQ.1) THEN
134 ;;          PRINT *,'ERROR WHILE READING MOTD'
135 ;;          STOP
136 ;;       ENDIF
137 ;;       IF ((INDEX(INLINE,'End of /MOTD').EQ.0).OR.
138 ;;      +     (INDEX(INLINE,'376').NE.0)) GOTO 10
139 ;;       RETURN
140 ;;       END
141 ;;
142 ;;       SUBROUTINE BOTTY(CHANEL, NICK, USER, HOST)
143 ;;       CHARACTER*80 CHANEL, NICK, USER, HOST
144 ;; C PURPOSE - TO BE BOTTY
145 ;;       CHARACTER*513 INLINE
146 ;;
147 ;;       I=WRSOCK('JOIN '//CHANEL)
148 ;;       IF (I.EQ.1) THEN
149 ;;          PRINT *,'ERROR WHILE JOINING CHANNEL'
150 ;;          STOP
151 ;;       ENDIF
152 ;;
153 ;;  20   CONTINUE
154 ;;       INLINE=''
155 ;;       I=RDSOCK(INLINE)
156 ;;          IF (I.EQ.1) THEN
157 ;;          PRINT *,'ERROR READING FROM IRC-SERVER'
158 ;;          STOP
159 ;;       ENDIF
160 ;;
161 ;;       IF (INDEX(INLINE,'PING').EQ.1) THEN
162 ;;          I=WRSOCK('PONG '//HOST)
163 ;;          IF (I.EQ.1) THEN
164 ;;             PRINT *,'ERROR WHILE PONGING'
165 ;;             STOP
166 ;;          ENDIF
167 ;;          GOTO 20
168 ;;       ENDIF
169 ;;
170 ;;       IF (INDEX(INLINE,'FORTRAN').NE.0) THEN
171 ;;          I=WRSOCK('PRIVMSG '//CHANEL(:INDEX(CHANEL,' ')-1)//
172 ;;      +        ' :YES I AM REALLY WRITTEN IN 3L33T FORTRAN-77!!!!!!!')
173 ;;          IF (I.EQ.1) THEN
174 ;;             PRINT *,'ERROR WRITING 3L33T MESSAGE TO IRC-SERVER'
175 ;;             STOP
176 ;;          ENDIF
177 ;;          GOTO 20
178 ;;       ENDIF
179 ;;
180 ;;       IF (INDEX(INLINE,'PHONE IS A SLUT').NE.0) RETURN
181 ;;
182 ;;       GOTO 20
183 ;;       RETURN
184 ;;       END
185 ;;
186 ;; ---sock.c---cut here---
187 ;; /*
188 ;;  * rudimentary C socket I/O routines for FORTRAN bot.
189 ;;  *
190 ;;  * Ben Mesander
191 ;;  * ben@gnu.ai.mit.edu
192 ;;  *
193 ;;  * this code is in the public domain
194 ;;  */
195 ;;
196 ;; #include <stdio.h>
197 ;; #include <sys/types.h>
198 ;; #include <sys/socket.h>
199 ;; #include <netinet/in.h>
200 ;; #include <netdb.h>
201 ;; #define IRCPORT 6667
202 ;;
203 ;; int sock;            /* socket to connect to server */
204 ;;
205 ;; /*
206 ;;  * open a socket to the irc server on "hostname"
207 ;;  */
208 ;;
209 ;; int opsock_(char *fhostname, int fhostnamelen)
210 ;; {
211 ;;      char *hostname;
212 ;;      int i;
213 ;;      struct sockaddr_in addr;
214 ;;      struct hostent *h;
215 ;;
216 ;;      if (NULL == (hostname = (char *)malloc(fhostnamelen+1))) {
217 ;;              return 1;
218 ;;      }
219 ;;      strncpy(hostname, fhostname, fhostnamelen+1);
220 ;;      for(i=0;i<strlen(hostname);i++) {
221 ;;              if (' ' == *(hostname+i)) {
222 ;;                      *(hostname+i)='\0';
223 ;;                      break;
224 ;;              }
225 ;;      }
226 ;;
227 ;;      if (NULL == (h = gethostbyname(hostname))) {
228 ;;              return 1;
229 ;;      }
230 ;;      addr.sin_family = AF_INET;
231 ;;      addr.sin_port = IRCPORT;
232 ;;      bcopy(h->h_addr, (char *)&addr.sin_addr, h->h_length);
233 ;;      bzero((char *)addr.sin_zero, sizeof(addr.sin_zero));
234 ;;
235 ;;      if ( 0 > (sock = socket(AF_INET, SOCK_STREAM, 0))) {
236 ;;              return 1;
237 ;;      }
238 ;;
239 ;;      if ( 0 > connect(sock, &addr, sizeof(addr))) {
240 ;;              return 1;
241 ;;      }
242 ;;
243 ;;      return(0);
244 ;; }
245 ;;
246 ;; int clsock_(void)
247 ;; {
248 ;;      close(sock);
249 ;; }
250 ;;
251 ;; int rdsock_(char *buf, int buflen)
252 ;; {
253 ;;      int i;
254 ;;
255 ;;      for (i=0; i<513; i++) {
256 ;;              if (1 != read(sock,buf+i,1)) {
257 ;;                      return 1;
258 ;;              }
259 ;;              if ('\n' == *(buf+i)) {
260 ;;                      return 0;
261 ;;              }
262 ;;      }
263 ;;      return 0;
264 ;; }
265 ;;
266 ;; int wrsock_(char *buf, int buflen)
267 ;; {
268 ;;      int i;
269 ;;
270 ;;      for (i=0; i<buflen; i++) {
271 ;;              if (1 != write(sock, buf+i, 1)) {
272 ;;                      return 1;
273 ;;              }
274 ;;      }
275 ;;      if (1 != write(sock, "\n", 1)) {
276 ;;              return 1;
277 ;;      }
278 ;;      return 0;
279 ;; }
280 ;;
281 ;; ---end of file---
282 ;;
283 ;; --Ben
284 ;; ben@gnu.ai.mit.edu
285 ;; oink.
286
287 ;; Thanks to zenirc-trigger.el, this elisp module has been reduced to a
288 ;; one-liner, but the real live fortran above is too eleet to stop
289 ;; distributing.
290
291 ;;; Code:
292
293 (require 'zenirc-trigger)
294
295 (zenirc-trigger-register "fortran"
296     "YES I AM REALLY WRITTEN IN 3L33T FORTRAN 77!!!!!!!!!111"
297     "\\bfortran\\b")
298
299 (provide 'zenirc-fortran)
300
301 ;; zenirc-fortran.el ends here