int lookup_done(void *context) { struct lookup_context *ctxt = (struct lookup_context *) context; int rv = close_parse(ctxt->parse); free(ctxt); return rv; }
long long get_WAPP_info(char *filename, FILE * files[], int numfiles, int numwapps, struct HEADERP **h, struct wappinfo *w) { int ii, wappindex; struct HEADERP *h2; struct wappinfo w2; long long N = 0; // Read the header of the first file with the yacc/lex generated tools // This sets the basic parameters of the conversion *h = head_parse(files[0]); set_wappinfo(*h, w); if (get_hdr_int(*h, "isalfa")) { w->beamnum = wapp_beamnum(filename); if (w->beamnum == -1) { printf("Warning! isalfa = 1, but beamnum is not set!\n"); exit(1); } } // Number of samples in the file w->numsamples = (chkfilelen(files[0], 1) - w->header_size) / w->bytes_per_sample; // This will be the total number of samples to convert N = w->numsamples; // Skip the ASCII and binary header chkfseek(files[0], w->header_size, SEEK_SET); // loop through all the other files and check/prep them for (ii = 1; ii < numfiles; ii++) { // Read the header with the yacc/lex generated tools h2 = head_parse(files[ii]); set_wappinfo(h2, &w2); close_parse(h2); // Number of samples in the file w2.numsamples = (chkfilelen(files[ii], 1) - w2.header_size) / w2.bytes_per_sample; // Skip the ASCII and binary header chkfseek(files[ii], w2.header_size, SEEK_SET); // Do a basic check to see if the files are similar wappindex = ii % numwapps; if (wappindex == 0) { // Same WAPP if (!compare_samewapp_files(ii, w, &w2)) exit(1); N += w2.numsamples; } else { // Different WAPPs if (!compare_diffwapp_files(ii, numwapps, wappindex, w, &w2)) exit(1); } } return N; }
struct HEADERP *head_parse(FILE *f) { int fd, count, ret; unsigned char byte; struct HEADERKEY *key; struct HEADERP *h; char temp[2048]; fd = fileno(f); rewind(f); if((ret = read( fd, temp, 2048)) != 2048 ) { return(NULL); } temp[2047] = 0; if( !strstr( temp, "struct WAPP_HEADER" ) ) { return(NULL); } count = 2048; while( (ret = read( fd, &byte, 1)) == 1 ) { if( byte == 0 ) break; count++; } wapp_incfile_length=count; if( ret < 0) { return(NULL); } h = ( struct HEADERP *)malloc( sizeof(struct HEADERP)); bzero( h, sizeof(struct HEADERP)); h->offset = count+1; h->fd = fd; h->buf = (char *)malloc( h->offset); lseek(fd, 0, SEEK_SET); read(fd, h->buf, h->offset ); yacc_input = h; while(yyparse()); /* use yacc to parse the header */ yyparse(); if( !(h->headlen = count_size(h))) { close_parse(h); return(NULL); } h->header = (void *)malloc( h->headlen ); if( read( fd, h->header, h->headlen ) != h->headlen ) { perror("read header"); close_parse(h); return(NULL); } key = h->head; count = 0; while( key ) { key->len = key_sizes(key->type); key->offset = count; count += key->len* key->alen; key = key->next; } return(h); }