Reorganized the code a bit.
[rpn.git] / src / console / help.c
blob824e4d3777e9a43735a3e91d3a3217d6db53b50c
1 /*******************************************************************************
2 * Reverse Polish Notation calculator. *
3 * Copyright (c) 2007-2008, Samuel Fredrickson <kinghajj@gmail.com> *
4 * All rights reserved. *
5 * *
6 * Redistribution and use in source and binary forms, with or without *
7 * modification, are permitted provided that the following conditions are met: *
8 * * Redistributions of source code must retain the above copyright *
9 * notice, this list of conditions and the following disclaimer. *
10 * * Redistributions in binary form must reproduce the above copyright *
11 * notice, this list of conditions and the following disclaimer in the *
12 * documentation and/or other materials provided with the distribution. *
13 * *
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER ``AS IS'' AND ANY EXPRESS *
15 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED *
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
17 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY *
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR *
20 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER *
21 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT *
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY *
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *
24 * DAMAGE. *
25 ******************************************************************************/
27 /*******************************************************************************
28 * help.c - a simple help system for the front-end. this is very loose from *
29 * the rest of the program; you could easily take this and use it yourself. *
30 ******************************************************************************/
32 #include "rpn.h"
33 #include <stdio.h>
34 #include <stdlib.h>
36 /*******************************************************************************
37 * Help-related variables and functions.
38 ******************************************************************************/
40 #ifndef DOXYGEN_SKIP
42 /* These are the various classes of CommandHelpItems.
44 static RPNCommandHelpItem options_help[] =
46 {"-v or --version", "Display version."},
47 {NULL},
50 static RPNCommandHelpItem operators_help[] = {
51 {"+, -, *, /, **, sqrt, =", "Normal math operators."},
52 {"%, ^, &, |", "Modulo and bitwise operators."},
53 {NULL},
56 static RPNCommandHelpItem commands_help[] = {
57 {"dup", "Pushes topmost value to the stack."},
58 {"pop", "Removes the topmost value of the stack."},
59 {"ph", "Prints the history stack."},
60 {"phd", "Prints the history stack in detail."},
61 {"ps", "Prints the stack."},
62 {"psd", "Prints the stack in detail."},
63 {"pv", "Prints the variable table."},
64 {"pvd", "Prints the variable table in detail."},
65 {"x", "Exits the program."},
66 {NULL},
69 /* This prints an array of CommandHelpItems, like those found just above.
71 static void printCommandHelpItemArray(char *title, RPNCommandHelpItem *items)
73 RPNCommandHelpItem item;
74 int i;
76 printf("%s:\n", title);
78 // print every help item.
79 for(i = 0, item = items[i]; item.command; i++, item = items[i])
80 RPN_printf("\t%s\n\t\t%s\n", item.command, item.help);
83 static void printOptionsHelp()
85 printCommandHelpItemArray("Options", options_help);
88 static void printOperatorsHelp()
90 printCommandHelpItemArray("Operators", operators_help);
93 static void printCommandsHelp()
95 printCommandHelpItemArray("Commands", commands_help);
98 void RPN_printHelp()
100 RPN_printf("rpn v. %i.%i.%i.%i -- a Reverse Polish Notation calculator\n",
101 __RPN_MAJOR__,
102 __RPN_MINOR__,
103 __RPN_REVIS__,
104 __RPN_BUILD__);
105 RPN_printf("By Sam Fredrickson <kinghajj@gmail.com>\n\n");
107 printOptionsHelp();
108 printOperatorsHelp();
109 printCommandsHelp();
112 #endif // DOXYGEN_SKIP