Пример #1
0
bool JsonIn::skip_member()
{
    skip_string();
    skip_pair_separator();
    skip_value();
    return skip_separator();
}
Пример #2
0
void JsonIn::skip_array()
{
    char ch;
    int brackets = 1;
    eat_whitespace();
    stream->get(ch);
    if (ch != '[') {
        std::stringstream err;
        err << line_number(-1) << ": expected array but found '" << ch << "'";
        throw err.str();
    }
    while (brackets && stream->good()) {
        stream->get(ch);
        // ignore everything inside strings
        if (ch == '"') {
            stream->unget();
            skip_string();
        // otherwise count opening and closing brackets until they all match
        } else if (ch == '[') {
            brackets += 1;
        } else if (ch == ']') {
            brackets -= 1;
        }
    }
    if (brackets != 0) {
        // something messed up!
        std::stringstream err;
        err << "couldn't find end of array!";
        err << " " << brackets << " bracket(s) left.";
        throw err.str();
    }
    skip_separator();
}
Пример #3
0
void JsonIn::skip_value()
{
    char ch;
    eat_whitespace();
    ch = peek();
    // it's either a string '"'
    if (ch == '"') {
        skip_string();
    // or an object '{'
    } else if (ch == '{') {
        skip_object();
    // or an array '['
    } else if (ch == '[') {
        skip_array();
    // or a number (-0123456789)
    } else if (ch == '-' || (ch >= '0' && ch <= '9')) {
        skip_number();
    // or "true", "false" or "null"
    } else if (ch == 't') {
        skip_true();
    } else if (ch == 'f') {
        skip_false();
    } else if (ch == 'n') {
        skip_null();
    // or an error.
    } else {
        std::stringstream err;
        err << line_number() << ": expected JSON value but got '" << ch << "'";
        throw err.str();
    }
    skip_separator();
}
Пример #4
0
void JsonIn::skip_member()
{
    skip_string();
    skip_pair_separator();
    skip_value();
    skip_separator();
}
Пример #5
0
double JsonIn::get_float()
{
    // this could maybe be prettier?
    char ch;
    bool neg = false;
    int i = 0;
    int e = 0;
    int mod_e = 0;
    eat_whitespace();
    stream->get(ch);
    if (ch == '-') {
        neg = true;
        stream->get(ch);
    }
    while (ch >= '0' && ch <= '9') {
        i *= 10;
        i += (ch - '0');
        stream->get(ch);
    }
    if (ch == '.') {
        stream->get(ch);
        while (ch >= '0' && ch <= '9') {
            i *= 10;
            i += (ch - '0');
            mod_e -= 1;
            stream->get(ch);
        }
    }
    if (neg) {
        i *= -1;
    }
    if (ch == 'e' || ch == 'E') {
        stream->get(ch);
        neg = false;
        if (ch == '-') {
            neg = true;
            stream->get(ch);
        } else if (ch == '+') {
            stream->get(ch);
        }
        while (ch >= '0' && ch <= '9') {
            e *= 10;
            e += (ch - '0');
            stream->get(ch);
        }
        if (neg) {
            e *= -1;
        }
    }
    skip_separator();
    // now put it all together!
    return i * pow(10.0f, static_cast<float>(e + mod_e));
}
Пример #6
0
void JsonIn::skip_true()
{
    char text[5];
    eat_whitespace();
    stream->get(text, 5);
    if (strcmp(text, "true") != 0) {
        std::stringstream err;
        err << line_number(-4) << ": expected \"true\", but found \"" << text << "\"";
        throw err.str();
    }
    skip_separator();
}
Пример #7
0
bool JsonIn::skip_false()
{
    char text[6];
    eat_whitespace();
    stream->get(text, 6);
    if (strcmp(text, "false") != 0) {
        std::stringstream err;
        err << line_number(-5) << ": expected \"false\", but found \"" << text << "\"";
        throw err.str();
    }
    return skip_separator();
}
Пример #8
0
bool JsonIn::skip_null()
{
    char text[5];
    eat_whitespace();
    stream->get(text, 5);
    if (strcmp(text, "null") != 0) {
        std::stringstream err;
        err << line_number(-4) << ": expected \"null\", but found \"" << text << "\"";
        throw err.str();
    }
    return skip_separator();
}
Пример #9
0
bool JsonIn::get_bool()
{
    char ch;
    char text[5];
    int pos = tell();
    std::stringstream err;
    eat_whitespace();
    stream->get(ch);
    if (ch == 't') {
        stream->get(text, 4);
        if (strcmp(text, "rue") == 0) {
            skip_separator();
            return true;
        } else {
            err << line_number(-4) << ": ";
            err << "not a boolean. expected \"true\", but got \"";
            err << ch << text << "\"";
            seek(pos);
            throw err.str();
        }
    } else if (ch == 'f') {
        stream->get(text, 5);
        if (strcmp(text, "alse") == 0) {
            skip_separator();
            return false;
        } else {
            err << line_number(-5) << ": ";
            err << "not a boolean. expected \"false\", but got \"";
            err << ch << text << "\"";
            seek(pos);
            throw err.str();
        }
    }
    err << line_number(-1) << ": ";
    err << "not a boolean value! expected 't' or 'f' but got '" << ch << "'";
    seek(pos);
    throw err.str();
}
Пример #10
0
bool JsonIn::skip_number()
{
    char ch;
    eat_whitespace();
    // skip all of (+-0123456789.eE)
    while (stream->good()) {
        stream->get(ch);
        if (ch != '+' && ch != '-' && (ch < '0' || ch > '9') &&
                ch != 'e' && ch != 'E' && ch != '.') {
            stream->unget();
            return (ch==',');
        }
    }
    return skip_separator();
}
Пример #11
0
void JsonIn::skip_array()
{
    char ch;
    int brackets = 1;
    eat_whitespace();
    int startpos = tell();
    stream->get(ch);
    if (ch != '[') {
        std::stringstream err;
        err << line_number(-1) << ": expected array but found '" << ch << "'";
        throw err.str();
    }
    while (brackets && stream->good()) {
        stream->get(ch);
        // ignore everything inside strings
        if (ch == '"') {
            stream->unget();
            skip_string();
        // otherwise count opening and closing brackets until they all match
        } else if (ch == '[') {
            brackets += 1;
        } else if (ch == ']') {
            brackets -= 1;
        }
    }
    if (brackets != 0) {
        // something messed up!
        std::stringstream err;
        if (stream->fail()) {
            throw (std::string)"stream failure while reading array.";
        } else if (stream->eof()) {
            stream->clear();
            seek(startpos);
            err << line_number() << ": ";
            err << "couldn't find end of array, reached EOF with ";
            err << brackets << " bracket(s) left.";
            throw err.str();
        } else { // this should be impossible
            err << line_number() << " ";
            seek(startpos);
            err << "(" << line_number() << "): ";
            err << "array brackets didn't match?";
            err << " " << brackets << " bracket(s) left.";
            throw err.str();
        }
    }
    skip_separator();
}
Пример #12
0
bool JsonIn::skip_string()
{
    char ch;
    eat_whitespace();
    stream->get(ch);
    if (ch != '"') {
        std::stringstream err;
        err << line_number(-1) << ": expecting string but found '" << ch << "'";
        throw err.str();
    }
    while (stream->good()) {
        stream->get(ch);
        if (ch == '\\') {
            stream->get(ch);
            continue;
        } else if (ch == '"') {
            break;
        }
    }
    return skip_separator();
}
Пример #13
0
bool JsonIn::skip_object()
{
    char ch;
    bool lastsep = false;
    int brackets = 1;
    eat_whitespace();
    int startpos = tell();
    stream->get(ch);
    if (ch != '{') {
        std::stringstream err;
        err << line_number(-1) << ": expected object but found '" << ch << "'";
        throw err.str();
    }
    while (brackets && stream->good()) {
        stream->get(ch);
        // ignore everything inside strings
        if (ch == '"') {
            stream->unget();
            lastsep = skip_string();
        // otherwise count opening and closing brackets until they all match
        } else if (ch == '{') {
            brackets += 1;
            lastsep = false;
        } else if (ch == '}') {
            brackets -= 1;
            if ( strict && lastsep ) {
                std::stringstream err;
                std::string txt;
                int errpos = tell();
                err << line_number(-1) << ": trailing comma: ";
                stream->seekg(startpos);
                stream->read(&txt[0],errpos-startpos);
                err << txt;
                throw err.str();                 
            }
            lastsep = false;
        } else if (!is_whitespace(ch)) {
            lastsep = false;
        }
    }
    if (brackets != 0) {
        // something messed up!
        std::stringstream err;
        if (stream->fail()) {
            throw (std::string)"stream failure while reading object.";
        } else if (stream->eof()) {
            stream->clear();
            seek(startpos);
            err << line_number() << ": ";
            err << "couldn't find end of object, reached EOF with ";
            err << brackets << " bracket(s) left.";
            throw err.str();
        } else { // this should be impossible
            err << line_number() << " ";
            seek(startpos);
            err << "(" << line_number() << "): ";
            err << "object brackets didn't match?";
            err << " " << brackets << " bracket(s) left.";
            throw err.str();
        }
    }
    return skip_separator();
}
Пример #14
0
list<str *> *str::split(str *sp, int max_splits) {
    __GC_STRING s = unit;
    int num_splits = 0;
    int sep_iter = 0, tmp, chunk_iter = 0;
    list<str *> *result = new list<str *>();
    if (sp == NULL)
    {
#define next_separator(iter) (s.find_first_of(ws, (iter)))
#define skip_separator(iter) (s.find_first_not_of(ws, (iter)))

        if(skip_separator(chunk_iter) == -1) /* XXX */
            return result;
        if(next_separator(chunk_iter) == 0)
            chunk_iter = skip_separator(chunk_iter);
        while((max_splits < 0 or num_splits < max_splits)
              and ((sep_iter = next_separator(chunk_iter)) != -1))
        {
            result->append(new str(s.substr(chunk_iter, sep_iter - chunk_iter)));
            if((tmp = skip_separator(sep_iter)) == -1) {
                chunk_iter = sep_iter;
                break;
            } else
                chunk_iter = tmp;
            ++num_splits;
        }
        if(not (max_splits < 0 or num_splits < max_splits))
            result->append(new str(s.substr(chunk_iter, s.size()-chunk_iter)));
        else if(sep_iter == -1)
            result->append(new str(s.substr(chunk_iter, s.size()-chunk_iter)));

#undef next_separator
#undef skip_separator

    } else { /* given separator (slightly different algorithm required)
              * (python is very inconsistent in this respect) */
        const char *sep = sp->unit.c_str();
        int sep_size = sp->unit.size();

#define next_separator(iter) s.find(sep, (iter))
#define skip_separator(iter) ((iter + sep_size) > s.size()? -1 : (iter + sep_size))

        if (max_splits == 0) {
            result->append(this);
            return result;
        }
        if(next_separator(chunk_iter) == 0) {
            chunk_iter = skip_separator(chunk_iter);
            result->append(new str());
            ++num_splits;
        }
        while((max_splits < 0 or num_splits < max_splits)
              and (sep_iter = next_separator(chunk_iter)) != -1)
        {
            result->append(new str(s.substr(chunk_iter, sep_iter - chunk_iter)));
            if((tmp = skip_separator(sep_iter)) == -1) {
                chunk_iter = sep_iter;
                break;
            } else
                chunk_iter = tmp;
            ++num_splits;
        }
        if(not (max_splits < 0 or num_splits < max_splits))
            result->append(new str(s.substr(chunk_iter, s.size()-chunk_iter)));
        else if(sep_iter == -1)
            result->append(new str(s.substr(chunk_iter, s.size()-chunk_iter)));


#undef next_separator
#undef skip_separator

    }

    return result;
}
Пример #15
0
void process_dialog_declaration( FILE *fi, FILE *fo, char *line )
/***************************************************************/
{
    long    font_size = 0;
    char    *font_name = NULL;
    char    *separators = " \t,|";
    int     font_set = 0;
    int     hidden_dialog = 0;
    char    *buff1;
    char    *p;
    char    **p2;
    size_t  len;
    int     sysmodal, visible;
    int     i;
    
    ++dialogs_cnt;
    if( opt.quiet == 0 ) {
        fprintf( stdout, "." );
    }
    // process DIALOG line
    buff1 = malloc( MAX_LINE_LEN );
    strcpy( buff1, skip_separator( line ) );
    p = strtok( buff1, separators );
    if( p != NULL )
        strcpy( dlg_hdr.ID, p );
    p = strtok( NULL, " ,\t" );
    while(( p != NULL ) && !isdigit( *p ) )
        p = strtok( NULL, separators );
    if( p != NULL )
        dlg_hdr.x = atoi( p ) * CONV_X;
    p = strtok( NULL, separators );
    if( p != NULL )
        dlg_hdr.y = atoi( p ) * CONV_Y;
    p = strtok( NULL, separators );
    if( p != NULL )
        dlg_hdr.dx = atoi( p ) * CONV_X;
    p = strtok( NULL, separators );
    if( p != NULL )
        dlg_hdr.dy = atoi( p ) * CONV_Y;
    dlg_hdr.y = 230 - dlg_hdr.y - dlg_hdr.dy;
    strcpy( dlg_hdr.text, "\"\"" );
    // process next lines
    my_fgets( line, MAX_LINE_LEN, fi );
    while(( *line != '\0' ) && ( strstr( line, "BEGIN" ) == NULL )) {
        strcpy( buff1, line );
        strtok( buff1, separators );
        if( strstr( line, "STYLE" ) != NULL ) {
            add_parms_list( &dlg_hdr, separators, 1 );
            len = strlen( line );
            for( p = line + len - 1; len && isspace( *p ); --len )
                *(p--) = '\0';
            if( *p == '|' ) {
                my_fgets( line, MAX_LINE_LEN, fi );
                strcpy( buff1, line );
                p = strtok( buff1, separators );
                while( p != NULL ) {
                    add_parms_item( dlg_hdr.parms, p, ADD_AFTER );
                    p = strtok( NULL, separators );
                }
            }
        } else if( (p = strstr( line, "CAPTION" )) != NULL ) {
            strcpy( dlg_hdr.text, p + 8 );
            dlg_hdr.text[ strlen( dlg_hdr.text ) ] = '\0';
        } else if( strstr( line, "FONT" ) != NULL ) {
            font_set = 1;
            p = strtok( NULL, separators );
            font_size = strtol( p, &p, 10 );
            p = strtok( NULL, "\"" );
            p = strtok( NULL, "\"" );
            if( opt.font ) {
                font_name = malloc( strlen( opt.font_name ) + 1 );
                strcpy( font_name, opt.font_name );
                if( opt.font_size != 0 ) {
                    font_size = opt.font_size;
                }
            } else {
                if( p != NULL ) {
                    font_name = malloc( strlen( p ) + 10 );
                    strcpy( font_name, p );
                    p2 = malloc( sizeof(char *) );
                    *p2 = font_name;
                    convert_font( p2, 1 );
                    free( p2 );
                }
            }
        }
        my_fgets( line, MAX_LINE_LEN, fi );
    }
    process_style( dlg_hdr.parms, "DIALOG" );
    if( font_set == 0 ) {
        font_name = malloc( 7 );
        strcpy( font_name, "Helv" );
        font_size = 10;
    }
    sysmodal = process_parms( dlg_hdr.parms, MAX_STMT_PARMS, control_class_win,
        control_class_os2, CTRL_NAME_CNT, 0, check_parm_item, "FCF_SYSMODAL" );
    if( opt.hide ) {
        for( i = 0; i < opt.flist_cnt; ++i ) {
            if( stricmp( dlg_hdr.ID, opt.flist_data[ i ] ) == 0 ) {
                hidden_dialog = 1;
                break;
            }
        }
    }
    visible = process_parms( dlg_hdr.parms, MAX_STMT_PARMS, control_class_win,
        control_class_os2, CTRL_NAME_CNT, 0, check_parm_item, "WS_VISIBLE" );
    fprintf( fo, "DLGTEMPLATE %s\n", dlg_hdr.ID );
    fprintf( fo, "BEGIN\n%sDIALOG %s, %s, %d, %d, %d, %d, ", STR_SPC, dlg_hdr.text,
               dlg_hdr.ID, dlg_hdr.x, dlg_hdr.y, dlg_hdr.dx, dlg_hdr.dy );
    if( hidden_dialog ) {
        fprintf( fo, "FS_BORDER | NOT FS_DLGBORDER | NOT WS_VISIBLE\n" );
    } else {
#if defined( OLD_FORMAT )
        if( sysmodal && visible ) {
            fprintf( fo, "FS_SYSMODAL\n\t\t| WS_VISIBLE" );
        } else if( sysmodal ) {
            fprintf( fo, "FS_SYSMODAL\n\t\t" );
        } else if( visible ) {
            fprintf( fo, "WS_VISIBLE\n\t\t" );
        } else {
            fprintf( fo, "0L\n\t\t" );
        }
#else
        if( sysmodal && visible ) {
            fprintf( fo, "\n\t\tFS_SYSMODAL | WS_VISIBLE" );
        } else if( sysmodal ) {
            fprintf( fo, "\n\t\tFS_SYSMODAL" );
        } else if( visible ) {
            fprintf( fo, "\n\t\tWS_VISIBLE" );
        } else {
            fprintf( fo, "\n\t\t0L" );
        }
#endif
        out_parms_style( fo, dlg_hdr.parms, "DIALOG" );
    }
    if(( font_name != NULL ) || ( font_size != 0 )) {
        fprintf( fo, "%sPRESPARAMS PP_FONTNAMESIZE, ", STR_SPC );
        if( font_size != 0 ) {
            fprintf( fo, "\"%ld.%s\"\n", font_size, font_name );
        } else {
            fprintf( fo, "\"%s\"\n", font_name );
        }
        free( font_name );
    }
    fprintf( fo, "%sBEGIN\n", STR_SPC );
    free( buff1 );
}
Пример #16
0
int process_statement( char *line, FILE *fo )
/*******************************************/
{
    char    *separators = " ,\t|";
    char    buff1[ MAX_LINE_LEN + 1 ];
    int     len = 0;
    char    *p;
    
    if( *line == '\0' )
        return( 0 );
    strcpy( buff1, skip_separator( line ) );
    p = strtok( buff1, " ,\t|" );
    if( p != NULL )
        strcpy( dlg_item.name, p );
    if( strncmp( dlg_item.name, "END", 3 ) == 0 ) {
        fprintf( fo, "%s%s\nEND\n", STR_SPC, dlg_item.name );
        return( 1 );
    }
    if( strcmp( dlg_item.name, "CONTROL" ) == 0 ) {
        p = skip_keyword( line, &len );
        if( p != NULL ) {
            strncpy( dlg_item.text, p, len );
            dlg_item.text[ len ] = '\0';
            p += len;
        }
        p = strtok( p, separators );
        if( p != NULL ) {
            strcpy( dlg_item.ID, p );
        } else {
            strcpy( dlg_item.ID, "-1" );
        }
        convert_buttons( dlg_item.ID, dlg_item.name, 1 );
        add_parms_list( &dlg_item, separators, 0 );
        get_rectangle_parms( &dlg_item );
    } else {
        if(( strcmp( dlg_item.name, "COMBOBOX" ) == 0 )
            || ( strcmp( dlg_item.name, "LISTBOX" ) == 0 )
            || ( strcmp( dlg_item.name, "SCROLLBAR" ) == 0 )
            || ( strcmp( dlg_item.name, "EDITTEXT" ) == 0 )) {
            strcpy( dlg_item.text, "\"\"" );
            p = NULL;
        } else {
            p = skip_keyword( line, &len );
            if( p != NULL ) {
                strncpy( dlg_item.text, p, len );
                dlg_item.text[ len ] = '\0';
                p += len;
                convert_buttons( dlg_item.text, dlg_item.text, 0 );
            } else {
                strcpy( dlg_item.text, "\"\"" );
                p = NULL;
            }
        }
        p = strtok( p, separators );
        if( p != NULL ) {
            strcpy( dlg_item.ID, p );
        } else {
            strcpy( dlg_item.ID, "-1" );
        }
        convert_buttons( dlg_item.ID, dlg_item.name, 1 );
        get_rectangle_list( &dlg_item, separators );
        add_parms_list( &dlg_item, separators, 0 );
    }
    if( !strcmp( dlg_item.name, "SCROLLBAR" ) ) {
        add_parms_item( dlg_item.parms, "WC_SCROLLBAR", ADD_BEFORE );
    }
    process_style( dlg_item.parms, dlg_item.name );
    dlg_item.y = dlg_hdr.dy - dlg_item.y - dlg_item.dy;
    fprintf( fo, "%s%s", STR_SPC STR_SPC, dlg_item.name );
    if( strlen( dlg_item.name ) < 8 )
        fprintf( fo, "\t" );
    fprintf( fo, "\t" );
    if( strcmp( dlg_item.name, "LISTBOX" ) )
        fprintf( fo, "%s, ", dlg_item.text );
    fprintf( fo, "%s, %d, %d, %d, %d", dlg_item.ID, dlg_item.x,
                          dlg_item.y, dlg_item.dx, dlg_item.dy );
    out_parms_style( fo, dlg_item.parms, dlg_item.name );
    out_color_style( fo, &dlg_item );
    return( 0 );
}
Пример #17
0
int main( int argc, char *argv[] )
/********************************/
{
    char    fname[ PATH_MAX ];
    FILE    *fi;
    FILE    *fo;
    char    *p;
    int     i;
    char    *line;
    char    *buff1;
    char    *buff2;
    char    *separators = " \t";
    
    i = process_cmdl( argc, argv );
    if( i == 0 ) {
        disp_usage();
        return( -1 );
    }
    strcpy( fname, argv[ i ] );
    if( strrchr( fname, '.' ) == NULL )
        strcat( fname, ".dlg" );
    fi = fopen( fname, "r" );
    if( fi == NULL ) {
        printf( "Could not open input file: %s\n", fname );
        return( -1 );
    }
    if( i + 1 < argc ) {
        strcpy( fname, argv[ i + 1 ] );
        if( strrchr( fname, '.' ) == NULL ) {
            strcat( fname, ".dlg" );
        }
    } else {
        strcpy( fname, "os2dlg.dlg" );
    }
    fo = fopen( fname, "w" );
    if( fo == NULL ) {
        printf( "Could not open input file: %s\n", fname );
        return( -1 );
    }
    
    alloc_statement( &dlg_hdr );
    alloc_statement( &dlg_item );

    line = malloc( MAX_LINE_LEN );
    
    buff1 = malloc( MAX_LINE_LEN );
    buff2 = malloc( MAX_LINE_LEN );
    
    my_fgets( line, MAX_LINE_LEN, fi );
    while( !feof( fi ) ) {
        while( !feof( fi ) ) {
            if( strstr( line, "DLGINCLUDE" ) != NULL ) {
                /**********************
                 * source file format:
                 *
                 * DLGINCLUDE
                 * BEGIN
                 * filename
                 * END
                 *
                 * converted to:
                 *
                 * DLGINCLUDE 1 filename
                 */
                p = malloc( MAX_LINE_LEN );
                strcpy( p, line );
                fprintf( fo, "%s 1 ", strtok( p, separators ) );
                my_fgets( line, MAX_LINE_LEN, fi );
                my_fgets( line, MAX_LINE_LEN, fi );
                strcpy( p, line );
                fprintf( fo, "%s\n", strtok( p, separators ) );
                free( p );
                my_fgets( line, MAX_LINE_LEN, fi );
                my_fgets( line, MAX_LINE_LEN, fi );
            } else if( strstr( line, "DIALOG" ) != NULL ) {
                p = malloc( MAX_LINE_LEN );
                strcpy( p, line );
                process_dialog_declaration( fi, fo, p );
                strcpy( line, p );
                free( p );
            } else if( strstr( line, "BEGIN" ) != NULL ) {
                my_fgets( line, MAX_LINE_LEN, fi );
                break;
            } else {
#if !defined( OLD_FORMAT )
                if( *line != '\0' )
#endif
                fprintf( fo, "%s\n", line );
                my_fgets( line, MAX_LINE_LEN, fi );
            }
        }
        p = "";
        while( !feof( fi ) && strcmp( p, "END" ) ) {
            while( my_fgets( buff1, MAX_LINE_LEN, fi ) != NULL ) {
                if( check_statement( buff1 ) )
                    break;
                strncat( line, skip_separator( buff1 ), MAX_LINE_LEN );
            }
            process_statement( line, fo );
            strcpy( line, buff1 );
            strcpy( buff2, buff1 );
            p = strtok( buff2, separators );
        }
        if( !feof( fi ) ) {
            fprintf( fo, "%sEND\n", STR_SPC );
        }
    }
    free( buff2 );
    free( buff1 );

    free( line );
    
    free_statement( &dlg_item );
    free_statement( &dlg_hdr );
    if( fi != NULL )
        fclose( fi );
    if( fo != NULL ) {
#if defined( OLD_FORMAT )
        fprintf( fo, "\n" );
#endif
        fclose( fo );
    }
    if( !opt.quiet )
        fprintf( stdout, "\nParsed %d dialogs.\n", dialogs_cnt );
    if( opt.flist_data ) {
        for( i = 0; i < opt.flist_cnt; i++ )
            free( opt.flist_data[ i ] );
        free( opt.flist_data );
    }
    return( 0 );
}
Пример #18
0
void JsonIn::end_value()
{
    ate_separator = false;
    skip_separator();
}
Пример #19
0
std::string JsonIn::get_string()
{
    std::string s = "";
    char ch;
    bool backslash = false;
    char unihex[5] = "0000";
    eat_whitespace();
    int startpos = tell();
    // the first character had better be a '"'
    stream->get(ch);
    if (ch != '"') {
        std::stringstream err;
        err << line_number(-1) << ": expecting string but got '" << ch << "'";
        throw err.str();
    }
    // add chars to the string, one at a time, converting:
    // \", \\, \/, \b, \f, \n, \r, \t and \uxxxx according to JSON spec.
    while (stream->good()) {
        stream->get(ch);
        if (ch == '\\') {
            if (backslash) {
                s += '\\';
                backslash = false;
            } else {
                backslash = true;
                continue;
            }
        } else if (backslash) {
            backslash = false;
            if (ch == '"') {
                s += '"';
            } else if (ch == '/') {
                s += '/';
            } else if (ch == 'b') {
                s += '\b';
            } else if (ch == 'f') {
                s += '\f';
            } else if (ch == 'n') {
                s += '\n';
            } else if (ch == 'r') {
                s += '\r';
            } else if (ch == 't') {
                s += '\t';
            } else if (ch == 'u') {
                // get the next four characters as hexadecimal
                stream->get(unihex, 5);
                // insert the appropriate unicode character in utf8
                // TODO: verify that unihex is in fact 4 hex digits.
                char** endptr = 0;
                unsigned u = (unsigned)strtoul(unihex, endptr, 16);
                s += utf32_to_utf8(u);
            } else {
                // for anything else, just add the character, i suppose
                s += ch;
            }
        } else if (ch == '"') {
            // end of the string
            skip_separator();
            return s;
        } else {
            s += ch;
        }
    }
    // if we get to here, probably hit a premature EOF?
    if (stream->fail()) {
        throw (std::string)"stream failure while reading string.";
    } else if (stream->eof()) {
        stream->clear();
        seek(startpos);
        std::stringstream err;
        err << line_number() << ": ";
        err << "couldn't find end of string, reached EOF.";
        throw err.str();
    }
    throw (std::string)"something went wrong D:";
}
Пример #20
0
int parse_time(const char *buf, int offset, int len, time_t * time_return)
{
	struct tm tm;
	time_t t;
	int i = offset;

	i = skip_word(buf, i, len);
	if (i < 0)
		return -1;
	i = skip_separator(buf, i, len);
	if (i < 0)
		return -1;

	if (i >= len)
		return -1;

	if (d2i(buf[i]) >= 0) {
		i = parse_int(buf, i, len, &tm.tm_mday);
		if (i < 0)
			return -1;
		i = skip_separator(buf, i, len);
		if (i < 0)
			return -1;
		i = parse_month(buf, i, len, &tm.tm_mon);
		if (i < 0)
			return -1;
		i = skip_separator(buf, i, len);
		if (i < 0)
			return -1;
		i = parse_int(buf, i, len, &tm.tm_year);
		if (i < 0)
			return -1;
		if (tm.tm_year < 100)
			tm.tm_year += 1900;
		if (tm.tm_year < 1937)
			tm.tm_year += 100;
		if (tm.tm_year < 1937)
			return -1;

		i = skip_separator(buf, i, len);
		if (i < 0)
			return -1;
		i = parse_int(buf, i, len, &tm.tm_hour);
		if (i < 0)
			return -1;
		i = skip_separator(buf, i, len);
		if (i < 0)
			return -1;
		i = parse_int(buf, i, len, &tm.tm_min);
		if (i < 0)
			return -1;
		i = skip_separator(buf, i, len);
		if (i < 0)
			return -1;
		i = parse_int(buf, i, len, &tm.tm_sec);
		if (i < 0)
			return -1;
		i = skip_separator(buf, i, len);
		if (i < 0)
			return -1;
		i = skip_word(buf, i, len);
		if (i < 0)
			return -1;
	} else {		
		i = parse_month(buf, i, len, &tm.tm_mon);
		if (i < 0)
			return -1;
		i = skip_separator(buf, i, len);
		if (i < 0)
			return -1;
		i = parse_int(buf, i, len, &tm.tm_mday);
		if (i < 0)
			return -1;
		i = skip_separator(buf, i, len);
		if (i < 0)
			return -1;
		i = parse_int(buf, i, len, &tm.tm_hour);
		if (i < 0)
			return -1;
		i = skip_separator(buf, i, len);
		if (i < 0)
			return -1;
		i = parse_int(buf, i, len, &tm.tm_min);
		if (i < 0)
			return -1;
		i = skip_separator(buf, i, len);
		if (i < 0)
			return -1;
		i = parse_int(buf, i, len, &tm.tm_sec);
		if (i < 0)
			return -1;
		i = skip_separator(buf, i, len);
		if (i < 0)
			return -1;
		i = parse_int(buf, i, len, &tm.tm_year);
		if (i < 0)
			return -1;
		if (tm.tm_year < 100)
			tm.tm_year += 1900;
		if (tm.tm_year < 1937)
			tm.tm_year += 100;
		if (tm.tm_year < 1937 || tm.tm_year > 2040)
			return -1;
	}

	if (tm.tm_year < 2038) {
		tm.tm_year -= 1900;
		tm.tm_isdst = -1;
		t = mktime_gmt(&tm);
		if (t == -1)
			return -1;
	} else {
		t = time_t_max;
	}

	*time_return = t;
	return i;
}