Beispiel #1
0
/**
 * Weryfikuje tekst ze strumienia z podanym słownikiem.
 *
 * Wypisuje informacje na standardowe wyjście i opcjonalnie wyjście błędów.
 * Tekst jest przepisywany na standardowe wyjście, za jednym wyjątkiem: słowa
 * (zdefiniowane jako spójne ciągi liter, zgodnie z tym, co zwraca funkcja
 * biblioteczna iswalpha) są poprzedzane znakiem '#', jeśli nie ma ich
 * w słowniku.
 *
 * Opcjonalnie, na wyjście błędów wypisywane są: pozycje, słowa i podpowiedzi
 * do słów ze standardowego wejścia, których nie ma w słowniku.
 *
 * @param [in] dict Słownik, z którym jest weryfikowany tekst.
 * @param [in] verbose Jeśli "true", drukowane są podpowiedzi na stderr.
 * @param [in] in Strumień tekstu. Jest wczytywany do napotkania znaku WEOF.
 */
void process_input(const struct dictionary * dict, bool verbose, FILE * in)
{
    struct parser_state pstate = { .dict = dict, .verbose = verbose,
        .line_num = 1, .column_num = 1, .last_non_word_column_num = 0,
        .buffer_iterator = word_buffer };

    wchar_t c;
    do
    {
        c = getwc(in);
        if (iswalpha(c))
        {
            cache_letter(&pstate.buffer_iterator, c);
        }
        else
        {
            if (word_buffer != pstate.buffer_iterator)
                process_word(&pstate);
            process_not_letter(c);
        }
        parser_state_update_position(&pstate, c);
    } while (WEOF != (wint_t) c);
}

/**
 * Przetwarza tekst ze standardowego wejścia i sprawdza go ze słownikiem
 * zapisanym w danej ścieżce. Format słownika musi odpowiadać formatowi
 * obsługiwanemu przez bibliotekę dictionary.
 * Szczegóły - patrz także: process_input.
 * @param [in] dict_path Ścieżka do słownika do wczytania.
 * @param [in] verbose Gdy flaga jest ustawiona, dodatkowe podpowiedzi
 * drukowane są na wyjście błędów.
 * @return Niezerowa wartość w przypadku błędu przy odczycie słownika z dysku.
 * 0 wpp.
 */
