home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Interactive Guide / c-cplusplus-interactive-guide.iso / c_ref / csource3 / 172_01 / mapch.c < prev    next >
Text File  |  1979-12-31  |  2KB  |  79 lines

  1. /*
  2.   HEADER:              CUG  nnn.nn;
  3.   TITLE:               LEX - A Lexical Analyser Generator
  4.   VERSION:             1.1 for IBM-PC
  5.   DATE:                Jan 30, 1985
  6.   DESCRIPTION:         A Lexical Analyser Generator. From UNIX
  7.   KEYWORDS:            Lexical Analyser Generator YACC C PREP
  8.   SYSTEM:              IBM-PC and Compatiables
  9.   FILENAME:            MAPCH.C
  10.   WARNINGS:            This program is not for the casual user. It will
  11.                        be useful primarily to expert developers.
  12.   CRC:                 N/A
  13.   SEE-ALSO:            YACC and PREP
  14.   AUTHORS:             Charles H. Forsyth
  15.                        Scott Guthery 11100 leafwood lane Austin, TX 78750
  16.                        Andrew M. Ward, Jr.  Houston, Texas (Modifications)
  17.   COMPILERS:           LATTICE C
  18.   REFERENCES:          UNIX Systems Manuals -- Lex Manual on distribution disks
  19. */
  20. /*
  21.  * Copyright (c) 1978 Charles H. Forsyth
  22.  *
  23.  */
  24.  
  25. /*
  26.  * mapch -- handle escapes within strings
  27.  */
  28.  
  29. #include "lex.h"
  30. extern FILE *lexin;
  31. extern int   yyline;
  32. extern int   lexchar(void);
  33. extern void  lexerror( char *);
  34.  
  35. int mapch(delim, esc)
  36. int delim;
  37. int esc;
  38. {
  39.     int c, octv, n;
  40.  
  41.     if ((c = lexchar())==delim)
  42.         return(EOF);
  43.     if (c==EOF || c=='\n') {
  44.         lexerror("Unterminated string");
  45.         ungetc(c, lexin);
  46.                 return(EOF);
  47.         }
  48.         if (c!=esc)
  49.         return(c);
  50.         switch (c=lexchar()) {
  51.         case 't':
  52.                 return('\t');
  53.         case 'n':
  54.                 return('\n');
  55.         case 'f':
  56.                 return('\f');
  57.         case '\"': case '\'':
  58.                 return(c);
  59.         case 'e':
  60.                 return('\e');
  61.         case 'p':
  62.                 return(033);
  63.         case 'r':
  64.                 return('\r');
  65.         case '0': case '1': case '2': case '3':
  66.         case '4': case '5': case '6': case '7':
  67.                 octv = c-'0';
  68.                 for (n = 1; (c = lexchar())>='0' && c<='7' && n<=3; n++)
  69.                         octv = octv*010 + (c-'0');
  70.         ungetc(c, lexin);
  71.                 return(octv);
  72.         case '\n':
  73.  
  74.                 yyline++;
  75.                 return(mapch(delim, esc));
  76.         }
  77.         return(c);
  78. }
  79.