void show() { ifstream file; file.open("emp.txt",ios::binary); fflush(stdin); client ob1; int l; int total=0,tamt=0; if(!file) { cout<<"\n\n\n\t\t\t-*** NO RECORD PRESENT ***-\n"; return; } while(file.read((char *)&ob1,sizeof ob1)) { if(ob1.billamt==0) continue; cout<<endl; cout<<ob1.sno; l=cint(ob1.sno); for(int j=0;j<4-l+2;j++) cout<<" "; cout<<ob1.empcd<<" "; for(int k=0;ob1.ename[k]!='\0';k++) cout<<ob1.ename[k]; l=strlen(ob1.ename); for(j=0;j<13-l+7;j++) cout<<" "; for( k=0;ob1.desig[k]!='\0';k++) cout<<ob1.desig[k]; l=strlen(ob1.desig); for(j=0;j<11-l+7;j++) cout<<" "; cout<<ob1.billno; cout<<" "; cout<<ob1.billamt; l=cint(ob1.billamt); for(j=0;j<7-l+2;j++) cout<<" "; cout<<ob1.nrmt<<" "<<ob1.dcode; cout<<endl; total=total+1; tamt=tamt+ob1.billamt; } cout<<"\n\n\n\t"; cout<<"TOTAL NO OF EMPLOYEE= "<<total; cout<<"\n\n\tTOTAL AMOUNT= "<<tamt; file.close(); }
int c_changed_pos (struct changed_pos *cp0, struct changed_pos *cp1) { int c = cpos (&cp0->p, &cp1->p); if (c) return c; else return cint ((int *) &cp0->reason, (int *) &cp1->reason); }
void Shop::render(cint mousePos, vector<Pickup*>* inventory) { Shop::inStore = true; cint currentLocation; Console::print("Shop:", (tl_xres() - 6) * 2, (tl_yres() - 6) * 2 + 1); int length = inventory->size(); for (int i = 0; i < length; i++) { inventory->at(i)->inventoryPosition = i; tl_scale(1); currentLocation = cint(tl_xres() - 6 + (i % 6), tl_yres() - 5 + (i / 6)); if (mousePos == currentLocation) { tl_color(0xFF0000FF); tl_rendertile(0x125, currentLocation.X(), currentLocation.Y()); tl_color(0xFFFFFFFF); inventory->at(i)->describe(BUY); } else { tl_rendertile(0x116, currentLocation.X(), currentLocation.Y()); } tl_rendertile(inventory->at(i)->Tile(), currentLocation.X(), currentLocation.Y()); } }
void init_predicates(module_ref &m) { def_eq(m); def_eqv(m); def_exact(m); def_inexact(m); def_typecheck(m, "atom?", 1); def_typecheck(m, "number?", 2); def_typecheck(m, "null?", cint(m->getContext(), nil_t)); def_typecheck(m, "integer?", cint(m->getContext(), integer_t)); def_typecheck(m, "rational?", cint(m->getContext(), rational_t)); def_typecheck(m, "real?", cint(m->getContext(), real_t)); def_typecheck(m, "complex?", cint(m->getContext(), complex_t)); def_typecheck(m, "boolean?", cint(m->getContext(), boolean_t)); def_typecheck(m, "string?", cint(m->getContext(), string_t)); def_typecheck(m, "symbol?", cint(m->getContext(), symbol_t)); def_typecheck(m, "procedure?", cint(m->getContext(), function_t)); def_typecheck(m, "pair?", cint(m->getContext(), cell_t)); }
void client::dis1() { int j,l,k; cout<<empcd<<" "; for( k=0;ename[k]!='\0';k++) cout<<ename[k]; l=strlen(ename); for(j=0;j<13-l+2;j++) cout<<" "; for( k=0;dept[k]!='\0';k++) cout<<dept[k]; l=strlen(dept); for(j=0;j<11-l+1;j++) cout<<" "; cout<<nrmt<<" "<<dcode<<" "<<billno<<" "<<billamt; l=cint(billamt); cout<<setw(6-l+10); cout<<t.tm_mday<<"/"<<t.tm_mon<<"/"<<(t.tm_year+1900); cout<<endl; }
void MethodBuilder::import_args_19_style() { Value* local_i = counter2_; Value* loop_i = info_.counter(); Value* arg_ary = b().CreateLoad( b().CreateConstGEP2_32(info_.args(), 0, offset::args_ary, "arg_ary_pos"), "arg_ary"); // The variables used in the 4 phases. int P = vmm_->post_args; int M = vmm_->required_args - P; Value* T = arg_total; int DT = vmm_->total_args; int R = vmm_->required_args; int O = vmm_->total_args - R; int HS = vmm_->splat_position > 0 ? 1 : 0; // Phase 1, the manditories // 0 ... M for(int i = 0; i < M; i++) { Value* int_pos = cint(i); Value* arg_val_offset = b().CreateConstGEP1_32(arg_ary, i, "arg_val_offset"); Value* arg_val = b().CreateLoad(arg_val_offset, "arg_val"); Value* idx2[] = { cint(0), cint(offset::vars_tuple), int_pos }; Value* pos = b().CreateGEP(vars, idx2, "var_pos"); b().CreateStore(arg_val, pos); } // Phase 2, the post args // T-P ... T { BasicBlock* top = info_.new_block("arg_loop_top"); BasicBlock* body = info_.new_block("arg_loop_body"); BasicBlock* after = info_.new_block("arg_loop_cont"); // *loop_i = T-P b().CreateStore( b().CreateSub(T, ConstantInt::get(T->getType(), P)), loop_i); // *local_i = M+O+HS b().CreateStore( cint(M+O+HS), local_i); b().CreateBr(top); b().SetInsertPoint(top); // loop_val = *loop_i Value* loop_val = b().CreateLoad(loop_i, "loop_val"); // if(loop_val < T) { goto body } else { goto after } b().CreateCondBr( b().CreateICmpSLT(loop_val, T, "loop_test"), body, after); // Now, the body b().SetInsertPoint(body); // local_val = *local_i Value* local_val = b().CreateLoad(local_i, "local_val"); Value* idx2[] = { cint(0), cint(offset::vars_tuple), local_val }; // locals[local_idx] = args[loop_val] b().CreateStore( b().CreateLoad( b().CreateGEP(arg_ary, loop_val)), b().CreateGEP(vars, idx2)); // *loop_i = loop_val + 1 b().CreateStore( b().CreateAdd(loop_val, cint(1)), loop_i); // *local_i = local_val + 1; b().CreateStore( b().CreateAdd(local_val, cint(1)), local_i); b().CreateBr(top); b().SetInsertPoint(after); } // Phase 3 - optionals // M ... M + min(O, T-R) Value* Oval = cint(O); Value* left = b().CreateSub(T, ConstantInt::get(ls_->Int32Ty, R)); Value* limit = b().CreateAdd( cint(M), b().CreateSelect( b().CreateICmpSLT(Oval, left), Oval, left)); { BasicBlock* top = info_.new_block("opt_arg_loop_top"); BasicBlock* body = info_.new_block("opt_arg_loop_body"); BasicBlock* after = info_.new_block("opt_arg_loop_cont"); // *loop_i = M b().CreateStore(cint(M), loop_i); b().CreateBr(top); b().SetInsertPoint(top); // loop_val = *loop_i; Value* loop_val = b().CreateLoad(loop_i, "loop_val"); // if(loop_val < limit) { goto body; } else { goto after; } b().CreateCondBr( b().CreateICmpSLT(loop_val, limit, "loop_test"), body, after); // Now, the body b().SetInsertPoint(body); Value* idx2[] = { cint(0), cint(offset::vars_tuple), loop_val }; // locals[loop_val] = args[loop_val] b().CreateStore( b().CreateLoad( b().CreateGEP(arg_ary, loop_val)), b().CreateGEP(vars, idx2)); // *loop_i = loop_val + 1 b().CreateStore( b().CreateAdd(loop_val, cint(1)), loop_i); b().CreateBr(top); b().SetInsertPoint(after); } // Phase 4 - splat if(vmm_->splat_position >= 0) { Signature sig(ls_, "Object"); sig << "VM"; sig << "Arguments"; sig << ls_->Int32Ty; sig << ls_->Int32Ty; Value* call_args[] = { info_.vm(), info_.args(), cint(M + O), cint(DT) }; Function* func = sig.function("rbx_construct_splat"); func->setOnlyReadsMemory(true); func->setDoesNotThrow(true); CallInst* splat_val = sig.call("rbx_construct_splat", call_args, 4, "splat_val", b()); splat_val->setOnlyReadsMemory(true); splat_val->setDoesNotThrow(true); Value* idx3[] = { cint(0), cint(offset::vars_tuple), cint(vmm_->splat_position) }; Value* pos = b().CreateGEP(vars, idx3, "splat_pos"); b().CreateStore(splat_val, pos); } }
void MethodBuilder::initialize_frame(int stack_size) { Value* cm_gep = get_field(call_frame, offset::CallFrame::cm); method = b().CreateBitCast( exec, cast<llvm::PointerType>(cm_gep->getType())->getElementType(), "cm"); // previous b().CreateStore(info_.previous(), get_field(call_frame, offset::CallFrame::previous)); // arguments b().CreateStore(info_.args(), get_field(call_frame, offset::CallFrame::arguments)); // msg b().CreateStore( ConstantInt::getNullValue(ls_->Int8PtrTy), get_field(call_frame, offset::CallFrame::dispatch_data)); // cm b().CreateStore(method, cm_gep); // flags int flags = CallFrame::cJITed; if(!use_full_scope_) flags |= CallFrame::cClosedScope; b().CreateStore( cint(flags), get_field(call_frame, offset::CallFrame::flags)); // ip b().CreateStore( cint(0), get_field(call_frame, offset::CallFrame::ip)); // scope b().CreateStore(vars, get_field(call_frame, offset::CallFrame::scope)); // jit_data b().CreateStore( constant(info_.context().runtime_data_holder(), ls_->Int8PtrTy), get_field(call_frame, offset::CallFrame::jit_data)); if(ls_->include_profiling()) { Value* test = b().CreateLoad(ls_->profiling(), "profiling"); BasicBlock* setup_profiling = info_.new_block("setup_profiling"); BasicBlock* cont = info_.new_block("continue"); b().CreateCondBr(test, setup_profiling, cont); b().SetInsertPoint(setup_profiling); Signature sig(ls_, ls_->VoidTy); sig << "VM"; sig << llvm::PointerType::getUnqual(ls_->Int8Ty); sig << "Executable"; sig << "Module"; sig << "Arguments"; sig << "CompiledMethod"; Value* call_args[] = { info_.vm(), method_entry_, exec, module, info_.args(), method }; sig.call("rbx_begin_profiling", call_args, 6, "", b()); b().CreateBr(cont); b().SetInsertPoint(cont); } }
void MethodBuilder::check_arity() { Value* total_offset = b().CreateConstGEP2_32(info_.args(), 0, offset::args_total, "total_pos"); Value* total = b().CreateLoad(total_offset, "arg.total"); // For others to use. arg_total = total; BasicBlock* arg_error = info_.new_block("arg_error"); BasicBlock* cont = info_.new_block("import_args"); // Check arguments // // if there is a splat.. if(vmm_->splat_position >= 0) { if(vmm_->required_args > 0) { // Make sure we got at least the required args Value* cmp = b().CreateICmpSLT(total, cint(vmm_->required_args), "arg_cmp"); b().CreateCondBr(cmp, arg_error, cont); } else { // Only splat or optionals, no handling! b().CreateBr(cont); } // No splat, a precise number of args } else if(vmm_->required_args == vmm_->total_args) { // Make sure we got the exact number of arguments Value* cmp = b().CreateICmpNE(total, cint(vmm_->required_args), "arg_cmp"); b().CreateCondBr(cmp, arg_error, cont); // No splat, with optionals } else { Value* c1 = b().CreateICmpSLT(total, cint(vmm_->required_args), "arg_cmp"); Value* c2 = b().CreateICmpSGT(total, cint(vmm_->total_args), "arg_cmp"); Value* cmp = b().CreateOr(c1, c2, "arg_combine"); b().CreateCondBr(cmp, arg_error, cont); } b().SetInsertPoint(arg_error); // Call our arg_error helper Signature sig(ls_, "Object"); sig << "VM"; sig << "CallFrame"; sig << "Arguments"; sig << ls_->Int32Ty; Value* call_args[] = { info_.vm(), info_.previous(), info_.args(), cint(vmm_->total_args) }; Value* val = sig.call("rbx_arg_error", call_args, 4, "ret", b()); return_value(val); // Switch to using continuation b().SetInsertPoint(cont); }
void MethodBuilder::import_args() { setup_scope(); if(vmm_->post_args > 0) { import_args_19_style(); return; } // Import the arguments Value* offset = b().CreateConstGEP2_32(info_.args(), 0, offset::args_ary, "arg_ary_pos"); Value* arg_ary = b().CreateLoad(offset, "arg_ary"); // If there are a precise number of args, easy. if(vmm_->required_args == vmm_->total_args) { for(int i = 0; i < vmm_->required_args; i++) { Value* int_pos = cint(i); Value* arg_val_offset = b().CreateConstGEP1_32(arg_ary, i, "arg_val_offset"); Value* arg_val = b().CreateLoad(arg_val_offset, "arg_val"); Value* idx2[] = { cint(0), cint(offset::vars_tuple), int_pos }; Value* pos = b().CreateGEP(vars, idx2, "var_pos"); b().CreateStore(arg_val, pos); } // Otherwise, we must loop in the generate code because we don't know // how many they've actually passed in. } else { Value* loop_i = info_.counter(); BasicBlock* top = info_.new_block("arg_loop_top"); BasicBlock* body = info_.new_block("arg_loop_body"); BasicBlock* after = info_.new_block("arg_loop_cont"); Value* limit; // Because of a splat, there can be more args given than // vmm->total_args, so we need to use vmm->total_args as a max. if(vmm_->splat_position >= 0) { Value* static_total = cint(vmm_->total_args); limit = b().CreateSelect( b().CreateICmpSLT(static_total, arg_total), static_total, arg_total); } else { // Because of arity checks, arg_total is less than or equal // to vmm->total_args. limit = arg_total; } b().CreateStore(cint(0), loop_i); b().CreateBr(top); b().SetInsertPoint(top); // now at the top of block, check if we should continue... Value* loop_val = b().CreateLoad(loop_i, "loop_val"); Value* cmp = b().CreateICmpSLT(loop_val, limit, "loop_test"); b().CreateCondBr(cmp, body, after); // Now, the body b().SetInsertPoint(body); Value* arg_val_offset = b().CreateGEP(arg_ary, loop_val, "arg_val_offset"); Value* arg_val = b().CreateLoad(arg_val_offset, "arg_val"); Value* idx2[] = { cint(0), cint(offset::vars_tuple), loop_val }; Value* pos = b().CreateGEP(vars, idx2, "var_pos"); b().CreateStore(arg_val, pos); Value* plus_one = b().CreateAdd(loop_val, cint(1), "add"); b().CreateStore(plus_one, loop_i); b().CreateBr(top); b().SetInsertPoint(after); } // Setup the splat. if(vmm_->splat_position >= 0) { Signature sig(ls_, "Object"); sig << "VM"; sig << "Arguments"; sig << ls_->Int32Ty; sig << ls_->Int32Ty; Value* call_args[] = { info_.vm(), info_.args(), cint(vmm_->total_args), cint(vmm_->total_args) }; Function* func = sig.function("rbx_construct_splat"); func->setOnlyReadsMemory(true); func->setDoesNotThrow(true); CallInst* splat_val = sig.call("rbx_construct_splat", call_args, 4, "splat_val", b()); splat_val->setOnlyReadsMemory(true); splat_val->setDoesNotThrow(true); Value* idx3[] = { cint(0), cint(offset::vars_tuple), cint(vmm_->splat_position) }; Value* pos = b().CreateGEP(vars, idx3, "splat_pos"); b().CreateStore(splat_val, pos); } }
void init_symbols(module_ref &m) { def_symbols(m, nil_t, "nil", cint(m->getContext(), 0), ".symbol."); def_symbols(m, boolean_t, "#t", cint(m->getContext(), 1), ".bool."); def_symbols(m, boolean_t, "#f", cint(m->getContext(), 0), ".bool."); }
void photon_torpedoes(void) { /* @@@ int c2, c3, x3, y3, x5; */ int x3, y3, x5; string sTemp; double_t c1; if (p <= 0) { printf("All photon torpedoes expended\n"); return; } if (d[5] < 0.0) { printf("Photon Tubes not operational\n"); return; } printf("Course (0-9): "); reads(sTemp); printf("\n"); c1 = atof(sTemp); if (c1 == 9.0) c1 = 1.0; /* @@@ if (c1 < 0 || c1 > 9.0) */ if (c1 < 1.0 || c1 > 9.0) { printf("Ensign Chekov roports:\n"); printf(" Incorrect course data, sir!\n\n"); return; } e = e - 2; p--; /* @@@ c2 = cint(c1); */ /* @@@ c3 = c2 + 1; */ /* @@@ x1 = c[0][c2] + (c[0][c3] - c[0][c2]) * (c1 - c2); */ /* @@@ x2 = c[1][c2] + (c[1][c3] - c[1][c2]) * (c1 - c2); */ x1 = c[1][(int)c1] + (c[1][(int)c1 + 1] - c[1][(int)c1]) * (c1 - (int)c1); x2 = c[2][(int)c1] + (c[2][(int)c1 + 1] - c[2][(int)c1]) * (c1 - (int)c1); x = s1 + x1; y = s2 + x2; x3 = cint(x); /* @@@ note: this is a true integer round in the MS BASIC version */ y3 = cint(y); /* @@@ note: this is a true integer round in the MS BASIC version */ x5 = 0; printf("Torpedo Track:\n"); while (x3 >= 1 && x3 <= 8 && y3 >= 1 && y3 <= 8) { printf(" %d, %d\n", x3, y3); strcpy(sA, " "); z1 = x3; z2 = y3; string_compare(); if (z3 == 0) { torpedo_hit(); klingons_shoot(); return; } x = x + x1; y = y + x2; x3 = cint(x); /* @@@ note: this is a true integer round in the MS BASIC version */ y3 = cint(y); /* @@@ note: this is a true integer round in the MS BASIC version */ } printf("Torpedo Missed\n\n"); klingons_shoot(); }
void BlockBuilder::initialize_frame(int stack_size) { Value* cm_gep = get_field(call_frame, offset::CallFrame::cm); method = b().CreateLoad(get_field(block_env, offset::blockenv_code), "env.code"); // previous b().CreateStore(info_.previous(), get_field(call_frame, offset::CallFrame::previous)); // static_scope Value* ss = b().CreateLoad(get_field(block_inv, offset::blockinv_static_scope), "invocation.static_scope"); b().CreateStore(ss, get_field(call_frame, offset::CallFrame::static_scope)); // arguments b().CreateStore(info_.args(), get_field(call_frame, offset::CallFrame::arguments)); // msg b().CreateStore(Constant::getNullValue(ls_->Int8PtrTy), get_field(call_frame, offset::CallFrame::dispatch_data)); // cm b().CreateStore(method, cm_gep); // flags inv_flags_ = b().CreateLoad(get_field(block_inv, offset::blockinv_flags), "invocation.flags"); int block_flags = CallFrame::cCustomStaticScope | CallFrame::cMultipleScopes | CallFrame::cBlock | CallFrame::cJITed; if(!use_full_scope_) block_flags |= CallFrame::cClosedScope; Value* flags = b().CreateOr(inv_flags_, cint(block_flags), "flags"); b().CreateStore(flags, get_field(call_frame, offset::CallFrame::flags)); // ip b().CreateStore(cint(0), get_field(call_frame, offset::CallFrame::ip)); // scope b().CreateStore(vars, get_field(call_frame, offset::CallFrame::scope)); // top_scope top_scope = b().CreateLoad( get_field(block_env, offset::blockenv_top_scope), "env.top_scope"); b().CreateStore(top_scope, get_field(call_frame, offset::CallFrame::top_scope)); // jit_data b().CreateStore( constant(info_.context().runtime_data_holder(), ls_->Int8PtrTy), get_field(call_frame, offset::CallFrame::jit_data)); }
BasicBlock* InlineMethodBuilder::setup_inline(Value* self, Value* blk, std::vector<Value*>& stack_args) { llvm::Value* prev = info_.parent_call_frame(); llvm::Value* args = ConstantExpr::getNullValue(ctx_->ptr_type("Arguments")); BasicBlock* entry = BasicBlock::Create(ctx_->llvm_context(), "inline_entry", info_.function()); b().SetInsertPoint(entry); info_.set_args(args); info_.set_previous(prev); info_.set_entry(entry); BasicBlock* body = BasicBlock::Create(ctx_->llvm_context(), "method_body", info_.function()); pass_one(body); BasicBlock* alloca_block = &info_.function()->getEntryBlock(); Value* cfstk = new AllocaInst(obj_type, ConstantInt::get(ctx_->Int32Ty, (sizeof(CallFrame) / sizeof(Object*)) + machine_code_->stack_size), "cfstk", alloca_block->getTerminator()); call_frame = b().CreateBitCast( cfstk, llvm::PointerType::getUnqual(cf_type), "call_frame"); stk = b().CreateConstGEP1_32(cfstk, sizeof(CallFrame) / sizeof(Object*), "stack"); info_.set_call_frame(call_frame); info_.set_stack(stk); Value* var_mem = new AllocaInst(obj_type, ConstantInt::get(ctx_->Int32Ty, (sizeof(StackVariables) / sizeof(Object*)) + machine_code_->number_of_locals), "var_mem", alloca_block->getTerminator()); vars = b().CreateBitCast( var_mem, llvm::PointerType::getUnqual(stack_vars_type), "vars"); info_.set_variables(vars); Value* rd = constant(runtime_data_, ctx_->ptr_type("jit::RuntimeData")); // Setup the CallFrame // // previous b().CreateStore(prev, get_field(call_frame, offset::CallFrame::previous)); // msg b().CreateStore( b().CreatePointerCast(rd, ctx_->Int8PtrTy), get_field(call_frame, offset::CallFrame::dispatch_data)); // compiled_code method = b().CreateLoad( b().CreateConstGEP2_32(rd, 0, offset::jit_RuntimeData::method, "method_pos"), "compiled_code"); Value* code_gep = get_field(call_frame, offset::CallFrame::compiled_code); b().CreateStore(method, code_gep); // constant_scope Value* constant_scope = b().CreateLoad( b().CreateConstGEP2_32(method, 0, offset::CompiledCode::scope, "constant_scope_pos"), "constant_scope"); Value* constant_scope_gep = get_field(call_frame, offset::CallFrame::constant_scope); b().CreateStore(constant_scope, constant_scope_gep); // flags int flags = CallFrame::cInlineFrame; if(!use_full_scope_) flags |= CallFrame::cClosedScope; b().CreateStore(cint(flags), get_field(call_frame, offset::CallFrame::flags)); // ip b().CreateStore(cint(0), get_field(call_frame, offset::CallFrame::ip)); // scope b().CreateStore(vars, get_field(call_frame, offset::CallFrame::scope)); nil_stack(machine_code_->stack_size, constant(cNil, obj_type)); Value* mod = b().CreateLoad( b().CreateConstGEP2_32(rd, 0, offset::jit_RuntimeData::module, "module_pos"), "module"); setup_inline_scope(self, blk, mod); // We know the right arguments are present, so we just need to put them // in the right place. // // We don't support splat in an inlined method! assert(machine_code_->splat_position < 0); assert(stack_args.size() <= (size_t)machine_code_->total_args); for(size_t i = 0; i < stack_args.size(); i++) { Value* int_pos = cint(i); Value* idx2[] = { cint(0), cint(offset::StackVariables::locals), int_pos }; Value* pos = b().CreateGEP(vars, idx2, "local_pos"); Value* arg_val = stack_args.at(i); LocalInfo* li = info_.get_local(i); li->make_argument(); if(ctx_->llvm_state()->type_optz()) { if(type::KnownType::has_hint(ctx_, arg_val)) { type::KnownType kt = type::KnownType::extract(ctx_, arg_val); li->set_known_type(kt); } } b().CreateStore(arg_val, pos); } b().CreateBr(body); b().SetInsertPoint(body); return entry; }
void course_control(void) { int i; /* @@@ int c2, c3, q4, q5; */ int q4, q5; string sTemp; double_t c1; char sX[4] = "8"; printf("Course (0-9): "); reads(sTemp); printf("\n"); c1 = atof(sTemp); if (c1 == 9.0) c1 = 1.0; if (c1 < 0 || c1 > 9.0) { printf("Lt. Sulu roports:\n"); printf(" Incorrect course data, sir!\n\n"); return; } if (d[1] < 0.0) strcpy(sX, "0.2"); printf("Warp Factor (0-%s): ", sX); reads(sTemp); printf("\n"); w1 = atof(sTemp); if (d[1] < 0.0 && w1 > 0.21) { printf("Warp Engines are damaged. "); printf("Maximum speed = Warp 0.2.\n\n"); return; } if (w1 <= 0.0) return; if (w1 > 8.1) { printf("Chief Engineer Scott reports:\n"); printf(" The engines won't take warp %4.1f!\n\n", w1); return; } n = cint(w1 * 8.0); /* @@@ note: this is a real round in the original basic */ if (e - n < 0) { printf("Engineering reports:\n"); printf(" Insufficient energy available for maneuvering"); printf(" at warp %4.1f!\n\n", w1); if (s >= n && d[7] >= 0.0) { printf("Deflector Control Room acknowledges:\n"); printf(" %d units of energy presently deployed to shields.\n", s); } return; } klingons_move(); repair_damage(); strcpy(sA, " "); /* @@@ z1 = cint(s1); */ z1 = (int)s1; /* @@@ z2 = cint(s2); */ z2 = (int)s2; insert_in_quadrant(); /* @@@ c2 = cint(c1); */ /* @@@ c3 = c2 + 1; */ /* @@@ x1 = c[0][c2] + (c[0][c3] - c[0][c2]) * (c1 - c2); */ /* @@@ x2 = c[1][c2] + (c[1][c3] - c[1][c2]) * (c1 - c2); */ x1 = c[1][(int)c1] + (c[1][(int)c1 + 1] - c[1][(int)c1]) * (c1 - (int)c1); x2 = c[2][(int)c1] + (c[2][(int)c1 + 1] - c[2][(int)c1]) * (c1 - (int)c1); x = s1; y = s2; q4 = q1; q5 = q2; for (i = 1; i <= n; i++) { s1 = s1 + x1; s2 = s2 + x2; /* @@@ z1 = cint(s1); */ z1 = (int)s1; /* @@@ z2 = cint(s2); */ z2 = (int)s2; if (z1 < 1 || z1 >= 9 || z2 < 1 || z2 >= 9) { exceed_quadrant_limits(); complete_maneuver(); return; } string_compare(); if (z3 != 1) /* Sector not empty */ { s1 = s1 - x1; s2 = s2 - x2; printf("Warp Engines shut down at sector "); printf("%d, %d due to bad navigation.\n\n", z1, z2); i = n + 1; } } complete_maneuver(); }
void torpedo_hit(void) { int i, x3, y3; x3 = cint(x); /* @@@ note: this is a true integer round in the MS BASIC version */ y3 = cint(y); /* @@@ note: this is a true integer round in the MS BASIC version */ z3 = 0; strcpy(sA, " * "); string_compare(); if (z3 == 1) { printf("Star at %d, %d absorbed torpedo energy.\n\n", x3, y3); return; } strcpy(sA, "+K+"); string_compare(); if (z3 == 1) { printf("*** Klingon Destroyed ***\n\n"); k3--; k9--; if (k9 <= 0) won_game(); for (i=0; i<=3; i++) if (x3 == k[i][1] && y3 == k[i][2]) k[i][3] = 0; } strcpy(sA, ">!<"); string_compare(); if (z3 == 1) { printf("*** Starbase Destroyed ***\n"); b3--; b9--; if (b9 <= 0 && k9 <= t - t0 - t9) { printf("That does it, Captain!!"); printf("You are hereby relieved of command\n"); printf("and sentanced to 99 stardates of hard"); printf("labor on Cygnus 12!!\n"); resign_commision(); } printf("Starfleet Command reviewing your record to consider\n"); printf("court martial!\n\n"); d0 = 0; /* Undock */ } z1 = x3; z2 = y3; strcpy(sA," "); insert_in_quadrant(); g[q1][q2] = (k3 * 100) + (b3 * 10) + s3; z[q1][q2] = g[q1][q2]; }
void BlockBuilder::import_args_19_style() { if(vmm_->required_args > 1) { Value* lambda_check = b().CreateICmpEQ( b().CreateAnd( inv_flags_, ConstantInt::get(inv_flags_->getType(), CallFrame::cIsLambda)), ConstantInt::get(inv_flags_->getType(), 0)); BasicBlock* destruct = BasicBlock::Create(ls_->ctx(), "destructure", info_.function()); BasicBlock* cont = BasicBlock::Create(ls_->ctx(), "arg_loop_body", info_.function()); b().CreateCondBr(lambda_check, destruct, cont); b().SetInsertPoint(destruct); Signature sig(ls_, "Object"); sig << "VM"; sig << "CallFrame"; sig << "Arguments"; Value* call_args[] = { info_.vm(), info_.call_frame(), info_.args() }; Value* val = sig.call("rbx_destructure_args", call_args, 3, "", b()); Value* null = Constant::getNullValue(val->getType()); Value* is_null = b().CreateICmpEQ(val, null); info_.add_return_value(null, b().GetInsertBlock()); b().CreateCondBr(is_null, info_.return_pad(), cont); b().SetInsertPoint(cont); } Value* local_i = counter2_; Value* loop_i = info_.counter(); Value* arg_ary = b().CreateLoad( b().CreateConstGEP2_32(info_.args(), 0, offset::args_ary), "arg_ary"); // The variables used in the 4 phases. int P = vmm_->post_args; Value* Pv = cint(P); int R = vmm_->required_args; int M = R - P; Value* Mv = cint(M); Value* T = b().CreateLoad( b().CreateConstGEP2_32(info_.args(), 0, offset::args_total), "args.total"); int DT = vmm_->total_args; Value* DTv = cint(DT); int O = DT - R; Value* Ov = cint(O); int HS = vmm_->splat_position > 0 ? 1 : 0; Value* CT = HS ? T : b().CreateSelect(b().CreateICmpSLT(T, DTv), T, DTv); Value* Z = b().CreateSub(CT, cint(M)); Value* U = b().CreateSub(Z, cint(P)); // Phase 1, the mandatories // 0 ... min(M,T) { BasicBlock* top = info_.new_block("mand_loop_top"); BasicBlock* body = info_.new_block("mand_loop_body"); BasicBlock* after = info_.new_block("mand_loop_cont"); // limit = min(M,T) Value* limit = b().CreateSelect(b().CreateICmpSLT(Mv, T), Mv, T); // *loop_i = T-P b().CreateStore(cint(0), loop_i); b().CreateBr(top); b().SetInsertPoint(top); // loop_val = *loop_i Value* loop_val = b().CreateLoad(loop_i, "loop_val"); // if(loop_val < T) { goto body } else { goto after } b().CreateCondBr( b().CreateICmpSLT(loop_val, limit, "loop_test"), body, after); // Now, the body b().SetInsertPoint(body); Value* idx2[] = { cint(0), cint(offset::vars_tuple), loop_val }; // locals[loop_val] = args[loop_val] b().CreateStore( b().CreateLoad( b().CreateGEP(arg_ary, loop_val)), b().CreateGEP(vars, idx2, idx2+3)); // *loop_i = loop_val + 1 b().CreateStore( b().CreateAdd(loop_val, cint(1)), loop_i); b().CreateBr(top); b().SetInsertPoint(after); } // Phase 2, the post args // CT - min(Z,P) ... CT { BasicBlock* top = info_.new_block("post_loop_top"); BasicBlock* body = info_.new_block("post_loop_body"); BasicBlock* after = info_.new_block("post_loop_cont"); // *loop_i = CT - min(Z,P) b().CreateStore( b().CreateSub( CT, b().CreateSelect(b().CreateICmpSLT(Z, Pv), Z, Pv)), loop_i); // *local_i = M+O+HS b().CreateStore( cint(M+O+HS), local_i); b().CreateBr(top); b().SetInsertPoint(top); // loop_val = *loop_i Value* loop_val = b().CreateLoad(loop_i, "loop_val"); // if(loop_val < T) { goto body } else { goto after } b().CreateCondBr( b().CreateICmpSLT(loop_val, CT, "loop_test"), body, after); // Now, the body b().SetInsertPoint(body); // local_val = *local_i Value* local_val = b().CreateLoad(local_i, "local_val"); Value* idx2[] = { cint(0), cint(offset::vars_tuple), local_val }; // locals[local_idx] = args[loop_val] b().CreateStore( b().CreateLoad( b().CreateGEP(arg_ary, loop_val)), b().CreateGEP(vars, idx2, idx2+3)); // *loop_i = loop_val + 1 b().CreateStore( b().CreateAdd(loop_val, cint(1)), loop_i); // *local_i = local_val + 1; b().CreateStore( b().CreateAdd(local_val, cint(1)), local_i); b().CreateBr(top); b().SetInsertPoint(after); } // Phase 3 - optionals // M ... M + min(O, U) { BasicBlock* top = info_.new_block("opt_arg_loop_top"); BasicBlock* body = info_.new_block("opt_arg_loop_body"); BasicBlock* after = info_.new_block("opt_arg_loop_cont"); Value* limit = b().CreateAdd( Mv, b().CreateSelect(b().CreateICmpSLT(Ov, U), Ov, U)); // *loop_i = M b().CreateStore(Mv, loop_i); b().CreateBr(top); b().SetInsertPoint(top); // loop_val = *loop_i; Value* loop_val = b().CreateLoad(loop_i, "loop_val"); // if(loop_val < limit) { goto body; } else { goto after; } b().CreateCondBr( b().CreateICmpSLT(loop_val, limit, "loop_test"), body, after); // Now, the body b().SetInsertPoint(body); Value* idx2[] = { cint(0), cint(offset::vars_tuple), loop_val }; // locals[loop_val] = args[loop_val] b().CreateStore( b().CreateLoad( b().CreateGEP(arg_ary, loop_val)), b().CreateGEP(vars, idx2, idx2+3)); // *loop_i = loop_val + 1 b().CreateStore( b().CreateAdd(loop_val, cint(1)), loop_i); b().CreateBr(top); b().SetInsertPoint(after); } // Phase 4 - splat if(vmm_->splat_position >= 0) { Signature sig(ls_, "Object"); sig << "VM"; sig << "Arguments"; sig << ls_->Int32Ty; sig << ls_->Int32Ty; Value* call_args[] = { info_.vm(), info_.args(), cint(M + O), cint(DT) }; Function* func = sig.function("rbx_construct_splat"); func->setOnlyReadsMemory(true); func->setDoesNotThrow(true); CallInst* splat_val = sig.call("rbx_construct_splat", call_args, 4, "splat_val", b()); splat_val->setOnlyReadsMemory(true); splat_val->setDoesNotThrow(true); Value* idx3[] = { cint(0), cint(offset::vars_tuple), cint(vmm_->splat_position) }; Value* pos = b().CreateGEP(vars, idx3, idx3+3, "splat_pos"); b().CreateStore(splat_val, pos); } }
main() { double ans, exact, err; int m; double eps = 1.0e-6; double a = 0.0; double b = PI; int n_jac = 12; std::vector<double> x_jac(n_jac); std::vector<double> w_jac(n_jac); gauss_jacobi(x_jac, w_jac, n_jac, 1.5, -0.5); printf("\n\n Abscissas and wights from gauss_jacobi with alpha = 1.5, beta = -0.5.\n"); for (int i = 0; i < n_jac; ++i) printf("\n x[%d] = %16.12f w[%d] = %16.12f", i, x_jac[i], i, w_jac[i]); int n_leg = 12; std::vector<double> x_leg(n_leg); std::vector<double> w_leg(n_leg); gauss_legendre(n_leg, a, b, x_leg, w_leg); printf("\n\n Abscissas and wights from gauss_legendre.\n"); for (int i = 0; i < n_leg; ++i) printf("\n x[%d] = %16.12f w[%d] = %16.12f", i, x_leg[i] / PIO2 - 1.0, i, w_leg[i] / PIO2); int n_jac2 = 12; std::vector<double> x_jac2(n_jac2); std::vector<double> w_jac2(n_jac2); gauss_jacobi(x_jac2, w_jac2, n_jac2, 0.0, 0.0); printf("\n\n Abscissas and wights from gauss_jacobi with alpha = beta = 0.0.\n"); for (int i = 0; i < n_jac2; ++i) printf("\n x[%d] = %16.12f w[%d] = %16.12f", i, x_jac2[i], i, w_jac2[i]); int n_cheb = 12; std::vector<double> x_cheb(n_cheb); std::vector<double> w_cheb(n_cheb); gauss_chebyshev(x_cheb, w_cheb, n_cheb); printf("\n\n Abscissas and wights from gauss_chebyshev.\n"); for (int i = 0; i < (n_cheb + 1) / 2; ++i) printf("\n x[%d] = -x[%d] = %16.12f w[%d] = w[%d] = %16.12f", i, n_cheb + 1 - i , x_cheb[i], i, n_cheb + 1 - i, w_cheb[i]); int n_jac3 = 12; std::vector<double> x_jac3(n_jac3); std::vector<double> w_jac3(n_jac3); gauss_jacobi(x_jac3, w_jac3, n_jac3, -0.5, -0.5); printf("\n\n Abscissas and wights from gauss_jacobi with alpha = beta = -0.5.\n"); for (int i = 0; i < n_jac3; ++i) printf("\n x[%d] = %16.12f w[%d] = %16.12f", i, x_jac3[i], i, w_jac3[i]); int n_herm = 12; std::vector<double> x_herm(n_herm); std::vector<double> w_herm(n_herm); gauss_hermite(x_herm, w_herm, n_herm); printf("\n\n Abscissas and wights from gauss_hermite.\n"); for (int i = 0; i < (n_herm + 1) / 2; ++i) printf("\n x[%d] = -x[%d] = %16.12f w[%d] = w[%d] = %16.12f", i, n_herm + 1 - i , x_herm[i], i, n_herm + 1 - i, w_herm[i]); n_lag = 12; std::vector<double> x_lag(n_lag); std::vector<double> w_lag(n_lag); gauss_laguerre(x_lag, w_lag, n_lag, 1.0); printf("\n\n Abscissas and wights from gauss_laguerre.\n"); for (int i = 0; i < n_lag; ++i) printf("\n x[%d] = %16.12f w[%d] = %16.12f", i , x_lag[i], i, w_lag[i]); m = 40; std::vector<double> c(m); std::vector<double> cint(m); std::vector<double> cder(m); printf("\n\n\n\n Test of integration routines..."); printf("\n\n"); printf("\n\n %-40s %g", "Input requested error", eps); printf("\n\n %-40s %d", "Input order of Gaussian quadrature", n_leg); printf("\n\n %-40s %d", "Input order of Chebyshev fit", m); printf("\n\n"); a = 0.0; b = PI; printf("\n\n Integrate cos(x) from a = %f to b = %f . . .", a, PI); exact = 0.0; printf("\n %-40s %16.12f", "Exact answer", exact); ans = quad_trapezoid(std::cos, a, b, eps); err = ans - exact; printf("\n %-40s %16.12f %16.12f", "Trapezoid rule", ans, err); ans = quad_simpson(std::cos, a, b, eps); err = ans - exact; printf("\n %-40s %16.12f %16.12f", "Simpson's rule", ans, err); ans = quad_romberg(std::cos, a, b, eps); err = ans - exact; printf("\n %-40s %16.12f %16.12f", "Romberg integration", ans, err); gauss_legendre(n_leg, a, b, x_leg, w_leg); ans = quad_gauss_legendre(std::cos, x_leg, w_leg, n_leg); err = ans - exact; printf("\n %-40s %16.12f %16.12f", "Gauss - Legendre quadrature", ans, err); chebyshev_fit(a, b, c, m, cos); chebyshev_integ(a, b, c, cint, m); ans = chebyshev_eval(a, b, cint, m, b); err = ans - exact; printf("\n %-40s %16.12f %16.12f", "Chebyshev evaluation of integral", ans, err); ans = clenshaw_curtis_quad(a, b, c, m, eps); err = ans - exact; printf("\n %-40s %16.12f %16.12f", "Clenshaw - Curtis quadrature", ans, err); a = 0.0; b = PI; printf("\n\n Integrate sin(x) from a = %f to b = %f . . .", a, b); exact = 2.0; printf("\n %-40s %16.12f", "Exact answer", exact); ans = quad_trapezoid(sin, a, b, eps); err = ans - exact; printf("\n %-40s %16.12f %16.12f", "Trapezoid rule", ans, err); ans = quad_simpson(sin, a, b, eps); err = ans - exact; printf("\n %-40s %16.12f %16.12f", "Simpson's rule", ans, err); ans = quad_romberg(sin, a, b, eps); err = ans - exact; printf("\n %-40s %16.12f %16.12f", "Romberg integration", ans, err); gauss_legendre(n_leg, a, b, x_leg, w_leg); ans = quad_gauss_legendre(sin, x_leg, w_leg, n_leg); err = ans - exact; printf("\n %-40s %16.12f %16.12f", "Gauss - Legendre quadrature", ans, err); chebyshev_fit(a, b, c, m, sin); chebyshev_integ(a, b, c, cint, m); ans = chebyshev_eval(a, b, cint, m, b); err = ans - exact; printf("\n %-40s %16.12f %16.12f", "Chebyshev evaluation of integral", ans, err); ans = clenshaw_curtis_quad(a, b, c, m, eps); err = ans - exact; printf("\n %-40s %16.12f %16.12f", "Clenshaw - Curtis quadrature", ans, err); a = 0.0; b = PI; printf("\n\n Integrate cos^2(x) from a = %f to b = %f . . .", a, b); exact = PI/2.0; printf("\n %-40s %16.12f", "Exact answer", exact); ans = quad_trapezoid(cos2, a, b, eps); err = ans - exact; printf("\n %-40s %16.12f %16.12f", "Trapezoid rule", ans, err); ans = quad_simpson(cos2, a, b, eps); err = ans - exact; printf("\n %-40s %16.12f %16.12f", "Simpson's rule", ans, err); ans = quad_romberg(cos2, a, b, eps); err = ans - exact; printf("\n %-40s %16.12f %16.12f", "Romberg integration", ans, err); gauss_legendre(n_leg, a, b, x_leg, w_leg); ans = quad_gauss_legendre(cos2, x_leg, w_leg, n_leg); err = ans - exact; printf("\n %-40s %16.12f %16.12f", "Gauss - Legendre quadrature", ans, err); chebyshev_fit(a, b, c, m, cos2); chebyshev_integ(a, b, c, cint, m); ans = chebyshev_eval(a, b, cint, m, b); err = ans - exact; printf("\n %-40s %16.12f %16.12f", "Chebyshev evaluation of integral", ans, err); ans = clenshaw_curtis_quad(a, b, c, m, eps); err = ans - exact; printf("\n %-40s %16.12f %16.12f", "Clenshaw - Curtis quadrature", ans, err); a = 0.0; b = PI; printf("\n\n Integrate sin^2(x) from a = %f to b = %f . . .", a, b); exact = PI/2.0; printf("\n %-40s %16.12f", "Exact answer", exact); ans = quad_trapezoid(sin2, a, b, eps); err = ans - exact; printf("\n %-40s %16.12f %16.12f", "Trapezoid rule", ans, err); ans = quad_simpson(sin2, a, b, eps); err = ans - exact; printf("\n %-40s %16.12f %16.12f", "Simpson's integral", ans, err); ans = quad_romberg(sin2, a, b, eps); err = ans - exact; printf("\n %-40s %16.12f %16.12f", "Romberg integration", ans, err); gauss_legendre(n_leg, a, b, x_leg, w_leg); ans = quad_gauss_legendre(sin2, x_leg, w_leg, n_leg); err = ans - exact; printf("\n %-40s %16.12f %16.12f", "Gauss - Legendre quadrature", ans, err); chebyshev_fit(a, b, c, m, sin2); chebyshev_integ(a, b, c, cint, m); ans = chebyshev_eval(a, b, cint, m, b); err = ans - exact; printf("\n %-40s %16.12f %16.12f", "Chebyshev evaluation of integral", ans, err); ans = clenshaw_curtis_quad(a, b, c, m, eps); err = ans - exact; printf("\n %-40s %16.12f %16.12f", "Clenshaw - Curtis quadrature", ans, err); a = 0.0; b = PI; printf("\n\n Integrate J_1(x) from a = %f to b = %f . . .", a, b); exact = bessel_j0(0.0) - bessel_j0(PI); printf("\n %-40s %16.12f", "Exact answer", exact); ans = quad_trapezoid(bessel_j1, a, b, eps); err = ans - exact; printf("\n %-40s %16.12f %16.12f", "Trapezoid rule", ans, err); ans = quad_simpson(bessel_j1, a, b, eps); err = ans - exact; printf("\n %-40s %16.12f %16.12f", "Simpson's integral", ans, err); ans = quad_romberg(bessel_j1, a, b, eps); err = ans - exact; printf("\n %-40s %16.12f %16.12f", "Romberg integration", ans, err); gauss_legendre(n_leg, a, b, x_leg, w_leg); ans = quad_gauss_legendre(bessel_j1, x_leg, w_leg, n_leg); err = ans - exact; printf("\n %-40s %16.12f %16.12f", "Gauss - Legendre quadrature", ans, err); chebyshev_fit(a, b, c, m, bessel_j1); chebyshev_integ(a, b, c, cint, m); chebyshev_deriv(a, b, c, cder, m); ans = chebyshev_eval(a, b, cint, m, b); err = ans - exact; printf("\n %-40s %16.12f %16.12f", "Chebyshev evaluation of integral", ans, err); ans = clenshaw_curtis_quad(a, b, c, m, eps); err = ans - exact; printf("\n %-40s %16.12f %16.12f", "Clenshaw - Curtis quadrature", ans, err); a = 0.0; b = 10.0*PI; printf("\n\n Integrate foo(x) = (1 - x)exp(-x/2) from a = %f to b = %f . . .", a, b); exact = 2.0*(1.0 + b)*exp(-b/2.0) - 2.0*(1.0 + a)*exp(-a/2.0); printf("\n %-40s %16.12f", "Exact answer", exact); ans = quad_trapezoid(foo, a, b, eps); err = ans - exact; printf("\n %-40s %16.12f %16.12f", "Trapezoid rule", ans, err); ans = quad_simpson(foo, a, b, eps); err = ans - exact; printf("\n %-40s %16.12f %16.12f", "Simpson's rule", ans, err); ans = quad_romberg_open(foo, a, b, eps, midpoint_exp); err = ans - exact; printf("\n %-40s %16.12f %16.12f", "Open Romberg integration", ans, err); gauss_legendre(n_leg, a, b, x_leg, w_leg); ans = quad_gauss_legendre(foo, x_leg, w_leg, n_leg); err = ans - exact; printf("\n %-40s %16.12f %16.12f", "Gauss - Legendre quadrature", ans, err); gauss_laguerre(x_lag, w_lag, n_lag, 0.0); ans = 0.0; for (int i = 0; i < n_lag; ++i) ans += 2 * w_lag[i] * foonum(2.0 * x_lag[i]); err = ans - exact; printf("\n %-40s %16.12f %16.12f", "Gauss - Laguerre quadrature", ans, err); chebyshev_fit(a, b, c, m, foo); chebyshev_integ(a, b, c, cint, m); chebyshev_deriv(a, b, c, cder, m); ans = chebyshev_eval(a, b, cint, m, b); err = ans - exact; printf("\n %-40s %16.12f %16.12f", "Chebyshev evaluation of integral", ans, err); ans = clenshaw_curtis_quad(a, b, c, m, eps); err = ans - exact; printf("\n %-40s %16.12f %16.12f", "Clenshaw - Curtis quadrature", ans, err); a = 0.0; b = PI; printf("\n\n Integrate funk1(x) = cos(x)/sqrt(x(PI - x)) from a = %f to b = %f . . .", a, b); exact = 0.0; printf("\n %-40s %16.12f", "Exact answer", exact); ans = quad_romberg_open(funk1, a, b, eps, midpoint); err = ans - exact; printf("\n %-40s %16.12f %16.12f", "Open Romberg quadrature with midpoint", ans, err); ans = quad_romberg_open(funk1, a, (a+b)/2, eps, midpoint_inv_sqrt_lower) + quad_romberg_open(funk1, (a+b)/2, b, eps, midpoint_inv_sqrt_upper); err = ans - exact; printf("\n %-40s %16.12f %16.12f", "Open Romberg with inverse sqrt step", ans, err); gauss_legendre(n_leg, a, b, x_leg, w_leg); ans = quad_gauss_legendre(funk1, x_leg, w_leg, n_leg); err = ans - exact; printf("\n %-40s %16.12f %16.12f", "Gauss - Legendre quadrature", ans, err); ans = quad_gauss(funk1num, a, b, x_cheb, w_cheb, n_cheb); err = ans - exact; printf("\n %-40s %16.12f %16.12f", "Gauss - Chebyshev quadrature", ans, err); ans = quad_gauss(funk1num, a, b, x_jac, w_jac, n_jac); err = ans - exact; printf("\n %-40s %16.12f %16.12f", "Gauss - Jacobi quadrature", ans, err); chebyshev_fit(a, b, c, m, funk1); chebyshev_integ(a, b, c, cint, m); ans = chebyshev_eval(a, b, cint, m, b); err = ans - exact; printf("\n %-40s %16.12f %16.12f", "Chebyshev evaluation of integral", ans, err); ans = dumb_gauss_crap(funk1num, a, b, 8); err = ans - exact; printf("\n %-40s %16.12f %16.12f", "Gauss - Chebyshev quadrature", ans, err); printf("\n\n"); plot_func(funk1, a+0.1, b-0.1, "", "", "", ""); a = 0.0; b = PI; printf("\n\n Integrate funk2(x) = (2.0+sin(x))/sqrt(x(PI - x)) from a = %f to b = %f . . .", a, b); exact = 0.0; printf("\n %-40s %16.12f", "Exact answer", exact); ans = quad_romberg_open(funk2, a, b, eps, midpoint); err = ans - exact; printf("\n %-40s %16.12f %16.12f", "Open Romberg quadrature with midpoint", ans, err); ans = quad_romberg_open(funk2, a, (a+b)/2, eps, midpoint_inv_sqrt_lower) + quad_romberg_open(funk2, (a+b)/2, b, eps, midpoint_inv_sqrt_upper); err = ans - exact; printf("\n %-40s %16.12f %16.12f", "Open Romberg with inverse sqrt step", ans, err); gauss_legendre(n_leg, a, b, x_leg, w_leg); ans = quad_gauss_legendre(funk2, x_leg, w_leg, n_leg); err = ans - exact; printf("\n %-40s %16.12f %16.12f", "Gauss - Legendre quadrature", ans, err); ans = quad_gauss(funk2num, a, b, x_cheb, w_cheb, n_cheb); err = ans - exact; printf("\n %-40s %16.12f %16.12f", "Gauss - Chebyshev quadrature", ans, err); ans = quad_gauss(funk2num, a, b, x_jac, w_jac, n_jac); err = ans - exact; printf("\n %-40s %16.12f %16.12f", "Gauss - Jacobi quadrature", ans, err); chebyshev_fit(a, b, c, m, funk2); chebyshev_integ(a, b, c, cint, m); ans = chebyshev_eval(a, b, cint, m, b); err = ans - exact; printf("\n %-40s %16.12f %16.12f", "Chebyshev evaluation of integral", ans, err); ans = dumb_gauss_crap(funk2num, a, b, 8); err = ans - exact; printf("\n %-40s %16.12f %16.12f", "Adaptive Gauss - Chebyshev quadrature", ans, err); printf("\n\n"); plot_func(funk2, a+0.1, b-0.1, "", "", "", ""); printf("\n\n"); }
int main(int argc, char **argv) { short mode=0; short i,j; //incrementers short p,t; //# of users stated in profile.dat(first 2 char),timeout char c; //getc buffer const char default_filename_profile[]="profile.dat\n"; char arr_status[]={ 'C','u','r','r','e','n','t','l','y',0x20,'O','f','f','l','i','n','e',0x0, 'C','u','r','r','e','n','t','l','y',0x20,'O','n','l','i','n','e',0x0, 'C','u','r','r','e','n','t','l','y',0x20,'I','n','-','G','a','m','e',0x0, 'T','e','a','m',0x20,'F','o','r','t','r','e','s','s',0x20,'2',0x0, 'e','r','r','o','r',0x0}; char **status; //{"Currently Offline\0","Currently Online\0","Currently In-Game\0","Team Fortress 2\0","error\0"}; char compare[3][40]={"<div class=\"profile_in_game_header\">\0","<div class=\"profile_in_game_name\">\0","<a href=\"steam://connect\0"}; char *filename_profile; void (*get_html)(char*,FILE*)=&vinyl_get_html; //use program's html-protocol //head *(filename_profile+0)=(char)(&default_filename_profile[0]); status=malloc(5*sizeof(char)); j=0; for(i=0;i<5;i++) { do { j++; }while(arr_status[j]!=0x0); j++; *(status+i)=&arr_status[j]; } if(argc>1 || *(*(argv+1)+0)=='-') { for(i=1;i<clen(*(argv+1));i++) { switch(*(*(argv+1)+i)) { case 'c': (*get_html)(char*)=&scratch_get_html; break; //use curl case 'l': mode+=1; break; //don't log: 1,3,5,7,9,11,13,15 case 'i': mode+=2; break; //interactive: 2,3,6,7,10,11,14,15 case 's': mode+=4; break; //silent: 4,5,6,7,12,13,14,15 case 'j': mode+=8; break; //join game: 8,9,10,11,12,13,14,15 case 'o': goto options; //options: timeout,profile file } } } goto headend; options:; for(i=2;i<argc;i+=2) { switch(*(*(argv+i)+1)) { case 't': t=cint(*(argv+i+1)); break; case 'f': filename_profile=&*(*(argv+i+1)); break; } } headend:; FILE *fpro = fopen(filename_profile,"r"); void *tmp=malloc(3*sizeof(char)); *(&tmp+(0*sizeof(char)))=getc(fpro); *(&tmp+(1*sizeof(char)))=getc(fpro); //to use as value: (char*)*((&tmp)+1*sizeof(char)); *(&tmp+(2*sizeof(char)))=0x0; p=(cint(tmp)); free(tmp); struct struct_profile *profile[p]; struct struct_memStream *memstream[p]; for(i=p;i!=0;i--) { profile[i]=malloc(sizeof(struct struct_profile)); profile[i]->status=-1; //uninitialized profile[i]->name=malloc(25*sizeof(char)); profile[i]->url=malloc(100*sizeof(char)); while(getc(fpro)!='\n'); //go to next line //set name j=0; c=getc(fpro); do { *(profile[i]->name+j)=c; j++; c=getc(fpro); }while(c!='\n'); //set url j=0; c=getc(fpro); do { *(profile[i]->url+j)=c; j++; c=getc(fpro); }while(c!='\n'); memstream[i]=malloc(sizeof(struct struct_memStream)); memstream[i]->buffer=0x0; memstream[i]->stream=open_memStream(&(memstream[i]->buffer),&(memstream[i]->size)); } //body while(0) { for(i=p;i!=0;i--) { (*get_html)(&profile[i]->url,&memstream[i]->stream); //read stream while(j!=430) { c=getc(memstream[i]->stream); if(c=='\n') j++; } j=0; c=getc(memstream[i]->stream); while(c!=EOF) { if(c==compare[0][j]) { j++; if(compare[0][j]==0x0) goto gud; } else j=0; c=getc(memstream[i]->stream); } printf("error could not find %s\n",compare[0]); gud:; c=getc(memstream[i]->stream); while(c!="<") { //if() c=getc(memstream[i]->stream); } //log //actions #if defined (WIN32) //windows #elif defined (__unix__) //unix #endif } } return 0; }
int main(int argc, char *argv[]) { char file[255]; options_type opt; char *data; char *mask = NULL; unsigned int mask_len = 0; unsigned int word_size; char *min_str; int control; int control_c_rep_impar = 0; unsigned int i, j, o; int err; int time_min; FILE *idf; char *buffer; char *data_hex = NULL; char *data_hex2 = NULL; char *mask_hex = NULL; unsigned int c_hex = 0; unsigned int mask_hex_len = 0; double file_pre_size_mb; opt.n = 0; opt.mask_c = 0; opt.mask_c_on = 0; opt.h_on = 0; opt.h = 0; opt.r = 0; opt.min = 0; opt.max = 0; opt.c = 0; opt.q = 0; opt.rep = 0; time_seg=0; //sin argumentos o con -? muestra el menu if (argc<=1) { mostrarmenu(); return 0; } if (strcmp(argv[1],"-?")==0) { mostrarmenu(); return 0; } //Establecer archivo de salida strcpy(file,argv[1]); //Establecer opciones de los argumentos for(o=2;o<argc;o++) { if (strcmp(argv[o],"-?")==0) { mostrarmenu(); return 0; } else if (strcmp(argv[o],"-n")==0) { if (opt.n!=0) { printf("\nParametro %c-n%c repetido o especificado junto con el parámetro incompatible %c-m%c\n",34,34,34,34); return 1; } if ((o+1)>=argc) { opt.n=13; //(128-24)/8; } else { opt.n=cint(argv[o+1],&err,0); if (err) { opt.n=13; //(128-24)/8; } else { if (!((opt.n==64) || (opt.n==128) || (opt.n==152) || (opt.n==256) || (opt.n==512))) { printf("\nEl parametro de %c-n%c es incorrecto\n",34,34); return 1; } opt.n=(opt.n-24)/8; o++; } } } else if (strcmp(argv[o],"-m")==0) { if (opt.n!=0) { printf("\nParametro %c-m%c repetido o especificado junto con el parámetro incompatible %c-n%c\n",34,34,34,34); return 1; } if ((o+1)>=argc) { printf("\nFalta el parametro de %c-m%c\n",34,34); return 1; } opt.n=cint(argv[o+1],&err,0); if ((err) || (opt.n<=0)) { printf("\nEl parametro de %c-m%c es incorrecto\n",34,34); return 1; } o++; } else if (strcmp(argv[o],"-h")==0) { if (opt.h_on) { printf("\nParametro %c-h%c repetido\n",34,34); return 1; } opt.h_on=1; opt.h=':'; if (!((o+1)>=argc)) { if ((cint(argv[o+1],&err,0)<0) || (cint(argv[o+1],&err,0)>255) || ((cint(argv[o+1],&err,0)>47) && (cint(argv[o+1],&err,0)<58))) { printf("\nEl parametro de %c-h%c debe estar dentro del rango [0-47][58-255]\n",34,34); return 1; } opt.h=cint(argv[o+1],&err,0); if (err) { opt.h=':'; } else { o++; } } } else if (strcmp(argv[o],"-min")==0) { if (opt.min!=0) { printf("\nParametro %c-min%c repetido\n",34,34); return 1; } if ((o+1)>=argc) { printf("\nFalta el parametro de %c-min%c\n",34,34); return 1; } if (strlen(argv[o+1])>15) { printf("\nEl parametro de %c-min%c no puede exceder de 15 digitos\n",34,34); return 1; } opt.min=cull(argv[o+1],&err,0); if (err) { printf("\nEl parametro de %c-min%c es incorrecto\n",34,34); return 1; } if (opt.max!=0) { if (opt.min>opt.max) { printf("\nEl parametro de %c-min%c debe ser menor o igual que el de %c-max%c\n",34,34,34,34); return 1; } } o++; } else if (strcmp(argv[o],"-max")==0) { if (opt.max!=0) { printf("\nParametro %c-max%c repetido\n",34,34); return 1; } if ((o+1)>=argc) { printf("\nFalta el parametro de %c-max%c\n",34,34); return 1; } if (strlen(argv[o+1])>15) { printf("\nEl parametro de %c-max%c no puede exceder de 15 digitos\n",34,34); return 1; } opt.max=cull(argv[o+1],&err,0); if ((err) || (opt.max==0)) { printf("\nEl parametro de %c-max%c es incorrecto\n",34,34); return 1; } if (opt.min!=0) { if (opt.min>opt.max) { printf("\nEl parametro de %c-min%c debe ser menor o igual que el de %c-max%c\n",34,34,34,34); return 1; } } o++; } else if (strcmp(argv[o],"-c")==0) { if (opt.c!=0) { printf("\nParametro %c-c%c repetido\n",34,34); return 1; } if ((o+1)>=argc) { printf("\nFalta el parametro de %c-c%c\n",34,34); return 1; } opt.c=cint(argv[o+1],&err,0); if ((err) || (opt.c<=0)) { printf("\nEl parametro de %c-c%c es incorrecto\n",34,34); return 1; } o++; } else if (strcmp(argv[o],"-cm")==0) { if (opt.mask_c_on!=0) { printf("\nPrametro %c-cm%c repetido\n",34,34); return 1; } if ((o+1)>=argc) { printf("\nFalta el parametro de %c-cm%c\n",34,34); return 1; } if ((cint(argv[o+1],&err,0)<0) || (cint(argv[o+1],&err,0)>255)) { printf("\nEl parametro de %c-cm%c debe estar dentro del rango [0-255]\n",34,34); return 1; } opt.mask_c=cint(argv[o+1],&err,0); if (err) { printf("\nEl parametro de %c-cm%c es incorrecto\n",34,34); return 1; } opt.mask_c_on=1; o++; } else if (strcmp(argv[o],"-r")==0) { opt.r=1; } else if (strcmp(argv[o],"-q")==0) { opt.q=1; } else if (strcmp(argv[o],"-rep")==0) { if ((o+1)>=argc) { printf("\nFalta el parametro de %c-rep%c\n",34,34); return 1; } opt.rep=cint(argv[o+1],&err,0); if ((err) || (opt.rep<=0)) { printf("\nEl parametro de %c-rep%c es incorrecto\n",34,34); return 1; } o++; } else { printf("\nParametro %c%s%c no reconocido\n",34,argv[o],34); return 1; } } //Opciones por defecto y ajuste if (opt.n==0) { opt.n=13; //(128-24)/8 } if (opt.c==0) { opt.c=8; } if (opt.h_on) { if (opt.rep) { if ((opt.c*(opt.rep+1))>(opt.n*2)) { printf("\nParametros de %c-c%c y de %c-rep%c incorrectos\n",34,34,34,34); return(1); } } else if (opt.c>(opt.n*2)) { opt.c=opt.n*2; } } else { if (opt.rep) { if ((opt.c*(opt.rep+1))>opt.n) { printf("\nParametros de %c-c%c y de %c-rep%c incorrectos\n",34,34,34,34); return(1); } } else if (opt.c>opt.n) { opt.c=opt.n; } } if (opt.mask_c_on==0) { opt.mask_c=48; } if (opt.min>(potull(10,opt.c)-1)) { printf("\nParametro de %c-min%c incorrecto\n",34,34); return(1); } if (opt.max>(potull(10,opt.c)-1)) { printf("\nParametro de %c-max%c incorrecto\n",34,34); return(1); } //Operaciones previas a la escritura min_str = (char *) calloc(1,16); if (min_str==NULL) { printf("\nMemoria insuficiente\n"); return -1; } ullToStr(opt.min,&min_str,16); data=(char *) calloc(1,opt.c+1); if (data==NULL) { printf("\nMemoria insuficiente\n"); free(min_str); return -1; } for(o=0;o<opt.c;o++) { if (o<(opt.c-strlen(min_str))) { data[o]=48; } else { data[o]=min_str[o-(opt.c-strlen(min_str))]; } } if (opt.h_on) { mask_hex_len=(opt.n*3-1)-opt.c*(opt.rep+1)-(opt.c*(opt.rep+1)-1)/2 + 2 - opt.r; c_hex=opt.c+(opt.c-1)/2; data_hex=(char *) calloc(1,c_hex+1); if (data_hex==NULL) { printf("\nMemoria insuficiente\n"); free(min_str); free(data); return -1; } if ((opt.rep) && (opt.c % 2)) { control_c_rep_impar = 1; data_hex2=(char *) calloc(1,c_hex+1); if (data_hex2==NULL) { printf("\nMemoria insuficiente\n"); free(min_str); free(data); free(data_hex); return -1; } } mask_hex=(char *) calloc(1,mask_hex_len+1); if (mask_hex==NULL) { printf("\nMemoria insuficiente\n"); free(min_str); free(data); free(data_hex); if (control_c_rep_impar) free(data_hex2); return -1; } for(o=0;o<mask_hex_len;o++) { if ((o%3)==(opt.c*(opt.rep+1)%2)) { mask_hex[o]=opt.h; } else { mask_hex[o]=opt.mask_c; } } if (opt.r) { mask_hex[mask_hex_len-1]=10; } else { mask_hex[mask_hex_len-2]=13; mask_hex[mask_hex_len-1]=10; } word_size = opt.n*3 + 1 - opt.r; } else { mask_len=opt.n-opt.c*(opt.rep+1)+1; if (opt.r==0) { mask_len++; } mask=(char *) calloc(1,mask_len+1); if (mask==NULL) { printf("\nMemoria insuficiente\n"); free(min_str); free(data); return -1; } for(o=0;o<mask_len;o++) { mask[o]=opt.mask_c; } if (opt.r) { mask[mask_len-1]=10; } else { mask[mask_len-2]=13; mask[mask_len-1]=10; } word_size=(opt.n + 2 - opt.r); } buffer_len = (MEM_BUFFER/word_size)*word_size; buffer = (char *) malloc(buffer_len); if (buffer==NULL) { printf("\nMemoria insuficiente, se intentara reservar una memoria minima..."); buffer_len = word_size; buffer = malloc(buffer_len); if (buffer==NULL) { printf(" FALLO!\n"); free(min_str); free(data); if (opt.h_on) { free(data_hex); if (control_c_rep_impar) free(data_hex2); free(mask_hex); } else { free(mask); } return(-1); } else { printf(" CORRECTO!\n"); } } //Abrimos el archivo if ((idf=fopen(file, "wb"))==NULL) { printf("\nError accediendo al archivo %c%s%c\n",34,file,34); free(min_str); free(data); if (opt.h_on) { free(data_hex); if (control_c_rep_impar) free(data_hex2); free(mask_hex); } else { free(mask); } return -1; } //Establece algunos parametros if (opt.max) { nclaves=opt.max-opt.min+1; } else { nclaves=potull(10,opt.c)-opt.min; } file_pre_size=nclaves*word_size; file_pre_size_mb=(double) file_pre_size/1048576; printf("\n\nEl diccionario contendra %llu claves y ocupara %0.2lfMB\n",nclaves,file_pre_size_mb); printf("\nGenerando diccionario... (Ctrl+C para cancelar)\n\n\n\n"); exit_th_mostrarProceso=1; control=1; v=0; n_buff_writes=0; time_i=time(NULL); if (!(opt.q)) { if (pthread_mutex_init(&proc_mutex,NULL)) opt.q=1; exit_th_mostrarProceso = 1; if (!(opt.q)) pthread_create(&th_mostrarProceso,NULL,(void *)&mostrarproceso,NULL); } //Empieza la generacion y escritura del diccionario if (opt.h_on) { //Modo: Hexadecimal while(control){ ArrayToHex(data_hex,data,c_hex,opt.h,0); memcpy(&buffer[v],data_hex,c_hex); v+=c_hex; if (control_c_rep_impar) { ArrayToHex(data_hex2,data,c_hex,opt.h,-1); for (j=0;j<opt.rep;j++) { if (j%2) { memcpy(&buffer[v],&(opt.h),1); v++; memcpy(&buffer[v],data_hex,c_hex); v+=c_hex; } else { memcpy(&buffer[v],data_hex2,c_hex); v+=c_hex; } } } else { for (j=0;j<opt.rep;j++) { memcpy(&buffer[v],&(opt.h),1); v++; memcpy(&buffer[v],data_hex,c_hex); v+=c_hex; } } memcpy(&buffer[v],mask_hex,mask_hex_len); v+=mask_hex_len; if (v>=buffer_len) { fwrite(buffer, 1, buffer_len, idf); if (!(opt.q)) { pthread_mutex_lock(&proc_mutex); n_buff_writes++; v=0; pthread_mutex_unlock(&proc_mutex); } else { v=0; } } if ((opt.max) && (cull(data,&err,opt.c)>=opt.max)) { control=0; } i=opt.c-1; while(data[i]>=57) { data[i]=48; if (i>0) { i--; } else { control=0; } } data[i]++; } if (v!=0) { fwrite(buffer, 1, v, idf); } free(data_hex); if (control_c_rep_impar) free(data_hex2); free(mask_hex); } else { //Modo: ASCII while(control){ memcpy(&buffer[v],data,opt.c); v+=opt.c; for (j=0;j<opt.rep;j++) { memcpy(&buffer[v],data,opt.c); v+=opt.c; } memcpy(&buffer[v],mask,mask_len); v+=mask_len; if (v>=buffer_len) { fwrite(buffer, 1, buffer_len, idf); if (!(opt.q)) { pthread_mutex_lock(&proc_mutex); n_buff_writes++; v=0; pthread_mutex_unlock(&proc_mutex); } else { v=0; } } if ((opt.max) && (cull(data,&err,opt.c)>=opt.max)) { control=0; } i=opt.c-1; while(data[i]>=57) { data[i]=48; if (i>0) { i--; } else { control=0; } } data[i]++; } if (v!=0) { fwrite(buffer, 1, v, idf); } free(mask); } time_seg=time(NULL)-time_i; //Finalizacion del proceso exit_th_mostrarProceso=0; if (!(opt.q)) { pthread_join(th_mostrarProceso,NULL); } time_min=0; while (time_seg>=60) { time_seg-=60; time_min++; } printf("\nDiccionario creado correctamente como %c%s%c\n",34,file,34); printf("Tiempo empleado: %d minutos %d segundos\n\n",time_min,time_seg); //Liberacion de memoria y recursos free(buffer); fclose(idf); free(min_str); free(data); if (!(opt.q)) pthread_mutex_destroy(&proc_mutex); return(0); }