bool User_Program::Initial_Table (String &line) { int i, j, index, lnum, len; Int_Itr litr, litr0; double fnum; Dbl_Itr fitr, fitr0; String token; Str_Itr sitr, sitr0; string::iterator ch, ch0; i = cmd.token; j = cmd.value; for (;;) { //---- remove leading spaces ---- line.Trim_Left (" \t"); if (line.empty ()) return (false); ch = ch0 = line.begin (); //---- determine the token type ---- if ((*ch >= '0' && *ch <= '9') || (*ch == '.' && *(ch+1) != '.') || (*ch == '-' && (*(ch+1) >= '0' && *(ch+1) <= '9'))) { //---- process a number ---- if (*ch == '-') ch++; do { if (++ch == line.end ()) break; } while ((*ch >= '0' && *ch <= '9') || (*ch == '.' && *(ch+1) != '.')); len = (int) (ch - ch0); token = line.substr (0, len); line.erase (0, len); //---- set the table size ---- if (open_par) { lnum = token.Integer (); if (lnum < 1) { exe->Error (String ("%s Table %d Size %d is Out of Range") % Data_Type (i) % j % lnum); return (false); } if (table [i] [j].size () > 0) { exe->Write (1); exe->Warning (String ("%s Table %d is Redefined") % Data_Type (i) % j); table [i] [j].clear (); } table [i] [j].reserve (lnum); } else { if (table_type == STAB) { exe->Error ("Attempt to Assign a Number to a String Table"); return (false); } //---- search for the value in the list ---- if (table_type == ITAB) { lnum = token.Integer (); for (litr = litr0 = lvalue.begin (); litr != lvalue.end (); litr++) { if (*litr == lnum) break; } if (litr == lvalue.end ()) { index = (int) lvalue.size (); //---- 0 based ---- lvalue.push_back (lnum); } else { index = (int) (litr - litr0); //---- 0 based ---- } } else { fnum = token.Double (); for (fitr = fitr0 = fvalue.begin (); fitr != fvalue.end (); fitr++) { if (*fitr == fnum) break; } if (fitr == fvalue.end ()) { index = (int) fvalue.size (); //---- 0 based ---- fvalue.push_back (fnum); } else { index = (int) (fitr - fitr0); //---- 0 based ---- } } table [i] [j].push_back (index); } } else if (*ch == '"') { if (table_type != STAB) goto error; //---- process a string ---- ch++; token.clear (); while (ch != line.end () && *ch != '"') { token += *ch++; } ch++; line.erase (0, ch - ch0); for (sitr = sitr0 = svalue.begin (); sitr != svalue.end (); sitr++) { if (token.Equals (*sitr)) break; } if (sitr == svalue.end ()) { index = (int) svalue.size (); svalue.push_back (token); } else { index = (int) (sitr - sitr0); //---- 0 based ---- } table [i] [j].push_back (index); } else if ((*ch >= 'A' && *ch <= 'Z') || (*ch >= 'a' && *ch <= 'z')) { do { if (++ch == line.end ()) break; } while ((*ch >= 'A' && *ch <= 'Z') || (*ch >= 'a' && *ch <= 'z') || (*ch >= '0' && *ch <= '9') || (*ch == '.' && *(ch+1) != '.') || *ch == '_'); len = (int) (ch - ch0); token = line.substr (0, len); line.erase (0, len); if (token.Equals ("ENDTAB")) { table_flag = false; open_par = false; return (true); } else { goto error; } } else if (*ch == '(' || *ch == ')' || *ch == ',' || *ch == '=') { if (*ch == '(') { open_par = true; } else if (*ch == ')') { open_par = false; } else if (*ch == ',' || *ch == '=') { if (open_par) { goto error; } } ch++; line.erase (0, ch - ch0); } else { goto error; } } return (true); error: return (Syntax_Error ("Table Declaration")); }
void Execution_Service::Read_Reports (void) { int i, num, num_reports; String key; Report_Name_Itr itr; Report_Number report; //---- get the number of selected reports ---- num_reports = Highest_Control_Group (PROGRAM_REPORTS, 0); if (num_reports <= 0) { report_flag = false; return; } report_flag = true; report_number.reserve (num_reports); for (i=1; i <= num_reports; i++) { key = Get_Control_String (PROGRAM_REPORTS, i); if (key.empty ()) continue; report.type = 0; report.data = 0.0; //---- identify the report ---- num = 1; for (itr = report_name.begin (); itr != report_name.end (); itr++, num++) { if (itr->name.Equals (key)) { itr->flag = true; report.type = num; break; } else { //---- check for a variable length report label ---- size_t index = itr->name.find_last_of ('*'); if (index != string::npos) { String temp = itr->name.substr (0, index); if (key.Starts_With (temp)) { itr->flag = true; report.type = num; temp = key.substr (index); report.data = temp.Double (); break; } } } } //---- check for unrecognized report types ---- if (report.type == 0) { Error (String ("Unrecognized Report Type = %s") % key); } else { report_number.push_back (report); } } }
bool Db_Base::Read_Field (Db_Field *fld, void *data, Field_Type type) { if (data == 0) return (Status (NULL_POINTER)); //---- initialize the data field ---- switch (type) { case DB_INTEGER: *((int *) data) = 0; break; case DB_DOUBLE: *((double *) data) = 0.0; break; case DB_STRING: ((string *) data)->clear (); break; case DB_TIME: *((Dtime *) data) = 0; break; default: return (Status (DB_ERROR)); } if (fld == 0) return (Status (NO_FIELD, false)); Nested (fld->Nested ()); char *field = Record_String (); if (field == 0) return (Status (RECORD_SIZE)); Field_Type fld_type; bool asc_flag = true; int len, lvalue = 0; double dvalue = 0.0; String svalue; Dtime tvalue = 0; int size = fld->Width (); int offset = fld->Offset (); switch (Record_Format ()) { case BINARY: if (fld->Type () != DB_STRING) { field += offset; asc_flag = false; break; } else { len = (int) strlen (field + offset); if (len < size) size = len; } case FIXED_COLUMN: svalue.assign (field + offset, size); svalue.Clean (); break; case COMMA_DELIMITED: case SPACE_DELIMITED: case TAB_DELIMITED: case CSV_DELIMITED: svalue (fld->Buffer ()); size = (int) svalue.size (); break; default: svalue = Get_Field_Number (offset); size = (int) svalue.size (); break; } //---- read the field from the current record ---- switch (fld->Type ()) { default: return (Status (DB_ERROR)); case DB_INTEGER: if (asc_flag) { lvalue = svalue.Integer (); } else if (size == sizeof (int)) { lvalue = *((int *) field); } else if (size == sizeof (short)) { lvalue = *((short *) field); } else if (size == sizeof (char)) { lvalue = *((char *) field); } else { return (Status (FIELD_BYTES)); } fld_type = DB_INTEGER; break; case DB_UNSIGNED: if (asc_flag) { lvalue = svalue.Integer (); } else if (size == sizeof (int)) { lvalue = *((unsigned int *) field); } else if (size == sizeof (short)) { lvalue = *((unsigned short *) field); } else if (size == sizeof (char)) { lvalue = *((unsigned char *) field); } else { return (Status (FIELD_BYTES)); } fld_type = DB_INTEGER; break; case DB_DOUBLE: if (asc_flag) { dvalue = svalue.Double (); } else if (size == sizeof (double)) { dvalue = *((double *) field); } else if (size == sizeof (float)) { dvalue = *((float *) field); } else { return (Status (FIELD_BYTES)); } fld_type = DB_DOUBLE; break; case DB_FIXED: if (asc_flag) { dvalue = svalue.Double (); if (svalue.find ('.') == 0) { dvalue = dvalue / pow (10.0, fld->Decimal ()); } } else { if (size == sizeof (int)) { lvalue = *((int *) field); } else if (size == sizeof (short)) { lvalue = *((short *) field); } else if (size == sizeof (char)) { lvalue = *((char *) field); } else { return (Status (FIELD_BYTES)); } dvalue = (double) lvalue / pow (10.0, fld->Decimal ()); } fld_type = DB_DOUBLE; break; case DB_STRING: fld_type = DB_STRING; break; case DB_CHAR: if (asc_flag) { if (svalue.empty ()) { svalue = " "; } } else { if (*field == '\0') { svalue = " "; } else { svalue.insert (0, field, 1); } } fld_type = DB_STRING; break; case DB_TIME: if (asc_flag) { tvalue.Time_String (svalue, fld->Units ()); } else if (size == sizeof (Dtime)) { tvalue = *((int *) field); } else if (size == sizeof (short)) { tvalue = *((short *) field); } else { return (Status (FIELD_BYTES)); } fld_type = DB_TIME; break; } //---- convert to internal units ---- if (fld->Units () != NO_UNITS) { if (fld_type == DB_INTEGER) { lvalue = Internal_Units (lvalue, fld->Units ()); } else if (fld_type == DB_DOUBLE) { dvalue = Internal_Units (dvalue, fld->Units ()); } else if (fld->Units () < SECONDS || fld->Units () > TIME_CODE) { if (fld_type == DB_STRING && fld->Units () >= FACILITY_CODE) { if (type == DB_INTEGER) { lvalue = Internal_Units (svalue, fld->Units ()); if (lvalue < -1) return (Status (FIELD_UNITS)); if (lvalue >= 0) fld_type = DB_INTEGER; } } else { return (Status (FIELD_UNITS)); } } } //---- convert to the output data type ---- switch (type) { case DB_INTEGER: switch (fld_type) { case DB_INTEGER: *((int *) data) = lvalue; break; case DB_DOUBLE: *((int *) data) = DTOI (dvalue); break; case DB_STRING: if (svalue [0] < '0' || svalue [0] > '9' || svalue.find_first_of ("@:") != svalue.npos) { *((int *) data) = (int) Dtime (svalue); } else { *((int *) data) = svalue.Integer (); } break; case DB_TIME: *((int *) data) = (int) tvalue; break; default: return (Status (DB_ERROR)); } break; case DB_DOUBLE: switch (fld_type) { case DB_INTEGER: *((double *) data) = lvalue; break; case DB_DOUBLE: *((double *) data) = dvalue; break; case DB_STRING: if (svalue [0] < '0' || svalue [0] > '9' || svalue.find_first_of ("@:") != svalue.npos) { *((double *) data) = (int) Dtime (svalue); } else { *((double *) data) = svalue.Double (); } break; case DB_TIME: *((double *) data) = (double) tvalue; break; default: return (Status (DB_ERROR)); } break; case DB_STRING: switch (fld->Type ()) { case DB_TIME: svalue = tvalue.Time_String (); break; default: if (fld_type == DB_INTEGER) { svalue (lvalue); } else if (fld_type == DB_DOUBLE) { svalue (dvalue, fld->Decimal ()); } break; } len = (int) svalue.size (); if (len > 0) { if (len > fld->Width ()) len = fld->Width (); *((string *) data) = svalue.substr (0, len); } else { (*((string *) data)).clear (); } break; case DB_TIME: switch (fld_type) { case DB_INTEGER: *((Dtime *) data) = Dtime (lvalue, fld->Units ()); break; case DB_DOUBLE: *((Dtime *) data) = Dtime (dvalue, fld->Units ()); break; case DB_STRING: *((Dtime *) data) = svalue; break; case DB_TIME: *((Dtime *) data) = tvalue; break; default: return (Status (DB_ERROR)); } break; default: return (Status (DB_ERROR)); } return (true); }