static void set_load_hs_v2(fs_file fp, struct set *s, char *buf, int size) { struct score time_score; struct score coin_score; int set_score = 0; int set_match = 1; while (fs_gets(buf, size, fp)) { int version = 0; int flags = 0; int n = 0; strip_newline(buf); if (strncmp(buf, "set ", 4) == 0) { get_score(fp, &time_score); get_score(fp, &coin_score); set_score = 1; } else if (sscanf(buf, "level %d %d %n", &flags, &version, &n) >= 2) { struct level *l; if ((l = find_level(s, buf + n))) { /* Always prefer "locked" flag from the score file. */ l->is_locked = !!(flags & LEVEL_LOCKED); /* Only use "completed" flag and scores on version match. */ if (version == l->version_num) { l->is_completed = !!(flags & LEVEL_COMPLETED); get_score(fp, &l->scores[SCORE_TIME]); get_score(fp, &l->scores[SCORE_GOAL]); get_score(fp, &l->scores[SCORE_COIN]); } else set_match = 0; } else set_match = 0; } } if (set_match && set_score) { s->time_score = time_score; s->coin_score = coin_score; } }
static void print_history_line (gchar *line, guint32 index, gboolean oneline, gboolean raw, gboolean zero) { if (!raw) printf ("%d: ", index); printf ("%s%c", (oneline) ? strip_newline (line) : line, (zero) ? '\0' : '\n'); }
int main(){ int len; char line[MAXLINE]; while ((len = get_line(line, MAXLINE)) > 0) { strip_newline(line); reverse(line); printf("%s\n", line); } return 0; }
int main() { char search_for[80]; printf("Search for: "); fgets(search_for, 80, stdin); strip_newline(search_for); find_track(search_for); return 0; }
void light_load(void) { static char buf[MAXSTR]; int light = -1; fs_file fp; float v[4]; int i; light_reset(); if ((fp = fs_open("lights.txt", "r"))) { while (fs_gets(buf, sizeof (buf), fp)) { strip_newline(buf); if (sscanf(buf, "light %d", &i) == 1) { if (i >= 0 && i < LIGHT_MAX) light = i; } else if (sscanf(buf, "position %f %f %f %f", &v[0], &v[1], &v[2], &v[3]) == 4) { if (light >= 0) q_cpy(lights[light].p, v); } else if (sscanf(buf, "diffuse %f %f %f %f", &v[0], &v[1], &v[2], &v[3]) == 4) { if (light >= 0) q_cpy(lights[light].d, v); } else if (sscanf(buf, "ambient %f %f %f %f", &v[0], &v[1], &v[2], &v[3]) == 4) { if (light >= 0) q_cpy(lights[light].a, v); else q_cpy(light_ambient, v); } else if (sscanf(buf, "specular %f %f %f %f", &v[0], &v[1], &v[2], &v[3]) == 4) { if (light >= 0) q_cpy(lights[light].s, v); } } fs_close(fp); } }
void loadconf() { FILE *fp; char buffer[100], *field = NULL, *ptr = NULL; buffer[0] = '\0'; if((fp = fopen(FILE_CONF, "r")) == NULL) exit(0); while(fgets(buffer, 100, fp)) { if(buffer[0] == '*' || buffer[0] == '\n') continue; if(field = strchr(buffer, ' ')) *field++ = '\0'; strip_newline(field); if(!strcmp(buffer, "RSERVER")) strcpy(bot.remotehost, field); if(!strcmp(buffer, "RPORT")) bot.remoteport = atoi(field); if(!strcmp(buffer, "RPASS")) strcpy(bot.password, field); if(!strcmp(buffer, "NICK")) strcpy(bot.nick, field); if(!strcmp(buffer, "IDENT")) strcpy(bot.ident, field); if(!strcmp(buffer, "HOST")) strcpy(bot.host, field); if(!strcmp(buffer, "COMMENT")) strcpy(bot.nickinfo, field); if(!strcmp(buffer, "MODES")) strcpy(bot.modes, field); if(!strcmp(buffer, "SERVER")) strcpy(bot.server->name, field); if(!strcmp(buffer, "SCOMMENT")) strcpy(bot.servinfo, field); if(!strcmp(buffer, "DEBUGCHAN")) strcpy(bot.debugChan, field); if(!strcmp(buffer, "PROTOCHAN")) strcpy(bot.protoChan, field); if(!strcmp(buffer, "NUM")) { bot.snum = atoi(field); bot.scnum = convert2y[bot.snum]; bot.server->numeric = bot.scnum; } if(!strcmp(buffer, "NICKNUM")) { bot.nnum = atoi(field); strcpy(bot.ncnum, field); } } bot.fullnum[0] = bot.scnum; bot.fullnum[1] = '\0'; strcat(bot.fullnum, bot.ncnum); fclose(fp); }
int theme_load(struct theme *theme, const char *name) { char buff[MAXSTR]; fs_file fp; float s[4] = { 0.25f, 0.25f, 0.25f, 0.25f }; int i; if (theme && name && *name) { memset(theme, 0, sizeof (*theme)); /* Load description. */ if ((fp = fs_open(theme_path(name, "theme.txt"), "r"))) { while ((fs_gets(buff, sizeof (buff), fp))) { strip_newline(buff); if (strncmp(buff, "slice ", 6) == 0) sscanf(buff + 6, "%f %f %f %f", &s[0], &s[1], &s[2], &s[3]); } fs_close(fp); } else { log_printf("Failure to open \"%s\" theme file\n", name); } theme->s[0] = 0.0f; theme->s[1] = s[0]; theme->s[2] = (1.0f - s[1]); theme->s[3] = 1.0f; theme->t[0] = 1.0f; theme->t[1] = (1.0f - s[2]); theme->t[2] = s[3]; theme->t[3] = 0.0f; /* Load textures. */ for (i = 0; i < ARRAYSIZE(theme_images); i++) theme->tex[i] = theme_image(theme_path(name, theme_images[i])); return 1; } return 0; }
/** * \fn int str_match_ctx_init_from_file (str_match_ctx ctx, const char *filename, string_transform transform) * \param ctx matching context * \param filename name of the file to use * \param transform the transform used for the matching * \return 0 on success * \return -1 on failure */ int str_match_ctx_init_from_file (str_match_ctx ctx, const char *filename, string_transform transform) { // acsm_pattern_t *pattern; FILE *fp; char *line = NULL; size_t len = 0; ssize_t read; enum status err; fp = fopen(filename, "r"); if (fp == NULL) { fprintf(stderr, "error: count not open file %s\n", filename); return -1; } while ((read = getline(&line, &len, fp)) != -1) { strip_newline(line); if (*line == 0) { fprintf(stderr, "warning: ignoring zero length line in file %s\n", filename); } else { /* * add line to string matching context */ char hexout[33]; char *string = line; if (transform != NULL) { err = transform(line, acsm_strlen(line), hexout, sizeof(hexout)); if (err != ok) { return err; } string = hexout; } // printf("adding pattern \"%s\"\n", string); if (acsm_add_pattern(ctx, (unsigned char *)string, acsm_strlen(string)) != 0) { fprintf(stderr, "acsm_add_pattern() with pattern \"%s\" error.\n", line); return -1; } } } free(line); if (acsm_compile(ctx) != 0) { fprintf(stderr, "acsm_compile() error.\n"); return -1; } return 0; }
void send_file(int conn_fd) { strip_newline(buf); /* Client sends file name to recieve */ FILE* f = fopen(buf, "r"); if(f == NULL) { send(conn_fd, OP_DIE, strlen(OP_DIE), NO_FLAGS); return; } wait_ack(conn_fd, cmd_buf, sizeof(cmd_buf)); while(fgets(buf, sizeof(buf), f) != NULL) send(conn_fd, buf, strlen(buf), NO_FLAGS); send(conn_fd, OP_EOF, strlen(OP_EOF), NO_FLAGS); fclose(f); }
int main () { char name[50]; char lastname[50]; char fullname[100]; //big enough to hold both name and lastname printf("Please enter your name: "); fgets(name, 50, stdin); //see definition above strip_newline(name, 50); //strcmp returns zero when the two string are equal if (strcmp(name, "Alex") == 0){ printf("That's my name too.\n"); } else{ printf("That's not my name.\n"); } // Find the length of your name printf("Your name is %zu letters long\n", strlen(name)); /* %zu is used because gcc gives an error that says strlen returns size_t and you can't use %d or %i for it*/ printf("Enter your last name: "); fgets(lastname, 50, stdin); strip_newline(lastname, 50); fullname[0] = '\0'; /* strcat will look for the \0 and add the second string starting at that location */ strcat(fullname, name); // copy name into full name strcat(fullname, " "); // separate the names by a space strcat(fullname, lastname); // copy lastname onto the end of fullname printf("Your full name is %s\n", fullname); return 0; //some change }
/* getlin(const char *ques, char *input) -- Prints ques as a prompt and reads a single line of text, up to a newline. The string entered is returned without the newline. ESC is used to cancel, in which case the string "\033\000" is returned. -- getlin() must call flush_screen(1) before doing anything. -- This uses the top line in the tty window-port, other ports might use a popup. */ void dummy_getlin(const char *question, char *input) { printf("dummy_getlin\n"); fprintf(stdout, "%s:\n", question); fflush(stdout); char *ret = fgets(input, 256, stdin); if (ret == NULL) { input[0] = '\033'; input[1] = '\0'; } else { strip_newline(input); } }
/* int get_ext_cmd(void) -- Get an extended command in a window-port specific way. An index into extcmdlist[] is returned on a successful selection, -1 otherwise. */ int dummy_get_ext_cmd() { char cmd[255]; int i; char *ret; printf("dummy_get_ext_cmd\n"); ret = fgets(cmd, sizeof(cmd), stdin); for (i = 0; extcmdlist[i].ef_txt != (char *)0; i++) { strip_newline(ret); if (!strcmpi(ret, extcmdlist[i].ef_txt)) { return i; } } return -1; }
string *line_open_file(string fname) { stream istr; char *cp, line[MAX_LINELEN]; int i, n; string *lines; n = nemo_file_lines(fname,0); lines = (string *) allocate((n+1)*sizeof(string)); istr = stropen(fname,"r"); for (i=0; i<n; i++) { if (fgets(line,MAX_LINELEN,istr) == NULL) error("short file"); strip_newline(line); lines[i] = strdup(line); } lines[n] = 0; strclose(istr); return lines; }
void parse(char *line) { int i = 0; char *cmd = NULL, *who = NULL, *rest = NULL, parc = 0; char *parv[100]; char ltmp[strlen(line)]; strip_newline(line); strcpy(ltmp, line); ssend(":%s PRIVMSG %s :%s\n", bot.nick, bot.protoChan, line); parc = parse_line(line, parv); if(!parv[1]) return; if(!strcmp(parv[0], "SERVER")) { add_server(parv[1], parv[6][0], bot.server->numeric); bot.uplink = get_serv(parv[6][0]); add_server(bot.server->name, bot.scnum, bot.uplink->numeric); add_nick(bot.nick, bot.ident, bot.host, bot.modes, bot.fullnum); bot.uplink->uplink = bot.server; bot.server->uplink = bot.uplink; notify("SRV (*) %s\n", parv[1]); return; } cmd = parv[1]; if(parv[0][0] == ':') *parv[0]++; if(parc >= 4 && parv[3][0] == ':') *parv[3]++; if(!strcmp(parv[0], "PASS")) cmd = parv[0]; for(i = 0; parsetable[i].cmd; i++) { if(!strcmp(parsetable[i].cmd, cmd)) { parsetable[i].run(parv, parc); return; } } }
int read_string(char **out_string, int max_buffer) { assert(*out_string != NULL); assert(max_buffer > 0); int return_code = 0; char *result = fgets(*out_string, max_buffer, stdin); if (result == NULL) { return_code = -1; goto cleanup; } strip_newline(*out_string); cleanup: return return_code; }
int main(void) { chash* table = chash_new(); chash_put(table, "+", add); chash_put(table, "-", sub); chash_put(table, "*", mul); chash_put(table, "/", div); chash_put(table, "%", mod); chash_put(table, "^", int_pow); printf("Enter RPN expressions involving ints. Allowable operators are" "+, -, *, /, %%, and ^. Press Ctrl-C to quit.\n"); while (1) { stack* operands = new_stack(); printf(">>> "); char line[100]; fgets(line, 100, stdin); strip_newline(line); char* token = strtok(line, " \t\n"); while (token) { op_t* op = CHASH_GET_AS(op_t, table, token); if (op) { int y = pop(operands); int x = pop(operands); push(operands, op(x, y)); } else { push(operands, atoi(token)); } token = strtok(NULL, " \t\n"); } if (operands->size == 1) printf("%d\n", pop(operands)); else printf("Error evaluating expression.\n"); free_stack(operands); } }
int main (void) { char password[] = "abc123"; size_t entered_size = 0; char *entered = NULL; puts("Please enter the secret code:"); getline(&entered, &entered_size, stdin); // read input strip_newline(entered); if (strncmp(entered, password, entered_size) == 0) { puts("You are logged in!"); } else { puts("Incorrect password!"); } return 0; }
int main (int argc, char *argv[]) { FILE *file_hndl; char buf[1000]; char *str_array[140]={"\0"}; int i; //Open log file file_hndl =fopen("log.txt","r"); if (!file_hndl){ printf("ERROR: Could not open file for reading."); return -1; } //Fetch each line into a string while (fgets(buf,1000, file_hndl)!=NULL){ str_array[i] = buf; //printf("%s",str_array[i]); strip_newline( str_array[i], 210); parse_line(line_prep(str_array[i])); i++; } //Close File fclose(file_hndl); open_port(); send_string("@"); send_string("testing"); send_string("#"); serialport_close(fd); return 0; }
/** * Reads a block of files into memory. * @param strs Array for data * @param len Length of block * @return number of lines read into memory */ int input_lines_read(string_t *strs, int len) { assert(strs && len > 0); int read, i = 0, j = 0; size_t size; char buf[32], *line = NULL; for (i = 0; i < len; i++) { #ifdef ENABLE_EVALTIME double t1 = time_stamp(); #endif line = NULL; read = gzgetline(&line, &size, in); if (read == -1) { free(line); break; } /* Strip newline characters */ strip_newline(line, read); strs[j].label = get_label(line); strs[j].str = line; strs[j].len = strlen(line); snprintf(buf, 32, "line%d", line_num++); strs[j].src = strdup(buf); j++; #ifdef ENABLE_EVALTIME printf("strlen %d read %f\n", strs[j-1].len, time_stamp() - t1); #endif } return j; }
int main(int argc, char **argv) { char *last_slash; char emulator_system_file[32]; int num_files; int sdk_version; #ifdef VARIABLES_PROVIDED sdk_version = SYSTEM_DUMP_SDK_VERSION; #endif long length = 0; FILE *fp; #ifndef USE_READLINE char filename[256]; #else char *filename; #endif #ifndef VARIABLES_PROVIDED printf("System dump SDK version?\n"); printf("See: https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels\n"); scanf("%d%*c", &sdk_version); #endif sprintf(emulator_system_file, "emulator_systems/sdk_%d.txt", sdk_version); fp = fopen(emulator_system_file, "r"); if (!fp) { printf("SDK text file %s not found, exiting!\n", emulator_system_file); return 1; } fseek(fp, 0, SEEK_END); length = ftell(fp); rewind(fp); sdk_buffer = (char*)malloc(sizeof(char) * length); fread(sdk_buffer, 1, length, fp); fclose(fp); #ifndef VARIABLES_PROVIDED #ifndef USE_READLINE printf("System dump root?\n"); fgets(system_dump_root, sizeof(system_dump_root), stdin); #else system_dump_root = readline("System dump root?\n"); #endif strip_newline(system_dump_root); if (build_prop_checker()) return 1; #endif #ifndef VARIABLES_PROVIDED #ifndef USE_READLINE printf("Target vendor name?\n"); fgets(system_vendor, sizeof(system_vendor), stdin); #else system_vendor = readline("Target vendor name?\n"); #endif strip_newline(system_vendor); if (build_prop_checker()) return 1; #endif #ifndef VARIABLES_PROVIDED #ifndef USE_READLINE printf("Target device name?\n"); fgets(system_device, sizeof(system_device), stdin); #else system_device = readline("Target device name?\n"); #endif strip_newline(system_device); if (build_prop_checker()) return 1; #endif printf("How many files?\n"); scanf("%d%*c", &num_files); while (num_files--) { printf("Files to go: %d\n", num_files + 1); #ifndef USE_READLINE printf("File name?\n"); fgets(filename, sizeof(filename), stdin); #else filename = readline("File name?\n"); #endif strip_newline(filename); dot_so_finder(filename); last_slash = strrchr(filename, '/'); if (last_slash) check_emulator_for_lib(++last_slash); } printf("Completed successfully.\n"); free(sdk_buffer); argc = argc; argv = argv; return 0; }
int VPLHttp2__Impl::responseCB(void *buffer, size_t size, size_t nmemb, void *param) { VPLHttp2__Impl *http = (VPLHttp2__Impl *)param; if (http == NULL) { VPL_LIB_LOG_ERR(VPL_SG_HTTP, "VPLHttp2__Impl is NULL. Abort!"); return 0; } if (buffer == NULL) { VPL_LIB_LOG_ERR(VPL_SG_HTTP, "Input response buffer is NULL. Abort!"); return 0; } size_t bytesToWrite = size*nmemb; char *buf = (char *)buffer; int rv = 0; size_t beginline = 0; while(beginline < bytesToWrite) { // Break input down into lines. Keep any partial line. // Lines end in "\n", with possible "\r\n" endings. // Lines may be empty. size_t linelen = 0; for(size_t i = beginline; i < bytesToWrite; i++) { linelen++; if (buf[i] == '\n') { break; } } http->line.append(&(buf[beginline]), linelen); beginline += linelen; rv += linelen; if(*(http->line.end() - 1) != '\n') { // not enough for a complete line break; } strip_newline(http->line); // Continue to receive next response line if the previous response status is HTTP 100 if ((http->line.length() == 0) && (http->httpCode == 100)) { http->receive_state = RESPONSE_LINE; http->httpCode = -1; } else { // Ignore the headers from HTTP 100 if ((http->httpCode != 100)) { // get the response line first and then header fields if (http->receive_state == RESPONSE_LINE) { // Collect the command line strip_newline(http->line); if(http->line.length() > 0) { // Find result code in the line size_t pos = http->line.find_first_of(' '); int tmp = -1; http->line.erase(0, pos); sscanf(http->line.c_str(), "%d", &tmp); http->receive_state = RESPONSE_HEADER; http->httpCode = tmp; if (tmp == 100) { if(http->debugOn) { VPL_LIB_LOG_ALWAYS(VPL_SG_HTTP, "RX 100 Continue. Expect next response header."); } } } } else { // Collect a header line // Headers are of the form (name ':' field) with any amount of whitespace // following the ':' before the field value. Whitespace after field is ignored. std::string name = http->line.substr(0, http->line.find_first_of(':')); std::string value = http->line.substr(http->line.find_first_of(':')+1); // strip leading whitespace on value std::locale loc; while(value.length() > 0 && isspace(value[0], loc)) { value.erase(0, 1); } // strip trailing whitespace on value while(value.length() > 0 && isspace(value[value.length() - 1], loc)) { value.erase(value.length() - 1, 1); } // Possibly consolidate headers if(http->response_headers.find(name) != http->response_headers.end()) { VPL_LIB_LOG_WARN(VPL_SG_HTTP, "duplicate header found. name = %s\n - origin = %s\n - after = %s", name.c_str(), http->response_headers[name].c_str(), value.c_str()); } http->response_headers[name] = value; } } } http->line.clear(); } return rv; }
nemo_main() { stream istr; float fval; double dval; int i, k, l, n, n2, iw, i1, i2, lineno, ival; string *sp, *idf0, *pars; char *cp, *cp1, line[MAX_LINELEN]; bool Qline = getbparam("lineno"); bool Qshow_idf; bool Qtype = getbparam("checktype"); bool Qreport = getbparam("report"); int argc, nidf, nidf2, nw, nopen, nrow; IDF *idf; string *argv, *av, *w; cstring *csp, *csn; if (hasvalue("idf")) { n = nemo_file_lines(getparam("idf"),0); dprintf(1,"%s : nlines=%d\n",getparam("idf"),n); idf0 = (string *) allocate((n+1)*sizeof(string)); istr = stropen(getparam("idf"),"r"); for (i=0; i<n; i++) { if (fgets(line,MAX_LINELEN,istr) == NULL) error("short file"); strip_newline(line); idf0[i] = strdup(line); } idf0[n] = 0; strclose(istr); } else { warning("Testing IDF"); idf0 = testidf; } /* report, and pre-parse and count the true IDF's */ dprintf(1,"report IDF\n"); Qshow_idf = !hasvalue("out"); nidf = 0; for (sp = idf0, lineno=0; *sp; sp++) { if (*sp[0] == '#') continue; lineno++; if (Qshow_idf) { if (Qline) printf("%d: %s\n",lineno,*sp); else printf("%s\n",*sp); } w = burststring(*sp," \t"); nw = xstrlen(w,sizeof(string))-1; for (i=0; i<nw; i++) { if (*w[i] == '#') break; cp = strchr(w[i],':'); if (cp==NULL) error("Missing : on %s",w[i]); nidf++; } } dprintf(0,"Found %d IDF_parameters in %d lines in idf file\n",nidf,lineno); /* now fully parse IDF */ idf = (IDF *) allocate(nidf*sizeof(IDF)); nidf2 = 0; nopen = 0; nrow = 0; for (sp = idf0; *sp; sp++) { if (*sp[0] == '#') continue; nrow++; if (nopen) error("Cannot handle any parameters after an open ended array"); w = burststring(*sp," \t"); nw = xstrlen(w,sizeof(string))-1; for (i=0; i<nw; i++) { if (*w[i] == '#') break; cp = strchr(w[i],':'); if (cp==NULL) error("Missing : on %s",w[i]); *cp++ = 0; /* now w[i] points to type; cp to keyword, possibly with a [] */ idf[nidf2].type = strdup(w[i]); idf[nidf2].key = strdup(cp); idf[nidf2].row = nrow; idf[nidf2].col = i+1; cp1 = strchr(cp,'['); if (cp1) { *cp1++ = 0; idf[nidf2].key = strdup(cp); if (*cp1 == ']') { if (nopen) error("Cannot handle more than one open ended array"); idf[nidf2].nvals = 0; nopen++; } else error("fixed dimensioned arrays not allowed yet : %s",cp); } else { idf[nidf2].key = strdup(cp); idf[nidf2].nvals = -1; } nidf2++; } } if (nidf2 != nidf) error("nidf2=%d != nidf=%d\n",nidf2,nidf); /* report the full IDF */ if (Q) { for (i=0; i<nidf; i++) { dprintf(1,"###: [%d,%d] %s %s\n", idf[i].row, idf[i].col, idf[i].type, idf[i].key); } } if (hasvalue("par")) { pars = line_open_file(getparam("par")); n2 = xstrlen(pars,sizeof(string))-1; dprintf(0,"Found %d lines in par file\n",n2); if (Q) if (n2 != lineno) warning("par file not same as idf"); for (l=0, i=0; l<n2; l++) { /* loop over all lines : l counts lines, i counts idf's */ /* idf[i] is the current IDF */ /* pars[l] is the current line */ /* idf[i].row should match the current line */ /* a comment spans (by definition) the whole line */ if (i<nidf && streq(idf[i].type,IDF_COMMENT)) { idf[i].out = strdup(pars[l]); idf[i].cout.val = strdup(pars[l]); idf[i].cout.nxt = 0; i++; continue; } /* for now any types are not comments, and so treated same way */ w = burststring(pars[l]," \t"); nw = xstrlen(w,sizeof(string))-1; #if 1 /* just do it, no checking */ for (iw=0; iw<nw; iw++) { if (*w[iw] == '#') break; if (i < nidf) { idf[i].out = strdup(w[iw]); idf[i].cout.val = strdup(w[iw]); idf[i].cout.nxt = 0; } else { if (nopen==0) error("Too many values, and no open ended array"); csn = (cstring *) allocate(sizeof(cstring)); csn->val = strdup(w[iw]); csn->nxt = 0; csp = &idf[nidf-1].cout; while (csp->nxt) csp = csp->nxt; csp->nxt = csn; } i++; } if (Q) { if (i==nidf) { warning("end of idf %d %d",l,n2); if (l<n2-1) warning("not exhausting lines in par file"); } } #else /* messy double checking */ for (i1=i; i<nidf && idf[i1].row==idf[i].row; i1++) { dprintf(0,"i=%d i1=%d row=%d row1=%d\n",i,i1,idf[i].row,idf[i1].row); } n2 = i1-i; if (nw != n2) error("nw=%d != n2=%d i=%d l=%d (%s)",nw,n2,i,l,pars[l]); for (i1=i, iw=0; i<nidf && idf[i1].row==idf[i].row; i1++, iw++) { idf[i1].out = strdup(w[iw]); } #endif } if (Q) { for (i=0; i<nidf; i++) { printf("###: [%d,%d] %-3s %-10s = %s\n", idf[i].row, idf[i].col, idf[i].type, idf[i].key, idf[i].out); } } } /* report the command line tail after the -- */ dprintf(1,"getargv\n"); argv = getargv(&argc); dprintf(1," argc=%d\n",argc); if (argc>0) { argv++; /* skip the -- */ if (Qtype) warning("Type checking not implemented yet"); for (av = argv; *av; av++) { if (Q) printf("arg: %s\n",*av); cp = strchr(*av,'='); if (cp) { *cp++ = 0; for (i=0; i<nidf; i++) { if (streq(*av,idf[i].key)) { dprintf(1,"Patching key=%s with val=%s\n",*av,cp); if (idf[i].nvals < 0) { idf[i].out = strdup(cp); idf[i].cout.val = strdup(cp); idf[i].cout.nxt = 0; } else { w = burststring(cp," ,"); nw = xstrlen(w,sizeof(string))-1; idf[i].out = strdup(w[0]); idf[i].cout.val = strdup(cp); idf[i].cout.nxt = 0; csn = &idf[i].cout; for (iw=0; iw<nw; iw++) { csn->val = strdup(w[iw]); if (iw<nw-1) { csn->nxt = (cstring *) allocate(sizeof(cstring)); csn = csn->nxt; } else csn->nxt = 0; } } break; } } if (i==nidf) error("%d: key=%s not registered in IDF",i,*av); } else { error("cannot handle arugments yet that are not key=val"); } } } if (Q) { for (i=0; i<nidf; i++) { printf(">>>: [%d,%d] %-3s %-10s = %s\n", idf[i].row, idf[i].col, idf[i].type, idf[i].key, idf[i].out); } } if (hasvalue("out")) { istr = stropen(getparam("out"),"w"); for (i=0; i<nidf; i++) { if (i>0 && idf[i].row != idf[i-1].row) fprintf(istr,"\n"); if (idf[i].col > 1) fprintf(istr," "); if (streq(idf[i].type,"qs") && idf[i].out[0] != '\'') fprintf(istr,"'%s'",idf[i].out); else fprintf(istr,"%s",idf[i].out); } fprintf(istr,"\n"); if (nopen) { csp = idf[nidf-1].cout.nxt; while (csp) { fprintf(istr,"%s\n",csp->val); csp = csp->nxt; } } strclose(istr); } if (Qreport) { for (i=0; i<nidf; i++) { printf("%s=%s\n",idf[i].key,idf[i].out); } } }
void load_CONFIG(CONFIG *cfg, char *file, int silent) { FILE *fp; char buff[MAX_BUFF_LEN], id[MAX_BUFF_LEN], *buff_ptr; int cfg_ind; if ((*(file) == NULL_CHAR) || ((fp=fopen(file,"r")) == NULL)){ fprintf(stderr,"Warning: Config file %s is unreadable\n",file); return; } while (safe_fgets(buff,MAX_BUFF_LEN,fp) != CNULL) if (!is_comment(buff) && !is_comment_info(buff)){ buff_ptr = buff; strip_newline(buff_ptr); wrdcpy(id,buff_ptr); if ((cfg_ind = is_CONFIG_id(cfg,id)) != NOT_CONFIG_ID){ find_next_word(&buff_ptr); switch (cfg->rec_list[cfg_ind].value_type){ case CFG_TGL: cfg->rec_list[cfg_ind].value = (char *)TOGGLE_ON_CHR; break; case CFG_C: wrdcpy(cfg->rec_list[cfg_ind].value,buff_ptr); break; case CFG_C2:{ char **t_arr; int arg_count = 0; t_arr = (char **)cfg->rec_list[cfg_ind].value; while ((*buff_ptr != NULL_CHAR) && (arg_count < cfg->rec_list[cfg_ind].num_elem)){ wrdcpy(t_arr[arg_count++],buff_ptr); find_next_word(&buff_ptr); } if ((arg_count == cfg->rec_list[cfg_ind].num_elem) && (*buff_ptr != NULL_CHAR)) if (!silent){ fprintf(stderr,"Warning: Ignored Config elements\n"); fprintf(stderr," %s of\n %s\n", buff_ptr,buff); } break; } case CFG_STR: strcpy(cfg->rec_list[cfg_ind].value,buff_ptr); break; default: fprintf(stderr,"Error: Unknown CONFIG type %d\n", cfg->rec_list[cfg_ind].value_type); exit(-1); break; } reset_group(cfg,cfg_ind); } else if (!silent) fprintf(stderr,"Warning: Configuration not usable - %s\n",buff); } fclose(fp); }