FILE *locate_file(char *override_filename, char *home_dir_filename, char *fallback_filename) { char *filename; FILE *result; errno = 0; if (override_filename) { if (string_Eq(override_filename, "-")) return(stdin); result = fopen(override_filename, "r"); if (!(result = fopen(override_filename, "r"))) { /* <<<>>> */ fprintf(stderr, "zwgc: error while opening %s for reading: ", override_filename); perror(""); } return(result); } if (home_dir_filename) { filename = get_home_directory(); if (filename) { filename = string_Concat(filename, "/"); filename = string_Concat2(filename, home_dir_filename); result = fopen(filename, "r"); if (result) { free(filename); return(result); } if (errno != ENOENT) { /* <<<>>> */ fprintf(stderr, "zwgc: error while opening %s for reading: ", filename); perror(""); free(filename); return(result); } free(filename); } else ERROR("unable to find your home directory.\n"); } if (fallback_filename) { if (!(result = fopen(fallback_filename, "r"))) { /* <<<>>> */ fprintf(stderr, "zwgc: error while opening %s for reading: ", fallback_filename); perror(""); } return(result); } return(NULL); }
static char * eat_til_endshow(int start_line_no) { register int c; string text_so_far = string_Copy(""); string next_line; for (;;) { /* * Skip the spaces & tabs at the start of the current line: */ while ((c=input()), c==' ' || c=='\t') ; unput(c); /* * Handle unterminated shows: */ if (!c) { report_parse_error("unterminated show beginning", start_line_no); free(text_so_far); return(0); } /* * Read in rest of the line (including the <cr> at end), allowing * for escape codes and checking for "endshow{nonalpha}" at the * start of the line. (Note: \<newline> is considered the * end of a line here!) */ next_line = eat_show_line(1); if (!next_line) /* i.e., is this the endshow line? */ return(text_so_far); text_so_far = string_Concat2(text_so_far, next_line); free(next_line); } }
/* * */ char * get_string_resource(string name, string class) { string full_name, full_class; int status; char *type; XrmValue value; full_name = string_Concat(APPNAME, "."); full_name = string_Concat2(full_name, name); full_class = string_Concat(APPCLASS, "."); full_class = string_Concat2(full_class, class); status = XrmGetResource(x_resources, full_name, full_class, &type, &value); free(full_name); free(full_class); if (status != True) return(NULL); if (string_Neq(type, "String")) return(NULL); return(value.addr); }