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