int main(int argc, char **argv) #endif { int i; #ifdef LINUXVGA LINUX_setup(); /* setup VGA before dropping privilege DBT 4/5/99 */ drop_privilege(); #endif /* make sure that we really have revoked root access, this might happen if gnuplot is compiled without vga support but is installed suid by mistake */ #ifdef __linux__ setuid(getuid()); #endif #if defined(MSDOS) && !defined(_Windows) && !defined(__GNUC__) PC_setup(); #endif /* MSDOS !Windows */ /* HBB: Seems this isn't needed any more for DJGPP V2? */ /* HBB: disable all floating point exceptions, just keep running... */ #if defined(DJGPP) && (DJGPP!=2) _control87(MCW_EM, MCW_EM); #endif #if defined(OS2) int rc; #ifdef OS2_IPC char semInputReadyName[40]; sprintf( semInputReadyName, "\\SEM32\\GP%i_Input_Ready", getpid() ); rc = DosCreateEventSem(semInputReadyName,&semInputReady,0,0); if (rc != 0) fputs("DosCreateEventSem error\n",stderr); #endif rc = RexxRegisterSubcomExe("GNUPLOT", (PFN) RexxInterface, NULL); #endif /* malloc large blocks, otherwise problems with fragmented mem */ #ifdef MALLOCDEBUG malloc_debug(7); #endif /* get helpfile from home directory */ #ifdef __DJGPP__ { char *s; strcpy(HelpFile, argv[0]); for (s = HelpFile; *s; s++) if (*s == DIRSEP1) *s = DIRSEP2; /* '\\' to '/' */ strcpy(strrchr(HelpFile, DIRSEP2), "/gnuplot.gih"); } /* Add also some "paranoid" tests for '\\': AP */ #endif /* DJGPP */ #ifdef VMS unsigned int status[2] = { 1, 0 }; #endif #if defined(HAVE_LIBEDITLINE) rl_getc_function = getc_wrapper; #endif #if defined(HAVE_LIBREADLINE) || defined(HAVE_LIBEDITLINE) /* T.Walter 1999-06-24: 'rl_readline_name' must be this fix name. * It is used to parse a 'gnuplot' specific section in '~/.inputrc' * or gnuplot specific commands in '.editrc' (when using editline * instead of readline) */ rl_readline_name = "Gnuplot"; rl_terminal_name = getenv("TERM"); #if defined(HAVE_LIBREADLINE) using_history(); #else history_init(); #endif #endif #if defined(HAVE_LIBREADLINE) && !defined(MISSING_RL_TILDE_EXPANSION) rl_complete_with_tilde_expansion = 1; #endif for (i = 1; i < argc; i++) { if (!argv[i]) continue; if (!strcmp(argv[i], "-V") || !strcmp(argv[i], "--version")) { printf("gnuplot %s patchlevel %s\n", gnuplot_version, gnuplot_patchlevel); return 0; } else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) { printf( "Usage: gnuplot [OPTION]... [FILE]\n" #ifdef X11 "for X11 options see 'help X11->command-line-options'\n" #endif " -V, --version\n" " -h, --help\n" " -p --persist\n" " -d --default-settings\n" " -e \"command1; command2; ...\"\n" "gnuplot %s patchlevel %s\n", gnuplot_version, gnuplot_patchlevel); #ifdef DEVELOPMENT_VERSION printf( #ifdef DIST_CONTACT "Report bugs to "DIST_CONTACT"\n" " or %s\n", #else "Report bugs to %s\n", #endif bug_email); #endif return 0; } else if (!strncmp(argv[i], "-persist", 2) || !strcmp(argv[i], "--persist") #ifdef _Windows || !stricmp(argv[i], "-noend") || !stricmp(argv[i], "/noend") #endif ) { persist_cl = TRUE; } else if (!strncmp(argv[i], "-d", 2) || !strcmp(argv[i], "--default-settings")) { /* Skip local customization read from ~/.gnuplot */ skip_gnuplotrc = TRUE; } } #ifdef X11 /* the X11 terminal removes tokens that it recognizes from argv. */ { int n = X11_args(argc, argv); argv += n; argc -= n; } #endif setbuf(stderr, (char *) NULL); #ifdef HAVE_SETVBUF /* This was once setlinebuf(). Docs say this is * identical to setvbuf(,NULL,_IOLBF,0), but MS C * faults this (size out of range), so we try with * size of 1024 instead. [SAS/C does that, too. -lh] */ if (setvbuf(stdout, (char *) NULL, _IOLBF, (size_t) 1024) != 0) (void) fputs("Could not linebuffer stdout\n", stderr); /* Switching to unbuffered mode causes all characters in the input * buffer to be lost. So the only safe time to do it is on program entry. * Do any non-X platforms suffer from this problem? * EAM - Jan 2013 YES. */ setvbuf(stdin, (char *) NULL, _IONBF, 0); #endif gpoutfile = stdout; /* Initialize pre-loaded user variables */ (void) Gcomplex(&udv_pi.udv_value, M_PI, 0.0); udv_NaN = add_udv_by_name("NaN"); (void) Gcomplex(&(udv_NaN->udv_value), not_a_number(), 0.0); udv_NaN->udv_undef = FALSE; init_memory(); interactive = FALSE; init_terminal(); /* can set term type if it likes */ push_terminal(0); /* remember the default terminal */ /* reset the terminal when exiting */ /* this is done through gp_atexit so that other terminal functions * can be registered to be executed before the terminal is reset. */ GP_ATEXIT(term_reset); # if defined(_Windows) && ! defined(WGP_CONSOLE) interactive = TRUE; # else interactive = isatty(fileno(stdin)); # endif /* Note: we want to know whether this is an interactive session so that we can * decide whether or not to write status information to stderr. The old test * for this was to see if (argc > 1) but the addition of optional command line * switches broke this. What we really wanted to know was whether any of the * command line arguments are file names or an explicit in-line "-e command". */ for (i = 1; i < argc; i++) { # ifdef _Windows if (!stricmp(argv[i], "/noend")) continue; # endif if ((argv[i][0] != '-') || (argv[i][1] == 'e')) { interactive = FALSE; break; } } /* Need this before show_version is called for the first time */ #ifdef HAVE_SYS_UTSNAME_H { struct utsname uts; /* something is fundamentally wrong if this fails ... */ if (uname(&uts) > -1) { # ifdef _AIX strcpy(os_name, uts.sysname); sprintf(os_name, "%s.%s", uts.version, uts.release); # elif defined(SCO) strcpy(os_name, "SCO"); strcpy(os_rel, uts.release); # elif defined(DJGPP) if (!strncmp(uts.sysname, "??Un", 4)) /* don't print ??Unknow" */ strcpy(os_name, "Unknown"); else { strcpy(os_name, uts.sysname); strcpy(os_rel, uts.release); } # else strcpy(os_name, uts.sysname); strcpy(os_rel, uts.machine); # ifdef OS2 if (!strchr(os_rel,'.')) /* write either "2.40" or "4.0", or empty -- don't print "OS/2 1" */ strcpy(os_rel, ""); # endif # endif } } #else /* ! HAVE_SYS_UTSNAME_H */ strcpy(os_name, OS); strcpy(os_rel, ""); #endif /* HAVE_SYS_UTSNAME_H */ if (interactive) show_version(stderr); else show_version(NULL); /* Only load GPVAL_COMPILE_OPTIONS */ #ifdef WGP_CONSOLE #ifdef CONSOLE_SWITCH_CP if (cp_changed && interactive) { fprintf(stderr, "\ngnuplot changed the codepage of this console from %i to %i to\n" \ "match the graph window. Some characters might only display correctly\n" \ "if you change the font to a non-raster type.\n", cp_input, GetConsoleCP()); } #else if ((GetConsoleCP() != GetACP()) && interactive) { fprintf(stderr, "\nWarning: The codepage of the graph window (%i) and that of the\n" \ "console (%i) differ. Use `set encoding` or `!chcp` if extended\n" \ "characters don't display correctly.\n", GetACP(), GetConsoleCP()); } #endif #endif update_gpval_variables(3); /* update GPVAL_ variables available to user */ #ifdef VMS /* initialise screen management routines for command recall */ if (status[1] = smg$create_virtual_keyboard(&vms_vkid) != SS$_NORMAL) done(status[1]); if (status[1] = smg$create_key_table(&vms_ktid) != SS$_NORMAL) done(status[1]); #endif /* VMS */ if (!SETJMP(command_line_env, 1)) { /* first time */ interrupt_setup(); /* should move this stuff another initialisation routine, * something like init_set() maybe */ get_user_env(); init_loadpath(); init_locale(); /* HBB: make sure all variables start in the same mode 'reset' * would set them to. Since the axis variables aren't in * initialized arrays any more, this is now necessary... */ reset_command(); init_color(); /* Initialization of color */ load_rcfile(0); /* System-wide gnuplotrc if configured */ load_rcfile(1); /* ./.gnuplot if configured */ init_fit(); /* Initialization of fitting module */ /* After this point we allow pipes and system commands */ successful_initialization = TRUE; load_rcfile(2); /* ~/.gnuplot */ if (interactive && term != 0) { /* not unknown */ #ifdef GNUPLOT_HISTORY FPRINTF((stderr, "Before read_history\n")); #if defined(HAVE_LIBREADLINE) || defined(HAVE_LIBEDITLINE) expanded_history_filename = tilde_expand(GNUPLOT_HISTORY_FILE); #else expanded_history_filename = gp_strdup(GNUPLOT_HISTORY_FILE); gp_expand_tilde(&expanded_history_filename); #endif FPRINTF((stderr, "expanded_history_filename = %s\n", expanded_history_filename)); read_history(expanded_history_filename); { /* BEGIN: Go local to get environment variable */ const char *temp_env = getenv ("GNUPLOT_HISTORY_SIZE"); if (temp_env) gnuplot_history_size = strtol (temp_env, (char **) NULL, 10); } /* END: Go local to get environment variable */ /* * It is safe to ignore the return values of 'atexit()' and * 'on_exit()'. In the worst case, there is no history of your * currrent session and you have to type all again in your next * session. * This is the default behaviour (traditional reasons), too. * In case you don't have one of these functions, or you don't * want to use them, 'write_history()' is called directly. */ GP_ATEXIT(wrapper_for_write_history); #endif /* GNUPLOT_HISTORY */ fprintf(stderr, "\nTerminal type set to '%s'\n", term->name); } /* if (interactive && term != 0) */ } else { /* come back here from int_error() */ if (!successful_initialization) { /* Only print the warning once */ successful_initialization = TRUE; fprintf(stderr,"WARNING: Error during initialization\n\n"); } if (interactive == FALSE) exit_status = EXIT_FAILURE; #ifdef HAVE_READLINE_RESET else { /* reset properly readline after a SIGINT+longjmp */ rl_reset_after_signal (); } #endif load_file_error(); /* if we were in load_file(), cleanup */ SET_CURSOR_ARROW; #ifdef VMS /* after catching interrupt */ /* VAX stuffs up stdout on SIGINT while writing to stdout, so reopen stdout. */ if (gpoutfile == stdout) { if ((stdout = freopen("SYS$OUTPUT", "w", stdout)) == NULL) { /* couldn't reopen it so try opening it instead */ if ((stdout = fopen("SYS$OUTPUT", "w")) == NULL) { /* don't use int_error here - causes infinite loop! */ fputs("Error opening SYS$OUTPUT as stdout\n", stderr); } } gpoutfile = stdout; } #endif /* VMS */ if (!interactive && !noinputfiles) { term_reset(); exit(EXIT_FAILURE); /* exit on non-interactive error */ } } /* load filenames given as arguments */ while (--argc > 0) { ++argv; c_token = 0; if (!strncmp(*argv, "-persist", 2) || !strcmp(*argv, "--persist") #ifdef _Windows || !stricmp(*argv, "-noend") || !stricmp(*argv, "/noend") #endif ) { FPRINTF((stderr,"'persist' command line option recognized\n")); } else if (strcmp(*argv, "-") == 0) { #if defined(_Windows) && !defined(WGP_CONSOLE) TextShow(&textwin); #endif interactive = TRUE; while (!com_line()); interactive = FALSE; } else if (strcmp(*argv, "-e") == 0) { --argc; ++argv; if (argc <= 0) { fprintf(stderr, "syntax: gnuplot -e \"commands\"\n"); return 0; } interactive = FALSE; noinputfiles = FALSE; do_string(*argv); } else if (!strncmp(*argv, "-d", 2) || !strcmp(*argv, "--default-settings")) { /* Ignore this; it already had its effect */ FPRINTF((stderr, "ignoring -d\n")); } else if (*argv[0] == '-') { fprintf(stderr, "unrecognized option %s\n", *argv); } else { interactive = FALSE; noinputfiles = FALSE; load_file(loadpath_fopen(*argv, "r"), gp_strdup(*argv), FALSE); } } #ifdef _Windows /* On Windows 'persist' is handled by keeping the main input loop running. */ if (persist_cl) { interactive = TRUE; while (!com_line()); interactive = FALSE; } else #endif { /* take commands from stdin */ if (noinputfiles) while (!com_line()); } #if (defined(HAVE_LIBREADLINE) || defined(HAVE_LIBEDITLINE)) && defined(GNUPLOT_HISTORY) #if !defined(HAVE_ATEXIT) && !defined(HAVE_ON_EXIT) /* You should be here if you neither have 'atexit()' nor 'on_exit()' */ wrapper_for_write_history(); #endif /* !HAVE_ATEXIT && !HAVE_ON_EXIT */ #endif /* (HAVE_LIBREADLINE || HAVE_LIBEDITLINE) && GNUPLOT_HISTORY */ #ifdef OS2 RexxDeregisterSubcom("GNUPLOT", NULL); #endif /* HBB 20040223: Not all compilers like exit() to end main() */ /* exit(exit_status); */ return exit_status; }
inline _2dArray<T>::_2dArray(size_t extent0, size_t extent1) { init_memory(extent0, extent1); }
inline _2dArray<T>::_2dArray(const _2dArray& other) { init_memory(other.m_extents[0], other.m_extents[1]); std::copy(other.begin(), other.end(), m_storage); }
void init_sim(void){ init_regs(0); init_memory(0); init_clock(); init_pipeline(); }
int init(int ac, char **av) { /* temporary ChannelInfo *ci; NickInfo *ni; */ int i; int openlog_failed = 0, openlog_errno = 0; int started_from_term = isatty(0) && isatty(1) && isatty(2); /* Initialize pseudo-random number generator. */ srand(time(NULL) ^ getppid() ^ getpid()<<16); /* Set file creation mask and group ID. */ #if defined(DEFUMASK) && HAVE_UMASK umask(DEFUMASK); #endif if (set_group() < 0) return -1; /* Parse command-line options; exit if an error occurs. */ if (parse_options(ac, av) < 0) return -1; /* Chdir to Services data directory. */ if (chdir(services_dir) < 0) { fprintf(stderr, "chdir(%s): %s\n", services_dir, strerror(errno)); return -1; } /* Open logfile, and complain if we didn't. */ if (open_log() < 0) { openlog_errno = errno; if (started_from_term) { fprintf(stderr, "Warning: unable to open log file %s: %s\n", log_filename, strerror(errno)); } else { openlog_failed = 1; } } /* Read configuration file; exit if there are problems. */ if (!read_config()) return -1; /* Re-parse command-line options (to override configuration file). */ parse_options(ac, av); /* Detach ourselves if requested. */ if (!nofork) { if ((i = fork()) < 0) { perror("fork()"); return -1; } else if (i != 0) { exit(0); } if (started_from_term) { close(0); close(1); close(2); } if (setpgid(0, 0) < 0) { perror("setpgid()"); return -1; } } #ifdef MEMCHECKS /* Account for runtime memory. Do this after forking to avoid a bogus * "XXX bytes leaked on exit" message when the parent exits. */ init_memory(); #endif /* Write our PID to the PID file. */ write_pidfile(); /* Announce ourselves to the logfile. */ if (debug || readonly || skeleton || noexpire) { log("Services %s (compiled for %s) starting up (options:%s%s%s%s)", version_number, version_protocol, debug ? " debug" : "", readonly ? " readonly" : "", skeleton ? " skeleton" : "", noexpire ? " noexpire" : ""); } else { log("Services %s (compiled for %s) starting up", version_number, version_protocol); } start_time = time(NULL); /* If in read-only mode, close the logfile again. */ if (readonly) close_log(); /* Set signal handlers. Catch certain signals to let us do things or * panic as necessary, and ignore all others. */ #ifdef NSIG for (i = 1; i <= NSIG; i++) { #else for (i = 1; i <= 32; i++) { #endif if (i != SIGPROF) signal(i, SIG_IGN); } signal(SIGINT, weirdsig_handler); signal(SIGTERM, weirdsig_handler); signal(SIGQUIT, weirdsig_handler); #ifndef DUMPCORE signal(SIGSEGV, weirdsig_handler); #endif signal(SIGBUS, weirdsig_handler); signal(SIGQUIT, weirdsig_handler); signal(SIGHUP, weirdsig_handler); signal(SIGILL, weirdsig_handler); signal(SIGTRAP, weirdsig_handler); signal(SIGFPE, weirdsig_handler); #ifdef SIGIOT signal(SIGIOT, weirdsig_handler); #endif /* This is our "out-of-memory" panic switch */ signal(SIGUSR1, weirdsig_handler); /* Initialize multi-language support */ lang_init(); if (debug) log("debug: Loaded languages"); /* Initialiize subservices */ ns_init(); cs_init(); #ifdef USE_MYSQL if(!db_connect(1)) fatal("could not connect to mysql database"); #endif /* Load up databases */ if (!skeleton) { db_load_ns(); //load_ns_dbase(); if (debug) log("debug: Loaded %s database (1/7)", s_NickServ); db_load_cs(); //load_cs_dbase(); if (debug) log("debug: Loaded %s database (2/7)", s_ChanServ); /* start: temporary code */ /* for (ni = firstnick(); ni; ni = nextnick()) { genpass(ni->pass); email_pass(ni->email ? ni->email : "invalid", ni->pass, ni->nick); log("debug: genpass for [%s]", ni->nick); #ifdef USE_ENCRYPTION encrypt_in_place(ni->pass, PASSMAX - 1); #endif db_nick_set(ni, "pass", ni->pass); } for(ci = cs_firstchan(); ci; ci = cs_nextchan()) { genpass(ci->founderpass); email_pass(ci->email ? ci->email : "invalid", ci->founderpass, ci->name); log("debug: genpass for [%s]", ci->name); #ifdef USE_ENCRYPTION encrypt_in_place(ci->founderpass, PASSMAX - 1); #endif db_chan_set(ci, "founderpass", ci->founderpass); } exit(0); */ /* for (ni = firstnick(); ni; ni = nextnick()) { if(db_add_nick(ni) == -1) log("dberror: while adding nicks. continuing"); } for(ci = cs_firstchan(); ci; ci = cs_nextchan()) { if(db_add_channel(ci) == -1) log("dberror: while adding channels. continuing"); } exit(1); */ /* end: temporary code */ } log("Databases loaded"); /* Connect to the remote server */ servsock = conn(RemoteServer, RemotePort, LocalHost, LocalPort); if (servsock < 0) fatal_perror("Can't connect to server"); send_server(); sgets2(inbuf, sizeof(inbuf), servsock); if (strnicmp(inbuf, "ERROR", 5) == 0) { /* Close server socket first to stop wallops, since the other * server doesn't want to listen to us anyway */ disconn(servsock); servsock = -1; fatal("Remote server returned: %s", inbuf); } /* Announce a logfile error if there was one */ if (openlog_failed) { wallops(NULL, "Warning: couldn't open logfile: %s", strerror(openlog_errno)); } /* Bring in our pseudo-clients */ introduce_user(NULL); /* Success! */ return 0; }
environment_data::environment_data( ) { init_memory( &direction, &intensity, sizeof( intensity ) ); }
int main(int argc, char **argv) #endif { int i; #ifdef LINUXVGA LINUX_setup(); /* setup VGA before dropping privilege DBT 4/5/99 */ drop_privilege(); #endif /* make sure that we really have revoked root access, this might happen if gnuplot is compiled without vga support but is installed suid by mistake */ #ifdef __linux__ setuid(getuid()); #endif #if defined(MSDOS) && !defined(_Windows) && !defined(__GNUC__) PC_setup(); #endif /* MSDOS !Windows */ /* HBB: Seems this isn't needed any more for DJGPP V2? */ /* HBB: disable all floating point exceptions, just keep running... */ #if defined(DJGPP) && (DJGPP!=2) _control87(MCW_EM, MCW_EM); #endif #if defined(OS2) int rc; #ifdef OS2_IPC char semInputReadyName[40]; sprintf( semInputReadyName, "\\SEM32\\GP%i_Input_Ready", getpid() ); rc = DosCreateEventSem(semInputReadyName,&semInputReady,0,0); if (rc != 0) fputs("DosCreateEventSem error\n",stderr); #endif rc = RexxRegisterSubcomExe("GNUPLOT", (PFN) RexxInterface, NULL); #endif /* malloc large blocks, otherwise problems with fragmented mem */ #ifdef OSK _mallocmin(102400); #endif #ifdef MALLOCDEBUG malloc_debug(7); #endif /* get helpfile from home directory */ #ifndef DOSX286 # ifndef _Windows # if defined (__TURBOC__) && (defined (MSDOS) || defined(DOS386)) strcpy(HelpFile, argv[0]); strcpy(strrchr(HelpFile, DIRSEP1), "\\gnuplot.gih"); # endif /* - DJL */ # endif /* !_Windows */ #endif /* !DOSX286 */ #ifdef __DJGPP__ { char *s; strcpy(HelpFile, argv[0]); for (s = HelpFile; *s; s++) if (*s == DIRSEP1) *s = DIRSEP2; /* '\\' to '/' */ strcpy(strrchr(HelpFile, DIRSEP2), "/gnuplot.gih"); } /* Add also some "paranoid" tests for '\\': AP */ #endif /* DJGPP */ #ifdef VMS unsigned int status[2] = { 1, 0 }; #endif #if defined(HAVE_LIBEDITLINE) rl_getc_function = getc_wrapper; #endif #if defined(HAVE_LIBREADLINE) || defined(HAVE_LIBEDITLINE) using_history(); /* T.Walter 1999-06-24: 'rl_readline_name' must be this fix name. * It is used to parse a 'gnuplot' specific section in '~/.inputrc' */ rl_readline_name = "Gnuplot"; rl_terminal_name = getenv("TERM"); #endif #if defined(HAVE_LIBREADLINE) rl_complete_with_tilde_expansion = 1; #endif for (i = 1; i < argc; i++) { if (!argv[i]) continue; if (!strcmp(argv[i], "-V") || !strcmp(argv[i], "--version")) { printf("gnuplot %s patchlevel %s\n", gnuplot_version, gnuplot_patchlevel); return 0; } else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) { printf( "Usage: gnuplot [OPTION]... [FILE]\n" #ifdef X11 "for X11 options see 'help X11->command-line-options'\n" #endif " -V, --version\n" " -h, --help\n" " -p --persist\n" " -e \"command1; command2; ...\"\n" "gnuplot %s patchlevel %s\n" #ifdef DIST_CONTACT "Report bugs to "DIST_CONTACT"\n" " or %s\n", #else "Report bugs to %s\n", #endif gnuplot_version, gnuplot_patchlevel, bug_report); return 0; } else if (!strncmp(argv[i], "-persist", 2) || !strcmp(argv[i], "--persist")) { persist_cl = TRUE; } } #ifdef X11 /* the X11 terminal removes tokens that it recognizes from argv. */ { int n = X11_args(argc, argv); argv += n; argc -= n; } #endif #ifdef APOLLO apollo_pfm_catch(); #endif setbuf(stderr, (char *) NULL); #ifdef HAVE_SETVBUF /* this was once setlinebuf(). Docs say this is * identical to setvbuf(,NULL,_IOLBF,0), but MS C * faults this (size out of range), so we try with * size of 1024 instead. [SAS/C does that, too. -lh] * Failing this, I propose we just make the call and * ignore the return : its probably not a big deal */ if (setvbuf(stdout, (char *) NULL, _IOLBF, (size_t) 1024) != 0) (void) fputs("Could not linebuffer stdout\n", stderr); #ifdef X11 /* This call used to be in x11.trm, with the following comment: * Multi-character inputs like escape sequences but also mouse-pasted * text got buffered and therefore didn't trigger the select() function * in X11_waitforinput(). Switching to unbuffered input solved this. * 23 Jan 2002 (joze) * But switching to unbuffered mode causes all characters in the input * buffer to be lost. So the only safe time to do it is on program entry. * The #ifdef X11 is probably unnecessary, but makes the change minimal. * Do any non-X platforms suffer from the same problem? * EAM - Jan 2004. */ setvbuf(stdin, (char *) NULL, _IONBF, 0); #endif #endif gpoutfile = stdout; /* Initialize pre-loaded user variables */ (void) Gcomplex(&udv_pi.udv_value, M_PI, 0.0); #ifdef HAVE_ISNAN udv_NaN = add_udv_by_name("NaN"); (void) Gcomplex(&(udv_NaN->udv_value), not_a_number(), 0.0); udv_NaN->udv_undef = FALSE; #endif init_memory(); interactive = FALSE; init_terminal(); /* can set term type if it likes */ push_terminal(0); /* remember the default terminal */ /* reset the terminal when exiting */ /* this is done through gp_atexit so that other terminal functions * can be registered to be executed before the terminal is reset. */ GP_ATEXIT(term_reset); #ifdef AMIGA_SC_6_1 if (IsInteractive(Input()) == DOSTRUE) interactive = TRUE; else interactive = FALSE; #else # if ((defined(__MSC__) && defined(_Windows)) || defined(__WIN32__)) && ! defined(WGP_CONSOLE) interactive = TRUE; # else interactive = isatty(fileno(stdin)); # endif #endif /* !AMIGA_SC_6_1 */ if (argc > 1) interactive = noinputfiles = FALSE; else noinputfiles = TRUE; /* Need this before show_version is called for the first time */ #ifdef HAVE_SYS_UTSNAME_H { struct utsname uts; /* something is fundamentally wrong if this fails ... */ if (uname(&uts) > -1) { # ifdef _AIX strcpy(os_name, uts.sysname); sprintf(os_name, "%s.%s", uts.version, uts.release); # elif defined(SCO) strcpy(os_name, "SCO"); strcpy(os_rel, uts.release); # elif defined(DJGPP) if (!strncmp(uts.sysname, "??Un", 4)) /* don't print ??Unknow" */ strcpy(os_name, "Unknown"); else { strcpy(os_name, uts.sysname); strcpy(os_rel, uts.release); } # else strcpy(os_name, uts.sysname); strcpy(os_rel, uts.release); # ifdef OS2 if (!strchr(os_rel,'.')) /* write either "2.40" or "4.0", or empty -- don't print "OS/2 1" */ strcpy(os_rel, ""); # endif # endif } } #else /* ! HAVE_SYS_UTSNAME_H */ strcpy(os_name, OS); strcpy(os_rel, ""); #endif /* HAVE_SYS_UTSNAME_H */ if (interactive) show_version(stderr); else show_version(NULL); /* Only load GPVAL_COMPILE_OPTIONS */ update_gpval_variables(3); /* update GPVAL_ variables available to user */ #ifdef VMS /* initialise screen management routines for command recall */ if (status[1] = smg$create_virtual_keyboard(&vms_vkid) != SS$_NORMAL) done(status[1]); if (status[1] = smg$create_key_table(&vms_ktid) != SS$_NORMAL) done(status[1]); #endif /* VMS */ if (!SETJMP(command_line_env, 1)) { /* first time */ interrupt_setup(); /* should move this stuff another initialisation routine, * something like init_set() maybe */ get_user_env(); init_loadpath(); init_locale(); /* HBB: make sure all variables start in the same mode 'reset' * would set them to. Since the axis variables aren't in * initialized arrays any more, this is now necessary... */ reset_command(); init_color(); /* Initialization of color */ load_rcfile(); init_fit(); /* Initialization of fitting module */ if (interactive && term != 0) { /* not unknown */ #ifdef GNUPLOT_HISTORY FPRINTF((stderr, "Before read_history\n")); #if defined(HAVE_LIBREADLINE) || defined(HAVE_LIBEDITLINE) expanded_history_filename = tilde_expand(GNUPLOT_HISTORY_FILE); #else expanded_history_filename = gp_strdup(GNUPLOT_HISTORY_FILE); gp_expand_tilde(&expanded_history_filename); #endif FPRINTF((stderr, "expanded_history_filename = %s\n", expanded_history_filename)); read_history(expanded_history_filename); { /* BEGIN: Go local to get environment variable */ const char *temp_env = getenv ("GNUPLOT_HISTORY_SIZE"); if (temp_env) gnuplot_history_size = strtol (temp_env, (char **) NULL, 10); } /* END: Go local to get environment variable */ /* * It is safe to ignore the return values of 'atexit()' and * 'on_exit()'. In the worst case, there is no history of your * currrent session and you have to type all again in your next * session. * This is the default behaviour (traditional reasons), too. * In case you don't have one of these functions, or you don't * want to use them, 'write_history()' is called directly. */ GP_ATEXIT(wrapper_for_write_history); #endif /* GNUPLOT_HISTORY */ fprintf(stderr, "\nTerminal type set to '%s'\n", term->name); } /* if (interactive && term != 0) */ } else { /* come back here from int_error() */ if (interactive == FALSE) exit_status = EXIT_FAILURE; #ifdef HAVE_LIBREADLINE else { /* reset properly readline after a SIGINT+longjmp */ rl_reset_after_signal (); } #endif #ifdef AMIGA_SC_6_1 (void) rawcon(0); #endif load_file_error(); /* if we were in load_file(), cleanup */ reset_eval_depth(); /* reset evaluate command recursion counter */ SET_CURSOR_ARROW; #ifdef VMS /* after catching interrupt */ /* VAX stuffs up stdout on SIGINT while writing to stdout, so reopen stdout. */ if (gpoutfile == stdout) { if ((stdout = freopen("SYS$OUTPUT", "w", stdout)) == NULL) { /* couldn't reopen it so try opening it instead */ if ((stdout = fopen("SYS$OUTPUT", "w")) == NULL) { /* don't use int_error here - causes infinite loop! */ fputs("Error opening SYS$OUTPUT as stdout\n", stderr); } } gpoutfile = stdout; } #endif /* VMS */ if (!interactive && !noinputfiles) { term_reset(); exit(EXIT_FAILURE); /* exit on non-interactive error */ } } if (argc > 1) { #ifdef _Windows TBOOLEAN noend = persist_cl; #endif /* load filenames given as arguments */ while (--argc > 0) { ++argv; c_token = NO_CARET; /* in case of file not found */ #ifdef _Windows if (stricmp(*argv, "-noend") == 0 || stricmp(*argv, "/noend") == 0 || stricmp(*argv, "-persist") == 0) noend = TRUE; else #endif if (!strncmp(*argv, "-persist", 2) || !strcmp(*argv, "--persist")) { FPRINTF((stderr,"'persist' command line option recognized\n")); } else if (strcmp(*argv, "-") == 0) { /* DBT 10-7-98 go interactive if "-" on command line */ interactive = TRUE; /* will this work on all platforms? */ while (!com_line()); interactive = FALSE; } else if (strcmp(*argv, "-e") == 0) { --argc; ++argv; if (argc <= 0) { fprintf(stderr, "syntax: gnuplot -e \"commands\"\n"); return 0; } do_string(*argv, FALSE); } else load_file(loadpath_fopen(*argv, "r"), gp_strdup(*argv), FALSE); } #ifdef _Windows if (noend) { interactive = TRUE; while (!com_line()); } #endif } else { /* take commands from stdin */ while (!com_line()); } #if (defined(HAVE_LIBREADLINE) || defined(HAVE_LIBEDITLINE)) && defined(GNUPLOT_HISTORY) #if !defined(HAVE_ATEXIT) && !defined(HAVE_ON_EXIT) /* You should be here if you neither have 'atexit()' nor 'on_exit()' */ wrapper_for_write_history(); #endif /* !HAVE_ATEXIT && !HAVE_ON_EXIT */ #endif /* (HAVE_LIBREADLINE || HAVE_LIBEDITLINE) && GNUPLOT_HISTORY */ #ifdef OS2 RexxDeregisterSubcom("GNUPLOT", NULL); #endif /* HBB 20040223: Not all compilers like exit() to end main() */ /* exit(exit_status); */ return exit_status; }
int main (int argc, char *argv[]) { char c; char plugins[100][100], s[20]; char romfile[PATH_MAX]; int old_i, i, i1, i2, i3, i4; int p, p_fullscreen = 0, p_emumode = 0, p_gfx = 0, p_audio = 0, p_input = 0, p_rsp = 0, p_help = 0, p_error = 0; int p_emumode_value=1, fileloaded = 0, p_interactive = 0; int true = 1; char *buffer, *buffer2; #if defined (__linux__) if (signal(SIGTERM, sigterm_handler) == SIG_ERR) printf("Warning: Couldn't register SIGTERM signal handler!\n"); #endif //Set working dir #ifdef WITH_HOME { char temp[PATH_MAX], orig[PATH_MAX]; FILE *src, *dest; struct dirent *entry; DIR *dir; strcpy(g_WorkingDir, getenv("HOME")); strcat(g_WorkingDir, "/.mupen64/"); strcpy(cwd, g_WorkingDir); mkdir(g_WorkingDir, 0700); strcpy(temp, g_WorkingDir); strcat(temp, "mupen64.ini"); dest = fopen(temp, "rb"); if (dest == NULL) { unsigned char byte; dest = fopen(temp, "wb"); strcpy(orig, WITH_HOME); strcat(orig, "share/mupen64/mupen64.ini"); src = fopen(orig, "rb"); while(fread(&byte, 1, 1, src)) fwrite(&byte, 1, 1, dest); fclose(src); fclose(dest); } else fclose(dest); strcpy(temp, g_WorkingDir); strcat(temp, "lang"); strcpy(orig, WITH_HOME); strcat(orig, "share/mupen64/lang"); symlink(orig, temp); /*strcpy(temp, g_WorkingDir); strcat(temp, "plugins"); strcpy(orig, WITH_HOME); strcat(orig, "share/mupen64/plugins"); symlink(orig, temp);*/ strcpy(temp, g_WorkingDir); strcat(temp, "plugins"); mkdir(temp, 0700); strcpy(orig, WITH_HOME); strcat(orig, "share/mupen64/plugins"); dir = opendir(orig); while((entry = readdir(dir)) != NULL) { if(strcmp(entry->d_name + strlen(entry->d_name) - 3, ".so")) { strcpy(orig, WITH_HOME); strcat(orig, "share/mupen64/plugins/"); strcat(orig, entry->d_name); src = fopen(orig, "rb"); if(src == NULL) continue; strcpy(temp, g_WorkingDir); strcat(temp, "plugins/"); strcat(temp, entry->d_name); dest = fopen(temp, "rb"); if(dest == NULL) { unsigned char byte; dest = fopen(temp, "wb"); while(fread(&byte, 1, 1, src)) fwrite(&byte, 1, 1, dest); fclose(src); fclose(dest); } else fclose(dest); } else { strcpy(temp, g_WorkingDir); strcat(temp, "plugins/"); strcat(temp, entry->d_name); strcpy(orig, WITH_HOME); strcat(orig, "share/mupen64/plugins/"); strcat(orig, entry->d_name); symlink(orig, temp); } } strcpy(temp, g_WorkingDir); strcat(temp, "save/"); mkdir(temp, 0700); chdir(g_WorkingDir); } #else if (argv[0][0] != '/') { getcwd(cwd, 1024); strcat(cwd, "/"); strcat(cwd, argv[0]); } else strcpy(cwd, argv[0]); while(cwd[strlen(cwd)-1] != '/') cwd[strlen(cwd)-1] = '\0'; strcpy(g_WorkingDir, cwd); #endif //read config file, read plugins config_read(); plugin_scan_directory(cwd); //get config file settings buffer = (char*)config_get_string("Gfx Plugin", ""); buffer2= plugin_name_by_filename(buffer); if(buffer2) { strcpy(plugins[100], buffer2); p_gfx = true; } else if(buffer) printf("GFX Plugin from ini-file could not be loaded\n"); buffer = (char*)config_get_string("Audio Plugin", ""); buffer2= plugin_name_by_filename(buffer); if(buffer2) { strcpy(plugins[99], buffer2); p_audio = true; } else if(buffer) printf("Audio Plugin from ini-file could not be loaded\n"); buffer = (char*)config_get_string("Input Plugin", ""); buffer2= plugin_name_by_filename(buffer); if(buffer2) { strcpy(plugins[98], buffer2); p_input = true; } else if(buffer) printf("Input Plugin from ini-file could not be loaded\n"); buffer = (char*)config_get_string("RSP Plugin", ""); buffer2= plugin_name_by_filename(buffer); if(buffer2) { strcpy(plugins[97], buffer2); p_rsp = true; } else if(buffer) printf("RSP Plugin from ini-file could not be loaded\n"); buffer = (char*)config_get_string("Core", ""); if(strcmp(buffer,"")) { p_emumode = true; p_emumode_value = buffer[0]-'0'+1; } buffer = (char*)config_get_string("Fullscreen", ""); if(strcmp(buffer,"")) { if(!strcmp(buffer, "true")) p_fullscreen = true; } buffer = (char*)config_get_string("No Ask", ""); if(strcmp(buffer,"")) { if(!strcmp(buffer, "true")) p_noask = true; } // Command Line Parameter - Parsing for(p=1; p<argc; p++) { if(argv[p][0] == '-') { if(!strcmp(argv[p], "--fullscreen")) p_fullscreen = true; else if(!strcmp(argv[p], "--help")) p_help = true; else if(!strcmp(argv[p], "--noask")) p_noask = true; else if(!strcmp(argv[p], "--interactive")) p_interactive = true; else if(!strcmp(argv[p], "--emumode")) { p++; if(p < argc) { p_emumode_value = argv[p][0]; p_emumode = true; } } else if(!strcmp(argv[p], "--gfx")) { p++; if(p < argc) { buffer = plugin_name_by_filename(argv[p]); if(buffer) { strcpy(plugins[100], buffer); p_gfx = true; } else printf("specified GFX Plugin couldn't be loaded!\n"); } } else if(!strcmp(argv[p], "--audio")) { p++; if(p < argc) { buffer = plugin_name_by_filename(argv[p]); if(buffer) { strcpy(plugins[99], buffer); p_audio = true; } else printf("specified Audio Plugin couldn't be loaded!\n"); } } else if(!strcmp(argv[p], "--input")) { p++; if(p < argc) { buffer = plugin_name_by_filename(argv[p]); if(buffer) { strcpy(plugins[98], buffer); p_input = true; } else printf("specified Input Plugin couldn't be loaded!\n"); } } else if(!strcmp(argv[p], "--rsp")) { p++; if(p < argc) { buffer = plugin_name_by_filename(argv[p]); if(buffer) { strcpy(plugins[97], buffer); p_rsp = true; } else printf("specified RSP Plugin couldn't be loaded!\n"); } } } else { strcpy(romfile, argv[p]); fileloaded = true; } } if(p_interactive) { p_emumode = 0; p_gfx = 0; p_audio = 0; p_input = 0; p_rsp = 0; } printf("\nMupen64 version : %s\n", VERSION); if (argc < 2 || p_help || p_error || fileloaded != true) { printf("\n\n" "syntax: mupen64_nogui [parameter(s)] rom\n" "\n" "Parameters:\n" " --fullscreen : turn fullscreen mode on\n" " --gfx (plugin) : set gfx plugin to (plugin)\n" " --audio (plugin) : set audio plugin to (plugin)\n" " --input (plugin) : set input plugin to (plugin)\n" " --rsp (plugin) : set rsp plugin to (plugin)\n" " --emumode (number) : set emu mode to: 1=interp./2=recomp./3=pure interp\n" " --noask : don't ask to force load on bad dumps\n" " --interactive : ask interactively for all plugins\n" "\n" "You can also use the Config-File from the Gui-Version\n" "but there are aditional Parameters for the NO-GUI Version\n" "\n"); return 0; } if (rom_read(romfile)) { if(rom) free(rom); if(ROM_HEADER) free(ROM_HEADER); return 1; } printf("Goodname:%s\n", ROM_SETTINGS.goodname); printf("16kb eeprom=%d\n", ROM_SETTINGS.eeprom_16kb); printf ("emulation mode:\n" " 1. interpreter\n" " 2. dynamic recompiler (default)\n" " 3. pure interpreter\n"); if(p_emumode) c = p_emumode_value; else c = getchar(); if (c == '1') dynacore=0; else if (c == '3') dynacore=2; else dynacore=1; SDL_Init(SDL_INIT_VIDEO); SDL_SetVideoMode(10, 10, 16, 0); SDL_ShowCursor(0); SDL_EnableKeyRepeat(0, 0); SDL_EnableUNICODE(1); init_memory(); // --------------------- loading plugins ---------------------- i=1; i1=1; printf(" Choose your gfx plugin : \n"); while(plugin_type() != -1) { if (plugin_type() == PLUGIN_TYPE_GFX) { strcpy(plugins[i], plugin_next()); printf("%s (%s)\n", plugins[i], plugin_filename_by_name(plugins[i])); i++; } else plugin_next(); } if(p_gfx) i1 = 100; else { if(p_emumode) getchar(); /*c = getchar(); s[0] = c; s[1] = 0;*/ scanf("%10s", s); i1 = atoi(s); } plugin_rewind(); old_i = i; printf(" Choose your audio plugin : \n"); while(plugin_type() != -1) { if (plugin_type() == PLUGIN_TYPE_AUDIO) { strcpy(plugins[i], plugin_next()); printf("%s (%s)\n", plugins[i], plugin_filename_by_name(plugins[i])); i++; } else plugin_next(); } /*getchar(); c = getchar(); //getchar(); s[0] = c; s[1] = 0;*/ if(p_audio) i2 = 99; else { scanf("%10s", s); i2 = old_i + atoi(s) - 1; } plugin_rewind(); old_i = i; printf(" Choose your input plugin : \n"); while(plugin_type() != -1) { if (plugin_type() == PLUGIN_TYPE_CONTROLLER) { strcpy(plugins[i], plugin_next()); printf("%s (%s)\n", plugins[i], plugin_filename_by_name(plugins[i])); i++; } else plugin_next(); } /*getchar(); c = getchar(); //getchar(); s[0] = c; s[1] = 0;*/ if(p_input) i3 = 98; else { scanf("%10s", s); i3 = old_i + atoi(s) - 1; } plugin_rewind(); old_i = i; printf(" Choose your RSP plugin : \n"); while(plugin_type() != -1) { if (plugin_type() == PLUGIN_TYPE_RSP) { strcpy(plugins[i], plugin_next()); printf("%s (%s)\n", plugins[i], plugin_filename_by_name(plugins[i])); i++; } else plugin_next(); } /*getchar(); c = getchar(); getchar(); s[0] = c; s[1] = 0;*/ if(p_rsp) i4 = 97; else { scanf("%10s", s); i4 = old_i + atoi(s) - 1; } printf("\n\nSelected Plugins: %s, %s, %s, %s\n", plugins[i1], plugins[i2], plugins[3], plugins[i4]); plugin_load_plugins(plugins[i1], plugins[i2], plugins[i3], plugins[i4]); romOpen_gfx(); romOpen_audio(); romOpen_input(); // ------------------------------------------------------------ SDL_SetEventFilter(filter); if(p_fullscreen) changeWindow(); go(); romClosed_RSP(); romClosed_input(); romClosed_audio(); romClosed_gfx(); closeDLL_RSP(); closeDLL_input(); closeDLL_audio(); closeDLL_gfx(); free(rom); free(ROM_HEADER); free_memory(); return 0; }
/*获取内存函数*/ int get_memory(pMem m_head,pMem g_head,pGet a_head,int size) { pMem m_temp = m_head; //空闲链表 pMem g_temp = g_head; //申请链表 pGet a_temp = a_head; //记录链表 pMem max = NULL; //记录最大差值的位置 pMem del=NULL; pMem will_del; // 存放将要删除的结点 pMem move_list=NULL; pMem change; //临时链表向申请链表 缓冲变量 pMem temp_list=NULL; int index=0; //记录每次申请的结点个数 init_memory(&temp_list);//初始化临时链表 while(size>0) { m_temp = m_head->next; max = m_head->next; while(m_temp!=m_head) { if(m_temp->memory_size==size) { del_memory(m_temp);//匹配则删除原来内存结点 insert_temp_memory(temp_list,m_temp); size = 0; break; } if(m_temp->memory_size > max->memory_size) { max = m_temp; //max指向需要申请的最大结点 } m_temp = m_temp->next; } if(size == 0) { break; } printf("max=%d\n",max->id); updata_memory(m_head,max,temp_list,&size); } move_list = temp_list->next; while(move_list!=temp_list) { index++; move_list = move_list->next; } insert_get_addr(a_head,temp_list,index);//更新记录链表 move_list = temp_list->next; while(move_list != temp_list) // 遍历临时链表 { move_list->pre->next = move_list->next; //从临时链表中拿下来 move_list->next->pre = move_list->pre; will_del = move_list; move_list = move_list->next; insert_memory(g_head,will_del); } move_list = temp_list->next; while(move_list!=temp_list) //释放临时链表 { will_del = move_list; move_list = move_list->next; free(will_del); } printf("申请内存成功\n"); }
main() { int index = 0; int size = 0; pMem pOwnHead;//原始内存链表 pMem pGetHead;//分配内存链表 pGet pGetaddr = NULL;//记录链表 pGet temp_addr ; init_memory(&pOwnHead);//初始化头结点 create_memory(pOwnHead,10);//创建10个结构体 init_memory(&pGetHead);//初始化分配内存链表 init_get_addr(&pGetaddr);// 初始化记录链接表 temp_addr = pGetaddr; while(index!=5) { printf("输入要进行的操作:\n"); printf(" 1--------Create\n"); printf(" 2--------Delete\n"); printf(" 3--------Display the free space\n"); printf(" '5'--------Exit\n"); scanf("%d",&index); switch(index) { case CREATE: { printf("输入要开辟的空间:\n"); scanf("%d",&size); get_memory(pOwnHead,pGetHead,pGetaddr,size); }break; case DELETE: { if(temp_addr->next!=pGetaddr) { free_memory(pOwnHead,pGetHead,temp_addr->next); temp_addr = temp_addr->next; } }break; case DISPLAY1: { printf("空闲的空间为:\n"); display_free(pOwnHead); printf("已经分配的空间为:\n"); display_free(pGetHead); }break; case '5':break; default:break; } } }