PyMODINIT_FUNC PyInit_ucl (void) { PyObject *mod = PyModule_Create (&uclmodule); init_macros (mod); return mod; }
/*** MAIN LOOP ***/ int main(int argc, char *argv[]) { #if DEBUG bmem = AvailMem( MEMF_PUBLIC ); #endif ParseArgs(&args, argc, argv); /* Look first if Jano isn't already running */ if( find_janoed( &args ) ) cleanup(0, RETURN_OK); /* Some global initialization */ init_searchtable(); /* Optionnal libraries */ AslBase = (struct Library *) OpenLibrary("asl.library", 36); LocaleBase = (struct LocaleBase *) OpenLibrary("locale.library", 38); DiskfontBase = (struct Library *) OpenLibrary("diskfont.library", 0); IFFParseBase = (struct Library *) OpenLibrary("iffparse.library",36); if(LocaleBase) InitLocale(); /* Localize the prog */ /* Open the required ROM libraries */ if( (IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library", 36)) && (GfxBase = (struct GfxBase *) OpenLibrary("graphics.library", 36)) && (GadToolsBase = (struct Library *) OpenLibrary("gadtools.library", 36)) && (KeymapBase = (struct Library *) OpenLibrary("keymap.library", 36)) && (UtilityBase = (struct UtilityBase *) OpenLibrary("utility.library", 36)) ) { init_macros(); set_default_prefs(&prefs, IntuitionBase->ActiveScreen); load_prefs(&prefs, NULL); /* See if it exists a config file */ sigport = create_port(); /* Create whether an empty project or an existing one */ if( ( edit = create_projects(NULL, args.sa_ArgLst, args.sa_NbArgs) ) ) { /* Open the main interface */ if(setup() == 0) { /* Makes edit project visible */ reshape_panel(edit); active_project(edit,TRUE); clear_brcorner(); dispatch_events(); } else cleanup(ErrMsg(ERR_NOGUI), RETURN_FAIL); } } else cleanup(ErrMsg(ERR_BADOS), RETURN_FAIL); /* Hope that all were well... */ cleanup(0, RETURN_OK); return 0; }
int main(void) { nagios_macros *mac; reset_variables(); init_environment(); init_macros(); mac = setup_macro_object(); test_escaping(mac); cleanup(); free(mac); return exit_status(); }
long PADinit(long flags) { int i,j; init_macros(); initPadtime(); for (i=0; i<MAXDEVICES; i++) { maxzero[i] = 250; minzero[i] = -250; for (j=0; j<MAXAXES; j++) { axestatus[i][j] = AXESTS_UNKNOWN; } } loadConfig(); return 0; }
int main(int argc, char *argv[]) { char *inputs[] = { "(lambda (x) (return x))", }; init_global_variable(); init_prims(); init_primitive_opcode(); init_macros(); load_init_file(); for (int i = 0; i < sizeof(inputs) / sizeof(char *); i++) { write_raw_string(">> ", standard_out); write_raw_string(inputs[i], standard_out); write_raw_char('\n', standard_out); lisp_object_t *expr = read_object_from_string(strdup(inputs[i])); expr = compile_to_bytecode(expr); if (is_signaled(expr)) writef(standard_out, "%?\n", expr); else writef(standard_out, "=> %?\n", expr); } return 0; }
/* ARGSUSED */ int main (int argc, char **argv, char **envp) { int skip_args = 0; #ifdef HAVE_PERSONALITY_LINUX32 /* See if there is a gap between the end of BSS and the heap. In that case, set personality and exec ourself again. */ if (!initialized && strcmp (argv[argc-1], "dump") == 0 && !getenv ("EMACS_HEAP_EXEC")) { /* Set this so we only do this once. */ putenv ("EMACS_HEAP_EXEC=true"); /* A flag to turn off address randomization which is introduced in linux kernel shipped with fedora core 4 */ personality (PER_LINUX32 | ADDR_NO_RANDOMIZE); execvp (argv[0], argv); /* If the exec fails, try to dump anyway. */ perror ("execvp"); } #endif /* HAVE_PERSONALITY_LINUX32 */ /* Map in shared memory, if we are using that. */ #ifdef HAVE_SHM if (argc > 1 && !strcmp (argv[1], "-nl")) { map_in_data (0); /* The shared memory was just restored, which clobbered this. */ skip_args = 1; } else { map_in_data (1); /* The shared memory was just restored, which clobbered this. */ skip_args = 0; } #endif #ifdef VMS /* If -map specified, map the data file in */ if (argc > 2 && ! strcmp (argv[1], "-map")) { skip_args = 2; mapin_data (argv[2]); } #ifdef LINK_CRTL_SHARE #ifdef SHAREABLE_LIB_BUG /* Bletcherous shared libraries! */ if (!stdin) stdin = fdopen (0, "r"); if (!stdout) stdout = fdopen (1, "w"); if (!stderr) stderr = fdopen (2, "w"); if (!environ) environ = envp; #endif /* SHAREABLE_LIB_BUG */ #endif /* LINK_CRTL_SHARE */ #endif /* VMS */ /* 92.11.4, 93.2.17 by M.Higashida */ #if defined(MSDOS) && defined(EMX) environ = envp; #endif #ifdef WIN32 environ = envp; #endif /* end of patch */ #ifdef USG_SHARED_LIBRARIES if (bss_end) brk (bss_end); #endif #ifdef NeXT extern int malloc_cookie; /* This helps out unexnext.c. */ if (initialized) { if (malloc_jumpstart (malloc_cookie) != 0) fatal("malloc jumpstart failed!\n"); } else { emacszone = NXCreateZone(ZONESIZE*vm_page_size,vm_page_size,1); if(emacszone == NX_NOZONE) fatal("can't create emacs zone.\n"); } #endif /* NeXT */ clearerr (stdin); #ifdef APOLLO #ifndef APOLLO_SR10 /* If USE_DOMAIN_ACLS environment variable exists, use ACLs rather than UNIX modes. */ if (egetenv ("USE_DOMAIN_ACLS")) default_acl (USE_DEFACL); #endif #endif /* APOLLO */ #ifndef SYSTEM_MALLOC /* Arrange for warnings when nearly out of space. */ malloc_init (0, malloc_warning); #endif /* 91.10.16 by S.Hirano */ #if defined(MSDOS) && defined(GO32) _fmode = O_BINARY; /* all of files are treated as binary files */ (stdin)->_flag &= ~_IOTEXT; /* also binary for stdio */ (stdout)->_flag &= ~_IOTEXT; (stderr)->_flag &= ~_IOTEXT; #endif /* MSDOS */ /* end of patch */ #ifdef HIGHPRI setpriority (PRIO_PROCESS, getpid (), HIGHPRI); setuid (getuid ()); #endif inhibit_window_system = 0; /* 92.3.31 by K.Handa, 92.10.21 by M.Higashida */ #if defined (HAVE_X_WINDOWS) || defined (HAVE_SUN_CONSOLE) || (defined(MSDOS) && defined(HAVE_VGA_ADAPTER)) || defined (WIN32) xargv = argv; xargc = argc; #endif /* Handle the -t switch, which specifies filename to use as terminal */ if (skip_args + 2 < argc && !strcmp (argv[skip_args + 1], "-t")) { skip_args += 2; close (0); close (1); open (argv[skip_args], O_RDWR, 2 ); dup (0); fprintf (stderr, "Using %s\n", argv[skip_args]); /* 92.3.31 by K.Handa, 92.10.21 by M.Higashida */ #if defined (HAVE_X_WINDOWS) || defined (HAVE_SUN_CONSOLE) || (defined(MSDOS) && defined(HAVE_VGA_ADAPTER)) || defined (WIN32) inhibit_window_system = 1; /* -t => -nw */ #endif } #ifdef HAVE_X_WINDOWS /* Handle the -d switch, which means use a different display for X */ if (skip_args + 2 < argc && (!strcmp (argv[skip_args + 1], "-d") || !strcmp (argv[skip_args + 1], "-display"))) { skip_args += 2; alternate_display = argv[skip_args]; } else alternate_display = 0; #endif /* HAVE_X_WINDOWS */ /* 92.3.31 by K.Handa */ #ifdef HAVE_SUN_CONSOLE if (skip_args + 1 < argc && (!strcmp (argv[skip_args + 1], "-sun"))) { extern Pixrect *screen; inhibit_window_system = -1; skip_args++; alternate_display = "/dev/fb"; if (skip_args + 2 < argc && (!strcmp (argv[skip_args + 1], "-fb"))) { skip_args += 2; alternate_display = argv[skip_args]; } if (screen = pr_open(alternate_display)) /* Just a test. */ pr_close(screen); else alternate_display = 0; } #endif /* HAVE_SUN_CONSOLE */ /* end of patch */ /* 92.10.17, 93.2.17 by M.Higashida */ #if defined(MSDOS) && defined(HAVE_VGA_ADAPTER) if (skip_args + 1 < argc && (!strcmp (argv[skip_args + 1], "-vga"))) { inhibit_window_system = -1; skip_args++; } #endif /* MSDOS and HAVE_VGA_ADAPTER */ #ifdef WIN32 inhibit_window_system = -1; #endif /* end of patch */ if (skip_args + 1 < argc && (!strcmp (argv[skip_args + 1], "-nw"))) { skip_args += 1; inhibit_window_system = 1; } /* Handle the -batch switch, which means don't do interactive display. */ noninteractive = 0; if (skip_args + 1 < argc && !strcmp (argv[skip_args + 1], "-batch")) { skip_args += 1; noninteractive = 1; } #ifdef POSIX_SIGNALS init_signals (); #endif #ifdef HAVE_TZSET /* Reinitialize the time zone if it was initialized before dumping Emacs. */ if (initialized) tzset (); #endif #ifdef WIN32 /* 93.2.25 by M.Higashida */ _tzset (); #endif if ( #ifndef CANNOT_DUMP ! noninteractive || initialized #else 1 #endif ) { /* Don't catch these signals in batch mode if not initialized. On some machines, this sets static data that would make signal fail to work right when the dumped Emacs is run. */ /* 91.10.16 by S.Hirano, 92.11.4 by M.Higashida */ #ifdef MSDOS #ifdef GO32 /* Nothing */ #else #ifdef EMX signal (SIGBREAK, fatal_error_signal); signal (SIGQUIT, fatal_error_signal); #endif #endif #else /* not MSDOS */ signal (SIGHUP, fatal_error_signal); signal (SIGQUIT, fatal_error_signal); signal (SIGILL, fatal_error_signal); signal (SIGTRAP, fatal_error_signal); signal (SIGIOT, fatal_error_signal); #ifdef SIGEMT signal (SIGEMT, fatal_error_signal); #endif signal (SIGFPE, fatal_error_signal); signal (SIGBUS, fatal_error_signal); signal (SIGSEGV, fatal_error_signal); signal (SIGSYS, fatal_error_signal); signal (SIGTERM, fatal_error_signal); #ifdef SIGXCPU signal (SIGXCPU, fatal_error_signal); #endif #ifdef SIGXFSZ signal (SIGXFSZ, fatal_error_signal); #endif #endif /* not MSDOS and GO32 */ /* end of patch */ #ifdef AIX /* This used to run fatal_error_signal, but it isn't fatal. There's nothing Emacs can usefully do. Might as well let the system kill us if it insists. */ signal (SIGDANGER, SIG_IGN); signal (20, fatal_error_signal); signal (21, fatal_error_signal); signal (22, fatal_error_signal); signal (23, fatal_error_signal); signal (24, fatal_error_signal); #ifdef SIGIO signal (SIGAIO, fatal_error_signal); signal (SIGPTY, fatal_error_signal); #endif #ifdef SIGURG /* Note that SIGIOINT is the same as SIGIO on some machines, and the same as SIGURG on others. It seems ore reliable to use the name with a uniform meaning. */ signal (SIGURG, fatal_error_signal); #endif signal (SIGGRANT, fatal_error_signal); signal (SIGRETRACT, fatal_error_signal); signal (SIGSOUND, fatal_error_signal); signal (SIGMSG, fatal_error_signal); #endif /* AIX */ } noninteractive1 = noninteractive; /* Perform basic initializations (not merely interning symbols) */ if (!initialized) { init_alloc_once (); init_obarray (); init_eval_once (); init_mc_once (); /* 89.7.26, 91.10.19 by K.Handa */ init_syntax_once (); /* Create standard syntax table. */ init_category_once (); /* 91.12.7 by K.Handa */ /* Must be done before init_buffer */ init_buffer_once (); /* Create buffer table and some buffers */ init_minibuf_once (); /* Create list of minibuffers */ /* Must precede init_window_once */ init_window_once (); /* Init the window system */ /* 92.10.28 by M.Higashida */ #if defined (MSDOS) && defined (HAVE_VGA_ADAPTER) init_bdf_once (); /* Init the BDF font structure. */ #endif /* end of patch */ } init_alloc (); #ifdef MAINTAIN_ENVIRONMENT init_environ (); /* 92.3.25 by N.Hikichi */ #ifdef HAVE_X_WINDOWS if (alternate_display) set_environment_alist (build_string ("DISPLAY"), build_string (alternate_display)); #endif /* HAVE_X_WINDOWS */ /* end of patch */ #endif init_codeconv (); /* 92.1.7 by K.Handa */ init_eval (); init_data (); init_read (); init_cmdargs (argc, argv, skip_args); /* Create list Vcommand_line_args */ init_buffer (); /* Init default directory of main buffer */ if (!noninteractive) { #ifdef VMS init_vms_input ();/* init_display calls get_screen_size, that needs this */ #endif /* VMS */ init_display (); /* Determine terminal type. init_sys_modes uses results */ } init_keyboard (); /* This too must precede init_sys_modes */ init_callproc (); /* And this too. */ init_sys_modes (); /* Init system terminal modes (RAW or CBREAK, etc.) */ init_xdisp (); init_macros (); init_editfns (); #ifdef VMS init_vmsfns (); #endif /* VMS */ #ifdef subprocesses init_process (); #endif /* subprocesses */ /* Intern the names of all standard functions and variables; define standard keys */ if (!initialized) { /* The basic levels of Lisp must come first */ /* And data must come first of all for the sake of symbols like error-message */ syms_of_data (); syms_of_alloc (); #ifdef MAINTAIN_ENVIRONMENT syms_of_environ (); #endif /* MAINTAIN_ENVIRONMENT */ syms_of_read (); syms_of_print (); syms_of_eval (); syms_of_fns (); syms_of_abbrev (); syms_of_buffer (); syms_of_bytecode (); syms_of_callint (); syms_of_casefiddle (); syms_of_callproc (); syms_of_category (); /* 91.11.11 by K.Handa */ syms_of_codeconv (); /* 92.1.7 by K.Handa */ syms_of_cmds (); #ifndef NO_DIR_LIBRARY syms_of_dired (); #endif /* not NO_DIR_LIBRARY */ syms_of_display (); syms_of_doc (); syms_of_editfns (); syms_of_emacs (); syms_of_fileio (); #ifdef CLASH_DETECTION syms_of_filelock (); #endif /* CLASH_DETECTION */ /* 92.11.1 by M.Higashida */ #ifdef FILE_TRANSLATION_MODE syms_of_transmode (); #endif /* FILE_TRANSLATION_MODE */ /* end of patch */ syms_of_indent (); syms_of_keyboard (); syms_of_keymap (); syms_of_macros (); syms_of_marker (); syms_of_minibuf (); syms_of_mocklisp (); #ifdef subprocesses syms_of_process (); #endif /* subprocesses */ syms_of_search (); syms_of_syntax (); syms_of_undo (); syms_of_window (); syms_of_xdisp (); #ifdef HAVE_X_WINDOWS syms_of_xfns (); #ifdef HAVE_X_MENU syms_of_xmenu (); #endif /* HAVE_X_MENU */ #endif /* HAVE_X_WINDOWS */ /* 87.6.8, 91.11.2, 92.3.31, 92.7.31 by K.Handa, 92.10.17, 93.2.17 by M.Higashida */ #ifdef HAVE_SUN_CONSOLE syms_of_sunterm (); #endif #if defined(MSDOS) && defined(HAVE_VGA_ADAPTER) syms_of_vgaterm (); #endif #ifdef WIN32 syms_of_win32term (); #endif syms_of_mc (); syms_of_ccl (); /* 93.5.14 by K.Handa */ #ifdef WNN4 syms_of_wnn (); #endif #ifdef CANNA syms_of_canna (); #endif /* CANNA */ /* end of patch */ #ifdef MCPATH syms_of_mcpath (); #endif /* MCPATH */ #ifdef SYMS_SYSTEM SYMS_SYSTEM; #endif #ifdef SYMS_MACHINE SYMS_MACHINE; #endif keys_of_casefiddle (); keys_of_cmds (); keys_of_buffer (); keys_of_keyboard (); keys_of_keymap (); keys_of_macros (); keys_of_minibuf (); keys_of_window (); } if (!initialized) { /* Handle -l loadup-and-dump, args passed by Makefile. */ if (argc > 2 + skip_args && !strcmp (argv[1 + skip_args], "-l")) Vtop_level = Fcons (intern ("load"), Fcons (build_string (argv[2 + skip_args]), Qnil)); #ifdef CANNOT_DUMP /* Unless next switch is -nl, load "loadup.el" first thing. */ if (!(argc > 1 + skip_args && !strcmp (argv[1 + skip_args], "-nl"))) Vtop_level = Fcons (intern ("load"), Fcons (build_string ("loadup.el"), Qnil)); #endif /* CANNOT_DUMP */ } initialized = 1; /* Enter editor command loop. This never returns. */ Frecursive_edit (); /* NOTREACHED */ }
/** * Initialises the CQP program (or cqpserver or cqpcl). * * This function: * - initialises the global variables; * - initialises the built-in random number generator; * - initialises the macro database; * - parses the program options; * - reads the initialisation file; * - reads the macro initialisation file; * - and loads the default corpus, if any. * * @param argc The argc from main() * @param argv The argv from main() * @return Always 1. */ int initialize_cqp(int argc, char **argv) { char *home = NULL; char *homedrive = NULL; char *homepath = NULL; char init_file_fullname[CL_MAX_FILENAME_LENGTH]; /* file handle for initialisation files, if any */ FILE *cqprc; extern int yydebug; /* initialize global variables */ exit_cqp = 0; cqp_file_p = 0; corpuslist = NULL; eep = -1; /* intialise built-in random number generator */ cl_randomize(); /* initialise macro database */ init_macros(); /* parse program options */ parse_options(argc, argv); /* let's always run stdout unbuffered */ /* if (batchmode || rangeoutput || insecure || !isatty(fileno(stdout))) */ if (setvbuf(stdout, NULL, _IONBF, 0) != 0) perror("unbuffer stdout"); yydebug = parser_debug; /* before we start looking for files, let's get the home directory, if we can, * so we don't have to detect it in more than one place. */ #ifndef __MINGW__ home = (char *)getenv("HOME"); #else /* under Windows it is %HOMEDRIVE%%HOMEPATH% */ if ((homepath = (char *)getenv("HOMEPATH")) != NULL && (homedrive = (char *)getenv("HOMEDRIVE")) != NULL ) { home = (char *)cl_malloc(256); sprintf(home, "%s%s", homedrive, homepath); } #endif /* note that either way above, home is NULL if the needed env var(s) were not found. */ /* read initialization file if specified via -I, or if we are in interactive mode */ if (cqp_init_file || (!child_process && (!batchmode || batchfd == NULL) && which_app != cqpserver) ) { /* * Read init file specified with -I <file> * if no init file was specified, and we're not in batchmode, child mode, or cqpserver, * looks for ~/.cqprc * Same with macro init file (-M <file> or ~/.cqpmacros), but ONLY if macros are enabled. */ /* * allow interactive commands during processing of initialization file ??? * (I don't think this is the case!!) */ init_file_fullname[0] = '\0'; /* read init file specified with -I , otherwise look for $HOME/.cqprc */ if (cqp_init_file) sprintf(init_file_fullname, "%s", cqp_init_file); else if (home) sprintf(init_file_fullname, "%s%c%s", home, SUBDIR_SEPARATOR, CQPRC_NAME); if (init_file_fullname[0] != '\0') { if ((cqprc = fopen(init_file_fullname, "r")) != NULL) { reading_cqprc = 1; /* not good for very much, really */ if (!cqp_parse_file(cqprc, 1)) { fprintf(stderr, "Parse errors while reading %s, exiting.\n", init_file_fullname); exit(1); } reading_cqprc = 0; /* fclose(cqprc); was already closed by cqp_parse_file!! */ } else if (cqp_init_file) { fprintf(stderr, "Can't read initialization file %s\n", init_file_fullname); exit(1); } } } if (!enable_macros && macro_init_file) cqpmessage(Warning, "Macros not enabled. Ignoring macro init file %s.", macro_init_file); if (enable_macros && (macro_init_file || (!child_process && (!batchmode || (batchfd == NULL)) && !(which_app == cqpserver)) ) ) { init_file_fullname[0] = '\0'; /* read macro init file specified with -M , otherwise look for ~/.cqpmacros */ if (macro_init_file) sprintf(init_file_fullname, "%s", macro_init_file); else if (home) sprintf(init_file_fullname, "%s%c%s", home, SUBDIR_SEPARATOR, CQPMACRORC_NAME); if (init_file_fullname[0] != '\0') { if ((cqprc = fopen(init_file_fullname, "r")) != NULL) { reading_cqprc = 1; /* not good for very much, really */ if (!cqp_parse_file(cqprc, 1)) { fprintf(stderr, "Parse errors while reading %s, exiting.\n", init_file_fullname); exit(1); } reading_cqprc = 0; /* fclose(cqprc); was already closed by cqp_parse_file!! */ } else if (macro_init_file) { fprintf(stderr, "Can't read macro initialization file %s\n", init_file_fullname); exit(1); } } } /* ends if (!child_process || (batchmode ... ) ... ) */ check_available_corpora(UNDEF); /* load the default corpus. */ if ((default_corpus) && !set_current_corpus_name(default_corpus, 0)) { fprintf(stderr, "Can't set current corpus to default corpus %s, exiting.\n", default_corpus); exit(1); } #ifndef __MINGW__ if (signal(SIGPIPE, SIG_IGN) == SIG_IGN) { /* fprintf(stderr, "Couldn't install SIG_IGN for SIGPIPE signal\n"); */ /* -- be silent about not being able to ignore the SIGPIPE signal, which often happens in slave mode */ /* note that SIGPIPE does not seem to exist in signal.h under MinGW */ signal(SIGPIPE, SIG_DFL); } #endif #ifdef __MINGW__ /* due to how the home path was calculated, home contains a malloc'ed string */ cl_free(home); #endif return 1; }
int main(int argc, char *argv[]) { int c; int n; char *p; if (signal(SIGINT, SIG_IGN) != SIG_IGN) signal(SIGINT, onintr); init_macros(); initspaces(); STACKMAX = INITSTACKMAX; mstack = xreallocarray(NULL, STACKMAX, sizeof(stae), NULL); sstack = xalloc(STACKMAX, NULL); maxout = 0; outfile = NULL; resizedivs(MAXOUT); while ((c = getopt(argc, argv, "gst:d:D:U:o:I:P")) != -1) switch(c) { case 'D': /* define something..*/ for (p = optarg; *p; p++) if (*p == '=') break; if (*p) *p++ = EOS; dodefine(optarg, p); break; case 'I': addtoincludepath(optarg); break; case 'P': prefix_builtins = 1; break; case 'U': /* undefine... */ macro_popdef(optarg); break; case 'g': mimic_gnu = 1; break; case 'd': set_trace_flags(optarg); break; case 's': synch_lines = 1; break; case 't': mark_traced(optarg, 1); break; case 'o': trace_file(optarg); break; case '?': usage(); } argc -= optind; argv += optind; initkwds(); if (mimic_gnu) setup_builtin("format", FORMATTYPE); active = stdout; /* default active output */ bbase[0] = bufbase; if (!argc) { sp = -1; /* stack pointer initialized */ fp = 0; /* frame pointer initialized */ set_input(infile+0, stdin, "stdin"); /* default input (naturally) */ macro(); } else for (; argc--; ++argv) { p = *argv; if (p[0] == '-' && p[1] == EOS) set_input(infile, stdin, "stdin"); else if (fopen_trypath(infile, p) == NULL) err(1, "%s", p); sp = -1; fp = 0; macro(); release_input(infile); } if (wrapindex) { int i; ilevel = 0; /* in case m4wrap includes.. */ bufbase = bp = buf; /* use the entire buffer */ if (mimic_gnu) { while (wrapindex != 0) { for (i = 0; i < wrapindex; i++) pbstr(m4wraps[i]); wrapindex =0; macro(); } } else { for (i = 0; i < wrapindex; i++) { pbstr(m4wraps[i]); macro(); } } } if (active != stdout) active = stdout; /* reset output just in case */ for (n = 1; n < maxout; n++) /* default wrap-up: undivert */ if (outfile[n] != NULL) getdiv(n); /* remove bitbucket if used */ if (outfile[0] != NULL) { (void) fclose(outfile[0]); } return exit_code; }
/* reset all system-wide variables, so when we've receive a SIGHUP we can restart cleanly */ int reset_variables(void) { log_file = nm_strdup(get_default_log_file()); temp_file = nm_strdup(get_default_temp_file()); temp_path = nm_strdup(get_default_temp_path()); check_result_path = nm_strdup(get_default_check_result_path()); command_file = nm_strdup(get_default_command_file()); qh_socket_path = nm_strdup(get_default_query_socket()); if (lock_file) /* this is kept across restarts */ free(lock_file); lock_file = nm_strdup(get_default_lock_file()); log_archive_path = nm_strdup(get_default_log_archive_path()); debug_file = nm_strdup(get_default_debug_file()); object_cache_file = nm_strdup(get_default_object_cache_file()); object_precache_file = nm_strdup(get_default_precached_object_file()); use_regexp_matches = FALSE; use_true_regexp_matching = FALSE; use_syslog = DEFAULT_USE_SYSLOG; log_service_retries = DEFAULT_LOG_SERVICE_RETRIES; log_host_retries = DEFAULT_LOG_HOST_RETRIES; log_initial_states = DEFAULT_LOG_INITIAL_STATES; enable_notification_suppression_reason_logging = DEFAULT_NSR_LOGGING; log_notifications = DEFAULT_NOTIFICATION_LOGGING; log_event_handlers = DEFAULT_LOG_EVENT_HANDLERS; log_external_commands = DEFAULT_LOG_EXTERNAL_COMMANDS; log_passive_checks = DEFAULT_LOG_PASSIVE_CHECKS; logging_options = NSLOG_RUNTIME_ERROR | NSLOG_RUNTIME_WARNING | NSLOG_VERIFICATION_ERROR | NSLOG_VERIFICATION_WARNING | NSLOG_CONFIG_ERROR | NSLOG_CONFIG_WARNING | NSLOG_PROCESS_INFO | NSLOG_HOST_NOTIFICATION | NSLOG_SERVICE_NOTIFICATION | NSLOG_EVENT_HANDLER | NSLOG_EXTERNAL_COMMAND | NSLOG_PASSIVE_CHECK | NSLOG_HOST_UP | NSLOG_HOST_DOWN | NSLOG_HOST_UNREACHABLE | NSLOG_SERVICE_OK | NSLOG_SERVICE_WARNING | NSLOG_SERVICE_UNKNOWN | NSLOG_SERVICE_CRITICAL | NSLOG_INFO_MESSAGE; syslog_options = NSLOG_RUNTIME_ERROR | NSLOG_RUNTIME_WARNING | NSLOG_VERIFICATION_ERROR | NSLOG_VERIFICATION_WARNING | NSLOG_CONFIG_ERROR | NSLOG_CONFIG_WARNING | NSLOG_PROCESS_INFO | NSLOG_HOST_NOTIFICATION | NSLOG_SERVICE_NOTIFICATION | NSLOG_EVENT_HANDLER | NSLOG_EXTERNAL_COMMAND | NSLOG_PASSIVE_CHECK | NSLOG_HOST_UP | NSLOG_HOST_DOWN | NSLOG_HOST_UNREACHABLE | NSLOG_SERVICE_OK | NSLOG_SERVICE_WARNING | NSLOG_SERVICE_UNKNOWN | NSLOG_SERVICE_CRITICAL | NSLOG_INFO_MESSAGE; service_check_timeout = DEFAULT_SERVICE_CHECK_TIMEOUT; host_check_timeout = DEFAULT_HOST_CHECK_TIMEOUT; event_handler_timeout = DEFAULT_EVENT_HANDLER_TIMEOUT; notification_timeout = DEFAULT_NOTIFICATION_TIMEOUT; ocsp_timeout = DEFAULT_OCSP_TIMEOUT; ochp_timeout = DEFAULT_OCHP_TIMEOUT; interval_length = DEFAULT_INTERVAL_LENGTH; use_aggressive_host_checking = DEFAULT_AGGRESSIVE_HOST_CHECKING; cached_host_check_horizon = DEFAULT_CACHED_HOST_CHECK_HORIZON; cached_service_check_horizon = DEFAULT_CACHED_SERVICE_CHECK_HORIZON; enable_predictive_host_dependency_checks = DEFAULT_ENABLE_PREDICTIVE_HOST_DEPENDENCY_CHECKS; enable_predictive_service_dependency_checks = DEFAULT_ENABLE_PREDICTIVE_SERVICE_DEPENDENCY_CHECKS; soft_state_dependencies = FALSE; retain_state_information = FALSE; retention_update_interval = DEFAULT_RETENTION_UPDATE_INTERVAL; use_retained_program_state = TRUE; use_retained_scheduling_info = FALSE; retention_scheduling_horizon = DEFAULT_RETENTION_SCHEDULING_HORIZON; modified_host_process_attributes = MODATTR_NONE; modified_service_process_attributes = MODATTR_NONE; retained_host_attribute_mask = 0L; retained_service_attribute_mask = 0L; retained_process_host_attribute_mask = 0L; retained_process_service_attribute_mask = 0L; retained_contact_host_attribute_mask = 0L; retained_contact_service_attribute_mask = 0L; check_reaper_interval = DEFAULT_CHECK_REAPER_INTERVAL; max_check_reaper_time = DEFAULT_MAX_REAPER_TIME; max_check_result_file_age = DEFAULT_MAX_CHECK_RESULT_AGE; service_freshness_check_interval = DEFAULT_FRESHNESS_CHECK_INTERVAL; host_freshness_check_interval = DEFAULT_FRESHNESS_CHECK_INTERVAL; check_external_commands = DEFAULT_CHECK_EXTERNAL_COMMANDS; check_orphaned_services = DEFAULT_CHECK_ORPHANED_SERVICES; check_orphaned_hosts = DEFAULT_CHECK_ORPHANED_HOSTS; check_service_freshness = DEFAULT_CHECK_SERVICE_FRESHNESS; check_host_freshness = DEFAULT_CHECK_HOST_FRESHNESS; log_rotation_method = LOG_ROTATION_NONE; last_log_rotation = 0L; max_parallel_service_checks = DEFAULT_MAX_PARALLEL_SERVICE_CHECKS; currently_running_service_checks = 0; enable_notifications = TRUE; execute_service_checks = TRUE; accept_passive_service_checks = TRUE; execute_host_checks = TRUE; accept_passive_service_checks = TRUE; enable_event_handlers = TRUE; obsess_over_services = FALSE; obsess_over_hosts = FALSE; next_comment_id = 0L; /* comment and downtime id get initialized to nonzero elsewhere */ next_downtime_id = 0L; next_event_id = 1; next_notification_id = 1; status_update_interval = DEFAULT_STATUS_UPDATE_INTERVAL; event_broker_options = BROKER_NOTHING; time_change_threshold = DEFAULT_TIME_CHANGE_THRESHOLD; enable_flap_detection = DEFAULT_ENABLE_FLAP_DETECTION; low_service_flap_threshold = DEFAULT_LOW_SERVICE_FLAP_THRESHOLD; high_service_flap_threshold = DEFAULT_HIGH_SERVICE_FLAP_THRESHOLD; low_host_flap_threshold = DEFAULT_LOW_HOST_FLAP_THRESHOLD; high_host_flap_threshold = DEFAULT_HIGH_HOST_FLAP_THRESHOLD; process_performance_data = DEFAULT_PROCESS_PERFORMANCE_DATA; translate_passive_host_checks = DEFAULT_TRANSLATE_PASSIVE_HOST_CHECKS; passive_host_checks_are_soft = DEFAULT_PASSIVE_HOST_CHECKS_SOFT; additional_freshness_latency = DEFAULT_ADDITIONAL_FRESHNESS_LATENCY; debug_level = DEFAULT_DEBUG_LEVEL; debug_verbosity = DEFAULT_DEBUG_VERBOSITY; max_debug_file_size = DEFAULT_MAX_DEBUG_FILE_SIZE; date_format = DATE_FORMAT_US; /* initialize macros */ init_macros(); global_host_event_handler = NULL; global_service_event_handler = NULL; global_host_event_handler_ptr = NULL; global_service_event_handler_ptr = NULL; ocsp_command = NULL; ochp_command = NULL; ocsp_command_ptr = NULL; ochp_command_ptr = NULL; /* reset umask */ umask(S_IWGRP | S_IWOTH); return OK; }
void initucl (void) { PyObject *mod = Py_InitModule ("ucl", uclMethods); init_macros (mod); }
int cmdline_main (int argc, char *argv[]) { guchar *output; int num_frames = 1; #ifdef MOVIES int generate_movie = 0; quicktime_t *output_movie; guchar **rows; #endif int antialiasing = 0, supersampling = 0; int img_width, img_height; char *generator = 0; userval_info_t *userval_info; int num_input_drawables = 0; gboolean size_is_set = FALSE; char *script = NULL; char *output_filename; gboolean htmldoc = FALSE; define_t *defines = NULL; int bench_render_count = 1; int render_num; gboolean bench_no_output = FALSE; gboolean bench_no_backend = FALSE; int compile_time_limit = DEFAULT_OPTIMIZATION_TIMEOUT; for (;;) { static struct option long_options[] = { { "version", no_argument, 0, OPTION_VERSION }, { "help", no_argument, 0, OPTION_HELP }, { "intersampling", no_argument, 0, 'i' }, { "oversampling", no_argument, 0, 'o' }, { "cache", required_argument, 0, 'c' }, { "generator", required_argument, 0, 'g' }, { "size", required_argument, 0, 's' }, { "script-file", required_argument, 0, 'f' }, { "htmldoc", no_argument, 0, OPTION_HTMLDOC }, { "bench-no-output", no_argument, 0, OPTION_BENCH_NO_OUTPUT }, { "bench-only-compile", no_argument, 0, OPTION_BENCH_ONLY_COMPILE }, { "bench-no-compile-time-limit", no_argument, 0, OPTION_BENCH_NO_COMPILE_TIME_LIMIT }, { "bench-no-backend", no_argument, 0, OPTION_BENCH_NO_BACKEND }, { "bench-render-count", required_argument, 0, OPTION_BENCH_RENDER_COUNT }, #ifdef MOVIES { "frames", required_argument, 0, 'F' }, { "movie", required_argument, 0, 'M' }, #endif { 0, 0, 0, 0 } }; int option, option_index; option = getopt_long(argc, argv, #ifdef MOVIES "f:ioF:D:M:c:g:s:", #else "f:ioD:c:g:s:", #endif long_options, &option_index); if (option == -1) break; switch (option) { case OPTION_VERSION : printf("MathMap " MATHMAP_VERSION "\n" "\n" "Copyright (C) 1997-2009 Mark Probst\n" "\n" "This program is free software; you can redistribute it and/or modify\n" "it under the terms of the GNU General Public License as published by\n" "the Free Software Foundation; either version 2 of the License, or\n" "(at your option) any later version.\n" "\n" "This program is distributed in the hope that it will be useful,\n" "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" "GNU General Public License for more details.\n" "\n" "You should have received a copy of the GNU General Public License\n" "along with this program; if not, write to the Free Software\n" "Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n"); return 0; case OPTION_HELP : usage(); return 0; case OPTION_HTMLDOC : htmldoc = TRUE; break; case 'f' : if (!g_file_get_contents(optarg, &script, NULL, NULL)) { fprintf(stderr, _("Error: The script file `%s' could not be read.\n"), optarg); return 1; } break; case 'i' : antialiasing = 1; break; case 'o' : supersampling = 1; break; case 'c' : cache_size = atoi(optarg); assert(cache_size > 0); break; case 'D' : append_define(optarg, &defines); break; case 'I' : alloc_cmdline_image_input_drawable(optarg); break; case 'g' : generator = optarg; break; case 's' : if (!parse_image_size(optarg, &img_width, &img_height)) { fprintf(stderr, _("Error: Invalid image size. Syntax is <width>x<height>. Example: 1024x768.\n")); exit(1); } size_is_set = 1; break; case OPTION_BENCH_RENDER_COUNT : bench_render_count = atoi(optarg); break; case OPTION_BENCH_ONLY_COMPILE : bench_render_count = 0; break; case OPTION_BENCH_NO_OUTPUT : bench_no_output = TRUE; break; case OPTION_BENCH_NO_COMPILE_TIME_LIMIT : compile_time_limit = -1; break; case OPTION_BENCH_NO_BACKEND : bench_no_backend = TRUE; break; #ifdef MOVIES case 'F' : generate_movie = 1; num_frames = atoi(optarg); assert(num_frames > 0); break; case 'M' : alloc_cmdline_movie_input_drawable(optarg); break; #endif } } if (script != NULL) { if (argc - optind != 1) { usage(); return 1; } output_filename = argv[optind]; } else { if (argc - optind != 2) { usage(); return 1; } script = argv[optind]; output_filename = argv[optind + 1]; } init_tags(); init_builtins(); init_macros(); init_compiler(); if (htmldoc) { mathmap_t *mathmap = parse_mathmap(script); filter_t *filter; FILE *out; if (mathmap == NULL) { fprintf(stderr, _("Error: Could not read MathMap script: %s\n"), error_string); return 1; } out = fopen(output_filename, "w"); if (out == NULL) { fprintf(stderr, _("Error: Cannot open file `%s' for writing: %s\n"), output_filename, strerror(errno)); return 1; } for (filter = mathmap->filters; filter != NULL; filter = filter->next) { if (filter->kind != FILTER_MATHMAP) continue; if (!write_filter_html_doc(out, filter->v.mathmap.decl)) return 1; } fclose(out); } else if (generator == 0) { char *support_paths[4]; mathmap_t *mathmap; mathmap_invocation_t *invocation; int current_frame; support_paths[0] = g_strdup_printf("%s/mathmap", GIMPDATADIR); support_paths[1] = g_strdup_printf("%s/.gimp-2.6/mathmap", getenv("HOME")); support_paths[2] = g_strdup_printf("%s/.gimp-2.4/mathmap", getenv("HOME")); support_paths[3] = NULL; mathmap = compile_mathmap(script, support_paths, compile_time_limit, bench_no_backend); if (bench_no_backend) return 0; if (mathmap == 0) { fprintf(stderr, _("Error: %s\n"), error_string); exit(1); } if (bench_render_count == 0) return 0; if (!size_is_set) for (userval_info = mathmap->main_filter->userval_infos; userval_info != NULL; userval_info = userval_info->next) { define_t *define; unsigned char *image; if (userval_info->type != USERVAL_IMAGE) continue; define = lookup_define(defines, userval_info->name); if (define == NULL) { fprintf(stderr, _("Error: No value defined for input image `%s'.\n"), userval_info->name); return 1; } image = read_image(define->value, &img_width, &img_height); if (image == NULL) { fprintf(stderr, _("Error: Could not read input image `%s'.\n"), define->value); return 1; } free(image); size_is_set = TRUE; break; } if (!size_is_set) { fprintf(stderr, _("Error: Image size not set and no input images given.\n")); exit(1); } invocation = invoke_mathmap(mathmap, NULL, img_width, img_height, TRUE); for (userval_info = mathmap->main_filter->userval_infos; userval_info != NULL; userval_info = userval_info->next) { userval_t *userval = &invocation->uservals[userval_info->index]; define_t *define = lookup_define(defines, userval_info->name); if (define == NULL) { if (userval_info->type == USERVAL_IMAGE) { fprintf(stderr, _("Error: No value defined for input image `%s'.\n"), userval_info->name); return 1; } } else switch (userval_info->type) { case USERVAL_INT_CONST : userval->v.int_const = atoi(define->value); break; case USERVAL_FLOAT_CONST : userval->v.float_const = g_ascii_strtod(define->value, NULL); break; case USERVAL_BOOL_CONST : userval->v.bool_const = (float)atoi(define->value); break; case USERVAL_IMAGE : assign_image_userval_drawable(userval_info, userval, alloc_cmdline_image_input_drawable(define->value)); ++num_input_drawables; break; default : fprintf(stderr, _("Error: Can only define user values for types int, float, bool and image.\n")); return 1; } } for (render_num = 0; render_num < bench_render_count; ++render_num) { #ifdef MOVIES for (i = 0; i < num_input_drawables; ++i) if (input_drawables[i].type == DRAWABLE_MOVIE) { assert(quicktime_video_width(input_drawables[i].v.movie, 0) == img_width); assert(quicktime_video_height(input_drawables[i].v.movie, 0) == img_height); } #endif invocation_set_antialiasing(invocation, antialiasing); invocation->supersampling = supersampling; invocation->output_bpp = 4; output = (guchar*)malloc((long)invocation->output_bpp * (long)img_width * (long)img_height); assert(output != 0); #ifdef MOVIES if (generate_movie) { output_movie = quicktime_open(output_filename, 0, 1); assert(output_movie != 0); quicktime_set_video(output_movie, 1, img_width, img_height, 25, QUICKTIME_JPEG); assert(quicktime_supported_video(output_movie, 0)); quicktime_seek_start(output_movie); rows = (guchar**)malloc(sizeof(guchar*) * img_height); for (i = 0; i < img_height; ++i) rows[i] = output + img_width * invocation->output_bpp * i; } #endif for (current_frame = 0; current_frame < num_frames; ++current_frame) { float current_t = (float)current_frame / (float)num_frames; image_t *closure = closure_image_alloc(&invocation->mathfuncs, NULL, invocation->mathmap->main_filter->num_uservals, invocation->uservals, img_width, img_height); mathmap_frame_t *frame = invocation_new_frame(invocation, closure, current_frame, current_t); call_invocation_parallel_and_join(frame, closure, 0, 0, img_width, img_height, output, 1); invocation_free_frame(frame); #ifdef MOVIES if (generate_movie && !bench_no_output) { fprintf(stderr, _("writing frame %d\n"), current_frame); assert(quicktime_encode_video(output_movie, rows, 0) == 0); } #endif closure_image_free(closure); } if (!bench_no_output) { #ifdef MOVIES if (generate_movie) quicktime_close(output_movie); else #endif write_image(output_filename, img_width, img_height, output, invocation->output_bpp, img_width * invocation->output_bpp, IMAGE_FORMAT_PNG); } free(output); } } else { if (strcmp(generator, "blender") == 0) { if (!blender_generate_plug_in(script, output_filename)) return 1; } /* else if (strcmp(generator, "pixeltree") == 0) { if (!pixeltree_generate_plug_in(argv[optind], argv[optind + 1])) return 1; } */ else { fprintf(stderr, _("Unknown generator `%s'\n"), generator); return 1; } } return 0; }