char *process_comment_option(const char *cmt) { char *retval; assert(cmt); if (!strcmp(cmt, "-")) { /* * Read comment from stdin. */ retval = read_from_fp(stdin); if (!retval) { myerror("Could not read data from stdin"); return NULL; } } else if (!strcmp(cmt, "--")) { /* * Open the user's favourite editor and edit the comment there * in a temporary file. */ char *e; e = get_editor(); if (!e) return NULL; retval = read_from_editor(e); free(e); if (!retval) return NULL; } else { /* * The comment was stored as a plain string in the -c/--comment * argument. */ retval = strdup(cmt); if (!retval) { myerror("%s: Cannot allocate memory for comment, " "strdup() failed"); return NULL; } } if (!valid_xml_chars(retval)) { fprintf(stderr, "%s: Comment contains illegal characters or " "is not valid UTF-8\n", progname); free(retval); return NULL; } /* fixme: This is how it's done in the Perl version. I'm not sure if * it's an ok thing to do, even though it looks nice in the log files * and has worked great for years. Maybe this behaviour should be * changed when the C version passes all tests in suuid.t . */ trim_str_front(retval); trim_str_end(retval); return retval; }
static void input_from_stdin(size_t offset, size_t fp_len, int action, int options) { size_t len, buf_len; if (action == BMZ_A_LIST) { do_list(0); } else { void *data = read_from_fp(stdin, &len, &buf_len); do_block(data, len, buf_len, offset, fp_len, action, options); } }
char *read_from_file(const char *fname) { FILE *fp; char *retval; assert(fname); assert(strlen(fname)); fp = fopen(fname, "rb"); if (!fp) { myerror("read_from_file(): Could not open file for read"); return NULL; } retval = read_from_fp(fp); if (!retval) return NULL; fclose(fp); return retval; }
/* * Parse a game file and retrieve game information */ int CTadsGameInfo::read_from_file(const char *fname) { /* open the file */ osfildef *fp; if ((fp = osfoprb(fname, OSFTGAME)) == 0 && (fp = osfoprb(fname, OSFTT3IMG)) == 0) { /* * we can't open the file, so we obviously can't parse it to find * game information */ return 0; } /* parse the file and find the game information */ int ret = read_from_fp(fp); /* we're done with the file - close it */ osfcls(fp); /* return the results from the parser */ return ret; }
static void test_from_stdin() { size_t len; char *data = read_from_fp(stdin, &len); test_from_string(data, len); }