home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume5 / smallc / part2 / while.c < prev   
Encoding:
C/C++ Source or Header  |  1986-11-30  |  980 b   |  77 lines

  1. /*    File while.c: 2.1 (83/03/20,16:02:22) */
  2. /*% cc -O -c %
  3.  *
  4.  */
  5.  
  6. #include <stdio.h>
  7. #include "defs.h"
  8. #include "data.h"
  9.  
  10. addwhile (ptr)
  11. int    ptr[];
  12. {
  13.     int    k;
  14.  
  15.     if (wsptr == WSMAX) {
  16.         error ("too many active whiles");
  17.         return;
  18.     }
  19.     k = 0;
  20.     while (k < WSSIZ)
  21.         *wsptr++ = ptr[k++];
  22. }
  23.  
  24. delwhile ()
  25. {
  26.     if (readwhile ())
  27.         wsptr = wsptr - WSSIZ;
  28. }
  29.  
  30. readwhile ()
  31. {
  32.     if (wsptr == ws) {
  33.         error ("no active do/for/while/switch");
  34.         return (0);
  35.     } else
  36.         return (wsptr-WSSIZ);
  37. }
  38.  
  39. findwhile ()
  40. {
  41.     int    *ptr;
  42.  
  43.     for (ptr = wsptr; ptr != ws;) {
  44.         ptr = ptr - WSSIZ;
  45.         if (ptr[WSTYP] != WSSWITCH)
  46.             return (ptr);
  47.     }
  48.     error ("no active do/for/while");
  49.     return (0);
  50. }
  51.  
  52. readswitch ()
  53. {
  54.     int    *ptr;
  55.  
  56.     if (ptr = readwhile ())
  57.         if (ptr[WSTYP] == WSSWITCH)
  58.             return (ptr);
  59.     return (0);
  60. }
  61.  
  62. addcase (val)
  63. int    val;
  64. {
  65.     int    lab;
  66.  
  67.     if (swstp == SWSTSZ)
  68.         error ("too many case labels");
  69.     else {
  70.         swstcase[swstp] = val;
  71.         swstlab[swstp++] = lab = getlabel ();
  72.         printlabel (lab);
  73.         col ();
  74.         nl ();
  75.     }
  76. }
  77.