void SymIdFunc::execute() { // return id of each symbol in the arguments boolean noargs = !nargs() && !nkeys(); int numargs = nargs(); if (!numargs) return; int symbol_ids[numargs]; for (int i=0; i<numargs; i++) { ComValue& val = stack_arg(i, true); if (val.is_type(AttributeValue::CommandType)) symbol_ids[i] = val.command_symid(); else if (val.is_type(AttributeValue::StringType)) symbol_ids[i] = val.string_val(); else if (val.is_type(AttributeValue::SymbolType)) symbol_ids[i] = val.symbol_val(); else symbol_ids[i] = -1; } reset_stack(); if (numargs>1) { AttributeValueList* avl = new AttributeValueList(); ComValue retval(avl); for (int i=0; i<numargs; i++) avl->Append(new AttributeValue(symbol_ids[i], AttributeValue::IntType)); push_stack(retval); } else { ComValue retval (symbol_ids[0], AttributeValue::IntType); push_stack(retval); } }
void SymValFunc::execute() { // return value for each symbol variable boolean noargs = !nargs() && !nkeys(); int numargs = nargs(); if (!numargs) return; ComValue* varvalues[numargs]; for (int i=0; i<numargs; i++) { // return fully-evaluated value: expression --> symbol --> value varvalues[i] = &stack_arg(i, false); // lookup_symval(*varvalues[i]); } if (numargs>1) { AttributeValueList* avl = new AttributeValueList(); ComValue retval(avl); for (int i=0; i<numargs; i++) avl->Append(new ComValue(*varvalues[i])); reset_stack(); push_stack(retval); } else { ComValue retval (*varvalues[0]); reset_stack(); push_stack(retval); } }
void SymbolFunc::execute() { // return symbol for each id argument boolean noargs = !nargs() && !nkeys(); int numargs = nargs(); if (!numargs) return; int symbol_ids[numargs]; for (int i=0; i<numargs; i++) { ComValue& val = stack_arg(i, true); if (val.is_char() || val.is_short() || val.is_int()) symbol_ids[i] = val.int_val(); else symbol_ids[i] = -1; } reset_stack(); if (numargs>1) { AttributeValueList* avl = new AttributeValueList(); ComValue retval(avl); for (int i=0; i<numargs; i++) { ComValue* av = new ComValue(symbol_ids[i], AttributeValue::SymbolType); av->bquote(1); avl->Append(av); } push_stack(retval); } else { ComValue retval (symbol_ids[0], AttributeValue::SymbolType); retval.bquote(1); push_stack(retval); } }
// parse a STATA command DwUseOptions* DwUseOptionParser::Parse(vector<string> words) { // there are 10 keywords we expect to see string keys[] = {"variables", "if", "using", "limit", "nulldata", "lowercase", "uppercase", "label_variable", "label_values", "username", "password", "database"}; size_t nkeys(sizeof(keys) / sizeof(string)); // create parser that accepts these keywords OptionParser* parser = new OptionParser( set<string>(keys, keys + nkeys) ); // prepare another vector where we can search // see if we have a using anywhere, if we do, the first part is the varlist, if not it is the tablename bool hasUsing = hasKeyword(words, "using"); // if it contains using somewhere we can start with variables (if missing it will be an empty string, if the list is there it will be expected) if( !hasUsing ) words.insert(words.begin(), "using"); else if( lowerCase(words[0]) != "if" && lowerCase(words[0]) != "using" ) words.insert(words.begin(), "variables"); // parse the options map<string,string> options = parser->Parse( words ); delete parser; // create a meaningful options object DwUseOptions* useOptions = new DwUseOptions( options ); return useOptions; }
/*========================================= * check_keys -- Validate keys of index or block * Created: 2003/09/05, Perry Rapp *=======================================*/ static BOOLEAN check_keys (BLOCK block, RKEY * lo, RKEY * hi) { INT n = nkeys(block); INT i = 0; INT start = 0; BOOLEAN ok = TRUE; if (ixtype(block) == BTINDEXTYPE) ++start; /* keys are 1..n for index */ else --n; /* keys are 0..n-1 for block */ for (i=start ; i <= n; i++) { if (i==start && lo) { INT rel = cmpkeys(lo, &rkeys(block, i)); if (rel < 0) { printf(_("First key in block below parent's limit\n")); printblock(block); ok = FALSE; } } if (i==n && hi) { INT rel = cmpkeys(&rkeys(block, i), hi); if (rel > 0) { printf(_("Last key in block above parent's limit\n")); printblock(block); ok = FALSE; } } if (i<n) { INT rel = cmpkeys(&rkeys(block, i), &rkeys(block, i+1)); if (rel >= 0) { printf(_("Key not below next key")); printf(": %ld\n", i); printblock(block); ok = FALSE; } } } return ok; }
/*========================================= * check_index -- Validate one index node of btree * Created: 2003/09/05, Perry Rapp *=======================================*/ static BOOLEAN check_index (BTREE btr, INDEX index, TABLE fkeytab, RKEY * lo, RKEY * hi) { INT n = nkeys(index); INT i; if (!check_keys((BLOCK)index, lo, hi)) return FALSE; for (i = 0; i <= n; i++) { INDEX newix=0; char scratch[200]; FKEY fkey = fkeys(index, i); RKEY *lox, *hix; get_index_file(scratch, btr, fkey); if (in_table(fkeytab, scratch)) { printf(_("Cycle in indexes, file %s found again!\n"), scratch); return FALSE; } else { insert_table_int(fkeytab, scratch, 1); } newix = readindex(btr, fkey, TRUE); if (!newix) { printf(_("Error loading index at key")); printf("%ld\n", i); printblock((BLOCK)index); } /* figure upper & lower bounds of what keys should be in the child */ lox = (i==0 ? lo : &rkeys(index, i)); hix = (i==n ? hi : &rkeys(index, i+1)); if (ixtype(newix) == BTINDEXTYPE) { if (!check_index(btr, newix, fkeytab, lox, hix)) return FALSE; } else { if (!check_block((BLOCK)newix, lox, hix)) return FALSE; } } /* TODO: use fkeytab */ return TRUE; }
void GlobalSymbolFunc::execute() { // return symbol(s) with global flag set boolean noargs = !nargs() && !nkeys(); int numargs = nargs(); if (!numargs) { reset_stack(); return; } int symbol_ids[numargs]; for (int i=0; i<numargs; i++) { ComValue& val = stack_arg(i, true); if (val.is_symbol()) symbol_ids[i] = val.symbol_val(); else symbol_ids[i] = -1; } reset_stack(); if (numargs>1) { AttributeValueList* avl = new AttributeValueList(); ComValue retval(avl); for (int i=0; i<numargs; i++) { ComValue* av = new ComValue(symbol_ids[i], AttributeValue::SymbolType); av->global_flag(true); av->bquote(1); avl->Append(av); } push_stack(retval); } else { ComValue retval (symbol_ids[0], AttributeValue::SymbolType); retval.global_flag(true); retval.bquote(1); push_stack(retval); } }
void SymAddFunc::execute() { // return each symbol in the arguments as is boolean noargs = !nargs() && !nkeys(); int numargs = nargs(); if (!numargs) return; int symbol_ids[numargs]; for (int i=0; i<numargs; i++) { ComValue& val = stack_arg(i); if (val.is_type(AttributeValue::CommandType)) symbol_ids[i] = val.command_symid(); else if (val.is_type(AttributeValue::StringType)) symbol_ids[i] = val.string_val(); else if (val.is_type(AttributeValue::SymbolType)) symbol_ids[i] = val.symbol_val(); else symbol_ids[i] = -1; } reset_stack(); if (numargs>1) { AttributeValueList* avl = new AttributeValueList(); ComValue retval(avl); for (int i=0; i<numargs; i++) { ComValue* av = new ComValue(symbol_ids[i], AttributeValue::SymbolType); av->bquote(1); if (symbol_ids[i]<0) av->type(ComValue::UnknownType); avl->Append(av); } push_stack(retval); } else { ComValue retval (symbol_ids[0], AttributeValue::SymbolType); if (symbol_ids[0]<0) retval.type(ComValue::UnknownType); retval.bquote(1); push_stack(retval); } }