void tzcheck_init(tzcheck_t *tzc) { bzero(tzc, sizeof (*tzc)); avl_create(&tzc->tzc_zoneinfo_manifest, tzent_comparator, sizeof (tzent_t), offsetof(tzent_t, tze_node)); avl_create(&tzc->tzc_zoneinfo_proto, tzent_comparator, sizeof (tzent_t), offsetof(tzent_t, tze_node)); if (custr_alloc(&tzc->tzc_prefix) != 0 || strpath_append(tzc->tzc_prefix, cm_pdir) != 0 || custr_appendc(tzc->tzc_prefix, '/') != 0) { err(1, "tzc_prefix setup"); } }
int split_on(const char *line, char delim, strlist_t *sl) { custr_t *cu = NULL; int error = 0; const char *c = line; if (custr_alloc(&cu) != 0) { error = errno; goto out; } for (;;) { char cc = *c++; if (cc == '\0') { if (custr_len(cu) > 0 && strlist_set_tail(sl, custr_cstr(cu)) != 0) { error = errno; } goto out; } else if (cc == delim) { if (strlist_set_tail(sl, custr_cstr(cu)) != 0) { error = errno; goto out; } custr_reset(cu); } else { if (custr_appendc(cu, cc) != 0) { error = errno; goto out; } } } out: custr_free(cu); errno = error; return (error == 0 ? 0 : -1); }
int main(int argc, char **argv) { int optc; int optC = 0; while ((optc = getopt(argc, argv, "DdfCs:c:")) != EOF) { switch (optc) { case 'd': test_set_debug(); break; case 'f': test_set_force(); break; case 'D': test_set_debug(); extra_debug++; break; case 'c': compilation = optarg; break; case 'C': optC++; break; case 's': sym = optarg; break; default: (void) fprintf(stderr, "Usage: %s [-df]\n", argv[0]); exit(1); } } if (test_load_config(NULL, compilation, "env", do_env, "env_group", do_env_group, NULL) < 0) { exit(1); } while (optind < argc) { if (test_load_config(NULL, argv[optind++], "type", do_type, "value", do_value, "define", do_define, "func", do_func, NULL) < 0) { exit(1); } } if (atexit(cleanup) != 0) { perror("atexit"); exit(1); } if (custr_alloc(&st_custr) == -1) { perror("custr"); exit(1); } if (mkworkdir() < 0) { perror("mkdir"); exit(1); } find_compiler(); if (!optC) test_compile(); exit(0); }
int parse_line(const char *line, strlist_t *sl) { custr_t *cu = NULL; state_t state = ST_WHITESPACE; const char *c = line; int error = 0; if (custr_alloc(&cu) != 0) { error = errno; goto out; } for (;;) { char cc = *c; lextype_t lextype; /* * Determine which class of character this is: */ switch (cc) { case '\0': case '#': case '\n': case '\r': lextype = LEX_ENDL; break; case ' ': case '\t': lextype = LEX_WHITESPACE; break; default: lextype = LEX_OTHER; break; } /* * Determine what to do with this character based on the class * and our current state: */ switch (state) { case ST_WHITESPACE: { switch (lextype) { case LEX_ENDL: goto out; case LEX_WHITESPACE: c++; break; case LEX_OTHER: state = ST_TOKEN; break; default: (void) printf("ST_WHITESPACE: unknown " "lextype: %d\n", lextype); abort(); } break; } case ST_TOKEN: { switch (lextype) { case LEX_ENDL: if (strlist_set_tail(sl, custr_cstr(cu)) != 0) { error = errno; goto out; } goto out; case LEX_WHITESPACE: if (strlist_set_tail(sl, custr_cstr(cu)) != 0) { error = errno; goto out; } custr_reset(cu); state = ST_WHITESPACE; break; case LEX_OTHER: if (custr_appendc(cu, cc) != 0) { error = errno; goto out; } c++; break; default: (void) printf("ST_TOKEN: unknown lextype: %d\n", lextype); abort(); } break; } default: (void) printf("unknown state: %d\n", state); abort(); } } out: custr_free(cu); errno = error; return (error == 0 ? 0 : -1); }