


# gen-file.pkg
# Compiled by:
# src/lib/compiler/back/low/tools/line-number-database.libpackage gen_file
: (weak) Generate_File # Generate_File is from src/lib/compiler/back/low/tools/line-number-db/generate-file.api{
include adl_error;
bufsize = 1024*1024;
fun gen { trans, program, file_suffix } (_, [infile])
=>
{ init();
my { base, ext } = winix::path::split_base_ext infile;
outfile = winix::path::join_base_ext { base, ext=>THE file_suffix };
if (infile == outfile)
fail("input and output file the same name!");
fi;
text = trans infile;
fun changed ()
=
{ s = file::open_for_read outfile;
t = file::read_n (s, bufsize);
file::close_input s;
t != text;
}
except _ = TRUE;
if (*error_count > 0)
print("[Result not written to " + outfile + "]\n"); 1;
else
if (changed ())
print("[Generating " + outfile + "]\n");
s = file::open_for_write outfile;
file::write (s, text);
file::close_output s;
0;
else
print ("[No change to " + outfile + "]\n");
0;
fi;
fi;
}
except ERROR => 1;
exn => fail("Uncaught exception " + exception_name exn);
end;
gen { program, ... } _
=>
fail ("usage: " + program + " <filename>");
end;
};


