static int rec_this_sets(unsigned int *rb, char *resfile) { int i; RBB_P head=NULL; RBB_P tmp; for(i = 0; i< 6; i++) { tmp = (RBB_P)malloc(sizeof(RBB_T)); tmp->value = rb[i]; tmp->next = NULL; head = insert_num(tmp, head); } FILE *fp; fp = fopen(resfile, "aw"); assert(fp); tmp = head; for(i = 0; i<6; i++) { fprintf(fp, "%02d ", tmp->value); tmp = tmp->next; } fprintf(fp, " %02d\n", rb[6]); fclose(fp); log("gen this record done\n"); free_mem(head); return 0; }
void test_num_queue() { num_queue q; q = initialize_num_queue(3); insert_num(&q, 1.31); insert_num(&q, 5.27); insert_num(&q, 2.141); insert_num(&q, 7.893); insert_num(&q, 10.567); print_num_queue(q); float x = get_first_num(&q); while (x != -1.0) { printf("Remove: %f\n", x); print_num_queue(q); x = get_first_num(&q); } }
static int insert_left_skip(int p,int skip) { skip += left_skip; if (skip) { write_buff[p++] = 27; write_buff[p++] = SPACE; p = insert_num(write_buff,p,skip); } return p; }
static void insert_picture(char *filename,int align,int line,int lsize) { int x, y; short *psiz; char *c = write_buff; psiz = ablock(get_data_handle(filename,pcx_8bit_decomp)); switch (align) { case ANUM_CENTER: x = (XMAX-psiz[0])/2; y = linepos; linepos += psiz[1]; *c++= 27; *c++= END_LINE; c += insert_num(c,0,psiz[1]+last_skip); break; case ANUM_LEFT: x = 0; y = linepos; left_skip = psiz[0]+5; total_width = XMAX-left_skip; break; case ANUM_RIGHT: total_width = (x = XMAX-psiz[0])-5; left_skip = 0; y = linepos; break; } if (!lsize) lsize = psiz[1]-line; picture_len = lsize; *c++= 27; *c++= PICTURE; while (*filename) *c++= *filename++; *c++=':'; c += insert_num(c,0,x); c += insert_num(c,0,y); c += insert_num(c,0,line); c += insert_num(c,0,lsize); *c++= 0; str_add(&all_text,write_buff); }
static int insert_end_line_and_save(int p,int ys) { int size; while (read_buff[buff_pos] ==' ' && buff_pos<buff_end) buff_pos++; size = buff_end-buff_pos; if (size)memcpy(read_buff,read_buff+buff_pos,size); write_buff[p++] = 27; write_buff[p++] = END_LINE; p = insert_num(write_buff,p,ys); write_buff[p++] = 0; str_add(&all_text,write_buff); buff_pos = size; buff_end = buff_pos; if (picture_len>0) picture_len -= ys; if (picture_len<= 0 && total_width != XMAX) { picture_len = 0; total_width = XMAX; left_skip = 0; } return p; }
static void save_line_oboustrane() { char space[] =" "; int xs,ys,ss,mez,mm = 0,mc = 0; int i,p; for(i = 0,xs = 0,mez = 0,ys = 0;i<buff_pos;i++) { space[0] = read_buff[i]; if (space[0] == 32) mez++;else { xs += text_width(space); p = text_height(space); if (p>ys) ys = p; } } ss = total_width-xs; p = 0; if (!ys) ys = last_skip; next_line(ys); p = insert_left_skip(p,0); for(i = 0,mc = 0;i<buff_pos;i++) { if (read_buff[i] == 32) { int sp; write_buff[p++] = 27; write_buff[p++] = SPACE; mc++; sp = ss*(mc)/mez; p = insert_num(write_buff,p,sp-mm); mm = sp; } else write_buff[p++] = read_buff[i]; } insert_end_line_and_save(p,ys); }
int main(void) { int i,j,k; int temp1, temp2, temp3, temp; int terminate = 0; char filename[100]; FILE *in, *out; // /* for(int t = 1; t <= 10; t++) { itoa(t, filename, 10); strcat(filename,".in"); in = fopen(filename,"r"); */ // n = 0; m = 0; terminate = 0; for(i = 0; i <= 300000; i++) set[i] = -1; while(1){ fscanf(IN,"%d",&temp1); switch(temp1){ case 0: terminate = 1; break; case 1: fscanf(IN,"%d",&temp2); insert_num(temp2); break; case 2: extract(); break; case 3: fscanf(IN,"%d %d",&temp2, &temp3); replace_it(temp2, temp3); break; } if(terminate) break; } // // itoa(t, filename, 10); // strcat(filename,".out"); // out = fopen(filename,"w"); for(i = 0; i < m; i++) fprintf(OUT,"%d ",res[i]); fprintf(OUT,"\n"); for(i = 1; i <= n; i++) fprintf(OUT,"%d ",set[i]); fprintf(OUT,"\n"); // fclose(in); // fclose(out); // } // return 0; }
void objdes(char *out_val,treas_ptr ptr,boolean pref) { /*{ Returns a description of item for inventory }*/ char *cpos; vtype tmp_val; ENTER("objdes","i"); //with ptr->data. do; strcpy(tmp_val, ptr->data.name); // fprintf(debug_file,": obj start: >%s<\n",tmp_val); cpos = strstr(tmp_val,"|"); if (cpos != NULL) { *cpos = 0; } // fprintf(debug_file,": obj thmp1: >%s<\n",tmp_val); cpos = strstr(tmp_val,"^"); if (cpos != NULL) { *cpos = 0; } // fprintf(debug_file,": obj thmp2: >%s<\n",tmp_val); if (!(pref)) { cpos = strstr(tmp_val," ("); if (cpos != NULL) { *cpos = 0; } } // fprintf(debug_file,": obj thmp3: >%s<\n",tmp_val); insert_num(tmp_val,"%P1",ptr->data.p1,true); insert_num(tmp_val,"%P2",ptr->data.tohit,true); insert_num(tmp_val,"%P3",ptr->data.todam,true); insert_num(tmp_val,"%P4",ptr->data.toac,true); insert_num(tmp_val,"%P5",ptr->data.p1,false); insert_num(tmp_val,"%P6",ptr->data.ac,false); // fprintf(debug_file,": obj thmp4: >%s<\n",tmp_val); if (ptr->data.number != 1) { insert_str(tmp_val,"ch~","ches"); insert_str(tmp_val,"y~","ies"); insert_str(tmp_val,"~","s"); } else { insert_str(tmp_val,"~",""); } // fprintf(debug_file,": obj thmp5: >%s<\n",tmp_val); if (pref) { if (strstr(tmp_val,"&") != NULL) { insert_str(tmp_val,"&",""); if (ptr->data.number > 1) { sprintf(out_val,"%d%s",ptr->data.number,tmp_val); } else if (ptr->data.number < 1) { sprintf(out_val,"no more%s",tmp_val); } else if (is_vowel(tmp_val[1])) { sprintf(out_val,"an%s",tmp_val); } else { sprintf(out_val,"a%s",tmp_val); } } else { if (ptr->data.number > 0 ) { strcpy(out_val, tmp_val); } else { sprintf(out_val,"no more %s",tmp_val); } } } else { insert_str(tmp_val,"& ",""); strcpy(out_val, tmp_val); } #if DO_DEBUG fprintf(debug_file,": obj final: >%s<\n",out_val); #endif LEAVE("objdes","i"); };