コード例 #1
0
ファイル: grammar.c プロジェクト: acherm/chess-analysis
static void
ParseOptGameList(SourceFileType file_type)
{   Move *move_list = NULL;

    while(ParseGame(&move_list) && !finished_processing()) {
        if(file_type == NORMALFILE) {
            DealWithGame(move_list);
        }
        else if(file_type == CHECKFILE) {
            DealWithGame(move_list);
        }
        else if(file_type == ECOFILE) {
            if(move_list != NULL) {
                DealWithEcoLine(move_list);
            }
            else {
                fprintf(GlobalState.logfile,"ECO line with zero moves.\n");
                report_details(GlobalState.logfile);
            }
        }
        else {
            /* Unknown type. */
            free_tags();
            free_move_list(move_list);
        }
        move_list = NULL;
        setup_for_new_game();
    }
}
コード例 #2
0
ファイル: mysqlsniffer.c プロジェクト: dizhaung/SeciMysql
void cleanup(void)
{
   pcap_freecode(&fp);
   pcap_close(handle);

   if(buff_frag) free(buff_frag);
   free_tags();
}
コード例 #3
0
ファイル: mysqlsniffer.c プロジェクト: dizhaung/SeciMysql
void handle_sighup(int signo)
{
   print_stats();
   total_mysql_pkts = total_mysql_bytes = 0;
   free_tags();

   printf("Connection tracking has been reset\n");
}
コード例 #4
0
ファイル: slice.c プロジェクト: Ingwar/amuse
void free_slice(Slice *s)
/* Free the space associated with the vectors in the given Slice */
/* Then free the Slice variable itself */
{
    free_tags(s);
    free_data(s);
    free(s);
    return;
}
コード例 #5
0
ファイル: tag_points.c プロジェクト: bcdarwin/libminc
VIOAPI  void  free_tag_points(
    int       n_volumes,
    int       n_tag_points,
    VIO_Real      **tags_volume1,
    VIO_Real      **tags_volume2,
    VIO_Real      weights[],
    int       structure_ids[],
    int       patient_ids[],
    char      **labels )
{
    int   i;

    if( n_tag_points > 0 )
    {
        free_tags( tags_volume1, n_tag_points );

        if( n_volumes == 2 )
            free_tags( tags_volume2, n_tag_points );

        if( weights != (VIO_Real *) NULL )
            FREE( weights );

        if( structure_ids != (int *) NULL )
            FREE( structure_ids );

        if( patient_ids != (int *) NULL )
            FREE( patient_ids );

        if( labels != (char **) NULL )
        {
            for( i = 0;  i < n_tag_points;  ++i )
                delete_string( labels[i] );

            if( n_tag_points > 0 )
                FREE( labels );
        }
    }
}
コード例 #6
0
ファイル: heplug.c プロジェクト: wothke/webpsx
int he_seek_sample (DB_fileinfo_t *_info, int sample) {
    he_info_t *info = (he_info_t *)_info;
    unsigned long int s = sample;
    if (s < info->samples_played) {
        struct psf_load_state state;
        memset( &state, 0, sizeof(state) );

        state.emu = info->emu;

        if ( !info->psf2fs ) {
            psx_clear_state( info->emu, 1 );
            if ( psf_load( info->path, &psf_file_system, 1, psf1_load, &state, psf_info_meta, &state, 0 ) <= 0 ) {
                trace( "he: invalid PSF file\n" );
                return -1;
            }
        } else {
            psx_clear_state( info->emu, 2 );
            if ( psf_load( info->path, &psf_file_system, 2, 0, 0, psf_info_meta, &state, 0 ) <= 0 ) {
                trace( "he: invalid PSF file\n" );
                return -1;
            }
            psx_set_readfile( info->emu, virtual_readfile, info->psf2fs );
        }

        if ( state.refresh )
            psx_set_refresh( info->emu, state.refresh );

        info->samples_played = 0;
		
		free_tags(state.tags);
    }
    while ( info->samples_played < s ) {
        int to_skip = s - info->samples_played;
        if ( to_skip > 32768 ) to_skip = 1024;
        if ( he_read( _info, NULL, to_skip * 2 * sizeof(short) ) < 0 ) {
            return -1;
        }
    }
    _info->readpos = s/(float)_info->fmt.samplerate;
    return 0;
}
コード例 #7
0
ファイル: heplug.c プロジェクト: wothke/webpsx
int he_init (DB_fileinfo_t *_info, const char * uri) {
	
    he_info_t *info = (he_info_t *)_info;
	info->path = strdup( uri );
	
 //   int psf_version = psf_load( uri, &psf_file_system, 0, 0, 0, 0, 0, 0 );
	requiredLib[0]= 0;
    int psf_version = psf_load( uri, &psf_file_system, 0, 0, 0, psf_lib_meta, 0, 0 );
    if (psf_version < 0) {
        trace ("he: failed to open %s\n", uri);
        return -1;
    }
	
	if (strlen(requiredLib)) {
		// lib must be loaded here or else the psf loading will fail..
		// (enter "retry-mode" if something is missing)
		// make sure the file will be available in the FS when the song asks for it later..		
		char tmpFileName[PATH_MAX];   
		char *p= strrchr(uri, '/');		
		int pathlen= p?(p-uri+1):0;
		memcpy(tmpFileName, uri, pathlen);
		snprintf(tmpFileName+pathlen, PATH_MAX-pathlen, "%s", requiredLib);

		int r= psx_request_file(tmpFileName);	// trigger load & check if ready
		if (r <0) {
			return -1; // file not ready
		}
	}
	
    char he_bios_path[PATH_MAX];
	memset(he_bios_path, 0, PATH_MAX);	// set specific BIOS here if needed

	he_install_bios(he_bios_path);		
    psx_init();

    struct psf_load_state state;
    memset( &state, 0, sizeof(state) );

    state.first = 1;
	
	state.emu= set_emu(info, malloc( psx_get_state_size( psf_version ) ));
    if ( !state.emu ) {
        trace( "he: out of memory\n" );
        return -1;
    }

    psx_clear_state( state.emu, psf_version );

    if ( psf_version == 1 ) {
        if ( psf_load( uri, &psf_file_system, 1, psf1_load, &state, psf_info_meta, &state, 0 ) <= 0 ) {
            trace( "he: invalid PSF file\n" );
            return -1;
        }
    } else if ( psf_version == 2 ) {
        info->psf2fs = psf2fs_create();
        if ( !info->psf2fs ) {
            trace( "he: out of memory\n" );
            return -1;
        }
        if ( psf_load( uri, &psf_file_system, 2, psf2fs_load_callback, info->psf2fs, psf_info_meta, &state, 0 ) <= 0 ) {
            trace( "he: invalid PSF file\n" );
            return -1;
        }
        psx_set_readfile( info->emu, virtual_readfile, info->psf2fs );
    }

    if ( state.refresh )
        psx_set_refresh( info->emu, state.refresh );

    int tag_song_ms = state.tag_song_ms;
    int tag_fade_ms = state.tag_fade_ms;

    if (!tag_song_ms)
    {
        tag_song_ms = ( 2 * 60 + 50 ) * 1000;
        tag_fade_ms =            10   * 1000;
    }

    const int srate = psf_version == 2 ? 48000 : 44100;

    info->samples_played = 0;
    info->samples_to_play = (uint64_t)tag_song_ms * (uint64_t)srate / 1000;
    info->samples_to_fade = (uint64_t)tag_fade_ms * (uint64_t)srate / 1000;

    _info->fmt.channels = 2;
    _info->fmt.bps = 16;
    _info->fmt.samplerate = srate;
	_info->readpos = 0;

	free_tags(state.tags);
	
    return 0;
}
コード例 #8
0
ファイル: psflib.c プロジェクト: droidmjt/Droidsound
static int psf_load_internal( psf_load_state * state, const char * file_name )
{
    psf_tag * tags = NULL;
    psf_tag * tag;

    char * full_path;

    void * file;

    long file_size, tag_size;

    int n;

    uint8_t header_buffer[16];

    uint8_t * exe_compressed_buffer = NULL;
    uint8_t * exe_decompressed_buffer = NULL;
    uint8_t * reserved_buffer = NULL;
    char * tag_buffer = NULL;

    uint32_t exe_compressed_size, exe_crc32, reserved_size;
    uLong exe_decompressed_size, try_exe_decompressed_size;

    int zerr;

    size_t full_path_size;

    if ( ++state->depth > max_recursion_depth ) return -1;

    full_path_size = strlen(state->base_path) + strlen(file_name) + 1;
    full_path = (char *) malloc( full_path_size );
    if ( !full_path ) return -1;

#if _MSC_VER >= 1300
    strcpy_s( full_path, full_path_size, state->base_path );
    strcat_s( full_path, full_path_size, file_name );
#else
    strcpy( full_path, state->base_path );
    strcat( full_path, file_name );
#endif

    file = state->file_callbacks->fopen( full_path );

    free( full_path );

    if ( !file ) return -1;

    if ( state->file_callbacks->fread( header_buffer, 1, 16, file ) < 16 ) goto error_close_file;

    if ( memcmp( header_buffer, "PSF", 3 ) ) goto error_close_file;

    if ( state->allowed_version && ( header_buffer[ 3 ] != state->allowed_version ) ) goto error_close_file;

    reserved_size = header_buffer[ 4 ] | ( header_buffer[ 5 ] << 8 ) | ( header_buffer[ 6 ] << 16 ) | ( header_buffer[ 7 ] << 24 );
    exe_compressed_size = header_buffer[ 8 ] | ( header_buffer[ 9 ] << 8 ) | ( header_buffer[ 10 ] << 16 ) | ( header_buffer[ 11 ] << 24 );
    exe_crc32 = header_buffer[ 12 ] | ( header_buffer[ 13 ] << 8 ) | ( header_buffer[ 14 ] << 16 ) | ( header_buffer[ 15 ] << 24 );

    if ( state->file_callbacks->fseek( file, 0, SEEK_END ) ) goto error_close_file;

    file_size = state->file_callbacks->ftell( file );

    if ( file_size <= 0 ) goto error_close_file;

    if ( (unsigned long)file_size >= 16 + reserved_size + exe_compressed_size + 5 )
    {
        tag_size = file_size - ( 16 + reserved_size + exe_compressed_size );
        if ( state->file_callbacks->fseek( file, -tag_size, SEEK_CUR ) ) goto error_close_file;
        tag_buffer = (char *) malloc( tag_size + 1 );
        if ( !tag_buffer ) goto error_close_file;
        if ( state->file_callbacks->fread( tag_buffer, 1, tag_size, file ) < (size_t)tag_size ) goto error_free_buffers;
        tag_buffer[ tag_size ] = 0;
        if ( !memcmp( tag_buffer, "[TAG]", 5 ) ) tags = process_tags( tag_buffer + 5 );
        free( tag_buffer );
        tag_buffer = NULL;

        if ( tags && state->info_target && ( state->depth == 1 || state->info_want_nested_tags ) )
        {
            tag = tags;
            while ( tag->next ) tag = tag->next;
            while ( tag )
            {
                state->info_target( state->info_context, tag->name, tag->value );
                tag = tag->prev;
            }
        }
    }

    if ( !state->load_target ) goto done;

    tag = find_tag( tags, "_lib" );
    if ( tag )
    {
        if ( psf_load_internal( state, tag->value ) < 0 ) goto error_free_tags;
    }

    reserved_buffer = (uint8_t *) malloc( reserved_size );
    if ( !reserved_buffer ) goto error_free_tags;
    exe_compressed_buffer = (uint8_t *) malloc( exe_compressed_size );
    if ( !exe_compressed_buffer ) goto error_free_tags;

    if ( state->file_callbacks->fseek( file, 16, SEEK_SET ) ) goto error_free_tags;
    if ( reserved_size && state->file_callbacks->fread( reserved_buffer, 1, reserved_size, file ) < reserved_size ) goto error_free_tags;
    if ( exe_compressed_size && state->file_callbacks->fread( exe_compressed_buffer, 1, exe_compressed_size, file ) < exe_compressed_size ) goto error_free_tags;
    state->file_callbacks->fclose( file );
    file = NULL;

    if ( exe_compressed_size )
    {
        if ( exe_crc32 != crc32(crc32(0L, Z_NULL, 0), exe_compressed_buffer, exe_compressed_size) ) goto error_free_tags;

        exe_decompressed_size = try_exe_decompressed_size = exe_compressed_size * 3;
        exe_decompressed_buffer = (uint8_t *) malloc( exe_decompressed_size );
        if ( !exe_decompressed_buffer ) goto error_free_tags;

        while ( Z_OK != ( zerr = uncompress( exe_decompressed_buffer, &exe_decompressed_size, exe_compressed_buffer, exe_compressed_size ) ) )
        {
            void * try_exe_decompressed_buffer;

            if ( Z_MEM_ERROR != zerr && Z_BUF_ERROR != zerr ) goto error_free_tags;

            if ( try_exe_decompressed_size < 1 * 1024 * 1024 )
                try_exe_decompressed_size += 1 * 1024 * 1024;
            else
                try_exe_decompressed_size += try_exe_decompressed_size;

            exe_decompressed_size = try_exe_decompressed_size;

            try_exe_decompressed_buffer = realloc( exe_decompressed_buffer, exe_decompressed_size );
            if ( !try_exe_decompressed_buffer ) goto error_free_tags;

            exe_decompressed_buffer = (uint8_t *) try_exe_decompressed_buffer;
        }
    }
    else
    {
        exe_decompressed_size = 0;
        exe_decompressed_buffer = (uint8_t *) malloc( exe_decompressed_size );
        if ( !exe_decompressed_buffer ) goto error_free_tags;
    }

    free( exe_compressed_buffer );
    exe_compressed_buffer = NULL;

    if ( state->load_target( state->load_context, exe_decompressed_buffer, exe_decompressed_size, reserved_buffer, reserved_size ) ) goto error_free_tags;

    free( reserved_buffer );
    reserved_buffer = NULL;

    free( exe_decompressed_buffer );
    exe_decompressed_buffer = NULL;

    n = 2;
    snprintf( state->lib_name_temp, 31, "_lib%u", n );
    state->lib_name_temp[ 31 ] = '\0';
    tag = find_tag( tags, state->lib_name_temp );
    while ( tag )
    {
        if ( psf_load_internal( state, tag->value ) < 0 ) goto error_free_tags;
        ++n;
        snprintf( state->lib_name_temp, 31, "_lib%u", n );
        state->lib_name_temp[ 31 ] = '\0';
        tag = find_tag( tags, state->lib_name_temp );
    }

done:
    if ( file ) state->file_callbacks->fclose( file );

    free_tags( tags );

    --state->depth;

    return header_buffer[ 3 ];

error_free_tags:
    free_tags( tags );
error_free_buffers:
    if ( exe_compressed_buffer ) free( exe_compressed_buffer );
    if ( exe_decompressed_buffer ) free( exe_decompressed_buffer );
    if ( reserved_buffer ) free( reserved_buffer );
    if ( tag_buffer ) free( tag_buffer );
error_close_file:
    if ( file ) state->file_callbacks->fclose( file );
    return -1;
}
コード例 #9
0
ファイル: genuuid.c プロジェクト: sunny256/suuid
struct uuid_result create_and_log_uuids(const struct Options *opt)
{
	struct uuid_result retval;
	char *rcfile = NULL, *logfile = NULL;
	unsigned int i, count;
	struct Rc rc;
	struct Entry entry;
	struct Logs logs;

