int main(int argc, char *argv[]) { NEOERR *err; HDF *hdf, *h2; err = hdf_init(&hdf); if (err != STATUS_OK) { nerr_log_error(err); return -1; } err = hdf_set_value(hdf, "CGI.Foo", "Bar"); if (err) { nerr_log_error(err); return -1; } err = hdf_set_value(hdf, "CGI.Foo", "Baz"); if (err) { nerr_log_error(err); return -1; } h2 = hdf_get_obj(hdf, "CGI"); err = hdf_set_value(h2, "Foo", "Bang"); hdf_dump(hdf, NULL); hdf_destroy(&hdf); return 0; }
void savesrc(char* templatedir, char* csfname, char* outfname, HDF* hdf) { CSPARSE* parse; NEOERR* err; FILE* fp; nerr_init(); chdir(templatedir); printf("reading %s ... ", csfname); err = cs_init(&parse, hdf); if( nerr_match(err, NERR_PASS) ) { printf("NG\n"); nerr_log_error(err); exit(41); } err = cs_parse_file(parse, csfname); if( nerr_match(err, NERR_PASS) ) { printf("NG\n"); nerr_log_error(err); exit(42); } printf("OK\n"); chdir(boot_path); chdir(CODEGEN_DIRNAME); printf("writing %s ... ", outfname); fp = fopen(outfname, "w"); if( fp != NULL ) { err = cs_render(parse, (void*)fp, render); fclose(fp); if( nerr_match(err, NERR_PASS) ) { printf("NG\n"); exit(43); } printf("OK\n"); }else{ printf("can't open file"); } cs_destroy(&parse); }
int process_template(HDF *hdf, char *infile, char *outfile) { int ret = 0; FILE *outfh = NULL; NEOERR *err; CSPARSE *parse = NULL; if (!make_dirs(outfile)) { ret = -1; } else { if ((outfh = fopen(outfile, "w")) == NULL) { perror("fopen"); ret = -2; } else { err = cs_init(&parse, hdf); if (err != STATUS_OK) { nerr_log_error(err); ret = -5; } else { err = cs_parse_file(parse, infile); if (err != STATUS_OK) { nerr_log_error(err); ret = -6; } err = cs_render(parse, outfh, csoutfunc); if (err != STATUS_OK) { nerr_log_error(err); ret = -7; } cs_destroy(&parse); } fclose(outfh); } } return ret; }
int getpwentries(HDF *hdf) { int ret = 0; NEOERR *err = NULL; struct passwd pw, *pwp; char buf[BUFLEN]; setpwent(); while (1) { if (getpwent_r(&pw, buf, BUFLEN, &pwp)) break; err = hdf_set_valuef(hdf, "system.passwd.%s.uid=%d", pwp->pw_name, pwp->pw_uid); err = hdf_set_valuef(hdf, "system.passwd.%s.gid=%d", pwp->pw_name, pwp->pw_gid); err = hdf_set_valuef(hdf, "system.passwd.%s.gecos=%s", pwp->pw_name, pwp->pw_gecos); err = hdf_set_valuef(hdf, "system.passwd.%s.dir=%s", pwp->pw_name, pwp->pw_dir); err = hdf_set_valuef(hdf, "system.passwd.%s.shell=%s", pwp->pw_name, pwp->pw_shell); if (err != STATUS_OK) { nerr_log_error(err); ret -1; } } endpwent(); return ret; }
int main(int argc, char **argv) { char *path; ULIST *files = NULL; char *filename; NEOERR *err; int x; if (argc > 1) path = argv[1]; else path = "."; ne_warn("Testing ne_listdir()"); err = ne_listdir(path, &files); if (err) { nerr_log_error(err); return -1; } for (x = 0; x < uListLength(files); x++) { err = uListGet(files, x, (void *)&filename); printf("%s\n", filename); } uListDestroy(&files, ULIST_FREE); ne_warn("Testing ne_listdir_match() with *.c"); err = ne_listdir_match(path, &files, "*.c"); if (err) { nerr_log_error(err); return -1; } for (x = 0; x < uListLength(files); x++) { err = uListGet(files, x, (void *)&filename); printf("%s\n", filename); } uListDestroy(&files, ULIST_FREE); return 0; }
void formatter_kml_split_output(formatter_split_t *obj, char *filename) { FILE *fp = fopen(filename, "w"); CSPARSE *csparse; HDF *hdf; NEOERR *err; int stage = 0; if ((err = hdf_init(&hdf)) != STATUS_OK) { goto error; } coordinate_subset_t *subset = obj->set->first_subset; int16_t i = 0; while (subset) { _cs_set_valuef(hdf, "tracks.%d.colour=%s", i, kml_colours[i % 9]); coordinate_t *coordinate = subset->first; int16_t j = 0; while (coordinate && coordinate != subset->last) { _cs_set_valuef(hdf, "tracks.%d.points.%d.lng=%f", i, j, coordinate->lng); _cs_set_valuef(hdf, "tracks.%d.points.%d.lat=%f", i, j, coordinate->lat); _cs_set_valuef(hdf, "tracks.%d.points.%d.ele=%d", i, j, coordinate->ele); _cs_set_valuef(hdf, "tracks.%d.points.%d.time=%f", i, j, coordinate->timestamp); coordinate = coordinate->next; j++; } subset = subset->next; i++; } if ((err = cs_init(&csparse, hdf)) != STATUS_OK || (err = cs_parse_file(csparse, "formatter/templates/flight.split.kml.cs.xml")) != STATUS_OK || (err = cs_render(csparse, fp, cs_fwrite)) != STATUS_OK) { goto error; } goto end; error: nerr_log_error(err); goto end; end: hdf_destroy(&hdf); cs_destroy(&csparse); fclose(fp); }
void ewf_request_init(ewf_request_t *request) { NEOERR *err = NULL; /* fill cgi struct */ err = cgi_init(&cgi, NULL); if (err != NULL) { #ifdef DEBUG cgi_neo_error(cgi, err); #endif nerr_log_error(err); nerr_ignore(&err); } request->type = ewf_request_type(); request->uri = hdf_get_value(cgi->hdf, "CGI.RequestURI", "/"); }
int main(int argc, char *argv[]) { NEOERR *err; HDF *hdf; double tstart = 0; err = hdf_init(&hdf); if (err != STATUS_OK) { nerr_log_error(err); return -1; } tstart = ne_timef(); TestSort(hdf); ne_warn("sort took %5.5fs", ne_timef() - tstart); hdf_dump(hdf, NULL); hdf_destroy(&hdf); return 0; }
int main(int argc, char **argv, char **envp) { NEOERR *err; CGI *cgi; char *cs_file; char hdf_file[_POSIX_PATH_MAX]; char *p; /* CGI works by passing information from the server to the CGI program via * environment variables and stdin. cgi_debug_init looks for a file as the * first argument, and loads it. That file contains key=value pairs which * cgi_debug_init will load into the environment, allowing you to test your * program via the command line. */ cgi_debug_init(argc, argv); /* The ClearSilver cgi toolkit accesses the CGI environment through a * wrapper. This allows the program to be used in other environments and * fake the CGI environment, such as FastCGI, mod_python, PyApache, or even * just from Python to access the python objects instead of the libc API. * cgiwrap_init_std just sets up for the default CGI environment using the * libc api. */ cgiwrap_init_std(argc, argv, envp); /* cgi_init creates a CGI struct, and parses the CGI environment variables. * It creates an HDF structure as well. */ err = cgi_init(&cgi, NULL); if (err != STATUS_OK) { /* cgi_neo_error renders a NEOERR as an error CGI result */ cgi_neo_error(cgi, err); /* nerr_log_error logs the error to stderr and cleans up */ nerr_log_error(err); return -1; } /* CGI.PathTranslated is a CGI env var which maps the URL with the * DocumentRoot to give you the location of the referenced file on disk */ cs_file = hdf_get_value(cgi->hdf, "CGI.PathTranslated", NULL); if (cs_file == NULL) { /* cgi_error returns a simple error page */ cgi_error(cgi, "No PATH_TRANSLATED var"); return -1; } /* The hdf.loadpaths variables specify where HDF and ClearSilver look for * files on the file system. We start setting that up here based on * the directory of the file referenced */ p = strrchr (cs_file, '/'); if (p) { *p = '\0'; err = hdf_set_value(cgi->hdf, "hdf.loadpaths.0", cs_file); chdir(cs_file); *p = '/'; if (err) { cgi_neo_error(cgi, err); nerr_log_error(err); return -1; } } /* Next, we look for a shared HDF static dataset in common.hdf */ err = hdf_read_file(cgi->hdf, "common.hdf"); if (err && !nerr_handle(&err, NERR_NOT_FOUND)) { cgi_neo_error(cgi, err); nerr_log_error(err); return -1; } /* Next, we look for an HDF file for this specific page. We first look * for passedfile.html.hdf, then we check for a file by removing an extension * from the file, so something like passedfile.html we'll look for * passedfile.hdf */ snprintf (hdf_file, sizeof(hdf_file), "%s.hdf", cs_file); err = hdf_read_file (cgi->hdf, hdf_file); if (err && !nerr_handle(&err, NERR_NOT_FOUND)) { cgi_neo_error(cgi, err); nerr_log_error(err); return -1; } p = strrchr (cs_file, '.'); if (p) { *p = '\0'; snprintf (hdf_file, sizeof(hdf_file), "%s.hdf", cs_file); *p = '.'; err = hdf_read_file (cgi->hdf, hdf_file); if (err && !nerr_handle(&err, NERR_NOT_FOUND)) { cgi_neo_error(cgi, err); nerr_log_error(err); return -1; } } /* Lastly, we need to render a template. The template is either the * file that was passed to us, or its specificed by CGI.StaticContent * in one of the HDF files we loaded above. */ cs_file = hdf_get_value (cgi->hdf, "CGI.StaticContent", cs_file); err = cgi_display (cgi, cs_file); if (err != STATUS_OK) { cgi_neo_error(cgi, err); nerr_log_error(err); return -1; } return 0; }