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 { string nameof(string x) { if(mixed tmp=search(all_constants(),x)) return tmp;
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]; }