GCC or similar ANSI/ISO-C compiler
Some knowledge of programming, though not much is necessary for the purpose of creating the program with the sample input.
Hello everyone! This is a tutorial for the Menu Maker for C, a program that makes creating a command-line interface menu ridiculously easy by writing 99% of the source for you! Continue reading for a detailed explanation, or skip to the bottom for quick steps to run it.
Start by downloading the file from SX Labs, and expand to find "menumaker.c". If you open the file with an editor, you'll notice the following file-format-scheme listed at the top:
This is the format used for input to the Menu Maker. For this tutorial, we will be using my example input file. You can download it below. Here is that file along with some comments, which unfortunately you cannot use for input as the comments would become part of the input:
A few notes on the input:
You can run the application from the command-line and type in each line of input, or you can just pipe the input file through stdin: ./menumaker <sampleinput.txt
which is much easier and faster. It's also easily reproducible since the input is saved in a file.
The values used for the Option Types are defined near the top of the program. You are welcome to change these values to suit yourself. These need only be modified at their definitions (That's what macros are for). The source produced by the program will use the values defined there as well.
You are responsible for the quality of input you provide. This program has just about no filtering for poorly designed input. This program was written for use by programmers, and as such requires some level of understanding. For instance, semicolons do not belong anywhere in the input. Spaces in titles and menu/function names are the only characters removed. This is because the menu titles are used not only when printing the menu but also for the menus' variable names! Be responsible for your input.
As just stated, a menu's title becomes it's variable name but with only spaces removed. This means that when calling another menu through an option, you must use the name exactly as declared (by your input) except for spaces which if there will be removed by the program before use.
Function names can be anything you would normally call a function (Must begin with a letter; can have letters, numbers, and underscores). They do not have to match the titles for their respective option in any way. I have matched them only for clarity.
Did you get all that? Good. Now here are the steps to get the program working with the sample input file:
Step 1 - Download the source
Download the Menu Maker for C source from SX Labs and expand it.
Step 2 - Download the sample input
Download the sample input file "sampleinput.txt" below and place it in the same folder as "menumaker.c".
Step 3 - Compile the Menu Maker
Using Terminal, navigate to the directory where you have put the two above files, then enter the following:
gcc -o menumaker menumaker.c
The source should compile without any errors or warnings.
Step 4 - Generate the Menu program with sample input
Still in Terminal in our working directory, enter the following to generate the menu code using the sample input file:
./menumaker <sampleinput.txt
Now get a directory listing (ls) and look at all your new source files!
Step 5 - Fill in the blanks
Launch a text editor (I often use nano) and open "mymenu.c". A few lines down from the top you'll notice some function definitions, but they are missing code! This is the only bit of coding needed in order to get the menus working properly (The program will still compile and run, but the functions won't do anything until filled in, doy). For this sample, the following code will suffice to demonstrate:
printf( "Running Function 1\n" );
Add that line into each Function, changing "1" to whichever Function it is, and here is the code for "Quit":
exit(0)
Step 6 - Compile the Menu program
gcc -o mymenu mymenu.c
The source should compile without any errors or warnings. Possible problems could occur if the original input used was not sound (mismatched names, incorrect option-type values, etc), and of course any problems within the formerly-blank functions will show up.
Step 7 - Run it!
./mymenu
And have fun playing with your new menu application!
Step 8 - Read the source!
Last, but certainly not least, open the source with an editor and read it! Not necessarily the "menumaker.c", but all the source that is generated. I have intentionally designed the code to be organized, easy to understand, and easy to modify. And fuck it, read the "menumaker.c" source too. I don't think any of this is very complicated, but then again no well-organized program should be.
Enjoy =)