Example #1
0
static char keyboard_cmd(enum DrawCmds cmd, struct guiKeyboard *keyboard, struct touch *coords)
{
    char lastchar = keyboard->lastchar;
    struct guiBox box;
    const char * const *keys = array[keyboard->type];

    u8 row, i;
    char ch = '\0';
    for(row = 0; row < 4; row++) {
        const char *ptr = keys[row];
        u8 first = get_first_char(ptr);
        u8 last  = get_last_char(ptr);
        u8 num_chars = 1 + last - first;
        u16 x_off = (LCD_WIDTH - KEY_W1 * num_chars) / 2;
        u16 y_off = Y_OFFSET + KEY_H * row;

        for(i = 0; i < strlen(ptr); i++) {
            char c = ptr[i];
            if (c == '\x09') { //CAPS
                _make_box(&box, 0, Y_OFFSET + KEY_H * 2, KEY_W2, KEY_H);
            } else if (c == '\x08') { //DEL
                _make_box(&box, LCD_WIDTH - KEY_W2 -1, Y_OFFSET + KEY_H * 2, KEY_W2, KEY_H);
            } else if (c == '\x01' || c == '\x02') { //change KB type
                _make_box(&box, 0, Y_OFFSET + KEY_H * 3, KEY_W3, KEY_H);
            } else if (c == '\x06') { //DONE
                _make_box(&box, LCD_WIDTH - KEY_W3 -1, Y_OFFSET + KEY_H * 3, KEY_W3, KEY_H);
            } else if (c == ' ') { //SPACE
                _make_box(&box, KEY_W3, Y_OFFSET + KEY_H * 3, LCD_WIDTH - 2 * KEY_W3 -1, KEY_H);
            } else {
                _make_box(&box, x_off + (i - first) * KEY_W1, y_off, KEY_W1, KEY_H);
            }
            if (cmd == KB_DRAW) {
                if ((c == '\x01' || c == '\x02') && (lastchar == '\x01' || lastchar == '\x02'))
                    keyboard->lastchar = c;
                u8 pressed = c == keyboard->lastchar;
                kb_draw_key(&box, set_case(c, keyboard->flags & FLAG_CAPS), pressed);
            } else if (cmd == KB_RELEASE || cmd == KB_PRESS) {
                if(c == lastchar) {
                    kb_draw_key(&box, set_case(c, keyboard->flags & FLAG_CAPS), cmd == KB_PRESS);
                    return '\0';
                }
            } else if(cmd == KB_COMPARE_AND_PRESS) {
                if (coords_in_box(&box, coords)) {
                    kb_draw_key(&box, set_case(c, keyboard->flags & FLAG_CAPS), 1);
                    ch = c;
                } else if(c == lastchar) {
                    kb_draw_key(&box, set_case(c, keyboard->flags & FLAG_CAPS), 0);
                }
            }
        }
    }
    return ch;
}
Example #2
0
int calcul_sol_unique_carre(SUDOKU grille, int ligne, int col){
	int i, j, k, l, ld, cd, val, seul, maj = 1;
	
	ld = 3*((ligne-1)/3)+1;
	cd = 3*((col-1)/3)+1;
	
	for(k=1; k<10; k++){
		if(get_possibilite_case(grille, ligne, col, k) != 0){
			val = get_possibilite_case(grille, ligne, col, k);
			seul = 0;
			for(i=ld; i<ld+3; i++){
				for(j=cd; j<cd+3; j++){
					for(l=1; l<10; l++){
						if(val == get_possibilite_case(grille, i, j, l) && (ligne != i || col != j)){
							seul++;
						}
					}
				}
			}
			if(seul == 0){
				set_case(grille, ligne, col, val);
				maj = 2;
			}
		}
	}
	
	return maj;
}
Example #3
0
/* met la valeur dans la case s'il reste une seule possibilite */
int set_val_possibilite_unique(SUDOKU grille, int ligne, int col){
	int indposs, count = 0, val, maj = 1;
	
	if(get_case(grille, ligne, col) == 0){
		for(indposs=1; indposs<10; indposs++){
			if(get_possibilite_case(grille, ligne, col, indposs) != 0){
				val = get_possibilite_case(grille, ligne, col, indposs);
				count++;
			}
		}
		
		if(count == 1){
			set_case(grille, ligne, col, val);
			maj = 2;
		}
		else if(count == 0){
			maj = 0;
		}
	}
	
	return maj;
}
Example #4
0
/*static*/
 WantGkEnd(gk_string *wantend, gk_string *haveend, bool writeflag, int strict)
{
	int compval;

	word_form wform, hform;
/*
	Dialect wdial = dialect_of(wantend);
	Dialect hdial = dialect_of(haveend);
*/
	Dialect wdial;
	Dialect hdial;

	Dialect d/*, AndDialect()*/;

	int wmood = mood_of( forminfo_of(wantend) );
	int hmood = mood_of( forminfo_of(haveend) );

	int wvoice = voice_of( forminfo_of(wantend) );
	int hvoice = voice_of( forminfo_of(haveend) );

	int wtense = tense_of( forminfo_of(wantend) );
	int htense = tense_of( forminfo_of(haveend) );

	int wgender = gender_of( forminfo_of(wantend) );
	int hgender = gender_of( forminfo_of(haveend) );

	int wdegree = degree_of( forminfo_of(wantend) );
	int hdegree = degree_of( forminfo_of(haveend) );

	int wcase = case_of( forminfo_of(wantend) );
	int hcase = case_of( forminfo_of(haveend) );

	int wperson = person_of( forminfo_of(wantend) );
	int hperson = person_of( forminfo_of(haveend) );

	int wnumber = number_of( forminfo_of(wantend) );
	int hnumber = number_of( forminfo_of(haveend) );

	char wendstr[MAXWORDSIZE];
	char * hendstr = gkstring_of(haveend);

	wform = forminfo_of(wantend);
	hform = forminfo_of(haveend);
	
/*
 * basically, we check to see if any particular form has been requested
 * and check each ending against this. if nothing is asked for (e.g. no
 * mood or voice is specified) then we just take the ending (i.e. we take
 * subjunctive, optative, indicative etc. rather than just the optatives or
 * subjunctives or whatever...
 */
	setwendstr(wendstr,gkstring_of(wantend));
	if( wmood && hmood != wmood ) {
		if( hmood || (!hmood && strict) ) {
#ifdef SHOWFAIL
printf("failing on wmood %o hmood %o\n", wmood, hmood );
#endif
			return(0);
		}
	}

/*
 *
 *  perfect actives are, by definition, always active in form
 */


   	if( (stemtype_of(wantend) & PPARTMASK ) == PP_PF ) {
   		wvoice = ACTIVE;
   		voice_of(wform) = ACTIVE;
   	}

   	if( (stemtype_of(wantend) & PPARTMASK ) == PP_SU && 
	     cur_lang() == LATIN && wvoice == DEPONENT ) {
			set_voice(forminfo_of(haveend), wvoice);
   	}

	if( cur_lang() == LATIN && wvoice == DEPONENT ) {
		if( hvoice == ACTIVE && hmood != PARTICIPLE && hmood != GERUNDIVE ) return(0);
	} else if( wvoice ) {
		if( ! Want_Voice( wform , hform )) {
		   if( hvoice || (!hvoice && strict)) {
#ifdef SHOWFAIL
printf("have [%s] failing on wvoice %o hvoice %o\n",hendstr, wvoice, hvoice );
#endif
				return(0);
			}
		} else {
/*
 * note that an ending may generally be either middle or passive, but
 * if the stem in hand is strictly middle or strictly passive,
 * then the ending inherits that limitation.
 */

			if( writeflag == YES )
			   set_voice(forminfo_of(haveend), wvoice);
		}
	}

	if( wtense && htense != wtense )
		if( htense || (!htense && strict) ) {
#ifdef SHOWFAIL
printf("failing on wtense %o htense %o\n", wtense, htense );
#endif
			return(0);
		}

/*
 * note that here you only fail if the gender is set in the
 * ending as well as in the stem.
 * 
 * if we follow the normal algorithm, a masculine stem would 
 * not match a set of endings that had no gender specified.
 *
 * likewise, we need to match either masculine or feminine against
 * an ending that is common to both (but not, for example, to a neuter
 * stem, e.g. -es in nom pl for masc and fem, but -a for neuter)
 */
/*

/*
 * only fail if gender set for both.
 * 	e.g., dwr- from dw=ron will want to find 
 * endings such as -on, or -a that are specifically flagged
 * as neuter, but will also want to find other endings
 * that can attach themselves to any gender
 */
	if( wgender ) {
		if( hgender ) {
			if( ! Want_Gender(wform, hform)) {
#ifdef SHOWFAIL
printf("failing with hgender %o and wgender %o\n", hgender , wgender );
#endif
				return(0);
			}
		}
		if( writeflag )
			if( Want_Gender(wform,hform) )
				set_gender(forminfo_of(haveend), Want_Gender(wform, hform));
			else
			   	set_gender(forminfo_of(haveend), wgender );
	}

	if( wcase ) {
		if( ! Want_Case(wform, hform))
			if( hcase || (!hcase && strict) ) {
#ifdef SHOWFAIL
printf("failing with hcase %o wcase %o\n", hcase , wcase );
#endif
				return(0);
			}
if( writeflag ) {
#ifdef SHOWFAIL
printf("[%s] hcase %o wcase %o anded %o\n", gkstring_of(haveend), hcase, wcase, hcase & wcase );
#endif
		set_case(forminfo_of(haveend) , wcase&hcase );
}
	}

	if( wperson && hperson != wperson ) {
		if( hperson || (!hperson && strict) ) {
#ifdef SHOWFAIL
printf("failing with hperson %o wperson %o\n", hperson , wperson );
#endif
			return(0);
		}
	}

	if( wnumber && hnumber != wnumber )
		if( hnumber || (!hnumber && strict) ) {
#ifdef SHOWFAIL
printf("failing on wnumber %o hnumber %o\n", wnumber , hnumber );
#endif
			return(0);
		}

	if( *wendstr && strict ) {
	
		if( (compval=endstrcmp(wendstr,hendstr))){
	/*
	 * this expects that you have a sorted list of endings and that you
	 * don't want to look for endings that are alphabetically larger
	 * than the ending that you want 
	 */
			if( compval < 0 && noaccstrcmp(wendstr,hendstr) ) {

#ifdef SHOWFAIL
#endif

				return(compval);
			}
#ifdef SHOWFAIL
printf("failing on wendsrr\n");
#endif
		/*
		 * don't fail if you did not specifically ask for a long vowel.
		 *
		 * do fail if you specifically ask for a long vowel and this ending is not 
		 * marked as long.
		 */
		if( has_quantacc(hendstr) != has_quantacc(wendstr) ) {
			char tmp[MAXWORDSIZE];
			
			Xstrncpy(tmp,hendstr,MAXWORDSIZE);
			stripquantacc(tmp);
			compval=endstrcmp(wendstr,tmp);
/*
			compval=dictstrcmp(wendstr,tmp);
*/
			if( compval  ) 				
						return(0);
		}  else
						return(0);
		} else {
			/*
			 * if you ask for "w=", then match only "w=" and not "w".
			 *
			 * if you ask for "w", however, then match both "w=" and "w".
			 */

			if( hasaccent(wendstr)  ) {
				char tmp1[MAXWORDSIZE];
				char tmp2[MAXWORDSIZE];
				
				Xstrncpy(tmp1,wendstr,(int)sizeof tmp1);
				stripquant(tmp1);
				
				Xstrncpy(tmp2,hendstr,(int)sizeof tmp2);
				stripquant(tmp2);
				if( strcmp(tmp1,tmp2) )
						return(0);
			}
		}
	}

	if(  ! EuphEnd(wantend,haveend,strict) ) {
#ifdef SHOWFAIL
printf("[%s] failing on euph end\n", gkstring_of(haveend) );
#endif
		return(0);
	}
	wdial = dialect_of(wantend);
	hdial = dialect_of(haveend);

/*
 * note that we are checking not for equality, but to see if
 * we want any of the dialect bits set for the current ending
 */
	if( (d=AndDialect(hdial,wdial)) < 0 )
		return(0);
/*
	else if( writeflag ) {
		set_dialect(haveend,d);
	}
*/
/*
 * we currently mark a)/ristos as "os_h_on superl". 
 * we thus want a)rist- to have all the normal endings (-os,-h,-on,-ou,-hs,-ou)
 * but not to have endings such as "-o/tatos" or "-w/teros" tacked onto it.
 */
 
/*
 * grc 6/5/89
 *
 * this system prevents morphology formulas from generating any actual endings.  the
 * formula has the flag "comp" or "superl", but none of the endings in the basic
 * paradigms are so marked, so they are all skipped.  i added the requirement that this
 * rule only be active if strict is non zero to get around this (this is much the same
 * strategy that we took with iteratives.
 */
	if( wdegree ) {
		if(  hdegree && wdegree != hdegree /* grc 6/5/89 */ && strict /* end mod*/) {
			if( hdegree || (!hdegree && strict) )
				return(0);
		}
		if( wdegree && writeflag ) set_degree(forminfo_of(haveend),wdegree);
	}

	if( ! RightMorphflags(wantend,haveend)) {
#ifdef SHOWFAIL
printf("[%s] failing on rightmorphflags\n", gkstring_of(haveend) );
#endif
		return(0);
	}
	return(1);
}
Example #5
0
 EndingOk(char *keys, gk_string *gstr, gk_string *avoidgstr, int wantderiv)
{
	int good = 0;
	gk_word * BlnkGkword;
	
	Cur_gkend = BlankGkend;
	BlnkGkword = CreatGkword(1);
	ScanAsciiKeys(keys,BlnkGkword,&Cur_gkend,avoidgstr);
	FreeGkword(BlnkGkword);
	
	if( wantderiv ) {
		if( ! derivtype_of(gstr) || derivtype_of(gstr) < 0 ) return(0);
		
		if( derivtype_of(gstr) != derivtype_of(&Cur_gkend)) 
			return(0);
	}
	
	good =  (WantGkEnd(gstr,&Cur_gkend,NO,0) > 0) &&
	  (NoWantGkEnd(avoidgstr,&Cur_gkend,1) == 0 );
/*
if( ! good ) {
printf("gstr [%s] [%s] want %o nowant %o\n",gkstring_of(gstr), gkstring_of(&Cur_gkend), WantGkEnd(gstr,&Cur_gkend,NO,0) ,
NoWantGkEnd(avoidgstr,&Cur_gkend,1)  );
LPrntGstr(gstr,stdout);
LPrntGstr(&Cur_gkend,stdout);

}
*/
	if( good ) {
		int case1, case2;
		int gend1, gend2;
		int num2, pers2;
		int voice1, voice2;
		Dialect dial1, dial2;

		voice1 = voice_of(forminfo_of(&Cur_gkend));
		voice2 = voice_of(forminfo_of(gstr));
		
		if( voice1 ) set_voice(forminfo_of(gstr),voice1);
		
		case1 = case_of(forminfo_of(&Cur_gkend));
		case2 = case_of(forminfo_of(gstr));
		if( case1 & case2 )
			set_case(forminfo_of(gstr), (case1 & case2) );
		else if( case1 && ! case2 )
			set_case(forminfo_of(gstr), case1 );
	
		num2 = number_of(forminfo_of(&Cur_gkend));
		if( num2 )
			set_number(forminfo_of(gstr), number_of(forminfo_of(&Cur_gkend)) );

		pers2 = person_of(forminfo_of(&Cur_gkend));
		if( pers2 )
			set_person(forminfo_of(gstr), person_of(forminfo_of(&Cur_gkend)) );

		gend1 = gender_of(forminfo_of(&Cur_gkend));
		gend2 = gender_of(forminfo_of(gstr));
		if( gend1 & gend2 )
			set_gender(forminfo_of(gstr), (gend1 & gend2) );
		else if( gend1 && ! gend2 )
			set_gender(forminfo_of(gstr), gend1 );

		dial1 = dialect_of(&Cur_gkend);
		dial2 = dialect_of(gstr);
		if( dial1 & dial2 ) 
			set_dialect(gstr,(dial1 & dial2) );
		else if( dial1 && (! dial2) )
			set_dialect(gstr,dial1);
			
		add_morphflags(gstr,morphflags_of(&Cur_gkend));
	}
	return( good );
}
Example #6
0
void read_cli_options(int argc, char **argv,
                        struct kw_conf * (*kw)(const char *), FILE ** fin, FILE ** fout)
{
    int i;
    if (argc == 1) return; // use stdin and stdout

