NEOERR* ltpl_parse_dir(char *dir, HASH *outhash) { struct dirent **eps = NULL; int n; NEOERR *err; if (!dir) return nerr_raise(NERR_ASSERT, "can't read null directory"); HASH *dbh, *evth; void *lib = dlopen(NULL, RTLD_NOW|RTLD_GLOBAL); if (!lib) return nerr_raise(NERR_SYSTEM, "dlopen %s", dlerror()); err = ldb_init(&dbh); if (err != STATUS_OK) return nerr_pass(err); err = levt_init(&evth); if (err != STATUS_OK) return nerr_pass(err); n = scandir(dir, &eps, ltpl_config, alphasort); for (int i = 0; i < n; i++) { mtc_dbg("parse file %s", eps[i]->d_name); err = ltpl_parse_file(dbh, evth, lib, dir, eps[i]->d_name, outhash); TRACE_NOK(err); free(eps[i]); } ldb_destroy(dbh); levt_destroy(evth); dlclose(lib); if (n > 0) free(eps); else mtc_warn("no .hdf file found in %s", dir); return STATUS_OK; }
int main(int argc, char *argv[]) { HASH *tplh = NULL, *dbh = NULL; NEOERR *err; int c, bid = 0, indexid = -1, pgtt; bool dorecurse = false; mtc_init(TC_ROOT"blg"); err = mconfig_parse_file(SITE_CONFIG, &g_cfg); DIE_NOK_MTL(err); while ( (c=getopt(argc, argv, "b:i:r")) != -1 ) { switch(c) { case 'b': bid = atoi(optarg); break; case 'i': indexid = atoi(optarg); break; case 'r': dorecurse = true; break; default: useage(argv[0]); } } err = ldb_init(&dbh); DIE_NOK_MTL(err); err = hash_init(&tplh, hash_str_hash, hash_str_comp); DIE_NOK_MTL(err); err = ltpl_parse_file(dbh, NULL, PATH_PAGER, "blog.hdf", tplh); DIE_NOK_MTL(err); if (indexid >= 0) { err = rend_blog_index(dbh, tplh, indexid, &pgtt); TRACE_NOK(err); if (indexid > 0 && pgtt > indexid) pgtt = indexid; if (dorecurse) { while (pgtt-- > 0) { err = rend_blog_index(dbh, tplh, pgtt, NULL); TRACE_NOK(err); } } } if (bid > 0) { if (bid > 1) rend_blog(dbh, tplh, bid-1); rend_blog(dbh, tplh, bid); rend_blog(dbh, tplh, bid+1); } ldb_destroy(dbh); ltpl_destroy(tplh); mconfig_cleanup(&g_cfg); return 0; }