home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / alt / slack / 3961 < prev    next >
Encoding:
Text File  |  1993-01-28  |  8.8 KB  |  456 lines

  1. Path: sparky!uunet!das.wang.com!ulowell!news.bbn.com!olivea!pagesat!netsys!agate!ames!network.ucsd.edu!szechuan.ucsd.edu!spl
  2. From: spl@szechuan.ucsd.edu (Steve Lamont)
  3. Newsgroups: alt.slack
  4. Subject: Re: A Message From Jehova 1..
  5. Message-ID: <1k3p9rINNeld@network.ucsd.edu>
  6. Date: 26 Jan 93 16:36:10 GMT
  7. References: <1993Jan24.002854.4818@mnemosyne.cs.du.edu> <C1G3rF.F64@unix.amherst.edu>
  8. Organization: University of Calif., San Diego/Microscopy and Imaging Resource
  9. Lines: 444
  10. NNTP-Posting-Host: szechuan.ucsd.edu
  11.  
  12. In article <C1G3rF.F64@unix.amherst.edu> mcspinks@unix.amherst.edu (Snarfblat) writes:
  13. >Can someone send me the source also? can it be FTP'd? if not, it should. 
  14. >The Barney story is a brilliant piece of work. I showed it to a few people
  15. >(no header or sig, just the prose). the response: aside from the boring ones
  16. >who were repulsed and didn't finish reading it, the ones who had opinions all
  17. >thought it was a piece of erotic literature. they cited things liked "fat 
  18. >purple fuck" and "i'm going to tie you up". So, Mr Lamont, is it ok with you 
  19. >if I submit it to Amherst's literary magazine? I won't put your name on it 
  20. >unless you want me to. 
  21.  
  22. Sure.  Send me a copy when it comes out.
  23.  
  24. Here's discord, a hack I wrote while waiting for some friends to show
  25. up to go eat Chinese food.  It's pretty ugly in places (well, actually
  26. pretty much everywhere).  If you don't have gcc, change the Makefile
  27. appropriately.
  28.  
  29.          - - - - gnaw on dotted line - - - -
  30. #!/bin/sh
  31. # shar:    Shell Archiver  (v1.22)
  32. #
  33. #    Run the following text with /bin/sh to create:
  34. #      Makefile
  35. #      discord.c
  36. #
  37. sed 's/^X//' << 'SHAR_EOF' > Makefile &&
  38. X# Released upon the public domain.
  39. X
  40. XCC    = gcc
  41. XOPT    = -O2
  42. XDEBUG    = -g
  43. XFNORD    =
  44. XCFLAGS    = $(OPT) $(DEBUG) $(FNORD)
  45. XLFLAGS    =
  46. X
  47. Xdiscord:    discord.c
  48. X    $(CC) $(CFLAGS) -o discord discord.c $(LFLAGS)
  49. SHAR_EOF
  50. chmod 0644 Makefile || echo "restore of Makefile fails"
  51. sed 's/^X//' << 'SHAR_EOF' > discord.c &&
  52. X#include <stdio.h>
  53. X#include <string.h>
  54. X#include <ctype.h>
  55. X#include <sys/types.h>
  56. X#include <sys/time.h>
  57. X
  58. X/*
  59. X * Copyright?  Hell, if asked, I'll deny I even wrote this bit of trash.
  60. X */
  61. X
  62. Xtypedef struct Words {
  63. X    char *word;
  64. X    int visited;
  65. X    int nfollows;
  66. X    int *counts;
  67. X    int class;
  68. X    struct Words **follows;
  69. X    struct Words *before;
  70. X    struct Words *after;
  71. X} Words;
  72. X
  73. Xenum { FullStop, Punct, Word };
  74. X
  75. Xchar *fetchWord();
  76. XWords *addWord( Words **, char * );
  77. XWords *newWord( char * );
  78. Xvoid erisify( Words *, long, long );
  79. Xvoid setup();
  80. Xvoid tally( Words *, Words * );
  81. Xvoid search( long, Words * );
  82. XWords *chase( Words *, long * );
  83. Xvoid fsort( Words * );
  84. XWords *findNewWord( Words * );
  85. X
  86. Xint wordcount = 0;
  87. X
  88. Xint tgrid[128] = { 0 };
  89. XFILE *f;
  90. X
  91. Xint main( int argc, char **argv )
  92. X
  93. X{
  94. X
  95. X    char *word;
  96. X    Words *w = ( Words *) NULL;
  97. X    Words *last;
  98. X
  99. X    setup();
  100. X
  101. X    last = addWord( &w, fetchWord() );
  102. X    while ( word = fetchWord() ) {
  103. X
  104. X    Words *wd;
  105. X
  106. X    wd = addWord( &w, word );
  107. X    tally( last, wd );
  108. X    last = wd;
  109. X
  110. X    }    
  111. X
  112. X    srandom( ( int ) time( ( time_t *) NULL ) );
  113. X
  114. X    erisify( w, ( random() % 10 ) + 1, random() % wordcount );
  115. X
  116. X    exit( 0 );
  117. X
  118. X}
  119. X
  120. Xvoid setup()
  121. X
  122. X{
  123. X
  124. X    tgrid['@'] = 1;
  125. X    tgrid['#'] = 1;
  126. X    tgrid['$'] = 1;
  127. X    tgrid['%'] = 1;
  128. X    tgrid['^'] = 1;
  129. X    tgrid['&'] = 1;
  130. X    tgrid['*'] = 1;
  131. X    tgrid['('] = 1;
  132. X    tgrid[')'] = 1;
  133. X    tgrid['_'] = 1;
  134. X    tgrid['-'] = 1;
  135. X    tgrid['='] = 1;
  136. X    tgrid['+'] = 1;
  137. X    tgrid['|'] = 1;
  138. X    tgrid['\\'] = 1;
  139. X    tgrid['`'] = 1;
  140. X    tgrid['~'] = 1;
  141. X    tgrid['['] = 1;
  142. X    tgrid[']'] = 1;
  143. X    tgrid['{'] = 1;
  144. X    tgrid['}'] = 1;
  145. X    tgrid[':'] = 1;
  146. X    tgrid[';'] = 1;
  147. X    tgrid['\"'] = 1;
  148. X    tgrid['<'] = 1;
  149. X    tgrid['>'] = 1;
  150. X    tgrid['/'] = 1;
  151. X
  152. X}
  153. X
  154. Xchar *fetchWord()
  155. X
  156. X{
  157. X
  158. X    static char text[30];
  159. X    int ch;
  160. X    int tp = 1;
  161. X    char *txt;
  162. X
  163. X    while ( ( ( ch = getchar() ) != EOF ) && 
  164. X        ( ( isspace( ch ) || 
  165. X            isdigit( ch ) ||
  166. X            tgrid[ch] ) ) )
  167. X    ;
  168. X
  169. X    if ( ch != EOF ) {
  170. X
  171. X    text[0] = ch;
  172. X    if ( !ispunct( ch ) ) {
  173. X
  174. X        while ( ( ( isalnum( text[tp] = getchar() ) ) ||
  175. X             ( text[tp] == '\'' ) ) && ( tp < 30 ) )
  176. X        tp++;
  177. X        
  178. X        if ( ( text[0] != 'M' ) || 
  179. X         ( text[1] != 'r' ) ||
  180. X         ( text[2] != '.' ) )
  181. X        ungetc( text[tp], stdin );
  182. X        else
  183. X        tp++;
  184. X
  185. X    }
  186. X    
  187. X    text[tp] = '\0';
  188. X    
  189. X    txt = text;
  190. X
  191. X    } else
  192. X    txt = ( char *) NULL;
  193. X
  194. X    return txt;
  195. X
  196. X}
  197. X
  198. XWords *addWord( Words **w, char *word )
  199. X
  200. X{
  201. X
  202. X    Words *nw;
  203. X
  204. X    if ( !*w )
  205. X    *w = nw = newWord( word );
  206. X    else {
  207. X
  208. X    int s = strcmp( ( *w )->word, word );
  209. X
  210. X    if ( s < 0 )
  211. X        nw = addWord( &( *w )->after, word );
  212. X    else if ( s > 0 )
  213. X        nw = addWord( &( *w )->before, word );
  214. X    else
  215. X        nw = *w;
  216. X
  217. X    }
  218. X
  219. X    return nw;
  220. X
  221. X}
  222. X
  223. XWords *newWord( char *word )
  224. X
  225. X{
  226. X
  227. X    static int left = 0;
  228. X    static Words *w;
  229. X    
  230. X    wordcount++;
  231. X    if ( !left )
  232. X    w = ( Words *) calloc( sizeof( Words ), left = 32768 );
  233. X
  234. X    left--;
  235. X    ( w + left )->word = strdup( word );
  236. X    switch ( *word ) {
  237. X
  238. X      case '!':
  239. X      case '?':
  240. X      case '.': {
  241. X
  242. X      ( w + left )->class = FullStop;
  243. X      break;
  244. X
  245. X      }
  246. X      default: {
  247. X
  248. X      ( w + left )->class = ispunct( *word ) ? Punct : Word;
  249. X      break;
  250. X
  251. X      }
  252. X
  253. X    }
  254. X
  255. X    return ( w + left );
  256. X
  257. X}
  258. X
  259. Xvoid tally( Words *last, Words *wd )
  260. X
  261. X{
  262. X
  263. X    int i;
  264. X
  265. X    for ( i = 0; i < last->nfollows; i++ )
  266. X    if ( strcmp( last->follows[i]->word, wd->word ) == 0 ) {
  267. X
  268. X        ( *( last->counts + i ) )++;
  269. X        return;
  270. X
  271. X    }
  272. X
  273. X    if ( last->nfollows ) {
  274. X
  275. X    last->follows = ( Words **) realloc( last->follows, sizeof( Words *) *
  276. X                        ( last->nfollows + 1 ) );
  277. X    
  278. X    last->counts = ( int *) realloc( last->counts, sizeof( int ) *
  279. X                    ( last->nfollows + 1 ) );
  280. X    
  281. X    } else {
  282. X
  283. X    last->follows = ( Words **) malloc( sizeof( Words *) *
  284. X                        ( last->nfollows + 1 ) );
  285. X    
  286. X    last->counts = ( int *) malloc( sizeof( int ) *
  287. X                    ( last->nfollows + 1 ) );
  288. X
  289. X    }
  290. X    *( last->follows + last->nfollows ) = wd;
  291. X    *( last->counts + last->nfollows ) = 1;
  292. X    last->nfollows++;
  293. X
  294. X}
  295. X
  296. Xvoid erisify( Words *w, long paragraphs, long start )
  297. X
  298. X{
  299. X
  300. X    Words *lastword = chase( w, &start );
  301. X    int count = 0;
  302. X    int paralen = ( random() % 5 ) + 1;
  303. X    int capitalize = 1;
  304. X
  305. X    fsort( lastword );
  306. X
  307. X    printf( ".PP\n" );
  308. X    do {
  309. X
  310. X    Words *theword;
  311. X
  312. X    if ( lastword->nfollows && ( lastword->class != FullStop ) )
  313. X        theword = findNewWord( lastword );
  314. X    else
  315. X        do {
  316. X
  317. X        long where = random() % wordcount;
  318. X
  319. X        fsort( theword = chase( w, &where ) );
  320. X
  321. X        } while ( theword->class != Word );
  322. X    
  323. X    if ( capitalize )
  324. X        printf( "%c%s", toupper( *( lastword->word ) ), 
  325. X                              ( lastword->word + 1 ) );
  326. X    else
  327. X        printf( "%s", lastword->word );
  328. X
  329. X    if ( random() % 200 == 0 )
  330. X        printf( " fnord" );
  331. X    if ( ( theword->class != Punct ) &&
  332. X         ( theword->class != FullStop ) &&
  333. X         ( lastword->class != FullStop ) )
  334. X        printf( " " );
  335. X    if ( !( ++count % 5 ) && 
  336. X          ( theword->class != Punct ) &&
  337. X          ( theword->class != FullStop ) &&
  338. X          ( lastword->class != FullStop ) )
  339. X        printf( "\n" );
  340. X
  341. X    if ( lastword->class == FullStop ) {
  342. X
  343. X        printf( "\n" );
  344. X        if ( !( --paralen ) ) {
  345. X
  346. X        printf( ".PP\n" );
  347. X        count = 0;
  348. X        paralen = ( random() % 5 ) + 1;
  349. X        --paragraphs;
  350. X
  351. X        }
  352. X
  353. X    }
  354. X    capitalize = lastword->class == FullStop;
  355. X    fsort( lastword = theword );
  356. X
  357. X    } while ( paragraphs );
  358. X
  359. X}
  360. X
  361. XWords *chase( Words *w, long *count )
  362. X
  363. X{
  364. X
  365. X    Words *wd;
  366. X
  367. X    if ( w->before )
  368. X    wd = chase( w->before, count );
  369. X    if ( *count ) {
  370. X
  371. X    if ( --( *count ) == 0 )
  372. X        wd = w;
  373. X    else if ( w->after )
  374. X        wd = chase( w->after, count );
  375. X
  376. X    }
  377. X
  378. X    return wd;
  379. X
  380. X}
  381. X
  382. Xvoid fsort( Words *w )
  383. X
  384. X{
  385. X
  386. X    if ( !w->visited && w->nfollows ) {
  387. X
  388. X    int i;
  389. X    int wsum;
  390. X
  391. X    for ( i = 0; i < w->nfollows - 1; i++ ) {
  392. X
  393. X        int j;
  394. X
  395. X        for ( j = i + 1; j < w->nfollows; j++ ) {
  396. X
  397. X        if ( w->counts[i] < w->counts[j] ) {
  398. X
  399. X            int temp = w->counts[i];
  400. X            Words *wtemp = w->follows[i];
  401. X
  402. X            w->counts[i] = w->counts[j];
  403. X            w->follows[i] = w->follows[j];
  404. X            
  405. X            w->counts[j] = temp;
  406. X            w->follows[j] = wtemp;
  407. X
  408. X        }
  409. X
  410. X        }
  411. X
  412. X    }
  413. X
  414. X    wsum = w->counts[0];
  415. X    for ( i = 1; i < w->nfollows; i++ ) {
  416. X
  417. X        wsum += w->counts[i];
  418. X        w->counts[i] = wsum;
  419. X
  420. X    }
  421. X    w->visited = wsum;
  422. X
  423. X    }
  424. X
  425. X}
  426. X
  427. XWords *findNewWord( Words *w )
  428. X
  429. X{
  430. X
  431. X    if ( w->visited ) {
  432. X
  433. X    int rnum = random() % w->visited;
  434. X    int i;
  435. X
  436. X    for ( i = 0; i < w->nfollows - 1; i++ )
  437. X        if ( w->counts[i] > rnum )
  438. X        break;
  439. X    
  440. X    return w->follows[i];
  441. X
  442. X    }
  443. X
  444. X}
  445. SHAR_EOF
  446. chmod 0644 discord.c || echo "restore of discord.c fails"
  447. exit 0
  448.  
  449. exit 0 # in case we lose our brakes and skid...
  450.               - - - - that's it - - - -
  451. -- 
  452. Steve Lamont, SciViGuy -- (619) 534-7968 -- spl@szechuan.ucsd.edu
  453. UCSD Microscopy and Imaging Resource/UCSD Med School/La Jolla, CA 92093-0608
  454.                  "Tenants of the house,
  455. Thoughts of a dry brain in a dry season." - TS Eliot, "Gerontion"
  456.