    if (argc == 2 && strcmp(argv[1], "--create-config-file") == 0) {
        if (create_conf_file(FSQLF_CONFFILE_NAME) != 0) {
            exit(1);
        } else {
            fprintf(stderr, "File '%s' (re)created.\n", FSQLF_CONFFILE_NAME);
            exit(0);
        }
    }

    for (i = 1; i < argc; i++) {
        if (argv[i][0] != '-') {
            if ((*fin) == stdin) {
                //try to openinig INPUT file
                (*fin) = fopen(argv[1], "r");
                if (!(*fin)) {
                    FAIL_WITH_ERROR(1, "Error opening input file: %s", argv[i]);
                }
            }
            else if ((*fout) == stdout) {   //try to openinig OUTPUT file (only if INPUT file is set)
                (*fout) = fopen(argv[2], "w+");
                if (!(*fout)) FAIL_WITH_ERROR(1, "Error opening output file: %s", argv[i]);
            }
        } else if (ARGV_MATCH(i, "-i")) {
            if (++i >= argc) FAIL_WITH_ERROR(1, "Missing value for option : %s", argv[i-1]);
            (*fin) = fopen(argv[i], "r");
            if (!(*fin)) FAIL_WITH_ERROR(1, "Error opening input file: %s", argv[i]);
        } else if (ARGV_MATCH(i, "-o")) {
            if (++i >= argc) FAIL_WITH_ERROR(1, "Missing value for option : %s", argv[i-1]);
            (*fout) = fopen(argv[i], "w+");
            if (!(*fout)) FAIL_WITH_ERROR(1, "Error opening output file: %s", argv[i]);
        } else if (ARGV_MATCH(i, "--config-file")) {
            if (++i >= argc) FAIL_WITH_ERROR(1, "Missing value for option : %s", argv[i-1]);
            if (read_conf_file(argv[i], kw) == READ_FAILED) {
                FAIL_WITH_ERROR(1, "Error reading configuration file: %s", argv[i]);
            }
        } else if (ARGV_MATCH(i, "--select-comma-newline")) {
            if (++i >= argc) FAIL_WITH_ERROR(1, "Missing value for option : %s", argv[i-1]);
            if (strcmp(argv[i], "after") == 0) {
                kw("kw_comma")->before.new_line = 0;
                kw("kw_comma")->after.new_line  = 1;
            } else if (strcmp(argv[i], "before") == 0) {
                kw("kw_comma")->before.new_line = 1;
                kw("kw_comma")->after.new_line  = 0;
            } else if (strcmp(argv[i], "none") == 0) {
                kw("kw_comma")->before.new_line = 0;
                kw("kw_comma")->after.new_line  = 0;
            }
        } else if (ARGV_MATCH(i, "--keyword-case")) {
            if (++i >= argc) FAIL_WITH_ERROR(1, "Missing value for option : %s", argv[i-1]);
            if (strcmp(argv[i], "none") == 0) {
                set_case(CASE_none);
            } else if (strcmp(argv[i], "upper") == 0) {
                set_case(CASE_UPPER);
            } else if (strcmp(argv[i], "lower") == 0) {
                set_case(CASE_lower);
            } else if (strcmp(argv[i], "initcap") == 0) {
                set_case(CASE_Initcap);
            }
        } else if (ARGV_MATCH(i, "--keyword-text")) {
            if (++i >= argc) FAIL_WITH_ERROR(1, "Missing value for option : %s", argv[i-1]);
            if (strcmp(argv[i], "original") == 0) {
                set_text_original(1);
            } else if (strcmp(argv[i], "default") == 0) {
                set_text_original(0);
            }
        } else if (ARGV_MATCH(i, "--select-newline-after")) {
            kw("kw_select")->after.new_line = get_int_arg(++i, argc, argv);
        } else if (ARGV_MATCH(i, "--newline-or-before")) {
            kw("kw_or")->before.new_line = get_int_arg(++i, argc, argv);
        } else if (ARGV_MATCH(i, "--newline-or-after")) {
            kw("kw_or")->after.new_line = get_int_arg(++i, argc, argv);
        } else if (ARGV_MATCH(i, "--newline-and-before")) {
            kw("kw_and")->before.new_line = get_int_arg(++i, argc, argv);
        } else if (ARGV_MATCH(i, "--newline-and-after")) {
            kw("kw_and")->after.new_line = get_int_arg(++i, argc, argv);
        } else if (ARGV_MATCH(i, "--newline-major-sections")) {
            int new_line_count = get_int_arg(++i, argc, argv);
            kw("kw_from")->before.new_line = new_line_count;
            kw("kw_where")->before.new_line = new_line_count;
            kw("kw_inner_join")->before.new_line = new_line_count;
            kw("kw_left_join")->before.new_line  = new_line_count;
            kw("kw_right_join")->before.new_line = new_line_count;
            kw("kw_full_join")->before.new_line  = new_line_count;
            kw("kw_cross_join")->before.new_line = new_line_count;
        } else if (ARGV_MATCH(i, "--debug")) {
            if (++i >= argc ) FAIL_WITH_ERROR(1, "Missing or invalid value for option : %s", argv[i-1]);
            if (ARGV_MATCH(i, "none")) debug_level |= DEBUGNONE;
            else if (ARGV_MATCH(i, "state")) debug_level |= DEBUGSTATES;
            else if (ARGV_MATCH(i, "match")) debug_level |= DEBUGMATCHES;
            else if (ARGV_MATCH(i, "parenthesis")) debug_level |= DEBUGPARCOUNTS;
            else FAIL_WITH_ERROR(1, "Missing or invalid value for option : %s", argv[i-1]);
        } else if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-h") == 0) {
            usage_info(argc, argv);
            exit(0);
        } else FAIL_WITH_ERROR(1, "Option `%s' is not recognised or used incorrectly.\nTry `%s --help' for more information\n", argv[i], argv[0]);
    }
}