int process(const char * dict_path, bool verbose)
{
    int error_value;
    struct dictionary * dict;
    if (0 != (error_value = load_dictionary(dict_path, &dict)))
        return error_value;

    process_input(dict, verbose, stdin);
    dictionary_done(dict);
    return 0;
}
Beispiel #2
0
static char *process_token(char *p, object list) 
{ 
	char word[128], *w; 
	int inquote, noexpand; 

	while (*p && space(*p)) 
		p++; 
	if (noexpand = inquote = *p == '"') 
		p++; 
	for (w=word ; *p && (!space(*p) || inquote) ; p++) 
		if (inquote && *p == '"') 
		inquote = 0; 
	else 
		*w++ = *p; 
	*w = '\0'; 
	if (*word == '@') 
		process_file(list, word+1); 
	else if (*word) 
		process_word(word, list, noexpand); 
	return p; 
} 
Beispiel #3
0
static void process_tag(Job *job, FILE *pjf)
{
    int x, y, w, h;
    char tag[11];
    fscanf(pjf, "%10s", tag);
    if (!strcmp(tag, "word"))
    {
        fscanf(pjf, "%d %d %d %d", &x, &y, &w, &h);
        process_word(job, x, y, w, h);
        skip_to_end_of_tag(pjf);
    }
    else if (!strcmp(tag, "letter"))
    {
        fscanf(pjf, "%d %d %d %d", &x, &y, &w, &h);
        process_letter(job, x, y, w, h);
        skip_to_end_of_tag(pjf);
    }
    else
    {
        fprintf(stderr, "unknown PJF tag: %s\n", tag);
    }
}
Beispiel #4
0
static int global_ini_callback(const char *section, const char *name, const char *value)
{
    //fprintf(stdout, "[%s] '%s'='%s'\n", section, name, value);

    #define check_ini_section(section_name)    (strcasecmp(section, section_name) == 0)

    // Make sure that we return successfully as soon as name matches the correct option_name
    #define process_word(option_name, target, value_names)                           \
    if (ini_process_word(name, value, option_name, target, value_names)) return 1;

    #define process_short(option_name, target, value_names)                           \
    if (ini_process_short(name, value, option_name, target, value_names)) return 1;

    #define process_byte(option_name, target, value_names)                           \
    if (ini_process_byte(name, value, option_name, target, value_names)) return 1;

    #define process_boolean(option_name, target)                        \
    if (ini_process_boolean(name, value, option_name, target)) return 1;

    if (check_ini_section("General")) {
        process_boolean("enable_copyprot", &options.enable_copyprot);
        process_boolean("enable_mixer", &options.enable_mixer);
        process_boolean("enable_fade", &options.enable_fade);
        process_boolean("enable_flash", &options.enable_flash);
        process_boolean("enable_text", &options.enable_text);
        process_boolean("start_fullscreen", &start_fullscreen);
        process_word("pop_window_width", &pop_window_width, NULL);
        process_word("pop_window_height", &pop_window_height, NULL);
        process_boolean("use_correct_aspect_ratio", &options.use_correct_aspect_ratio);

        if (strcasecmp(name, "levelset") == 0) {
            if (value[0] == '\0' || strcasecmp(value, "original") == 0 || strcasecmp(value, "default") == 0) {
                use_custom_levelset = 0;
            } else {
                use_custom_levelset = 1;
                strcpy(levelset_name, value);
            }
            return 1;
        }
    }

    if (check_ini_section("AdditionalFeatures")) {
        process_boolean("enable_quicksave", &options.enable_quicksave);
        process_boolean("enable_quicksave_penalty", &options.enable_quicksave_penalty);
        process_boolean("enable_replay", &options.enable_replay);
    }

    if (check_ini_section("Enhancements")) {
        if (strcasecmp(name, "use_fixes_and_enhancements") == 0) {
            if (strcasecmp(value, "true") == 0) options.use_fixes_and_enhancements = 1;
            else if (strcasecmp(value, "false") == 0) options.use_fixes_and_enhancements = 0;
            else if (strcasecmp(value, "prompt") == 0) options.use_fixes_and_enhancements = 2;
            return 1;
        }
        process_boolean("enable_crouch_after_climbing", &options.enable_crouch_after_climbing);
        process_boolean("enable_freeze_time_during_end_music", &options.enable_freeze_time_during_end_music);
        process_boolean("enable_remember_guard_hp", &options.enable_remember_guard_hp);
        process_boolean("fix_gate_sounds", &options.fix_gate_sounds);
        process_boolean("fix_two_coll_bug", &options.fix_two_coll_bug);
        process_boolean("fix_infinite_down_bug", &options.fix_infinite_down_bug);
        process_boolean("fix_gate_drawing_bug", &options.fix_gate_drawing_bug);
        process_boolean("fix_bigpillar_climb", &options.fix_bigpillar_climb);
        process_boolean("fix_jump_distance_at_edge", &options.fix_jump_distance_at_edge);
        process_boolean("fix_edge_distance_check_when_climbing", &options.fix_edge_distance_check_when_climbing);
        process_boolean("fix_painless_fall_on_guard", &options.fix_painless_fall_on_guard);
        process_boolean("fix_wall_bump_triggers_tile_below", &options.fix_wall_bump_triggers_tile_below);
        process_boolean("fix_stand_on_thin_air", &options.fix_stand_on_thin_air);
        process_boolean("fix_press_through_closed_gates", &options.fix_press_through_closed_gates);
        process_boolean("fix_grab_falling_speed", &options.fix_grab_falling_speed);
        process_boolean("fix_skeleton_chomper_blood", &options.fix_skeleton_chomper_blood);
        process_boolean("fix_move_after_drink", &options.fix_move_after_drink);
        process_boolean("fix_loose_left_of_potion", &options.fix_loose_left_of_potion);
        process_boolean("fix_guard_following_through_closed_gates", &options.fix_guard_following_through_closed_gates);
        process_boolean("fix_safe_landing_on_spikes", &options.fix_safe_landing_on_spikes);
        process_boolean("fix_glide_through_wall", &options.fix_glide_through_wall);
        process_boolean("fix_drop_through_tapestry", &options.fix_drop_through_tapestry);
        process_boolean("fix_land_against_gate_or_tapestry", &options.fix_land_against_gate_or_tapestry);
    }

    if (check_ini_section("CustomGameplay")) {
        process_word("start_minutes_left", &start_minutes_left, NULL);
        process_word("start_ticks_left", &start_ticks_left, NULL);
        process_word("start_hitp", &start_hitp, NULL);
        process_word("max_hitp_allowed", &max_hitp_allowed, NULL);
        process_word("saving_allowed_first_level", &saving_allowed_first_level, NULL);
        process_word("saving_allowed_last_level", &saving_allowed_last_level, NULL);
        process_boolean("allow_triggering_any_tile", &allow_triggering_any_tile);
    }

    // [Level 1], etc.
    int ini_level = -1;
    if (strncasecmp(section, "Level ", 6) == 0 && sscanf(section+6, "%d", &ini_level) == 1) {
        if (ini_level >= 0 && ini_level <= 15) {
            // TODO: And maybe allow new types in addition to the existing ones.
            process_byte("level_type", &tbl_level_type[ini_level], &level_type_names_list);
            process_word("level_color", &tbl_level_color[ini_level], NULL);
            process_short("guard_type", &tbl_guard_type[ini_level], &guard_type_names_list);
            process_byte("guard_hp", &tbl_guard_hp[ini_level], NULL);
        } else {
            // TODO: warning?
        }
    }
    return 0;
}
Beispiel #5
0
int main(int argc, char **argv)
{
    Job job;
    int i;
    FILE *pjf;

    init_job(&job);
    job.core = create_core();
    
    for (i = 1; i < argc; i++)
    {
        char *opt = argv[i];
        char *arg = argv[i + 1];
        if (opt[0] == '-' && strcmp(opt, "-"))
        {
            if (!strcmp(opt, "-L") || !strcmp(opt, "--letter"))
            {
                job.just_one_letter = 1;
                job.just_one_word = 0;
            }
            if (!strcmp(opt, "-t") || !strcmp(opt, "--truth"))
            {
                i++; if (!arg) usage();
                job.just_one_letter = 1;
                job.just_one_word = 0;
                job.ground_truth = arg;
            }
            if (!strcmp(opt, "-a") || !strcmp(opt, "--append"))
            {
                job.append = 1;
            }
            else if (!strcmp(opt, "-W") || !strcmp(opt, "--word"))
            {
                job.just_one_letter = 0;
                job.just_one_word = 1;
            }
            else if (!strcmp(opt, "-l") || !strcmp(opt, "--lib"))
            {
                Library l;
                i++; if (!arg) usage();
                l = library_open(arg);
                library_discard_prototypes(l);
                add_to_core(job.core, l);
            }
            else if (!strcmp(opt, "-p") || !strcmp(opt, "-j") || !strcmp(opt, "--pjf"))
            {
                i++; if (!arg) usage();
                job.job_file_path = arg;
            }
            else if (!strcmp(opt, "-i") || !strcmp(opt, "--in"))
            {
                i++; if (!arg) usage();
                job.input_path = arg;                
            }
            else if (!strcmp(opt, "-o") || !strcmp(opt, "--out"))
            {
                i++; if (!arg) usage();
                set_core_orange_policy(job.core, 1);
                job.out_library_path = arg;
            }
            else if (!strcmp(opt, "-c") || !strcmp(opt, "--color"))
            {
                job.colored_output = 1;
            }
            else if (!strcmp(opt, "-n") || !strcmp(opt, "--nocolor"))
            {
                job.colored_output = 0;
            }
        }
    }


    load_image(&job);

    if (job.just_one_letter)
    {
        process_letter(&job, 0, 0, job.width, job.height);
        putchar('\n');
        if (job.ground_truth && job.out_library_path)
        {
            Library l = get_core_orange_library(job.core);
            if (library_shelves_count(l))
            {
                Shelf *s = library_get_shelf(l, 0);
                if (s->count)
                {
                    strncpy(s->records[0].text, job.ground_truth, MAX_TEXT_SIZE);
                }
            }
        }
    }
    else if (job.just_one_word)
    {
        process_word(&job, 0, 0, job.width, job.height);
        putchar('\n');
    }
    else 
    {
        if (!job.job_file_path)
        {
            fprintf(stderr, "You must specify a pjf file (or either -L or -W).\n");
            usage();
        }
        pjf = fopen(job.job_file_path, "r");
        if (!pjf)
        {
            perror(job.job_file_path);
            exit(1);
        }
        go(&job, pjf);
    }

    if (job.out_library_path)
        library_save(get_core_orange_library(job.core), job.out_library_path, job.append);

    free_bitmap(job.pixels);
    free_core(job.core);
    return 0;
}
Beispiel #6
0
void POCSAG::frame(int bit)
{
	int nh;
//	unsigned int fs0=0x7CD2, fs1=0x15D8;
	static unsigned int iWordNumber=0, cc, sr0=0, sr1=0;
	static bool bSynced=false;

	// update register
	sr0 = sr0 << 1;

	if ((sr1 & 0x8000) != 0)
	{
		sr0 = sr0 ^ 0x01;
	}
	sr1 = sr1 << 1;

	if (bit == 1) sr1 = sr1 ^ 0x01;

	else if (bit == -1)	// reset
	{
		bSynced = false;

		reset(); // reset in preperation of next message

		// just in case we finish a message, don't get any more address
		// codewords, and drop out of POCSAG mode...

		sr0 = 0;
		sr1 = 0;
	}

	if (!bSynced) // find pocsag sync sequence - sync up if there are less than 3 mismatched bits
	{
		nh = nOnes(sr0 ^ 0x7CD2) + nOnes(sr1 ^ 0x15D8);

		if (nh < 5)
		{
			bSynced = true;

			iWordNumber = 0;
			cc = 0;
		}
		else if (nh == 32)	// 32 errors, so must be inverted
		{
			InvertData();	// Invert receive polarity

			bSynced = true;

			iWordNumber = 0;
			cc = 0;
		}
	}
	else	// format, process 16 by 32 bit paging block
	{
		ob[cc] = bit;
		cc++;

		if (cc == 32)	// find idle codeword; strip it out
		{
			nh = nOnes(sr0 ^ 0x7A89) + nOnes(sr1 ^ 0xC197);

			if (nh < 5)
			{
				pocbit = 170;	// keep from switching back to flex if idle

				// at this point it is possible we still have a short message
				// in that we haven't even begun to show on screen yet...
				// This will be true for all messages with wordc < 8.
				// Next line finds them and flushes them out of the woodwork

				if (bAddressWord)
				{
					show_message();
				}
				reset();	// IDLE means message is terminated
			}
			else	// dump one block through with word position relative to sync word
			{		// (determines frame number which is the 3 lsb bits of POCSAG capcode).
				process_word(iWordNumber);
			}
			iWordNumber++;	// Number of Words
			cc = 0;
		}
		if (iWordNumber == 16)
		{
			bSynced = false;	// if block count is zero go back to look for sync word
		}
	}
}