	assert(opt);

	logs.logfp = NULL;
	count = opt->count;
	retval.count = 0;
	memset(retval.lastuuid, 0, UUID_LENGTH + 1);
	retval.success = TRUE;
	init_xml_entry(&entry);

	/*
	 * Get information about the environment; hostname, current directory, 
	 * tty, location of rc file and log directory, etc.
	 */

	if (init_randomness() == EXIT_FAILURE) {
		retval.success = FALSE;
		goto cleanup;
	}

	rcfile = get_rcfilename(opt);
	if (read_rcfile(rcfile, &rc) == EXIT_FAILURE) {
		retval.success = FALSE;
		goto cleanup;
	}

	if (fill_entry_struct(&entry, &rc, opt) == EXIT_FAILURE) {
		retval.success = FALSE;
		goto cleanup;
	}

	logfile = get_log_prefix(&rc, opt, ".xml");
	if (!logfile) {
		retval.success = FALSE;
		goto cleanup;
	}

	signal(SIGHUP, sighandler);
	signal(SIGINT, sighandler);
	signal(SIGQUIT, sighandler);
	signal(SIGPIPE, sighandler);
	signal(SIGTERM, sighandler);

	/*
	 * Open the log file. If it's missing, create it.
	 */

	logs.logfp = open_logfile(logfile);
	if (!logs.logfp) {
		retval.success = FALSE;
		goto cleanup;
	}

	/*
	 * Generate the UUIDs and write them to the log file.
	 */

	if (opt->uuid)
		count = 1;
	for (i = 0; i < count; i++) {
		if (!process_uuid(&logs, &rc, opt, &entry)) {
			retval.success = FALSE;
			goto cleanup;
		}
		retval.count++;
		if (should_terminate)
			break;
	}
	if (valid_uuid(entry.uuid, TRUE))
		strncpy(retval.lastuuid, entry.uuid, UUID_LENGTH + 1);

	/*
	 * Check that the correct amount of UUIDs were created.
	 */

	if (retval.count < opt->count)
		fprintf(stderr, "%s: Generated only %u of %u UUIDs\n",
		                progname, retval.count, opt->count);

	/*
	 * Close up the shop and go home.
	 */

cleanup:
	if (logs.logfp && (close_logfile(logs.logfp) == EXIT_FAILURE))
		retval.success = FALSE;

	free(logfile);
	free_sess(&entry);
	free_tags(&entry);
	free(rc.uuidcmd);
	free(rc.macaddr);
	free(rc.hostname);
	free(entry.txt);
	free(entry.date);
	free(entry.cwd);
	free(rcfile);

	return retval;
}