-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsave.js
More file actions
71 lines (71 loc) · 2.58 KB
/
Copy pathsave.js
File metadata and controls
71 lines (71 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
"use strict";
/**
* SAVE command - write current design into a file that can be read as a STARTUP
* file. optionally, create a print listing
*/
var fs = require("fs");
var sprintf = require("sprintf-js").sprintf;
function save(split_line) {
var cpname = 'CHECKPT';
var name = split_line.shift();
var comment = split_line.join(" ");
console.log('SAVE ...');
while (name === undefined) {
console.log('SELECT:');
console.log(' <enter> OR 0 TO RETURN TO COMMAND LEVEL.');
console.log(' 1 TO WRITE ONE FILE TO DISK IN');
console.log(' STARTUP (.DSN) FORMAT.');
console.log(' 2 TO WRITE TWO FILES TO DISK;');
console.log(' STARTUP (.DSN) AND PRINTER (.PRN) FORMATS.');
console.log(' 3 FOR IMMEDIATE OUTPUT TO PRINTER,');
console.log(' NOTHING TO DISK.');
console.log(': ');
var choice = '1';
console.log(DESIGN_NAME + ': ' +choice);
if (choice === undefined || choice < '1' || choice > '3')
return;
console.log('ENTER FILE NAME IN WHICH TO SAVE CURRENT STATUS');
console.log(sprintf('(DEFAULT WILL USE %s.DSN & %s.PRN). : ', cpname, cpname));
name = cpname;
console.log(DESIGN_NAME + ': ' +name);
if (name === undefined) {
console.log('SAVE ...');
}
}
if (name !== undefined) {
cpname = name.replace(/\.[^/.]+$/, "");
}
/* add code to start sequence to review available checkpoint names */
if (comment !== undefined && comment != '') {
design.labels.forEach(function(label) {
if (label.name == 'COMMENT') {
label.value = comment;
}
});
}
var rc = sfwriter(cpname);
return;
function sfwriter(cpname) {
var dname = cpname + '.DSN';
if (fs.existsSync(dname)) {
console.log('%s ALREADY EXISTS ...', dname);
console.log('OVER WRITE ? (y/N): ');
var yn = 'N';
if (!'YES'.startsWith(yn))
return;
}
var json = JSON.stringify(design, null, 4);
try {
fs.writeFileSync(dname, json, 'utf8');
} catch (err) {
console.log('err=' + err);
console.log('*** ERROR IN FILE NAME ***');
return;
}
if (IOOPT >= 3) {
console.log(sprintf('%s IS COMPLETE', dname));
}
return 1;
}
}
module.exports = save;