int16_t check_and_look (int16_t *lth,LTIMG **wrddef, voc_state *dindict,int16_t status,int16_t incr) { #ifdef OVERVOC if(CHECKVOC) { int32_t size; size=read_all_file((char *)Q.temp_voc_file,V_POINT(Q.v_state.vocseg,0)); unlink(Q.temp_voc_file); if ( size != -1 ) { dindict->vocfree=size; voc_open(dindict); } else if ( voc_init(dindict) < 0 ) return -3; } #endif return(look_through_voc(lth,wrddef,dindict,status,incr,NULL)); }
uint32_t LoadUserDict(char *DictName, char *pool, uint32_t pool_size, voc_state *user_dict) { int32_t size; pool_size = pool_size; if (_IsUserDict(DictName) != UD_PERMITTED) return 0; #ifdef TURBO_C if(TEST_PRPH(pool)) pool=ALI_PR(pool); #endif user_dict -> vocseg = (uchar *) SET_VOC_ROOT(pool); { int16_t Fh; char nm[128]; strcpy(nm, DictName); Fh = TGOPEN(VC_STREAM, nm, (int16_t)(O_RDONLY | O_BINARY), S_IREAD); if (Fh == -1) return 0; if (TGFILELTH(Fh) > MAX_VOC_SIZE) { TGCLOSE(Fh); return 0; } size = TGREAD(Fh, V_POINT(user_dict -> vocseg, 0), TGFILELTH(Fh)); TGCLOSE(Fh); } if (size <= 0) return 0; else { voc_open(user_dict); user_dict -> vocfree = (uint16_t) size; } return MAX_VOC_SIZE; }
ALLEGRO_SAMPLE *_al_load_voc_f(ALLEGRO_FILE *file) { AL_VOC_DATA *vocdata; ALLEGRO_SAMPLE *sample = NULL; size_t pos = 0; /* where to write in the buffer */ size_t read = 0; /*bytes read during last operation */ char* buffer; size_t bytestoread = 0; bool endofvoc = false; vocdata = al_malloc(sizeof(AL_VOC_DATA)); memset(vocdata, 0, sizeof(*vocdata)); /* * Open file and populate VOC DATA, then create a buffer for the number of * samples of the frst block. * Iterate on the following blocks till EOF or terminator block */ vocdata = voc_open(file); if (!vocdata) return NULL; ALLEGRO_DEBUG("channels %d\n", vocdata->channels); ALLEGRO_DEBUG("word_size %d\n", vocdata->sample_size); ALLEGRO_DEBUG("rate %d\n", vocdata->samplerate); ALLEGRO_DEBUG("first_block_samples %d\n", vocdata->samples); ALLEGRO_DEBUG("first_block_size %d\n", vocdata->samples * vocdata->sample_size); /* * Let's allocate at least the first block's bytes; */ buffer = al_malloc(vocdata->samples * vocdata->sample_size); if (!buffer) { return NULL; } /* * We now need to iterate over data blocks till either we hit end of file * or we find a terminator block. */ bytestoread = vocdata->samples * vocdata->sample_size; while(!endofvoc && !al_feof(vocdata->file)) { uint32_t blocktype = 0; uint32_t x = 0, len = 0; read = al_fread(vocdata->file, buffer, bytestoread); pos += read; READNBYTES(vocdata->file, blocktype, 1, NULL); // read next block type if (al_feof(vocdata->file)) break; switch (blocktype) { case 0:{ /* we found a terminator block */ endofvoc = true; break; } case 2:{ /*we found a continuation block: unlikely but handled */ x = 0; bytestoread = 0; READNBYTES(vocdata->file, bytestoread, 2, NULL); READNBYTES(vocdata->file, x, 1, NULL); bytestoread += x<<16; /* increase subsequently storage */ buffer = al_realloc(buffer, sizeof(buffer) + bytestoread); break; } case 1: // we found a NEW data block starter, I assume this is wrong case 8: // and let the so far read sample data correctly in the case 9:{ // already allocated buffer. endofvoc = true; break; } case 3: /* we found a pause block */ case 4: /* we found a marker block */ case 5: /* we found an ASCII c-string block */ case 6: /* we found a repeat block */ case 7:{ /* we found an end repeat block */ /* all these blocks will be skipped */ unsigned int ii; len = 0; x = 0; READNBYTES(vocdata->file, len, 2, NULL); READNBYTES(vocdata->file, x, 1, NULL); len += x<<16; // this is the length what's left to skip */ for (ii = 0; ii < len ; ++ii) { al_fgetc(vocdata->file); } bytestoread = 0; //should let safely check for the next block */ break; } default: break; } } sample = al_create_sample(buffer, pos, vocdata->samplerate, _al_word_size_to_depth_conf(vocdata->sample_size), _al_count_to_channel_conf(vocdata->channels), true); if (!sample) al_free(buffer); voc_close(vocdata); return sample; }