home *** CD-ROM | disk | FTP | other *** search
/ gdead.berkeley.edu / gdead.berkeley.edu.tar / gdead.berkeley.edu / pub / cad-tools / ciftomann.tar / edger_dir / parseprocs.c < prev    next >
C/C++ Source or Header  |  1988-01-28  |  3KB  |  214 lines

  1. /* this file contains the various routines used by
  2.  * the parser to find paths, integers, layernames, etc in
  3.  * the input
  4.  */
  5.  
  6. #include "parser.h"
  7.  
  8. #define VAL(char) ( (int) ( char - '0'))
  9.  
  10. point *get_path()
  11. {
  12.     point *ptr;
  13.     point *path;
  14.  
  15.     path = get_point();
  16.  
  17.     if (path != NIL(point)) {
  18.     ptr = path;
  19.     while ( (ptr->next = get_point()) != NIL(point)) {
  20.         ptr = ptr->next;
  21.     }
  22.     }
  23.  
  24.     return(path);
  25. }
  26.  
  27. point *get_point()
  28. {
  29.     point *point_ptr;
  30.  
  31.     flush(SEP);
  32.  
  33.     point_ptr = ALLOC(point);
  34.  
  35.     if ( (point_ptr->x = get_sinteger()) == INFINITE) {
  36.     free(point_ptr);
  37.     return(NIL(point));
  38.     }
  39.  
  40.     if ( (point_ptr->y = get_sinteger()) == INFINITE) {
  41.     free(point_ptr);
  42.     error("missing second coordinate in point");
  43.     }
  44.  
  45.     point_ptr->next = NIL(point);
  46.  
  47.     return(point_ptr);
  48. }
  49.  
  50.     /* get a signed integer */
  51.  
  52. get_sinteger()
  53. {
  54.     int sign = 1;
  55.     int val;
  56.  
  57.     flush(SEP);
  58.  
  59.     if (! IS(DIGIT,GET_CHAR)) {
  60.     if (current_char == '-') {
  61.         sign = -1;
  62.         GET_CHAR;
  63.     } else {
  64.         ungetc(current_char,infile);
  65.         return(INFINITE);
  66.     }
  67.     }
  68.  
  69.     val = VAL(current_char);
  70.     while (IS(DIGIT,GET_CHAR)) {
  71.     if ( (MAX_INT - VAL(current_char))/10  < val ) {
  72.         error("integer out of range");
  73.         break;
  74.     }
  75.  
  76.     val = 10*val + VAL(current_char);
  77.     }
  78.  
  79.     ungetc(current_char,infile);
  80.     val *= sign;
  81.     return(val);
  82. }
  83.  
  84. get_integer()
  85. {
  86.     int val;
  87.  
  88.     flush(SEP);
  89.  
  90.     if (! IS(DIGIT,GET_CHAR)) {
  91.     ungetc(current_char,infile);
  92.     return(INFINITE);
  93.     }
  94.  
  95.     val = VAL(current_char);
  96.     while (IS(DIGIT,GET_CHAR)) {
  97.     if ( (MAX_INT - VAL(current_char))/10  < val ) {
  98.         error("integer out of range");
  99.         break;
  100.     }
  101.  
  102.     val = 10*val + VAL(current_char);
  103.     }
  104.  
  105.     ungetc(current_char,infile);
  106.     return(val);
  107. }
  108.  
  109. char *get_shortname()
  110. {
  111.     int num = 0;
  112.     char *name;
  113.  
  114.     name = (char *) malloc(5*sizeof(char));;
  115.  
  116.     while ( IS(DIGIT | UPPER_CHAR,GET_CHAR) ) {
  117.     if ( num > 3 ) {
  118.         error("Layer name is too long");
  119.     }
  120.     name[num++] = current_char;
  121.     }
  122.  
  123.     if ( num == 0 ) {
  124.     return(NIL(char));
  125.     }
  126.  
  127.     name[num] = '\0';
  128.  
  129.     ungetc(current_char,infile);
  130.     return(name);
  131. }
  132.  
  133. transform *get_transterm()
  134. {
  135.     transform *t;
  136.  
  137.     t = ALLOC(transform);
  138.  
  139.     flush(BLANK);
  140.  
  141.     switch( GET_CHAR ) {
  142.  
  143.     case 'T' :
  144.         t->type = TRANSLATE;
  145.         t->point = get_point();
  146.         if ( t->point == NIL(point) ) {
  147.         error(" point missing after translation ");
  148.         }
  149.         break;
  150.  
  151.     case 'R' :
  152.         t->type = ROTATE;
  153.         t->point = get_point();
  154.         if ( t->point == NIL(point) ) {
  155.         error(" point missing after rotation ");
  156.         }
  157.         break;
  158.         
  159.     case 'M' :
  160.         switch ( GET_CHAR ) {
  161.  
  162.         case 'X' :
  163.             t->type = MIRROR_X;
  164.             t->point = NIL(point);
  165.             break;
  166.  
  167.         case 'Y' :
  168.             t->type = MIRROR_Y;
  169.             t->point = NIL(point);
  170.             break;
  171.  
  172.         default :
  173.             error("Bad Mirror option in transformation");
  174.             break;
  175.         }
  176.  
  177.     default :
  178.         ungetc(current_char,infile);
  179.         return(NIL(transform));
  180.     }
  181.  
  182.     return (t);
  183. }
  184.  
  185.     /*
  186.      * at the moment, since ciftomann doesn't use them, I simply
  187.      * throw away the transformation information
  188.      */
  189. get_transform()
  190. {
  191.     while ( get_transterm() != NIL(transform) )
  192.     ;
  193. }
  194.  
  195.     /*
  196.      * throw away input until something of type 'type' is found
  197.      */
  198.  
  199. flush(type)
  200. type_type type;
  201. {
  202.     while ( IS(type,GET_CHAR) ) {
  203.     }
  204.  
  205.     ungetc(current_char,infile);
  206. }
  207.  
  208. static error(str)
  209. char *str;
  210. {
  211.     fprintf(stderr,"Fatal error at line %d : %s\n",line_number,str);
  212.     exit(1);
  213. }
  214.