1*45324Sbostic /*
2*45324Sbostic * Help functions for sc
3*45324Sbostic * R. Bond, 1988
4*45324Sbostic * $Revision: 6.8 $
5*45324Sbostic */
6*45324Sbostic
7*45324Sbostic #include <curses.h>
8*45324Sbostic #include "sc.h"
9*45324Sbostic
10*45324Sbostic char *intro[] = {
11*45324Sbostic " ",
12*45324Sbostic " Overview:",
13*45324Sbostic " ",
14*45324Sbostic " A: This overview",
15*45324Sbostic " B: Options",
16*45324Sbostic " C: Cursor movement commands",
17*45324Sbostic " D: Cell entry and editing commands",
18*45324Sbostic " E: Line Editing",
19*45324Sbostic " F: File commands",
20*45324Sbostic " G: Row and column commands",
21*45324Sbostic " H: Range commands",
22*45324Sbostic " I: Miscellaneous commands",
23*45324Sbostic " J: Variable names/Expressions",
24*45324Sbostic " K: Range functions",
25*45324Sbostic " L: Numeric functions",
26*45324Sbostic " M: String functions",
27*45324Sbostic " N: Financial functions",
28*45324Sbostic " O: Time and date functions",
29*45324Sbostic " ",
30*45324Sbostic " Q: Return to main spreadsheet",
31*45324Sbostic (char *)0
32*45324Sbostic };
33*45324Sbostic
34*45324Sbostic char *options[] = {
35*45324Sbostic " ",
36*45324Sbostic " B: Options",
37*45324Sbostic " ",
38*45324Sbostic " ^To Toggle options. Toggle one option selected by o:",
39*45324Sbostic " ",
40*45324Sbostic " a Recalculate automatically or on ``@'' commands.",
41*45324Sbostic " c Current cell highlighting enable/disable.",
42*45324Sbostic " e External function execution enable/disable.",
43*45324Sbostic " n If enabled, a digit starts a numeric value.",
44*45324Sbostic " t Top line display enable/disable.",
45*45324Sbostic " x Encrypt/decrypt database and listing files.",
46*45324Sbostic " $ Dollar prescale. If enabled, all numeric constants.",
47*45324Sbostic " (not expressions) entered are multipled by 0.01.",
48*45324Sbostic " ",
49*45324Sbostic " S Set options. Options include:",
50*45324Sbostic " ",
51*45324Sbostic " byrows Recalculate in row order. (default)",
52*45324Sbostic " bycols Recalculate in column order.",
53*45324Sbostic " iterations=n Set the number of iterations allowed. (10)",
54*45324Sbostic " tblstyle=xx Set ``T'' output style to:",
55*45324Sbostic " 0 (none), tex, latex, or tbl.",
56*45324Sbostic (char *)0
57*45324Sbostic };
58*45324Sbostic
59*45324Sbostic char *cursor[] = {
60*45324Sbostic " ",
61*45324Sbostic " C: Cell cursor movement (always OK):",
62*45324Sbostic " ",
63*45324Sbostic " ^N ^P ^B ^F Down, up, back, forward",
64*45324Sbostic " ^Ed Go to end of range. Follow ^E by a direction indicator",
65*45324Sbostic " such as ^P or j.",
66*45324Sbostic " Arrow keys (if the terminal and termcap support them.)",
67*45324Sbostic " ",
68*45324Sbostic " Cell cursor movement if no prompt active:",
69*45324Sbostic " j,k,l,h Down, up, right, left",
70*45324Sbostic " SPACE Forward",
71*45324Sbostic " ^H Back",
72*45324Sbostic " TAB Forward, otherwise starts/ends a range",
73*45324Sbostic " ^ Up to row 0 of the current column.",
74*45324Sbostic " # Down to the last valid row of the current column.",
75*45324Sbostic " 0 Back to column A. Preface with ^U if numeric mode.",
76*45324Sbostic " $ Forward to the last valid column of the current row.",
77*45324Sbostic " b Back then up to the previous valid cell.",
78*45324Sbostic " w Forward then down to the next valid cell.",
79*45324Sbostic " g Go to a cell. Cell name, range name, quoted string,",
80*45324Sbostic " or a number specify which cell.",
81*45324Sbostic (char *)0
82*45324Sbostic };
83*45324Sbostic
84*45324Sbostic
85*45324Sbostic char *cell[] = {
86*45324Sbostic " ",
87*45324Sbostic " D: Cell entry and editing commands:",
88*45324Sbostic " ",
89*45324Sbostic " = Enter a numeric constant or expression.",
90*45324Sbostic " < Enter a left justified string or string expression.",
91*45324Sbostic " \",> Enter a right justified string or string expression.",
92*45324Sbostic " e Edit the current cell's numeric value.",
93*45324Sbostic " E Edit the current cell's string part.",
94*45324Sbostic " x Clear the current cell.",
95*45324Sbostic " c Copy the last marked cell to the current cell.",
96*45324Sbostic " m Mark a cell to be used as the source for ``c''",
97*45324Sbostic " + Increment numeric part",
98*45324Sbostic " - Decrement numeric part",
99*45324Sbostic " ",
100*45324Sbostic " In numeric mode, a decimal digit, ``+'', ``-'', and ``.'' all start",
101*45324Sbostic " a new numeric constant or expression.",
102*45324Sbostic (char *)0
103*45324Sbostic };
104*45324Sbostic
105*45324Sbostic
106*45324Sbostic char *vi[] = {
107*45324Sbostic " ",
108*45324Sbostic " E: Line Editor",
109*45324Sbostic " ",
110*45324Sbostic " Hitting the ESC key while entering any command on the top line",
111*45324Sbostic " will start a one-line vi-style editor. Supported commands:",
112*45324Sbostic " ",
113*45324Sbostic " ESC q Abort command entry.",
114*45324Sbostic " h l Move cursor forward, backward.",
115*45324Sbostic " 0 $ Move cursor to the beginning, end of the line.",
116*45324Sbostic " b w Move cursor forward/back one word.",
117*45324Sbostic " fc Move cursor to character c.",
118*45324Sbostic " tc Move the cursor the the character before c.",
119*45324Sbostic " i a Enter insert mode before/after the cursor.",
120*45324Sbostic " I Move to cursor column 0 and enter insert mode.",
121*45324Sbostic " x X Delete the character under/before the cursor.",
122*45324Sbostic " rc Replace the character under the cursor with c.",
123*45324Sbostic " cm Change - m = b,f,h,l,t or w.",
124*45324Sbostic " dm Delete - m = b,f,h,l,t or w.",
125*45324Sbostic " R Enter replace (overstrike) mode.",
126*45324Sbostic " + j - k / Forward/backward/search the command history.",
127*45324Sbostic " n Repeat last history search.",
128*45324Sbostic " . u Repeat/undo the last command.",
129*45324Sbostic (char *)0
130*45324Sbostic };
131*45324Sbostic
132*45324Sbostic char *file[] = {
133*45324Sbostic " ",
134*45324Sbostic " F: File commands:",
135*45324Sbostic " ",
136*45324Sbostic " G Get a new database from a file. ",
137*45324Sbostic " M Merge a new file into the current database.",
138*45324Sbostic " P Put the current database into a file.",
139*45324Sbostic " W Write a listing of the current database into a file in",
140*45324Sbostic " a form that matches its appearance on the screen.",
141*45324Sbostic " T Write a listing of the current database to a file, but",
142*45324Sbostic " put delimiters between each pair of fields.",
143*45324Sbostic " Optionally brackets output with control lines for ``tbl'',",
144*45324Sbostic " ``LaTeX'', or ``TeX''.",
145*45324Sbostic " ",
146*45324Sbostic " If encryption mode is set, file I/O will be encrypted/decrypted.",
147*45324Sbostic " ``\"| program\"'' for a file name will pipe (unencrypted) output to",
148*45324Sbostic " a program for Put, Write and Table. If a cell name is used",
149*45324Sbostic " as the file name, the cell's string part will be used as the",
150*45324Sbostic " file name.",
151*45324Sbostic (char *)0
152*45324Sbostic };
153*45324Sbostic
154*45324Sbostic
155*45324Sbostic char *row[] = {
156*45324Sbostic " ",
157*45324Sbostic " G: Row and column commands:",
158*45324Sbostic " ",
159*45324Sbostic " ir, ic Insert a new, empty row (column)",
160*45324Sbostic " ar, ac Append a new copy of the current row (column)",
161*45324Sbostic " dr, dc Delete the current row (column)",
162*45324Sbostic " pr, pc, pm Pull deleted cells back into the spreadsheet",
163*45324Sbostic " Insert rows, columns or merge the cells.",
164*45324Sbostic " vr, vc Remove expressions from the affected rows (columns),",
165*45324Sbostic " leaving only the values.",
166*45324Sbostic " zr, zc Hide (``zap'') the current row (column)",
167*45324Sbostic " sr, sc Show hidden rows (columns)",
168*45324Sbostic " f Set the output format to be used with the values of",
169*45324Sbostic " each cell in this column. Enter field width and",
170*45324Sbostic " number of fractional digits. A preceding count can be",
171*45324Sbostic " used to change more than one column.",
172*45324Sbostic " ",
173*45324Sbostic " Commands which move or copy cells also modify the row and column ",
174*45324Sbostic " references in the new cell expressions. Use ``fixed'' or the",
175*45324Sbostic " ``$'' style cell reference to supress the change.",
176*45324Sbostic (char *)0
177*45324Sbostic };
178*45324Sbostic
179*45324Sbostic
180*45324Sbostic char *range[] = {
181*45324Sbostic " ",
182*45324Sbostic " H: Range commands:",
183*45324Sbostic " ",
184*45324Sbostic " /x Clear a range. ",
185*45324Sbostic " /v Remove the expressions from a range of cells, leaving ",
186*45324Sbostic " just the values.",
187*45324Sbostic " /c Copy a source range to a destination range.",
188*45324Sbostic " /f Fill a range with constant values starting with a given",
189*45324Sbostic " value and increasing by a given increment.",
190*45324Sbostic " /d Assign a name to a cell or a range of cells. Give the",
191*45324Sbostic " the name, surrounded by quotes, and either a cell name such",
192*45324Sbostic " as ``A10'' or a range such as ``a1:b20''.",
193*45324Sbostic " /s Shows the currently defined range names. Pipe output to",
194*45324Sbostic " sort, then to less.",
195*45324Sbostic " /u Use this command to undefine a previously defined range",
196*45324Sbostic " name.",
197*45324Sbostic " ",
198*45324Sbostic " Range operations affect a rectangular region on the screen",
199*45324Sbostic " defined by the upper left and lower right cells in the region.",
200*45324Sbostic " A range is specified by giving the cell names separated by ``:'',",
201*45324Sbostic " such as ``a20:k52''. Another way to refer to a range is to use",
202*45324Sbostic " a name previously defined using ``/d''.",
203*45324Sbostic (char *)0
204*45324Sbostic };
205*45324Sbostic
206*45324Sbostic
207*45324Sbostic char *misc[] = {
208*45324Sbostic " ",
209*45324Sbostic " I: Miscellaneous commands:",
210*45324Sbostic " ",
211*45324Sbostic " Q q ^C Exit from the program.",
212*45324Sbostic " ^G ESC Abort entry of the current command.",
213*45324Sbostic " ? Help",
214*45324Sbostic " ! Shell escape. Enter a command to run. ``!!'' repeats",
215*45324Sbostic " the last command. Just ``!'' starts an interactive shell.",
216*45324Sbostic " ^L Redraw the screen.",
217*45324Sbostic " ^R Redraw the screen. Highlight cells with values but no",
218*45324Sbostic " expressions.",
219*45324Sbostic " ^X Redraw the screen. Show formulas, not values.",
220*45324Sbostic " @ Recalculate the spreadsheet.",
221*45324Sbostic " ^V Type, in the command line, the name of the current cell.",
222*45324Sbostic " ^W Type, in the command line, the current cell's expression.",
223*45324Sbostic " ^A Type, in the command line, the current cell's numeric value.",
224*45324Sbostic " TAB When the character cursor is on the top line TAB can be used",
225*45324Sbostic " to start or stop the display of the default range.",
226*45324Sbostic (char *)0
227*45324Sbostic };
228*45324Sbostic
229*45324Sbostic char *var[] = {
230*45324Sbostic " ",
231*45324Sbostic " J: Variable names:",
232*45324Sbostic " ",
233*45324Sbostic " K20 Row and column can vary on copies.",
234*45324Sbostic " $K$20 Row and column stay fixed on copies.",
235*45324Sbostic " $K20 Row can vary; column stays fixed on copies.",
236*45324Sbostic " K$20 Row stays fixed; column can vary on copies.",
237*45324Sbostic " fixed holds following expession fixed on copies.",
238*45324Sbostic " Cells and ranges can be given a symbolic name via ``/d''.",
239*45324Sbostic " ",
240*45324Sbostic " Expressions:",
241*45324Sbostic " -e Negation e<=e Less than or equal",
242*45324Sbostic " e+e Addition e=e Equal",
243*45324Sbostic " e-e Subtraction e!=e Not Equal",
244*45324Sbostic " e*e Multiplication e>=e Greater than or equal",
245*45324Sbostic " e/e Division e>e Greater than",
246*45324Sbostic " e%e Modulo e<e Less than",
247*45324Sbostic " e^e Exponentiation e&e Boolean operator AND.",
248*45324Sbostic " ~e Boolean operator NOT e|e Boolean operator OR",
249*45324Sbostic " e?e1:e2 or @if(e,e1,e2)",
250*45324Sbostic " Conditional: If e is non zero then then e1, else e2.",
251*45324Sbostic " Terms may be constants, variables, and parenthesized expressions.",
252*45324Sbostic (char *)0
253*45324Sbostic };
254*45324Sbostic
255*45324Sbostic char *rangef[] = {
256*45324Sbostic " ",
257*45324Sbostic " K: Range functions:",
258*45324Sbostic " ",
259*45324Sbostic " @sum(r) Sum all valid cells in the range.",
260*45324Sbostic " @prod(r) Multiply together all valid cells in the range.",
261*45324Sbostic " @avg(r) Average all valid cells in the range.",
262*45324Sbostic " @count(r) Count all valid cells in the range.",
263*45324Sbostic " @max(r) Return the maximum value in the range.",
264*45324Sbostic " @min(r) Return the minimum value in the range.",
265*45324Sbostic " @stddev(r) Return the sample standard deviation of ",
266*45324Sbostic " the cells in the range.",
267*45324Sbostic " @index(e,r) @stindex(e,r)",
268*45324Sbostic " Return the numeric (string) value of the cell at",
269*45324Sbostic " index e into range r.",
270*45324Sbostic " @lookup(e,r) @hlookup(e,r,n) @vlookup(e,r,n)",
271*45324Sbostic " Search through the range r for a value that",
272*45324Sbostic " matches e. If e is numeric, the last value <= e",
273*45324Sbostic " matches; if string, an exact match is required.",
274*45324Sbostic " @lookup searches a single row (column) and returns",
275*45324Sbostic " the value from the next column (row); @hlookup",
276*45324Sbostic " (@vlookup) searches the first row (column) in r and",
277*45324Sbostic " returns the value n columns (rows) from the match.",
278*45324Sbostic (char *)0
279*45324Sbostic };
280*45324Sbostic
281*45324Sbostic char *numericf[] = {
282*45324Sbostic " ",
283*45324Sbostic " L: Numeric functions:",
284*45324Sbostic " ",
285*45324Sbostic " @atan2(e1,e2) Arc tangent of e1/e2.",
286*45324Sbostic " @ceil(e) Smallest integer not less than e.",
287*45324Sbostic " @eqs(se1,se2) 1 if string expr se1 has the same value as se2.",
288*45324Sbostic " @exp(e) Exponential function of e.",
289*45324Sbostic " @abs(e) @fabs(e) Absolute value of e.",
290*45324Sbostic " @floor(e) The largest integer not greater than e.",
291*45324Sbostic " @hypot(x,y) Sqrt(x*x+y*y).",
292*45324Sbostic " @max(e1,e2,...) The maximum of the values of the e's.",
293*45324Sbostic " @min(e1,e2,...) The minimum of the values of the e's",
294*45324Sbostic " @nval(se,e) The numeric value of a named cell.",
295*45324Sbostic " pi A constant quite close to pi.",
296*45324Sbostic " @pow(e1,e2) e1 raised to the power of e2.",
297*45324Sbostic " @rnd(e) Round e to the nearest integer.",
298*45324Sbostic " @round(e,n) Round e to n decimal places.",
299*45324Sbostic " @sqrt(e) Square root of e.",
300*45324Sbostic " @ston(se) Convert string expr se to a numeric",
301*45324Sbostic " @ln(e) @log(e) Natural/base 10 logarithm of e.",
302*45324Sbostic " @dtr(e) @rtd(e) Convert degrees to/from radians.",
303*45324Sbostic " @cos(e) @sin(e) @tan(e) Trig functions of radian arguments.",
304*45324Sbostic " @asin(e) @acos(e) @atan(e) Inverse trig function.",
305*45324Sbostic (char *)0
306*45324Sbostic };
307*45324Sbostic
308*45324Sbostic char *stringf[] = {
309*45324Sbostic " ",
310*45324Sbostic " M: String functions:",
311*45324Sbostic " ",
312*45324Sbostic " # Concatenate strings. For example, the",
313*45324Sbostic " string expression ``A0 # \"zy dog\"'' yields",
314*45324Sbostic " ``the lazy dog'' if A0 is ``the la''.",
315*45324Sbostic " @substr(se,e1,e2) Extract characters e1 through e2 from the",
316*45324Sbostic " string expression se. For example,",
317*45324Sbostic " ``@substr(\"Nice jacket\" 4, 7)'' yields ",
318*45324Sbostic " ``e jac''.",
319*45324Sbostic " @fmt(se,e) Convert a number to a string using sprintf(3).",
320*45324Sbostic " For example, ``@fmt(\"*%6.3f*\",10.5)'' yields",
321*45324Sbostic " ``*10.500*''. Use formats are e, E, f, g, and G.",
322*45324Sbostic " @sval(se,e) Return the string value of a cell selected by name.",
323*45324Sbostic " @ext(se,e) Call an external function (program or",
324*45324Sbostic " script). Convert e to a string and append it",
325*45324Sbostic " to the command line as an argument. @ext yields",
326*45324Sbostic " a string: the first line printed to standard",
327*45324Sbostic " output by the command.",
328*45324Sbostic " String expressions are made up of constant strings (characters",
329*45324Sbostic " surrounded by quotes), variables, and string functions.",
330*45324Sbostic (char *)0
331*45324Sbostic };
332*45324Sbostic
333*45324Sbostic
334*45324Sbostic char *finf[] = {
335*45324Sbostic " ",
336*45324Sbostic " N: Financial functions:",
337*45324Sbostic " ",
338*45324Sbostic " @pmt(e1,e2,e3) @pmt(60000,.01,360) computes the monthly",
339*45324Sbostic " payments for a $60000 mortgage at 12%",
340*45324Sbostic " annual interest (.01 per month) for 30",
341*45324Sbostic " years (360 months).",
342*45324Sbostic " ",
343*45324Sbostic " @fv(e1,e2,e3) @fv(100,.005,36) computes the future value",
344*45324Sbostic " of 36 monthly payments of $100 at 6%",
345*45324Sbostic " interest (.005 per month). It answers the",
346*45324Sbostic " question: ``How much will I have in 36",
347*45324Sbostic " months if I deposit $100 per month in a",
348*45324Sbostic " savings account paying 6% interest com-",
349*45324Sbostic " pounded monthly?''",
350*45324Sbostic " ",
351*45324Sbostic " @pv(e1,e2,e3) @pv(1000,.015,36) computes the present",
352*45324Sbostic " value of an ordinary annuity of 36",
353*45324Sbostic " monthly payments of $1000 at 18% annual",
354*45324Sbostic " interest. It answers the question: ``How",
355*45324Sbostic " much can I borrow at 18% for 30 years if I",
356*45324Sbostic " pay $1000 per month?''",
357*45324Sbostic (char *)0
358*45324Sbostic };
359*45324Sbostic
360*45324Sbostic
361*45324Sbostic char *timef[] = {
362*45324Sbostic " ",
363*45324Sbostic " O: Time and date functions:",
364*45324Sbostic " ",
365*45324Sbostic " @now Return the time encoded in seconds since 1970.",
366*45324Sbostic " @dts(m,d,y) Return m/d/y encoded in seconds since 1970.",
367*45324Sbostic " @tts(h,m,s) Return h:m:s encoded in seconds since midnight.",
368*45324Sbostic " ",
369*45324Sbostic " All of the following take an argument expressed in seconds:",
370*45324Sbostic " ",
371*45324Sbostic " @date(e) Convert the time in seconds to a date",
372*45324Sbostic " string 24 characters long in the following",
373*45324Sbostic " form: ``Sun Sep 16 01:03:52 1973''. Note",
374*45324Sbostic " that you can extract pieces of this fixed format",
375*45324Sbostic " string with @substr.",
376*45324Sbostic " @year(e) Return the year. Valid years begin with 1970.",
377*45324Sbostic " @month(e) Return the month: 1 (Jan) to 12 (Dec).",
378*45324Sbostic " @day(e) Return the day of the month: 1 to 31.",
379*45324Sbostic " @hour(e) Return the number of hours since midnight: 0 to 23.",
380*45324Sbostic " @minute(e) Return the number of minutes since the",
381*45324Sbostic " last full hour: 0 to 59.",
382*45324Sbostic " @second(e) Return the number of seconds since the",
383*45324Sbostic " last full minute: 0 to 59.",
384*45324Sbostic (char *)0
385*45324Sbostic };
386*45324Sbostic void
help()387*45324Sbostic help()
388*45324Sbostic {
389*45324Sbostic int option;
390*45324Sbostic char **ns = intro;
391*45324Sbostic
392*45324Sbostic while((option = pscreen(ns)) != 'q' && option != 'Q') {
393*45324Sbostic switch (option) {
394*45324Sbostic case 'a': case 'A': ns = intro; break;
395*45324Sbostic case 'b': case 'B': ns = options; break;
396*45324Sbostic case 'c': case 'C': ns = cursor; break;
397*45324Sbostic case 'd': case 'D': ns = cell; break;
398*45324Sbostic case 'e': case 'E': ns = vi; break;
399*45324Sbostic case 'f': case 'F': ns = file; break;
400*45324Sbostic case 'g': case 'G': ns = row; break;
401*45324Sbostic case 'h': case 'H': ns = range; break;
402*45324Sbostic case 'i': case 'I': ns = misc; break;
403*45324Sbostic case 'j': case 'J': ns = var; break;
404*45324Sbostic case 'k': case 'K': ns = rangef; break;
405*45324Sbostic case 'l': case 'L': ns = numericf; break;
406*45324Sbostic case 'm': case 'M': ns = stringf; break;
407*45324Sbostic case 'n': case 'N': ns = finf; break;
408*45324Sbostic case 'o': case 'O': ns = timef; break;
409*45324Sbostic default: ns = intro; break;
410*45324Sbostic }
411*45324Sbostic }
412*45324Sbostic FullUpdate++;
413*45324Sbostic (void) move(1,0);
414*45324Sbostic (void) clrtobot();
415*45324Sbostic }
416*45324Sbostic
pscreen(screen)417*45324Sbostic pscreen(screen)
418*45324Sbostic char *screen[];
419*45324Sbostic {
420*45324Sbostic int line;
421*45324Sbostic int dbline;
422*45324Sbostic
423*45324Sbostic (void) move(1,0);
424*45324Sbostic (void) clrtobot();
425*45324Sbostic dbline = 1;
426*45324Sbostic for (line = 0; screen[line]; line++) {
427*45324Sbostic (void) move(dbline++, 4);
428*45324Sbostic (void) addstr (screen[line]);
429*45324Sbostic (void) clrtoeol();
430*45324Sbostic }
431*45324Sbostic (void) move(0,0);
432*45324Sbostic (void) printw("Which Screen? [a-n, q]");
433*45324Sbostic (void) clrtoeol();
434*45324Sbostic (void) refresh();
435*45324Sbostic return(nmgetch());
436*45324Sbostic }
437