home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d1xx / d101 / microspell.lha / MicroSpell / source.c < prev    next >
C/C++ Source or Header  |  1987-09-05  |  2KB  |  83 lines

  1. /*    SOURCE:    Source file processing for MicroSPELL 1.0
  2.         Spell Checker and Corrector
  3.  
  4.         (C)opyright May 1987 by Daniel Lawrence
  5.         All Rights Reserved
  6. */
  7.  
  8. #include    <stdio.h>
  9. #include    "dopt.h"
  10. #include    "dstruct.h"
  11. #include    "ddef.h"
  12.  
  13. WORD *getword()        /* get the next word in the input stream */
  14.  
  15. {
  16.     register char *wp;        /* ptr into word */
  17.     register int len;        /* length of word */
  18.  
  19.     static WORD rword;        /* word to return */
  20.     static char text[NSTRING];    /* text of word */
  21.     /*    text MUST immediatly follow rword for now */
  22.  
  23. nextfile:
  24.     /* first check if we need a new file */
  25.     if (srcfile == NULL) {
  26.         /* are we out of input files? */
  27.         if (++sfnum >= numspell)
  28.             return(NULL);
  29.  
  30.         /* open the next one! */
  31.         srcfile = fopen(splname[sfnum], "r");
  32.         if (srcfile == NULL) {
  33.             printf("%%Can not open input file '%s'\n",
  34.                 splname[sfnum]);
  35.             return(NULL);
  36.         }
  37.  
  38.         /* and make sure we are ready for more... */
  39.         iptr = NULL;
  40.         srcline = -1;
  41.     }
  42.  
  43.     /* skip off leading non-alphas */
  44.     if (iptr)
  45.         while (*iptr && !isletter(*iptr))
  46.             iptr++;
  47.  
  48. nextline:
  49.     /* time to read a new line? */
  50.     if (iptr == NULL || *iptr == 0) {
  51.         if (fgets(iline, MAXLINE - 1, srcfile) == NULL) {
  52.             fclose(srcfile);
  53.             srcfile = NULL;
  54.             goto nextfile;
  55.         }
  56.         iptr = iline;
  57.         srcline++;
  58.     }
  59.  
  60.     /* skip off leading non-alphas */
  61.     while (*iptr && !isletter(*iptr))
  62.         iptr++;
  63.  
  64.  
  65.     if (*iptr == 0)
  66.         goto nextline;
  67.  
  68.     /* and now set the word up */
  69.     wp = &rword.w_text[0];
  70.     rword.w_file = sfnum;
  71.     rword.w_line = srcline;
  72.     rword.w_col = iptr - &iline[0];
  73.     while (*iptr && isletter(*iptr))
  74.         *wp++ = *iptr++;
  75.  
  76.     /* terminate and return it... */
  77.     *wp = 0;
  78.     if (rword.w_text[1] == 0)
  79.         goto nextfile;
  80.  
  81.     return(&rword);
  82. }
  83.