main.c

来自「SRI international 发布的OAA框架软件」· C语言 代码 · 共 1,748 行 · 第 1/4 页

C
1,748
字号

	require(j<NumLexClasses, eMsgd("No label or expr for token %d",token));
	return "invalid";
}

                    /* S i m p l e  I n t  S t a c k */

void
#ifdef __USE_PROTOS
pushint( int i )
#else
pushint( i )
int i;
#endif
{
	require(isp>0, "pushint: stack overflow");
	istack[--isp] = i;
}

int
#ifdef __USE_PROTOS
popint( void )
#else
popint( )
#endif
{
	require(isp<MAX_INT_STACK, "popint: stack underflow");
	return istack[isp++];
}

int
#ifdef __USE_PROTOS
istacksize( void )
#else
istacksize( )
#endif
{
	return MAX_INT_STACK-isp;
}

void
#ifdef __USE_PROTOS
istackreset( void )
#else
istackreset( )
#endif
{
	isp = MAX_INT_STACK;
}

int
#ifdef __USE_PROTOS
istackempty( void )
#else
istackempty( )
#endif
{
	return isp==MAX_INT_STACK;
}

int
#ifdef __USE_PROTOS
topint( void )
#else
topint( )
#endif
{
	require(isp<MAX_INT_STACK, "topint: stack underflow");
	return istack[isp];
}

void
#ifdef __USE_PROTOS
ProcessArgs( int argc, char **argv, Opt *options )
#else
ProcessArgs( argc, argv, options )
int argc;
char **argv;
Opt *options;
#endif
{
	Opt *p;
	require(argv!=NULL, "ProcessArgs: command line NULL");

	while ( argc-- > 0 )
	{
		p = options;
		while ( p->option != NULL )
		{
			if ( strcmp(p->option, "*") == 0 ||
				 ci_strequ(p->option, *argv) == 1 )
			{
				if ( p->arg )
				{
/* MR9  26-Sep-97   Check for argv valid                */
                    if (argc-- > 0) {
  				     	(*p->process)( *argv, *(argv+1) );
					    argv++;
                    } else {
fprintf(stderr,"error: required argument for option %s omitted\n",*argv);
exit(PCCTS_EXIT_FAILURE);
                    };
				}
				else
					(*p->process)( *argv );
				break;
			}
			p++;
		}
		argv++;
	}
}

static void 
#ifdef __USE_PROTOS
CompleteContextGuards(void)
#else
CompleteContextGuards()
#endif
{
    ListNode *      p;
    Predicate *     pred;

    if (ContextGuardPredicateList == NULL) return;

    for (p=ContextGuardPredicateList->next; p != NULL; p=p->next) {
      pred=(Predicate *)p->elem;
      recomputeContextGuard(pred);
    }
}

/* Go back into the syntax diagram and compute all meta tokens; i.e.
 * turn all '.', ranges, token class refs etc... into actual token sets
 */
static void
#ifdef __USE_PROTOS
CompleteTokenSetRefs(void)
#else
CompleteTokenSetRefs()
#endif
{
	ListNode *p;

	if ( MetaTokenNodes==NULL ) return;
	for (p = MetaTokenNodes->next; p!=NULL; p=p->next)
	{
		set a,b;

		TokNode *q = (TokNode *)p->elem;
		if ( q->wild_card )
		{
			q->tset = all_tokens;
		}
		else if ( q->tclass!=NULL )
		{
			if ( q->complement ) q->tset = set_dif(all_tokens, q->tclass->tset);
			else q->tset = q->tclass->tset;
		}
		else if ( q->upper_range!=0 )
		{
			/* we have a range on our hands: make a set from q->token .. q->upper_range */
			int i;
			a = empty;
			for (i=q->token; i<=q->upper_range; i++) { set_orel(i, &a); }   /* MR13 */

/* MR13 */    if (q->complement) {
/* MR13 */      q->tset = set_dif(all_tokens, a);
/* MR13 */        set_free(a);
/* MR13 */      } else {
/* MR13 */	      q->tset = a;
/* MR13 */      }

        }

		/* at this point, it can only be a complemented single token */
		else if ( q->complement )
		{
			a = set_of(q->token);
			b = set_dif(all_tokens, a);
			set_free(a);
			q->tset=b;
		}
		else fatal("invalid meta token");
	}
}

/* MR10: Jeff Vincent
   MR10: Changed to remove directory information from n only if
   MR10: if OutputDirectory was changed by user (-o option)
*/

char *
#ifdef __USE_PROTOS
OutMetaName(char *n)
#else
OutMetaName(n)
char *n;
#endif
{	
    static char *dir_sym = DirectorySymbol;
    static char newname[MaxFileName+1];
    char *p;

	/* If OutputDirectory is same as TopDirectory (platform default) then leave n alone. */
    if (strcmp(OutputDirectory, TopDirectory) == 0)		/* TopDirectory is "." on Unix. */
		return n;

	/* p will point to filename without path information */
	if ((p = strrchr(n, *dir_sym)) != NULL)				/* Directory symbol is "/" on Unix. */
		p++;
	else
		p = n;

	/* Copy new output directory into newname[] */
	strcpy(newname, OutputDirectory);

	/* if new output directory does not have trailing dir_sym, add it! */
	if (newname[strlen(newname)-1] != *dir_sym) {
		strcat(newname, dir_sym);
	}
	strcat(newname, p);
	return newname;
}

