+ char * f_name = "try_fgetc_noeof()";
+ int test = try_fgetc(file, f_name);
+ exit_trouble(EOF == test, f, "fgetc() unexpectedly hitting EOF");
+ return (uint8_t) test;
+}
+
+
+
+extern void try_fclose_unlink_rename(FILE * file, char * p1, char * p2,
+ char * f)
+{
+ try_fclose(file, f);
+ char * msg1 = "Trouble in ";
+ char * msg4 = "'.";
+ if (!access(p2, F_OK))
+ {
+ char * msg2 = " with unlink() on path '";
+ uint16_t size = strlen(msg1) + strlen(msg2) + strlen(msg4)
+ + strlen(f) + strlen(p2) + 1;
+ char msg[size];
+ sprintf(msg, "%s%s%s%s%s", msg1, f, msg2, p2, msg4);
+ exit_err(unlink(p2), msg);
+ }
+ char * msg2 = " with rename() from '";
+ char * msg3 = "' to '";
+ uint16_t size = strlen(msg1) + strlen(f) + strlen(msg2) + strlen(p1)
+ + strlen(msg3) + strlen(p2) + strlen(msg4) + 1;
+ char msg[size];
+ sprintf(msg, "%s%s%s%s%s%s%s", msg1, f, msg2, p1, msg3, p2, msg4);
+ exit_err(rename(p1, p2), msg);
+}
+
+
+
+extern uint16_t get_linemax(FILE * file, char * f)
+{
+ uint16_t linemax;
+ exit_trouble(textfile_sizes(file, &linemax, NULL), f, "textfile_sizes()");
+ return linemax;
+}
+
+
+
+extern uint8_t textfile_sizes(FILE * file, uint16_t * linemax_p,
+ uint16_t * n_lines_p)
+{
+ char * f_name = "textfile_sizes()";
+ int c = 0;
+ uint16_t c_count = 0;
+ uint16_t n_lines = 0;
+ uint16_t linemax = 0;
+ while (1)
+ {
+ c = try_fgetc(file, f_name);
+ if (EOF == c)
+ {
+ break;
+ }
+ c_count++;
+ if ('\n' == c)
+ {
+ if (c_count > linemax)
+ {
+ linemax = c_count;
+ }
+ c_count = 0;
+ if (n_lines_p)
+ {
+ n_lines++;
+ }
+ }
+ }
+ if (0 == linemax && 0 < c_count) /* Handle files that consist of only one */
+ { /* line / lack newline chars. */
+ linemax = c_count;
+ }
+
+ if (-1 == fseek(file, 0, SEEK_SET))
+ {
+ return 1;
+ }
+ * linemax_p = linemax;
+ if (n_lines_p)
+ {
+ * n_lines_p = n_lines;
+ }
+ return 0;