static char *_get_lang_name_from_file(const char *file_name, char *lang_code) { char *line; char buf1[256], buf2[256]; ASSERT(file_name); ASSERT(*file_name); ASSERT(lang_code); lang_code[0] = file_name[0]; lang_code[1] = file_name[1]; lang_code[2] = 0; get_executable_name(buf1, sizeof(buf1)); replace_filename(buf2, buf1, file_name, sizeof(buf2)); push_config_state(); set_config_file(buf2); line = m_strdup(get_config_string(0, "language_name", "")); pop_config_state(); if (*line) return line; free(line); return 0; }
static void initialize (void) { get_executable_name (); setup_regexps (); if (target && !detection_mode) { char fn[STRLEN]; char *slash; fn[0] = '\0'; if(depfile_name){ strncpy(fn, depfile_name, STRLEN); } else { slash = strrchr(target, '/'); /* copy the path */ strncat (fn, target, min(STRLEN, slash?slash-target+1:0)); strncat (fn, ".", STRLEN); /* copy the name */ strncat(fn, slash?slash+1:target, STRLEN); strncat (fn, ".d", STRLEN); } fn[STRLEN-1]=0; if((output = fopen (fn, "w"))==0){ fprintf(stderr, "libgendep.so: cannot open %s for writing\n", fn); return; } write_word (target); write_word (":"); } }
void usage() { printf( "OpenFlow Switch Manager.\n" "Usage: %s [OPTION]... [DESTINATION-RULE]...\n" "\n" " -s, --socket=fd secure channnel socket\n" " -n, --name=SERVICE_NAME service name\n" " -l, --logging_level=LEVEL set logging level\n" " --no-flow-cleanup do not cleanup flows on start\n" " -h, --help display this help and exit\n" "\n" "DESTINATION-RULE:\n" " openflow-message-type::destination-service-name\n" "\n" "openflow-message-type:\n" " packet_in packet-in openflow message type\n" " port_status port-status openflow message type\n" " vendor vendor openflow message type\n" " state_notify connection status\n" "\n" "destination-service-name destination service name\n" , get_executable_name() ); }
void usage() { printf( "OpenFlow Switch Manager.\n" "Usage: %s [OPTION]... [DESTINATION-RULE]...\n" "\n" " -s, --socket=fd secure channnel socket\n" " -n, --name=SERVICE_NAME service name\n" " -l, --logging_level=LEVEL set logging level\n" " -g, --syslog output log messages to syslog\n" " -f, --logging_facility=FACILITY set syslog facility\n" " --no-flow-cleanup do not cleanup flows on startup\n" " --no-cookie-translation do not translate cookie values\n" " --no-packet_in do not allow packet-ins on startup\n" " -h, --help display this help and exit\n" "\n" "DESTINATION-RULE:\n" " openflow-message-type::destination-service-name\n" "\n" "openflow-message-type:\n" " packet_in packet-in openflow message type\n" " port_status port-status openflow message type\n" " vendor vendor openflow message type\n" " state_notify connection status\n" "\n" "destination-service-name destination service name\n" , get_executable_name() ); }
static void load_pc8x16_font() { char fname[256]; int n; char *p; get_executable_name(fname, sizeof(fname)); n = strlen(fname); do n--; while (fname[n] !='\\' && fname[n] !='/'); fname[n] = '\0'; append_filename(fname, fname, "pc8x16.fnt", sizeof(fname)); font8x16 = load_font(fname, NULL, NULL); if (font8x16) return; p = getenv("ALLEGRO"); if (p) { strncpy(fname, p, sizeof(fname)); append_filename(fname, fname, "vitetris", sizeof(fname)); set_allegro_resource_path(5, fname); } #ifdef UNIX set_allegro_resource_path(4, "/usr/share/allegro/vitetris"); set_allegro_resource_path(3, "/usr/share/allegro"); set_allegro_resource_path(2, "/usr/local/share/allegro/vitetris"); set_allegro_resource_path(1, "/usr/local/share/allegro"); #endif if (find_allegro_resource(fname, "pc8x16.fnt", 0,0,0,0,0, sizeof(fname)) == 0) font8x16 = load_font(fname, NULL, NULL); }
static char * add_to_file_dir(const char * prefix, const char * suffix) { char * cur_path; char * last; char * ret; size_t output_len; cur_path = get_executable_name(); if ( cur_path == NULL ){ fputs("GetModuleFileName failed\n",stderr); exit(2); } last = strrchr(cur_path, '\\') ; if ( last == NULL ){ fputs("GetModuleFileName failed\n",stderr); exit(2); } *last = '\0'; output_len = strlen(prefix) + strlen(suffix) + strlen(cur_path) + 1 ; ret=xmalloc(output_len); snprintf(ret,output_len,"%s%s%s",prefix,cur_path,suffix); free(cur_path); return ret; }
void ResourceFinder::findInBinDir(const char* filename) { char buf[1024], path[1024]; get_executable_name(path, sizeof(path)); replace_filename(buf, path, filename, sizeof(buf)); addPath(buf); }
std::string redir(const std::string &filename) { char exe[1024], buf[1024]; get_executable_name(exe, sizeof(exe)); replace_filename(buf, exe, filename.c_str(), sizeof(buf)); return std::string(buf); }
void usage() { printf( "Set OpenFlow Switch Manager/Daemon event forward entries.\n" " Switch Manager: %s -m -t EVENT_TYPE service_name1,service_name2,...\n" " Switch Daemon : %s -s SWITCH_DPID -t EVENT_TYPE service_name1,service_name2,...\n" "\n" " EVENT_TYPE:\n" " -t, --type={vendor,packet_in,port_status,state_notify} Specify event type.\n" " TREMA COMMON:\n" " -n, --name=SERVICE_NAME service name\n" " -d, --daemonize run in the background\n" " -l, --logging_level=LEVEL set logging level\n" " -g, --syslog output log messages to syslog\n" " -f, --logging_facility=FACILITY set syslog facility\n" " -h, --help display this help and exit\n" , get_executable_name() , get_executable_name() ); }
/* create_directx_window: * Creates the Allegro window. */ static HWND create_directx_window(void) { static int first = 1; WNDCLASS wnd_class; char fname[1024]; HWND wnd; if (first) { /* setup the window class */ wnd_class.style = CS_HREDRAW | CS_VREDRAW; wnd_class.lpfnWndProc = directx_wnd_proc; wnd_class.cbClsExtra = 0; wnd_class.cbWndExtra = 0; wnd_class.hInstance = allegro_inst; wnd_class.hIcon = LoadIcon(allegro_inst, "allegro_icon"); if (!wnd_class.hIcon) wnd_class.hIcon = LoadIcon(NULL, IDI_APPLICATION); wnd_class.hCursor = LoadCursor(NULL, IDC_ARROW); wnd_class.hbrBackground = NULL; wnd_class.lpszMenuName = NULL; wnd_class.lpszClassName = ALLEGRO_WND_CLASS; RegisterClass(&wnd_class); /* what are we called? */ get_executable_name(fname, sizeof(fname)); ustrlwr(fname); usetc(get_extension(fname), 0); if (ugetat(fname, -1) == '.') usetat(fname, -1, 0); do_uconvert(get_filename(fname), U_CURRENT, wnd_title, U_ASCII, WND_TITLE_SIZE); first = 0; } /* create the window now */ wnd = CreateWindowEx(WS_EX_APPWINDOW, ALLEGRO_WND_CLASS, wnd_title, WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX, -100, -100, 0, 0, NULL, NULL, allegro_inst, NULL); if (!wnd) { _TRACE(PREFIX_E "CreateWindowEx() failed (%s)\n", win_err_str(GetLastError())); return NULL; } ShowWindow(wnd, SW_SHOWNORMAL); SetForegroundWindow(wnd); UpdateWindow(wnd); return wnd; }
bool init_gdb_crash_handler() { if (sem_init(&g_sem_started, 0, 1) != 0 || get_executable_name() != 0) { g_prepared = false; return false; } g_prepared = true; return true; }
void write_help(std::ostream &out) { out << "Usage: " << get_executable_name() << " " << internal::exe_usage << std::endl; out << internal::exe_description << std::endl; out << internal::flags << std::endl; if (internal::help_advanced) { out << "Advanced options:" << std::endl; out << internal::advanced_flags << std::endl; } out << "This program is part of IMP, the Integrative Modeling Platform," << std::endl; out << "which is Copyright 2007-2016 IMP Inventors." << std::endl; out << "For additional information about IMP, " << "see <http://integrativemodeling.org>." << std::endl; }
void usage() { printf( "OpenFlow Switch Manager.\n" "Usage: %s [OPTION]... [-- SWITCH_MANAGER_OPTION]...\n" "\n" " -s, --switch=PATH the command path of switch\n" " -n, --name=SERVICE_NAME service name\n" " -p, --port=PORT server listen port (default %u)\n" " -d, --daemonize run in the background\n" " -l, --logging_level=LEVEL set logging level\n" " -h, --help display this help and exit\n" , get_executable_name(), OFP_TCP_PORT ); }
void load_options(void) { { char ef[256], cf[256]; get_executable_name(ef, 256); replace_filename(cf, ef, "studio.ini", 256); set_config_file(cf); } opt.gfx_w = get_config_int("options", "gfx_w", DEF_GFX_W); opt.gfx_h = get_config_int("options", "gfx_h", DEF_GFX_H); atexit(&save_options); }
extern "C" void be_sys_message(AL_CONST char *msg) { char filename[MAXPATHLEN]; char *title; char tmp[ALLEGRO_MESSAGE_SIZE]; char tmp2[ALLEGRO_MESSAGE_SIZE]; get_executable_name(filename, sizeof(filename)); title = get_filename(filename); BAlert *alert = new BAlert(title, uconvert(msg, U_CURRENT, tmp, U_UTF8, ALLEGRO_MESSAGE_SIZE), uconvert(get_config_text("Ok"), U_CURRENT, tmp2, U_UTF8, ALLEGRO_MESSAGE_SIZE)); alert->SetShortcut(0, B_ESCAPE); be_app->ShowCursor(); alert->Go(); be_app->HideCursor(); }
void write_help(std::ostream &out) { /* Suppress usage if the caller already handles it (e.g. IMP.ArgumentParser Python class) */ if (internal::exe_usage != "==SUPPRESS==") { out << "Usage: " << get_executable_name() << " " << internal::exe_usage << std::endl; } out << internal::exe_description << std::endl; out << internal::flags << std::endl; if (internal::help_advanced) { out << "Advanced options:" << std::endl; out << internal::advanced_flags << std::endl; } out << "This program is part of IMP, the Integrative Modeling Platform," << std::endl; out << "which is Copyright 2007-2018 IMP Inventors." << std::endl; out << "For additional information about IMP, " << "see <https://integrativemodeling.org>." << std::endl; }
// Run an NSF, or a MIDI if the NSF is missing somehow. bool try_zcmusic(char *filename, int track, int midi) { ZCMUSIC *newzcmusic = NULL; // Try the ZC directory first { char exepath[2048]; char musicpath[2048]; get_executable_name(exepath, 2048); replace_filename(musicpath, exepath, filename, 2048); newzcmusic=(ZCMUSIC*)zcmusic_load_file(musicpath); } // Not in ZC directory, try the quest directory if(newzcmusic==NULL) { char musicpath[2048]; replace_filename(musicpath, qstpath, filename, 2048); newzcmusic=(ZCMUSIC*)zcmusic_load_file(musicpath); } // Found it if(newzcmusic!=NULL) { zcmusic_stop(zcmusic); zcmusic_unload_file(zcmusic); stop_midi(); zcmusic=newzcmusic; zcmusic_play(zcmusic, emusic_volume); if(track>0) zcmusic_change_track(zcmusic,track); return true; } // Not found, play MIDI - unless this was called by a script (yay, magic numbers) else if(midi>-1000) jukebox(midi); return false; }
void usage() { printf( "OpenFlow Packet in dispatcher.\n" "Usage: %s [OPTION]... [PACKETIN-DISPATCH-RULE]...\n" "\n" " -n, --name=SERVICE_NAME service name\n" " -d, --daemonize run in the background\n" " -l, --logging_level=LEVEL set logging level\n" " -h, --help display this help and exit\n" "\n" "PACKETIN-DISPATCH-RULE:\n" " dispatch-type::destination-service-name\n" "\n" "dispatch-type:\n" " arp_or_unicast arp or unicast packets\n" " broadcast broadcast (arp not include)\n" "\n" "destination-service-name destination service name\n" , get_executable_name() ); }
// Do whatever is necessary to locate an additional SimCoupe file - The Win32 version looks in the // same directory as the EXE, but other platforms could use an environment variable, etc. // If the path is already fully qualified (an OS-specific decision), return the same string const char* OSD::GetFilePath (const char* pcszFile_/*=""*/) { static char szPath[512], szExePath[MAX_PATH]; // If the supplied file path looks absolute, use it as-is if (*pcszFile_ == PATH_SEPARATOR #if defined(ALLEGRO_WINDOWS) || defined(ALLEGRO_DOS) || strchr(pcszFile_, ':') #endif ) strncpy(szPath, pcszFile_, sizeof szPath); // Form the full path relative to the current EXE file else { // Make sure Allegro is initialised, as get_executable_name() needs it if (!fAllegroInit && !szPath[0]) { allegro_init(); fAllegroInit = true; // Get the full path of the running module get_executable_name(szExePath, sizeof szExePath); // Strip the filename if a full path, otherwise use no path char* psz = strrchr(szExePath, PATH_SEPARATOR); if (psz) psz[1] = '\0'; else szExePath[0] = '\0'; } // Append the supplied file/path strcat(strcpy(szPath, szExePath), pcszFile_); } // Return a pointer to the new path return szPath; }
void usage() { printf( "OpenFlow Packet in Filter.\n" "Usage: %s [OPTION]... [PACKETIN-FILTER-RULE]...\n" "\n" " -n, --name=SERVICE_NAME service name\n" " -d, --daemonize run in the background\n" " -l, --logging_level=LEVEL set logging level\n" " -h, --help display this help and exit\n" "\n" "PACKETIN-FILTER-RULE:\n" " match-type::destination-service-name\n" "\n" "match-type:\n" " lldp LLDP ethernet frame type and priority is 0x8000\n" " packet_in any packet and priority is zero\n" "\n" "destination-service-name destination service name\n" , get_executable_name() ); }
/** * @brief flushes the buffer * * This is the actual worker function. It opens the log file if it wasn't yet * open, composes the addr2line commandline, pipes the buffer through it and * writes the output of that - after some formatting - to the real logfile. */ void CLogger::FlushBuffer() { char buf1[4096], buf2[4096]; char* nl; // Open logfile if it's not open. if (!logfile) { assert(filename); if (!(logfile = fopen(filename, "a"))) return; time_t t; time(&t); char* ct = ctime_r(&t, buf1); if ((nl = strchr(ct, '\n'))) *nl = 0; fprintf(logfile, "\n===> %s <===\n", ct); } // Get executable name if we didn't have it yet. if (exename.empty()) { get_executable_name(buf1, sizeof(buf1)); int len = strlen(buf1); strncpy(buf2, buf1, sizeof(buf2)); buf2[sizeof(buf2)-1] = '\0'; // make sure the string is terminated if (len > 4 && buf2[len-4] == '.') buf2[len-4] = 0; // Note: strncat: 3rd param: maximum number of characters to append STRNCAT(buf2, ".dbg", sizeof(buf2) - strlen(buf2) - 1); fprintf(logfile, "trying debug symbols file: '%s'\n", buf2); struct stat tmp; if (stat(buf2, &tmp) == 0) { exename = buf2; } else { exename = buf1; } if (exename.empty()) return; fprintf(logfile, "executable name: '%s'\n", exename.c_str()); } // Compose addr2line command. std::stringstream command; std::vector<std::string>::iterator it; bool runTheCommand = false; command << ADDR2LINE << " \"--exe=" << exename << "\" --functions --demangle --inline"; for (it = buffer.begin(); it != buffer.end(); ++it) { const int open = it->find('{'); const int close = it->find('}', open + 1); if (open != std::string::npos && close != std::string::npos) { command << " " << it->substr(open + 1, close - open - 1); runTheCommand = true; } } if (runTheCommand) { // We got some addresses, so run the addr2line command. // (This is usually the branch taken by the host) fprintf(logfile, "addr2line command : '%s'\n", command.str().c_str()); // Open pipe to the addr2line command. FILE* p = popen(command.str().c_str(), "r"); if (!p) { fprintf(logfile, " %s\n", strerror(errno)); runTheCommand = false; } else { // Pipe the buffer through the addr2line command. for (it = buffer.begin(); it != buffer.end(); ++it) { const int open = it->find('{'); const int close = it->find('}', open + 1); if (open != std::string::npos && close != std::string::npos) { fgets(buf1, sizeof(buf1), p); fgets(buf2, sizeof(buf2), p); CppFilt(buf1, sizeof(buf1)); if ((nl = strchr(buf1, '\n'))) *nl = 0; if ((nl = strchr(buf2, '\n'))) *nl = 0; fprintf(logfile, "%s%s [%s]%s\n", it->substr(0, open).c_str(), buf1, buf2, it->substr(close + 1).c_str()); } else { fprintf(logfile, "%s\n", it->c_str()); } } // Close pipe & clear buffer. pclose(p); } } if (!runTheCommand) { // Just dump the buffer to the file. // (this is usually the branch taken by the clients) for (it = buffer.begin(); it != buffer.end(); ++it) { fprintf(logfile, "%s\n", it->c_str()); } } buffer.clear(); }
void usage() { topology_service_interface_usage( get_executable_name(), "Sliceable switch.", option_description ); }
void usage() { printf( "Usage: %s COUNT\n", get_executable_name() ); }
void usage() { topology_service_interface_usage( get_executable_name(), "list port", NULL ); }
int eof_add_silence(char * oggfn, unsigned long ms) { char sys_command[1024] = {0}; char backupfn[1024] = {0}; //The file path of the backup of the target audio file char wavfn[1024] = {0}; //The file path of the silent WAV file created char soggfn[1024] = {0}; //The file path of the silent OGG file created char oggcfn[1024] = {0}; //The file path to the oggCat utility char old_wd[1024] = {0}; //Store working directory before changing it so we can get back char *rel_oggfn; //Relative file path to the target audio file char *rel_backupfn; //Relative file path to the backup of the target audio file SAMPLE * silence_sample; int retval; if(!oggfn || (ms == 0) || eof_silence_loaded) { return 1; //Return error: Invalid parameters } eof_log("eof_add_silence() entered", 1); set_window_title("Adjusting Silence..."); /* back up original file */ (void) snprintf(backupfn, sizeof(backupfn) - 1, "%s.backup", oggfn); if(!exists(backupfn)) { (void) eof_copy_file(oggfn, backupfn); } (void) delete_file(oggfn); silence_sample = create_silence_sample(ms); if(!silence_sample) { eof_fix_window_title(); return 2; //Return error: Couldn't create silent audio } (void) replace_filename(wavfn, eof_song_path, "silence.wav", 1024); (void) save_wav(wavfn, silence_sample); destroy_sample(silence_sample); (void) replace_filename(soggfn, eof_song_path, "silence.ogg", 1024); #ifdef ALLEGRO_WINDOWS (void) uszprintf(sys_command, (int) sizeof(sys_command) - 1, "oggenc2 -o \"%s\" -b %d \"%s\"", soggfn, alogg_get_bitrate_ogg(eof_music_track) / 1000, wavfn); #else (void) uszprintf(sys_command, (int) sizeof(sys_command) - 1, "oggenc -o \"%s\" -b %d \"%s\"", soggfn, alogg_get_bitrate_ogg(eof_music_track) / 1000, wavfn); #endif if(eof_system(sys_command)) { eof_fix_window_title(); return 3; //Return error: Could not encode silent audio } /* stitch the original file to the silence file */ if(!getcwd(old_wd, 1024)) { //If the current working directory could not be obtained eof_fix_window_title(); return 4; //Return error: Could not obtain current working directory } (void) eof_chdir(eof_song_path); //Change directory to the project's folder, since oggCat does not support paths that have any Unicode/extended ASCII, relative paths will be given #ifdef ALLEGRO_WINDOWS get_executable_name(oggcfn, 1024); (void) replace_filename(oggcfn, oggcfn, "oggCat.exe", 1024); //Build the full path to oggCat #else ustrzcpy(oggcfn, 1024, "oggCat"); #endif rel_oggfn = get_filename(oggfn); //Get the relative path to the target OGG file rel_backupfn = get_filename(backupfn); //Get the relative path to the backup of the target OGG file //Call oggCat while the current working directory is the project folder. This way, if the project folder's path contains any Unicode or extended ASCII, oggCat won't fail #ifdef ALLEGRO_WINDOWS //For some reason, the Windows build needs extra quotation marks to enclose the entire command if the command begins with a full executable path in quote marks (void) uszprintf(sys_command, (int) sizeof(sys_command) - 1, "\"\"%s\" \"%s\" \"silence.ogg\" \"%s\"\"", oggcfn, rel_oggfn, rel_backupfn); #else (void) uszprintf(sys_command, (int) sizeof(sys_command) - 1, "\"%s\" \"%s\" \"silence.ogg\" \"%s\"", oggcfn, rel_oggfn, rel_backupfn); //Use oggCat to overwrite the target OGG file with the silent audio concatenated with the backup of the target OGG file #endif retval = eof_system(sys_command); /* change back to the program folder */ if(eof_chdir(old_wd)) { allegro_message("Could not change directory to EOF's program folder!\n%s", backupfn); return 5; //Return error: Could not set working directory } if(retval) { //If the command failed (void) snprintf(eof_log_string, sizeof(eof_log_string) - 1, "\tError issuing command \"%s\" from path \"%s\"", sys_command, eof_song_path); eof_log(eof_log_string, 1); (void) eof_copy_file(backupfn, oggfn); //Restore the original OGG file eof_fix_window_title(); return 6; //Return error: oggCat failed } /* clean up */ (void) delete_file(wavfn); //Delete silence.wav (void) delete_file(soggfn); //Delete silence.ogg if(eof_load_ogg(oggfn, 0)) { //If the combined audio was loaded eof_fix_waveform_graph(); eof_fix_spectrogram(); eof_fix_window_title(); eof_chart_length = eof_music_length; return 0; //Return success } eof_fix_window_title(); //If this part of the function is reached, the OGG failed to load if(exists(oggfn)) return 7; //Return error: Could not load new audio, but audio file exists return 8; //Return error: Could not load new audio, file does not exist }
int main(int argc, char *argv[]) { int c, w, h; char buf[256], buf2[256]; ANIMATION_TYPE type; for (c = 1; c < argc; c++) { if (stricmp(argv[c], "-cheat") == 0) cheat = TRUE; if (stricmp(argv[c], "-jumpstart") == 0) jumpstart = TRUE; } /* The fonts we are using don't contain the full latin1 charset (not to * mention Unicode), so in order to display correctly author names in * the credits with 8-bit characters, we will convert them down to 7 * bits with a custom mapping table. Fortunately, Allegro comes with a * default custom mapping table which reduces Latin-1 and Extended-A * characters to 7 bits. We don't even need to call set_ucodepage()! */ set_uformat(U_ASCII_CP); srand(time(NULL)); if (allegro_init() != 0) return 1; install_keyboard(); install_timer(); install_mouse(); if (install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL) != 0) { allegro_message("Error initialising sound\n%s\n", allegro_error); install_sound(DIGI_NONE, MIDI_NONE, NULL); } if (install_joystick(JOY_TYPE_AUTODETECT) != 0) { allegro_message("Error initialising joystick\n%s\n", allegro_error); install_joystick(JOY_TYPE_NONE); } if (set_gfx_mode(GFX_AUTODETECT, 320, 200, 0, 0) != 0) { if (set_gfx_mode(GFX_SAFE, 320, 200, 0, 0) != 0) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("Unable to set any graphic mode\n%s\n", allegro_error); return 1; } } get_executable_name(buf, sizeof(buf)); replace_filename(buf2, buf, "demo.dat", sizeof(buf2)); set_color_conversion(COLORCONV_NONE); data = load_datafile(buf2); if (!data) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("Error loading %s\n", buf2); exit(1); } if (!jumpstart) { intro_screen(); } clear_bitmap(screen); set_gui_colors(); set_mouse_sprite(NULL); if (!gfx_mode_select(&c, &w, &h)) exit(1); if (pick_animation_type(&type) < 0) exit(1); init_display(c, w, h, type); generate_explosions(); //stop_sample(data[INTRO_SPL].dat); clear_bitmap(screen); while (title_screen()) play_game(); destroy_display(); destroy_explosions(); stop_midi(); set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); end_title(); unload_datafile(data); allegro_exit(); return 0; }
void initpc() { char *p; // allegro_init(); get_executable_name(pcempath,511); pclog("executable_name = %s\n", pcempath); p=get_filename(pcempath); *p=0; pclog("path = %s\n", pcempath); fdd_init(); keyboard_init(); mouse_init(); joystick_init(); midi_init(); loadconfig(NULL); pclog("Config loaded\n"); loadfont("mda.rom", 0, cga_fontdat, cga_fontdatm); loadfont("roms/pc1512/40078.ic127", 0, pc1512_fontdat, pc1512_fontdatm); loadfont("roms/pc200/40109.bin", 0, pc200_fontdat, pc200_fontdatm); codegen_init(); cpuspeed2=(AT)?2:1; // cpuspeed2=cpuspeed; atfullspeed=0; device_init(); initvideo(); mem_init(); loadbios(); mem_add_bios(); timer_reset(); sound_reset(); fdc_init(); // #ifdef USE_NETWORKING vlan_reset(); //NETWORK network_card_init(network_card_current); // #endif loaddisc(0,discfns[0]); loaddisc(1,discfns[1]); //loadfont(); loadnvr(); sound_init(); resetide(); #if __unix if (cdrom_drive == -1) cdrom_null_open(cdrom_drive); else #endif ioctl_open(cdrom_drive); pit_reset(); /* if (romset==ROM_AMI386 || romset==ROM_AMI486) */fullspeed(); ali1429_reset(); // CPUID=(is486 && (cpuspeed==7 || cpuspeed>=9)); // pclog("Init - CPUID %i %i\n",CPUID,cpuspeed); shadowbios=0; #if __unix if (cdrom_drive == -1) cdrom_null_reset(); else #endif ioctl_reset(); }
void play_DmapMusic() { static char tfile[2048]; static int ttrack=0; bool domidi=false; // Seems like this ought to call try_zcmusic()... if(DMaps[currdmap].tmusic[0]!=0) { if(zcmusic==NULL || strcmp(zcmusic->filename,DMaps[currdmap].tmusic)!=0 || (zcmusic->type==ZCMF_GME && zcmusic->track != DMaps[currdmap].tmusictrack)) { if(zcmusic != NULL) { zcmusic_stop(zcmusic); zcmusic_unload_file(zcmusic); zcmusic = NULL; } // Try the ZC directory first { char exepath[2048]; char musicpath[2048]; get_executable_name(exepath, 2048); replace_filename(musicpath, exepath, DMaps[currdmap].tmusic, 2048); zcmusic=(ZCMUSIC*)zcmusic_load_file(musicpath); } // Not in ZC directory, try the quest directory if(zcmusic==NULL) { char musicpath[2048]; replace_filename(musicpath, qstpath, DMaps[currdmap].tmusic, 2048); zcmusic=(ZCMUSIC*)zcmusic_load_file(musicpath); } if(zcmusic!=NULL) { stop_midi(); strcpy(tfile,DMaps[currdmap].tmusic); zcmusic_play(zcmusic, emusic_volume); int temptracks=0; temptracks=zcmusic_get_tracks(zcmusic); temptracks=(temptracks<2)?1:temptracks; ttrack = vbound(DMaps[currdmap].tmusictrack,0,temptracks-1); zcmusic_change_track(zcmusic,ttrack); } else { tfile[0] = 0; domidi=true; } } } else { domidi=true; } if(domidi) { int m=DMaps[currdmap].midi; switch(m) { case 1: jukebox(ZC_MIDI_OVERWORLD); break; case 2: jukebox(ZC_MIDI_DUNGEON); break; case 3: jukebox(ZC_MIDI_LEVEL9); break; default: if(m>=4 && m<4+MAXCUSTOMMIDIS) jukebox(m-4+ZC_MIDI_COUNT); else music_stop(); } } }
int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil) { HWND hwnd; /* This is the handle for our window */ MSG messages; /* Here messages to the application are saved */ WNDCLASSEX wincl; /* Data structure for the windowclass */ int c; int oldf = 0; char *p; for (c = 0; c < 128; c++) keylookup[c] = c; processcommandline(); hinstance = hThisInstance; /* The Window structure */ wincl.hInstance = hThisInstance; wincl.lpszClassName = szClassName; wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */ wincl.style = CS_DBLCLKS; /* Catch double-clicks */ wincl.cbSize = sizeof (WNDCLASSEX); /* Use default icon and mouse-pointer */ wincl.hIcon = LoadIcon(hThisInstance, "allegro_icon"); wincl.hIconSm = LoadIcon(hThisInstance, "allegro_icon"); wincl.hCursor = LoadCursor (NULL, IDC_ARROW); wincl.lpszMenuName = NULL; /* No menu */ wincl.cbClsExtra = 0; /* No extra bytes after the window class */ wincl.cbWndExtra = 0; /* structure or the window instance */ /* Use Windows's default color as the background of the window */ wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND; /* Register the window class, and if it fails quit the program */ if (!RegisterClassEx (&wincl)) return 0; /* The class is registered, let's create the program*/ hwnd = CreateWindowEx ( 0, /* Extended possibilites for variation */ szClassName, /* Classname */ VERSION_STR, /* Title Text */ WS_OVERLAPPEDWINDOW/*&~WS_SIZEBOX&~WS_THICKFRAME&~WS_MAXIMIZEBOX*/, /* default window */ CW_USEDEFAULT, /* Windows decides the position */ CW_USEDEFAULT, /* where the window ends up on the screen */ 640 + (GetSystemMetrics(SM_CXFIXEDFRAME) * 2), /* The programs width */ 480 + (GetSystemMetrics(SM_CYFIXEDFRAME) * 2) + GetSystemMetrics(SM_CYMENUSIZE) + GetSystemMetrics(SM_CYCAPTION) + 1, /* and height in pixels */ HWND_DESKTOP, /* The window is a child-window to desktop */ LoadMenu(hThisInstance, TEXT("MainMenu")), /* No menu */ hThisInstance, /* Program Instance handler */ NULL /* No Window Creation data */ ); ghwnd = hwnd; win_set_window(hwnd); allegro_init(); get_executable_name(exedir, 511); p = get_filename(exedir); p[0] = 0; config_load(); InitializeCriticalSection(&cs); /* Make the window visible on the screen */ ShowWindow (hwnd, nFunsterStil); initmenu(); mainthread = (HANDLE)_beginthread(_mainthread, 0, NULL); updatewindowtitle(); /* Run the message loop. It will run until GetMessage() returns 0 */ while (!quited) { // runbbc(); if (PeekMessage(&messages, NULL, 0, 0, PM_REMOVE)) { if (messages.message == WM_QUIT) { quited=1; } TranslateMessage(&messages); DispatchMessage(&messages); } else Sleep(10); if ((key[KEY_LCONTROL] || key[KEY_RCONTROL]) && key[KEY_END] && mousecapture) { ClipCursor(&oldclip); mousecapture = 0; updatewindowtitle(); } if (key[KEY_ALT] && key[KEY_ENTER] && fullscreen && !oldf) { EnterCriticalSection(&cs); fullscreen = 0; video_leavefullscreen(); LeaveCriticalSection(&cs); } else if (key[KEY_ALT] && key[KEY_ENTER] && !fullscreen && !oldf) { EnterCriticalSection(&cs); fullscreen = 1; video_enterfullscreen(); LeaveCriticalSection(&cs); } oldf = key[KEY_ALT] && key[KEY_ENTER]; } EnterCriticalSection(&cs); TerminateThread(mainthread, 0); main_close(); DeleteCriticalSection(&cs); return messages.wParam; }
/** * Prepares command line arguments */ int parseargs(int* out_argc, char*** out_args) { // get argument line from system char* unparsedCommandLine = (char*) malloc(G_CLIARGS_BUFFER_LENGTH); if (unparsedCommandLine == NULL) { return -1; } g_cli_args_release(unparsedCommandLine); // count arguments char* pos = unparsedCommandLine; int argc = 1; while (*pos) { SKIP_WHITESPACE(pos); SKIP_ARGUMENT(pos); ++argc; } // create argument array char** argv = (char**) malloc(sizeof(char*) * (argc + 1)); if (argv == NULL) { return -1; } // put executable path as first argument argv[0] = get_executable_name(); pos = unparsedCommandLine; int argpp = 1; while (*pos) { SKIP_WHITESPACE(pos); argv[argpp++] = pos; SKIP_ARGUMENT(pos); if (*pos == 0) { break; } *pos++ = 0; } argv[argpp] = 0; // clean up arguments for (int i = 1; i < argc; i++) { char* arg = argv[i]; size_t arglen = strlen(arg); bool esc = false; for (int p = 0; p < arglen; p++) { if (!esc && arg[p] == '\\') { for (int x = p; x < arglen; x++) { arg[x] = arg[x + 1]; } arglen--; --p; // repeat on same position esc = true; } else if (!esc && arg[p] == '"') { for (int x = p; x < arglen; x++) { arg[x] = arg[x + 1]; } arglen--; --p; // repeat on same position esc = false; } else { esc = false; } } } // write out parameters *out_argc = argc; *out_args = argv; return 0; }