bool VRML1_MODEL_PARSER::Load( const wxString& aFilename )
{
    char text[BUFLINE_SIZE];

    wxLogTrace( traceVrmlV1Parser, wxT( "Loading: %s" ), GetChars( aFilename ) );

    m_file = wxFopen( aFilename, wxT( "rt" ) );

    if( m_file == NULL )
        return false;

    // Switch the locale to standard C (needed to print floating point numbers)
    LOCALE_IO toggle;

    m_ModelParser->childs.clear();

    while( GetNextTag( m_file, text, sizeof(text) ) )
    {
        if( ( *text == '}' ) || ( *text == ']' ) )
        {
            continue;
        }

        if( strcmp( text, "Separator" ) == 0 )
        {
            m_model.reset( new S3D_MESH() );
            m_ModelParser->childs.push_back( m_model );
            read_separator();
        }
    }

    fclose( m_file );

    return true;
}
int VRML1_MODEL_PARSER::read_separator()
{
    char text[BUFLINE_SIZE];

    // DBG( printf( "Separator\n" ) );

    while( GetNextTag( m_file, text, sizeof(text) ) )
    {
        if( strcmp( text, "Material" ) == 0 )
        {
            readMaterial();
        }
        else if( strcmp( text, "Coordinate3" ) == 0 )
        {
            readCoordinate3();
        }
        else if( strcmp( text, "IndexedFaceSet" ) == 0 )
        {
            readIndexedFaceSet();
        }
        else if( strcmp( text, "Separator" ) == 0 )
        {
            S3D_MESH_PTR parent( m_model.get() );

            S3D_MESH_PTR new_mesh_model( new S3D_MESH() );

            m_model->childs.push_back( new_mesh_model );

            m_model.reset( new_mesh_model.get() );

            // recursive
            read_separator();

            m_model.reset( parent.get() );
        }
        else if( ( *text != '}' ) )
        {
            // DBG( printf( "read_NotImplemented %s\n", text ) );
            Read_NotImplemented( m_file, '}' );
        }
        else
            break;
    }

    return 0;
}
示例#3
0
int handle_response(char *ip, char *filename) {

    int i;

    char buffer[RESPONSE_BUFFER_SIZE];
    int buffer_size = 0;
    int pointer = 0;

    char status_line[HEADER_LINE_LENGTH];
    char header[HEADER_LINE_LENGTH];
    char value[HEADER_LINE_LENGTH];
    int status_ok;

    char header_content_length[HEADER_LINE_LENGTH];
    char header_content_type[HEADER_LINE_LENGTH];
    char header_last_modified[HEADER_LINE_LENGTH];

    time_t curtime;
    char current_time[HEADER_LINE_LENGTH];

    FILE *fp;

    /* fill buffer with first part of response */
    buffer_size = get_response_header(buffer, RESPONSE_BUFFER_SIZE);
    if (buffer_size < 0) {
        printf("Request failed: could not retrieve response from server\n");
        return 0;
    }

    /* read status line */
    pointer = parse_status_line(buffer, buffer_size, status_line,
                                HEADER_LINE_LENGTH, &status_ok);
    if (pointer < 0) {
        printf("Request failed: invalid response status code sent by server\n");
        return 0;
    }

    /* default value for headers */
    snprintf(header_content_length, HEADER_LINE_LENGTH, "Unknown");
    snprintf(header_content_type, HEADER_LINE_LENGTH, "Unknown");
    snprintf(header_last_modified, HEADER_LINE_LENGTH, "Unknown");

    /* read headers */
    while ((i = parse_header(buffer + pointer, buffer_size - pointer,
                             header, HEADER_LINE_LENGTH,
                             value, HEADER_LINE_LENGTH)) > 0) {
        pointer += i;
        if (strcmp(header, "Content-Length") == 0) {
            memcpy(header_content_length, value, HEADER_LINE_LENGTH);
        } else if (strcmp(header, "Content-Type") == 0) {
            memcpy(header_content_type, value, HEADER_LINE_LENGTH);
        } else if (strcmp(header, "Last-Modified") == 0) {
            memcpy(header_last_modified, value, HEADER_LINE_LENGTH);
        }
    }

    i = read_separator(buffer + pointer, buffer_size - pointer);
    if (i < 0) {
        printf("Request failed: invalid response sent by server\n");
        return 0;
    }
    pointer += i;

    /* get current time */
    time(&curtime);
    strftime(current_time, HEADER_LINE_LENGTH, DATE_TIME_FORMAT,
             gmtime(&curtime));

    /* print some output */
    printf("Request sent to http server at %s. Received response:\n", ip);
    printf("  The return code was:        %s\n", status_line);
    printf("  Date of retrieval:          %s\n", current_time);
    printf("  Document last modified at:  %s\n", header_last_modified);
    printf("  Document size:              %s bytes\n", header_content_length);
    printf("  Document's mime type:       %s\n", header_content_type);

    if (!status_ok) {
        printf("Since the status code was not '200 OK', no data has been written\nto %s\n",
               filename);
        return 1;
    }

    /* open file for writing */
    if ((fp = fopen(filename, "w")) == (FILE *)0) {
        switch (errno) {
            case EACCES:
                printf("No permissions to open file for writing: %s\n", filename);
                return 0;
                break;
            default:
                printf("Could not open file for writing: %s\n", filename);
                return 0;
        }
    }

    /* read until end of stream */
    do {

        /* write buffer contents to file */
        while (pointer < buffer_size) {
            putc(buffer[pointer], fp);
            pointer++;
        }

        signal(SIGALRM, alarm_handler);
        alarm(TIME_OUT);
        buffer_size = tcp_read(buffer, RESPONSE_BUFFER_SIZE);
        alarm(0);

        /* failed reading */
        if (buffer_size < 0
            || alarm_went_off) {
            /*
              Actually, we should write to a temp file
              and delete it here. Only if all data is
              received, copy temp file to real file.
              But this is a problem if we have write
              rights on filename, but not to create
              temp file. So we leave this for the time
              being.                  
            */
            fclose(fp);
            printf("Request failed: could not retrieve message body\n");
            printf("Wrote partial message body to file: %s\n", filename);
            return 0;
        }

        pointer = 0;

    } while (buffer_size);

    fclose(fp);

    printf("Wrote message body to file: %s\n", filename);

    return 1;

}
示例#4
0
文件: read_exp.c 项目: Azhr4n/42Sh
/*
** exp ::= separator_exp
*/
int		read_exp(t_ast **tree, t_list **tokens)
{
	if (read_separator(tree, tokens) == TRUE)
		return (TRUE);
	return (FALSE);
}