int parse_delete(FILE * file, int * number) { bool succeed = 0 <= (*number = parse_index(file)) && 0 == parse_endl(file) ; skip_line(file); return succeed ? 0 : -1; }
int parse_find(FILE * file, char * out_pattern, const int limit) { bool succeed = 0 == parse_word(file, out_pattern, limit) && 0 == parse_endl(file) ; skip_line(file); return succeed ? 0 : -1; }
void vertical_position_traps() { int n; if (has_arg() && get_integer(&n)) vertical_position_traps_flag = (n != 0); else vertical_position_traps_flag = 1; skip_line(); }
void page_length() { vunits n; if (has_arg() && get_vunits(&n, 'v', topdiv->get_page_length())) topdiv->set_page_length(n); else topdiv->set_page_length(11*units_per_inch); skip_line(); }
int parse_insert(FILE * file, char * out_word, const int limit) { bool succeed = 0 == parse_word(file, out_word, limit) && 0 == parse_endl(file) ; skip_line(file); return succeed ? 0 : -1; }
inline void read_vert(LMESH* mesh, istream& in) { double x, y, z; in >> x >> y >> z; skip_line(in); assert(mesh); mesh->add_vertex(Wpt(x,y,z)); }
void skip_white (char **start, char *end) { while (*start < end && (isspace (**start) || **start == '%')) { if (**start == '%') skip_line (start, end); else /* Skip the white char */ (*start)++; } return; }
void rename_reg() { symbol s1 = get_name(1); if (!s1.is_null()) { symbol s2 = get_name(1); if (!s2.is_null()) number_reg_dictionary.rename(s1, s2); } skip_line(); }
void remove_reg() { for (;;) { symbol s = get_name(); if (s.is_null()) break; number_reg_dictionary.remove(s); } skip_line(); }
int parse_and_print_to_stdout(const char * operation) { if (NULL == operation) { skip_line(stdin); return -1; } if (0 == strcmp(OP_INSERT, operation)) { if (0 != parse_insert(stdin, word_buffer, MAX_WORD_LEN)) return -1; int word_num = trie_insert(word_buffer); if (word_num < 0) return -1; printf("word number: %d\n", word_num); } if (0 == strcmp(OP_PREV, operation)) { int number, start, end; if (0 != parse_prev(stdin, &number, &start, &end)) return -1; int word_num = trie_prev(number, start, end); if (word_num < 0) return -1; printf("word number: %d\n", word_num); } if (0 == strcmp(OP_DELETE, operation)) { int number; if (0 != parse_delete(stdin, &number)) return -1; int word_num = trie_delete(number); if (word_num < 0) return -1; printf("deleted: %d\n", number); } if (0 == strcmp(OP_FIND, operation)) { if (0 != parse_find(stdin, word_buffer, MAX_WORD_LEN)) return -1; int find_result = trie_find(word_buffer, strlen(word_buffer)); if (find_result < 0) return -1; puts(find_result == 0 ? "YES" : "NO"); } if (0 == strcmp(OP_CLEAR, operation)) { if (0 != parse_clear(stdin)) return -1; if (0 != trie_clear()) return -1; puts("cleared"); } return 0; }
static struct ptr_valid_map *get_proc_maps(unsigned int *num) { char *buf, *p; struct ptr_valid_map *map; unsigned int max = 16; buf = grab("/proc/self/maps"); if (!buf) { *num = 0; return NULL; } map = malloc(sizeof(*map) * max); if (!map) goto free_buf; *num = 0; for (p = buf; p && *p; p = skip_line(p)) { unsigned long start, end; char *endp; /* Expect '<start-in-hex>-<end-in-hex> rw... */ start = strtoul(p, &endp, 16); if (*endp != '-') goto malformed; end = strtoul(endp+1, &endp, 16); if (*endp != ' ') goto malformed; endp++; if (endp[0] != 'r' && endp[0] != '-') goto malformed; if (endp[1] != 'w' && endp[1] != '-') goto malformed; /* We only add readable mappings. */ if (endp[0] == 'r') { map = add_map(map, num, &max, start, end, endp[1] == 'w'); if (!map) goto free_buf; } } free(buf); return map; malformed: free(map); free_buf: free(buf); *num = 0; return NULL; }
int parse_prev(FILE * file, int * number, int * start, int * end) { bool succeed = 0 <= (*number = parse_index(file)) && 0 <= (*start = parse_index(file)) && 0 <= (*end = parse_index(file)) && 0 == parse_endl(file) ; skip_line(file); return succeed ? 0 : -1; }
int main() { int numtests; input = fopen("ai.in","r"); assert(input!=NULL); fscanf(input,"%d",&numtests); skip_line(); while (numtests--) solve_case(); fclose(input); return 0; }
void mark() { symbol s = get_name(); if (s.is_null()) curdiv->marked_place = curdiv->get_vertical_position(); else if (curdiv == topdiv) set_number_reg(s, nl_reg_contents); else set_number_reg(s, curdiv->get_vertical_position().to_units()); skip_line(); }
void save_vertical_space() { vunits x; if (!has_arg() || !get_vunits(&x, 'v')) x = curenv->get_vertical_spacing(); if (curdiv->distance_to_next_trap() > x) curdiv->space(x, 1); else saved_space = x; skip_line(); }
/* Read the header. Two numbers for width and height, and two optional * numbers for scale and offset. */ static int vips__matrix_header( char *whitemap, FILE *fp, int *width, int *height, double *scale, double *offset ) { double header[4]; double d; int i; int ch; for( i = 0; i < 4 && (ch = read_ascii_double( fp, whitemap, &header[i] )) == 0; i++ ) ; if( i < 2 ) { vips_error( "mask2vips", "%s", _( "no width / height" ) ); return( -1 ); } if( floor( header[0] ) != header[0] || floor( header[1] ) != header[1] ) { vips_error( "mask2vips", "%s", _( "width / height not int" ) ); return( -1 ); } *width = header[0]; *height = header[1]; if( *width <= 0 || *width > 100000 || *height <= 0 || *height > 100000 ) { vips_error( "mask2vips", "%s", _( "width / height out of range" ) ); return( -1 ); } if( i == 3 ) { vips_error( "mask2vips", "%s", _( "bad scale / offset" ) ); return( -1 ); } if( (ch = read_ascii_double( fp, whitemap, &d )) != '\n' ) { vips_error( "mask2vips", "%s", _( "extra chars in header" ) ); return( -1 ); } if( i > 2 && header[2] == 0.0 ) { vips_error( "mask2vips", "%s", _( "zero scale" ) ); return( -1 ); } *scale = i > 2 ? header[2] : 1.0; *offset = i > 2 ? header[3] : 0.0; skip_line( fp ); return( 0 ); }
void skip_whitespace_comments (FILE *fp) /* skips over all whitespace and comments, if any */ { skip_whitespace (fp); while (nextchar == '#') { skip_line (fp); if (nextchar != EOF) skip_whitespace (fp); } }
// skip_comments(is) utilise la fonction précédente pour sauter zéro, une ou plusieurs lignes // de commentaires débutées par '#' et allant jusqu'à '\n'. static void skip_comments(std::istream& is) { char c; is.get(c); // Lire un caractère. while(c=='#') // Tant que c'est un '#'. { skip_line(is); // On élimine les caractères jusqu'à la fin de ligne, is.get(c); // Et on lit un nouveau caractère. } is.putback(c); // On remet le caractère lu puisqu'il n'est pas un '#'. }
void read_next_task(STREAM *file, TODOLIST *list) { char c; char *message = NULL; int done = 0; int priority = 0; skip_whitespace(file); c = stream_getc(file); if (c != '[') { if (c == '#') { read_next_option(file, list); skip_line(file); return; } stream_ungetc(c, file); skip_line(file); return; } c = stream_getc(file); switch (c) { case 'X': case 'x': done = 1; break; case ' ': done = 0; break; default: stream_ungetc(c, file); skip_line(file); return; } c = stream_getc(file); if (c != ']') { stream_ungetc(c, file); skip_line(file); return; } skip_whitespace(file); message = read_string(file); add_task(list, message, done, priority); }
bool get_param (void) { if (key_pending [0] != '\0') { strcpy (key, key_pending); strcpy (area, parameter_pending); key_pending [0] = parameter_pending [0] = '\0'; return true; } if (* command <= 32) {skip_line (); return false;} char * cp = key; while (* command > 32 && * command != '=') copy_char (& cp, & command); * cp = '\0'; if (strcmp (key, boundary) == 0) { command = strstr (command, "name="); if (command == 0) return false; while (* command > 32 && * command != '"') command++; command++; cp = key; while (* command > 32 && * command != '"') * cp++ = * command++; * cp = '\0'; if (strstr (command, "filename=") == command + 3) { strcpy (key_pending, key); strcat (key_pending, "_filename"); char * sub1 = parameter_pending; char * sub2 = command + 13; while (* sub2 > 0 && * sub2 != '"') * sub1++ = * sub2++; * sub1 = '\0'; skip_line (); } skip_line (); skip_line (); cp = area; char * terminator = strstr (command, boundary); while (terminator != 0 && command < terminator - 2) * cp++ = * command++; skip_line (); * cp = '\0'; return true; } if (boundary [0] != '\0' && strstr (key, boundary) == key) return false; if (* command == '=') command++; cp = area; while (* command > 32 && * command != '&') copy_char (& cp, & command); * cp = '\0'; if (* command == '&') command++; return true; }
void change_trap() { symbol s = get_name(1); if (!s.is_null()) { vunits x; if (has_arg() && get_vunits(&x, 'v')) topdiv->change_trap(s, x); else topdiv->remove_trap(s); } skip_line(); }
void page_number() { int n; // the ps4html register is set if we are using -Tps // to generate images for html reg *r = (reg *)number_reg_dictionary.lookup("ps4html"); if (r == NULL) if (has_arg() && get_integer(&n, topdiv->get_page_number())) topdiv->set_next_page_number(n); skip_line(); }
void when_request() { vunits n; if (get_vunits(&n, 'v')) { symbol s = get_name(); if (s.is_null()) topdiv->remove_trap_at(n); else topdiv->add_trap(s, n); } skip_line(); }
void alias_reg() { symbol s1 = get_name(1); if (!s1.is_null()) { symbol s2 = get_name(1); if (!s2.is_null()) { if (!number_reg_dictionary.alias(s1, s2)) warning(WARN_REG, "number register `%1' not defined", s2.contents()); } } skip_line(); }
static void skip_white_space( FILE * fp ) { int ch; while( isspace( ch = fgetc( fp ) ) ) ; ungetc( ch, fp ); if( ch == '#' ) { skip_line( fp ); skip_white_space( fp ); } }
//gets the x,y,z coordinates from the off file int get_tuples(FILE *fp, jmesh *jm){ int status, line=0; for(int i=0; i < jm->nvert; i++){ status=fscanf(fp, "%f %f %f", getX(jm, i), getY(jm, i), getZ(jm, i)); line++; if(status != 3){ return line; } skip_line(fp); } return line; }
int main(int argc, char * argv[]) { FILE * edict = fopen("./edict.locale", "r"); if(!edict) { fprintf(stderr, "Could not open the file edict.locale.\n"); fprintf(stderr, "Exiting.\n"); } FILE * kanjidic = fopen("./kanjidic.locale", "r"); if(!kanjidic) { fprintf(stderr, "Could not open the file kanjidic.locale.\n"); fprintf(stderr, "Exiting.\n"); } /* The first line is only a comment */ //skip_line(edict); skip_line(kanjidic); fprintf(stderr, "I have opened both edict.locale and kanjidic.locale.\n"); /* Read in the kanjidic file. */ kanji * klist = readkanjidic(kanjidic); fprintf(stderr, "Parsed the KANJIDIC file.\n"); /* We'll need a panini monad later (this is used by learnentry_func) */ pmonad = monad_new(); monad_rules(pmonad, "english"); /* Read the edict file in line by line */ int i = 0; for(;;) { /* Read in the headword. */ char * headword = readword(edict); if(!headword) break; if(!strlen(headword)) break; /* Every 32nd line, print out how far we've come. * (This test is an optimisation; the terminal is a slow thing to print to.) */ if(i == (i & ~(017))) fprintf(stderr, "EDICT importer: %d %s \r", i, headword); /* Parse the line and try to generate Panini source code */ readentry(edict, headword, klist); i++; } /* Print out all the used kanji. */ compilekanji(klist); free_kanji(klist); return 0; }
void page_offset() { hunits n; // The troff manual says that the default scaling indicator is v, // but it is in fact m: v wouldn't make sense for a horizontally // oriented request. if (!has_arg() || !get_hunits(&n, 'm', topdiv->page_offset)) n = topdiv->prev_page_offset; topdiv->prev_page_offset = topdiv->page_offset; topdiv->page_offset = n; topdiv->modified_tag.incl(MTSM_PO); skip_line(); }
//returns the number of tris in the file int get_tris(FILE *fp, jmesh *jm){ fpos_t pos; fgetpos(fp, &pos); //get the start of the faces section int nVerts, sum_tris = 0; for(int i=0; i < jm->ntri; i++){ int temp = fscanf(fp, "%d", &nVerts); sum_tris+= nVerts-2; skip_line(fp); //we only care about the number of vertices } fsetpos(fp, &pos); //go back to the start of the start of the faces section return sum_tris; }
void glibtop_get_cpu_s (glibtop *server, glibtop_cpu *buf) { char buffer [BUFSIZ], *p; int i; memset (buf, 0, sizeof (glibtop_cpu)); file_to_buffer(server, buffer, sizeof buffer, FILENAME); /* * GLOBAL */ p = skip_token (buffer); /* "cpu" */ buf->user = strtoull (p, &p, 0); buf->nice = strtoull (p, &p, 0); buf->sys = strtoull (p, &p, 0); buf->idle = strtoull (p, &p, 0); buf->total = buf->user + buf->nice + buf->sys + buf->idle; buf->frequency = 100; buf->flags = _glibtop_sysdeps_cpu; /* * PER CPU */ for (i = 0; i <= server->ncpu; i++) { p = skip_line(p); /* move to ^ */ if (!check_cpu_line_warn(server, p, i)) break; p = skip_token(p); /* "cpuN" */ buf->xcpu_user [i] = strtoull (p, &p, 0); buf->xcpu_nice [i] = strtoull (p, &p, 0); buf->xcpu_sys [i] = strtoull (p, &p, 0); buf->xcpu_idle [i] = strtoull (p, &p, 0); buf->xcpu_total[i] = buf->xcpu_user [i] \ + buf->xcpu_nice [i] \ + buf->xcpu_sys [i] \ + buf->xcpu_idle [i]; } if(server->ncpu) /* ok, that's a real SMP */ buf->flags |= _glibtop_sysdeps_cpu_smp; }