5 Updates some MP reference documents.
7 Angel Ortega <angel@triptico.com>
11 sub load_ref_document(file)
12 /* loads a document and returns a structure with header,
13 data entries and signature */
22 if ((f = open(file, "r")) == NULL)
29 l = sregex(l, "/\r?\n$/");
31 /* is the line only dashes? */
32 if (regex(l, '/^-+$/')) {
37 /* concat all data and reset */
38 local b = join(d, "\n");
41 /* flush previous data: is this the first one? */
43 /* yes; everything is the header */
47 /* there is a previous one; store */
48 r.data[k] = b->sregex("/\n$/")->sregex("/^\n/");
53 /* if it's the empty string, it's the
54 signature mark; we're done */
56 r.sig = join([ l, read(f) ], "\n");
70 sub save_ref_document(file, r, hash, prefix, def)
71 /* saves a parsed document filling empty entries from hash */
75 if ((f = open(file, "w")) == NULL)
81 foreach (k, sort(keys(hash))) {
87 write(f, sregex(k, '/./g', '-'));
90 write(f, r.data[k] || def[k] || "To be written.");
101 sub update_ref_document(file, hash, prefix, def)
105 if (r = load_ref_document(file))
106 save_ref_document(file, r, hash, prefix, def);
111 update_ref_document('doc/mp_configuration.txt', mp.config, 'mp.config');
115 foreach (k, keys(mp.keycodes))
116 kc[mp.keycodes[k]] = k;
120 /* fill now the default descriptions */
121 foreach (k, keys(mp.actdesc)) {
124 l = '_' ~ mp.actdesc[k] ~ '_';
127 l = l ~ " (`" ~ kc[k] ~ "')";
129 l = l ~ "\n\nTo be written.";
134 update_ref_document('doc/mp_actions.txt', mp.actdesc, NULL, def);
138 if ((f = open('doc/mp_keycodes.txt', 'w')) != NULL) {
139 write(f, "Minimum Profit Keycodes\n");
140 write(f, "=======================\n\n");
142 write(f, "Table with Minimum Profit's keycodes and their default assigned actions.\n\n");
144 local tbl = " +---------------------+------------------------+\n";
147 write(f, sprintf(" | %19s | %22s |\n", 'Keycode', 'Action'));
150 foreach(k, sort(keys(mp.keycodes))) {
151 write(f, sprintf(" | %19s | %22s |\n", k, mp.keycodes[k]));