home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / awk / awk320sr.zip / YYMAPC.C < prev    next >
Text File  |  1991-04-25  |  1KB  |  72 lines

  1. /*
  2.  *  yymapc -- handle escapes within strings
  3.  *
  4.  * Copyright (C) 1988, 1989, 1990, 1991 by Rob Duff
  5.  * All rights reserved
  6.  */
  7.  
  8. #include <stdio.h>
  9.  
  10. extern int yynext(void);
  11. extern void yyback(char);
  12. extern void yyerror(char*);
  13.  
  14. yymapc(delim, esc)
  15. {
  16.     register c, octv, n;
  17.  
  18. mapch:
  19.     if (delim != EOF) {
  20.         c = yynext();
  21.         if (c == EOF) {
  22.             yyerror("Unterminated string");
  23.             return(EOF);
  24.         }
  25.         if (c == delim)
  26.             return(EOF);
  27.         if (c == '\n')
  28.             yyerror("Newline in string");
  29.         if (c != esc)
  30.             return(c);
  31.     }
  32.     c = yynext();
  33.     switch (c) {
  34.     case '\n':
  35.         if (delim == EOF)
  36.             return(EOF);
  37.         goto mapch;
  38.     case 'e':
  39.         return('\e');
  40.     case 'f':
  41.         return('\f');
  42.     case 'n':
  43.         return('\n');
  44.     case 'p':
  45.         return(033);
  46.     case 'r':
  47.         return('\r');
  48.     case 't':
  49.         return('\t');
  50.     case '0':
  51.     case '1':
  52.     case '2':
  53.     case '3':
  54.     case '4':
  55.     case '5':
  56.     case '6':
  57.     case '7':
  58.         octv = c - '0';
  59.         for (n = 1; (c = yynext()) >= '0' && c<='7' && n <= 3; n++)
  60.             octv = octv * 010 + c - '0';
  61.         yyback(c);
  62.         return(octv);
  63.     case '\"':
  64.     case '\'':
  65.     default:
  66.         return(c);
  67.     }
  68. }
  69.  
  70. 
  71.  
  72.