/* The markdown handler */ static int markdown_handler(request_rec *r) { FILE *fp; MMIOT *doc; if (strcmp(r->handler, "markdown")) { return DECLINED; } if (r->header_only) { return OK; } ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "markdown_handler(): %s", r->filename); fp = fopen(r->filename, "r"); if (fp == NULL) { switch (errno) { case ENOENT: return HTTP_NOT_FOUND; case EACCES: return HTTP_FORBIDDEN; default: ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "open error, errno: %d\n", errno); return HTTP_INTERNAL_SERVER_ERROR; } } if (r->args && !strcasecmp(r->args, "raw")) { r->content_type = "text/plain; charset=UTF-8"; raw_output(fp, r); fclose(fp); } else { r->content_type = "text/html"; doc = mkd_in(fp, 0); fclose(fp); if (doc == NULL) { ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "mkd_in() returned NULL\n"); return HTTP_INTERNAL_SERVER_ERROR; } markdown_output(doc, r); } return OK; }
static int intel_mcu_tty_write(struct tty_struct *tty, const unsigned char *buf, int count) { struct mcu_data *data = tty->driver_data; switch (tty->index) { default: pr_err("TTY index %d not supported!\n", tty->index); case 1: return -1; case 0: if (count > TTY_WRITE_ROOM) { pr_err("Port 0's input size is limited by %d!\n", TTY_WRITE_ROOM); return -1; } raw_output(data, tty->index, buf, count); break; } return count; }
int ir_generator::print_module(std::string file_path, ir_generator::Context& ctx, const Options& options) { std::error_code ec; auto flags = llvm::sys::fs::F_Text; if (!options.force_overwrite) { flags = flags | llvm::sys::fs::F_Excl; } llvm::raw_fd_ostream raw_output(file_path, ec, flags); ctx.currentModule->print(raw_output, nullptr); if(ec) { options.err << "Failed printing module: " << ec.message() << "\n"; return EXIT_FAILURE; } auto main_ok = true; if(options.verify) { main_ok = !llvm::verifyModule(*ctx.currentModule, &options.err); if (options.verbose || !main_ok) { options.log << "Main module verification: " << (main_ok ? "OK" : "Failed") << "\n"; } } return main_ok ? EXIT_SUCCESS : EXIT_FAILURE; }
int Packet::Write(ClientService client) { if (null/*null packet*/) return 0; byte buf[6]; google::protobuf::io::ArrayOutputStream raw_output(buf, 1024); google::protobuf::io::CodedOutputStream coded_output(&raw_output); coded_output.WriteRaw((void*)&ServiceId, 1); coded_output.WriteVarint32(MethodId); byte requestIdTemp[2]; requestIdTemp[0] = (byte)(RequestId & 0xff); requestIdTemp[1] = (byte)(RequestId >> 8); coded_output.WriteRaw(requestIdTemp, 2); if (ServiceId != 0xfe) coded_output.WriteVarint64(Unknown); coded_output.WriteVarint32(PayloadLength); client.socket->Send(buf, coded_output.ByteCount()); //DumpBuffer(buf, coded_output.ByteCount()); if (PayloadLength > 0) { client.socket->Send(Payload, PayloadLength); //DumpBuffer(Payload, PayloadLength); } return 0; }
int main(int argc, char* argv[]) { init_console(); // do this FIRST //start curses initscr(); gamelog.initialize(GAMELOG_FILEPATH, OVERWRITE_GAMELOG, NEWLINEMODE_GAMELOG); //Initialize the gamelog (and also initialize artdir and homedir) time_t t = time(0); struct tm *now = localtime(&t); //Do not need to deallocate this. Statically allocated by system char datetime[41]; sprintf(datetime, "---------%i-%02i-%02i %02i:%02i:%02i---------\n\n\n", now->tm_year+1900, now->tm_mon+1, now->tm_mday, now->tm_hour, now->tm_min, now->tm_sec); //YYYY-MM-DD HH:MM:SS format gamelog.log(string("\n\n\n---------- PROGRAM STARTED ----------\n") + datetime); char file_name[13]; FILE *file; music.play(MUSIC_TITLEMODE); // initialize music and play title mode song (do this BEFORE displaying anything on the screen, but AFTER initializing artdir and homedir) // set window title char wtitle[50]; strcpy(wtitle,"Liberal Crime Squad "); strcat(wtitle,PACKAGE_VERSION); set_title(wtitle); noecho(); //initialize curses color start_color(); initMainRNG(); //initialize the array of color pairs for(int i=0;i<8;i++) for(int j=0;j<8;j++) { if(i==0&&j==0) { init_pair(7*8,0,0); continue; } if(i==7&&j==0) continue; init_pair(i*8+j,i,j); } //turns off cursor curs_set(0); //begin the game loop keypad(stdscr,TRUE); raw_output(TRUE); //addstr("Loading Graphics... "); //getkey(); loadgraphics(); //addstr("Loading Init File Options... "); //getkey(); loadinitfile(); //addstr("Loading sitemaps.txt... "); //getkey(); oldMapMode=!readConfigFile("sitemaps.txt"); // load site map data if(oldMapMode) { addstr("Failed to load sitemaps.txt! Reverting to old map mode.",gamelog); gamelog.nextMessage(); getkey(); } //move(1,0); //addstr("Setting initial game data... "); //getkey(); strcpy(slogan,"We need a slogan!"); if(!LCSrandom(20)) { switch(LCSrandom(7)) { case 0: strcpy(slogan,"To Rogues and Revolution!"); break; case 1: strcpy(slogan,"Hell yes, LCS!"); break; case 2: strcpy(slogan,"Striking high, standing tall!"); break; case 3: strcpy(slogan,"Revolution never comes with a warning!"); break; case 4: strcpy(slogan,"True Liberal Justice!"); break; case 5: strcpy(slogan,"Laissez ain't fair!"); break; case 6: strcpy(slogan,"This is a slogan!"); break; } } //Initialize sorting choices. for(int s=0;s<SORTINGCHOICENUM;s++) activesortingchoice[s]=SORTING_NONE; for(int v=0;v<VIEWNUM;v++) { attitude[v]=30+LCSrandom(25); public_interest[v]=0; background_liberal_influence[v]=0; } attitude[VIEW_LIBERALCRIMESQUAD]=0; attitude[VIEW_LIBERALCRIMESQUADPOS]=5; //attitude[VIEW_POLITICALVIOLENCE]=5; #ifdef REVOLUTIONNOW for(int v=0;v<VIEWNUM;v++) attitude[v]=100; #endif law[LAW_ABORTION]=1; law[LAW_ANIMALRESEARCH]=-1; law[LAW_POLICEBEHAVIOR]=-1; law[LAW_PRIVACY]=-1; law[LAW_DEATHPENALTY]=-1; law[LAW_NUCLEARPOWER]=-1; law[LAW_POLLUTION]=-1; law[LAW_LABOR]=0; law[LAW_GAY]=1; law[LAW_CORPORATE]=0; law[LAW_FREESPEECH]=0; law[LAW_FLAGBURNING]=1; law[LAW_GUNCONTROL]=-1; law[LAW_TAX]=0; law[LAW_WOMEN]=1; law[LAW_CIVILRIGHTS]=1; law[LAW_DRUGS]=-1; law[LAW_IMMIGRATION]=0; law[LAW_ELECTIONS]=0; law[LAW_MILITARY]=-1; law[LAW_PRISONS]=0; law[LAW_TORTURE]=-1; #ifdef SHITLAWS for(int l=0;l<LAWNUM;l++) law[l]=-2; #endif #ifdef PERFECTLAWS for(int l=0;l<LAWNUM;l++) law[l]=2; #endif for(int s=0;s<SENATENUM;s++) { if(s<25) senate[s]=-2; else if(s<60) senate[s]=-1; else if(s<80) senate[s]=0; else if(s<95) senate[s]=1; else senate[s]=2; } for(int h=0;h<HOUSENUM;h++) { if(h<50) house[h]=-2; else if(h<250) house[h]=-1; else if(h<350) house[h]=0; else if(h<400) house[h]=1; else house[h]=2; } for(int c=0;c<COURTNUM;c++) { if(c<3) court[c]=-2; else if(c<5) court[c]=-1; else if(c<5) court[c]=0; else if(c<8) court[c]=1; else court[c]=2; do { if(court[c]==-2) generate_name(courtname[c],GENDER_WHITEMALEPATRIARCH); else generate_name(courtname[c]); } while(len(courtname[c])>20); } for(int e=0;e<EXECNUM;e++) { exec[e]=-2; generate_name(execname[e],GENDER_WHITEMALEPATRIARCH); } initOtherRNG(attorneyseed); strcpy(lcityname,cityname()); xmllog.initialize("xmllog",true,1); bool xml_loaded_ok = true; xml_loaded_ok&=populate_from_xml(vehicletype,"vehicles.xml",xmllog); xml_loaded_ok&=populate_from_xml(cliptype,"clips.xml",xmllog); xml_loaded_ok&=populate_from_xml(weapontype,"weapons.xml",xmllog); xml_loaded_ok&=populate_from_xml(armortype,"armors.xml",xmllog); xml_loaded_ok&=populate_masks_from_xml(armortype,"masks.xml",xmllog); xml_loaded_ok&=populate_from_xml(loottype,"loot.xml",xmllog); xml_loaded_ok&=populate_from_xml(creaturetype,"creatures.xml",xmllog); xml_loaded_ok&=populate_from_xml(augmenttype,"augmentations.xml",xmllog); if(!xml_loaded_ok) end_game(EXIT_FAILURE); //addstr("Attempting to load saved game... "); //getkey(); //addstr("Setup complete!"); //getkey(); clear(); mode_title(); //deinitialize curses end_game(); return EXIT_SUCCESS; }
/* full character sheet (with surrounding interface) */ void fullstatus(int p) { if(activesquad==NULL)return; const int pagenum=3; int page=0; do { erase(); set_color(COLOR_GREEN,COLOR_BLACK,1); move(0,0); addstr("Profile of a Liberal"); if(page==0) printliberalstats(*activesquad->squad[p]); else if(page==1) printliberalskills(*activesquad->squad[p]); else if (page == 2) printliberalcrimes(*activesquad->squad[p]); move(23,0); addstr("N - Change Code Name G - Fix Gender Label"); if(activesquad->squad[1]!=NULL) { addstr(" LEFT/RIGHT - Other Liberals"); } move(24,0); addstr("Press any other key to continue the Struggle"); addstr(" UP/DOWN - More Info"); refresh(); int c=getch(); translategetch(c); if(activesquad->squad[1]!=NULL&&((c==KEY_LEFT)||(c==KEY_RIGHT))) { int sx=1; if(c==KEY_LEFT)sx=-1; do { p=(p+6+sx)%6; }while(activesquad->squad[p]==NULL); continue; } if(c==KEY_DOWN) { page++; page%=pagenum; continue; } if(c==KEY_UP) { page--; if(page<0)page=pagenum-1; page%=pagenum; continue; } if(c=='n') { move(23,0); set_color(COLOR_WHITE,COLOR_BLACK,0); addstr("What is the new code name? "); move(24,0); addstr(" "); keypad(stdscr,FALSE); raw_output(FALSE); echo(); curs_set(1); move(24,0); enter_name(activesquad->squad[p]->name,CREATURE_NAMELEN,activesquad->squad[p]->propername); curs_set(0); noecho(); raw_output(TRUE); keypad(stdscr,TRUE); continue; } else if(c=='g') { activesquad->squad[p]->gender_liberal++; if(activesquad->squad[p]->gender_liberal > 2) activesquad->squad[p]->gender_liberal = 0; continue; } break; }while(1); }
int main(int argc, char* argv[]) { if(argc != 2) { std::cerr << "Usage : " << argv[0] << "<0,1>" <<std::endl; std::cerr << "with : " << std::endl; std::cerr << "0 : quadratic loss" << std::endl; std::cerr << "1 : cross entropy loss" << std::endl; return -1; } bool quadratic_loss = (atoi(argv[1]) == 0); srand(time(NULL)); // We compare our computation of the gradient to // a finite difference approximation // The loss is also involved std::cout << "---------------------------------" << std::endl; std::cout << "Comparing the analytical gradient and numerical approximation " << std::endl; auto input = gaml::mlp::input<X>(INPUT_DIM, fillInput); auto l1 = gaml::mlp::layer(input, HIDDEN_LAYER_SIZE, gaml::mlp::mlp_sigmoid(), gaml::mlp::mlp_dsigmoid()); auto l2 = gaml::mlp::layer(l1, HIDDEN_LAYER_SIZE, gaml::mlp::mlp_identity(), gaml::mlp::mlp_didentity()); auto l3 = gaml::mlp::layer(l2, HIDDEN_LAYER_SIZE, gaml::mlp::mlp_tanh(), gaml::mlp::mlp_dtanh()); auto l4 = gaml::mlp::layer(l3, OUTPUT_DIM, gaml::mlp::mlp_sigmoid(), gaml::mlp::mlp_dsigmoid()); auto mlp = gaml::mlp::perceptron(l4, output_of); std::cout << "We use the following architecture : " << std::endl; std::cout << mlp << std::endl; std::cout << "which has a total of " << mlp.psize() << " parameters"<< std::endl; gaml::mlp::parameters_type params(mlp.psize()); gaml::mlp::parameters_type paramsph(mlp.psize()); gaml::mlp::values_type derivatives(mlp.psize()); gaml::mlp::values_type forward_sweep(mlp.size()); X x; auto loss_ce = gaml::mlp::loss::CrossEntropy(); auto loss_quadratic = gaml::mlp::loss::Quadratic(); auto f = [&mlp, ¶ms] (const typename decltype(mlp)::input_type& x) -> gaml::mlp::values_type { auto output = mlp(x, params); gaml::mlp::values_type voutput(mlp.output_size()); fillOutput(voutput.begin(), output); return voutput; }; auto df = [&mlp, &forward_sweep, ¶ms] (const typename decltype(mlp)::input_type& x, unsigned int parameter_dim) -> gaml::mlp::values_type { return mlp.deriv(x, params, forward_sweep, parameter_dim); }; unsigned int nbtrials = 100; unsigned int nbfails = 0; std::cout << "I will compare " << nbtrials << " times a numerical approximation and the analytical gradient we compute" << std::endl; for(unsigned int t = 0 ; t < nbtrials ; ++t) { randomize_data(params, -1.0, 1.0); randomize_data(x, -1.0, 1.0); // Compute the output at params auto output = mlp(x, params); gaml::mlp::values_type raw_output(OUTPUT_DIM); fillOutput(raw_output.begin(), output); gaml::mlp::values_type raw_outputph(OUTPUT_DIM); // For computing the loss, we need a target gaml::mlp::values_type raw_target(OUTPUT_DIM); randomize_data(raw_target); double norm_dh = 0.0; for(unsigned int i = 0 ; i < mlp.psize() ; ++i) { // Let us compute params + h*[0 0 0 0 0 0 1 0 0 0 0 0], the 1 at the ith position std::copy(params.begin(), params.end(), paramsph.begin()); double dh = (sqrt(DBL_EPSILON) * paramsph[i]); paramsph[i] += dh; norm_dh += dh*dh; // Compute the output at params + h auto outputph = mlp(x, paramsph); fillOutput(raw_outputph.begin(), outputph); // We now compute the approximation of the derivative if(quadratic_loss) derivatives[i] = (loss_quadratic(raw_target, raw_outputph) - loss_quadratic(raw_target, raw_output))/dh; else derivatives[i] = (loss_ce(raw_target, raw_outputph) - loss_ce(raw_target, raw_output))/dh; } // We now compute the analytical derivatives mlp(x, params); std::copy(mlp.begin(), mlp.end(), forward_sweep.begin()); gaml::mlp::values_type our_derivatives(mlp.psize()); for(unsigned int i = 0 ; i < mlp.psize() ; ++i) { if(quadratic_loss) our_derivatives[i] = loss_quadratic.deriv(x, raw_target, forward_sweep, f, df, i); else our_derivatives[i] = loss_ce.deriv(x, raw_target, forward_sweep, f, df, i); } // We finally compute the norm of the difference double error = 0.0; auto diter = derivatives.begin(); for(auto& ourdi : our_derivatives) { error = (ourdi - *diter) * (ourdi - *diter); diter++; } error = sqrt(error); std::cout << "Error between the analytical and numerical gradients " << error << " with a step size of " << sqrt(norm_dh) << " in norm" << std::endl; if(error > 1e-7) ++nbfails; /* std::cout << "numerical " << std::endl; for(auto & di : derivatives) std::cout << di << " "; std::cout << std::endl; std::cout << "our :" << std::endl; for(auto& di : our_derivatives) std::cout << di << " "; std::cout << std::endl; */ } std::cout << nbfails << " / " << nbtrials << " with an error higher than 1e-7" << std::endl; }
int chkr_raw_output(bool arg) { return(raw_output(arg)); }
int Shop::fenceselect(squadst& customers) const { int ret=0; consolidateloot(location[customers.squad[0]->base]->loot); int page=0; vector<int> selected(location[customers.squad[0]->base]->loot.size(),0); do { erase(); set_color(COLOR_WHITE,COLOR_BLACK,0); move(0,0); addstr("What will you sell?"); if (ret > 0) { move(0,30); addstr("Estimated Liberal Amount: $"); addstr(tostring(ret).c_str()); } printparty(); int x = 1, y = 10; std::string outstr; std::string itemstr; for (int l = page * 18; l < (int)location[customers.squad[0]->base]->loot.size() && l < page * 18 + 18; l++) { if (selected[l]) set_color(COLOR_GREEN,COLOR_BLACK,1); else set_color(COLOR_WHITE,COLOR_BLACK,0); itemstr = location[customers.squad[0]->base]->loot[l]->equip_title(); if (location[customers.squad[0]->base]->loot[l]->get_number() > 1) { if(selected[l] > 0) { itemstr += " " + tostring(selected[l]) + "/"; } else itemstr += " x"; itemstr += tostring(location[customers.squad[0]->base]->loot[l]->get_number()); } outstr = static_cast<char>(l - page * 18 + 'A'); outstr += " - " + itemstr; move(y,x); addstr(outstr.c_str()); x += 26; if (x > 53) { x = 1; y++; } } //PAGE UP set_color(COLOR_WHITE,COLOR_BLACK,0); if (page > 0) { move(17,1); addprevpagestr(); } //PAGE DOWN if((page + 1) * 18 < (int)location[customers.squad[0]->base]->loot.size()) { move(17,53); addnextpagestr(); } set_color(COLOR_WHITE,COLOR_BLACK,0); move(23,1); addstr("Press a letter to select an item to sell."); move(24,1); addstr("Enter - Done"); refresh(); int c = getch(); translategetch(c); if (c >= 'a' && c <= 'r') { int slot = c - 'a' + page * 18; if(slot >= 0 && slot < (int)location[customers.squad[0]->base]->loot.size()) { if (selected[slot]) { ret -= location[customers.squad[0]->base]->loot[slot]->get_fencevalue() * selected[slot]; selected[slot] = 0; } else { if (!location[customers.squad[0]->base]->loot[slot]->is_good_for_sale()) { printparty(); move(8,15); set_color(COLOR_WHITE,COLOR_BLACK,1); addstr(" You can't sell damaged goods."); refresh(); getch(); } else { if (location[customers.squad[0]->base]->loot[slot]->get_number() > 1) { selected[slot] = 1; printparty(); move(8,15); set_color(COLOR_WHITE,COLOR_BLACK,1); addstr(" How many? "); refresh(); char str[100]; keypad(stdscr,FALSE); raw_output(FALSE); echo(); curs_set(1); mvgetstr(8,32,str); curs_set(0); noecho(); raw_output(TRUE); keypad(stdscr,TRUE); selected[slot] = atoi(str); if (selected[slot] < 0) selected[slot] = 0; else if (selected[slot] > location[customers.squad[0]->base]->loot[slot]->get_number()) selected[slot]=location[customers.squad[0]->base]->loot[slot]->get_number(); } else selected[slot]=1; ret += location[customers.squad[0]->base]->loot[slot]->get_fencevalue() * selected[slot]; } } } } if(c == 'x'||c==10||c==ESC) break; //PAGE UP if((c == interface_pgup || c == KEY_UP || c == KEY_LEFT) && page > 0) page--; //PAGE DOWN if((c == interface_pgdn || c == KEY_DOWN || c == KEY_RIGHT) && (page + 1) * 18 < (int)location[customers.squad[0]->base]->loot.size()) page++; } while (true); for(int l = location[customers.squad[0]->base]->loot.size() - 1; l >= 0; l--) { if(selected[l] > 0) { location[customers.squad[0]->base]->loot[l]->decrease_number(selected[l]); if(location[customers.squad[0]->base]->loot[l]->get_number() <= 0) delete_and_remove(location[customers.squad[0]->base]->loot,l); } } return ret; }