1: /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
   2: /* hack.rumors.c - version 1.0.3 */
   3: 
   4: #include    <stdio.h>
   5: #include    "hack.h"        /* for RUMORFILE and BSD (index) */
   6: #define CHARSZ  8           /* number of bits in a char */
   7: extern long *alloc();
   8: extern char *index();
   9: int n_rumors = 0;
  10: int n_used_rumors = -1;
  11: char *usedbits;
  12: 
  13: init_rumors(rumf) register FILE *rumf; {
  14: register int i;
  15:     n_used_rumors = 0;
  16:     while(skipline(rumf)) n_rumors++;
  17:     rewind(rumf);
  18:     i = n_rumors/CHARSZ;
  19:     usedbits = (char *) alloc((unsigned)(i+1));
  20:     for( ; i>=0; i--) usedbits[i] = 0;
  21: }
  22: 
  23: skipline(rumf) register FILE *rumf; {
  24: char line[COLNO];
  25:     while(1) {
  26:         if(!fgets(line, sizeof(line), rumf)) return(0);
  27:         if(index(line, '\n')) return(1);
  28:     }
  29: }
  30: 
  31: outline(rumf) register FILE *rumf; {
  32: char line[COLNO];
  33: register char *ep;
  34:     if(!fgets(line, sizeof(line), rumf)) return;
  35:     if((ep = index(line, '\n')) != 0) *ep = 0;
  36:     pline("This cookie has a scrap of paper inside! It reads: ");
  37:     pline(line);
  38: }
  39: 
  40: outrumor(){
  41: register int rn,i;
  42: register FILE *rumf;
  43:     if(n_rumors <= n_used_rumors ||
  44:       (rumf = fopen(RUMORFILE, "r")) == (FILE *) 0) return;
  45:     if(n_used_rumors < 0) init_rumors(rumf);
  46:     if(!n_rumors) goto none;
  47:     rn = rn2(n_rumors - n_used_rumors);
  48:     i = 0;
  49:     while(rn || used(i)) {
  50:         (void) skipline(rumf);
  51:         if(!used(i)) rn--;
  52:         i++;
  53:     }
  54:     usedbits[i/CHARSZ] |= (1 << (i % CHARSZ));
  55:     n_used_rumors++;
  56:     outline(rumf);
  57: none:
  58:     (void) fclose(rumf);
  59: }
  60: 
  61: used(i) register int i; {
  62:     return(usedbits[i/CHARSZ] & (1 << (i % CHARSZ)));
  63: }

Defined functions

init_rumors defined in line 13; used 1 times
  • in line 45
outline defined in line 31; used 1 times
  • in line 56
outrumor defined in line 40; used 1 times
skipline defined in line 23; used 2 times
used defined in line 61; used 2 times

Defined variables

n_rumors defined in line 9; used 5 times
n_used_rumors defined in line 10; used 5 times
usedbits defined in line 11; used 4 times

Defined macros

CHARSZ defined in line 6; used 5 times
Last modified: 1985-10-01
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2464
Valid CSS Valid XHTML 1.0 Strict