/* Read the dimensions of an image */ int img_read_pgm_dimensions(char *filename, int *w, int *h) { FILE *fp = fopen(filename, "rb"); // int char1, char2; // int c1, c2; if (fp == NULL) { printf("Error: could not open file %s", filename); return -1; } // char1 = fgetc(fp); // char2 = fgetc(fp); skip_comments(fp); // c1 = fscanf(fp, "%d", w); skip_comments(fp); // c2 = fscanf(fp, "%d", h); fclose(fp); return 0; }
/*for reading:*/ PGMData* read_PGM(const char *file_name, PGMData *data) { FILE *pgmFile; char version[3]; int i, j; int lo, hi; pgmFile = fopen(file_name, "rb"); if (pgmFile == NULL) { perror("cannot open file to read"); exit(EXIT_FAILURE); } fgets(version, sizeof(version), pgmFile); if (strcmp(version, "P5")) { fprintf(stderr, "Wrong file type!\n"); exit(EXIT_FAILURE); } skip_comments(pgmFile); fscanf(pgmFile, "%d", &data->col); skip_comments(pgmFile); fscanf(pgmFile, "%d", &data->row); skip_comments(pgmFile); fscanf(pgmFile, "%d", &data->max_gray); fgetc(pgmFile); data->matrix = allocate_dynamic_matrix(data->row, data->col); if (data->max_gray > 255) for (i = 0; i < data->row; ++i) for (j = 0; j < data->col; ++j) { hi = fgetc(pgmFile); lo = fgetc(pgmFile); data->matrix[i][j] = (hi << 8) + lo; } else for (i = 0; i < data->row; ++i) for (j = 0; j < data->col; ++j) { lo = fgetc(pgmFile); data->matrix[i][j] = lo; } fclose(pgmFile); return data; }
static int next_token(char *code, int *start, int *end) { int c; *start = *end; while (code[*start] && (skip_spaces(code, start) || skip_comments(code, start))) ; *end = *start + 1; c = code[*start]; if (c == '(') return TK_PAREN_OPEN; else if (c == ')') return TK_PAREN_CLOSE; else if (c == '.') return TK_DOT; else if (c >= '0' && c <= '9') { while (code[*end] && ((code[*end] >= '0' && code[*end] <= '9') || (code[*end] == '.'))) ++(*end); return TK_NUMBER; } else if (is_symbol_char(c)) { while (code[*end] && is_symbol_char(code[*end])) ++(*end); return TK_SYMBOL; } else { return TK_EOF; } }
static inline bool get_next_token( char*& cur ) { for( ; cur < _gSrcEnd; ++cur ) { switch( *(cur) ) { case ' ' : continue; case '\t': continue; case 13 : continue; case 10 : { ++_gLineNo;continue; } case '/' : skip_comments( cur ); --cur; continue; default : break; }; break; } if ( cur >= _gSrcEnd ) return false; else return true; }
static inline void skip_scope_block( char*& cur ) { size_t level = 0; for( ; cur < _gSrcEnd ; ++cur ) switch( *cur ) { case '/' : skip_comments( cur ); --cur; continue; case '"' : skip_quoted_string( cur ); --cur; continue; case '{' : ++level; continue; case '}' :--level; if ( level == 0 ) { ++cur; // skip final closing curly brace return; } case 10 : ++_gLineNo; continue; default : continue; }; }
static int get_image_size(FILE *fp, ppm_hdr_t *ppm_hdr){ skip_comments(fp); if(fscanf(fp, "%d %d", &ppm_hdr->width, &ppm_hdr->height) != 2){ fprintf(stderr, "Warning: PGM --> File currupted\n"); return 0; } return 1; }
void STDPWeightChange::LoadLearningRule(FILE * fh, long & Currentline) throw (EDLUTFileException){ skip_comments(fh,Currentline); if(!(fscanf(fh,"%f",&this->MaxChangeLTP)==1 && fscanf(fh,"%f",&this->tauLTP)==1 && fscanf(fh,"%f",&this->MaxChangeLTD)==1 && fscanf(fh,"%f",&this->tauLTD)==1)){ throw EDLUTFileException(4,28,23,1,Currentline); } }
status qra_hajlamot (CStr path_to_hajlamot) { ifstream hajlamot_infile; StringTemp thefilename = concat_path_to_filename(path_to_hajlamot,"hajlamot.ma"); cerr << "reading hajlamot file " << thefilename << endl; DOr(open(thefilename.str,hajlamot_infile)); skip_comments(hajlamot_infile,'%'); DOr(read(hajlamot_infile, mone_hajlamot_pealim, Format("P "))); hajlamot_infile.close(); return OK; }
static img_t *img_read_pgm(FILE *fp) { int char1, char2, w, h, max, c1, c2, c3, x, y; img_t *img; char1 = fgetc(fp); char2 = fgetc(fp); skip_comments(fp); c1 = fscanf(fp, "%d", &w); skip_comments(fp); c2 = fscanf(fp, "%d", &h); skip_comments(fp); c3 = fscanf(fp, "%d", &max); printf("[pgm.c] (%d, %d, %d)\n", w, h, max); if (char1 != 'P' || char2 != '5' || c1 != 1 || c2 != 1 || c3 != 1 || max > 255) { printf("Input is not a standard raw 8-bit PGM file.\n" "Use xv or pnmdepth to convert file to 8-bit PGM format.\n"); return NULL; } fgetc(fp); /* Discard exactly one byte after header. */ /* Create floating point image with pixels in range [0,1]. */ img = img_new(w, h); for (y = h - 1; y > 0; y--) { color_t *c = img->pixels + y * w; for (x = 0; x < w; x++) { int v = (int) fgetc(fp); // img_set_pixel(img, x, y, v, v, v); c->r = c->g = c->b = v; img_set_valid_pixel(img, x, y); c++; } } return img; }
status qra_lexicon_bituyim (CStr thepath) { ifstream in; StringTemp thefilename; thefilename = concat_path_to_filename(thepath, "milon/lex20.ma"); cerr << "reading lexicon file " << thefilename << endl; DOr(open(thefilename.str,in)); skip_comments(in,'%'); DOr(qra_lexicon_bituyim(in)); in.close(); return OK; }
static int get_pixmax(FILE *fp, ppm_hdr_t *ppm_hdr){ skip_comments(fp); ppm_hdr->pixmax = 1; if(ppm_hdr->magic == 2 || ppm_hdr->magic == 3 || ppm_hdr->magic == 5 || ppm_hdr->magic == 6){ if(fscanf(fp, "%d", &ppm_hdr->pixmax) != 1){ fprintf(stderr, "Warning: PGM --> pixmax not valid\n"); return 0; } } fgetc(fp); return 1; }
static const char* skip_spaces(const char* json) { CE_ASSERT_NOT_NULL(json); while (*json) { if (*json == '/') json = skip_comments(json); else if (isspace(*json) || *json == ',') ++json; else break; } return json; }
Image<T>* Image<T>::readPGM(std::istream& is) { unsigned int _width =0 , _height=0 , nbGris = 255 ; std::string _magicKey ; if ( is) { is >> _magicKey; if ( !_magicKey.compare("P5\n")) { throw std::runtime_error(" Image<T>::readPGM(std::istream& is):Erreur dans le fichier type"); } skip_line(is); skip_comments(is); is >> _width >> _height; skip_comments(is); is >> nbGris ; if ( nbGris != 255) { throw std::runtime_error(" Image<T>::readPGM(std::istream& is):Erreur composition incorrecte"); } //on crée un variable pour attrapper le /n char c ; is.get(c); //on lit ensuite les caracteres par blocs //on crée l'instance de classe Image<T> * temp = new Image<T> (_width,_height); is.read((char*) temp->array, _width * _height ); return temp; } else throw std::runtime_error(" Image<T>::readPGM(std::istream& is): impossible d'ouvrir le fichier");
void Vanderpol::LoadNeuronModel(string ConfigFile) throw (EDLUTFileException){ FILE *fh; long Currentline = 0L; fh=fopen(ConfigFile.c_str(),"rt"); if(fh){ Currentline=1L; skip_comments(fh,Currentline); this->InitialState = (VectorNeuronState *) new VectorNeuronState(2, true); //INTEGRATION METHOD this->integrationMethod = LoadIntegrationMethod::loadIntegrationMethod(fh, &Currentline,N_NeuronStateVariables, N_DifferentialNeuronState, N_TimeDependentNeuronState, N_CPU_thread); } }
static void parse_file(char *fullname, char *cvspath, char *filename) { PAPI_INFO api_info; char prev[200]; char name[200]; int tag_id; read_file(fullname); prev[0] = 0; do { tag_id = skip_to_next_tag(); if (tag_id == TAG_UNKNOWN) { break; } /* Skip rest of the comments between the tag and the function name */ skip_comments(); if (skip_to_next_name(name)) { if (strlen(name) == 0) { printf("Warning: empty function name in file %s. Previous function name was %s.\n", fullname, prev); } api_info = malloc(sizeof(API_INFO)); if (api_info == NULL) { printf("Out of memory\n"); exit(1); } api_info->tag_id = tag_id; strcpy(api_info->name, name); get_filename(cvspath, filename, api_info->filename); api_info->next = api_info_list; api_info_list = api_info; strcpy(prev, name); } } while (1); close_file(); }
void skip_comments(FILE *fp) { int ch; char line[100]; while ((ch = fgetc(fp)) != EOF && isspace(ch)) ; if (ch == '#') { fgets(line, sizeof(line), fp); skip_comments(fp); } else fseek(fp, -1, SEEK_CUR); }
char *load_entry(FILE *file) { int ch; static char cmd[MAX_COMMAND]; skip_comments(file); ch = get_string(cmd, MAX_COMMAND, file, "\n"); if (ch == EOF) { return NULL; } return cmd; }
static wxChar* set_comment_text( wxString& text, wxChar* start ) { wxChar* end = start; // to avoid poluting the queue with this comment _gLastSuppresedComment = start; skip_comments( end ); if ( *(end-1) == _T('/') ) end -= 2; start += 2; // skip multiple leading '/''s or '*''s while( *start == _T('/') && start < end ) ++start; while( *start == _T('*') && start < end ) ++start; get_string_between( start, end, &text ); return end; }
static inline void skip_statement( char*& cur ) { for( ; cur < _gSrcEnd; ++cur ) switch (*cur) { case ';' : ++cur; // skip statement-terminator token return; case '"' : skip_quoted_string(cur); --cur; continue; case 10 : ++_gLineNo; continue; case '/' : skip_comments( cur ); --cur; continue; default : continue; } }
/* imports the given fig-file, returns TRUE if successful */ static gboolean import_fig(const gchar *filename, DiagramData *dia, DiaContext *ctx, void* user_data) { FILE *figfile; char buf[BUFLEN]; int figmajor, figminor; int i; for (i = 0; i < FIG_MAX_USER_COLORS; i++) { fig_colors[i] = color_black; } for (i = 0; i < FIG_MAX_DEPTHS; i++) { depths[i] = NULL; } figfile = g_fopen(filename,"r"); if (figfile == NULL) { dia_context_add_message_with_errno(ctx, errno, _("Couldn't open: '%s' for reading.\n"), dia_context_get_filename(ctx)); return FALSE; } /* First check magic bytes */ if (fgets(buf, BUFLEN, figfile) == NULL || sscanf(buf, "#FIG %d.%d\n", &figmajor, &figminor) != 2) { dia_context_add_message_with_errno(ctx, errno, _("Doesn't look like a Fig file")); fclose(figfile); return FALSE; } if (figmajor != 3 || figminor != 2) { dia_context_add_message(ctx, _("This is a Fig version %d.%d file.\n It may not be importable."), figmajor, figminor); } figversion = figmajor*100+figminor; if (!skip_comments(figfile)) { if (!feof(figfile)) { dia_context_add_message_with_errno(ctx, errno, _("Error reading Fig file.")); } else { dia_context_add_message(ctx, _("Premature end of Fig file")); } fclose(figfile); return FALSE; } if (!fig_read_meta_data(figfile, dia, ctx)) { fclose(figfile); return FALSE; } compound_stack = NULL; do { if (!skip_comments(figfile)) { if (!feof(figfile)) { dia_context_add_message_with_errno(ctx, errno, _("Error reading Fig file.")); } else { break; } } if (! fig_read_object(figfile, ctx)) { fclose(figfile); break; } } while (TRUE); /* Now we can reorder for the depth fields */ for (i = 0; i < FIG_MAX_DEPTHS; i++) { if (depths[i] != NULL) layer_add_objects_first(dia->active_layer, depths[i]); } return TRUE; }
void CyberGloveBasic::vt_read_lowres_hand_model(char infilename[], VirtualHand hand) { int finger,joint,numobjects; FILE *inputfp; matrix4x4 totmatrix; static vec3d digitvec,scalevec; Boolean right_handed; if (hand->right_hand != NULL) right_handed = *(hand->right_hand); else right_handed = TRUE; inputfp = fopen(infilename,"r"); /* skip any comments at the beginning of the file */ skip_comments(inputfp); fscanf(inputfp,"\tTotal Number of Objects In World:%d\n",&numobjects); if (numobjects < 3) printf("WARNING in vt_read_hand_model: file contains too few objects"); vt_read_object(inputfp,&(hand->surface->forearm)); vt_set_vec3(3.5,1.0,1.5,scalevec); if (!right_handed) scalevec[VX] = -scalevec[VX]; vt_scale_matrix(scalevec,totmatrix); transform_object(&(hand->surface->forearm),totmatrix); vt_calculate_face_normals(&(hand->surface->forearm),right_handed); vt_calculate_dihedral_angles(&(hand->surface->forearm)); vt_calculate_vertex_normals(&(hand->surface->forearm)); vt_read_object(inputfp,&(hand->surface->palm)); vt_set_vec3(1.0,1.0,1.0,scalevec); if (!right_handed) scalevec[VX] = -scalevec[VX]; vt_scale_matrix(scalevec,totmatrix); transform_object(&(hand->surface->palm),totmatrix); vt_calculate_face_normals(&(hand->surface->palm),right_handed); vt_calculate_dihedral_angles(&(hand->surface->palm)); vt_calculate_vertex_normals(&(hand->surface->palm)); for (finger=THUMB; finger < FINGERS; finger++) for (joint=MCP; joint < ABDUCT; joint++) { vt_read_object(inputfp,&(hand->surface->digit[finger][joint])); vt_vec_sub3(hand->geom[finger][joint],hand->geom[finger][joint+1], digitvec); vt_set_vec3(1.0,vt_vec_length3(digitvec)/5.0,1.0,scalevec); if (!right_handed) scalevec[VX] = -scalevec[VX]; vt_scale_matrix(scalevec,totmatrix); transform_object(&(hand->surface->digit[finger][joint]),totmatrix); vt_calculate_face_normals(&(hand->surface->digit[finger][joint]), right_handed); vt_calculate_dihedral_angles(&(hand->surface->digit[finger][joint])); vt_calculate_vertex_normals(&(hand->surface->digit[finger][joint])); } fclose(inputfp); }
/* return ERR = end of file * FALSE = not an env setting (file was repositioned) * TRUE = was an env setting */ int load_env(char *envstr, FILE *f) { long filepos; int fileline; enum env_state state; char name[MAX_ENVSTR], val[MAX_ENVSTR]; char quotechar, *c, *str; filepos = ftell(f); fileline = LineNumber; skip_comments(f); if (EOF == get_string(envstr, MAX_ENVSTR, f, "\n")) return (ERR); Debug(DPARS, ("load_env, read <%s>\n", envstr)); (void)memset(name, 0, sizeof name); (void)memset(val, 0, sizeof val); str = name; state = NAMEI; quotechar = '\0'; c = envstr; while (state != ERROR && *c) { switch (state) { case NAMEI: case VALUEI: if (*c == '\'' || *c == '"') quotechar = *c++; state++; /* FALLTHROUGH */ case NAME: case VALUE: if (quotechar) { if (*c == quotechar) { state++; c++; break; } if (state == NAME && *c == '=') { state = ERROR; break; } } else { if (state == NAME) { if (isspace((unsigned char)*c)) { c++; state++; break; } if (*c == '=') { state++; break; } } } *str++ = *c++; break; case EQ1: if (*c == '=') { state++; str = val; quotechar = '\0'; } else { if (!isspace((unsigned char)*c)) state = ERROR; } c++; break; case EQ2: case FINI: if (isspace((unsigned char)*c)) c++; else state++; break; default: abort(); } } if (state != FINI && !(state == VALUE && !quotechar)) { Debug(DPARS, ("load_env, not an env var, state = %d\n", state)); (void)fseek(f, filepos, 0); Set_LineNum(fileline); return (FALSE); } if (state == VALUE) { /* End of unquoted value: trim trailing whitespace */ c = val + strlen(val); while (c > val && isspace((unsigned char)c[-1])) *(--c) = '\0'; } /* 2 fields from parser; looks like an env setting */ /* * This can't overflow because get_string() limited the size of the * name and val fields. Still, it doesn't hurt to be careful... */ if (!glue_strings(envstr, MAX_ENVSTR, name, val, '=')) return (FALSE); Debug(DPARS, ("load_env, <%s> <%s> -> <%s>\n", name, val, envstr)); return (TRUE); }
Token InputReader::get_next_token() { skip_white_spaces(); Token token, raw_token; std::string qstr; std::string value; get_raw_token(raw_token); switch(raw_token.type_) { case null_token: token.type_ = null_token; // this means no more tokens left break; case digit_token: case negative_token: float_t n_value; input_stream_.unget(); if(!read_number(n_value)) { std::cerr << "fatal error: failed while reading a number" << std::endl; token.type_ = error_token; } else { token.type_ = number_token; token.dvalue_ = n_value; } // if-else break; case object_begin_token: token.type_ = object_begin_token; structure_stack_.push(object_begin_token); break; case object_end_token: token.type_ = object_end_token; if(structure_stack_.top() != object_begin_token) { std::cerr << "fatal error: mismatched object encapsulators" << std::endl; token.type_ = error_token; } else { structure_stack_.pop(); } // if-else break; case array_begin_token: token.type_ = array_begin_token; structure_stack_.push(array_begin_token); break; case array_end_token: token.type_ = array_end_token; if(structure_stack_.top() != array_begin_token) { std::cerr << "fatal error: mismatched array encapsulators" << std::endl; token.type_ = error_token; } else { structure_stack_.pop(); } // if-else break; case string_begin_end_token: // will always be begin since // end will be removed while reading //the whole string earlier if(!read_quoted_string(qstr)) { std::cerr << "fatal error: premature EOF reached while reading string" << std::endl; token.type_ = error_token; } else { token.type_ = string_token; token.svalue_ = qstr; } // if-else break; case character_token: input_stream_.unget(); read_keyword(value); token.type_ = process_keyword_token(value); if(token.type_ == error_token) { std::cerr << "fatal error: unknown keyword '" << value << "'" << std::endl; } // if token.svalue_ = value; break; case assignment_token: token.type_ = assignment_token; break; case separator_token: token.type_ = separator_token; break; case comment_token: skip_comments(); token.type_ = comment_token; break; default: std::cerr << "fatal error: unknown token" << std::endl; token.type_ = error_token; } // switch return token; } // InputReader::get_next_token()
/* return NULL if eof or syntax error occurs; * otherwise return a pointer to a new entry. */ entry * load_entry(FILE *file, void (*error_func)(const char *), struct passwd *pw, char **envp) { /* this function reads one crontab entry -- the next -- from a file. * it skips any leading blank lines, ignores comments, and returns * NULL if for any reason the entry can't be read and parsed. * * the entry is also parsed here. * * syntax: * user crontab: * minutes hours doms months dows cmd\n * system crontab (/etc/crontab): * minutes hours doms months dows USERNAME cmd\n */ ecode_e ecode = e_none; entry *e; int ch; char cmd[MAX_COMMAND]; char envstr[MAX_ENVSTR]; char **tenvp; Debug(DPARS, ("load_entry()...about to eat comments\n")); skip_comments(file); ch = get_char(file); if (ch == EOF) return (NULL); /* ch is now the first useful character of a useful line. * it may be an @special or it may be the first character * of a list of minutes. */ e = calloc(sizeof(*e), sizeof(char)); if (ch == '@') { /* all of these should be flagged and load-limited; i.e., * instead of @hourly meaning "0 * * * *" it should mean * "close to the front of every hour but not 'til the * system load is low". Problems are: how do you know * what "low" means? (save me from /etc/cron.conf!) and: * how to guarantee low variance (how low is low?), which * means how to we run roughly every hour -- seems like * we need to keep a history or let the first hour set * the schedule, which means we aren't load-limited * anymore. too much for my overloaded brain. (vix, jan90) * HINT */ ch = get_string(cmd, MAX_COMMAND, file, " \t\n"); if (!strcmp("reboot", cmd)) { e->flags |= WHEN_REBOOT; } else if (!strcmp("yearly", cmd) || !strcmp("annually", cmd)){ bit_set(e->minute, 0); bit_set(e->hour, 0); bit_set(e->dom, 0); bit_set(e->month, 0); bit_nset(e->dow, 0, (LAST_DOW-FIRST_DOW+1)); e->flags |= DOW_STAR; } else if (!strcmp("monthly", cmd)) { bit_set(e->minute, 0); bit_set(e->hour, 0); bit_set(e->dom, 0); bit_nset(e->month, 0, (LAST_MONTH-FIRST_MONTH+1)); bit_nset(e->dow, 0, (LAST_DOW-FIRST_DOW+1)); e->flags |= DOW_STAR; } else if (!strcmp("weekly", cmd)) { bit_set(e->minute, 0); bit_set(e->hour, 0); bit_nset(e->dom, 0, (LAST_DOM-FIRST_DOM+1)); bit_nset(e->month, 0, (LAST_MONTH-FIRST_MONTH+1)); bit_set(e->dow, 0); e->flags |= DOM_STAR; } else if (!strcmp("daily", cmd) || !strcmp("midnight", cmd)) { bit_set(e->minute, 0); bit_set(e->hour, 0); bit_nset(e->dom, 0, (LAST_DOM-FIRST_DOM+1)); bit_nset(e->month, 0, (LAST_MONTH-FIRST_MONTH+1)); bit_nset(e->dow, 0, (LAST_DOW-FIRST_DOW+1)); e->flags |= DOM_STAR | DOW_STAR; } else if (!strcmp("hourly", cmd)) { bit_set(e->minute, 0); bit_nset(e->hour, 0, (LAST_HOUR-FIRST_HOUR+1)); bit_nset(e->dom, 0, (LAST_DOM-FIRST_DOM+1)); bit_nset(e->month, 0, (LAST_MONTH-FIRST_MONTH+1)); bit_nset(e->dow, 0, (LAST_DOW-FIRST_DOW+1)); e->flags |= DOM_STAR | DOW_STAR; } else { ecode = e_timespec; goto eof; } /* Advance past whitespace between shortcut and * username/command. */ Skip_Blanks(ch, file); if (ch == EOF || ch == '\n') { ecode = e_cmd; goto eof; } } else { Debug(DPARS, ("load_entry()...about to parse numerics\n")); if (ch == '*') e->flags |= MIN_STAR; ch = get_list(e->minute, FIRST_MINUTE, LAST_MINUTE, PPC_NULL, ch, file); if (ch == EOF) { ecode = e_minute; goto eof; } /* hours */ if (ch == '*') e->flags |= HR_STAR; ch = get_list(e->hour, FIRST_HOUR, LAST_HOUR, PPC_NULL, ch, file); if (ch == EOF) { ecode = e_hour; goto eof; } /* DOM (days of month) */ if (ch == '*') e->flags |= DOM_STAR; ch = get_list(e->dom, FIRST_DOM, LAST_DOM, PPC_NULL, ch, file); if (ch == EOF) { ecode = e_dom; goto eof; } /* month */ ch = get_list(e->month, FIRST_MONTH, LAST_MONTH, MonthNames, ch, file); if (ch == EOF) { ecode = e_month; goto eof; } /* DOW (days of week) */ if (ch == '*') e->flags |= DOW_STAR; ch = get_list(e->dow, FIRST_DOW, LAST_DOW, DowNames, ch, file); if (ch == EOF) { ecode = e_dow; goto eof; } } /* make sundays equivalent */ if (bit_test(e->dow, 0) || bit_test(e->dow, 7)) { bit_set(e->dow, 0); bit_set(e->dow, 7); } /* check for permature EOL and catch a common typo */ if (ch == '\n' || ch == '*') { ecode = e_cmd; goto eof; } /* ch is the first character of a command, or a username */ unget_char(ch, file); if (!pw) { char *username = cmd; /* temp buffer */ Debug(DPARS, ("load_entry()...about to parse username\n")); ch = get_string(username, MAX_COMMAND, file, " \t\n"); Debug(DPARS, ("load_entry()...got %s\n",username)); if (ch == EOF || ch == '\n' || ch == '*') { ecode = e_cmd; goto eof; } pw = getpwnam(username); if (pw == NULL) { ecode = e_username; goto eof; } Debug(DPARS, ("load_entry()...uid %ld, gid %ld\n", (long)pw->pw_uid, (long)pw->pw_gid)); } if ((e->pwd = pw_dup(pw)) == NULL) { ecode = e_memory; goto eof; } (void)memset(e->pwd->pw_passwd, 0, strlen(e->pwd->pw_passwd)); /* copy and fix up environment. some variables are just defaults and * others are overrides. */ if ((e->envp = env_copy(envp)) == NULL) { ecode = e_memory; goto eof; } if (!env_get("SHELL", e->envp)) { if (glue_strings(envstr, sizeof envstr, "SHELL", _PATH_BSHELL, '=')) { if ((tenvp = env_set(e->envp, envstr)) == NULL) { ecode = e_memory; goto eof; } e->envp = tenvp; } else log_it("CRON", getpid(), "error", "can't set SHELL"); } if (!env_get("HOME", e->envp)) { if (glue_strings(envstr, sizeof envstr, "HOME", pw->pw_dir, '=')) { if ((tenvp = env_set(e->envp, envstr)) == NULL) { ecode = e_memory; goto eof; } e->envp = tenvp; } else log_it("CRON", getpid(), "error", "can't set HOME"); } /* If login.conf is in used we will get the default PATH later. */ if (!env_get("PATH", e->envp)) { if (glue_strings(envstr, sizeof envstr, "PATH", _PATH_DEFPATH, '=')) { if ((tenvp = env_set(e->envp, envstr)) == NULL) { ecode = e_memory; goto eof; } e->envp = tenvp; } else log_it("CRON", getpid(), "error", "can't set PATH"); } if (glue_strings(envstr, sizeof envstr, "LOGNAME", pw->pw_name, '=')) { if ((tenvp = env_set(e->envp, envstr)) == NULL) { ecode = e_memory; goto eof; } e->envp = tenvp; } else log_it("CRON", getpid(), "error", "can't set LOGNAME"); #if defined(BSD) || defined(__linux) if (glue_strings(envstr, sizeof envstr, "USER", pw->pw_name, '=')) { if ((tenvp = env_set(e->envp, envstr)) == NULL) { ecode = e_memory; goto eof; } e->envp = tenvp; } else log_it("CRON", getpid(), "error", "can't set USER"); #endif Debug(DPARS, ("load_entry()...about to parse command\n")); /* If the first character of the command is '-' it is a cron option. */ while ((ch = get_char(file)) == '-') { switch (ch = get_char(file)) { case 'q': e->flags |= DONT_LOG; Skip_Nonblanks(ch, file); break; default: ecode = e_option; goto eof; } Skip_Blanks(ch, file); if (ch == EOF || ch == '\n') { ecode = e_cmd; goto eof; } } unget_char(ch, file); /* Everything up to the next \n or EOF is part of the command... * too bad we don't know in advance how long it will be, since we * need to malloc a string for it... so, we limit it to MAX_COMMAND. */ ch = get_string(cmd, MAX_COMMAND, file, "\n"); /* a file without a \n before the EOF is rude, so we'll complain... */ if (ch == EOF) { ecode = e_cmd; goto eof; } /* got the command in the 'cmd' string; save it in *e. */ if ((e->cmd = strdup(cmd)) == NULL) { ecode = e_memory; goto eof; } Debug(DPARS, ("load_entry()...returning successfully\n")); /* success, fini, return pointer to the entry we just created... */ return (e); eof: if (e->envp) env_free(e->envp); if (e->pwd) free(e->pwd); if (e->cmd) free(e->cmd); free(e); while (ch != '\n' && !feof(file)) ch = get_char(file); if (ecode != e_none && error_func) (*error_func)(ecodes[(int)ecode]); return (NULL); }
void CyberGloveBasic::vt_read_hand_model(char infilename[], VirtualHand hand, char *glovedir) { int finger,joint,numobjects; vec3d thumb_roll_vecs[2]; vec3d geom[5][4]; FILE *inputfp; matrix4x4 totmatrix,rotmatrix; static vec3d scalevec = {0.4475,0.4475,0.4475}; static vec3d transvec = {-0.06,4.2,0.1}; Boolean right_handed; char geomfile[100]; /* cout << "\nReading "<< infilename << " ..."; */ if (hand->right_hand != NULL) right_handed = *(hand->right_hand); else right_handed = TRUE; inputfp = fopen(infilename,"r"); /* skip any comments at the beginning of the file */ skip_comments(inputfp); fscanf(inputfp,"\tTotal Number of Objects In World:%d\n",&numobjects); if (numobjects < (1+FINGERS*ABDUCT)) printf("WARNING in vt_read_hand_model: file contains too few objects"); /* the palm and first phalanx of the thumb were created at a different */ /* scale and orientation than the rest of the model, so we use a different */ /* transform for them */ vt_rot_matrix(M_PI,'z',totmatrix); vt_mult_scale_matrix(scalevec,Postmult,totmatrix); vt_mult_trans_matrix(transvec,Postmult,totmatrix); vt_mult_rot_matrix(M_PI,'z',Postmult,totmatrix); /* Viewpoint has their hand pointing in the -y direction !@%$&*^ */ vt_rot_matrix(M_PI,'z',rotmatrix); vt_read_object(inputfp,&(hand->surface->forearm)); transform_object(&(hand->surface->forearm),rotmatrix); vt_read_object(inputfp,&(hand->surface->palm)); transform_object(&(hand->surface->palm),totmatrix); for (finger=THUMB; finger < FINGERS; finger++) for (joint=MCP; joint < ABDUCT; joint++) { vt_read_object(inputfp,&(hand->surface->digit[finger][joint])); if ((finger == THUMB) && (joint == MCP)) transform_object(&(hand->surface->digit[finger][joint]),totmatrix); else transform_object(&(hand->surface->digit[finger][joint]),rotmatrix); vt_calculate_face_normals(&(hand->surface->digit[finger][joint]), right_handed); vt_calculate_dihedral_angles(&(hand->surface->digit[finger][joint])); vt_calculate_vertex_normals(&(hand->surface->digit[finger][joint])); } /* HACK ALERT hardwired filename - LJE */ sprintf(geomfile, "%s/%s", glovedir, "hand_model.geom"); read_model_geom(geomfile,geom,thumb_roll_vecs); adjust_hand_model_geometry(geom,thumb_roll_vecs,hand); vt_calculate_face_normals(&(hand->surface->forearm),right_handed); vt_calculate_dihedral_angles(&(hand->surface->forearm)); vt_calculate_vertex_normals(&(hand->surface->forearm)); vt_calculate_face_normals(&(hand->surface->palm),right_handed); vt_calculate_dihedral_angles(&(hand->surface->palm)); vt_calculate_vertex_normals(&(hand->surface->palm)); for (finger=THUMB; finger < FINGERS; finger++) for (joint=MCP; joint < ABDUCT; joint++) { vt_calculate_face_normals(&(hand->surface->digit[finger][joint]), right_handed); vt_calculate_dihedral_angles(&(hand->surface->digit[finger][joint])); vt_calculate_vertex_normals(&(hand->surface->digit[finger][joint])); } fclose(inputfp); }
static int fig_read_meta_data(FILE *file, DiagramData *dia, DiaContext *ctx) { if (figversion >= 300) { /* Might exist earlier */ int portrait; if ((portrait = fig_read_line_choice(file, "Portrait", "Landscape", ctx)) == -1) { dia_context_add_message(ctx, _("Error reading paper orientation.")); return FALSE; } dia->paper.is_portrait = portrait; } if (figversion >= 300) { /* Might exist earlier */ int justify; if ((justify = fig_read_line_choice(file, "Center", "Flush Left", ctx)) == -1) { dia_context_add_message(ctx, _("Error reading justification.")); return FALSE; } /* Don't know what to do with this */ } if (figversion >= 300) { /* Might exist earlier */ int units; if ((units = fig_read_line_choice(file, "Metric", "Inches", ctx)) == -1) { dia_context_add_message(ctx, _("Error reading units.")); return FALSE; } /* Don't know what to do with this */ } if (figversion >= 302) { if (!fig_read_paper_size(file, dia, ctx)) return FALSE; } { real mag; char* old_locale; old_locale = setlocale(LC_NUMERIC, "C"); if (fscanf(file, "%lf\n", &mag) != 1) { dia_context_add_message_with_errno(ctx, errno, _("Error reading magnification.")); setlocale(LC_NUMERIC, old_locale); return FALSE; } setlocale(LC_NUMERIC, old_locale); dia->paper.scaling = mag/100; } if (figversion >= 302) { int multiple; if ((multiple = fig_read_line_choice(file, "Single", "Multiple", ctx)) == -1) { dia_context_add_message(ctx, _("Error reading multipage indicator.")); return FALSE; } /* Don't know what to do with this */ } { int transparent; if (fscanf(file, "%d\n", &transparent) != 1) { dia_context_add_message_with_errno(ctx, errno, _("Error reading transparent color.")); return FALSE; } /* Don't know what to do with this */ } if (!skip_comments(file)) { if (!feof(file)) { dia_context_add_message_with_errno(ctx, errno, _("Error reading Fig file.")); } else { dia_context_add_message(ctx, _("Premature end of Fig file\n")); } return FALSE; } { int resolution, coord_system; if (fscanf(file, "%d %d\n", &resolution, &coord_system) != 2) { dia_context_add_message_with_errno(ctx, errno, _("Error reading resolution.")); return FALSE; } /* Don't know what to do with this */ } return TRUE; }
void ReadCurve(std::ifstream & is, Curve_2 & cv) { // Read a line from the input file. char one_line[128]; skip_comments (is, one_line); std::string stringvalues(one_line); std::istringstream str_line (stringvalues, std::istringstream::in); // Get the arc type. // Supported types are: 'f' - Full ellipse (or circle). // 'e' - Elliptic arc (or circular arc). // 's' - Line segment. char type; bool is_circle = false; // Is this a circle. Rat_circle_2 circle; Rational r, s, t, u, v, w; // The conic coefficients. str_line >> type; // An ellipse (full ellipse or a partial ellipse): if (type == 'f' || type == 'F' || type == 'e' || type == 'E') { // Read the ellipse (using the format "a b x0 y0"): // // x - x0 2 y - y0 2 // ( -------- ) + ( -------- ) = 1 // a b // int a, b, x0, y0; str_line >> a >> b >> x0 >> y0; Rational a_sq = Rational(a*a); Rational b_sq = Rational(b*b); if (a == b) { is_circle = true; circle = Rat_circle_2 (Rat_point_2 (Rational(x0), Rational(y0)), Rational(a*b)); } else { r = b_sq; s = a_sq; t = 0; u = Rational(-2*x0*b_sq); v = Rational(-2*y0*a_sq); w = Rational(x0*x0*b_sq + y0*y0*a_sq - a_sq*b_sq); } if (type == 'f' || type == 'F') { // Create a full ellipse (or circle). if (is_circle) cv = Curve_2 (circle); else cv = Curve_2 (r, s, t, u, v, w); } else { // Read the endpointd of the arc. int x1, y1, x2, y2; str_line >> x1 >> y1 >> x2 >> y2; Point_2 source = Point_2 (Algebraic(x1), Algebraic(y1)); Point_2 target = Point_2 (Algebraic(x2), Algebraic(y2)); // Create the arc. Note that it is always clockwise oriented. if (is_circle) cv = Curve_2 (circle, CGAL::CLOCKWISE, source, target); else cv = Curve_2 (r, s, t, u, v, w, CGAL::CLOCKWISE, source, target); } }
/* NOTE: the input buffer must be null-terminated, i.e., *inbufend == 0 */ pst_obj * pst_get_token (unsigned char **inbuf, unsigned char *inbufend) { pst_obj *obj = NULL; unsigned char c; ASSERT(*inbuf <= inbufend && !*inbufend); skip_white_spaces(inbuf, inbufend); skip_comments(inbuf, inbufend); if (*inbuf >= inbufend) return NULL; c = **inbuf; switch (c) { #if 0 case '%': obj = pst_parse_comment(inbuf, inbufend); break; #endif case '/': obj = pst_parse_name(inbuf, inbufend); break; case '[': case '{': /* This is wrong */ obj = pst_new_mark(); (*inbuf)++; break; case '<': if (*inbuf + 1 >= inbufend) return NULL; c = *(*inbuf+1); if (c == '<') { obj = pst_new_mark(); *inbuf += 2; } else if (isxdigit(c)) obj = pst_parse_string(inbuf, inbufend); else if (c == '~') /* ASCII85 */ obj = pst_parse_string(inbuf, inbufend); break; case '(': obj = pst_parse_string(inbuf, inbufend); break; case '>': if (*inbuf + 1 >= inbufend || *(*inbuf+1) != '>') { ERROR("Unexpected end of ASCII hex string marker."); } else { char *mark; mark = NEW(3, char); mark[0] = '>'; mark[1] = '>'; mark[2] = '\0'; obj = pst_new_obj(PST_TYPE_UNKNOWN, mark); (*inbuf) += 2; } break; case ']': case '}': { char *mark; mark = NEW(2, char); mark[0] = c; mark[1] = '\0'; obj = pst_new_obj(PST_TYPE_UNKNOWN, mark); (*inbuf)++; } break; default: if (c == 't' || c == 'f') obj = pst_parse_boolean(inbuf, inbufend); else if (c == 'n') obj = pst_parse_null(inbuf, inbufend); else if (c == '+' || c == '-' || isdigit(c) || c == '.') obj = pst_parse_number(inbuf, inbufend); break; } if (!obj) { obj = pst_parse_any(inbuf, inbufend); } return obj; }