/* * FILE */ #include #include #include "global.h" #include "file.h" #define STR_SIZE 128 static char str[STR_SIZE]; /*************************************************************************** * * file_get_int(...) * ***************************************************************************/ FLAG file_get_int(file,i_ptr) FILE *file; int *i_ptr; { if (!fscanf (file,"%d",i_ptr)) {if (!feof(file)) error("Not at end of file and cannot read file"); return (FALSE); } return (TRUE); } /*************************************************************************** * * file_get_line(...) * ***************************************************************************/ char *file_get_line(file) FILE *file; { int i; if (feof(file)) return (NULL); for (i = 0; i < STR_SIZE; i++) { if (fscanf(file,"%c",&str[i]) != 1) { perror("System Error"); if (!feof(file)) { perror("System Error"); error("Not at end of file and cannot read file"); } return (NULL); } if (str[i] == '\n') { i++; break; } } str[i] = NULL; if (strlen(str) >= STR_SIZE) { error("String from file too long"); return (NULL); } return (str); } /*************************************************************************** * * file_get_str(...) * ***************************************************************************/ char *file_get_str(file) FILE *file; { if (feof(file)) return (NULL); if (!fscanf (file,"%s",str)) {if (!feof(file)) error("Not at end of file and cannot read file"); return (NULL); } if (strlen(str) >= STR_SIZE) { error("String from file too long"); return (NULL); } return (str); } /*************************************************************************** * * file_open(...) * ***************************************************************************/ FILE *file_open(name) char *name; { FILE *file; file = fopen(name,"r"); if (!file) { perror("System Error"); error("Cannot open file"); return (NULL); } return (file); }