jounal_is_valid removed -- check errno
This commit is contained in:
parent
e9dcc1d3bc
commit
0039d6d297
|
@ -212,8 +212,7 @@ static int scan(struct flights *const f,
|
||||||
catch:
|
catch:
|
||||||
if(!errno) errno = EILSEQ;
|
if(!errno) errno = EILSEQ;
|
||||||
date32_to_string(date, &datestr);
|
date32_to_string(date, &datestr);
|
||||||
fprintf(stderr, "%s\n"
|
fprintf(stderr, "%s line %zu: %s.\n", datestr, line, why);
|
||||||
"%s line %zu: %s.\n", text, datestr, line, why);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/** Dynamic memory allocation for `f` will be zero, <fn:flights_is_valid> will
|
/** Dynamic memory allocation for `f` will be zero, <fn:flights_is_valid> will
|
||||||
|
|
|
@ -35,7 +35,7 @@ struct journal { struct day_tree days; struct text backing; };
|
||||||
struct journal_iterator { struct day_tree_iterator _; };
|
struct journal_iterator { struct day_tree_iterator _; };
|
||||||
struct journal journal(void);
|
struct journal journal(void);
|
||||||
void journal_(struct journal *);
|
void journal_(struct journal *);
|
||||||
//int journal_is_valid(const struct journal *);
|
/*int journal_is_valid(const struct journal *);*/
|
||||||
const char *journal_to_string(const struct journal *);
|
const char *journal_to_string(const struct journal *);
|
||||||
struct journal_iterator journal_iterator(struct journal *const j);
|
struct journal_iterator journal_iterator(struct journal *const j);
|
||||||
int journal_next(struct journal_iterator *, union date32 *, const char **);
|
int journal_next(struct journal_iterator *, union date32 *, const char **);
|
||||||
|
|
|
@ -102,8 +102,7 @@ static unsigned looks_like_day(const char *const a) {
|
||||||
#define PROTO
|
#define PROTO
|
||||||
#include "../src/journal.h" /* Just prototypes. */
|
#include "../src/journal.h" /* Just prototypes. */
|
||||||
|
|
||||||
/** Dynamic memory allocation for `j` will be zero, <fn:journal_is_valid> will
|
/** Erases memory allocation for `j`. */
|
||||||
be false. */
|
|
||||||
void journal_(struct journal *const j) {
|
void journal_(struct journal *const j) {
|
||||||
if(!j) return;
|
if(!j) return;
|
||||||
day_tree_(&j->days);
|
day_tree_(&j->days);
|
||||||
|
@ -176,8 +175,8 @@ struct journal journal(void) {
|
||||||
}
|
}
|
||||||
if(closedir(dir)) { dir = 0; goto catch; } dir = 0;
|
if(closedir(dir)) { dir = 0; goto catch; } dir = 0;
|
||||||
qsort(days.data, days.size, sizeof *days.data, &void_int_cmp);
|
qsort(days.data, days.size, sizeof *days.data, &void_int_cmp);
|
||||||
fprintf(stderr, "Days in <<%s>>: %s.\n",
|
/*fprintf(stderr, "Days in <<%s>>: %s.\n",
|
||||||
fn, int_array_to_string(&days));
|
fn, int_array_to_string(&days)); <- Too much spam. */
|
||||||
|
|
||||||
for(d = days.data, d_end = d + days.size; d < d_end; d++) {
|
for(d = days.data, d_end = d + days.size; d < d_end; d++) {
|
||||||
const union date32 d32 = { .year = (uint32_t)*y,
|
const union date32 d32 = { .year = (uint32_t)*y,
|
||||||
|
@ -216,7 +215,7 @@ struct journal journal(void) {
|
||||||
goto finally;
|
goto finally;
|
||||||
catch:
|
catch:
|
||||||
fprintf(stderr, "On date: %s/%d-%.2d-%.2d.\n",
|
fprintf(stderr, "On date: %s/%d-%.2d-%.2d.\n",
|
||||||
dir_journal, y ? *y : 0, m ? *m : 0, d ? *d : 0 );
|
dir_journal, y ? *y : 0, m ? *m : 0, d ? *d : 0);
|
||||||
if(intent) fprintf(stderr, "(%s)\n", intent);
|
if(intent) fprintf(stderr, "(%s)\n", intent);
|
||||||
recatch:
|
recatch:
|
||||||
journal_(&j);
|
journal_(&j);
|
||||||
|
@ -227,9 +226,9 @@ finally:
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return `j` read in some data? */
|
/** @return `j` read in some data? */
|
||||||
int journal_is_valid(const struct journal *const j) {
|
/*int journal_is_valid(const struct journal *const j) {
|
||||||
return j && j->days.root.node && j->backing.a.data;
|
return j && j->days.root.node && j->backing.a.data;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
/** @return `j` as a string. */
|
/** @return `j` as a string. */
|
||||||
const char *journal_to_string(const struct journal *const j)
|
const char *journal_to_string(const struct journal *const j)
|
||||||
|
|
|
@ -184,13 +184,15 @@ catch:
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
int success = EXIT_SUCCESS;
|
int success = EXIT_SUCCESS;
|
||||||
|
errno = 0;
|
||||||
struct journal j;
|
struct journal j;
|
||||||
struct journal_iterator it;
|
struct journal_iterator it;
|
||||||
struct kjv bible = kjv();
|
struct kjv bible = kjv();
|
||||||
|
if(errno) goto catch;
|
||||||
union date32 k;
|
union date32 k;
|
||||||
const char *v;
|
const char *v;
|
||||||
j = journal();
|
j = journal();
|
||||||
if(!journal_is_valid(&j)) goto catch;
|
if(errno) goto catch;
|
||||||
fprintf(stderr, "Journal: %s.\n", journal_to_string(&j));
|
fprintf(stderr, "Journal: %s.\n", journal_to_string(&j));
|
||||||
printf("set term postscript eps enhanced\n"
|
printf("set term postscript eps enhanced\n"
|
||||||
"set output \"kjv.eps\"\n"
|
"set output \"kjv.eps\"\n"
|
||||||
|
|
|
@ -134,8 +134,7 @@ static int scan(union date32 date, const char *const buffer,
|
||||||
catch:
|
catch:
|
||||||
if(!errno) errno = EILSEQ;
|
if(!errno) errno = EILSEQ;
|
||||||
date32_to_string(date, &datestr);
|
date32_to_string(date, &datestr);
|
||||||
fprintf(stderr, "%s\n"
|
fprintf(stderr, "%s line %zu: %s.\n", datestr, line, why);
|
||||||
"%s line %zu: %s.\n", buffer, datestr, line, why);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/** Dynamic memory allocation for `s` will be zero. */
|
/** Dynamic memory allocation for `s` will be zero. */
|
||||||
|
|
|
@ -3,11 +3,13 @@
|
||||||
#include <inttypes.h> /* C99 */
|
#include <inttypes.h> /* C99 */
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
|
errno = 0;
|
||||||
struct journal j = journal();
|
struct journal j = journal();
|
||||||
int success = EXIT_SUCCESS;
|
int success = EXIT_SUCCESS;
|
||||||
if(!journal_is_valid(&j)) goto catch;
|
if(errno) goto catch;
|
||||||
printf("Journal: %s.\n", journal_to_string(&j));
|
printf("Journal: %s.\n", journal_to_string(&j));
|
||||||
{
|
{
|
||||||
struct journal_iterator it = journal_iterator(&j);
|
struct journal_iterator it = journal_iterator(&j);
|
||||||
|
|
Loading…
Reference in New Issue