示例#1
0
文件: main.c 项目: Kiriax/Zappy
void	unit_test(char *data, char *mask)
{
  t_command	*command;

  if (!data || !mask)
    printf("un pointeur d entree au moins est a nul\n");
  else
    printf("checking : data = \"%s\"\nwith : mask = \"%s\"\n",
	 data, mask);
  if ((command = parser_parse(data, mask)))
    {
      int	i = 0;

      while (i < list_size(&command->arguments))
	{
	  printf("string %d {value = \"%s\"}\n",
		 i, parser_get_string(command, i));
	  printf("int %d {value = \"%d\"}\n",
		 i, parser_get_int(command, i));
	  i++;
	}
      parser_command_destroy(command);
    }
  else
    printf("dismatch\n");
}
/* load config */
static void parse_player( PData *pd, Player *player )
{
    char *str;
    PData *sub;
    if ( parser_get_value( pd, "name", &str, 0 ) )
        strcpy( player->name, str );
    if ( parser_get_pdata( pd, "controls", &sub ) ) {
        parser_get_int( sub, "left", &player->controls.left );
        parser_get_int( sub, "right", &player->controls.right );
        parser_get_int( sub, "rot_left", &player->controls.rot_left );
        parser_get_int( sub, "rot_right", &player->controls.rot_right );
        parser_get_int( sub, "down", &player->controls.down );
        parser_get_int( sub, "drop", &player->controls.drop );
    }
}
void config_load( )
{
    char file_name[512];
    PData *pd, *sub; 
    /* set to defaults */
    config_check_dir();
    config_reset();
    /* load config */
    sprintf( file_name, "%s/%s", config.dir_name, CONFIG_FILE_NAME );
    if ( ( pd = parser_read_file( "config", file_name ) ) == 0 ) {
        fprintf( stderr, "%s\n", parser_get_error() );
        return;
    }
    /* parse config */
    parser_get_int( pd, "gametype", &config.gametype );
    parser_get_int( pd, "starting_level", &config.starting_level );
    if (config.starting_level > 9 || config.starting_level < 0) {
	    config.starting_level = 0;
    }
    parser_get_int( pd, "preview", &config.preview );
    parser_get_int( pd, "help", &config.help );
    parser_get_int( pd, "expert", &config.expert );
    parser_get_int( pd, "same_blocks", &config.same_blocks_for_all );
    parser_get_int( pd, "center_preview", &config.center_preview );
    parser_get_int( pd, "holes", &config.holes );
    parser_get_int( pd, "rand_holes", &config.rand_holes );
    parser_get_int( pd, "send_all", &config.send_all );
    parser_get_int( pd, "send_tetris", &config.send_tetris );
    if ( parser_get_pdata( pd, "player1", &sub ) )
        parse_player( sub, &config.player1 );
    if ( parser_get_pdata( pd, "player2", &sub ) )
        parse_player( sub, &config.player2 );
    if ( parser_get_pdata( pd, "player3", &sub ) )
        parse_player( sub, &config.player3 );
    parser_get_int( pd, "clear_keystate", &config.clear_keystate );
    parser_get_int( pd, "cpu_aggr", &config.cpu_aggr );
    parser_get_int( pd, "cpu_delay", &config.cpu_delay );
    parser_get_int( pd, "cpu_rot_delay", &config.cpu_rot_delay );
    parser_get_int( pd, "sound", &config.sound );
    parser_get_int( pd, "volume", &config.volume );
    parser_get_int( pd, "transparency", &config.trp );
    parser_get_int( pd, "animations", &config.anim );
    parser_get_int( pd, "fullscreen", &config.fullscreen );
    parser_get_int( pd, "fading", &config.fade );
    parser_get_int( pd, "fps", &config.fps );
    parser_get_int( pd, "background", &config.bkgnd );
    parser_get_int( pd, "static_background", &config.keep_bkgnd );
    parser_get_int( pd, "smooth_hori", &config.smooth_hori );
    parser_get_int( pd, "hori_delay", &config.hori_delay );
    parser_get_int( pd, "block_by_block", &config.block_by_block );
    parser_get_int( pd, "motion_mod", &config.motion_mod );
    parser_get_int( pd, "relative_motion", &config.rel_motion );
    parser_get_int( pd, "grap_input", &config.grab );
    parser_get_int( pd, "invert_mouse", &config.invert );
    parser_get_int( pd, "quick_help", &config.quick_help );
    parser_get_int( pd, "async_collision_check", &config.async_col_check );
    parser_free( &pd );
}
示例#4
0
/*
====================================================================
Load terrain types, weather information and hex tile icons.
====================================================================
*/
int terrain_load( char *fname )
{
    int i, j, k;
    PData *pd, *sub, *subsub, *subsubsub;
    List *entries, *flags;
    char path[512], transitionPath[512];
    char *flag, *str;
    char *domain = 0;
    int count;
    /* log info */
    int  log_dot_limit = 40; /* maximum of dots */
    char log_str[128];
    sprintf( transitionPath, "Scenario/%s", fname );
    search_file_name_exact( path, transitionPath, config.mod_name );
    if ( ( pd = parser_read_file( fname, path ) ) == 0 ) goto parser_failure;
//    domain = determine_domain(pd, fname);
//    locale_load_domain(domain, 0/*FIXME*/);
    /* get weather */
    if ( !parser_get_entries( pd, "weather", &entries ) ) goto parser_failure;
    weather_type_count = entries->count;
    weather_types = calloc( weather_type_count, sizeof( Weather_Type ) );
    list_reset( entries ); i = 0;
    while ( ( sub = list_next( entries ) ) ) {
        weather_types[i].id = strdup( sub->name );
//        if ( !parser_get_localized_string( sub, "name", domain, &weather_types[i].name ) ) goto parser_failure;
        if ( !parser_get_value( sub, "name", &str, 0 ) ) goto parser_failure;
        weather_types[i].name = strdup( str );
        if ( !parser_get_value( sub, "ground_cond", &str, 0 ) ) goto parser_failure;
        weather_types[i].ground_conditions = strdup( str );
        if ( !parser_get_values( sub, "flags", &flags ) ) goto parser_failure;
        list_reset( flags );
        while ( ( flag = list_next( flags ) ) )
            weather_types[i].flags |= check_flag( flag, fct_terrain );
        i++;
    }
    /* hex tile geometry */
    if ( !parser_get_int( pd, "hex_width", &hex_w ) ) goto parser_failure;
    if ( !parser_get_int( pd, "hex_height", &hex_h ) ) goto parser_failure;
    if ( !parser_get_int( pd, "hex_x_offset", &hex_x_offset ) ) goto parser_failure;
    if ( !parser_get_int( pd, "hex_y_offset", &hex_y_offset ) ) goto parser_failure;
    /* terrain icons */
    terrain_icons = calloc( 1, sizeof( Terrain_Icons ) );
    if ( !parser_get_value( pd, "fog", &str, 0 ) ) goto parser_failure;
    sprintf( transitionPath, "Graphics/%s", str );
    search_file_name_exact( path, transitionPath, config.mod_name );
    if ( ( terrain_icons->fog = load_surf( path, SDL_SWSURFACE, 0, 0, 0, 0 ) ) == 0 ) goto failure;
    if ( !parser_get_value( pd, "danger", &str, 0 ) ) goto parser_failure;
    sprintf( transitionPath, "Graphics/%s", str );
    search_file_name_exact( path, transitionPath, config.mod_name );
    if ( ( terrain_icons->danger = load_surf( path, SDL_SWSURFACE, 0, 0, 0, 0 ) ) == 0 ) goto failure;
    if ( !parser_get_value( pd, "grid", &str, 0 ) ) goto parser_failure;
    sprintf( transitionPath, "Graphics/%s", str );
    search_file_name_exact( path, transitionPath, config.mod_name );
    if ( ( terrain_icons->grid = load_surf( path, SDL_SWSURFACE, 0, 0, 0, 0 ) ) == 0 ) goto failure;
    if ( !parser_get_value( pd, "frame", &str, 0 ) ) goto parser_failure;
    sprintf( transitionPath, "Graphics/%s", str );
    search_file_name_exact( path, transitionPath, config.mod_name );
    if ( ( terrain_icons->select = load_surf( path, SDL_SWSURFACE, 0, 0, 0, 0 ) ) == 0 ) goto failure;
    if ( !parser_get_value( pd, "crosshair", &str, 0 ) ) goto parser_failure;
    sprintf( transitionPath, "Graphics/%s", str );
    search_file_name_exact( path, transitionPath, config.mod_name );
    if ( ( terrain_icons->cross = anim_create( load_surf( path, SDL_SWSURFACE, 0, 0, 0, 0 ), 1000/config.anim_speed, hex_w, hex_h, sdl.screen, 0, 0 ) ) == 0 )
        goto failure;
    anim_hide( terrain_icons->cross, 1 );
    if ( !parser_get_value( pd, "explosion", &str, 0 ) ) goto parser_failure;
    sprintf( transitionPath, "Graphics/%s", str );
    search_file_name_exact( path, transitionPath, config.mod_name );
    if ( ( terrain_icons->expl1 = anim_create( load_surf( path, SDL_SWSURFACE, 0, 0, 0, 0 ), 50/config.anim_speed, hex_w, hex_h, sdl.screen, 0, 0 ) ) == 0 )
        goto failure;
    anim_hide( terrain_icons->expl1, 1 );
    if ( ( terrain_icons->expl2 = anim_create( load_surf( path, SDL_SWSURFACE, 0, 0, 0, 0 ), 50/config.anim_speed, hex_w, hex_h, sdl.screen, 0, 0 ) ) == 0 )
        goto failure;
    anim_hide( terrain_icons->expl2, 1 );
    /* terrain sounds */
#ifdef WITH_SOUND    
    if ( parser_get_value( pd, "explosion_sound", &str, 0 ) )
    {
        snprintf( transitionPath, 512, "Sound/%s", str );
        search_file_name_exact( path, transitionPath, config.mod_name );
        terrain_icons->wav_expl = wav_load( path, 2 );
    }
    if ( parser_get_value( pd, "select_sound", &str, 0 ) )
    {
        snprintf( transitionPath, 512, "Sound/%s", str );
        search_file_name_exact( path, transitionPath, config.mod_name );
        terrain_icons->wav_select = wav_load( path, 1 );
    }
#endif
    /* terrain data image columns */
    if ( !parser_get_int( pd, "terrain_columns", &terrain_columns ) ) goto parser_failure;
    /* terrain data image rows */
    if ( !parser_get_int( pd, "terrain_rows", &terrain_rows ) ) goto parser_failure;
    /* each ground condition type got its own image -- if it's named 'default' we
       point towards the image of weather_type 0 */
    terrain_images = calloc( 1, sizeof( Terrain_Images ) );
    terrain_images->images = calloc( weather_type_count / 4, sizeof( SDL_Surface* ) );
    for ( j = 0; j < weather_type_count / 4; j++ ) {
        terrain_images->ground_conditions = strdup( weather_types[4*j].ground_conditions );
        sprintf( path, "image/%s", weather_types[4*j].ground_conditions );
        if ( !parser_get_value( pd, path, &str, 0 ) ) goto parser_failure;
        if ( STRCMP( "default", str ) && j > 0 ) {
            /* just a pointer */
            terrain_images->images[j] = terrain_images->images[0];
        }
        else {
            sprintf( transitionPath, "Graphics/%s", str );
            search_file_name_exact( path, transitionPath, config.mod_name );
            if ( ( terrain_images->images[j] = load_surf( path, SDL_SWSURFACE, 0, 0, 0, 0 ) ) == 0 ) goto parser_failure;
            SDL_SetColorKey( terrain_images->images[j], SDL_SRCCOLORKEY, 
                             get_pixel( terrain_images->images[j], 0, 0 ) );
        }
    }
    /* fog image */
    terrain_images->images_fogged = calloc( weather_type_count / 4, sizeof( SDL_Surface* ) );
    for ( j = 0; j < weather_type_count / 4; j++ ) {
        if ( terrain_images->images[j] == terrain_images->images[0] && j > 0 ) {
            /* just a pointer */
            terrain_images->images_fogged[j] = terrain_images->images_fogged[0];
        }
        else {
            terrain_images->images_fogged[j] = create_surf( terrain_images->images[j]->w, terrain_images->images[j]->h, SDL_SWSURFACE );
            FULL_DEST( terrain_images->images_fogged[j]  );
            FULL_SOURCE( terrain_images->images[j] );
            blit_surf();
            count =  terrain_images->images[j]->w /  hex_w;
            for ( i = 0; i < terrain_rows; i++ )
                for ( k = 0; k < terrain_columns; k++ ) {
                    DEST( terrain_images->images_fogged[j], k * hex_w, i * hex_h,  hex_w, hex_h );
                    SOURCE( terrain_icons->fog, 0, 0 );
                    alpha_blit_surf( FOG_ALPHA );
                }
            SDL_SetColorKey( terrain_images->images_fogged[j], SDL_SRCCOLORKEY, get_pixel( terrain_images->images_fogged[j], 0, 0 ) );
        }
    }
    /* terrain types */
    if ( !parser_get_entries( pd, "terrain", &entries ) ) goto parser_failure;
    terrain_type_count = entries->count;
    terrain_types = calloc( terrain_type_count, sizeof( Terrain_Type ) );
    list_reset( entries ); i = 0;
    while ( ( sub = list_next( entries ) ) ) {
        /* id */
        terrain_types[i].id = sub->name[0];
        /* name */
        if ( !parser_get_localized_string( sub, "name", domain, &terrain_types[i].name ) ) goto parser_failure;
        /* spot cost */
        terrain_types[i].spt = calloc( weather_type_count, sizeof( int ) );
        if ( !parser_get_pdata( sub, "spot_cost",  &subsub ) ) goto parser_failure;
        for ( j = 0; j < weather_type_count; j++ )
            if ( !parser_get_int( subsub, weather_types[j].id, &terrain_types[i].spt[j] ) ) goto parser_failure;
        /* image */
        terrain_types[i].images = terrain_images->images;
        /* fog image */
        terrain_types[i].images_fogged = terrain_images->images_fogged;
        /* mov cost */
        terrain_types[i].mov = calloc( mov_type_count * weather_type_count, sizeof( int ) );
        if ( !parser_get_pdata( sub, "move_cost",  &subsub ) ) goto parser_failure;
        for ( k = 0; k < mov_type_count; k++ ) {
            if ( !parser_get_pdata( subsub, mov_types[k].id,  &subsubsub ) ) goto parser_failure;
            for ( j = 0; j < weather_type_count; j++ ) {
                if ( !parser_get_value( subsubsub, weather_types[j].id, &str, 0 ) ) goto parser_failure;
                if ( str[0] == 'X' )
                    terrain_types[i].mov[j + k * weather_type_count] = 0; /* impassable */
                else
                    if ( str[0] == 'A' )
                        terrain_types[i].mov[j + k * weather_type_count] = -1; /* costs all */
                    else
                        terrain_types[i].mov[j + k * weather_type_count] = atoi( str ); /* normal cost */
            }
        }
        /* entrenchment */
        if ( !parser_get_int( sub, "min_entr",  &terrain_types[i].min_entr ) ) goto parser_failure;
        if ( !parser_get_int( sub, "max_entr",  &terrain_types[i].max_entr ) ) goto parser_failure;
        /* initiative modification */
        if ( !parser_get_int( sub, "max_init",  &terrain_types[i].max_ini ) ) goto parser_failure;
        /* flags */
        terrain_types[i].flags = calloc( weather_type_count, sizeof( int ) );
        if ( !parser_get_pdata( sub, "flags",  &subsub ) ) goto parser_failure;
        for ( j = 0; j < weather_type_count; j++ ) {
            if ( !parser_get_values( subsub, weather_types[j].id, &flags ) ) goto parser_failure;
            list_reset( flags );
            while ( ( flag = list_next( flags ) ) )
                terrain_types[i].flags[j] |= check_flag( flag, fct_terrain );
        }
        /* next terrain */
        i++;
        /* LOG */
        strcpy( log_str, "  [                                        ]" );
        for ( k = 0; k < i * log_dot_limit / entries->count; k++ )
            log_str[3 + k] = '*';
        write_text( log_font, sdl.screen, log_x, log_y, log_str, 255 );
        SDL_UpdateRect( sdl.screen, log_font->last_x, log_font->last_y, log_font->last_width, log_font->last_height );
    }
    parser_free( &pd );
    /* LOG */
    write_line( sdl.screen, log_font, log_str, log_x, &log_y ); refresh_screen( 0, 0, 0, 0 );
    free(domain);
    return 1;
parser_failure:        
    fprintf( stderr, "%s\n", parser_get_error() );
failure:
    terrain_delete();
    if ( pd ) parser_free( &pd );
    free(domain);
    printf(tr("If data seems to be missing, please re-run the converter lgc-pg.\n"));
    return 0;
}
示例#5
0
/* load config */
void config_load( )
{
    char *str;
    char file_name[512];
    PData *pd; 
    /* set to defaults */
    config_check_dir();
    config_reset();
    /* load config */
    sprintf( file_name, "%s/%s", config.dir_name, CONFIG_FILE_NAME );
    if ( ( pd = parser_read_file( "config", file_name ) ) == 0 ) {
        fprintf( stderr, "%s\n", parser_get_error() );
        return;
    }
    /* assign */
    parser_get_int( pd, "set_id_local", &config.levelset_id_local );
    parser_get_int( pd, "set_count_local", &config.levelset_count_local );
    parser_get_int( pd, "set_id_home", &config.levelset_id_home );
    parser_get_int( pd, "set_count_home", &config.levelset_count_home );
    parser_get_int( pd, "player_count", &config.player_count );
    if ( parser_get_value( pd, "player0", &str, 0 ) )
        strcpy_lt( config.player_names[0], str, 31 );
    if ( parser_get_value( pd, "player1", &str, 0 ) )
        strcpy_lt( config.player_names[1], str, 31 );
    if ( parser_get_value( pd, "player2", &str, 0 ) )
        strcpy_lt( config.player_names[2], str, 31 );
    if ( parser_get_value( pd, "player3", &str, 0 ) )
        strcpy_lt( config.player_names[3], str, 31 );
    parser_get_int( pd, "diff", &config.diff );
    parser_get_int( pd, "starting_level", &config.startlevel );
    parser_get_int( pd, "rel_warp_limit", &config.rel_warp_limit );
    parser_get_int( pd, "add_bonus_levels", &config.addBonusLevels );
    parser_get_int( pd, "left", &config.k_left );
    parser_get_int( pd, "right", &config.k_right );
    parser_get_int( pd, "fire_left", &config.k_lfire );
    parser_get_int( pd, "fire_right", &config.k_rfire );
    parser_get_int( pd, "return", &config.k_return );
    parser_get_int( pd, "turbo", &config.k_turbo );
    parser_get_int( pd, "rel_motion", &config.rel_motion );
    parser_get_int( pd, "grab", &config.grab );
    parser_get_int( pd, "motion_mod", &config.i_motion_mod );
    config.motion_mod = 0.01 * config.i_motion_mod;
    parser_get_int( pd, "convex", &config.convex );
    parser_get_int( pd, "linear_corner", &config.linear_corner );
    parser_get_int( pd, "random_angle", &config.random_angle );
    parser_get_int( pd, "maxballspeed", &config.maxballspeed_int1000 );
    config.maxballspeed_float = (float)config.maxballspeed_int1000 / 1000;
    parser_get_int( pd, "invert", &config.invert );
    parser_get_int( pd, "sound", &config.sound );
    parser_get_int( pd, "volume", &config.volume );
    parser_get_int( pd, "speech", &config.speech );
    parser_get_int( pd, "badspeech", &config.badspeech );
    parser_get_int( pd, "audio_buffer_size", &config.audio_buffer_size );
    parser_get_int( pd, "anim", &config.anim );
    parser_get_int( pd, "fullscreen", &config.fullscreen );
    parser_get_int( pd, "fade", &config.fade );
    parser_get_int( pd, "bonus_info", &config.bonus_info );
    parser_get_int( pd, "fps", &config.fps );
    parser_get_int( pd, "ball_level", &config.ball_level );
    parser_get_int( pd, "debris_level", &config.debris_level );
    parser_get_int( pd, "i_key_speed", &config.i_key_speed );
    config.key_speed = 0.001 * config.i_key_speed;
    parser_get_int( pd, "use_hints", &config.use_hints );
    parser_get_int( pd, "return_on_click", &config.return_on_click );
    parser_get_int( pd, "theme_id", &config.theme_id );
    parser_get_int( pd, "theme_count", &config.theme_count );
    if ( parser_get_value( pd, "server", &str, 0 ) )
        strcpy_lt( config.server, str, 64 );
    if ( parser_get_value( pd, "local_port", &str, 0 ) )
        strcpy_lt( config.local_port, str, 6 );
    if ( parser_get_value( pd, "username", &str, 0 ) )
        strcpy_lt( config.username, str, 15 );
    parser_get_int( pd, "mp_diff", &config.mp_diff );
    parser_get_int( pd, "mp_rounds", &config.mp_rounds );
    parser_get_int( pd, "mp_frags", &config.mp_frags );
    parser_get_int( pd, "mp_balls", &config.mp_balls );
    parser_free( &pd );
}
示例#6
0
文件: main.c 项目: Flyswat/wmmp
int main ( int argc, char *argv[] ) {

	parser_t * parser = NULL;
	uint key = 0, Nc = 0, Nv = 0, Ns = 0, epw, e;
	double wcr_start,
		wcr_step,
		wcr_end,
		wcr = 0.0;
	vec wcr_vec;

	mat 	U = NULL;


	if ( argc == 1 )
	{
		fprintf( stderr, "Usage: %s config.cfg\n", argv[0] );
		exit( EXIT_FAILURE );
	}

	parser = parser_init( argc, argv, argv[1], NULL );

	key = parser_get_int( parser, "KEY" );
	wcr_vec = parser_get_vec( parser, "WCR" );
	Nv  = parser_get_int( parser, "Nv" );
	Nc  = parser_get_int( parser, "Nc" );
	Ns  = parser_get_int( parser, "Ns" );
	epw  = parser_get_int( parser, "EPW" );
	parser_delete( parser );


	if (vec_length(wcr_vec) != 3)
	{
		fprintf( stderr, "Invalid config for WCR values\n" );
		exit( EXIT_FAILURE );
	}
	wcr_start = wcr_vec[0];
	wcr_step = wcr_vec[1];
	wcr_end = wcr_vec[2];

	U = make_carriers( Nc, Nv, key );

	for (wcr = wcr_start; wcr <= wcr_end; wcr += wcr_step)
	{
		for (e=0; e<epw;e++)
		{
			mat	U_est = NULL,
				Y = NULL,
				Y_attack = NULL;

			// gen watermarks with U
			Y = make_Y(Nv, Ns, Nc, U, wcr);

			// Estimated carriers from PCA
			U_est = estimate_carriers(Y, Nv, Nc);

			// Attack Y
			Y_attack = attack(Y,U_est);

			print_dist(Y,Y_attack,wcr);

			mat_delete( Y );
			mat_delete( Y_attack );
			mat_delete( U_est );
		}
	}

	mat_delete( U );

	exit( EXIT_SUCCESS );
}
示例#7
0
文件: bask_import.c 项目: marc-q/bask
/*
	Function: import_ical (bask_core* tcore, struct bask_task** first, char* filename);
	Description: Imports tasks from a ical formated file.
	InitVersion: 0.0.1
*/
short import_ical (bask_core* tcore, struct bask_task** first, char* filename)
{
	unsigned int tid;
	short tactive, tpriority, tstate;
	char line[200], today[T_S_DUE], tadded[T_S_ADDED], tdue[T_S_DUE], tfinished[T_S_FINISHED], tproject[T_S_PROJECT], tdescription[T_S_DESCRIPTION];
	char tt_tmp[50];
	char saveptr[200];
	FILE* importfile;
	
	tid = tpriority = tstate = 0;
	tactive = TRUE;
	
	strcpy (tt_tmp, " ");
	strcpy (tadded, " ");
	strcpy (tdue, " ");
	strcpy (tfinished, " ");
	strcpy (tproject, " ");
	strcpy (tdescription, " "); 

	time_get_str (today, sizeof (today));

	importfile = fopen (filename, "r");

	if (importfile == NULL)
	{
		errors_filenotopened (filename);
		return -1;
	}
	
	while (fgets (line, sizeof (line), importfile) != NULL)
	{
		
		if (parser_get_str (line, "END:", tt_tmp, sizeof (tt_tmp), ICALSEP, saveptr) == 0)
		{
			if (utils_streq (tt_tmp, "VTODO") == 0)
			{
				if (tid == 0)
				{
					tcore->baskbin_uid++;
					tid = tcore->baskbin_uid;
				}
				
				/* TODO: Put that into a function! */
				if (BITGET (tcore->t_options, T_O_AUTODUETODAY) == TRUE &&
				    utils_streq (tdue, "NONE") != 0 &&
				   ( time_get_day (today) == time_get_day (tdue) &&
				      time_get_month (today) == time_get_month (tdue) &&
				      time_get_year (today) == time_get_year (tdue)))
				{
					tpriority = 2;
				}
				
				task_insert (first, tcore->tc_amount, tid, tactive, tpriority, tstate, tadded, tdue, tfinished, tproject, tdescription);
				
				tcore->tc_amount++;
				tid = tpriority= 0;
				
				/* If there is no clue to tactive we enable it by default. */
				tactive = TRUE;
				tstate = FALSE;
			}
		}
		else
		{
			parser_get_int (line, "UID:", &tid, ICALSEP, saveptr);
			
			/* Try multiple ways to find the data. */
			if (parser_get_str (line, "CREATED:", tt_tmp, sizeof (tt_tmp), ICALSEP, saveptr) == 0)
			{
				import_ical_getdatestr (tadded, tt_tmp);
			}
			else if (parser_get_str (line, "DTSTART:", tt_tmp, sizeof (tt_tmp), ICALSEP, saveptr) == 0)
			{
				import_ical_getdatestr (tadded, tt_tmp);
			}
			else if (parser_get_str (line, "COMPLETED:", tt_tmp, sizeof (tt_tmp), ICALSEP, saveptr) == 0)
			{
				if (import_ical_getdatestr (tfinished, tt_tmp) == -1)
				{
					strcpy (tfinished, "NONE");
					tstate = FALSE;
				}
				else
				{
					tstate = TRUE;
				}
			}
			else if (parser_get_str (line, "DTEND:", tt_tmp, sizeof (tt_tmp), ICALSEP, saveptr) == 0)
			{
				if (import_ical_getdatestr (tfinished, tt_tmp) == -1)
				{
					strcpy (tfinished, "NONE");
					tstate = FALSE;
				}
				else
				{
					tstate = TRUE;
				}
			}
			else if (parser_get_str (line, "DUE:", tt_tmp, sizeof (tt_tmp), ICALSEP, saveptr) == 0)
			{
				if (import_ical_getdatestr (tdue, tt_tmp) == -1)
				{
					strcpy (tdue, "NONE");
				}
			}
			
			parser_get_short (line, "PRIORITY:", &tpriority, ICALSEP, saveptr);
			parser_get_str (line, "DESCRIPTION:", tdescription, sizeof (tdescription), ICALSEP, saveptr);
			parser_get_str (line, "SUMMARY:", tproject, sizeof (tproject), ICALSEP, saveptr);
			
			if (parser_get_str (line, "STATUS:", tt_tmp, sizeof (tt_tmp), ICALSEP, saveptr) == 0)
			{
				if (utils_streq (tt_tmp, "IN-PROCESS") == 0)
				{
					tactive = TRUE;
				}
				else if (utils_streq (tt_tmp, "NEEDS-ACTION") == 0)
				{
					tactive = FALSE;
				}
			}
		}
	}
	
	fclose (importfile);
	
	return 0;
}
示例#8
0
文件: bask_import.c 项目: marc-q/bask
/*
	Function: import_baskbin (bask_core* tcore, struct bask_task** first, char* filename);
	Description: Imports the tasks from a baskbin formated file.
	InitVersion: 0.0.1
*/
short import_baskbin (bask_core* tcore, struct bask_task** first, char* filename)
{
	unsigned int tid;
	int tstate, bb_state;
	short tactive, tpriority;
	char line[200], today[T_S_DUE], tadded[T_S_ADDED], tdue[T_S_DUE], tfinished[T_S_FINISHED], tproject[T_S_PROJECT], tdescription[T_S_DESCRIPTION];
	char saveptr[200];
	FILE* importfile;

	bb_state = tid = tactive = tpriority = tstate = 0;
	
	strcpy (tadded, "NONE");
	strcpy (tdue, "NONE");
	strcpy (tfinished, "NONE");
	strcpy (tproject, " ");
	strcpy (tdescription, " ");
	
	time_get_str (today, sizeof (today));

	importfile = fopen (filename, "r");

	if (importfile == NULL)
	{
		errors_filenotopened (filename);
		return -1;
	}
	
	while (fgets (line, sizeof (line), importfile) != NULL)
	{		
		if (utils_streq (line, "BASKBIN\n") == 0)
		{
			bb_state = TRUE;
		}
		else if (utils_streq (line, "BBEND\n") == 0)
		{
			bb_state = FALSE;
		}
			
		if (bb_state == TRUE)
		{
			parser_get_int (line, "bbuid=", &tcore->baskbin_uid, BASKSEP, saveptr);
		}
		else if (utils_streq (line, "END\n") == 0)
		{
			/* TODO: Put that into a function! */
			if (BITGET (tcore->t_options, T_O_AUTODUETODAY) == TRUE &&
			    utils_streq (tdue, "NONE") != 0 &&
			    ( time_get_day (today) == time_get_day (tdue) &&
			      time_get_month (today) == time_get_month (tdue) &&
			      time_get_year (today) == time_get_year (tdue)))
			{
				tpriority = 2;
			}
			
			task_insert (first, tcore->tc_amount, tid, tactive, tpriority, tstate, tadded, tdue, tfinished, tproject, tdescription);
			tcore->tc_amount++;
		}
		else
		{
			parser_get_int (line, "tid=", &tid, BASKSEP, saveptr);
			parser_get_short (line, "tactive=", &tactive, BASKSEP, saveptr);
			parser_get_short (line, "tpriority=", &tpriority, BASKSEP, saveptr);
			parser_get_str (line, "tadded=", tadded, sizeof (tadded), BASKSEP, saveptr);
			parser_get_str (line, "tdue=", tdue, sizeof (tdue), BASKSEP, saveptr);
			
			if (parser_get_str (line, "tfinished=", tfinished, sizeof (tfinished), BASKSEP, saveptr) == 0)
			{
				/* Use this instead of tstate because this tells us already the state. */
				if (strlen (tfinished) == F_BB_S_DATE-1)
				{
					tstate = TRUE;
				}
				else
				{
					tstate = FALSE;
				}
			}
			
			parser_get_str (line, "tproject=", tproject, sizeof (tproject), BASKSEP, saveptr);
			parser_get_str (line, "tdescription=", tdescription, sizeof (tdescription), BASKSEP, saveptr);
		}
	}
	
	fclose (importfile);
	
	return 0;
}