e576bb2002-10-11Martin Nilsson /* || This file is part of Pike. For copyright information see COPYRIGHT. || Pike is distributed under GPL, LGPL and MPL. See the file COPYING || for more information. */
aedfb12002-10-09Martin Nilsson 
5267b71995-08-09Fredrik Hübinette (Hubbe) #include "global.h"
5740881998-01-01Fredrik Hübinette (Hubbe) #include "fdlib.h"
5267b71995-08-09Fredrik Hübinette (Hubbe) #include "backend.h" #include "module.h" #include "object.h" #include "lex.h"
06983f1996-09-22Fredrik Hübinette (Hubbe) #include "pike_types.h" #include "builtin_functions.h"
5267b71995-08-09Fredrik Hübinette (Hubbe) #include "array.h" #include "stralloc.h" #include "interpret.h"
b2d3e42000-12-01Fredrik Hübinette (Hubbe) #include "pike_error.h"
bb55f81997-03-16Fredrik Hübinette (Hubbe) #include "pike_macros.h"
5267b71995-08-09Fredrik Hübinette (Hubbe) #include "callback.h"
06983f1996-09-22Fredrik Hübinette (Hubbe) #include "signal_handler.h"
07513e1996-10-04Fredrik Hübinette (Hubbe) #include "threads.h"
9c6f7d1997-04-15Fredrik Hübinette (Hubbe) #include "dynamic_load.h" #include "gc.h"
61e9a01998-01-25Fredrik Hübinette (Hubbe) #include "multiset.h"
9c6f7d1997-04-15Fredrik Hübinette (Hubbe) #include "mapping.h"
5740881998-01-01Fredrik Hübinette (Hubbe) #include "cpp.h"
0808b21998-01-25Fredrik Hübinette (Hubbe) #include "main.h"
19aaeb1998-05-25Fredrik Hübinette (Hubbe) #include "operators.h"
ab56702001-04-30Martin Stjernholm #include "rbtree.h"
37775c2004-04-06Martin Nilsson #include "pike_security.h"
67f0b51999-09-26Henrik Grubbström (Grubba) #include "constants.h"
c37c7e1999-03-26Fredrik Hübinette (Hubbe) #include "version.h"
4b63c62001-12-14Martin Nilsson #include "program.h"
d5c61f2002-12-07Henrik Grubbström (Grubba) #include "pike_rusage.h"
d658ab2002-09-26Martin Stjernholm #include "module_support.h"
143d882003-11-14Martin Stjernholm #include "opcodes.h"
4b63c62001-12-14Martin Nilsson #include "bignum.h"
5740881998-01-01Fredrik Hübinette (Hubbe) 
ec337d2004-12-29Henrik Grubbström (Grubba) #include "pike_embed.h"
2064c02010-06-17Henrik Grubbström (Grubba) #ifdef LIBPIKE #if defined(HAVE_DLOPEN) && defined(HAVE_DLFCN_H)
07eda22000-07-05Fredrik Hübinette (Hubbe) #include <dlfcn.h>
2064c02010-06-17Henrik Grubbström (Grubba) #undef LIBPIKE #endif
07eda22000-07-05Fredrik Hübinette (Hubbe) #endif
cee5811999-12-05Henrik Grubbström (Grubba) #include "las.h"
834e022003-11-28Henrik Grubbström (Grubba) #ifdef HAVE_UNISTD_H
fde6ed2003-11-27Martin Stjernholm #include <unistd.h>
834e022003-11-28Henrik Grubbström (Grubba) #endif #ifdef HAVE_ERRNO_H
ac173e1997-11-02Henrik Grubbström (Grubba) #include <errno.h>
834e022003-11-28Henrik Grubbström (Grubba) #endif
ac173e1997-11-02Henrik Grubbström (Grubba) 
5267b71995-08-09Fredrik Hübinette (Hubbe) #ifdef HAVE_LOCALE_H #include <locale.h> #endif
6930181996-02-25Fredrik Hübinette (Hubbe) 
6e37dc1996-06-21Fredrik Hübinette (Hubbe) #include "time_stuff.h"
6930181996-02-25Fredrik Hübinette (Hubbe) 
5267b71995-08-09Fredrik Hübinette (Hubbe) #ifdef HAVE_SYS_RESOURCE_H #include <sys/resource.h> #endif
ff34a52001-05-31Henrik Grubbström (Grubba) /* Define this to trace the execution of main(). */ /* #define TRACE_MAIN */
b0f01d2007-05-18Henrik Grubbström (Grubba) #ifdef PIKE_EXTRA_DEBUG #define TRACE_MAIN #endif /* PIKE_EXTRA_DEBUG */
ff34a52001-05-31Henrik Grubbström (Grubba) #ifdef TRACE_MAIN #define TRACE(X) fprintf X #else /* !TRACE_MAIN */ #define TRACE(X) #endif /* TRACE_MAIN */
f8e5fe1997-01-18Henrik Grubbström (Grubba) 
df458c2004-12-30Henrik Grubbström (Grubba) /* * Code searching for master & libpike. */
3f1eeb1998-04-05Fredrik Hübinette (Hubbe) 
df458c2004-12-30Henrik Grubbström (Grubba) #define MASTER_COOKIE1 "(#*&)@(*&$" #define MASTER_COOKIE2 "Master Cookie:"
5267b71995-08-09Fredrik Hübinette (Hubbe) 
df458c2004-12-30Henrik Grubbström (Grubba) #define MASTER_COOKIE MASTER_COOKIE1 MASTER_COOKIE2
5267b71995-08-09Fredrik Hübinette (Hubbe) 
df458c2004-12-30Henrik Grubbström (Grubba) #ifndef MAXPATHLEN #define MAXPATHLEN 32768 #endif static char master_location[MAXPATHLEN * 2] = MASTER_COOKIE; static void set_master(const char *file)
5267b71995-08-09Fredrik Hübinette (Hubbe) {
df458c2004-12-30Henrik Grubbström (Grubba)  if (strlen(file) >= MAXPATHLEN*2 - CONSTANT_STRLEN(MASTER_COOKIE)) {
4e5f742005-05-20Martin Stjernholm  fprintf(stderr, "Too long path to master: \"%s\" (limit:%"PRINTPTRDIFFT"d)\n",
df458c2004-12-30Henrik Grubbström (Grubba)  file, MAXPATHLEN*2 - CONSTANT_STRLEN(MASTER_COOKIE)); exit(1); } strcpy(master_location + CONSTANT_STRLEN(MASTER_COOKIE), file);
5267b71995-08-09Fredrik Hübinette (Hubbe) }
a999e71998-07-27Fredrik Hübinette (Hubbe) #ifdef __NT__
1c32fd2000-08-19Henrik Grubbström (Grubba) static void get_master_key(HKEY cat)
a999e71998-07-27Fredrik Hübinette (Hubbe) { HKEY k; char buffer[4096]; DWORD len=sizeof(buffer)-1,type=REG_SZ;
a5cd6a2001-09-24Henrik Grubbström (Grubba) 
a999e71998-07-27Fredrik Hübinette (Hubbe)  if(RegOpenKeyEx(cat,
387b042003-01-02Martin Nilsson  (LPCTSTR)("SOFTWARE\\Pike\\"
1f1f182001-03-10Henrik Grubbström (Grubba)  DEFINETOSTR(PIKE_MAJOR_VERSION) "."
a999e71998-07-27Fredrik Hübinette (Hubbe)  0,KEY_READ,&k)==ERROR_SUCCESS) { if(RegQueryValueEx(k, "PIKE_MASTER", 0, &type, buffer, &len)==ERROR_SUCCESS) {
df458c2004-12-30Henrik Grubbström (Grubba)  /* FIXME: Look at len? UNICODE? */ set_master(buffer);
a999e71998-07-27Fredrik Hübinette (Hubbe)  } RegCloseKey(k); } } #endif /* __NT__ */
1176e82009-09-18Henrik Grubbström (Grubba) static void set_default_master(const char *bin_name)
df458c2004-12-30Henrik Grubbström (Grubba) {
200ba82008-06-29Martin Stjernholm  char *mp = master_location + CONSTANT_STRLEN (MASTER_COOKIE);
df458c2004-12-30Henrik Grubbström (Grubba) #ifdef HAVE_GETENV
200ba82008-06-29Martin Stjernholm  if(!*mp && getenv("PIKE_MASTER")) {
df458c2004-12-30Henrik Grubbström (Grubba)  set_master(getenv("PIKE_MASTER")); } #endif #ifdef __NT__
200ba82008-06-29Martin Stjernholm  if(!*mp) get_master_key(HKEY_CURRENT_USER); if(!*mp) get_master_key(HKEY_LOCAL_MACHINE);
df458c2004-12-30Henrik Grubbström (Grubba) #endif
1176e82009-09-18Henrik Grubbström (Grubba)  if(!*mp && strncmp(DEFAULT_MASTER, "NONE/", 5))
df458c2004-12-30Henrik Grubbström (Grubba)  {
200ba82008-06-29Martin Stjernholm  SNPRINTF (mp, sizeof (master_location) - CONSTANT_STRLEN (MASTER_COOKIE),
df458c2004-12-30Henrik Grubbström (Grubba)  }
1700b02008-06-28Martin Stjernholm #ifdef __NT__
200ba82008-06-29Martin Stjernholm  if (!(*mp == '/' || *mp == '\\' || (isalpha (*mp) && mp[1] == ':'))) {
1700b02008-06-28Martin Stjernholm  char exepath[MAXPATHLEN]; if (!GetModuleFileName (NULL, exepath, _MAX_PATH)) fprintf (stderr, "Failed to get path to exe file: %d\n", GetLastError()); else { char tmp[MAXPATHLEN * 2]; char *p = strrchr (exepath, '\\'); if (p) *p = 0;
200ba82008-06-29Martin Stjernholm  SNPRINTF (tmp, sizeof (tmp), "%s/%s", exepath, mp); strncpy (mp, tmp,
1700b02008-06-28Martin Stjernholm  sizeof (master_location) - CONSTANT_STRLEN (MASTER_COOKIE)); } }
1176e82009-09-18Henrik Grubbström (Grubba) #else if (!*mp) { /* Attempt to find a master via the path to the binary. */ /* Note: We assume that MAXPATHLEN is > 18 characters. */ if (strlen(bin_name) < (2*MAXPATHLEN - CONSTANT_STRLEN(MASTER_COOKIE "master.pike"))) { char *p; strcpy(mp, bin_name); p = strrchr(mp, '/'); if (!p) p = mp; else p++; strcpy(p, "master.pike"); } }
1700b02008-06-28Martin Stjernholm #endif
200ba82008-06-29Martin Stjernholm  TRACE((stderr, "Default master at \"%s\"...\n", mp));
df458c2004-12-30Henrik Grubbström (Grubba) } #ifdef LIBPIKE static char libpike_file[MAXPATHLEN * 2]; static void *libpike;
d59abf2010-06-22Henrik Grubbström (Grubba) typedef void (*modfun)(void); #ifdef NO_CAST_TO_FUN /* Function pointers can't be casted to scalar pointers according to * ISO-C (probably to support true Harward achitecture machines). */ static modfun CAST_TO_FUN(void *ptr) { union { void *ptr; modfun fun; } u; u.ptr = ptr; return u.fun; } #else /* !NO_CAST_TO_FUN */ #define CAST_TO_FUN(X) ((modfun)X) #endif /* NO_CAST_TO_FUN */
11ae6e2010-06-17Henrik Grubbström (Grubba) static void (*init_pike_var)(const char **argv, const char *file); static void (*init_pike_runtime_var)(void (*exit_cb)(int)); static void (*add_predefine_var)(char *s);
df458c2004-12-30Henrik Grubbström (Grubba) #endif /* LIBPIKE */ static void find_lib_dir(int argc, char **argv) { int e; TRACE((stderr, "find_lib_dir...\n"));
1176e82009-09-18Henrik Grubbström (Grubba)  set_default_master(argv[0]);
df458c2004-12-30Henrik Grubbström (Grubba)  for(e=1; e<argc; e++) { TRACE((stderr, "Parse argument %d:\"%s\"...\n", e, argv[e])); if(argv[e][0] != '-') break; switch(argv[e][1]) { default: break; case 'm': if(argv[e][2]) { set_master(argv[e]+2); }else{ e++; if(e >= argc) { fprintf(stderr,"Missing argument to -m\n"); exit(1); } set_master(argv[e]); } break; case 's': if((!argv[e][2]) || ((argv[e][2] == 's') && !argv[e][3])) { e++; } break; case 'q': if(!argv[e][2]) e++; break; } }
b0757b2006-07-05Martin Stjernholm 
df458c2004-12-30Henrik Grubbström (Grubba) #ifdef LIBPIKE
b0757b2006-07-05Martin Stjernholm  { char *p; char *dir; memcpy(libpike_file, master_location + CONSTANT_STRLEN(MASTER_COOKIE), sizeof(master_location) - CONSTANT_STRLEN(MASTER_COOKIE)); for (p = dir = libpike_file; *p; p++) { if ((*p == '/')
df458c2004-12-30Henrik Grubbström (Grubba) #ifdef __NT__
b0757b2006-07-05Martin Stjernholm  || (*p == '\\')
df458c2004-12-30Henrik Grubbström (Grubba) #endif /* __NT__ */
b0757b2006-07-05Martin Stjernholm  ) dir = p+1; }
a205122010-06-23Henrik Grubbström (Grubba)  if ((dir + CONSTANT_STRLEN("pike.so")) >= libpike_file + 2*MAXPATHLEN) {
b0757b2006-07-05Martin Stjernholm  /* Not likely to happen as long as MASTER_COOKIE is longer than "pike.so". */ fprintf(stderr, "Too long path to pike.so.\n"); exit(1); } /* Don't forget the NUL! */
a205122010-06-23Henrik Grubbström (Grubba)  memcpy(dir, "pike.so", CONSTANT_STRLEN("pike.so") + 1);
df458c2004-12-30Henrik Grubbström (Grubba)  } #endif /* LIBPIKE */ } int main(int argc, char **argv)
ec337d2004-12-29Henrik Grubbström (Grubba) { JMP_BUF back; int e, num;
5267b71995-08-09Fredrik Hübinette (Hubbe)  char *p;
a025662007-05-17Henrik Grubbström (Grubba) #ifdef PIKE_EXTRA_DEBUG #ifdef HAVE_SIGNAL if (sizeof(void *) == 8) { /* 64-bit Solaris 10 in Xenofarm fails with SIGPIPE. * Force a core dump. */ signal(SIGPIPE, abort); } #endif #endif
89d10f2012-08-17Henrik Grubbström (Grubba) #ifdef HAVE_MALLOPT TRACE((stderr, "Init malloc...\n")); /* The malloc implementation in recent glibc (eg Linux) * defaults to using one arena / thread. This means that * memory once allocated from one thread can't later be * allocated by another thread. * * cf [bug 6045] and http://sourceware.org/bugzilla/show_bug.cgi?id=11261 * * We try to alleviate the problem by reducing the number * of arenas as much as possible. */ #ifdef M_ARENA_TEST /* NB: Some versions of glibc don't support setting M_ARENA_TEST to 0. */ /* Note also that the test is inverted since mallopt returns 0 on success. */ mallopt(M_ARENA_TEST, 0) && mallopt(M_ARENA_TEST, 1); #endif #ifdef M_ARENA_MAX mallopt(M_ARENA_MAX, 1); #endif #endif /* HAVE_MALLOPT */
df458c2004-12-30Henrik Grubbström (Grubba)  TRACE((stderr, "Init master...\n")); find_lib_dir(argc, argv);
cee5811999-12-05Henrik Grubbström (Grubba) 
df458c2004-12-30Henrik Grubbström (Grubba) #ifdef LIBPIKE
9bd21e2005-01-03Marcus Agehall #ifdef HAVE_DLINIT
df458c2004-12-30Henrik Grubbström (Grubba)  if (!dlinit()) { fprintf(stderr, "dlinit failed.\n"); exit(1); }
9bd21e2005-01-03Marcus Agehall #endif /* HAVE_DLINIT */
bf47e12000-04-06Henrik Grubbström (Grubba) 
f15b4b2010-06-21Henrik Grubbström (Grubba)  if (!(libpike = dlopen(libpike_file, RTLD_NOW))) {
df458c2004-12-30Henrik Grubbström (Grubba)  const char *err = dlerror(); if (!err) err = "Unknown reason.";
f15b4b2010-06-21Henrik Grubbström (Grubba)  fprintf(stderr, "Failed to open %s: %s\n", libpike_file, err);
df458c2004-12-30Henrik Grubbström (Grubba)  exit(1); } #define LOOKUP(symbol) do { \
11ae6e2010-06-17Henrik Grubbström (Grubba)  if (!(PIKE_CONCAT(symbol, _var) = \ CAST_TO_FUN(dlsym(libpike, TOSTR(symbol)))) && \ !(PIKE_CONCAT(symbol, _var) = \ CAST_TO_FUN(dlsym(libpike, "_" TOSTR(symbol))))) { \
df458c2004-12-30Henrik Grubbström (Grubba)  fprintf(stderr, "Missing symbol in %s: " TOSTR(symbol) "\n", \
f15b4b2010-06-21Henrik Grubbström (Grubba)  libpike_file); \
df458c2004-12-30Henrik Grubbström (Grubba)  dlclose(libpike); \ exit(1); \ } \ } while(0) LOOKUP(init_pike);
11ae6e2010-06-17Henrik Grubbström (Grubba) #define init_pike init_pike_var
df458c2004-12-30Henrik Grubbström (Grubba)  LOOKUP(init_pike_runtime);
11ae6e2010-06-17Henrik Grubbström (Grubba) #define init_pike_runtime init_pike_runtime_var
df458c2004-12-30Henrik Grubbström (Grubba)  LOOKUP(add_predefine);
11ae6e2010-06-17Henrik Grubbström (Grubba) #define add_predefine add_predefine_var
ff34a52001-05-31Henrik Grubbström (Grubba) 
df458c2004-12-30Henrik Grubbström (Grubba) #endif /* LIBPIKE */ TRACE((stderr, "init_pike()\n")); init_pike(argv, master_location + CONSTANT_STRLEN(MASTER_COOKIE));
895ced2003-10-25Martin Nilsson 
5267b71995-08-09Fredrik Hübinette (Hubbe)  for(e=1; e<argc; e++) {
ff34a52001-05-31Henrik Grubbström (Grubba)  TRACE((stderr, "Parse argument %d:\"%s\"...\n", e, argv[e]));
5267b71995-08-09Fredrik Hübinette (Hubbe)  if(argv[e][0]=='-') { for(p=argv[e]+1; *p;) { switch(*p) { case 'D': add_predefine(p+1); p+=strlen(p); break; case 'm': if(p[1]) { p+=strlen(p); }else{ e++; if(e >= argc) { fprintf(stderr,"Missing argument to -m\n"); exit(1); } p+=strlen(p); } break;
9f243b1996-08-12Fredrik Hübinette (Hubbe)  case 's': if(!p[1]) { e++; if(e >= argc) { fprintf(stderr,"Missing argument to -s\n"); exit(1); } p=argv[e];
4908871998-08-10Fredrik Hübinette (Hubbe)  }else{ p++; if(*p=='s') { if(!p[1]) { e++; if(e >= argc) { fprintf(stderr,"Missing argument to -ss\n"); exit(1); } p=argv[e]; }else{ p++; } #ifdef _REENTRANT thread_stack_size=STRTOL(p,&p,0); #endif p+=strlen(p); break; }
9f243b1996-08-12Fredrik Hübinette (Hubbe)  }
7965d72001-01-24Fredrik Hübinette (Hubbe)  Pike_stack_size=STRTOL(p,&p,0);
9f243b1996-08-12Fredrik Hübinette (Hubbe)  p+=strlen(p);
7965d72001-01-24Fredrik Hübinette (Hubbe)  if(Pike_stack_size < 256)
9f243b1996-08-12Fredrik Hübinette (Hubbe)  { fprintf(stderr,"Stack size must at least be 256.\n"); exit(1); } break;
3f1eeb1998-04-05Fredrik Hübinette (Hubbe)  case 'q': if(!p[1]) { e++; if(e >= argc) { fprintf(stderr,"Missing argument to -q\n"); exit(1); } p=argv[e];
4908871998-08-10Fredrik Hübinette (Hubbe)  }else{ p++;
3f1eeb1998-04-05Fredrik Hübinette (Hubbe)  }
dc3e782005-01-01Henrik Grubbström (Grubba)  set_pike_evaluator_limit(STRTOL(p, &p, 0));
3f1eeb1998-04-05Fredrik Hübinette (Hubbe)  p+=strlen(p); break;
5267b71995-08-09Fredrik Hübinette (Hubbe)  case 'd':
cd83521998-02-02Fredrik Hübinette (Hubbe)  more_d_flags: switch(p[1]) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': d_flag+=STRTOL(p+1,&p,10); break;
943f851998-04-13Henrik Grubbström (Grubba)  case 'c': p++;
262b092012-12-10Felipe Monteiro de Carvalho #if (defined(YYDEBUG) && (YYDEBUG==1)) && defined(PIKE_DEBUG)
943f851998-04-13Henrik Grubbström (Grubba)  yydebug++;
262b092012-12-10Felipe Monteiro de Carvalho #endif /* YYDEBUG && PIKE_DEBUG */
943f851998-04-13Henrik Grubbström (Grubba)  break;
cd83521998-02-02Fredrik Hübinette (Hubbe)  case 's':
df458c2004-12-30Henrik Grubbström (Grubba)  set_pike_debug_options(DEBUG_SIGNALS, DEBUG_SIGNALS);
cd83521998-02-02Fredrik Hübinette (Hubbe)  p++;
9b08a21998-03-31Fredrik Hübinette (Hubbe)  goto more_d_flags; case 't':
df458c2004-12-30Henrik Grubbström (Grubba)  set_pike_debug_options(NO_TAILRECURSION, NO_TAILRECURSION);
cd83521998-02-02Fredrik Hübinette (Hubbe)  p++;
9b08a21998-03-31Fredrik Hübinette (Hubbe)  goto more_d_flags;
cd83521998-02-02Fredrik Hübinette (Hubbe) 
7386972001-06-30Fredrik Hübinette (Hubbe)  case 'g':
df458c2004-12-30Henrik Grubbström (Grubba)  set_pike_debug_options(GC_RESET_DMALLOC, GC_RESET_DMALLOC);
7386972001-06-30Fredrik Hübinette (Hubbe)  p++; goto more_d_flags; case 'p':
df458c2004-12-30Henrik Grubbström (Grubba)  set_pike_debug_options(NO_PEEP_OPTIMIZING, NO_PEEP_OPTIMIZING);
7386972001-06-30Fredrik Hübinette (Hubbe)  p++; goto more_d_flags;
01185d2003-04-01Martin Stjernholm  case 'T':
df458c2004-12-30Henrik Grubbström (Grubba)  set_pike_debug_options(ERRORCHECK_MUTEXES, ERRORCHECK_MUTEXES);
01185d2003-04-01Martin Stjernholm  p++; goto more_d_flags;
2d54492008-07-31Martin Stjernholm  case 'L': set_pike_debug_options (WINDOWS_ERROR_DIALOGS, WINDOWS_ERROR_DIALOGS); p++; goto more_d_flags;
7d955e1999-12-13Henrik Grubbström (Grubba)  default: d_flag += (p[0] == 'd');
cee5811999-12-05Henrik Grubbström (Grubba)  p++;
7d955e1999-12-13Henrik Grubbström (Grubba)  } break;
cee5811999-12-05Henrik Grubbström (Grubba) 
7d955e1999-12-13Henrik Grubbström (Grubba)  case 'r':
17e1771999-12-13Per Hedbor  more_r_flags: switch(p[1]) {
7d955e1999-12-13Henrik Grubbström (Grubba)  case 't':
df458c2004-12-30Henrik Grubbström (Grubba)  set_pike_runtime_options(RUNTIME_CHECK_TYPES, RUNTIME_CHECK_TYPES);
7d955e1999-12-13Henrik Grubbström (Grubba)  p++;
17e1771999-12-13Per Hedbor  goto more_r_flags;
7d955e1999-12-13Henrik Grubbström (Grubba)  case 'T':
df458c2004-12-30Henrik Grubbström (Grubba)  set_pike_runtime_options(RUNTIME_STRICT_TYPES, RUNTIME_STRICT_TYPES);
7d955e1999-12-13Henrik Grubbström (Grubba)  p++;
17e1771999-12-13Per Hedbor  goto more_r_flags;
7d955e1999-12-13Henrik Grubbström (Grubba) 
17e1771999-12-13Per Hedbor  default: p++;
7d955e1999-12-13Henrik Grubbström (Grubba)  break;
cd83521998-02-02Fredrik Hübinette (Hubbe)  }
5267b71995-08-09Fredrik Hübinette (Hubbe)  break; case 'a': if(p[1]>='0' && p[1]<='9') a_flag+=STRTOL(p+1,&p,10); else a_flag++,p++; break; case 't':
24d38f2004-03-17Martin Stjernholm  more_t_flags: switch (p[1]) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': Pike_interpreter.trace_level+=STRTOL(p+1,&p,10); break; case 'g': gc_trace++; p++; goto more_t_flags; default: if (p[0] == 't') Pike_interpreter.trace_level++; p++; }
97ebb32003-01-09Henrik Grubbström (Grubba)  default_t_flag = Pike_interpreter.trace_level;
5267b71995-08-09Fredrik Hübinette (Hubbe)  break;
06983f1996-09-22Fredrik Hübinette (Hubbe)  case 'p':
0612442001-05-16Fredrik Hübinette (Hubbe)  if(p[1]=='s') {
ec337d2004-12-29Henrik Grubbström (Grubba)  pike_enable_stack_profiling();
0612442001-05-16Fredrik Hübinette (Hubbe)  p+=strlen(p); }else{ if(p[1]>='0' && p[1]<='9') p_flag+=STRTOL(p+1,&p,10); else p_flag++,p++; }
06983f1996-09-22Fredrik Hübinette (Hubbe)  break;
5267b71995-08-09Fredrik Hübinette (Hubbe)  case 'l': if(p[1]>='0' && p[1]<='9') l_flag+=STRTOL(p+1,&p,10); else l_flag++,p++; break; default:
4967071997-01-15Fredrik Hübinette (Hubbe)  p+=strlen(p);
5267b71995-08-09Fredrik Hübinette (Hubbe)  } } }else{ break; } }
01185d2003-04-01Martin Stjernholm #ifndef PIKE_MUTEX_ERRORCHECK
d867062005-01-01Henrik Grubbström (Grubba)  if (set_pike_debug_options(0,0) & ERRORCHECK_MUTEXES)
01185d2003-04-01Martin Stjernholm  fputs ("Warning: -dT (error checking mutexes) not supported on this system.\n", stderr); #endif
d867062005-01-01Henrik Grubbström (Grubba)  if (d_flag) set_pike_debug_options(ERRORCHECK_MUTEXES, ERRORCHECK_MUTEXES);
01185d2003-04-01Martin Stjernholm 
8196fb2008-07-31Martin Stjernholm #ifdef HAVE_SETERRORMODE
2d54492008-07-31Martin Stjernholm  if (!(debug_options & WINDOWS_ERROR_DIALOGS)) {
8196fb2008-07-31Martin Stjernholm  /* This avoids popups when LoadLibrary fails to find a dll. * * Note that the popup is the _only_ way to see which dll (loaded * indirectly by dependencies from the one in the LoadLibrary * call) that Windows didn't find. :( Hence the -rl runtime option * to turn it on. * * Note: This setting is process global. */ SetErrorMode (SEM_FAILCRITICALERRORS | /* Maybe set this too? Don't know exactly when it * has effect. /mast */ /*SEM_NOOPENFILEERRORBOX | */
9624b62008-07-31Martin Stjernholm  SetErrorMode (0));
8196fb2008-07-31Martin Stjernholm  } #endif
ec337d2004-12-29Henrik Grubbström (Grubba)  init_pike_runtime(exit);
a9388a1998-09-02Henrik Grubbström (Grubba) 
df458c2004-12-30Henrik Grubbström (Grubba)  /* NOTE: Reuse master_location here to avoid duplicates of * the MASTER_COOKIE string in the binary. */ add_pike_string_constant("__master_cookie", master_location, CONSTANT_STRLEN(MASTER_COOKIE));
ec337d2004-12-29Henrik Grubbström (Grubba)  if(SETJMP(back))
5267b71995-08-09Fredrik Hübinette (Hubbe)  {
a1ed502010-08-26Martin Stjernholm  if(throw_severity == THROW_EXIT || throw_severity == THROW_THREAD_EXIT)
61e9a01998-01-25Fredrik Hübinette (Hubbe)  { num=throw_value.u.integer; }else{
017b572011-10-28Henrik Grubbström (Grubba)  if (TYPEOF(throw_value) == T_OBJECT &&
667ec22003-07-22Martin Stjernholm  throw_value.u.object->prog == master_load_error_program && !get_master()) { /* Report this specific error in a nice way. Since there's no * master it'd be reported with a raw error dump otherwise. */ struct generic_error_struct *err;
e8cbe42004-07-04Martin Nilsson  dynamic_buffer buf; dynbuf_string s; struct svalue t;
1ab4ac2008-01-26Martin Stjernholm  move_svalue (Pike_sp++, &throw_value); mark_free_svalue (&throw_value);
667ec22003-07-22Martin Stjernholm  err = (struct generic_error_struct *) get_storage (Pike_sp[-1].u.object, generic_error_program);
e8cbe42004-07-04Martin Nilsson 
017b572011-10-28Henrik Grubbström (Grubba)  SET_SVAL(t, PIKE_T_STRING, 0, string, err->error_message);
e8cbe42004-07-04Martin Nilsson  init_buf(&buf); describe_svalue(&t,0,0); s=complex_free_buf(&buf);
9f6bfe2004-07-04Stephen R. van den Berg  fputs(s.str, stderr);
e8cbe42004-07-04Martin Nilsson  free(s.str);
667ec22003-07-22Martin Stjernholm  } else call_handle_error();
61e9a01998-01-25Fredrik Hübinette (Hubbe)  num=10; }
ec337d2004-12-29Henrik Grubbström (Grubba)  }else{
dc3e782005-01-01Henrik Grubbström (Grubba)  struct object *m;
ec337d2004-12-29Henrik Grubbström (Grubba) 
dc3e782005-01-01Henrik Grubbström (Grubba)  back.severity=THROW_EXIT;
09126b2001-12-19Martin Stjernholm 
dc3e782005-01-01Henrik Grubbström (Grubba)  if ((m = load_pike_master())) { TRACE((stderr, "Call master->_main()...\n"));
09126b2001-12-19Martin Stjernholm 
dc3e782005-01-01Henrik Grubbström (Grubba)  pike_push_argv(argc, argv);
d867062005-01-01Henrik Grubbström (Grubba) 
7afbec2008-06-05Martin Stjernholm  apply(m, "_main", 1);
dc3e782005-01-01Henrik Grubbström (Grubba)  pop_stack(); num=0; } else { num = -1; }
5267b71995-08-09Fredrik Hübinette (Hubbe)  } UNSETJMP(back);
cfd36c2003-11-14Martin Stjernholm  TRACE((stderr, "Exit %d...\n", num));
ec337d2004-12-29Henrik Grubbström (Grubba) 
eb2fd52000-11-06Henrik Grubbström (Grubba)  pike_do_exit(num);
3c0c281998-01-26Fredrik Hübinette (Hubbe)  return num; /* avoid warning */
61e9a01998-01-25Fredrik Hübinette (Hubbe) }