Ejemplo n.º 1
0
void main (int argc, uchar **argv) {
    int i, j, c;
    struct stat f_stat;

    printf("compdic: Utility for compilation of word dictionaries\n");
    if (argc!=4) error("Usage:\ncompdic <alphabet> <text_dic> <comp_dic>");

    if ((fi=fopen(argv[1],"rb"))==NULL) error("Error opening alphabet file");
    memset(codes, 0, 256);
    for (letter_count=1; (c=getc(fi))>=' '; codes[c] = letter_count++) ;
    fclose(fi);

    stat(argv[2],&f_stat);
    init_mem(letter_count, f_stat.st_size + 50000);

    if ((fi=fopen(argv[2],"rb"))==NULL) error("Error opening input file");

    clear_state(0);
    owf[0]=0;

    wf1[0]=0;
    get_word_info(wf); // init of get_word_inf()

    while (get_word_info(wf)) {

        for (i=0; wf[i]==owf[i]; i++) ;		// find difference location

        for (j=strlen(owf)-1; j>=i; j--) state(j, codes[owf[j]]) = save_state(j+1);

        for (j=i+1; j<=strlen(wf); j++) clear_state(j);

        state(--j,0) = 1;

        strcpy(owf, wf);
    }
    fclose(fi);

    for (j=strlen(owf)-1; j>=0; j--) state(j, codes[owf[j]]) = save_state(j+1);

    save_cell(0, 'S', save_state(0));
    save_cell(1, 'T', last_full_cell+1);

    fo = fopen(argv[3], "wb");
    fwrite (cells, sizeof(tcell), last_full_cell+1, fo);
    fwrite (strings, 1, last_string, fo);
    fclose(fo);

    print_statistics();
}
Ejemplo n.º 2
0
/*
 * Write one level_t to file f, at current file position
 */
void save_level(level_t *l, FILE *f)
{
        int y, x;

        fwrite("LEVEL", sizeof(char), 5, f);
        fwrite(&l->xsize, sizeof(short), 1, f);
        fwrite(&l->ysize, sizeof(short), 1, f);
        for(y = 0; y < l->ysize; y++)
                for(x = 0; x < l->xsize; x++)
                        save_cell(&l->c[y][x], f);
}
Ejemplo n.º 3
0
/**
 * insert temp. state into the compressed array
 */
int new_state(int i, int k) {
    int j,c;

    for (j=first_free_cell; ; j++) {
        if (j>=cells_size-k) {
            if ((cells=realloc(cells,(cells_size+=cells_delta)*sizeof(tcell)))==NULL)
                error("Memory full");
            memset(cells+(cells_size-cells_delta),0,cells_delta*sizeof(tcell));
        }
        if (free_cell(j) && state_fits(i,j,k)) {
            for (c=1; c<=k; c++)
                if (state(i,c)!=0) save_cell(j+c, c, state(i,c));
            save_cell(j, (state(i,0)==0 ? letter_count : 0), string_set(i));
            break;
        }
    }
    if (j-COMPWIN > first_free_cell) first_free_cell = j-COMPWIN;
    for ( ; !free_cell(first_free_cell); first_free_cell++) ;
    if (j+k > last_full_cell) last_full_cell = j+k;
    return(j);
}