void Program::exchange_line(int line1, int line2){ Line * lg1,*lg2; lg1=find_line(line1); lg2=find_line(line2); del_line(line1); add_line_at(lg2,line1); del_line(line2); add_line_at(lg1,line2); }
/* ** 'delete range' is called to delete a range of lines from 'low' to ** 'high'. The lines themselves do not have to be present, in which case ** lines from the nearest one above to nearest below will be disposed of */ void delete_range(int32 low, int32 high) { byte *lowline, *highline; if (low>high) return; lowline = find_line(low); if (get_lineno(lowline)==ENDLINENO) return; /* No lines are in the range to delete */ clear_refs(); highline = find_line(high); if (get_lineno(highline)==high) highline+=get_linelen(highline); memmove(lowline, highline, basicvars.top-highline+ENDMARKSIZE); basicvars.top-=(highline-lowline); adjust_heaplimits(); last_added = NIL; }
/* ---------------- get_n_att --------------------------------- * Keep reading the file and find the number of attributes in the * classification. * There is a call to find_regex() below. This used to print an * error when it did not find anything. Unfortunately, it the * unified code, this may not be an error. We may be reading a * file without sequence information. */ static size_t get_n_att (FILE *fp, char *buf, const int bufsiz) { size_t n_att = 1; const char *this_sub = "get_n_att"; const char *parse_fail = "Failed at %s:%d\n"; const char *look_for = "Looking for regex \"%s\"\n"; const char *heading = "num description "; const char *magic_line = "[0-9]+ aa *[0-9] +[0-9].[0-9]+"; if ( ! find_line (buf, bufsiz, fp, heading)) { err_printf (this_sub, parse_fail, __FILE__, __LINE__); err_printf (this_sub, look_for, heading); return 0; } if ( ! find_regex (buf, bufsiz, fp, magic_line, 20)) { # ifdef want_parse_error err_printf (this_sub, parse_fail, __FILE__, __LINE__); err_printf (this_sub, look_for, magic_line); # endif /* want_parse_error */ return 0; } while ( find_regex (buf, bufsiz, fp, magic_line, 1)) n_att++; return n_att; }
struct passwd *internal_getpwuid(const char *filename, uid_t uid) { static struct passwd retpw; char find[10], *line; snprintf(find,10,"%d",(int)uid); line = find_line(filename, find, 2); if (line) { retpw.pw_name = field_from_line(line, 0); retpw.pw_gid = int_field_from_line(line, 3); retpw.pw_dir = field_from_line(line, 5); retpw.pw_shell = field_from_line(line, 6); if (retpw.pw_name == NULL || retpw.pw_gid == -1 || retpw.pw_shell == NULL || retpw.pw_dir == NULL || strlen(retpw.pw_name)<1 || strlen(retpw.pw_dir)<1 || strlen(retpw.pw_shell)<1) { if (retpw.pw_name) free(retpw.pw_name); if (retpw.pw_dir) free(retpw.pw_dir); if (retpw.pw_shell) free(retpw.pw_shell); return NULL; } retpw.pw_uid = uid; retpw.pw_gecos = NULL; /* not required */ retpw.pw_passwd = NULL; /* not required */ return &retpw; } return NULL; }
/* ** 'delete_line' deletes the line passed to it in 'line', if it ** exists */ void delete_line(int32 line) { int32 length; byte *p; p = find_line(line); if (get_lineno(p)==line) { /* Need an exact match. Cannot delete just anything... */ length = get_linelen(p); memmove(p, p+length, basicvars.top-p-length+ENDMARKSIZE); basicvars.top-=length; adjust_heaplimits(); last_added = NIL; } }
/* return TRUE if shell was found. Default: FALSE */ static int valid_shell(mavis_ctx * mcx, char *shell) { int fn, found; fn = open(mcx->shellpath, O_RDONLY); if (fn < 0) return (errno == ENOENT); found = find_line(fn, shell); close(fn); return found; }
/* return TRUE if user was not found. DEFAULT: TRUE */ static int valid_user(mavis_ctx * mcx, char *user) { int fn, found; fn = open(mcx->ftpuserspath, O_RDONLY); if (fn < 0) return (errno == ENOENT); found = find_line(fn, user); close(fn); return !found; }
int count_entries(char *buf, off_t len, char *me, char *t, char *br) { char *e = &buf[len]; int count = 0; while ((buf = find_line(buf, e, me, t, br)) != NULL) { count++; buf = get_eol(buf)+1; if (buf >= e) break; } return count; }
// char *TextFile, char *ExclusionList, int line_to_start, int lines_to_read, int splitter_id, int num_builder int main(int argc, char **argv) { FILE * fp; char *TextFile=NULL; char *ExclusionList=NULL; int line_to_start=0; int lines_to_read=0; int splitter_id=-1; int *builder=NULL; int num_builder=0; WordNode *ExList; int i; struct tms tb1; // Get start time start = (double) times(&tb1); if(splitter_cmd_arg_parser(argc, argv, &TextFile, &ExclusionList, &line_to_start, &lines_to_read, &splitter_id, &num_builder, &builder) == -1 ) { return -1; } printf( "\nSplitter %d (pid: %d) : Parameters are: \nInput File: %s \nExclusion List: %s \nLine to Start: %d \nLines to Read: %d \nBuilder File Descriptors (to write): ", splitter_id+1, getpid(), TextFile, ExclusionList, line_to_start, lines_to_read); fflush(stdout); for(i=0; i<num_builder; i++) printf(" %d ", builder[i]); printf("\n\n"); fflush(stdout); if( ( ExList = CreateExclusionList(ExclusionList) ) == NULL ) { return -1; } // word_print_list(ExList); if ( ( fp=find_line(line_to_start, TextFile) ) == NULL ) { return -1; } if ( splitter(fp, lines_to_read, ExList, num_builder, builder, splitter_id) == -1 ) { perror("error at splitter function\n"); return -1; } fclose(fp); free(builder); // Free Exclusion List and its Contents word_delete_list(ExList); // printf("\n\n%d: Splitter's Total Time: %lf secs\n", splitter_id, totalTime); // Sent SIGUSR1 to parent if( kill(getppid(), SIGUSR1) == -1 ) { perror("splitter - kill"); return -1; } if( kill(getppid(), SIGRTMIN+1) == -1 ) { perror("splitter - kill"); return -1; } return 0; }
void ascii_check::inspect( const string & library_name, const path & full_path, // example: c:/foo/boost/filesystem/path.hpp const string & contents ) // contents of file to be inspected { if (contents.find( "boostinspect:" "noascii" ) != string::npos) return; string::const_iterator bad_char = std::find_if ( contents.begin (), contents.end (), non_ascii ()); if ( bad_char != contents.end ()) { ++m_files_with_errors; string the_line = find_line ( contents, bad_char ); error( library_name, full_path, string ( name()) + " non-ASCII: " + the_line ); } }
char *get_next_line(const int fd) { char *str; char *tmp; int x; tmp = NULL; str = NULL; x = 1; if ((fd < 0) || (SIZE_READ < 1)) return (NULL); str = find_line(str, tmp, x, fd); return (str); }
void my_ia(t_prog_base *base) { if (!one_line(base)) return ; base->line = find_line(base); base->matches = 1; if (rand() % 100 <= base->difficulty) while (xor_all_pile(base) != 0) { base->matches++; if (base->matches > base->matches_per_lines[base->line - 1] - base->nb_deleted[base->line - 1]) { base->matches = 1; while (base->is_empty[++base->line + 1]); if (base->line > base->nb_lines) { base->line = find_line(base); return ; } } } }
const struct dfont_rect * dfont_insert(struct dfont *df, int c, int font, int width, int height) { if (width > df->width) return NULL; assert(dfont_lookup(df,c,font) == NULL); for (;;) { struct font_line *line = find_line(df, width, height); if (line == NULL) break; struct hash_rect * hr = find_space(df, line, width); if (hr) { return insert_char(df,c,font,hr); } } struct hash_rect * hr = release_space(df, width, height); if (hr) { return insert_char(df,c,font,hr); } return NULL; }
/****************************** GLUI_List::mouse_down_handler() **********/ int GLUI_List::mouse_down_handler( int local_x, int local_y ) { int tmp_line; unsigned long int ms; timeb time; ftime(&time); ms = time.millitm + (time.time)*1000; tmp_line = find_line( local_x-x_abs, local_y-y_abs-5 ); if ( tmp_line == -1 ) { if ( glui ) glui->deactivate_current_control( ); return false; } if (tmp_line < num_lines) { curr_line = tmp_line; if (scrollbar) scrollbar->set_int_val(curr_line); this->execute_callback(); if (associated_object != NULL) if (cb_click_type == GLUI_SINGLE_CLICK) { if (obj_cb) { // obj_cb(associated_object, user_id); obj_cb(this); } } else { if (last_line == curr_line && (ms - last_click_time) < 300) { //obj_cb(associated_object, user_id); obj_cb(this); } else { last_click_time = ms; last_line = curr_line; } } if ( can_draw()) update_and_draw_text(); } return true; }
int sync(int nbr, FILE *inf, char str[], int outp) { enum line_type ty; int nn; for(;;) { ty = find_line(inf, str); if(ty == bad_line) return -1; if(ty == test_no) { nn = get_dec(str + 2); if(nn >= nbr) return nn; } if(outp) printf("\n %s", str); } }
static void parse_header(http_connect_t * con) { request *in; buffer *header; buffer *b; read_buffer *dst; pool_t *p; char * start, *end; p = (pool_t *)con->p; dst = (read_buffer *)palloc(p, sizeof(read_buffer)); in = con->in; header = in->header; start = (char *)(header->ptr); end = (char *)header->ptr + (header->used - 1); if(strncasecmp(start,"put", 3) == 0) { in->http_method = _PUT; start += 3; }if(strncasecmp(start,"get", 3) == 0) { in->http_method = _GET; start += 3; } else if(strncasecmp(start, "post", 4) == 0) { in->http_method = _POST; start += 4; } start = skip_space(start, end); in->uri = (read_buffer *)palloc(p, sizeof(read_buffer)); in->uri->ptr = start; start = find_line(start, end); in->uri->size = start - in->uri->ptr; start++; in->content_length = atoi(start); //test_print_header(in); return ; }
bool cull_entries(int fd, char *me, char *t, char *br) { struct stat sb; char *buf, *p, *e, *nic; off_t len; nic = alloca(100); fstat(fd, &sb); len = sb.st_size; if (len == 0) return true; buf = mmap(NULL, len, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); if (buf == MAP_FAILED) { fprintf(stderr, "Failed to create mapping: error %d\n", errno); return false; } p = buf; e = buf + len; while ((p = find_line(p, e, me, t, br)) != NULL) { if (!get_nic_from_line(p, &nic)) continue; if (nic && !nic_exists(nic)) { // copy from eol(p)+1..e to p char *src = get_eol(p) + 1, *dest = p; int diff = src - p; while (src < e) *(dest++) = *(src)++; e -= diff; } else p = get_eol(p) + 1; if (p >= e) break; } munmap(buf, sb.st_size); if (ftruncate(fd, e-buf)) fprintf(stderr, "Failed to set new file size\n"); return true; }
int one_line(t_prog_base *base) { int i; int k; int e; i = -1; k = 0; e = find_line(base) - 1; while (++i < base->nb_lines) if (base->matches_per_lines[i] - base->nb_deleted[i] > 1) { if (k == 1) return (1); e = i; k++; } base->line = e + 1; base->matches = base->matches_per_lines[e] - base->nb_deleted[e]; base->matches += (xor_all_pile(base) == 0) ? -1 : 0; if (base->matches <= 0) base->matches = 1; return (0); }
void ref_test(const char *in_file, const unsigned int it_cnt, enum test_type t_type, AESREF alg) { u4byte i, kl, test_no, cnt, e_cnt; u1byte key[32], pt[16], iv[16], ect[16], act[32]; char str[128], tstr[16]; int ty; IFILE inf; con_string("\nTest file: "); con_string(in_file); con_string("\nStatus: \n"); if(!(inf = open_ifile(inf, in_file))) // reference file for test vectors { // if file is not present con_string("error in running test\n"); return; } cnt = 0; e_cnt = test_no = 0; for(;;) // while there are tests { ty = find_line(inf, str); // input a line if(ty < 0) // until end of file break; switch(ty) // process line type { case 0: kl = get_dec(str + 8); continue; // key length case 1: test_no = get_dec(str + 2); continue; // test number case 2: block_in(iv, str + 3); continue; // init vector case 3: block_in(key, str + 4); continue; // key case 4: block_in(pt, str + 3); // plaintext if(t_type != ecb_md && t_type != cbc_md) continue; break; case 5: block_in(ect, str + 3); // ciphertext if(t_type == ecb_md || t_type == cbc_md) continue; break; } if(serpent_hack) block_reverse(key, kl / 8); alg.set_key(key, kl, both); // set the key if(it_cnt > 100) OUT_DOTS(test_no); if(t_type == ecb_md || t_type == cbc_md) { block_copy(act, ect, 16); // encrypted text to low block if(t_type == cbc_md) // CBC Monte Carlo decryption { block_copy(act + 16, iv, 16); // IV to high block for(i = 0; i < it_cnt; i += 2) // do decryptions two at a time { if(serpent_hack) block_reverse(act, 16); alg.decrypt(act, ect); // decrypt low block if(serpent_hack) { block_reverse(act, 16); block_reverse(ect, 16); } block_xor(act + 16, ect, 16);// xor into high block if(serpent_hack) block_reverse(act + 16, 16); alg.decrypt(act + 16, ect); // decrypt high block if(serpent_hack) { block_reverse(ect, 16); block_reverse(act + 16, 16); } block_xor(act, ect, 16); // xor into low block } } else // ECB Monte Carlo decryption { if(serpent_hack) block_reverse(act, 16); for(i = 0; i < it_cnt; ++i) alg.decrypt(act, act); if(serpent_hack) block_reverse(act, 16); } if(!block_cmp(pt, act, 16)) { con_string("\n\ndecryption error on test "); put_dec(tstr, test_no); con_string(tstr); e_cnt++; } if(t_type == ecb_md) // test encryption if ECB mode { if(serpent_hack) block_reverse(act, 16); for(i = 0; i < it_cnt; ++i) alg.encrypt(act, act); if(serpent_hack) block_reverse(act, 16); if(!block_cmp(ect, act, 16)) { con_string("\n\nencryption error on test "); put_dec(tstr, test_no); con_string(tstr); e_cnt++; } } } else // if(t_type == ecb_me || t_type == cbc_me || ecb_vk || ecb_vt) { if(t_type == cbc_me) // CBC Monte Carlo encryption { block_copy(act, iv, 16); block_copy(act + 16, pt, 16); // copy IV and plaintext for(i = 0; i < it_cnt; i += 2) { block_xor(act + 16, act, 16); // xor low block into high block if(serpent_hack) block_reverse(act + 16, 16); alg.encrypt(act + 16, act + 16); // encrypt high block if(serpent_hack) block_reverse(act + 16, 16); block_xor(act, act + 16, 16); // xor high block into low block if(serpent_hack) block_reverse(act, 16); alg.encrypt(act, act); // encrypt low block if(serpent_hack) block_reverse(act, 16); } } else // ECB Monte Carlo encryption { block_copy(act, pt, 16); if(serpent_hack) block_reverse(act, 16); for(i = 0; i < it_cnt; ++i) alg.encrypt(act, act); if(serpent_hack) block_reverse(act, 16); } if(!block_cmp(ect, act, 16)) { con_string("\n\nencryption error on test "); put_dec(tstr, test_no); con_string(tstr); e_cnt++; } if(t_type != cbc_me) // if ECB mode test decrytpion { if(serpent_hack) block_reverse(act, 16); for(i = 0; i < it_cnt; ++i) alg.decrypt(act, act); if(serpent_hack) block_reverse(act, 16); if(!block_cmp(pt, act, 16)) { con_string("\n\ndecryption error on test "); put_dec(tstr, test_no); con_string(tstr); e_cnt++; } } } } close_ifile(inf); if(e_cnt > 0) // report any errors { put_dec(tstr, e_cnt); con_string("\n"); con_string(tstr); con_string(" errors during test\n"); } else // else report all is well con_string("\nall tests correct\n"); }
int read_doscar( FILE *fp, dos *p_ndos, int need_pdos, int *p_part_dos_list, int num_atoms_pdos, dos *p_pdos, int *p_spd, int num_columns ) { int iloop, jloop, iatom, iorb; int found, sep; int skip=TRUE; int noskip=FALSE; int num_to_skip; int error, good_read; int num_dos, this_num_dos; int pdos_atom; dos *p_this_pdos; double e_min, e_max; double this_e_min, this_e_max; double pop, pop2; char *p_key, *p_key2, *p_key3; char *tok, *tok2, *p_letter; printf("Entered read_dos\n"); p_key= "none"; p_key2= "system"; sep = 0; num_dos = -1; tok= tok_get( fp, skip, FALSE); find_line( fp, p_key, p_key2, sep, &found, -1 ); if (found) { if (strcmp(p_key,"none") != 0 ) printf("Found >>%s<< in DOSCAR file\n", p_key); else printf("Found >>%s<< in DOSCAR file\n", p_key2); tok= tok_get( fp, skip, FALSE); e_max = atof(tok); printf("got e_max as %10.6f\n", e_max); tok= tok_get( fp, noskip, FALSE); e_min = atof(tok); printf("got e_min as %10.6f\n", e_min); tok= tok_get( fp, noskip, FALSE); num_dos = atoi(tok); printf("got num_dos as %d\n", num_dos); if (num_dos > MAX_DOS) { printf("ERROR : Number of points in DOSCAR file (%d) exceeds MAX_DOS (%d).\n", num_dos, MAX_DOS); exit(0); } printf("File e_min = %10.6f, e_max = %10.6f, num_dos = %d\n", e_min, e_max, num_dos); printf("Number of columns = %d\n", num_columns); if (num_dos > 0) { for(iloop=0; iloop < num_dos; iloop++) { /*** If spin restricted ... ***/ if (num_columns == 2 || num_columns == 5 || num_columns == 11) { p_ndos->energy = atof(tok_get( fp, skip, FALSE)); p_ndos->up_dos = atof(tok_get( fp, noskip, FALSE)); p_ndos->up_totdos = atof(tok_get( fp, noskip, FALSE)); printf("Read from doscar: %10.6f %10.6f %10.6f\n", p_ndos->energy, p_ndos->up_dos, p_ndos->up_totdos); } /*** If spin unrestricted ... ***/ else if (num_columns == 4 || num_columns == 10 || num_columns == 22) { p_ndos->energy = atof(tok_get( fp, skip, FALSE)); p_ndos->up_dos = atof(tok_get( fp, noskip, FALSE)); p_ndos->down_dos = atof(tok_get( fp, noskip, FALSE)); p_ndos->up_totdos = atof(tok_get( fp, noskip, FALSE)); p_ndos->down_totdos = atof(tok_get( fp, noskip, FALSE)); printf("Read from doscar: %10.6f %10.6f %10.6f %10.6f %10.6f\n", p_ndos->energy, p_ndos->up_dos, p_ndos->down_dos, p_ndos->up_totdos, p_ndos->down_totdos); } p_ndos++; } } else { printf("ERROR: Bad num_dos read in DOSCAR file\n"); exit(0); } } else { printf("Keyword >>%s<< not found when reading DOSCAR file\n", p_key); exit(0); } if ( need_pdos ) { printf("Building pdos\n"); iatom=1; pdos_atom=0; while (iatom <= *(p_part_dos_list+num_atoms_pdos)) { /**** Next line should be pdos header line ****/ tok= tok_get( fp, skip, FALSE); /**** Alert the user if this fails to check that PDOS was created ****/ if (!tok || strcmp(tok, "Thatsit") == 0) { printf("ERROR: Failure while reading PDOS data, did you ask for PDOS (LORBIT = 12) in INCAR?\n"); exit(0); } this_e_max = atof(tok); tok= tok_get( fp, noskip, FALSE); this_e_min = atof(tok); tok= tok_get( fp, noskip, FALSE); this_num_dos = atoi(tok); /**** Test consistency of this pdos header line with the original information from the dos ****/ if (fabs(e_min-this_e_min) > 0.0001) { printf("ERROR: Minimum energy given in PDOS title is inconsistent with DOSCAR header\n"); printf("ERROR: Read %10.6f DOSCAR header %10.6f\n", this_e_min, e_min); exit(0); } if (fabs(e_max-this_e_max) > 0.0001) { printf("ERROR: Maximum energy given in PDOS title is inconsistent with DOSCAR header\n"); printf("ERROR: Read %10.6f DOSCAR header %10.6f\n", this_e_max, e_max); exit(0); } if ( num_dos - this_num_dos != 0 ) { printf("ERROR: Number of entries reported in PDOS title is inconsistent with DOSCAR header\n"); printf("ERROR: Read %d DOSCAR header %d\n", this_num_dos, num_dos); exit(0); } /**** See if we need this atoms data ****/ printf("iatom = %d\n", iatom); if (iatom == *(p_part_dos_list+pdos_atom)) { printf("Reading this pdos contribution\n"); p_this_pdos = p_pdos; printf("Entered first atom in PDOS list\n"); for(iloop=0; iloop < num_dos; iloop++) { tok=tok_get( fp, skip, FALSE); if (pdos_atom == 0) { /**** First acceptable contribution to pdos ****/ p_this_pdos->energy = atof(tok); /**** Second or higher acceptable contribution to pdos ****/ } else { if (fabs(atof(tok)-p_this_pdos->energy) > 0.0001) { printf("ERROR: Energy scale changed during PDOS read\n"); printf("ERROR: Read %10.6f reference is %10.6f\n", atof(tok), p_this_pdos->energy); exit(0); } } if (pdos_atom == 0) p_this_pdos->up_dos =0.0; iorb = 0; while ( (tok = tok_get( fp, noskip, FALSE)) ) { /**** s, p, d orbitals ****/ if (num_columns == 5) { if (*(p_spd+iorb)) p_this_pdos->up_dos += atof(tok); iorb++; } /**** s, px, py, pz, dxy, dyz, dxz, dx2-y2, dz2 orbitals ****/ else if (num_columns == 11) { if (iorb == 0) { pop = atof(tok); } else if (iorb == 1) { pop = atof(tok); tok = tok_get( fp, noskip, FALSE); pop += atof(tok); tok = tok_get( fp, noskip, FALSE); pop += atof(tok); } else if (iorb == 2) { pop = atof(tok); tok = tok_get( fp, noskip, FALSE); pop += atof(tok); tok = tok_get( fp, noskip, FALSE); pop += atof(tok); tok = tok_get( fp, noskip, FALSE); pop += atof(tok); tok = tok_get( fp, noskip, FALSE); pop += atof(tok); } else if (iorb > 2) { printf("ERROR: Too many orbitals in PDOS entries of DOSCAR file.\n"); printf("ERROR: Only expecting spd level but iorb = %d.\n", iorb); exit(0); } if (*(p_spd+iorb)) p_this_pdos->up_dos += pop; iorb++; } /**** s, p, d orbitals, spin unrestricted ****/ else if (num_columns == 10) { if (*(p_spd+iorb)) { p_this_pdos->up_dos += atof(tok); tok = tok_get( fp, noskip, FALSE); p_this_pdos->down_dos += atof(tok); } iorb++; } /**** s, px, py, pz, dxy, dyz, dxz, dx2-y2, dz2 orbitals, spin unrestricted ****/ else if (num_columns == 22) { if (iorb == 0) { pop = atof(tok); tok = tok_get( fp, noskip, FALSE); pop2 = atof(tok); } else if (iorb == 1) { pop = atof(tok); tok = tok_get( fp, noskip, FALSE); pop2 = atof(tok); tok = tok_get( fp, noskip, FALSE); pop += atof(tok); tok = tok_get( fp, noskip, FALSE); pop2 += atof(tok); tok = tok_get( fp, noskip, FALSE); pop += atof(tok); tok = tok_get( fp, noskip, FALSE); pop2 += atof(tok); } else if (iorb == 2) { pop = atof(tok); tok = tok_get( fp, noskip, FALSE); pop2 = atof(tok); tok = tok_get( fp, noskip, FALSE); pop += atof(tok); tok = tok_get( fp, noskip, FALSE); pop2 += atof(tok); tok = tok_get( fp, noskip, FALSE); pop += atof(tok); tok = tok_get( fp, noskip, FALSE); pop2 += atof(tok); tok = tok_get( fp, noskip, FALSE); pop += atof(tok); tok = tok_get( fp, noskip, FALSE); pop2 += atof(tok); tok = tok_get( fp, noskip, FALSE); pop += atof(tok); tok = tok_get( fp, noskip, FALSE); pop2 += atof(tok); } else if (iorb > 2) { printf("ERROR: Too many orbitals in PDOS entries of DOSCAR file.\n"); printf("ERROR: Only expecting spd level but iorb = %d.\n", iorb); exit(0); } if (*(p_spd+iorb)) { p_this_pdos->up_dos += pop; p_this_pdos->down_dos += pop2; } iorb++; } else { printf("ERROR: Unrecognised number of columns in pdos section of DOSCAR file\n"); exit(0); } } p_this_pdos++; } pdos_atom++; } else { /**** If not needed read in the lines to ensure proper skipping *****/ for(iloop=0; iloop < num_dos; iloop++) tok=tok_get( fp, skip, FALSE); } iatom++; } } return num_dos; }
void comp_vecs(const char *fn1, const char *fn2) { char str1[128], str2[128]; enum line_type ty1, ty2; int no1, no2, err_cnt, np_cnt, req; FILE *if1, *if2; err_cnt = np_cnt = 0; req = TRUE; if(fopen_s(&if1, fn1, "r")) { printf("\n*** 1st file (%s) not found ***", fn1); return; } if(fopen_s(&if2, fn2, "r")) { printf("\n*** 2nd file (%s) not found ***", fn2); return; } for(;;) // while there is still input { if(req) // if another line needs to be input { ty1 = find_line(if1, str1); ty2 = find_line(if2, str2); } if(ty1 == bad_line && ty2 == bad_line) // if end of file on both files break; if(ty1 == bad_line || ty2 == bad_line) // if end of file on one file { printf("\n%s%s%s%s" , fn1, (ty1 == bad_line ? " short" : " long"), "er than ", fn2); break; } if(ty1 == test_no) // if 'test number' line in file 1 no1 = get_dec(str1); if(ty2 == test_no) // if 'test number' line in file 2 no2 = get_dec(str2); if(cmp_nocase(str1, str2) == 0) { req = TRUE; continue; // if lines are the same continue } if(ty1 == test_no && ty2 == test_no) // if not the same but both are at a { // 'test number' line np_cnt += abs(no2 - no1); req = FALSE; if(no2 < no1) // extra tests in file 2 { printf("\nextra test(s) in %s:\n %s", fn2, str2); no2 = sync(no1, if2, str2, np_cnt < 10); // skip tests in file 2 } if(no1 < no2) // extra test in file 1 { printf("\nextra test(s) in %s:\n %s", fn1, str1); no1 = sync(no2, if1, str1, np_cnt < 10);// skip tests in file 1 } } else if(ty1 != ty2) // cannot synchronise test vector files { printf("\n*** synchronisation error tests %i and %i ***", no1, no2); fflush(stdout); return; } else if(ty1 != bad_line) // test vector mismatch { err_cnt++; printf("\r*** mismatch error test %i ***", no1); } fflush(stdout); } if(np_cnt && !err_cnt) // all tests present match printf("\nother tests match\n"); else { if(err_cnt) printf("\r%s doesn't match %s (%i errors)\n", fn2, fn1, err_cnt); else printf("\r%s matches %s\n", df_string(fn2), df_string(fn1)); } fclose(if1); fclose(if2); }
/* ---------------- read_class -------------------------------- * We have the overview of the classification, now read up the * description of each class. buf is just a line buffer for us to * use. aa_clssfcn is the main classification. * n_class is the number of the class we are reading. * n_val is the number of values a descriptor can have. For this * function, it is always 20, the number of amino acids. */ static int read_class (FILE *fp, char *buf, const int bufsiz, struct aa_clssfcn *aa_clssfcn, const size_t n_class, const size_t num_aa) { float wt; int want_new_att = 1; int att_num = -1; int ret = EXIT_SUCCESS; /* On error, set this and go to escape */ unsigned aa_seen = 0; unsigned att_seen = 0; regex_t new_att, next_aa, three_num, get_att_num; const char *this_sub = "read_class"; const char *heading1 = " numb t mtt description I-jk"; /* 00 02 D SM aa 2 ............... 0.116 h .................. -1.79e+00 3.84e-03 2.30e-02 */ const char *s_class_wt = "normalized weight "; const char *s_new_att = "[0-9]+ [0-9]+ .+M +.+[.]+.+[.]+ -*[0-9]"; /* n .................. -1.02e+00 1.53e-02 4.26e-02 */ /* const char *s_next_aa = "[a-zA-Z] [.]{13}"; */ const char *s_next_aa = "[a-zA-Z] [ .]{13}"; const char *s_three_num = "-*[0-9][.][0-9]+e[+-][0-9]+"; /* const char *s_get_att_num = "[0-9]{2,} [DR] +S.+[a-zA-Z0-9] [.]{13}"; */ const char *s_get_att_num = "[0-9]{2,} [DR] +S.+aa"; const char *broke_ijk = "Broke looking for I-jk value in \"%s\"\n"; if ( ! find_line (buf, bufsiz, fp, s_class_wt)) return EXIT_FAILURE; if ((wt = get_class_wt (buf)) < 0) { err_printf (this_sub, "Failed finding class weight on %s\n", buf); return EXIT_FAILURE; } aa_clssfcn->class_wt[n_class] = wt; if ( ! find_line (buf, bufsiz, fp, heading1)) return EXIT_FAILURE; if (m_regcomp (&new_att, s_new_att) == EXIT_FAILURE) return EXIT_FAILURE; if (m_regcomp (&next_aa, s_next_aa) == EXIT_FAILURE) return EXIT_FAILURE; if (m_regcomp (&three_num, s_three_num) == EXIT_FAILURE) return EXIT_FAILURE; if (m_regcomp (&get_att_num, s_get_att_num) == EXIT_FAILURE) return EXIT_FAILURE; while ( fgets (buf, bufsiz, fp) && (att_seen < aa_clssfcn->n_att)) { char *p = buf; regmatch_t pmatch[1]; const size_t nmatch = 1; int r; const int eflags = 0; char aa; unsigned char t_aa; float f1, f2, f3; if (want_new_att) { aa_seen = 0; r = regexec (&get_att_num, p, nmatch, pmatch, eflags); if (r != 0) /* This is a new attribute, so */ continue; /* first we get the attribute */ p += pmatch->rm_so; /* number into att_num */ att_num = (int) strtol (p, NULL, 0); if (r !=0) { err_printf (this_sub, broke_ijk, buf); ret = EXIT_FAILURE; goto escape; } want_new_att = 0; } r = regexec (&next_aa, p, nmatch, pmatch, eflags); if (r != 0) /* Now we are looking for the substring */ break; /* which contains the amino acid letter */ p += pmatch->rm_so; aa = *p++; t_aa = std2thomas_char (aa); if (get_three_num (p, &three_num, &f1, &f2, &f3) == EXIT_FAILURE) { ret = EXIT_FAILURE; goto escape; } aa_clssfcn->log_pp [n_class] [att_num] [t_aa] = f1; if (++aa_seen >= num_aa) { want_new_att = 1; att_seen++; } } escape: regfree (&get_att_num); regfree (&next_aa); regfree (&new_att); regfree (&three_num); return ret; }
task main() { initialize (); // In the original template this was "initializeRobot();" waitForStart (); // Wait for the beginning of autonomous phase. // // Raise the arm. Unless the arm is ALL the way down, this call will hang // your robot. // // raise_arm (); // // Drive forward twelve inches. // drive_both_wheels (75, 75, 12 * kInch); // // Rotate right 90 degrees. This will cause one motor to turn in one // direction, but the other will turn in the opposite direction. // TurnRight (90 * kDegrees); // // Drive forward twelve inches. // drive_both_wheels (75, 75, 12 * kInch); // // Rotate right 90 degrees. This will cause one motor to turn in one // direction, but the other will turn in the opposite direction. // TurnRight (90 * kDegrees); // // Drive forward until a white line is found. // find_line (); // // Lower the arm and close the hand. // // lower_arm (); move_hand (e_hand_command_close); // // Drive forward twelve inches. // drive_both_wheels (75, 75, 12 * kInch); // // Rotate left 90 degrees. // TurnLeft (90 * kDegrees); // // Drive forward twelve inches. // drive_both_wheels (75, 75, 12 * kInch); } // main
int main(int argc, char **argv) { FILE *in; char str[1024], r[128], t[128]; int i, j, k, n; char *s, *u; if (argc != 3) { fprintf(stderr, "usage: cnvasm <input-asm> <output-asm>\n"); return EXIT_SUCCESS; } lines = (char **) malloc(sizeof(char *)); if (!(in = fopen(argv[1], "r"))) { perror(argv[1]); exit(EXIT_FAILURE); } printf("- Finetuning %s\n", argv[1]); printf("- Reading code lines: "); while (!feof(in)) { fgets(str, 1024, in); add_line(lineno, str); } printf("done\n"); /* * This is the stack trick. Watch for the comments to see how this * works. */ n = find_line(".rodata"); if (n > -1) { printf("- Copying data fields to the text segment: "); /* * After locating the .rodata section, find the .text section * and the end of the code ending with .Lfe. (this is a.out * syntax). */ k = find_line_from(".text", n); j = find_line_from(".Lfe", k); /* * Copy each line from the .rodata section starting with .LC * to the text section after the .Lfe mark. In order words * use a part of the code that is not executed. The code ends * at .Lfe. */ for (i = k - 1; i > n; i--) { s = get_line(i); if ((u = strstr(s, ".LC"))) { strcpy(s, u + 1); } add_line(j, s); printf("."); } printf(" done\n"); /* * Remove the lines copied above from the .rodata section */ printf("- Removing data fields in the data segment: "); for (i = k - 1; i >= n; i--) { del_line(i); printf("."); } printf(" done\n"); /* * Find all instruction that used the addresses from .rodata. */ printf("- Patching data field addresses (pushl): "); for (j = 0, i = 0; (i = find_line_from("pushl $.LC", i)) > -1; j++, i++) { /* * This loop looks for simple "pushl $.LC?" instructions. * if one is found it is replaced by a sequence of instructions. * See below. */ strncpy(r, strchr(get_line(i), '$') + 2, 128); r[strlen(r) - 1] = 0; /* * Find the line that holds the data for the found .LC? data. * Remember, those have been copied to the text segment just * before. */ snprintf(t, 128, "%s:", r); n = find_line(t); /* * Add the call before the definition of .LC? */ snprintf(t, 128, "\tcall BF%d\n", j); add_line(n + 1, t); /* * Replace the pushl with a jmp and a label. */ snprintf(t, 128, "\tjmp %s\n", r); set_line(i, t); snprintf(t, 128, "BF%d:\n", j); add_line(i + 1, t); printf("."); } printf(" done\n"); printf("- Patching data field addresses (movl): "); for (i = 0; (i = find_line_from("movl $.LC", i)) > -1; j++, i++) { /* * This loop looks for simple "movl $.LC?" instructions. * if one is found it is replaced by a sequence of instructions. * See below. */ strncpy(r, strchr(get_line(i), '$') + 2, 128); r[3] = 0; /* * Find the line that holds the data for the found .LC? data. * Remember, those have been copied to the text segment just * before. */ snprintf(t, 128, "%s:", r); n = find_line(t); /* * Add a call before the definition of .LC? */ snprintf(t, 128, "\tcall BF%d\n", j); add_line(n + 1, t); /* * Replace the movl with a jmp, a label and a final popl * that retrieves the address from the stack and gets it back * to the register used in the inital movl. */ snprintf(t, 128, "\tjmp %s\n", r); strncpy(r, strchr(get_line(i), '%'), 128); r[strlen(r) - 1] = 0; set_line(i, t); snprintf(t, 128, "BF%d:\n", j); add_line(i + 1, t); snprintf(t, 128, "\tpopl %s\n", r); add_line(i + 2, t); printf("."); } printf(" done\n"); } /* * Add the magic entry point and a pushl dx instruction. Most other * register are pushed by default, dx isn't. */ printf("- Adding magic entry point.\n"); k = find_line("main:"); add_line(k + 1, "\tpushl %edx\n"); add_line(k + 1, "\tmovl 0xaffeaffe,%ebp\n"); /* * Prepare the end of the code to hold a placeholder for host_entry * and restore the dx register by issuing a popl edx. */ printf("- Adding magic exit point.\n"); k = find_line_from("\tret", k); set_line(k, "\tjmp *%ebp\n"); add_line(k, "\tmovl $0xdeadbeef,%ebp\n"); add_line(k, "\tpop %edx\n"); fclose(in); /* * Write the new file. */ if (!(in = fopen(argv[2], "w"))) { perror(argv[2]); exit(EXIT_FAILURE); } for (i = 0; i < lineno; i++) fputs(get_line(i), in); fclose(in); return EXIT_SUCCESS; }