char *
#ifdef __USE_PROTOS
pcctsBaseName(char *n) /* MR32 */
#else
pcctsBaseName(n)
char *n;
#endif
{
    static char newname[MaxFileName+1];
    static char* dir_sym = DirectorySymbol;
    int count = 0;
    char *p;

    p = n;

    while ( *p != '\0' )  {p++;}                    /* go to end of string */
    while ( (*p != *dir_sym) && (p != n) ) {--p;}   /* Find last DirectorySymbol */
    while ( *p == *dir_sym) p++;                    /* step forward if we're on a dir symbol */
    while ( *p != '\0' && *p != '.')
    {
        newname[count++] = *p;
        p++;
    }                                               /* create a new name */
    newname[count] = '\0';
    return newname;
}

static void
#ifdef __USE_PROTOS
ensure_no_C_file_collisions(char *class_c_file)
#else
ensure_no_C_file_collisions(class_c_file)
char *class_c_file;
#endif
{
	int i;

	for (i=0; i<NumFiles; i++)
	{

#ifdef PCCTS_CASE_INSENSITIVE_FILE_NAME
		/* assume that file names are case insensitive */
		if ( STRICMP(outname(FileStr[i]), class_c_file)==0 )
#else
		if ( strcmp(outname(FileStr[i]), class_c_file)==0 )
#endif
		{
			fatal(eMsg1("class def output file conflicts with parser output file: %s",
						outname(FileStr[i])));
		}
	}
}

void
#ifdef __USE_PROTOS
warnNoFL(char *err)
#else
warnNoFL(err)
char *err;
#endif
{
	fprintf(stderr, "warning: %s\n", err);
}

void
#ifdef __USE_PROTOS
warnFL(char *err,char *f,int l)
#else
warnFL(err,f,l)
char *f;
int l;
char *err;
#endif
{
	fprintf(stderr, ErrHdr, f, l);						
	fprintf(stderr, " warning: %s\n", err);
}

void
#ifdef __USE_PROTOS
warn(char *err)												
#else
warn(err)												
char *err;
#endif
{
	/* back up the file number if we hit an error at the end of the last file */
	if ( CurFile >= NumFiles && CurFile >= 1 ) CurFile--;
	fprintf(stderr, ErrHdr, FileStr[CurFile], zzline);
	fprintf(stderr, " warning: %s\n", err);
}

void
#ifdef __USE_PROTOS
warnNoCR( char *err )
#else
warnNoCR( err )											
char *err;
#endif
{
	/* back up the file number if we hit an error at the end of the last file */
	if ( CurFile >= NumFiles && CurFile >= 1 ) CurFile--;
	fprintf(stderr, ErrHdr, FileStr[CurFile], zzline);
	fprintf(stderr, " warning: %s", err);
}

void
#ifdef __USE_PROTOS
errNoFL(char *err)
#else
errNoFL(err)
char *err;
#endif
{
	fprintf(stderr, "error: %s\n", err);
}

void
#ifdef __USE_PROTOS
errFL(char *err,char *f,int l)
#else
errFL(err,f,l)
char *err;
char *f;
int l;
#endif
{
	fprintf(stderr, ErrHdr, f, l);						
	fprintf(stderr, " error: %s\n", err);
}

void
#ifdef __USE_PROTOS
err(char *err)												
#else
err(err)												
char *err;
#endif
{
	/* back up the file number if we hit an error at the end of the last file */
	if ( CurFile >= NumFiles && CurFile >= 1 ) CurFile--;
	fprintf(stderr, ErrHdr, FileStr[CurFile], zzline);
	fprintf(stderr, " error: %s\n", err);
}

void
#ifdef __USE_PROTOS
errNoCR( char *err )											
#else
errNoCR( err )											
char *err;
#endif
{
	/* back up the file number if we hit an error at the end of the last file */
	if ( CurFile >= NumFiles && CurFile >= 1 ) CurFile--;
	fprintf(stderr, ErrHdr, FileStr[CurFile], zzline);
	fprintf(stderr, " error: %s", err);
}

UserAction *
#ifdef __USE_PROTOS
newUserAction(char *s)
#else
newUserAction(s)
char *s;
#endif
{
	UserAction *ua = (UserAction *) calloc(1, sizeof(UserAction));
	require(ua!=NULL, "cannot allocate UserAction");

	ua->action = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char));
	strcpy(ua->action, s);
	return ua;
}

/* Added by TJP September 1994 */
/* Take in file.h and return file_h; names w/o '.'s are left alone */
char *
#ifdef __USE_PROTOS
gate_symbol(char *name)
#else
gate_symbol(name)
char *name;
#endif
{
	static char buf[100];
	char *p;
	sprintf(buf, "%s", name);

	for (p=buf; *p!='\0'; p++)
	{
		if ( *p=='.' ) *p = '_';
	}
	return buf;
}

char *
#ifdef __USE_PROTOS
makeAltID(int blockid, int altnum)
#else
makeAltID(blockid, altnum)
int blockid;
int altnum;
#endif
{
	static char buf[100];
	char *p;
	sprintf(buf, "_blk%d_alt%d", blockid, altnum);
	p = (char *)malloc(strlen(buf)+1);
	strcpy(p, buf);
	return p;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?