LString makeRelativePath(const LString &aAbs, const LString &aBase) { fs::path abspath(aAbs.c_str()); fs::path basepath(aBase.c_str()); if (!abspath.is_complete() || !basepath.is_complete()) return aAbs; // aAbs or aBase is not absolute path if (abspath.root_path()!=basepath.root_path()) return aAbs; // root names are different; cannot make relative path fs::path::const_iterator iter1 = abspath.begin(); fs::path::const_iterator iter1_end = abspath.end(); fs::path::const_iterator iter2 = basepath.begin(); fs::path::const_iterator iter2_end = basepath.end(); for (; iter1!=iter1_end && iter2!=iter2_end ; ++iter1, ++iter2) { if (*iter1!=*iter2) break; } fs::path relpath; //if (iter1!=iter1_end && iter2!=iter2_end) { for (; iter2!=iter2_end; ++iter2) relpath /= ".."; for (; iter1!=iter1_end; ++iter1) relpath /= *iter1; //} // string() will canonicalize the path separator to "/" //return relpath.file_string(); return relpath.string(); }
Fireball::Fireball(float x, float y, b2World& World, Render* renderer, float d) { world = &World; initX = x; initY = y; dir = d; std::string basepath(SDL_GetBasePath()); std::string imagePath; if (dir == 2) { imagePath = basepath + "spearL.bmp"; } else { imagePath = basepath + "spearR.bmp"; } sprite = SDL_LoadBMP(imagePath.c_str()); if (spriteRect == NULL) { spriteRect = renderer->AddSurfaceToRenderer(sprite, initX, initY, 0.5f); } else { } CreateBody(); }
QueryEngine::QueryEngine(const char * filepath) : decoder(filepath){ //Create filepaths std::string basepath(filepath); std::string path_to_hashtable = basepath + "/probing_hash.dat"; std::string path_to_data_bin = basepath + "/binfile.dat"; std::string path_to_source_vocabid = basepath + "/source_vocabids"; ///Source phrase vocabids read_map(&source_vocabids, path_to_source_vocabid.c_str()); //Target phrase vocabIDs vocabids = decoder.get_target_lookup_map(); //Read config file std::string line; std::ifstream config ((basepath + "/config").c_str()); getline(config, line); int tablesize = atoi(line.c_str()); //Get tablesize. config.close(); //Mmap binary table struct stat filestatus; stat(path_to_data_bin.c_str(), &filestatus); binary_filesize = filestatus.st_size; binary_mmaped = read_binary_file(path_to_data_bin.c_str(), binary_filesize); //Read hashtable size_t table_filesize = Table::Size(tablesize, 1.2); mem = readTable(path_to_hashtable.c_str(), table_filesize); Table table_init(mem, table_filesize); table = table_init; std::cerr << "Initialized successfully! " << std::endl; }
static boost::optional<openstudio::path> findFile(openstudio::path base, std::string filename) { //boost::filesystem::recursive_directory_iterator(base); //boost::filesystem::recursive_directory_iterator(); //boost::filesystem2::basic_recursive_directory_iterator(base); if(boost::filesystem::is_directory(base)) { openstudio::path filepath = base / openstudio::toPath(filename); std::cout<<"Looking for "<<openstudio::toString(filepath)<<std::endl; if(boost::filesystem::exists(filepath)) { return boost::optional<openstudio::path>(filepath); } // WHY!?!?! boost::filesystem2::path basepath(openstudio::toString(base)); boost::filesystem::directory_iterator iter(basepath); boost::filesystem::directory_iterator end; for(;iter!=end;++iter) { boost::optional<openstudio::path> optional = findFile(openstudio::toPath(iter->path().string()),filename); if(optional) { return optional; } } } return false; }
QueryEngine::QueryEngine(const char * filepath){ //Create filepaths std::string basepath(filepath); std::string path_to_hashtable = basepath + "/probing_hash.dat"; std::string path_to_data_bin = basepath + "/binfile.dat"; std::string path_to_vocabid = basepath + "/vocabid.dat"; //Read config file std::string line; std::ifstream config ((basepath + "/config").c_str()); getline(config, line); int tablesize = atoi(line.c_str()); //Get tablesize. getline(config, line); largest_entry = atoi(line.c_str()); //Set largest_entry. config.close(); //Mmap binary table struct stat filestatus; stat(path_to_data_bin.c_str(), &filestatus); binary_filesize = filestatus.st_size; binary_mmaped = read_binary_file(path_to_data_bin.c_str(), binary_filesize); //Read hashtable size_t table_filesize = Table::Size(tablesize, 1.2); mem = readTable(path_to_hashtable.c_str(), table_filesize); Table table_init(mem, table_filesize); table = table_init; //Read vocabid read_map(&vocabids, path_to_vocabid.c_str()); std::cout << "Initialized successfully! " << std::endl; }
/* * Class: mapnik_MapDefinition * Method: setBasePath * Signature: (Ljava/lang/String;)V */ JNIEXPORT void JNICALL Java_mapnik_MapDefinition_setBasePath (JNIEnv *env, jobject mapobject, jstring basepathj) { PREAMBLE; mapnik::Map* map=LOAD_MAP_POINTER(mapobject); refjavastring basepath(env, basepathj); map->set_base_path(basepath.stringz); TRAILER_VOID; }
//load the texture void Bullet::LoadAssets(float x, float y) { std::string basepath(SDL_GetBasePath()); std::string imagePath; if (bulletForPlayer1 == true) imagePath = basepath + "../Sprites/player1Bullet.bmp"; else imagePath = basepath + "../Sprites/player2Bullet.bmp"; sprite = SDL_LoadBMP(imagePath.c_str()); spriteRect = Render::GetInstance()->AddSurfaceToRenderer(sprite, x, y); }
/* * Class: mapnik_MapDefinition * Method: loadMapString * Signature: (Ljava/lang/String;ZLjava/lang/String;)V */ JNIEXPORT void JNICALL Java_mapnik_MapDefinition_loadMapString (JNIEnv *env, jobject mapobject, jstring strj, jboolean strict, jstring basepathj) { PREAMBLE; mapnik::Map* map=LOAD_MAP_POINTER(mapobject); refjavastring str(env, strj); refjavastring basepath(env, basepathj); mapnik::load_map_string(*map, str.stringz, (bool)strict, basepath.stringz); TRAILER_VOID; }
static int readspace(char *spacefile, int *error) { FILE *fp; char line[LSIZE]; long blocks, nodes; int n; if (spacefile == NULL) return (0); if ((fp = fopen(spacefile, "r")) == NULL) { progerr(gettext("unable to open spacefile %s"), spacefile); return (-1); } while (fgets(line, LSIZE, fp)) { struct fstable *fs_tab; char *pt, path[PATH_MAX]; blocks = nodes = 0; for (pt = line; isspace(*pt); /* void */) pt++; if (*pt == '#' || *pt == '\0') continue; (void) sscanf(line, "%s %ld %ld", path, &blocks, &nodes); mappath(2, path); basepath(path, get_basedir(), get_inst_root()); canonize(path); n = resolved_fsys(path); if (fsys_stat(n)) { (*error)++; continue; } /* * Don't accumulate space requirements on read-only * remote filesystems. NOTE: For some reason, this * used to check for !remote && read only. If this * blows up later, then maybe that was correct -- JST */ if (is_remote_fs_n(n) && !is_fs_writeable_n(n)) continue; fs_tab = get_fs_entry(n); fs_tab->bused += blocks; fs_tab->fused += nodes; } (void) fclose(fp); return (0); }
static void writeturn(void) { char zText[4096]; FILE *f; path_join(basepath(), "datum", zText, sizeof(zText)); f = fopen(zText, "w"); if (!f) { perror(zText); return; } fputs(gamedate2(default_locale), f); fclose(f); path_join(basepath(), "turn", zText, sizeof(zText)); f = fopen(zText, "w"); if (!f) { perror(zText); return; } fprintf(f, "%d\n", turn); fclose(f); }
static void writeturn(void) { char zText[MAX_PATH]; FILE *f; sprintf(zText, "%s/datum", basepath()); f = fopen(zText, "w"); if (!f) { perror(zText); return; } fputs(gamedate2(default_locale), f); fclose(f); sprintf(zText, "%s/turn", basepath()); f = fopen(zText, "w"); if (!f) { perror(zText); return; } fprintf(f, "%d\n", turn); fclose(f); }
LString makeAbsolutePath(const LString &aRel, const LString &aBase) { MB_DPRINTLN("makeAbsPath rel=%s, base=%s", aRel.c_str(), aBase.c_str()); fs::path relpath(aRel.c_str()); fs::path basepath(aBase.c_str()); if (relpath.is_complete()) return aRel; // aRel is already in abs form // convert to the absolute representation fs::path::const_iterator iter1 = relpath.begin(); fs::path::const_iterator iter1_end = relpath.end(); int nup = 0; for (; iter1!=iter1_end; ++iter1) { if (*iter1=="..") ++nup; else break; } if (nup==0) { // There's no up-dir ('..') string --> just concat to make abs path. #if (BOOST_FILESYSTEM_VERSION==2) relpath = fs::complete(relpath, basepath); return relpath.file_string(); #else relpath = fs::absolute(relpath, basepath); return relpath.string(); #endif } for (; nup>0; --nup) { MB_ASSERT(basepath.has_parent_path()); basepath = basepath.parent_path(); } for (; iter1!=iter1_end; ++iter1) { basepath /= *iter1; } #if (BOOST_FILESYSTEM_VERSION==2) return basepath.file_string(); #else return basepath.string(); #endif }
Door::Door(float x, float y, Render* renderer) { initX = x; initY = y; initX1 = 100000; initY1 = 100000; std::string basepath(SDL_GetBasePath()); std::string imagePath = basepath + "door2.bmp"; sprite = SDL_LoadBMP(imagePath.c_str()); spriteRect = renderer->AddSurfaceToRenderer(sprite, -1000, -1000, 0.5f); std::string imagePath1 = basepath + "door1.bmp"; sprite1 = SDL_LoadBMP(imagePath1.c_str()); spriteRect1 = renderer->AddSurfaceToRenderer(sprite1, -1000, -1000, 0.5f); }
MagicFolder::MagicFolder(LPCTSTR name_, /*LPCTSTR path_, */LPCTSTR base_) { type = ptMagicFolder; parent = NULL; name = name_; // Using CPathName ensures we get trailing slashes... CPathName basepath(base_); basePath = basepath.c_str(); read = false; cache = NULL; filter = _T("*"); excludedFileFilter = FolderAdder::getDefaultExcludedFileFilter(); folderFilter = FolderAdder::getDefaultExcludedFolderFilter(); }
void log_dead_factions(void) { if (dead_factions) { const char *logname = config_get("game.deadlog"); if (logname) { FILE *F; char path[PATH_MAX]; join_path(basepath(), logname, path, sizeof(path)); F = fopen(path, "at"); if (F) { faction *f; for (f = dead_factions; f; f = f->next) { fprintf(F, "%d\t%d\t%d\t%s\t%s\t%s\n", turn, f->lastorders, f->age, itoa36(f->no), f->email, f->name); } fclose(F); } } } }
static void load_inifile(dictionary * d) { const char *reportdir = reportpath(); const char *datadir = datapath(); const char *basedir = basepath(); const char *str; assert(d); str = iniparser_getstring(d, "eressea:base", basedir); if (str != basedir) { set_basepath(str); } str = iniparser_getstring(d, "eressea:report", reportdir); if (str != reportdir) { set_reportpath(str); } str = iniparser_getstring(d, "eressea:data", datadir); if (str != datadir) { set_datapath(str); } lomem = iniparser_getint(d, "eressea:lomem", lomem) ? 1 : 0; str = iniparser_getstring(d, "eressea:encoding", NULL); if (str && (_strcmpl(str, "utf8") == 0 || _strcmpl(str, "utf-8") == 0)) { enc_gamedata = ENCODING_UTF8; } verbosity = iniparser_getint(d, "eressea:verbose", 2); battledebug = iniparser_getint(d, "eressea:debug", battledebug) ? 1 : 0; str = iniparser_getstring(d, "eressea:locales", "de,en"); make_locales(str); if (global.inifile) iniparser_freedict(global.inifile); global.inifile = d; }
Cannon::Cannon(float x, float y, b2World& World, Render* renderer, float d) { initX = x; initY = y; dir = d; std::string basepath(SDL_GetBasePath()); std::string imagePath; if (dir == 1) { imagePath = basepath + "cannon3.bmp"; } else { imagePath = basepath + "cannon3.bmp"; } sprite = SDL_LoadBMP(imagePath.c_str()); if (spriteRect == NULL) { spriteRect = renderer->AddSurfaceToRenderer(sprite, initX, initY, 0.5f); } else { } fireballs.push_back(new Fireball(230, y - 5, World, renderer, dir)); fireballs.push_back(new Fireball(660, y - 5, World, renderer, dir)); //fireballs.push_back(new Fireball(858, y - 5, World, renderer, dir)); //fireballs.push_back(new Fireball(0, y - 5, World, renderer, dir)); }
int writepasswd(void) { FILE *F; char zText[128]; path_join(basepath(), "passwd", zText, sizeof(zText)); F = fopen(zText, "w"); if (!F) { perror(zText); } else { faction *f; log_info("writing passwords..."); for (f = factions; f; f = f->next) { fprintf(F, "%s:%s:%s:%d\n", itoa36(f->no), faction_getemail(f), faction_getpassword(f), f->uid); } fclose(F); return 0; } return 1; }
/* opt - process option in arg */ static void opt(char *arg) { switch (arg[1]) { /* multi-character options */ case 'W': /* -Wxarg */ if (arg[2] && arg[3]) switch (arg[2]) { case 'o': if (option(&arg[3])) return; break; case 'p': plist = append(&arg[3], plist); return; case 'f': if (strcmp(&arg[3], "-C") == 0 && !option("-b")) break; /* -C requires that -b is supported */ clist = append(&arg[3], clist); if (strcmp(&arg[3], "-unsigned_char=1") == 0) { plist = append("-D__CHAR_UNSIGNED__", plist); plist = append("-U_CHAR_IS_SIGNED", plist); } #define xx(name,k) \ if (strcmp(&arg[3], "-wchar_t=" #name) == 0) \ plist = append("-D_WCHAR_T_SIZE=" #k, plist); xx(unsigned_char,1) xx(unsigned_short,2) xx(unsigned_int,4) #undef xx return; case 'a': alist = append(&arg[3], alist); return; case 'l': llist[0] = append(&arg[3], llist[0]); return; } fprintf(stderr, "%s: %s ignored\n", progname, arg); return; case 'd': /* -dn -dynamic */ if (strcmp(arg, "-dynamic") == 0) { if (!option(arg)) fprintf(stderr, "%s: %s ignored\n", progname, arg); } else { arg[1] = 's'; clist = append(arg, clist); } return; case 't': /* -t -tname -tempdir=dir */ if (strncmp(arg, "-tempdir=", 9) == 0) tempdir = arg + 9; else clist = append(arg, clist); return; case 'p': /* -p -pg */ if (option(arg)) clist = append(arg, clist); else fprintf(stderr, "%s: %s ignored\n", progname, arg); return; case 'D': /* -Dname -Dname=def */ case 'U': /* -Uname */ case 'I': /* -Idir */ plist = append(arg, plist); return; case 'B': /* -Bdir -Bstatic -Bdynamic */ #ifdef sparc if (strcmp(arg, "-Bstatic") == 0 || strcmp(arg, "-Bdynamic") == 0) llist[1] = append(arg, llist[1]); else #endif { static char *path; if (path) error("-B overwrites earlier option", 0); path = arg + 2; if (strstr(com[1], "win32") != NULL) com[0] = concat(replace(path, '/', '\\'), concat("rcc", first(suffixes[4]))); else com[0] = concat(path, "rcc"); if (path[0] == 0) error("missing directory in -B option", 0); } return; case 'h': if (strcmp(arg, "-help") == 0) { static int printed = 0; case '?': if (!printed) help(); printed = 1; return; } break; case 's': if (strcmp(arg, "-static") == 0) { if (!option(arg)) fprintf(stderr, "%s: %s ignored\n", progname, arg); return; } break; } if (arg[2] == 0) switch (arg[1]) { /* single-character options */ case 'S': Sflag++; return; case 'O': fprintf(stderr, "%s: %s ignored\n", progname, arg); return; case 'A': case 'n': case 'w': case 'P': clist = append(arg, clist); return; case 'g': case 'b': if (option(arg)) clist = append(arg[1] == 'g' ? "-g2" : arg, clist); else fprintf(stderr, "%s: %s ignored\n", progname, arg); return; case 'G': if (option(arg)) { clist = append("-g3", clist); llist[0] = append("-N", llist[0]); } else fprintf(stderr, "%s: %s ignored\n", progname, arg); return; case 'E': Eflag++; return; case 'c': cflag++; return; case 'M': Eflag++; /* -M implies -E */ plist = append(arg, plist); return; case 'N': if (strcmp(basepath(cpp[0]), "gcc-cpp") == 0) plist = append("-nostdinc", plist); include[0] = 0; ilist = 0; return; case 'v': if (verbose++ == 0) { if (strcmp(basepath(cpp[0]), "gcc-cpp") == 0) plist = append(arg, plist); clist = append(arg, clist); fprintf(stderr, "%s %s\n", progname, rcsid); } return; } if (cflag || Sflag || Eflag) fprintf(stderr, "%s: %s ignored\n", progname, arg); else llist[1] = append(arg, llist[1]); }
/* filename - process file name argument `name', return status */ static int filename(char *name, char *base) { int status = 0; static char *stemp, *itemp; if (base == 0) base = basepath(name); switch (suffix(name, suffixes, 4)) { case 0: /* C source files */ compose(cpp, plist, append(name, 0), 0); if (Eflag) { status = callsys(av); break; } if (itemp == NULL) itemp = tempname(first(suffixes[1])); compose(cpp, plist, append(name, 0), append(itemp, 0)); status = callsys(av); if (status == 0) return filename(itemp, base); break; case 1: /* preprocessed source files */ if (Eflag) break; if (Sflag) status = compile(name, outfile ? outfile : concat(base, first(suffixes[2]))); else if ((status = compile(name, stemp?stemp:(stemp=tempname(first(suffixes[2]))))) == 0) return filename(stemp, base); break; case 2: /* assembly language files */ if (Eflag) break; if (!Sflag) { char *ofile; if (cflag && outfile) ofile = outfile; else if (cflag) ofile = concat(base, first(suffixes[3])); else ofile = tempname(first(suffixes[3])); compose(as, alist, append(name, 0), append(ofile, 0)); status = callsys(av); if (!find(ofile, llist[1])) llist[1] = append(ofile, llist[1]); } break; case 3: /* object files */ if (!find(name, llist[1])) llist[1] = append(name, llist[1]); break; default: if (Eflag) { compose(cpp, plist, append(name, 0), 0); status = callsys(av); } llist[1] = append(name, llist[1]); break; } if (status) errcnt++; return status; }
void report_summary(summary * s, summary * o, bool full) { FILE *F = NULL; int i, newplayers = 0; faction *f; char zText[MAX_PATH]; if (full) { sprintf(zText, "%s/parteien.full", basepath()); } else { sprintf(zText, "%s/parteien", basepath()); } F = fopen(zText, "w"); if (!F) { perror(zText); return; } #ifdef SUMMARY_BOM else { const unsigned char utf8_bom[4] = { 0xef, 0xbb, 0xbf, 0 }; fwrite(utf8_bom, 1, 3, F); } #endif log_info("writing summary to file: parteien.\n"); fprintf(F, "%s\n%s\n\n", game_name(), gamedate2(default_locale)); fprintf(F, "Auswertung Nr: %d\n\n", turn); fprintf(F, "Parteien: %s\n", pcomp(s->factions, o->factions)); fprintf(F, "Einheiten: %s\n", pcomp(s->nunits, o->nunits)); fprintf(F, "Spielerpopulation: %s\n", pcomp(s->playerpop, o->playerpop)); fprintf(F, " davon bewaffnet: %s\n", pcomp(s->armed_men, o->armed_men)); fprintf(F, " Helden: %s\n", pcomp(s->heroes, o->heroes)); if (full) { fprintf(F, "Regionen: %d\n", listlen(regions)); fprintf(F, "Bewohnte Regionen: %d\n", s->inhabitedregions); fprintf(F, "Landregionen: %d\n", s->landregionen); fprintf(F, "Spielerregionen: %d\n", s->regionen_mit_spielern); fprintf(F, "Landspielerregionen: %d\n", s->landregionen_mit_spielern); fprintf(F, "Orkifizierte Regionen: %d\n", s->orkifizierte_regionen); fprintf(F, "Inaktive Vulkane: %d\n", s->inactive_volcanos); fprintf(F, "Aktive Vulkane: %d\n\n", s->active_volcanos); } for (i = 0; i < MAXRACES; i++) { if (i != RC_TEMPLATE && i != RC_CLONE && s->factionrace[i]) { const race *rc = get_race(i); if (rc && playerrace(rc)) { fprintf(F, "%13s%s: %s\n", LOC(default_locale, rc_name(rc, NAME_CATEGORY)), LOC(default_locale, "stat_tribe_p"), pcomp(s->factionrace[i], o->factionrace[i])); } } } if (full) { fprintf(F, "\n"); { struct language *plang = s->languages; while (plang != NULL) { struct language *olang = o->languages; int nold = 0; while (olang && olang->locale != plang->locale) olang = olang->next; if (olang) nold = olang->number; fprintf(F, "Sprache %12s: %s\n", locale_name(plang->locale), rcomp(plang->number, nold)); plang = plang->next; } } } fprintf(F, "\n"); if (full) { for (i = 0; i < MAXRACES; i++) { if (s->poprace[i]) { const race *rc = get_race(i); fprintf(F, "%20s: %s\n", LOC(default_locale, rc_name(rc, NAME_PLURAL)), rcomp(s->poprace[i], o->poprace[i])); } } } else { for (i = 0; i < MAXRACES; i++) { if (i != RC_TEMPLATE && i != RC_CLONE && s->poprace[i]) { const race *rc = get_race(i); if (playerrace(rc)) { fprintf(F, "%20s: %s\n", LOC(default_locale, rc_name(rc, NAME_PLURAL)), rcomp(s->poprace[i], o->poprace[i])); } } } } if (full) { fprintf(F, "\nWaffen: %s\n", pcomp(s->waffen, o->waffen)); fprintf(F, "Ruestungen: %s\n", pcomp(s->ruestungen, o->ruestungen)); fprintf(F, "ungezaehmte Pferde: %s\n", pcomp(s->pferde, o->pferde)); fprintf(F, "gezaehmte Pferde: %s\n", pcomp(s->spielerpferde, o->spielerpferde)); fprintf(F, "Schiffe: %s\n", pcomp(s->schiffe, o->schiffe)); fprintf(F, "Gebaeude: %s\n", pcomp(s->gebaeude, o->gebaeude)); fprintf(F, "\nBauernpopulation: %s\n", pcomp(s->peasants, o->peasants)); fprintf(F, "Population gesamt: %d\n\n", s->playerpop + s->peasants); fprintf(F, "Reichtum Spieler: %s Silber\n", pcomp(s->playermoney, o->playermoney)); fprintf(F, "Reichtum Bauern: %s Silber\n", pcomp(s->peasantmoney, o->peasantmoney)); fprintf(F, "Reichtum gesamt: %s Silber\n\n", pcomp(s->playermoney + s->peasantmoney, o->playermoney + o->peasantmoney)); } fprintf(F, "\n\n"); newplayers = update_nmrs(); for (i = 0; i <= NMRTimeout(); ++i) { if (i == NMRTimeout()) { fprintf(F, "+ NMR:\t\t %d\n", nmrs[i]); } else { fprintf(F, "%d NMR:\t\t %d\n", i, nmrs[i]); } } if (age) { if (age[2] != 0) { fprintf(F, "Erstabgaben:\t %d%%\n", 100 - (dropouts[0] * 100 / age[2])); } if (age[3] != 0) { fprintf(F, "Zweitabgaben:\t %d%%\n", 100 - (dropouts[1] * 100 / age[3])); } } fprintf(F, "Neue Spieler:\t %d\n", newplayers); if (full) { if (factions) fprintf(F, "\nParteien:\n\n"); for (f = factions; f; f = f->next) { out_faction(F, f); } if (NMRTimeout() && full) { fprintf(F, "\n\nFactions with NMRs:\n"); for (i = NMRTimeout(); i > 0; --i) { for (f = factions; f; f = f->next) { if (i == NMRTimeout()) { if (turn - f->lastorders >= i) { out_faction(F, f); } } else { if (turn - f->lastorders == i) { out_faction(F, f); } } } } } } fclose(F); if (full) { log_info("writing date & turn\n"); writeturn(); } free(nmrs); nmrs = NULL; }
void doinclude(Tokenrow* trp) { char fname[256], iname[256]; Includelist* ip; int angled, len, fd, i; trp->tp += 1; if (trp->tp >= trp->lp) goto syntax; if (trp->tp->type != STRING && trp->tp->type != LT) { len = trp->tp - trp->bp; expandrow(trp, "<include>"); trp->tp = trp->bp + len; } if (trp->tp->type == STRING) { len = trp->tp->len - 2; if (len > sizeof(fname) - 1) len = sizeof(fname) - 1; strncpy(fname, (char*)trp->tp->t + 1, len); angled = 0; } else if (trp->tp->type == LT) { len = 0; trp->tp++; while (trp->tp->type != GT) { if (trp->tp > trp->lp || len + trp->tp->len + 2 >= sizeof(fname)) goto syntax; strncpy(fname + len, (char*)trp->tp->t, trp->tp->len); len += trp->tp->len; trp->tp++; } angled = 1; } else goto syntax; trp->tp += 2; if (trp->tp < trp->lp || len == 0) goto syntax; fname[len] = '\0'; appendDirToIncludeList(basepath(fname)); if (fname[0] == '/') { fd = open(fname, 0); strcpy(iname, fname); } else for (fd = -1, i = NINCLUDE - 1; i >= 0; i--) { ip = &includelist[i]; if (ip->file == NULL || ip->deleted || (angled && ip->always == 0)) continue; if (strlen(fname) + strlen(ip->file) + 2 > sizeof(iname)) continue; strcpy(iname, ip->file); strcat(iname, "/"); strcat(iname, fname); if ((fd = open(iname, 0)) >= 0) break; } if (Mflag > 1 || (!angled && Mflag == 1)) { write(1, objname, strlen(objname)); write(1, iname, strlen(iname)); write(1, "\n", 1); } if (fd >= 0) { if (++incdepth > 10) error(FATAL, "#include too deeply nested"); setsource((char*)newstring((uchar*)iname, strlen(iname), 0), fd, NULL); genline(); } else { trp->tp = trp->bp + 2; error(ERROR, "Could not find include file %r", trp); } return; syntax: error(ERROR, "Syntax error in #include"); return; }
void createProbingPT(const char * phrasetable_path, const char * target_path){ //Get basepath and create directory if missing std::string basepath(target_path); mkdir(basepath.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); //Set up huffman and serialize decoder maps. Huffman huffmanEncoder(phrasetable_path); //initialize huffmanEncoder.assign_values(); huffmanEncoder.produce_lookups(); huffmanEncoder.serialize_maps(target_path); //Get uniq lines: unsigned long uniq_entries = huffmanEncoder.getUniqLines(); //Source phrase vocabids std::map<uint64_t, std::string> source_vocabids; //Read the file util::FilePiece filein(phrasetable_path); //Init the probing hash table size_t size = Table::Size(uniq_entries, 1.2); char * mem = new char[size]; memset(mem, 0, size); Table table(mem, size); BinaryFileWriter binfile(basepath); //Init the binary file writer. line_text prev_line; //Check if the source phrase of the previous line is the same //Keep track of the size of each group of target phrases uint64_t entrystartidx = 0; //uint64_t line_num = 0; //Read everything and processs while(true){ try { //Process line read line_text line; line = splitLine(filein.ReadLine()); //Add source phrases to vocabularyIDs add_to_map(&source_vocabids, line.source_phrase); if ((binfile.dist_from_start + binfile.extra_counter) == 0) { prev_line = line; //For the first iteration assume the previous line is } //The same as this one. if (line.source_phrase != prev_line.source_phrase){ //Create a new entry even //Create an entry for the previous source phrase: Entry pesho; pesho.value = entrystartidx; //The key is the sum of hashes of individual words. Probably not entirerly correct, but fast pesho.key = 0; std::vector<uint64_t> vocabid_source = getVocabIDs(prev_line.source_phrase); for (int i = 0; i < vocabid_source.size(); i++){ pesho.key += vocabid_source[i]; } pesho.bytes_toread = binfile.dist_from_start + binfile.extra_counter - entrystartidx; //Put into table table.Insert(pesho); entrystartidx = binfile.dist_from_start + binfile.extra_counter; //Designate start idx for new entry //Encode a line and write it to disk. std::vector<unsigned char> encoded_line = huffmanEncoder.full_encode_line(line); binfile.write(&encoded_line); //Set prevLine prev_line = line; } else{ //If we still have the same line, just append to it: std::vector<unsigned char> encoded_line = huffmanEncoder.full_encode_line(line); binfile.write(&encoded_line); } } catch (util::EndOfFileException e){ std::cerr << "Reading phrase table finished, writing remaining files to disk." << std::endl; binfile.flush(); //After the final entry is constructed we need to add it to the phrase_table //Create an entry for the previous source phrase: Entry pesho; pesho.value = entrystartidx; //The key is the sum of hashes of individual words. Probably not entirerly correct, but fast pesho.key = 0; std::vector<uint64_t> vocabid_source = getVocabIDs(prev_line.source_phrase); for (int i = 0; i < vocabid_source.size(); i++){ pesho.key += vocabid_source[i]; } pesho.bytes_toread = binfile.dist_from_start + binfile.extra_counter - entrystartidx; //Put into table table.Insert(pesho); break; } } serialize_table(mem, size, (basepath + "/probing_hash.dat").c_str()); serialize_map(&source_vocabids, (basepath + "/source_vocabids").c_str()); delete[] mem; //Write configfile std::ofstream configfile; configfile.open((basepath + "/config").c_str()); configfile << uniq_entries << '\n'; configfile.close(); }
void report_summary(const summary * s, bool full) { FILE *F = NULL; int newplayers = 0; faction *f; char zText[4096]; int timeout = NMRTimeout(); if (full) { path_join(basepath(), "parteien.full", zText, sizeof(zText)); } else { path_join(basepath(), "parteien", zText, sizeof(zText)); } F = fopen(zText, "w"); if (!F) { perror(zText); return; } #ifdef SUMMARY_BOM else { const unsigned char utf8_bom[4] = { 0xef, 0xbb, 0xbf, 0 }; fwrite(utf8_bom, 1, 3, F); } #endif log_info("writing summary to file: parteien.\n"); fprintf(F, "%s\n%s\n\n", game_name(), gamedate2(default_locale)); fprintf(F, "Auswertung Nr: %8d\n\n", turn); fprintf(F, "Parteien: %8d\n", s->factions); fprintf(F, "Einheiten: %8d\n", s->nunits); fprintf(F, "Spielerpopulation: %8d\n", s->playerpop); fprintf(F, " davon bewaffnet: %8d\n", s->armed_men); fprintf(F, " Helden: %8d\n", s->heroes); if (full) { fprintf(F, "Regionen: %8d\n", (int)listlen(regions)); fprintf(F, "Bewohnte Regionen: %8d\n", s->inhabitedregions); fprintf(F, "Landregionen: %8d\n", s->landregionen); fprintf(F, "Spielerregionen: %8d\n", s->regionen_mit_spielern); fprintf(F, "Landspielerregionen: %8d\n", s->landregionen_mit_spielern); fprintf(F, "Inaktive Vulkane: %8d\n", s->inactive_volcanos); fprintf(F, "Aktive Vulkane: %8d\n\n", s->active_volcanos); } summarize_players(s, F); if (full) { fprintf(F, "\n"); { struct language *plang = s->languages; while (plang != NULL) { fprintf(F, "Sprache %2s: %8d\n", locale_name(plang->locale), plang->number); plang = plang->next; } } } fprintf(F, "\n"); summarize_races(s, F, full); if (full) { fprintf(F, "\nWaffen: %8d\n", s->waffen); fprintf(F, "Ruestungen: %8d\n", s->ruestungen); fprintf(F, "ungezaehmte Pferde: %8d\n", s->pferde); fprintf(F, "gezaehmte Pferde: %8d\n", s->spielerpferde); fprintf(F, "Schiffe: %8d\n", s->schiffe); fprintf(F, "Gebaeude: %8d\n", s->gebaeude); fprintf(F, "\nBauernpopulation: %8d\n", s->peasants); fprintf(F, "Population gesamt: %8d\n\n", s->playerpop + s->peasants); fprintf(F, "Reichtum Spieler: %12lld Silber\n", s->playermoney); fprintf(F, "Reichtum Bauern: %12lld Silber\n", s->peasantmoney); fprintf(F, "Reichtum gesamt: %12lld Silber\n\n", s->playermoney + s->peasantmoney); } fprintf(F, "\n"); newplayers = update_nmrs(); if (nmrs) { int i; for (i = 0; i <= timeout; ++i) { if (i == timeout) { fprintf(F, "+ NMR: %3d\n", nmrs[i]); } else { fprintf(F, "%d NMR: %3d\n", i, nmrs[i]); } } } if (age) { if (age[2] != 0) { fprintf(F, "Erstabgaben: %3d%%\n", 100 - (dropouts[0] * 100 / age[2])); } if (age[3] != 0) { fprintf(F, "Zweitabgaben: %3d%%\n", 100 - (dropouts[1] * 100 / age[3])); } } fprintf(F, "Neue Spieler: %d\n", newplayers); if (full) { if (factions) { fprintf(F, "\nParteien:\n\n"); for (f = factions; f; f = f->next) { out_faction(F, f); } } if (timeout>0 && full) { int i; fprintf(F, "\n\nFactions with NMRs:\n"); for (i = timeout; i > 0; --i) { for (f = factions; f; f = f->next) { if (i == timeout) { if (turn - f->lastorders >= i) { out_faction(F, f); } } else { if (turn - f->lastorders == i) { out_faction(F, f); } } } } } } fclose(F); if (full) { log_info("writing date & turn\n"); writeturn(); } free(nmrs); nmrs = NULL; }
int main(int, char**) { //initialise SDL system and the video subsystem if (SDL_Init(SDL_INIT_VIDEO) != 0) { QuitWithError("SDL_Init Error: "); } //Create a Window SDL_Window *win = SDL_CreateWindow("Hello World!", 100, 100, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN); if (win == nullptr) { QuitWithError("SDL_CreateWindow Error: "); } //SDL_SetWindowFullscreen(win, SDL_WINDOW_FULLSCREEN); Mix_Music *music = NULL; Mix_OpenAudio(22050, MIX_DEFAULT_FORMAT, 2, 4096) == -1; std::string basepath(SDL_GetBasePath()); music = Mix_LoadMUS((basepath + "background.wav").c_str()); Mix_PlayMusic(music, -1); Render* renderer = new Render(win); //Main loop flag bool quit = false; b2Vec2 Gravity(0.f, 0.0098f); b2World World(Gravity); string bgPath = basepath + "background22.bmp"; SDL_Surface* back = SDL_LoadBMP(bgPath.c_str()); SDL_Rect* backGroundRect = renderer->AddSurfaceToRenderer(back, 0, -600, 1.0f); Button button = Button(-200, -50, World, renderer); Door door = Door(600, -100, renderer); Level level = Level(World, renderer); Player player = Player(100, 500, World, renderer); vector<Cannon*> cannons; cannons.push_back(new Cannon(170, 350, World, renderer, 1)); cannons.push_back(new Cannon(1010, 50, World, renderer, 2)); cannons.push_back(new Cannon(170, 450, World, renderer, 1)); cannons.push_back(new Cannon(1010, 150, World, renderer, 2)); cannons.push_back(new Cannon(170, 550, World, renderer, 1)); cannons.push_back(new Cannon(1010, 250, World, renderer, 2)); MenuScene* menu = new MenuScene(1200, 100, renderer); SDL_Event e; //thread t1(&Process::run, Process((*(game)))); //Passing references //t1.detach(); //detaches from SDL mainline float prevTicks = SDL_GetTicks(); float currentTicks = SDL_GetTicks(); float FPS = 0; int fpsTimer = 0; SDL_Init(0); //game loop while (!quit) { World.Step(1 / 60.f, 6, 2); while (SDL_PollEvent(&e) != 0) { if (inputHandler.CheckInput(SDLK_ESCAPE, e)) { quit = true; } } if (menu->playBool == false && menu->quitBool == false) { renderer->DrawMenuScene(); menu->Update(renderer); } if (menu->playBool == true) { //PLAY GAME STATE int dir = player.Move(inputHandler, e); for (int i = 0; i < cannons.size(); i++) { cannons.at(i)->Update(); } SDL_Rect rec(player.spriteRect); rec.y = player.GetY(); for (int j = 0; j < cannons.size(); j++) { for (int i = 0; i < cannons.at(j)->fireballs.size(); i++) { if (cannons.at(j)->fireballs.at(i)->CheckCollision(&rec) == true) { std::cout << "Collision Detected!" << std::endl; player.Respawn(); button.setOnce(false); button.buttonBody->SetTransform(b2Vec2(880 / SCALE, 39 / SCALE), 0); door.spriteRect->x = -1000; door.spriteRect->y = -1000; player.prevPosX.clear(); player.prevPosY.clear(); player.count = 0; } } } button.Update(); if (button.CheckCollision(&rec) == true) { std::cout << "Collision Detected!" << std::endl; button.collision = true; button.spriteRect->x = -2000; button.spriteRect->y = -2000; button.buttonBody->SetTransform(b2Vec2(-2000, -2000), 0); //door.Draw(renderer); } if (door.CheckCollision(&rec) == true) { button.buttonBody->SetTransform(b2Vec2(880 / SCALE, 39/ SCALE), 0); std::cout << "Collision Detected!" << std::endl; player.Respawn(); button.setOnce(false); door.spriteRect->x = -1000; door.spriteRect->y = -1000; player.prevPosX.clear(); player.prevPosY.clear(); player.count = 0; player.Respawn(); menu->playBool = false; menu->quitBool = false; menu->backGroundRect->x = 0; menu->current = 0; button.collision = false; } if (button.collision == false) { door.DrawCage(renderer); } if (button.collision == true) { door.DrawNoCage(renderer); } int ticks = SDL_GetTicks(); int seconds = ticks / 50; int sprite = seconds % 8; renderer->Update(player.srcRect, player.dstRect, *player.LeftTexture, *player.RightTexture, *player.StandTexture, sprite, dir, player.moving, player.GetY()); player.dstRect.w = player.spriteRect.w; player.dstRect.h = player.spriteRect.h; player.dstRect.x = player.spriteRect.x; player.dstRect.y = player.spriteRect.y + 5; } if (menu->quitBool == true) { quit = true; } fpsthink(); if (fpsTimer == 60) { printf("%f\n", framespersecond); fpsTimer = 0; } fpsTimer++; } SDL_DestroyRenderer(renderer->ren); SDL_DestroyWindow(win); SDL_DestroyMutex(mutex); SDL_Quit(); return 0; }