static void dpkg_options_load_dir(const char *prog, const struct cmdinfo *cmdinfos) { char *dirname; struct dirent **dlist; int dlist_n, i; dirname = str_fmt("%s/%s.cfg.d", CONFIGDIR, prog); dlist_n = scandir(dirname, &dlist, valid_config_filename, alphasort); if (dlist_n < 0) { if (errno == ENOENT) { free(dirname); return; } else ohshite(_("error opening configuration directory '%s'"), dirname); } for (i = 0; i < dlist_n; i++) { char *filename; filename = str_fmt("%s/%s", dirname, dlist[i]->d_name); dpkg_options_load_file(filename, cmdinfos); free(dlist[i]); free(filename); } free(dirname); free(dlist); }
char * Ext_File::Groupname (void) { if (extend == 1) { return (str_fmt (buffer, sizeof (buffer), "%s.*", pathname)); } else if (extend == 2) { return (str_fmt (buffer, sizeof (buffer), "%s.t*", pathname)); } else { return (pathname); } }
char * Ext_File::Extension (int ext_number) { buffer [0] = '\0'; if (extend && ext_number >= 0) { if (extend == 1) { str_fmt (buffer, sizeof (buffer), "%c%c", ('A' + (ext_number / 26)), ('A' + (ext_number % 26))); } else { str_fmt (buffer, sizeof (buffer), "t%c%c", ('A' + (ext_number / 26)), ('A' + (ext_number % 26))); } } return (buffer); }
PRAGMA_FORMAT_NONLITERAL_IGNORED_EXTERNAL void KlassInfoHisto::print_title(outputStream* st, bool csv_format, bool selected[], int width_table[], const char *name_table[]) { if (csv_format) { st->print("Index,Super"); for (int c=0; c<KlassSizeStats::_num_columns; c++) { if (selected[c]) {st->print(",%s", name_table[c]);} } st->print(",ClassName"); } else { st->print("Index Super"); for (int c=0; c<KlassSizeStats::_num_columns; c++) { PRAGMA_DIAG_PUSH PRAGMA_FORMAT_NONLITERAL_IGNORED_INTERNAL if (selected[c]) {st->print(str_fmt(width_table[c]), name_table[c]);} PRAGMA_DIAG_POP } st->print(" ClassName"); } if (is_selected("ClassLoader")) { st->print(",ClassLoader"); } st->cr(); }
/** * Generate the pathname for the destination binary package from control file. * * @return The pathname for the package being built. */ static char * gen_dest_pathname_from_pkg(const char *dir, struct pkginfo *pkg) { return str_fmt("%s/%s_%s_%s%s", dir, pkg->set->name, versiondescribe(&pkg->available.version, vdew_never), pkg->available.arch->name, DEBEXT); }
void req_broadcast(t_data *d, int fd, int fd_dir, char *cmd) { int i; char *str; (void)fd_dir; i = 0; while (i < d->maxfd && i < d->max + 1) { d->fd[i].broad = Xmalloc(sizeof(t_broad)); if (d->fd[i].type == FD_CLT && d->fd[i].status == CLT_IA && i != fd) { check_short_way(d, fd, i); str = str_fmt("message %d, %s\n", d->fd[i].broad->case_recep, erase_broad(cmd)); if (str) { printcs(d, i, str); free(str); } } free(d->fd[i].broad); ++i; } printcs(d, fd, "ok\n"); broad_grc(d, fd, cmd); }
bool Skim_Group::Skim_Filename (char *filename) { int i, num_field; bool binary_flag; Db_Field *fld; if (skim_file == NULL || skim_a == NULL || skim_b == NULL) return (false); //---- open the skim file ---- char buffer [FIELD_BUFFER]; str_fmt (buffer, sizeof (buffer), "Zone Skim File #%d", Group ()); skim_file->File_Type (buffer); skim_a->File_Type (buffer); skim_b->File_Type (buffer); skim_file->File_ID (str_fmt (buffer, sizeof (buffer), "Skim%d", Group ())); skim_a->File_ID (str_fmt (buffer, sizeof (buffer), "Skim%dA", Group ())); skim_b->File_ID (str_fmt (buffer, sizeof (buffer), "Skim%dB", Group ())); if (!skim_file->Open (filename)) return (false); if (!skim_a->Add_Field ("KEY", Db_Code::INTEGER, sizeof (int), 0, 0, true)) return (false); if (!skim_b->Add_Field ("KEY", Db_Code::INTEGER, sizeof (int), 0, 0, true)) return (false); num_field = skim_file->Num_Fields (); binary_flag = (skim_file->Record_Format () == Db_Code::BINARY); for (i=1; i <= num_field; i++) { if (i == skim_file->Origin_Field ()) continue; if (i == skim_file->Destination_Field ()) continue; if (i == skim_file->Period_Field ()) continue; fld = skim_file->Field (i); if (fld == NULL) continue; if (!str_cmp (fld->Name (), "NOTES")) continue; if (!skim_a->Add_Field (fld->Name (), fld->Type (), fld->Size (), fld->Decimal (), END_OF_RECORD, binary_flag)) return (false); if (!skim_b->Add_Field (fld->Name (), fld->Type (), fld->Size (), fld->Decimal (), END_OF_RECORD, binary_flag)) return (false); } dump_field = skim_a->Optional_Field ("TIME", "DRIVE", "TRANSIT", "WALK", "COST"); return (true); }
void dpkg_options_load(const char *prog, const struct cmdinfo *cmdinfos) { char *home, *file; dpkg_options_load_dir(prog, cmdinfos); file = str_fmt("%s/%s.cfg", CONFIGDIR, prog); dpkg_options_load_file(file, cmdinfos); free(file); home = getenv("HOME"); if (home != NULL) { file = str_fmt("%s/.%s.cfg", home, prog); dpkg_options_load_file(file, cmdinfos); free(file); } }
void Message_Service::Banner (FILE *file) { time_t ltime; int pad1, pad2; char buffer [FIELD_BUFFER]; char blank = ' '; char *bar = "********************************************"; if (file == NULL) file = stdout; fprintf (file, "\n\t%s", bar); fprintf (file, "\n\t|%42c|", blank); str_fmt (buffer, sizeof (buffer), "%s - Version %s", Program (), Version ()); pad1 = (int) (42 - strlen (buffer)); pad2 = pad1 - pad1 / 2; pad1 = pad1 / 2; fprintf (file, "\n\t|%*c%s%*c|", pad1, blank, buffer, pad2, blank); str_fmt (buffer, sizeof (buffer), "Copyright (c) %s", CopyRight ()); pad1 = (int) (42 - strlen (buffer)); pad2 = pad1 - pad1 / 2; pad1 = pad1 / 2; fprintf (file, "\n\t|%*c%s%*c|", pad1, blank, buffer, pad2, blank); ltime = StartTime (); str_cpy (buffer, sizeof (buffer), c_time (<ime)); pad1 = (int) (42 - strlen (buffer)); pad2 = pad1 - pad1 / 2; pad1 = pad1 / 2; fprintf (file, "\n\t|%*c%s%*c|", pad1, blank, buffer, pad2, blank); fprintf (file, "\n\t|%42c|", blank); fprintf (file, "\n\t%s\n", bar); fflush (file); }
DiurnalMatrix::DiurnalMatrix (void) : Execution_Service () { //---- set the program name, version numbers, and default title ---- Program ("DiurnalMatrix"); Version ("4.0.0"); Title ("Reformat Diurnal and Matrix File"); //---- add program specific keys to a null terminated array of strings ---- char *keys [] = { IN_DIURNAL_FILE, IN_DIURNAL_ZONE_FIELD, IN_DIURNAL_START_FIELD, IN_DIURNAL_END_FIELD, IN_DIURNAL_SHARE_FIELD, IN_MATRIX_FILE, IN_MATRIX_ORG_FIELD, IN_MATRIX_DES_FIELD, IN_MATRIX_TRIPS_FIELD, IN_MATRIX_MATCH_FIELD, INTERVAL_ROLLOVER, OUT_FILE_BASE_NAME, MAX_SHARE_COLS, NULL }; //---- pass the list of keys to the key processing methods ---- Key_List (keys); //---- initialize global variables ---- // file names input_matrix_name[0] = 0x00; input_diurnal_name[0] = 0x00; output_file_name[0] = 0x00; // maximum number of share columns in the resulting diurnal distribution file(s) max_col = 5; // start time distribution with this interval rollover = 0; // default values for field names in diurnal and matrix files str_fmt (diurnal_zone_field, sizeof(diurnal_zone_field), "ZONE"); str_fmt (diurnal_start_field, sizeof(diurnal_zone_field), "START"); str_fmt (diurnal_end_field, sizeof(diurnal_zone_field), "END"); str_fmt (diurnal_share_field, sizeof(diurnal_zone_field), "SHARE"); str_fmt (matrix_org_field, sizeof(diurnal_zone_field), "ORG"); str_fmt (matrix_des_field, sizeof(diurnal_zone_field), "DES"); str_fmt (matrix_trips_field, sizeof(diurnal_zone_field), "TRIPS"); str_fmt (matrix_match_field, sizeof(diurnal_zone_field), "ORG"); }
void ModeChoice::Write_Share_File (Travel_Leg &leg) { char buffer [FIELD_BUFFER]; share_file.Put_Field (1, leg.hhold); share_file.Put_Field (2, leg.person); share_file.Put_Field (3, leg.trip); share_file.Put_Field (4, leg.purpose); share_file.Put_Field (5, time_step.Format_Step (leg.start)); share_file.Put_Field (6, leg.origin); share_file.Put_Field (7, leg.org_zone); share_file.Put_Field (8, time_step.Format_Step (leg.end)); share_file.Put_Field (9, leg.destination); share_file.Put_Field (10, leg.des_zone); if (mode_flag) { Mode_Group *mode_ptr; for (mode_ptr = mode_group.First (); mode_ptr; mode_ptr = mode_group.Next ()) { if (mode_ptr->Mode () == leg.mode) { share_file.Put_Field (11, mode_ptr->Label ()); break; } } if (mode_ptr == NULL) { str_fmt (buffer, sizeof (buffer), "Mode #%d", leg.mode); share_file.Put_Field (11, buffer); } for (mode_ptr = mode_group.First (); mode_ptr; mode_ptr = mode_group.Next ()) { share_file.Put_Field (11 + mode_group.Record_Index (), mode_ptr->Share ()); } } else { str_fmt (buffer, sizeof (buffer), "Mode #%d", leg.mode); share_file.Put_Field (11, buffer); } if (!share_file.Write ()) { Error ("Writing %s", share_file.File_Type ()); } }
struct atomic_file * atomic_file_new(const char *filename, enum atomic_file_flags flags) { struct atomic_file *file; file = m_malloc(sizeof(*file)); file->flags = flags; file->fp = NULL; file->name = m_strdup(filename); file->name_new = str_fmt("%s%s", filename, ATOMIC_FILE_NEW_EXT); return file; }
void SmoothPlans::Change_Report (void) { int hour, time; double average; char buffer [20]; Period_Index *period_ptr; //---- print the report header ---- if (!Break_Check (32)) { Print (1); } Print (1, "Time Change Summary Report"); Print (1); Print (1, " ------ Trips ------- Average Minimum Maximum"); Print (1, " Hour Original Smoothed Change Change Change"); Print (1); for (hour=1; hour < 24; hour++) { period_ptr = period_index [hour]; Print (1, "%10.10s %10d %10d", time_step.Format_Step (hour * 3600), period_ptr->Original (), period_ptr->Smoothed ()); average = period_ptr->Average_Change (); if (time_step.Format () == Time_Step::HOURS) { if (average >= 0) { time = (int) (average + 0.5); } else { time = -((int) (-average + 0.5)); } Print (0, " %11.11s", time_step.Format_Duration (time)); } else { if (average >= 0) { time = (int) average; average = average - time; } else { time = -((int) (-average)); average = time - average; } str_fmt (buffer, sizeof (buffer), "%.1lf", average); Print (0, " %10.10s%s", time_step.Format_Duration (time), buffer+1); } Print (0, " %10.10s", time_step.Format_Duration (period_ptr->Min_Change ())); Print (0, " %10.10s", time_step.Format_Duration (period_ptr->Max_Change ())); } }
bool Ext_File::Filename (int ext_number) { Db_File::Filename (NULL); extension [0] = '\0'; if (extend) { if (ext_number < 0) { return (Status (EXTENSION)); } else { char name [FILE_NAME_SIZE]; str_fmt (extension, sizeof (extension), Extension (ext_number)); str_fmt (name, sizeof (name), "%s.%s", pathname, extension); return (Db_File::Filename (name)); } } else if (ext_number != 0) { return (Status (EXTENSION)); } else { return (Db_File::Filename (pathname)); } }
static void atomic_file_backup(struct atomic_file *file) { char *name_old; name_old = str_fmt("%s%s", file->name, ATOMIC_FILE_OLD_EXT); if (unlink(name_old) && errno != ENOENT) ohshite(_("error removing old backup file '%s'"), name_old); if (link(file->name, name_old) && errno != ENOENT) ohshite(_("error creating new backup file '%s'"), name_old); free(name_old); }
bool Ext_File::Filename (char *rootname, int ext_number) { extend = 0; if (pathname != NULL) { delete [] pathname; pathname = NULL; } extension [0] = '\0'; Db_File::Filename (NULL); if (rootname == NULL) return (false); int len = (int) strlen (rootname) + 1; pathname = new char [len]; if (pathname == NULL) return (Status (MEMORY)); str_cpy (pathname, len, rootname); char *str_ptr = strstr (pathname, ".*"); if (str_ptr != NULL) { extend = 1; *str_ptr = '\0'; } else { str_ptr = strstr (pathname, ".t*"); if (str_ptr != NULL) { extend = 2; *str_ptr = '\0'; } else { extend = 0; } } if (ext_number >= 0 && extend) { Extension (ext_number); extend = 0; len = (int) (strlen (pathname) + strlen (buffer) + 2); str_ptr = new char [len]; if (str_ptr == NULL) return (Status (MEMORY)); str_fmt (str_ptr, len, "%s.%s", pathname, buffer); delete [] pathname; pathname = str_ptr; } return (Filename (0)); }
char * Time_Range::Range_Label (int num, bool pad_flag) { char start [40], end [40]; Range_Data *range_ptr = (Range_Data *) Record (num); if (range_ptr == NULL) return (NULL); str_cpy (start, sizeof (start), Time_Label (range_ptr->Low (), pad_flag)); str_cpy (end, sizeof (end), Time_Label (range_ptr->High ()+1, pad_flag)); //---- set time string ---- str_fmt (buffer, sizeof (buffer), "%s_%s", start, end); return (buffer); }
int execbackend(const char *const *argv) { struct command cmd; command_init(&cmd, cipaction->arg_ptr, NULL); command_add_arg(&cmd, cipaction->arg_ptr); command_add_arg(&cmd, str_fmt("--%s", cipaction->olong)); /* Exlicitely separate arguments from options as any user-supplied * separator got stripped by the option parser */ command_add_arg(&cmd, "--"); command_add_argl(&cmd, (const char **)argv); command_exec(&cmd); }
static void check_writable_dir(struct file *f) { char *tmpname; int tmpfd; tmpname = str_fmt("%s%s", f->name, ".dpkg-divert.tmp"); tmpfd = creat(tmpname, 0600); if (tmpfd < 0) ohshite(_("error checking '%s'"), f->name); close(tmpfd); (void)unlink(tmpname); free(tmpname); }
bool Skim_Group::Time_Period_File (char *filename) { if (time_equiv != NULL) return (false); time_equiv = new Time_Equiv (); if (time_equiv == NULL) return (false); char buffer [FIELD_BUFFER]; str_fmt (buffer, sizeof (buffer), "Time Period Equivalence #%d", Group ()); time_equiv->File_Type (buffer); if (!time_equiv->Open (filename)) return (false); return (true); }
void req_pnw(t_data *d, int fd, int fd_dir, char *cmd) { char *res; (void)cmd; res = str_fmt("pnw %d %d %d %d %d %s\n", fd, d->fd[fd].pos.pos_x, d->fd[fd].pos.pos_y, d->fd[fd].pos.dir, d->fd[fd].lvl, d->fd[fd].team); if (res) { printcs(d, fd_dir, res); free(res); } }
static void control_treewalk_feed(const char *dir, int fd_out) { struct treeroot *tree; struct treenode *node; tree = treewalk_open(dir, TREEWALK_NONE, NULL); for (node = treewalk_node(tree); node; node = treewalk_next(tree)) { char *nodename; nodename = str_fmt("./%s", treenode_get_virtname(node)); if (fd_write(fd_out, nodename, strlen(nodename) + 1) < 0) ohshite(_("failed to write filename to tar pipe (%s)"), _("control member")); free(nodename); } treewalk_close(tree); }
static void file_treewalk_feed(const char *dir, int fd_out) { struct treeroot *tree; struct treenode *node; struct file_info *fi; struct file_info *symlist = NULL; struct file_info *symlist_end = NULL; tree = treewalk_open(dir, TREEWALK_NONE, NULL); for (node = treewalk_node(tree); node ; node = treewalk_next(tree)) { const char *virtname = treenode_get_virtname(node); char *nodename; if (strncmp(virtname, BUILDCONTROLDIR, strlen(BUILDCONTROLDIR)) == 0) continue; nodename = str_fmt("./%s", virtname); if (strchr(nodename, '\n')) ohshit(_("newline not allowed in pathname '%s'"), nodename); /* We need to reorder the files so we can make sure that symlinks * will not appear before their target. */ if (S_ISLNK(treenode_get_mode(node))) { fi = file_info_new(nodename); file_info_list_append(&symlist, &symlist_end, fi); } else { if (fd_write(fd_out, nodename, strlen(nodename) + 1) < 0) ohshite(_("failed to write filename to tar pipe (%s)"), _("data member")); } free(nodename); } treewalk_close(tree); for (fi = symlist; fi; fi = fi->next) if (fd_write(fd_out, fi->fn, strlen(fi->fn) + 1) < 0) ohshite(_("failed to write filename to tar pipe (%s)"), _("data member")); file_info_list_free(symlist); }
void KlassInfoHisto::print_title(outputStream* st, bool csv_format, bool selected[], int width_table[], const char *name_table[]) { if (csv_format) { st->print("Index,Super"); for (int c=0; c<KlassSizeStats::_num_columns; c++) { if (selected[c]) {st->print(",%s", name_table[c]);} } st->print(",ClassName"); } else { st->print("Index Super"); for (int c=0; c<KlassSizeStats::_num_columns; c++) { if (selected[c]) {st->print(str_fmt(width_table[c]), name_table[c]);} } st->print(" ClassName"); } if (is_selected("ClassLoader")) { st->print(",ClassLoader"); } st->cr(); }
/** * Check the control file. * * @param dir The directory from where to build the binary package. * @return The pkginfo struct from the parsed control file. */ static struct pkginfo * check_control_file(const char *ctrldir) { struct pkginfo *pkg; char *controlfile; controlfile = str_fmt("%s/%s", ctrldir, CONTROLFILE); parsedb(controlfile, pdb_parse_binary, &pkg); if (strspn(pkg->set->name, "abcdefghijklmnopqrstuvwxyz0123456789+-.") != strlen(pkg->set->name)) ohshit(_("package name has characters that aren't lowercase alphanums or '-+.'")); if (pkg->available.arch->type == DPKG_ARCH_NONE || pkg->available.arch->type == DPKG_ARCH_EMPTY) ohshit(_("package architecture is missing or empty")); if (pkg->priority == PKG_PRIO_OTHER) warning(_("'%s' contains user-defined Priority value '%s'"), controlfile, pkg->otherpriority); free(controlfile); return pkg; }
static void file_copy(const char *src, const char *dst) { struct dpkg_error err; char *tmp; int srcfd, dstfd; srcfd = open(src, O_RDONLY); if (srcfd < 0) ohshite(_("unable to open file '%s'"), src); tmp = str_fmt("%s%s", dst, ".dpkg-divert.tmp"); dstfd = creat(tmp, 0600); if (dstfd < 0) ohshite(_("unable to create file '%s'"), tmp); push_cleanup(cu_filename, ~ehflag_normaltidy, 1, tmp); if (fd_fd_copy(srcfd, dstfd, -1, &err) < 0) ohshit(_("cannot copy '%s' to '%s': %s"), src, tmp, err.str); close(srcfd); if (fsync(dstfd)) ohshite(_("unable to sync file '%s'"), tmp); if (close(dstfd)) ohshite(_("unable to close file '%s'"), tmp); file_copy_perms(src, tmp); if (rename(tmp, dst) != 0) ohshite(_("cannot rename '%s' to '%s'"), tmp, dst); free(tmp); pop_cleanup(ehflag_normaltidy); }
int do_raw_extract(const char *const *argv) { enum dpkg_tar_options data_options; const char *debar, *dir; char *control_dir; debar = *argv++; if (debar == NULL) badusage(_("--%s needs .deb filename and directory arguments"), cipaction->olong); else if (strcmp(debar, "-") == 0) badusage(_("--%s does not support (yet) reading the .deb from standard input"), cipaction->olong); dir = *argv++; if (dir == NULL) badusage(_("--%s needs a target directory.\n" "Perhaps you should be using dpkg --install ?"), cipaction->olong); else if (*argv) badusage(_("--%s takes at most two arguments (.deb and directory)"), cipaction->olong); control_dir = str_fmt("%s/%s", dir, EXTRACTCONTROLDIR); data_options = DPKG_TAR_EXTRACT | DPKG_TAR_PERMS; if (opt_verbose) data_options |= DPKG_TAR_LIST; extracthalf(debar, dir, data_options, 0); extracthalf(debar, control_dir, DPKG_TAR_EXTRACT, 1); free(control_dir); return 0; }
void ActivityPattern::Write_Count (void) { char buffer [STRING_BUFFER]; Survey_Person *person_ptr; Show_Message ("Writing %s -- Record", count_file.File_Type ()); Set_Progress (10000); for (person_ptr = survey_pop_data.First_Key (); person_ptr; person_ptr = survey_pop_data.Next_Key ()) { Show_Progress (); str_fmt (buffer, sizeof (buffer), "%d\t%d\t%d", person_ptr->Household (), person_ptr->Person (), person_ptr->Count ()); if (!count_file.Write (buffer)) { Error ("Writing %s", count_file.File_Type ()); } } End_Progress (); count_file.Close (); Print (2, "Number of %s Records = %d", count_file.File_Type (), Progress_Count ()); }
void DynusTNet::Program_Control (void) { int i, lvalue; char *str_ptr, buffer [STRING_BUFFER], project [STRING_BUFFER]; //---- create the network files ---- Demand_Service::Program_Control (); //---- get the time of day format ---- str_ptr = Get_Control_String (TIME_OF_DAY_FORMAT); if (str_ptr == NULL) { str_ptr = "24_HOUR_CLOCK"; } if (!time_range.Format (str_ptr)) { Error ("Time of Day Format %s was Unrecognized", str_ptr); } Print (2, "Time of Day Format = %s", str_ptr); //---- get the select time period ---- str_ptr = Get_Control_String (SELECT_TIME_PERIOD); if (str_ptr != NULL) { Print (2, "Select Time Period = %s", str_ptr); if (!time_range.Add_Ranges (str_ptr)) { File_Error ("Time Period Range", str_ptr); } } else { time_range.Add_Ranges ("0:00..24:00"); } //---- saturation flow rates ---- str_ptr = Get_Control_String (SATURATION_FLOW_RATES); i = 0; while (str_ptr != NULL && i < EXTERNAL) { str_ptr = Get_Integer (str_ptr, &lvalue); if (lvalue == 0) break; if (lvalue < 1000 || lvalue > 3000) { Error ("Saturation Flow Rate %d is Out of Range (1000..3000)", lvalue); } sat_flow [++i] = lvalue; } if (i) { for (; i <= EXTERNAL; i++) { sat_flow [i] = lvalue; } } Print (2, "Saturation Flow Rates = "); for (i=1; i <= EXTERNAL; i++) { Print (0, "%d ", sat_flow [i]); } //---- service flow rates ---- str_ptr = Get_Control_String (SERVICE_FLOW_RATES); i = 0; while (str_ptr != NULL && i < EXTERNAL) { str_ptr = Get_Integer (str_ptr, &lvalue); if (lvalue == 0) break; if (lvalue < 1000 || lvalue > 3000) { Error ("Service Flow Rate %d is Out of Range (1000..3000)", lvalue); } ser_flow [++i] = lvalue; } if (i) { for (; i <= EXTERNAL; i++) { ser_flow [i] = lvalue; } } Print (2, "Service Flow Rates = "); for (i=1; i <= EXTERNAL; i++) { Print (0, "%d ", ser_flow [i]); } //---- open the DynusT project name ---- str_ptr = Get_Control_String (DYNUST_PROJECT_NAME); if (str_ptr == NULL) { str_ptr = "ProjectName"; } Print (2, "DynusT Project Name = %s", str_ptr); str_cpy (project, sizeof (project), str_ptr); //---- open the DynusT network directory ---- str_ptr = Get_Control_String (DYNUST_NETWORK_DIRECTORY); if (str_ptr == NULL) goto control_error; str_cpy (net_dir, sizeof (net_dir), Project_Filename (str_ptr)); Print (2, "DynusT Network Directory = %s", net_dir); //---- project dws ---- dws_file.File_Type ("DynusT Project File"); str_fmt (buffer, sizeof (buffer), "%s/%s.dws", net_dir, project); dws_file.Create (buffer); fprintf (dws_file.File (), "VERSION = \"%3.1lf\"\nORIGIN = \"BOTTOM_LEFT\"\n", 1.3); dws_file.Close (); //---- xy.dat ---- xy_file.File_Type ("DynusT Node Coordinate File"); str_fmt (buffer, sizeof (buffer), "%s/xy.dat", net_dir); xy_file.Create (buffer); //---- network.dat ---- net_file.File_Type ("DynusT Network File"); str_fmt (buffer, sizeof (buffer), "%s/network.dat", net_dir); net_file.Create (buffer); if (Network_File_Flag (SHAPE)) { //---- linkxy.dat ---- shp_file.File_Type ("DynusT Link Coordinate File"); str_fmt (buffer, sizeof (buffer), "%s/linkxy.dat", net_dir); shp_file.Create (buffer); } //---- linkname.dat ---- name_file.File_Type ("DynusT Link Name File"); str_fmt (buffer, sizeof (buffer), "%s/linkname.dat", net_dir); name_file.Create (buffer); //---- movement.dat ---- move_file.File_Type ("DynusT Movement File"); str_fmt (buffer, sizeof (buffer), "%s/movement.dat", net_dir); move_file.Create (buffer); //---- control.dat ---- ctl_file.File_Type ("DynusT Control File"); str_fmt (buffer, sizeof (buffer), "%s/control.dat", net_dir); ctl_file.Create (buffer); //---- origin.dat ---- org_file.File_Type ("DynusT Generation Link File"); str_fmt (buffer, sizeof (buffer), "%s/origin.dat", net_dir); org_file.Create (buffer); //---- destination.dat ---- des_file.File_Type ("DynusT Destination File"); str_fmt (buffer, sizeof (buffer), "%s/destination.dat", net_dir); des_file.Create (buffer); //---- bus.dat ---- bus_file.File_Type ("DynusT Bus File"); str_fmt (buffer, sizeof (buffer), "%s/bus.dat", net_dir); bus_file.Create (buffer); //---- GradeLengthPCE.dat ---- pce_file.File_Type ("DynusT Grade Length PCE File"); str_fmt (buffer, sizeof (buffer), "%s/GradeLengthPCE.dat", net_dir); pce_file.Create (buffer); //---- leftcap.dat ---- left_file.File_Type ("DynusT Left Capacity File"); str_fmt (buffer, sizeof (buffer), "%s/leftcap.dat", net_dir); left_file.Create (buffer); //---- output_option.dat ---- out_file.File_Type ("DynusT Output Option File"); str_fmt (buffer, sizeof (buffer), "%s/output_option.dat", net_dir); out_file.Create (buffer); //---- ramp.dat ---- ramp_file.File_Type ("DynusT Ramp File"); str_fmt (buffer, sizeof (buffer), "%s/ramp.dat", net_dir); ramp_file.Create (buffer); //---- StopCap2Way.dat ---- cap2_file.File_Type ("DynusT Stop Capacity 2 Way File"); str_fmt (buffer, sizeof (buffer), "%s/StopCap2Way.dat", net_dir); cap2_file.Create (buffer); //---- StopCap4Way.dat ---- cap4_file.File_Type ("DynusT Stop Capacity 4 Way File"); str_fmt (buffer, sizeof (buffer), "%s/StopCap4Way.dat", net_dir); cap4_file.Create (buffer); //---- superzone.dat ---- super_file.File_Type ("DynusT SuperZone File"); str_fmt (buffer, sizeof (buffer), "%s/superzone.dat", net_dir); super_file.Create (buffer); //---- TrafficFlowModel.dat ---- model_file.File_Type ("DynusT Traffic Flow Model File"); str_fmt (buffer, sizeof (buffer), "%s/TrafficFlowModel.dat", net_dir); model_file.Create (buffer); //---- vms.dat ---- vms_file.File_Type ("DynusT VMS File"); str_fmt (buffer, sizeof (buffer), "%s/vms.dat", net_dir); vms_file.Create (buffer); //---- yield.dat ---- yield_file.File_Type ("DynusT Yield Capacity File"); str_fmt (buffer, sizeof (buffer), "%s/YieldCap.dat", net_dir); yield_file.Create (buffer); //---- zone.dat ---- zone_file.File_Type ("DynusT Zone File"); str_fmt (buffer, sizeof (buffer), "%s/zone.dat", net_dir); zone_file.Create (buffer); //---- demand.dat ---- dem_file.File_Type ("DynusT Demand File"); str_fmt (buffer, sizeof (buffer), "%s/Demand.dat", net_dir); dem_file.Create (buffer); //---- demand_truck.dat ---- trk_file.File_Type ("DynusT Demand Truck File"); str_fmt (buffer, sizeof (buffer), "%s/demand_truck.dat", net_dir); trk_file.Create (buffer); //---- demand_hov.dat ---- hov_file.File_Type ("DynusT Demand HOV File"); str_fmt (buffer, sizeof (buffer), "%s/demand_HOV.dat", net_dir); hov_file.Create (buffer); //---- zone_map.dat ---- zmap_file.File_Type ("Zone Number Equivalence File"); str_fmt (buffer, sizeof (buffer), "%s/zone_map.dat", net_dir); zmap_file.Create (buffer); return; //---- error message ---- control_error: Error ("Missing Control Key = %s", Current_Key ()); }
void ZoneData::Program_Control (void) { int i, size, num, decimal, existing; char *str_ptr, *format_ptr, name [FIELD_BUFFER], buffer [FIELD_BUFFER]; Db_Code::Field_Type type; Db_Header *file; //---- open network files ---- Network_Service::Program_Control (); input_file = (Zone_File *) Network_Db_File (ZONE); input_file->File_ID ("In"); output_file = (Zone_File *) Network_Db_File (NEW_ZONE); output_file->File_ID ("Out"); //---- copy existing fields ---- str_ptr = Get_Control_String (COPY_EXISTING_FIELDS); if (str_ptr != NULL) { Print (2, "Copy Existing Fields = %s", str_ptr); copy_flag = Get_Control_Flag (COPY_EXISTING_FIELDS); if (copy_flag) { output_file->Clear_Fields (); output_file->Replicate_Fields (input_file, false); } } //---- get the new zone fields ---- num = Highest_Control_Group (NEW_ZONE_FIELD_x, 0); if (num == 0) { if (Get_Control_String (NEW_ZONE_FIELD) != NULL) { num = 1; } } else { num++; } if (num == 0) { if (!copy_flag) { Warning ("No New Zone Fields"); } } else { Print (1); for (i=0; i < num; i++) { if (i == 0) { str_ptr = Get_Control_String (NEW_ZONE_FIELD); } else { str_ptr = Get_Control_String (NEW_ZONE_FIELD_x, i); } if (str_ptr == NULL) continue; if (i == 0) { Print (1, "New Zone Field = %s", str_ptr); } else { Print (1, "New Zone Field #%d = %s", i, str_ptr); } str_ptr = Get_Token (str_ptr, name, sizeof (name)); if (name [0] == '\0') goto data_error; existing = output_file->Field_Number (name); if (existing != 0) goto field_error; str_ptr = Get_Token (str_ptr, buffer, sizeof (buffer)); if (buffer [0] == '\0' || buffer [0] == 'I') { type = INTEGER; } else if (buffer [0] == 'R' || buffer [0] == 'D') { type = DOUBLE; } else if (buffer [0] == 'S' || buffer [0] == 'C') { type = STRING; } else { goto data_error; } str_ptr = Get_Token (str_ptr, buffer); if (buffer [0] == '\0') { size = 10; if (type == DOUBLE) { decimal = 2; } else { decimal = 0; } } else { size = atoi (buffer); if (type == DOUBLE) { str_ptr = strchr (buffer, '.'); if (str_ptr != NULL) { decimal = atoi (str_ptr+1); } else { decimal = 2; } } else { decimal = 0; } } output_file->Add_Field (name, type, size, decimal); } } if (copy_flag && output_file->Notes_Flag ()) { if (output_file->Field_Number ("NOTES") == 0) { output_file->Add_Field ("NOTES", STRING, FIELD_BUFFER); } } output_file->Write_Header (); //---- check for data files ---- num_data_files = Highest_Control_Group (DATA_FILE_x, 0); if (num_data_files == 0) { if (Get_Control_String (DATA_FILE) != NULL) { num_data_files = 1; } } else { num_data_files++; } if (num_data_files > 0) { data_flag = true; } //---- check for polygon files ---- num_polygons = Highest_Control_Group (BOUNDARY_POLYGON_x, 0); if (num_polygons == 0) { if (Get_Control_String (BOUNDARY_POLYGON) != NULL) { num_polygons = 1; } } else { num_polygons++; } if (num_polygons > 0) { polygon_flag = true; } //---- read conversion script ---- str_ptr = Get_Control_String (CONVERSION_SCRIPT); if (str_ptr == NULL) { if (data_flag || polygon_flag) { Error ("A Convertion Script is needed for Data Processing"); } } else { script_flag = true; Print (1); program_file.File_Type ("Conversion Script"); program_file.Open (Project_Filename (str_ptr)); Print (1); } //---- read data files ---- if (data_flag) { //---- allocate data files ---- data_files = new Db_Header * [num_data_files]; data_field = new int [num_data_files]; zone_field = new int [num_data_files]; if (data_files == NULL || data_field == NULL || zone_field == NULL) { Error ("Insufficient Memory for %d Data Files", num_data_files); } memset (data_files, '\0', num_data_files * sizeof (Db_Header *)); memset (data_field, '\0', num_data_files * sizeof (int)); memset (zone_field, '\0', num_data_files * sizeof (int)); //---- open each file ---- for (i=0; i < num_data_files; i++) { if (i == 0) { str_ptr = Get_Control_String (DATA_FILE); } else { str_ptr = Get_Control_String (DATA_FILE_x, i); } if (str_ptr == NULL) continue; //---- create a header file and file labels ---- Print (1); data_files [i] = file = new Db_Header (); if (i == 0) { file->File_Type ("Data File"); file->File_ID ("Data"); format_ptr = Get_Control_String (DATA_FORMAT); } else { str_fmt (buffer, sizeof (buffer), "Data File #%d", i); file->File_Type (buffer); str_fmt (buffer, sizeof (buffer), "Data%d", i); file->File_ID (buffer); format_ptr = Get_Control_String (DATA_FORMAT_x, i); } //---- open the file ---- if (format_ptr != NULL) { file->Dbase_Format (format_ptr); } file->Open (Project_Filename (str_ptr)); //---- find the data join field ---- if (i == 0) { str_ptr = Get_Control_String (DATA_JOIN_FIELD); } else { str_ptr = Get_Control_String (DATA_JOIN_FIELD_x, i); } if (str_ptr == NULL) goto control_error; data_field [i] = file->Field_Number (str_ptr); if (data_field [i] == 0) { Error ("Data Join Field %s was Not Found", str_ptr); } if (i == 0) { Print (1, "Data Join Field = %s, Number = %d", str_ptr, data_field [i]); } else { Print (1, "Data Join Field #%d = %s, Number = %d", i, str_ptr, data_field [i]); } //---- find the zone join field ---- if (i == 0) { str_ptr = Get_Control_String (ZONE_JOIN_FIELD); } else { str_ptr = Get_Control_String (ZONE_JOIN_FIELD_x, i); } if (str_ptr == NULL) goto control_error; zone_field [i] = input_file->Field_Number (str_ptr); if (zone_field [i] == 0) { Error ("Zone Join Field %s was Not Found", str_ptr); } if (i == 0) { Print (1, "Zone Join Field = %s, Number = %d", str_ptr, zone_field [i]); } else { Print (1, "Zone Join Field #%d = %s, Number = %d", i, str_ptr, zone_field [i]); } } } //---- read the boundary polygons ---- if (polygon_flag) { Arcview_File *poly_file; projection.Read_Control (); //---- allocate data files ---- polygon_files = new Arcview_File * [num_polygons]; polygons = new Index_Array * [num_polygons]; polygon_db = new Db_Index_Array * [num_polygons]; if (polygon_files == NULL || polygons == NULL || polygon_db == NULL) { Error ("Insufficient Memory for %d Polygon Files", num_polygons); } memset (polygon_files, '\0', num_polygons * sizeof (Arcview_File *)); memset (polygons, '\0', num_polygons * sizeof (Index_Array *)); memset (polygon_db, '\0', num_polygons * sizeof (Db_Index_Array *)); //---- open each file ---- for (i=0; i < num_polygons; i++) { if (i == 0) { str_ptr = Get_Control_String (BOUNDARY_POLYGON); } else { str_ptr = Get_Control_String (BOUNDARY_POLYGON_x, i); } if (str_ptr == NULL) continue; //---- open the file ---- polygon_files [i] = poly_file = new Arcview_File (); polygons [i] = new Index_Array (sizeof (Boundary)); poly_file->Set_Projection (projection.Input_Projection (), projection.Output_Projection ()); Print (1); if (i == 0) { poly_file->File_Type ("Boundary Polygon File"); poly_file->File_ID ("Polygon"); } else { str_fmt (buffer, sizeof (buffer), "Boundary Polygon File #%d", i); poly_file->File_Type (buffer); str_fmt (buffer, sizeof (buffer), "Polygon%d", i); poly_file->File_ID (buffer); } poly_file->Open (Project_Filename (str_ptr)); } } Show_Message (1); return; control_error: Error ("Missing Control Key = %s", Current_Key ()); data_error: Error ("New Zone Field %d is Improperly Specified", i); field_error: Error ("New Zone Field %s already exists as Field %d", name, existing); }