/****************************************************************************** * * L I S T P R O C S V A R S (char *name) * * Used in processing the ICL command "VARS". * Lists the variables of procedure name with their current types and values * OR, when name is CHARNIL, lists the direct mode variables * * A PROC entry is always found in the global world symbtab. * Its symboltable_part() member, if it has been executed at least once, * points to its local symbol table. * * Search the global symtab for a match (lookup_proc() using the string * argument name) and if we find it, we use the symboltable_part() entry * as the source of the variables. * If name is nil, we use the world symtab as the source. * We save the current active symbol table in symbols and restore * it once done and we use print_typed_symbols() to do the printing * (symtab.c). * ****************************************************************************** */ value listprocsvars(char *name) { if (name != CHARNIL) { node *proc; if ((proc = lookup_proc(name)) != NODENIL) { symtab *savesym = symbols; symbols = symboltable_part(proc->val); (void) print_typed_symbols(SYM_VARIABLE); symbols = savesym; return trueval; } else return exception1( "PROCERR VARS: Unrecognised procedure or command name \"%s\" ", name); } else { symtab *savesym = symbols; symbols = world; (void) print_typed_symbols(SYM_VARIABLE); symbols = savesym; return trueval; } }
void boost_throw_exception_test() { try { BOOST_THROW_EXCEPTION(exception1()); BOOST_ERROR("BOOST_THROW_EXCEPTION failed to throw."); } catch( boost::exception & x ) { char const * const * file=boost::get_error_info<boost::throw_function>(x); char const * const * function=boost::get_error_info<boost::throw_file>(x); int const * line=boost::get_error_info<boost::throw_line>(x); BOOST_TEST( file && *file ); BOOST_TEST( function && *function ); BOOST_TEST( line && *line==32 ); } catch( ... ) { BOOST_TEST(false); } try { BOOST_THROW_EXCEPTION(exception2() << test_data(42)); BOOST_ERROR("BOOST_THROW_EXCEPTION failed to throw."); } catch( boost::exception & x ) { char const * const * file=boost::get_error_info<boost::throw_function>(x); char const * const * function=boost::get_error_info<boost::throw_file>(x); int const * line=boost::get_error_info<boost::throw_line>(x); int const * data=boost::get_error_info<test_data>(x); BOOST_TEST( file && *file ); BOOST_TEST( function && *function ); BOOST_TEST( line && *line==52 ); BOOST_TEST( data && *data==42 ); } catch( ... ) { BOOST_TEST(false); } }
/****************************************************************************** * * L O O K F O R _ V A R I A B L E _ V A L U E (symtab *sym, char * name) * * This routine looks up a variable in a given symbol_table. * * If the variable is a parameter then, on calling the current procedure we * could have passed EITHER an expression, which is evaluated and the formal * node's value member points to that value (whose interpret member will not * be parameter_interpret()) * OR * a variable. In this case the value member points to a node whose type is * TYPE_SYMTAB, whose interpret member is parameter_interpret(), whose * symboltable_part() member points to the symbol table of the corresponding * actual variable and whose sub[0] member points to a node that is the * corresponding actual variable (ie a name_interpret() node whose value field * is an ICL string whose value is the identity of the passed variable). * * If a value cannot be found, a suitable exception is returned. * * RETURNS AN ACTUAL VALUE STRUCTURE - IE A COPY OF ONE IN A * SYMBOL TABLE * ****************************************************************************** */ value lookfor_variable_value(symtab * sym, char *name) { node *var, *var2; if ((var = get_symbol(sym, name, SYM_VARIABLE)) != NODENIL) return var->val; else if ((var = get_symbol(sym, name, SYM_PARAMETER)) == NODENIL) return exception1("UNDEFVAR variable \"%s\" not defined", name); /* * do we have a parameter that was passed an expression ? */ else if (var->interpret != parameter_interpret) return var->val; else if ((var2 = get_passbyreferencevar(var)) != NODENIL) return var2->val; else return exception2( "UNDEFVAR Parameter \"%s\" is undefined variable \"%s\"", name, string_part(var->sub[0]->val)); }
int main(int argc, char *argv[]) { char cmd_buff[1024]; char *pinput; char *fname = argv[1]; char *mode = "r"; FILE *f= fopen(fname, mode); cmd_line *c, *backup; char* extra_buff; char* test = malloc(sizeof(char)*514); char buf[1024]; if(argv[2] != NULL){ /*if trying to run batch with 2 filenames*/ err(); exit(0); } if(f == NULL){ /*if read is invalid*/ err(); exit(0); } dw = getcwd(buf, 1024); /*for global var accessible to function calls*/ while (1) { /*INTERACTIVE MODE*/ if(argv[1] == NULL){ myPrint("myshell> "); pinput = fgets(cmd_buff, 100, stdin); c = parseCmdLine(cmd_buff); backup = c; while(backup != NULL){ processCmd(backup->c); backup = backup->next; } /*BATCH MODE*/ } else if(argv[1] != NULL){ memset(cmd_buff,'\0',514); pinput = fgets(cmd_buff, 514, f); if (!pinput) { /*invalid fgets*/ exit(0); } if((extra_buff = strstr(cmd_buff,"\n"))!=NULL) {/*check if whole command has been taken in*/ if (check_space(cmd_buff)==0) /*if all blank spaces, don't print*/ continue; else { myPrint(cmd_buff); /*print command*/ collapsed_str(cmd_buff,test); /*CATCH ERRORS RIGHT AWAY*/ if(exception1(test)==1){ err(); } else if(exception2(test)==1) { err(); } else if(exception3(test)==1) { continue; } /*PARSE*/ else { c = parseCmdLine(cmd_buff); backup = c; while(backup != NULL){ processCmd(backup->c); backup = backup->next; } free_cmdline(c); } } } /*COMMAND TOO LONG*/ if(extra_buff==NULL) { myPrint(cmd_buff); while(fgets(cmd_buff,1024,f)!=NULL) {/*keep getting more chars while you can*/ if((strlen(cmd_buff)<1023) || cmd_buff[1022]=='\n') { /*if new one is shorter than max, break*/ myPrint(cmd_buff); memset(cmd_buff, '\0', 1024); break; } else myPrint(cmd_buff); /*else keep getting*/ memset(cmd_buff, '\0', 1024); } err(); } } } free(test); fclose(f); return 0; }
void ERR30_2_f(void) throw( exception1) { // /* ... */ throw (exception1()); }