home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / CROSSASM / 68ASMSIM.ZIP / simsrc / scan.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-04-09  |  1.2 KB  |  61 lines

  1.  
  2. /***************************** 68000 SIMULATOR ****************************
  3.  
  4. File Name: SCAN.C
  5. Version: 1.0
  6.  
  7. This file contains the routine scan() which is used to scan strings that
  8. were input at the simulator command line.
  9.  
  10. ***************************************************************************/
  11.  
  12.  
  13. #include "extern.h"
  14.  
  15.  
  16. scan (str, ptrbuf, maxcnt)               /* scan up to maxcnt words in str */
  17. char    *str;
  18. char    *ptrbuf[];
  19. int    maxcnt;
  20. {
  21.     int count;
  22.     char qflag;
  23.  
  24.     count = 0;
  25.     qflag = 0;
  26.     while (*str)
  27.         {
  28.         if (*str == ';' && !qflag) break;        /* comment introducer */
  29.         if (count == maxcnt) break;                /* enough words scanned */
  30.         while (iswhite(*str++,&qflag));            /* flush leading white space */
  31.         if (*--str)
  32.             {
  33.             ptrbuf[count++] = str;
  34.             while (!iswhite(*++str,&qflag))        /* find end of */
  35.                 if (!*str) return(count);            /* non-white space */
  36.             *str++ = '\0';
  37.             }
  38.         }
  39.  
  40.     return count;
  41.  
  42. }
  43.  
  44.  
  45.  
  46. iswhite (c, qflag)
  47. char c, *qflag;
  48. {
  49.  
  50.     if (c == '\'') *qflag = ~*qflag;
  51.     if (*qflag) return(0);                    /* inside a pair of 'quotes' */
  52.     if (c == ' ') return(1);
  53.     if (c == '\t') return(1);
  54.     if (c == '\n') return(1);
  55.  
  56.     return (0);
  57.  
  58. }
  59.  
  60.  
  61.