engine/source/preprocessorlib/pp_parser.c
/**
 * Prints an error or warning message to the log file.
 * @param messageType the type of message ("error" or "warning")
 * @param message the actual message to display
 */
Prints an error or warning message to the log file.
@param messageType the type of message ("error" or "warning")
@param message the actual message to display
Prints an error or warning message to the log file . @param messageType the type of message ( " error " or " warning " ) @param message the actual message to display
void pp_message(pp_parser *self, char *messageType, char *message)
{
    pp_parser *parser = self;
    char buf[1024] = {""}, *linePtr;
    int bufPos, i;
    printf("\n\n");
    while(parser->parent)
    {
        parser = parser->parent;
    }
    while(parser->child && parser->child->type == PP_INCLUDE)
    {
        printf("In file included from %s, line %d:\n", parser->filename, parser->lexer.theTokenPosition.row);
        parser = parser->child;
    }
    printf("Script %s: %s, line %d: %s\n", messageType, parser->filename, parser->lexer.theTokenPosition.row, message);
    linePtr = parser->lexer.pcurChar - strlen(parser->lexer.theTokenSource);
    while(linePtr-- > parser->lexer.ptheSource)
        if(*linePtr == '\n' || *linePtr == '\r' || *linePtr == '\f')
        {
            break;
        }
    linePtr++;
    bufPos = 0;
    while(*linePtr != '\n' && *linePtr != '\r' && *linePtr != '\f' && *linePtr != '\0')
    {
        buf[bufPos++] = *linePtr++;
        if(bufPos >= sizeof(buf) - 1)
        {
            break;
        }
    }
    buf[bufPos] = '\0';
    printf("\n%s\n", buf);
    for(i = 0; i < parser->token.theTextPosition.col; i++)
    {
        printf(" ");
    }
    printf("^\n\n");
}
void pp_message ( pp_parser * self , char * messageType , char * message ) { pp_parser * parser = self ; char buf [ 1024 ] = { " " } , * linePtr ; int bufPos , i ; printf ( " \n \n " ) ; while ( parser -> parent ) { parser = parser -> parent ; } while ( parser -> child && parser -> child -> type == PP_INCLUDE ) { printf ( " \n " , parser -> filename , parser -> lexer . theTokenPosition . row ) ; parser = parser -> child ; } printf ( " \n " , messageType , parser -> filename , parser -> lexer . theTokenPosition . row , message ) ; linePtr = parser -> lexer . pcurChar - strlen ( parser -> lexer . theTokenSource ) ; while ( linePtr -- > parser -> lexer . ptheSource ) if ( * linePtr == ' \n ' || * linePtr == ' \r ' || * linePtr == ' \f ' ) { break ; } linePtr ++ ; bufPos = 0 ; while ( * linePtr != ' \n ' && * linePtr != ' \r ' && * linePtr != ' \f ' && * linePtr != ' \0 ' ) { buf [ bufPos ++ ] = * linePtr ++ ; if ( bufPos >= sizeof ( buf ) - 1 ) { break ; } } buf [ bufPos ] = ' \0 ' ; printf ( " \n \n " , buf ) ; for ( i = 0 ; i < parser -> token . theTextPosition . col ; i ++ ) { printf ( " " ) ; } printf ( " \n \n " ) ; }
Prints an error or warning message to the log file.
Prints an error or warning message to the log file .
// print a backtrace of #includes to make it clear exactly where this error/warning is occurring // print the error/warning and its location // find the start of the line that the error occurred on // write the line that the error/warning occurred on to the log file // print a position marker to show where in the line the error/warning occurred, just for completeness :)