static void gen_atom(const ast *atom, FILE *out){ const state *s; switch(get_atom_type(atom)){ case ATOM_STRING: fprintf(out, "%s", atom->children[0]->text); break; case ATOM_CHARSET: gen_charset(atom->children[0], out); break; case ATOM_SPECIAL: case ATOM_PARENS: case ATOM_RULE: s = (const state*)atom->children[0]->text; s->gen(s, out); break; } }
int main(int argc, char *argv[]) { FILE * f_pretty = fopen("pretty.h", "w"); FILE * f_charset = fopen("font.c", "w"); FILE * f_charmap = fopen("charmap.c", "w"); FILE * f_translate = fopen("translate.c", "w"); gen_pretty(f_pretty); fclose(f_pretty); gen_charset(f_charset); fclose(f_charset); gen_charmap(f_charmap); fclose(f_charmap); gen_translate(f_translate); fclose(f_translate); return sanity_check(); }
/* * Routine: * Purpose: * Algorithm: * Data Structures: * * Params: * Returns: * Called By: * Calls: * Assumptions: * Side Effects: * TODO: None */ int mk_s_customer (void *pDest, ds_key_t kIndex) { static int bInit = 0; struct S_CUSTOMER_TBL *r; static date_t dtMin, dtMax, dtBirthMin, dtBirthMax, dtToday, dt1YearAgo, dt10YearsAgo; static decimal_t dMinIncome, dMaxIncome; int nTemp; ds_key_t kTempDemographic; char *szTemp; static int *pPermutation; if (pDest == NULL) r = &g_s_customer; else r = pDest; if (!bInit) { memset (&g_s_customer, 0, sizeof (struct S_CUSTOMER_TBL)); setUpdateDateRange (S_CUSTOMER, &dtMin, &dtMax); strtodec (&dMinIncome, "0.00"); strtodec (&dMaxIncome, "200000.00"); r->pBirthCountry = strdup ("<UNKNOWN>"); strtodt (&dtBirthMin, "1924-01-01"); strtodt (&dtBirthMax, "1992-12-31"); strtodt (&dtToday, TODAYS_DATE); jtodt (&dt1YearAgo, dtToday.julian - 365); jtodt (&dt10YearsAgo, dtToday.julian - 365); pPermutation = makePermutation (NULL, (int) getIDCount (CUSTOMER), S_CUST_ID); bInit = 1; } r->kID = getPermutationEntry (pPermutation, (int) kIndex); kTempDemographic = mk_join (S_CUST_GENDER, CUSTOMER_DEMOGRAPHICS, 1) - 1; bitmap_to_dist (&szTemp, "gender", &kTempDemographic, 1, CUSTOMER_DEMOGRAPHICS); switch (*szTemp) { case 'M': /* male */ r->sGender[0] = 'M'; pick_distribution (&r->pFirstName, "first_names", 1, 1, S_CUST_FIRST_NAME); pick_distribution (&r->pSalutation, "salutations", 1, 2, S_CUST_SALUTATION); break; case 'F': /* female */ r->sGender[0] = 'F'; pick_distribution (&r->pFirstName, "first_names", 1, 2, S_CUST_FIRST_NAME); pick_distribution (&r->pSalutation, "salutations", 1, 3, S_CUST_SALUTATION); break; default: /* gender neutral */ r->sGender[0] = 'U'; pick_distribution (&r->pFirstName, "first_names", 1, 3, S_CUST_FIRST_NAME); pick_distribution (&r->pSalutation, "salutations", 1, 1, S_CUST_SALUTATION); break; } bitmap_to_dist (&r->pMaritalStatus, "marital_status", &kTempDemographic, 1, CUSTOMER_DEMOGRAPHICS); bitmap_to_dist (&r->pEducation, "education", &kTempDemographic, 1, CUSTOMER_DEMOGRAPHICS); bitmap_to_dist (&r->nPurchaseEstimate, "purchase_band", &kTempDemographic, 1, CUSTOMER_DEMOGRAPHICS); bitmap_to_dist (&r->pCreditRating, "credit_rating", &kTempDemographic, 1, CUSTOMER_DEMOGRAPHICS); r->nDependents = (int) (kTempDemographic % (ds_key_t) CD_MAX_CHILDREN); kTempDemographic /= (ds_key_t) CD_MAX_CHILDREN; r->nEmployed = (int) (kTempDemographic % (ds_key_t) CD_MAX_EMPLOYED); kTempDemographic /= (ds_key_t) CD_MAX_EMPLOYED; r->nCollege = (int) (kTempDemographic % (ds_key_t) CD_MAX_COLLEGE); pick_distribution (&r->pLastName, "last_names", 1, 1, S_CUST_LAST_NAME); r->bPreferredFlag = (genrand_integer (NULL, DIST_UNIFORM, 1, 100, 0, S_CUST_PREFERRED_FLAG) > 50) ? 1 : 0; genrand_date (&r->dtBirthDate, DIST_UNIFORM, &dtBirthMin, &dtBirthMax, NULL, S_CUST_BIRTH_DATE); genrand_date (&r->dtFirstPurchaseDate, DIST_UNIFORM, &dt10YearsAgo, &dt1YearAgo, NULL, S_CUST_FIRST_PURCHASE_DATE); genrand_integer (&nTemp, DIST_UNIFORM, 1, 30, 0, S_CUST_FIRST_SHIPTO_DATE); jtodt (&r->dtFirstShipToDate, r->dtFirstPurchaseDate.julian + nTemp); gen_charset (r->szLogin, ALPHANUM, 5, RS_S_CUST_LOGIN, S_CUST_LOGIN); genrand_email (r->szEmail, r->pFirstName, r->pLastName, S_CUST_EMAIL); genrand_date (&r->dtLastLogin, DIST_UNIFORM, &dt1YearAgo, &dtToday, NULL, S_CUST_LAST_LOGIN); genrand_date (&r->dtReview, DIST_UNIFORM, &dt1YearAgo, &dtToday, NULL, S_CUST_LAST_REVIEW); genrand_ipaddr (r->szPrimaryMachine, S_CUST_PRIMARY_MACHINE); genrand_ipaddr (r->szSecondaryMachine, S_CUST_SECONDARY_MACHINE); pick_distribution (&r->pLocationType, "location_type", 1, 1, S_CUST_LOCATION_TYPE); pick_distribution (&r->nVehicle, "vehicle_count", 1, 1, S_CUST_VEHICLE_CNT); genrand_decimal (&r->dIncome, DIST_UNIFORM, &dMinIncome, &dMaxIncome, NULL, S_CUST_INCOME); pick_distribution (&r->pBuyPotential, "buy_potential", 1, 1, S_CUST_PURCHASE_ESTIMATE); mk_w_customer_address (NULL, kIndex); return (0); }
/* * mk_item */ int mk_w_item (void* row, ds_key_t index) { int32_t res = 0; /* begin locals declarations */ decimal_t dMinPrice, dMaxPrice, dMarkdown; static decimal_t dMinMarkdown, dMaxMarkdown; int32_t bUseSize, bFirstRecord = 0, nFieldChangeFlags, nMin, nMax, nIndex, nTemp; char *cp; struct W_ITEM_TBL *r; static int32_t bInit = 0; struct W_ITEM_TBL *rOldValues = &g_OldValues; char *szMinPrice = NULL, *szMaxPrice = NULL; tdef *pT = getSimpleTdefsByNumber(ITEM); if (row == NULL) r = &g_w_item; else r = row; if (!bInit) { /* some fields are static throughout the data set */ strtodec(&dMinMarkdown, MIN_ITEM_MARKDOWN_PCT); strtodec(&dMaxMarkdown, MAX_ITEM_MARKDOWN_PCT); bInit = 1; } memset(r, 0, sizeof(struct W_ITEM_TBL)); /* build the new value */ nullSet(&pT->kNullBitMap, I_NULLS); r->i_item_sk = index; nIndex = pick_distribution(&nMin, "i_manager_id", 2, 1, I_MANAGER_ID); dist_member(&nMax, "i_manager_id", nIndex, 3); genrand_key(&r->i_manager_id, DIST_UNIFORM, (ds_key_t)nMin, (ds_key_t)nMax, 0, I_MANAGER_ID); /* if we have generated the required history for this business key and generate a new one * then reset associated fields (e.g., rec_start_date minimums) */ if (setSCDKeys(I_ITEM_ID, index, r->i_item_id, &r->i_rec_start_date_id, &r->i_rec_end_date_id)) { /* * some fields are not changed, even when a new version of the row is written */ bFirstRecord = 1; } /* * this is where we select the random number that controls if a field changes from * one record to the next. */ nFieldChangeFlags = next_random(I_SCD); /* the rest of the record in a history-keeping dimension can either be a new data value or not; * use a random number and its bit pattern to determine which fields to replace and which to retain */ gen_text (r->i_item_desc, 1, RS_I_ITEM_DESC, I_ITEM_DESC); changeSCD(SCD_CHAR, &r->i_item_desc, &rOldValues->i_item_desc, &nFieldChangeFlags, bFirstRecord); nIndex = pick_distribution(&szMinPrice, "i_current_price", 2, 1, I_CURRENT_PRICE); dist_member(&szMaxPrice, "i_current_price", nIndex, 3); strtodec(&dMinPrice, szMinPrice); strtodec(&dMaxPrice, szMaxPrice); genrand_decimal(&r->i_current_price, DIST_UNIFORM, &dMinPrice, &dMaxPrice, NULL, I_CURRENT_PRICE); changeSCD(SCD_INT, &r->i_current_price, &rOldValues->i_current_price, &nFieldChangeFlags, bFirstRecord); genrand_decimal(&dMarkdown, DIST_UNIFORM, &dMinMarkdown, &dMaxMarkdown, NULL, I_WHOLESALE_COST); decimal_t_op(&r->i_wholesale_cost, OP_MULT, &r->i_current_price, &dMarkdown); changeSCD(SCD_DEC, &r->i_wholesale_cost, &rOldValues->i_wholesale_cost, &nFieldChangeFlags, bFirstRecord); hierarchy_item (I_CATEGORY, &r->i_category_id, &r->i_category, index); /* * changeSCD(SCD_INT, &r->i_category_id, &rOldValues->i_category_id, &nFieldChangeFlags, bFirstRecord); */ hierarchy_item (I_CLASS, &r->i_class_id, &r->i_class, index); changeSCD(SCD_KEY, &r->i_class_id, &rOldValues->i_class_id, &nFieldChangeFlags, bFirstRecord); cp = &r->i_brand[0]; hierarchy_item (I_BRAND, &r->i_brand_id, &cp, index); changeSCD(SCD_KEY, &r->i_brand_id, &rOldValues->i_brand_id, &nFieldChangeFlags, bFirstRecord); /* some categories have meaningful sizes, some don't */ if (r->i_category_id) { dist_member(&bUseSize, "categories", (int)r->i_category_id, 3); pick_distribution (&r->i_size, "sizes", 1, bUseSize + 2, I_SIZE); changeSCD(SCD_PTR, &r->i_size, &rOldValues->i_size, &nFieldChangeFlags, bFirstRecord); } else { bUseSize = 0; r->i_size = NULL; } nIndex = pick_distribution(&nMin, "i_manufact_id", 2, 1, I_MANUFACT_ID); genrand_integer(&nTemp, DIST_UNIFORM, nMin, dist_member(NULL, "i_manufact_id", nIndex, 3), 0, I_MANUFACT_ID); r->i_manufact_id = nTemp; changeSCD(SCD_KEY, &r->i_manufact_id, &rOldValues->i_manufact_id, &nFieldChangeFlags, bFirstRecord); mk_word (r->i_manufact, "syllables", (int) r->i_manufact_id, RS_I_MANUFACT, ITEM); changeSCD(SCD_CHAR, &r->i_manufact, &rOldValues->i_manufact, &nFieldChangeFlags, bFirstRecord); gen_charset(r->i_formulation, DIGITS, RS_I_FORMULATION, RS_I_FORMULATION, I_FORMULATION); embed_string(r->i_formulation, "colors", 1, 2, I_FORMULATION); changeSCD(SCD_CHAR, &r->i_formulation, &rOldValues->i_formulation, &nFieldChangeFlags, bFirstRecord); pick_distribution (&r->i_color, "colors", 1, 2, I_COLOR); changeSCD(SCD_PTR, &r->i_color, &rOldValues->i_color, &nFieldChangeFlags, bFirstRecord); pick_distribution (&r->i_units, "units", 1, 1, I_UNITS); changeSCD(SCD_PTR, &r->i_units, &rOldValues->i_units, &nFieldChangeFlags, bFirstRecord); pick_distribution (&r->i_container, "container", 1, 1, ITEM); changeSCD(SCD_PTR, &r->i_container, &rOldValues->i_container, &nFieldChangeFlags, bFirstRecord); mk_word (r->i_product_name, "syllables", (int) index, RS_I_PRODUCT_NAME, ITEM); r->i_promo_sk = mk_join(I_PROMO_SK, PROMOTION, 1); genrand_integer(&nTemp, DIST_UNIFORM, 1, 100, 0, I_PROMO_SK); if (nTemp > I_PROMO_PERCENTAGE) r->i_promo_sk = -1; /* * if this is the first of a set of revisions, then baseline the old values */ if (bFirstRecord) memcpy(&g_OldValues, r, sizeof(struct W_ITEM_TBL)); if (index == 1) memcpy(&g_OldValues, r, sizeof(struct W_ITEM_TBL)); return (res); }