// add a new string to the hashtable void hashtable_add(hashtable_t *hashtable, const char *s) { char* tmp = strdup(s); int sum = sumchar(tmp); int hash = sum % (hashtable->size); struct __list_node *new_node = (struct __list_node *)malloc (sizeof(struct __list_node)); new_node->s = tmp; //list_add(&hashtable->hashtable[hash],tmp); if (hashtable->hashtable[hash] == NULL) { list_init(hashtable->hashtable[hash]); hashtable->hashtable->head = new_node; }else{ new_node->next = hashtable->hashtable[hash]->head; hashtable->hashtable->head = new_node; } free(tmp); }
int main(int argc, char **argv) { char deck[54]; int i, j; int mode = 0; /* default mode is encode, non-zero is decode */ for (i = 0; i < 54; i++) deck[i] = i + 1; if (argc > 1 && argv[1][0] == '-') { if(argv[1][1] == 'd') { mode = 1; } else if (argv[1][1] == 'e') { mode = 0; } else usage(); } else usage(); argc--; argv++; /* do key */ while (argc-- > 1) { char *ap = *++argv; while (*ap) { int c = *ap++; char tmp[53]; if (c >= 'a' && c <= 'z') c = c - 'a' + 'A'; if (c >= 'A' && c <= 'Z') { c = c - 'A' + 1; step(deck); i = 0; for (j = c; j < 53; j++) tmp[i++] = deck[j]; for (j = 0; j < c; j++) tmp[i++] = deck[j]; for (j = 0; j < 53; j++) deck[j] = tmp[j]; } } } j = 0; while ((i = getalpha()) != 0) { putchar(mode ? sumchar(i, -step(deck)) : sumchar(i, step(deck))); j++; if (j % 5 == 0) { if (j == 50) { j = 0; putchar('\n'); } else putchar (' '); } } j = j % 5; if (j) while (j < 5) { i = 'X'; putchar(mode ? sumchar(i, -step(deck)) : sumchar(i, step(deck))); j++; } printf("\n"); return EXIT_SUCCESS; }
void scamp2fb(FILE *input, FILE *output) /* includefile */ { FILE *fpou; unsigned char *gulp,*spew,*flip,sumof[256]; float realtime; double junk; char string[80],schead[640]; int i,j,k,doit,idump=0,nread,opened=0,s,f, ntotal=0,nclipped=0,ichans,sum,clipmax; //if (scamp_chans != nchans) exit(0); /* allocated space to store incoming and outgoing data blocks */ gulp = (unsigned char *) malloc(scamp_block_size * sizeof(unsigned char)); flip = (unsigned char *) malloc(scamp_block_size * sizeof(unsigned char)); spew = (unsigned char *) malloc(8*scamp_block_size * sizeof(unsigned char)); if (headerfile) { /* write output ASCII header file */ fpou=open_file("head","w"); fprintf(fpou,"Original SCAMP file: %s\n",inpfile); fprintf(fpou,"Sample time (us): %f\n",tsamp*1.0e6); fprintf(fpou,"Center freq (MHz): %f\n",fch1+(float)scamp_chans*foff/2.0); fprintf(fpou,"Channel band (kHz): %f\n",fabs(foff)*1000.0); fprintf(fpou,"Time stamp (MJD): %18.12f\n",tstart); fprintf(fpou,"RA (J2000): %f\n",src_raj); fprintf(fpou,"DEC (J2000): %f\n",src_dej); fclose(fpou); } if (clip_threshold>0.0) { /* clip samples which deviate by more than clip_threshold sigma times the mean. For these data, mean=nchan/2 and sigma = sqrt(nchan) */ clipmax=(float)(scamp_chans)/2.0+clip_threshold*sqrt((float)scamp_chans); for (i=0;i<256;i++) sumof[i]=sumchar(i); /* look-up table of byte sums */ } while (!feof(input)) { /* read ina 48k block of data */ nread=fread(gulp,1,scamp_block_size,input); /* do the band inversion here if necessary DEDISPERSE requires that the first channel is the highest frequency */ if (invert_band) { for (i=0; i<scamp_block_size; i++) flip[i]=flipchar(gulp[i]); for (i=0; i<scamp_block_size/scamp_chans; i++) { s=i*scamp_chans; f=(i+1)*scamp_chans; k=0; for (j=s;j<f;j++) { gulp[j]=flip[f-1-k]; k++; } } } /* now do clipping if necessary */ if (clip_threshold>0.0) { ichans=sum=j=0; for (i=0; i<scamp_block_size; i++) { /* keep track of sum over each byte (8 channels!) */ sum+=sumof[gulp[i]]; ichans+=8; if (ichans==scamp_chans) { /* decide whether to clip this sample */ if (sum>clipmax) { nclipped++; for (k=j; k<=i; k++) gulp[k]=0; } ntotal++; j=i+1; sum=0; ichans=0; } } } if (scamp_rawdata) { /* read off the header from the data and proceed as normal */ fread(schead,sizeof(schead),1,input); } else { /* extra (FORTRAN!) junk that gets written after each block */ fread(&junk,8,1,input); } /* decide whether to write out this block */ realtime=tsamp*idump; if ((doit=process(realtime,start_time,final_time))==-1) break; if (doit) { if (idump%1024 == 0) { if (!opened) { open_log("filterbank.monitor"); opened=1; } sprintf(string,"time:%.1fs",realtime); update_log(string); } /* output as single bit (default) or single byte data */ switch (obits) { case 1: idump+=8*nread/scamp_chans; i=1; /* write out only segments not in scamp.ignore */ for (j=1;j<=nread;j++) { if (!scamp_ignore[i]) fwrite(&gulp[j-1],1,1,output); i++; if (i>scamp_chans/8) i=1; } /*fwrite(gulp,1,nread,output);*/ break; case 8: k=0; for (i=0; i<nread; i++) { for (j=0;j<8;j++) { spew[k]=gulp[i]&1; gulp[i]>>=1; k++; if (!(k%scamp_chans)) idump++; } } fwrite(spew,1,8*scamp_block_size,output); break; } } } /* write out clipping statistics to ASCII file clip.stats */ if (clip_threshold>0) { fpou=open_file("clip.stats","w"); fprintf(fpou,"threshold %.1f sigma (sum = %d)\n", clip_threshold,clipmax); fprintf(fpou,"samples clipped = %d (total = %d)\n", nclipped,ntotal); fclose(fpou); } free(gulp);free(flip);free(spew); }