Exemplo n.º 1
0
Arquivo: font.c Projeto: 7890/shout
//--------------------------------
void expand_string(char *s)
{
	int i=0;
	char c;
	//while there are more chars in null-terminated encoded spf line string
	while((c=s[i]) != '\0')
	{
		expand_char(c);
		i++;
	}
}
Exemplo n.º 2
0
int GetToken(void) 
{
	/* skip white space and comment */
    while( isspace(nextch)  || ('/' == nextch)) {
		if (nextch == '\n') {			
			lineno++;
		}
		/* skip comment */
		if( nextch == '/') {			
		    nextch=getc(infile);
			if(nextch == '/')
			{ /* eat to end of line */
				do { nextch=getc(infile); 
					} while(nextch != '\n');
					lineno++;
			}
			else if(nextch == '*')
				scanComment();
			else  {				
				return('/');
			}
		}			
		nextch = getc(infile);
    }
		
    if (nextch == EOF) 	return( T_EOF);
   		
	if (isalpha (nextch) || nextch == '_' ) /*scan identifier */
	{	char *s = lexeme;        
		do {
				*s = nextch; s++;
				nextch = getc(infile);				
		} while( isalpha(nextch) || isdigit( nextch ) || (nextch == '_' ) );
		*s = '\0';
		return ID;
	}

	switch (nextch)
	{
		case  ':'  :  nextch = getc(infile); return COLON;
		case  ';'  :  nextch = getc(infile); return SEMI;
		case  '|'  :  nextch = getc(infile); return BAR;
		case  '('  :  nextch = getc(infile); return LPAREN;
		case  ')'  :  nextch = getc(infile); return RPAREN;		
		case  '*'  :  nextch = getc(infile); return STAR;		
		case  '?'  :  nextch = getc(infile); return QUEST;						
		case  '+'  :  nextch = getc(infile); return PLUS;						
		case  '{'  :  nextch = getc(infile); return LBRACE;
		case  '}'  :  nextch = getc(infile); return RBRACE;		
		case  ','  :  nextch = getc(infile); return COMMA;		
		case  '%'  :  nextch = getc(infile);
					  if (nextch == '%') {
						nextch = getc(infile);
						strcpy(lexeme, "%%" );
						return END_SPEC;
					  } else if(isalpha(nextch)) {
						char *s = lexeme;    			
						do {
							*s++ = nextch;
							nextch = getc(infile);				
						} while(isalpha(nextch));
						*s = '\0';			
						if (strcmp(lexeme, "token") == 0) {
							return TOKEN_SPEC;
						} else { 
							SyntaxError("Unknown directive");
							return( BAD_TOKEN );
						}
					  } else
					  return( BAD_TOKEN );
		
		case '\"': /*multichar token "token" or single char "c" */
			{
			char *s = lexeme;
			while (nextch != EOF) {
				nextch = toupper(getc(infile));				
				while (nextch <= ' ' )
					nextch = toupper(getc(infile));				
				if (nextch == '\"'){
					nextch = getc(infile); 
					break;
				}
				*s = nextch; s++;				
			};				
			*s = '\0';
			if (strlen(lexeme) == 1) { /*single char*/
				expand_char(lexeme, lexeme[1]);
				return CHR_LIT;
			}
			else
			  return ID;	
			} 
		/* single char token 'c'*/
		case '\'': 
			expand_char(lexeme, getc(infile));
			nextch = getc(infile);
			if (nextch != '\'') {
				SyntaxError("Single char token must be terminated with \'.");	
				return(BAD_TOKEN);
			} else {
				nextch = getc(infile);
				return CHR_LIT;
			}
	}						
    return BAD_TOKEN;
}