cb22561995-10-11Fredrik Hübinette (Hubbe) /*\
3e9a462002-01-16Martin Nilsson ||| This file is part of Pike. For copyright information see COPYRIGHT.
59e32d2002-06-01Martin Nilsson ||| Pike is distributed under GPL, LGPL and MPL. See the file COPYING ||| for more information.
1b10db2002-10-08Martin Nilsson ||| $Id: module.c,v 1.18 2002/10/08 20:22:23 nilsson Exp $
cb22561995-10-11Fredrik Hübinette (Hubbe) \*/
db3e131997-02-06Fredrik Hübinette (Hubbe) #include "global.h"
5267b71995-08-09Fredrik Hübinette (Hubbe) #include "module.h"
bb55f81997-03-16Fredrik Hübinette (Hubbe) #include "pike_macros.h"
b2d3e42000-12-01Fredrik Hübinette (Hubbe) #include "pike_error.h"
db3e131997-02-06Fredrik Hübinette (Hubbe) #include "builtin_functions.h" #include "main.h" #include "svalue.h" #include "interpret.h" #include "stralloc.h" #include "object.h" #include "mapping.h"
992e662000-07-06Fredrik Hübinette (Hubbe) #include "program_id.h"
37b0222002-01-31Marcus Comstedt #include "language.h" #include "lex.h"
5267b71995-08-09Fredrik Hübinette (Hubbe) 
db3e131997-02-06Fredrik Hübinette (Hubbe) #include "modules/modlist_headers.h"
f173082001-02-01Fredrik Hübinette (Hubbe) #ifndef IN_TPIKE #include "post_modules/modlist_headers.h" #endif
5267b71995-08-09Fredrik Hübinette (Hubbe) 
1b10db2002-10-08Martin Nilsson RCSID("$Id: module.c,v 1.18 2002/10/08 20:22:23 nilsson Exp $");
24ddc71998-03-28Henrik Grubbström (Grubba) 
db3e131997-02-06Fredrik Hübinette (Hubbe) typedef void (*modfun)(void);
5267b71995-08-09Fredrik Hübinette (Hubbe) 
db3e131997-02-06Fredrik Hübinette (Hubbe) struct static_module
5267b71995-08-09Fredrik Hübinette (Hubbe) {
db3e131997-02-06Fredrik Hübinette (Hubbe)  char *name; modfun init; modfun exit; };
5267b71995-08-09Fredrik Hübinette (Hubbe) 
db3e131997-02-06Fredrik Hübinette (Hubbe) static struct static_module module_list[] = {
156fd51997-10-27Fredrik Hübinette (Hubbe)  { "Builtin", low_init_main, low_exit_main }
db3e131997-02-06Fredrik Hübinette (Hubbe) #include "modules/modlist.h"
f173082001-02-01Fredrik Hübinette (Hubbe) #ifndef IN_TPIKE #include "post_modules/modlist.h" #endif
156fd51997-10-27Fredrik Hübinette (Hubbe)  ,{ "Builtin2", init_main, exit_main }
db3e131997-02-06Fredrik Hübinette (Hubbe) }; void init_modules(void)
5267b71995-08-09Fredrik Hübinette (Hubbe) {
c712e71998-04-23Fredrik Hübinette (Hubbe)  struct program *p;
5267b71995-08-09Fredrik Hübinette (Hubbe)  unsigned int e;
37b0222002-01-31Marcus Comstedt  struct lex save_lex; save_lex = lex; lex.current_line=1; lex.current_file=make_shared_string("-");
c712e71998-04-23Fredrik Hübinette (Hubbe)  start_new_program();
992e662000-07-06Fredrik Hübinette (Hubbe)  Pike_compiler->new_program->id=PROG___BUILTIN_ID;
db3e131997-02-06Fredrik Hübinette (Hubbe) 
5267b71995-08-09Fredrik Hübinette (Hubbe)  for(e=0;e<NELEM(module_list);e++) {
37b0222002-01-31Marcus Comstedt  JMP_BUF recovery;
db3e131997-02-06Fredrik Hübinette (Hubbe)  start_new_program();
37b0222002-01-31Marcus Comstedt  if(SETJMP(recovery)) { free_program(end_program()); call_handle_error(); } else { module_list[e].init(); debug_end_class(module_list[e].name,strlen(module_list[e].name),0); } UNSETJMP(recovery);
5267b71995-08-09Fredrik Hübinette (Hubbe)  }
c712e71998-04-23Fredrik Hübinette (Hubbe)  push_text("_static_modules"); push_object(low_clone(p=end_program())); f_add_constant(2); free_program(p);
37b0222002-01-31Marcus Comstedt  free_string(lex.current_file); lex = save_lex;
5267b71995-08-09Fredrik Hübinette (Hubbe) }
db3e131997-02-06Fredrik Hübinette (Hubbe) void exit_modules(void)
5267b71995-08-09Fredrik Hübinette (Hubbe) {
37b0222002-01-31Marcus Comstedt  JMP_BUF recovery;
5267b71995-08-09Fredrik Hübinette (Hubbe)  int e;
db3e131997-02-06Fredrik Hübinette (Hubbe)  for(e=NELEM(module_list)-1;e>=0;e--)
37b0222002-01-31Marcus Comstedt  { if(SETJMP(recovery)) call_handle_error(); else module_list[e].exit(); UNSETJMP(recovery); }
5267b71995-08-09Fredrik Hübinette (Hubbe) }