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 >
Wrap
C/C++ Source or Header
|
1988-01-28
|
3KB
|
214 lines
/* this file contains the various routines used by
* the parser to find paths, integers, layernames, etc in
* the input
*/
#include "parser.h"
#define VAL(char) ( (int) ( char - '0'))
point *get_path()
{
point *ptr;
point *path;
path = get_point();
if (path != NIL(point)) {
ptr = path;
while ( (ptr->next = get_point()) != NIL(point)) {
ptr = ptr->next;
}
}
return(path);
}
point *get_point()
{
point *point_ptr;
flush(SEP);
point_ptr = ALLOC(point);
if ( (point_ptr->x = get_sinteger()) == INFINITE) {
free(point_ptr);
return(NIL(point));
}
if ( (point_ptr->y = get_sinteger()) == INFINITE) {
free(point_ptr);
error("missing second coordinate in point");
}
point_ptr->next = NIL(point);
return(point_ptr);
}
/* get a signed integer */
get_sinteger()
{
int sign = 1;
int val;
flush(SEP);
if (! IS(DIGIT,GET_CHAR)) {
if (current_char == '-') {
sign = -1;
GET_CHAR;
} else {
ungetc(current_char,infile);
return(INFINITE);
}
}
val = VAL(current_char);
while (IS(DIGIT,GET_CHAR)) {
if ( (MAX_INT - VAL(current_char))/10 < val ) {
error("integer out of range");
break;
}
val = 10*val + VAL(current_char);
}
ungetc(current_char,infile);
val *= sign;
return(val);
}
get_integer()
{
int val;
flush(SEP);
if (! IS(DIGIT,GET_CHAR)) {
ungetc(current_char,infile);
return(INFINITE);
}
val = VAL(current_char);
while (IS(DIGIT,GET_CHAR)) {
if ( (MAX_INT - VAL(current_char))/10 < val ) {
error("integer out of range");
break;
}
val = 10*val + VAL(current_char);
}
ungetc(current_char,infile);
return(val);
}
char *get_shortname()
{
int num = 0;
char *name;
name = (char *) malloc(5*sizeof(char));;
while ( IS(DIGIT | UPPER_CHAR,GET_CHAR) ) {
if ( num > 3 ) {
error("Layer name is too long");
}
name[num++] = current_char;
}
if ( num == 0 ) {
return(NIL(char));
}
name[num] = '\0';
ungetc(current_char,infile);
return(name);
}
transform *get_transterm()
{
transform *t;
t = ALLOC(transform);
flush(BLANK);
switch( GET_CHAR ) {
case 'T' :
t->type = TRANSLATE;
t->point = get_point();
if ( t->point == NIL(point) ) {
error(" point missing after translation ");
}
break;
case 'R' :
t->type = ROTATE;
t->point = get_point();
if ( t->point == NIL(point) ) {
error(" point missing after rotation ");
}
break;
case 'M' :
switch ( GET_CHAR ) {
case 'X' :
t->type = MIRROR_X;
t->point = NIL(point);
break;
case 'Y' :
t->type = MIRROR_Y;
t->point = NIL(point);
break;
default :
error("Bad Mirror option in transformation");
break;
}
default :
ungetc(current_char,infile);
return(NIL(transform));
}
return (t);
}
/*
* at the moment, since ciftomann doesn't use them, I simply
* throw away the transformation information
*/
get_transform()
{
while ( get_transterm() != NIL(transform) )
;
}
/*
* throw away input until something of type 'type' is found
*/
flush(type)
type_type type;
{
while ( IS(type,GET_CHAR) ) {
}
ungetc(current_char,infile);
}
static error(str)
char *str;
{
fprintf(stderr,"Fatal error at line %d : %s\n",line_number,str);
exit(1);
}