54 lines
1.3 KiB
JavaScript
54 lines
1.3 KiB
JavaScript
load('texdefs.js');
|
|
load('texfuncs.js');
|
|
|
|
// File to convert
|
|
file = getArg('-f','No file specified with -f',true);
|
|
// Page
|
|
p = getArg('-p','No page specified with -p',true);
|
|
// Index
|
|
i = getArg('-i','No index specified with -i',false);
|
|
// Key
|
|
key = getArg('-k','No index specified with -k',false);
|
|
// Cost
|
|
cost = getArg('-c','No index specified with -c',false);
|
|
// Owner
|
|
owner = getArg('-o','No owner specified with -o',true);
|
|
|
|
f = new File(file);
|
|
if (! f.exists || ! f.open('r')) {
|
|
log(LOG_ERROR,'Unable to open ['+file+']');
|
|
exit(1);
|
|
}
|
|
|
|
frame = new Frame(p,i);
|
|
frame.owner = base64_encode(owner.replace(/\\1/g,"\1"));
|
|
frame.content = base64_encode(f.read());
|
|
|
|
if (key) {
|
|
frame.key = key.split(',').map(function(t){return parseInt(t)});
|
|
|
|
if (frame.key.length != 10) {
|
|
log(LOG_ERROR,'Must specify 10 keys with -k');
|
|
exit(1);
|
|
}
|
|
}
|
|
|
|
// Public
|
|
frame.isPublic = (argv.indexOf('-P') >= 0);
|
|
frame.isAccessible = (argv.indexOf('-A') >= 0);
|
|
if (cost)
|
|
frame.cost = cost;
|
|
|
|
// Date
|
|
frame.date = new Date().toISOString();
|
|
|
|
w = new File(system.text_dir+'ansitex/'+frame.page+'.tex');
|
|
if (! w.open('w')) {
|
|
log(LOG_ERROR,'Unable to create TEX file for '+frame.page);
|
|
exit(1);
|
|
}
|
|
|
|
w.write(JSON.stringify(frame));
|
|
w.close();
|
|
|
|
printf('Saved file: %s.tex',frame.page); |