d7f2202002-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.
ef08342006-03-17Henrik Grubbström (Grubba) || $Id: dumpmaster.pike,v 1.15 2006/03/17 18:36:44 grubba Exp $
d7f2202002-10-11Martin Nilsson */
03c7b32002-10-08Martin Nilsson 
26f3da2000-07-11Fredrik Hübinette (Hubbe) string fr;
9073712000-03-26Fredrik Hübinette (Hubbe) 
d178fe2001-01-23Fredrik Hübinette (Hubbe) array encoded=({});
d4140e2004-07-04Stephen R. van den Berg private function werror = _static_modules.files()->_stderr->write;
e3276e2004-07-04Stephen R. van den Berg 
0cd76f1998-10-22Fredrik Hübinette (Hubbe) void handle_error(mixed err) {
d178fe2001-01-23Fredrik Hübinette (Hubbe)  foreach(encoded, mixed o) { werror("***Failed to encode %t: %O\n",o,o); #if constant(_describe) _describe(o); #endif }
0cd76f1998-10-22Fredrik Hübinette (Hubbe)  werror("%O\n",err); }
9073712000-03-26Fredrik Hübinette (Hubbe) 
26f3da2000-07-11Fredrik Hübinette (Hubbe) void compile_error(string file,int line,string err)
9073712000-03-26Fredrik Hübinette (Hubbe) {
57b2262002-10-11Martin Nilsson  werror("%s:%s:%s\n", file, line?(string)line:"-", err);
26f3da2000-07-11Fredrik Hübinette (Hubbe) }
9073712000-03-26Fredrik Hübinette (Hubbe) 
26f3da2000-07-11Fredrik Hübinette (Hubbe) string fakeroot(string s) { if(fr) s=fr+combine_path(getcwd(),s); return s; } string read_file(string s) {
fd0fd72004-04-17Marcus Comstedt  return _static_modules.files()->Fd(fakeroot(s),"r")->read();
9073712000-03-26Fredrik Hübinette (Hubbe) }
0cd76f1998-10-22Fredrik Hübinette (Hubbe) program compile_file(string file) {
9073712000-03-26Fredrik Hübinette (Hubbe)  return compile(cpp(read_file(file),file));
0cd76f1998-10-22Fredrik Hübinette (Hubbe) } class Codec {
ef08342006-03-17Henrik Grubbström (Grubba)  mixed encode_object(object o) { if (o->_encode) return o->_encode(); werror("Can't encode object %O without _encode function.\n", o); throw(({ "No _encode().\n", backtrace() })); }
9cba792001-01-25Fredrik Hübinette (Hubbe)  string nameof(mixed x)
0cd76f1998-10-22Fredrik Hübinette (Hubbe)  { if(mixed tmp=search(all_constants(),x)) return tmp;
9cba792001-01-25Fredrik Hübinette (Hubbe)  switch(x) { #define CONST(X) case X: return #X
fd0fd72004-04-17Marcus Comstedt  CONST(_static_modules.files.Stat);
87f9082001-03-12Fredrik Hübinette (Hubbe)  CONST(_static_modules.Builtin.__backend);
9cba792001-01-25Fredrik Hübinette (Hubbe)  }
d178fe2001-01-23Fredrik Hübinette (Hubbe)  encoded+=({x});
0cd76f1998-10-22Fredrik Hübinette (Hubbe)  return UNDEFINED; } }
57b2262002-10-11Martin Nilsson  void _main(array(string) argv, array(string) env)
0cd76f1998-10-22Fredrik Hübinette (Hubbe) {
9073712000-03-26Fredrik Hübinette (Hubbe)  foreach(argv[1..sizeof(argv)-2], string f)
57b2262002-10-11Martin Nilsson  sscanf(f, "--fakeroot=%s", fr);
9073712000-03-26Fredrik Hübinette (Hubbe) 
0cd76f1998-10-22Fredrik Hübinette (Hubbe)  program p=compile_file(argv[-1]); string s=encode_value(p, Codec());
fd0fd72004-04-17Marcus Comstedt  _static_modules.files()->Fd(fakeroot(argv[-1]) + ".o","wct")->write(s);
0cd76f1998-10-22Fredrik Hübinette (Hubbe)  exit(0); }
cc0bf12000-01-31Fredrik Hübinette (Hubbe) 
57b2262002-10-11Martin Nilsson mixed resolv() { return UNDEFINED; }