03c7b32002-10-08Martin 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. \*/ /* $Id: dumpmaster.pike,v 1.8 2002/10/08 18:21:20 nilsson Exp $ */
0cd76f1998-10-22Fredrik Hübinette (Hubbe) #define UNDEFINED (([])[0])
26f3da2000-07-11Fredrik Hübinette (Hubbe) string fr;
9073712000-03-26Fredrik Hübinette (Hubbe) 
d178fe2001-01-23Fredrik Hübinette (Hubbe) array encoded=({});
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) {
26f3da2000-07-11Fredrik Hübinette (Hubbe)  werror(sprintf("%s:%s:%s\n",file, line?(string)line:"-",err)); }
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) { 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 {
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 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; } } void _main(string *argv, string *env) {
9073712000-03-26Fredrik Hübinette (Hubbe)  foreach(argv[1..sizeof(argv)-2], string f)
26f3da2000-07-11Fredrik Hübinette (Hubbe)  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());
26f3da2000-07-11Fredrik Hübinette (Hubbe)  _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)  mixed resolv() { return ([])[0]; }