void nl_convert_spice_t::convert(const pstring &contents) { std::vector<pstring> spnl(plib::psplit(contents, "\n")); // Add gnd net // FIXME: Parameter out("NETLIST_START(dummy)\n"); add_term("0", "GND"); pstring line = ""; for (const auto &i : spnl) { // Basic preprocessing pstring inl = plib::ucase(plib::trim(i)); if (plib::startsWith(inl, "+")) line = line + inl.substr(1); else { process_line(line); line = inl; } } process_line(line); dump_nl(); // FIXME: Parameter out("NETLIST_END()\n"); }
void nl_convert_spice_t::convert(const pstring &contents) { pstring_vector_t spnl(contents, "\n"); // Add gnd net // FIXME: Parameter out("NETLIST_START(dummy)\n"); add_term("0", "GND"); pstring line = ""; for (std::size_t i=0; i < spnl.size(); i++) { // Basic preprocessing pstring inl = spnl[i].trim().ucase(); if (inl.startsWith("+")) line = line + inl.substr(1); else { process_line(line); line = inl; } } process_line(line); dump_nl(); // FIXME: Parameter out("NETLIST_END()\n"); }
void compile_shader_mem(void *data, int len) { char line[256]; memset(&line,0,sizeof(line)); int i =0; char c; char *p = (char *)data; while((len-- > 0) && (c = (char)*p++)) { if(c == 0) { line[i] = 0; if(line[0] != '#' || line[0] == ';') process_line(line); //printf("Last line: %s\n",line); break; } else if(c == '\t' || c=='\r') { } else if(c == '\n') { line[i] = 0; i = 0; if(line[0] != '#' || line[0] == ';') process_line(line); //printf("Parse line: %s\n",line); }else { line[i++] = c; } } }
/* * Open the file and initiate recursive processing. */ static int process(const char *fname) { char buf[8192]; char *collector = 0; size_t collector_size = sizeof(buf); size_t collector_offset = 0; int lineno = 0; FILE *fp; if(strcmp(fname, "-")) { fp = fopen(fname, "r"); if(!fp) { perror(fname); return -1; } } else { fp = stdin; } while(fgets(buf, sizeof(buf), fp) || !feof(fp)) { size_t len = strlen(buf); if(!len) continue; if(collector_offset || buf[len - 1] != '\n') { if((collector_size - collector_offset) <= len || !collector) { collector_size <<= 1; collector = REALLOC(collector, collector_size); if(!collector) { perror("realloc()"); exit(EX_OSERR); } } memcpy(collector + collector_offset, buf, len + 1); collector_offset += len; } if(buf[len - 1] != '\n') continue; if(collector_offset) { assert(collector[collector_offset - 1] == '\n'); process_line(fname, collector, ++lineno); collector_offset = 0; } else { process_line(fname, buf, ++lineno); } } if(fp != stdin) fclose(fp); return 0; }
void unix_console_connection::process_input(int len) { int st = 0; while (st < len) { int i; for (i = st; i < len; i++) { if (buffer[i] == '\n' || buffer[i] == ';' || buffer[i] == '?') { break; } } if (buffer[i] == '?') { //std::string in((const char *)buffer + st, i - st); std::string in((const char *)buffer + st, (i + 1) - st); dump_partial(in.c_str()); } else if ((i - st) > 0) { if (buffer[i] == '\n') i--; std::string in((const char *)buffer + st, i - st); process_line(in.c_str()); } st = i + 1; } if (autoclose) { if (bufbuffer.empty()) console->release_connection(this); else doom(); } }
DEFINE_CMD_MAIN(filecmd,int argc,TCHAR** argv) { int i; TCHAR* fn; FILE* fp; for(i=1;i<argc;i++) { fn=argv[i]; if(_tcscmp(fn,TEXT("-"))==0) fp=stdin; else { fp=_tfopen(fn,TEXT("r")); } if(fp) { TCHAR* line = malloc(MAX_ARG_LENGTH*sizeof(TCHAR)+1); int l=0; DEBUG_PRINT(TEXT("reading file %s\n"),fn); while((l=fgetline(line,MAX_ARG_LENGTH,fp))!=-1) { if(l==0) continue; if(!process_line(APPNAME,line)) break; } fclose(fp); } else { fprintf(stderr,TEXT("File not accessable:\"%s\"\n"),fn); } } return 0; }
static int process_file(const char *fname) { FILE *fp; int linenum = 0, err = 0; char linebuf[256]; fp = fopen(fname, "r"); if (!fp) { err = ERR_FILE_NOT_FOUND; goto ret; } while (fgets(linebuf, sizeof(linebuf), fp)) { ++linenum; err = process_line(linebuf); if (err) { fprintf(stderr, "error at line %d: ", linenum); break; } } ret: if (fp) fclose(fp); return err; }
/* process a single client connection */ static void do_connection(mysocket_t sd) { char line[256]; int rc; /* loop over: - get a request from the client - process the request */ for (;;) { rc = get_nvt_line(sd, line); if (rc < 0 || !*line) goto done; fprintf(stderr, "client: %s\n", line); if (process_line(sd, line) < 0) { perror("process_line"); goto done; } } /* for (;;) */ done: if (myclose(sd) < 0) { perror("myclose (sd)"); } }
void set_read(const char *filename) { FILE *fp; char line[4096]; if (config_file_has_been_read) { warn("%s(): trying to read config file again", __func__); return; } config_file_has_been_read = 1; fp = fopen(filename, "r"); if (!fp) { warn("could not open file %s", filename); return; } while (fgets(line, sizeof(line), fp)) { char *p; if (line[0] == '\0') continue; p = strrchr(line, '\n'); if (!p) continue; *p = '\0'; process_line(line); } fclose(fp); }
/* ** Write the header of the file (minus the prog size) ** init the linked lists storing label definition and reference ** Read every line of the file fd_champ, ** split them into a word tab and send them ** to process_line ** Then launch late_operation ** if any error is encountered during these operations, ** return -1, else return 0 */ int my_parsefile(int fd_champ, int fd_binary) { char *line; char **lexed_line; int j; int fileoffset; t_lateinfo info; my_init_info(&info); if ((fileoffset = write_header(fd_champ, fd_binary)) == -1) return (-1); j = 1; while ((line = get_next_line(fd_champ)) != NULL) { if (line[0] != COMMENT_CHAR && line[0] != '.' && line[0] && line[0]) { if ((lexed_line = my_epur(all_in_tab(line))) == NULL || process_line(lexed_line, fd_binary, &fileoffset, &info) == -1) { my_fprintf(2, "at line %i : \"%s\" ", j, line); return (-1); } } free(line); ++j; } return (late_operation(fd_binary, fileoffset, &info)); }
static void user_marker_info(char *fname) { int idx; char *buf; const char *msg; FILE *ins; ins = fopen(fname, "r"); if (ins == NULL) { warning("unable to open marker info file"); return; } idx = 1; buf = (char *) malloc(MaxLineLen); assert(buf != NULL); while (get_line(ins, buf, MaxLineLen, &msg) != NULL) { if (msg != NULL) { fflush(stdout); fprintf(stderr, "%s, line %d: %s\n", fname, idx, msg); fprintf(stderr, " (length = %d)\n", (int) strlen(buf)); fflush(stderr); } process_line(buf, fname, idx); idx += 1; } free(buf); fclose(ins); }
int risin_processf( fields *risin, char *p, char *filename, long nref ) { newstr tag, data; newstr_init( &tag ); newstr_init( &data ); while ( *p ) { if ( risin_istag( p ) ) { p = process_line( &tag, &data, p ); /* no anonymous fields allowed */ /* if ( tag.len && data.len )*/ if ( tag.len ) fields_add( risin, tag.data, data.data, 0 ); } else { p = process_line2( &tag, &data, p ); if ( data.len && risin->nfields>0 ) { newstr *od; od = &(risin->data[risin->nfields-1] ); newstr_addchar( od, ' ' ); newstr_strcat( od, data.data ); } } newstr_empty( &tag ); newstr_empty( &data ); } newstr_free( &tag ); newstr_free( &data ); return 1; }
/** Get the lines and boundaries from the map and load them in an array */ void load_lines(struct Map_info *map, struct Point **points, int *num_points, struct Line **lines, int *num_lines) { int index_line = 0; int index_point = 0; struct line_pnts *sites; struct line_cats *cats; int cat = 0; int type; sites = Vect_new_line_struct(); cats = Vect_new_cats_struct(); while ((type = Vect_read_next_line(map, sites, cats)) > -1) { if (type != GV_LINE && type != GV_BOUNDARY && type != GV_POINT) continue; if (type == GV_LINE) process_line(sites, points, &index_point, lines, &index_line, -1); else if (type == GV_BOUNDARY) process_boundary(sites, points, &index_point, lines, &index_line, cat++); else if (type == GV_POINT) process_point(sites, points, &index_point, -1); } *num_points = index_point; *num_lines = index_line; Vect_destroy_line_struct(sites); Vect_destroy_cats_struct(cats); }
void *connection_handler(void *socket_desc) { repl_t *repl = make_repl(); repl->current_prompt = form_prompt(repl->current_ns, false); repl->session_id = ++session_id_counter; int sock = *(int *) socket_desc; ssize_t read_size; char client_message[4096]; write(sock, repl->current_prompt, strlen(repl->current_prompt)); while ((read_size = recv(sock, client_message, 4095, 0)) > 0) { sock_to_write_to = sock; cljs_set_print_sender(&socket_sender); client_message[read_size] = '\0'; process_line(repl, strdup(client_message)); cljs_set_print_sender(NULL); sock_to_write_to = 0; write(sock, repl->current_prompt, strlen(repl->current_prompt)); } free(socket_desc); return NULL; }
/* main program controls all the action */ int main(int argc, char *argv[]) { int fileinput=0; command_t comd; csv_t D; /* first argument on commandline is the data file name */ read_csv_file(argv[1], &D); /* second argument, if it exists, is file of input commands */ if (argc==3) { fileinput = 1; reassign_input(argv[2]); } /* start the main execution loop */ print_prompt(); while (read_command(&comd, fileinput, D.ncols)) { process_line(&comd, &D); /* then round we go */ print_prompt(); } /* all done, so pack up and go home */ printf("bye\n"); return 0; }
static gboolean channel_process_input () { static char linebuf[4096]; char *linep = linebuf; char *line; int bytes_read; #if GLIB_MAJOR_VERSION > 1 // we need to call this again because we will get new events before returning // from this function // semantics of add_watch silently changing between glib versions!!!! g_io_add_watch (channel_in, G_IO_IN, (GIOFunc) channel_process_input, NULL); #endif g_io_channel_read (channel_in, linebuf, 4096, &bytes_read); linebuf[bytes_read] = '\0'; while (*linep != '\0') { line = linep; while (*linep++ != '\n') g_assert (linep[-1] != '\0'); linep[-1] = '\0'; if (opt_verbose) printf ("engine got command \"%s\"\n", line); command_list = g_slist_append (command_list, g_strdup (line)); } while (process_line ()) ; #if GLIB_MAJOR_VERSION == 1 return TRUE; #else return FALSE; #endif }
static int read_file(int const fd, char **line, char **test, int c) { int byte_read; char buf[BUFF_SIZE + 1]; int char_left; if ((char_left = 0) == 0 && process_buf(&char_left, test, &c, line)) return (1); while ((byte_read = read(fd, buf, BUFF_SIZE))) { if ((buf[byte_read] = 0) == 0 && byte_read == -1) return (-1); char_left = process_line(byte_read, buf, line, c); c += byte_read; if (char_left > 0) { if (!(*test)) ft_memdel((void **)test); (*test) = ft_strnew(char_left); ft_strncpy((*test), buf + (byte_read - char_left), char_left); } else if (char_left == 0) ft_memdel((void **)test); if (char_left != -1) return (1); } return (0); }
void hdcolors::read_config(char *filename){ FILE *cfgfile=fopen(filename,"rt"); if (cfgfile==NULL) con->printf("^7failed to open config-file %s\n",filename); else { char line[256]; line[255]=0; while(!feof(cfgfile)){ fgets(line,255,cfgfile); line[strlen(line)!=0?strlen(line)-1:0]=0; char *pos; pos=strchr(line,';'); if (pos!=NULL) *pos=0; pos=strchr(line,'#'); if (pos!=NULL) *pos=0; if (*pos!=0){ pos=line+strlen(line)-1; while(*pos==' ')pos--; *(++pos)=0; pos=line; while(*pos==' ')pos++; // strupr(pos); strlwr(pos); if (*pos!=0&&strrchr(pos,'=')!=0) process_line(pos); }; }; fclose(cfgfile); }; };
void convert(FILE *a, FILE *b, FILE *c, FILE *d) { static char line[MAX_LINE_LEN+1]; header(b, "gnuplot help"); fprintf(b, "<h1 align=\"center\">gnuplot %s patchlevel %s</h1>\n", gnuplot_version, gnuplot_patchlevel); header(c, "gnuplot help contents"); fprintf(c, "<ul>\n"); if (d) { header(d, "gnuplot help index"); fprintf(d, "<ul>\n"); } /* process each line of the file */ while (get_line(line, sizeof(line), a)) { process_line(line, b, c, d); } footer(b); fprintf(c, "</ul>\n"); footer(c); if (d) { fprintf(d, "</ul>\n"); footer(d); } list_free(); }
int process_file(ai::PL::KnowledgeBase &kb, char *buf, std::istream &in, std::ostream &out) { int done = 0; int interactive = 0; if(isatty(fileno(in))) { interactive = 1; } while(in.good() && !done) { if(interactive) { out << "> " << std::flush; } in.getline(buf, BUF_SIZE); if((strlen(buf) == 0) && !in.good()) { // end of file without any data out << std::endl; continue; } done = process_line(kb, interactive, buf, in, out); } return 0; }
void GPS_Neo::tick() { QFile file("/tmp/nmeaNP"); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { // qDebug() << file.error(); return; } QByteArray line; while (!file.atEnd()) { line = file.readLine(); if (line.contains("GPRMC")) { break; } } file.close(); GPS_Position pos = process_line(line); emit(new_position(pos.time, QPointF(pos.longitude, pos.latitude))); if (running) { QTimer::singleShot(1000, this, SLOT(tick())); } }
void client_read_cb(struct bufferevent *bev, void *ctx) { size_t len; struct evbuffer *input = bufferevent_get_input(bev); char *line = evbuffer_readln(input, &len, EVBUFFER_EOL_CRLF); if (!line) return; #ifdef BOARDD_MT process_line_ctx *plc = (process_line_ctx *) malloc(sizeof(process_line_ctx)); if (!plc) return; // One request at a time. bufferevent_disable(bev, EV_READ); plc->bev = bev; plc->ctx = ctx; plc->line = line; threadpool_do(g_threadpool, threadpool_job_new(process_line_job_func, plc)); #else process_line(bev, ctx, line); #endif }
static void read_file(FILE *fp) { char line[1024]; while (fgets(line, sizeof(line), fp)) process_line(line); }
static int http_read_header(URLContext *h, int *new_location) { HTTPContext *s = h->priv_data; char line[MAX_URL_SIZE]; int err = 0; s->chunksize = -1; for (;;) { if ((err = http_get_line(s, line, sizeof(line))) < 0) return err; av_log(h, AV_LOG_TRACE, "header='%s'\n", line); err = process_line(h, line, s->line_count, new_location); if (err < 0) return err; if (err == 0) break; s->line_count++; } if (s->seekable == -1 && s->is_mediagateway && s->filesize == 2000000000) h->is_streamed = 1; /* we can in fact _not_ seek */ // add any new cookies into the existing cookie string cookie_string(s->cookie_dict, &s->cookies); av_dict_free(&s->cookie_dict); return err; }
/* Callback triggered when some serial msgs are available */ int in_serial_collect(struct flb_config *config, void *in_context) { int ret; int bytes; char line[1024]; struct flb_in_serial_config *ctx = in_context; while (1) { bytes = read(ctx->fd, line, sizeof(line) - 1); if (bytes == -1) { if (errno == -EPIPE) { return -1; } return 0; } /* Always set a delimiter to avoid buffer trash */ line[bytes - 1] = '\0'; /* Check if our buffer is full */ if (ctx->buffer_id + 1 == SERIAL_BUFFER_SIZE) { ret = flb_engine_flush(config, &in_serial_plugin); if (ret == -1) { ctx->buffer_id = 0; } } /* Process and enqueue the received line */ process_line(line, ctx); } }
void process_lines(struct ast_node_lines* lines) { struct ast_node_line* current; struct dbg_sym* newsym; // First reverse the lines. reverse_lines(lines); // Now navigate the linked list (although it says prev / last // here, we are actually now navigating it forwards because // we reversed it). current = lines->last; list_init(&newsyms); while (current != NULL) { // Process each line. process_line(current); current = current->prev; } while (list_size(&newsyms) > 0) { // Get each trailing debug symbol and store it in the list anyway. newsym = list_extract_at(&newsyms, 0); printd(LEVEL_DEBUG, "Debugging trailing symbol.\n"); list_append(assem_dbg_symbols, newsym); } list_destroy(&newsyms); }
static int process_file(struct selabel_handle *rec, const char *filename) { unsigned int line_num; int rc; char *line_buf = NULL; size_t line_len = 0; FILE *context_file; const char *prefix = NULL; context_file = fopen(filename, "r"); if (!context_file) { fprintf(stderr, "Error opening %s: %s\n", filename, strerror(errno)); return -1; } line_num = 0; rc = 0; while (getline(&line_buf, &line_len, context_file) > 0) { rc = process_line(rec, filename, prefix, line_buf, ++line_num); if (rc || ctx_err) { /* With -p option need to check and fail if ctx err as * process_line() context validation on Linux does not * return an error, but does print the error line to * stderr. Android will set both to error and print * the error line. */ rc = -1; goto out; } } out: free(line_buf); fclose(context_file); return rc; }
static void read_file(struct db_main *db, char *name, int flags, void (*process_line)(struct db_main *db, char *line)) { struct stat file_stat; FILE *file; char line[LINE_BUFFER_SIZE]; if (flags & RF_ALLOW_DIR) { if (stat(name, &file_stat)) { if (flags & RF_ALLOW_MISSING) if (errno == ENOENT) return; pexit("stat: %s", path_expand(name)); } else if (S_ISDIR(file_stat.st_mode)) return; } if (!(file = fopen(path_expand(name), "r"))) { if ((flags & RF_ALLOW_MISSING) && errno == ENOENT) return; pexit("fopen: %s", path_expand(name)); } while (fgets(line, sizeof(line), file)) { process_line(db, line); check_abort(0); } if (ferror(file)) pexit("fgets"); if (fclose(file)) pexit("fclose"); }
int main(int argc, char **argv) { char buf[READBUFSIZE]; prog = *argv; argv++; argc--; memset(buf, 0, READBUFSIZE); if (argc == 0 || !strcmp(*argv, "-h")) { usage(); return 0; } if (argc == 1 && !strcmp(*argv, "-v")) { printf("%s\n", FEX_VERSION); return 0; } while (NULL != fgets(buf, READBUFSIZE, stdin)) { int len; len = strlen(buf); len--; /* skip EOL */ buf[len] = '\0'; /* Turn EOL into null */ process_line(buf, len, argc, argv); } return 0; }
// Based off of the example provided by bdonlan at // http://stackoverflow.com/questions/6090594/c-recv-read-until-newline-occurs void read_lines(int fd) { size_t buf_remain = sizeof(buffer) - inbuf_used; if (buf_remain == 0) { fprintf(stderr, "Line exceeded buffer length. \n"); } ssize_t rv = read(fd, (void *)&buffer[inbuf_used], buf_remain); if (rv == 0) { exit(EXIT_SUCCESS); } if (rv < 0 && errno == EAGAIN) { // Socket has no data for us return; } if (rv < 0) { printf("Connection error"); } inbuf_used += rv; char *line_start = buffer; char *line_end; while( (line_end = memchr((void*)line_start, '\n', inbuf_used - (line_start - buffer)))){ *line_end = 0; printf("%s\n", line_start); process_line(line_start, fd); line_start = line_end + 1; } inbuf_used -= (line_start - buffer); memmove(buffer, line_start, inbuf_used); }