void set_proposal_pop(proposal_info_type *info) { char buf[100]; size_t rcv_cnt; date_type sdate; date_type edate; int ret_code; while (1) { print_str("Enter the program start date (MM/DD/YYYY): "); rcv_cnt=getnstr(buf, sizeof(buf)); ret_code=strtodate(buf, &sdate); if (ret_code==-1) { print_str("Invalid date format\n"); continue; } else if (ret_code==-2) { print_str("Invalid date entered\n"); continue; } else if (sdate.year < FIRST_YEAR || sdate.year > FIRST_YEAR + PROPOSAL_YEARS) { print_str("Valid start dates must be in the years "); print_int(FIRST_YEAR, 0); print_str(" through "); print_int(FIRST_YEAR+PROPOSAL_YEARS, 0); print_str("\n\n"); continue; } else break; } // while info->start_date=sdate; while (1) { print_str("Enter the program end date (MM/DD/YYYY): "); rcv_cnt=getnstr(buf, sizeof(buf)); ret_code=strtodate(buf, &edate); if (ret_code==-1) { print_str("Invalid date format\n"); continue; } else if (ret_code==-2) { print_str("Invalid date entered\n"); continue; } else if (edate.year < FIRST_YEAR || edate.year > FIRST_YEAR + PROPOSAL_YEARS) { print_str("Valid end dates must be in the years "); print_int(FIRST_YEAR, 0); print_str(" through "); print_int(FIRST_YEAR+PROPOSAL_YEARS, 0); print_str("\n\n"); continue; } else if (edate.year > sdate.year) break; else if (edate.year < sdate.year) { print_str("End date must be after start date\n\n"); continue; } else if (edate.month > sdate.month) break; else if (edate.month < sdate.month) { print_str("End date must be after start date\n\n"); continue; } else if (edate.day <= sdate.day) { print_str("End date must be after start date\n\n"); continue; } else break; } // while info->end_date=edate; return; }
/* * Routine: mk_customer * Purpose: populate the customer dimension * Algorithm: * Data Structures: * * Params: * Returns: * Called By: * Calls: * Assumptions: * Side Effects: * TODO: */ int mk_w_customer (void * row, ds_key_t index) { int res = 0, nTemp; static int nBaseDate; /* begin locals declarations */ int nNameIndex, nGender; struct W_CUSTOMER_TBL *r; static int bInit = 0; date_t dtTemp; static date_t dtBirthMin, dtBirthMax, dtToday, dt1YearAgo, dt10YearsAgo; tdef *pT = getSimpleTdefsByNumber(CUSTOMER); if (row == NULL) r = &g_w_customer; else r = row; if (!bInit) { nBaseDate = dttoj (strtodate (DATE_MINIMUM)); strtodt(&dtBirthMax, "1992-12-31"); strtodt(&dtBirthMin, "1924-01-01"); strtodt(&dtToday, TODAYS_DATE); jtodt(&dt1YearAgo, dtToday.julian - 365); jtodt(&dt10YearsAgo, dtToday.julian - 3650); bInit = 1; } nullSet(&pT->kNullBitMap, C_NULLS); r->c_customer_sk = index; mk_bkey(&r->c_customer_id[0], index, C_CUSTOMER_ID); genrand_integer (&nTemp, DIST_UNIFORM, 1, 100, 0, C_PREFERRED_CUST_FLAG); r->c_preferred_cust_flag = (nTemp < C_PREFERRED_PCT) ? 1 : 0; /* demographic keys are a composite of values. rebuild them a la bitmap_to_dist */ r->c_current_hdemo_sk = mk_join(C_CURRENT_HDEMO_SK, HOUSEHOLD_DEMOGRAPHICS, 1); r->c_current_cdemo_sk = mk_join(C_CURRENT_CDEMO_SK, CUSTOMER_DEMOGRAPHICS, 1); r->c_current_addr_sk = mk_join (C_CURRENT_ADDR_SK, CUSTOMER_ADDRESS, r->c_customer_sk); nNameIndex = pick_distribution (&r->c_first_name, "first_names", 1, 3, C_FIRST_NAME); pick_distribution (&r->c_last_name, "last_names", 1, 1, C_LAST_NAME); dist_weight (&nGender, "first_names", nNameIndex, 2); pick_distribution (&r->c_salutation, "salutations", 1, (nGender == 0) ? 2 : 3, C_SALUTATION); genrand_date(&dtTemp, DIST_UNIFORM, &dtBirthMin, &dtBirthMax, NULL, C_BIRTH_DAY); r->c_birth_day = dtTemp.day; r->c_birth_month = dtTemp.month; r->c_birth_year = dtTemp.year; genrand_email(r->c_email_address, r->c_first_name, r->c_last_name, C_EMAIL_ADDRESS); genrand_date(&dtTemp, DIST_UNIFORM, &dt1YearAgo, &dtToday, NULL, C_LAST_REVIEW_DATE); r->c_last_review_date = dtTemp.julian; genrand_date(&dtTemp, DIST_UNIFORM, &dt10YearsAgo, &dtToday, NULL, C_FIRST_SALES_DATE_ID); r->c_first_sales_date_id = dtTemp.julian; r->c_first_shipto_date_id = r->c_first_sales_date_id + 30; pick_distribution(&r->c_birth_country, "countries", 1, 1, C_BIRTH_COUNTRY); return (res); }
/*-------------------------------------------------------------------------*/ int main(int argc, const char **argv) { int fileargc, switchargc; char *fileargv[255], *switchargv[255], env_prompt[MAXSWITCH], tmp_switch[MAXSWITCH] = "", src_pathname[MYMAXPATH] = "", src_filename[MAXFILE + MAXEXT] = "", dest_pathname[MYMAXPATH] = "", dest_filename[MAXFILE + MAXEXT] = "", *ptr, ch; int i, length; THEDATE dt; #ifdef __WATCOMC__ struct dostime_t tm; #else struct time tm; #endif cat = catopen ("xcopy", 0); /* initialize kitten */ classify_args(argc, argv, &fileargc, fileargv, &switchargc, switchargv); if (fileargc < 1 || switchargv[0] == "?") { print_help(); catclose(cat); exit(4); } if (fileargc > 2) { printf("%s\n",catgets(cat, 1, 1, "Invalid number of parameters")); catclose(cat); exit(4); } /* activate termination function */ /* (writes no. of copied files at exit) */ atexit(exit_fn); /* read environment variable COPYCMD to set confirmation switch */ strmcpy(env_prompt, getenv("COPYCMD"), sizeof(env_prompt)); if (env_prompt[0] != '\0') { strupr(env_prompt); if (strcmp(env_prompt, "/Y") == 0) /* overwrite existing file(s) */ switch_confirm = 0; else if (strcmp(env_prompt, "/N") == 0) /* skip existing file(s) */ switch_confirm = 1; else /* ask for confirmation */ switch_confirm = 2; } /* get switches */ for (i = 0; i < switchargc; i++) { strmcpy(tmp_switch, switchargv[i], sizeof(tmp_switch)); strupr(tmp_switch); if (strcmp(tmp_switch, "A") == 0) switch_archive = -1; else if (strcmp(tmp_switch, "C") == 0) switch_continue = -1; else if (strcmp(tmp_switch, "D") == 0) switch_date = -1; else if (strncmp(tmp_switch, "D:", 2) == 0) { if (strtodate(tmp_switch+2, &dt) != 0 || !datevalid(&dt)) { printf("%s\n",catgets(cat, 1, 2, "Invalid date")); catclose(cat); exit(4); } #ifdef __WATCOMC__ memset((void *)&tm, 0, sizeof(struct dostime_t)); /* tm.tm_hour = 0; tm.tm_min = 0; tm.tm_sec = 0; tm.tm_hund = 0; */ #else memset((void *)&tm, 0, sizeof(struct time)); /* tm.ti_hour = 0; tm.ti_min = 0; tm.ti_sec = 0; tm.ti_hund = 0; */ #endif switch_date = dostounix(&dt, &tm); } else if (strcmp(tmp_switch, "E") == 0) switch_emptydir = -1; else if (strcmp(tmp_switch, "F") == 0) switch_fullnames = -1; else if (strcmp(tmp_switch, "H") == 0) switch_hidden = -1; else if (strcmp(tmp_switch, "I") == 0) switch_intodir = -1; else if (strcmp(tmp_switch, "L") == 0) switch_listmode = -1; else if (strcmp(tmp_switch, "M") == 0) switch_archive_reset = -1; else if (strcmp(tmp_switch, "N") == 0) switch_confirm = 1; else if (strcmp(tmp_switch, "P") == 0) switch_prompt = -1; else if (strcmp(tmp_switch, "Q") == 0) switch_quiet = -1; else if (strcmp(tmp_switch, "R") == 0) switch_readonly = -1; else if (strcmp(tmp_switch, "S") == 0) switch_subdir = -1; else if (strcmp(tmp_switch, "T") == 0) switch_tree = -1; else if (strcmp(tmp_switch, "V") == 0) { switch_verify = -1; bak_verify = getverify(); setverify(1); } else if (strcmp(tmp_switch, "W") == 0) switch_wait = -1; else if (strcmp(tmp_switch, "Y") == 0) switch_confirm = 0; else if (strcmp(tmp_switch, "-Y") == 0) switch_confirm = 2; else { printf("%s - %s\n", catgets(cat, 1, 3, "Invalid switch"), switchargv[i]); catclose(cat); exit(4); } } /* get source pathname (with trailing backspace) and filename/-pattern */ length = strlen(fileargv[0]); if (length > (MAXPATH - 1)) { printf("%s\n", catgets(cat, 1, 4, "Source path too long")); catclose(cat); exit(4); } _fullpath(src_pathname, fileargv[0], MYMAXPATH); if (src_pathname[0] == '\0') { printf("%s\n", catgets(cat, 1, 5, "Invalid source drive specification")); catclose(cat); exit(4); } /* check source path */ if (!dir_exists(src_pathname)) { /* source path contains a filename/-pattern -> separate it */ ptr = strrchr(src_pathname, *DIR_SEPARATOR); ptr++; strmcpy(src_filename, ptr, sizeof(src_filename)); *ptr = '\0'; if (!dir_exists(src_pathname)) { printf("%s - %s\n", catgets(cat, 1, 6, "Source path not found"), src_pathname); catclose(cat); exit(4); } } else { /* source is a directory -> filepattern = "*.*" */ strmcpy(src_filename, "*.*", sizeof(src_filename)); } cat_separator(src_pathname); length = strlen(src_pathname); if (length > (MAXDRIVE - 1 + MAXDIR - 1)) { printf("%s\n", catgets(cat, 1, 7, "Source path too long")); catclose(cat); exit(4); } /* get destination pathname (with trailing backspace) and */ /* filename/-pattern */ if (fileargc < 2) { /* no destination path specified -> use current */ getcwd(dest_pathname, MAXPATH); strmcpy(dest_filename, "*.*", sizeof(dest_filename)); } else { /* destination path specified */ length = strlen(fileargv[1]); if (length > (MAXPATH - 1)) { printf("%s\n", catgets(cat, 1, 8, "Destination path too long")); catclose(cat); exit(4); } _fullpath(dest_pathname, fileargv[1], MYMAXPATH); if (dest_pathname[0] == '\0') { printf("%s\n", catgets(cat, 1, 9, "Invalid destination drive specification")); catclose(cat); exit(4); } /* check destination path */ if (fileargv[1][length - 1] != *DIR_SEPARATOR && !dir_exists(dest_pathname)) { ptr = strrchr(dest_pathname, *DIR_SEPARATOR); ptr++; strmcpy(dest_filename, ptr, sizeof(dest_filename)); *ptr = '\0'; if ((ptr = strchr(dest_filename, '*')) == NULL && (ptr = strchr(dest_filename, '?')) == NULL) { /* last destination entry is not a filepattern -> does it specify */ /* a file or directory? */ if (((ptr = strchr(src_filename, '*')) == NULL && (ptr = strchr(src_filename, '?')) == NULL) || !switch_intodir) { /* source is a single file or switch /I was not specified -> ask */ /* user if destination should be a file or a directory */ printf("%s %s %s\n", catgets(cat, 1, 10, "Does"), dest_filename, catgets(cat, 1, 11, "specify a file name")); ch = confirm( catgets(cat, 1, 12, "or directory name on the target"), catgets(cat, 1, 13, "File"), catgets(cat, 1, 14, "Directory"), NULL, NULL); switch (ch) { case 1: /* 'F' */ /* file */ switch_file = -1; break; case 2: /* 'D' */ /* directory */ switch_intodir = -1; break; } } if (switch_intodir) { /* destination is a directory -> filepattern = "*.*" */ strmcat(dest_pathname, dest_filename, sizeof(dest_pathname)); strmcpy(dest_filename, "*.*", sizeof(dest_filename)); } } } else { /* destination is a directory -> filepattern = "*.*" */ strmcpy(dest_filename, "*.*", sizeof(dest_filename)); } } cat_separator(dest_pathname); length = strlen(dest_pathname); if (length > (MAXDRIVE - 1 + MAXDIR - 1)) { printf("%s\n",catgets(cat, 1, 15, "Destination path too long")); catclose(cat); exit(4); } /* check for cyclic path */ if ((switch_emptydir || switch_subdir) && cyclic_path(src_pathname, dest_pathname)) { printf("%s\n",catgets(cat, 1, 16, "Cannot perform a cyclic copy")); catclose(cat); exit(4); } /* get destination drive (1 = A, 2 = B, 3 = C, ...) */ dest_drive = toupper(dest_pathname[0]) - 64; if (switch_wait) { printf("%s\n",catgets(cat, 1, 17, "Press enter to continue...")); (void)getchar(); /* getch(); would need conio.h */ fflush(stdin); } xcopy_files(src_pathname, src_filename, dest_pathname, dest_filename); if (!file_found) { printf("%s - %s\n",catgets(cat, 1, 18, "File not found"), src_filename); catclose(cat); exit(1); } catclose(cat); return 0; }