Menu Maker for C

Prerequisites: 

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:

[# of menus]
{For each menu}[Title]
[# of options]
{For each option}[Title]
[Option Type]
[Menu/Function Name]
{End For each option}
{End For each menu}

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:

3  // Total # of menus
Main Menu  // First menu. This will be the "Main Menu" because it's the first listed, no matter what it's named.
4  // # of options for Main Menu
Go to Sub Menu 1  // First option, title
2  // Option Type. 2 == Menu
SubMenu1  // Name of Menu to launch for this option
Run Function 1  // 2nd option (Main Menu), title
1  // Option Type. 1 == Function
Function1  // Name of Function to call
Run Function 2  // 3rd option, Main Menu, title
1  // Type = Function
Function2  // Name of function to call.
Quit  // 4th option, Main Menu, Title
1  // Type = Function
Quit  // Function to call. This is the last piece of the last option for "Main Menu", so next line is a new menu
Sub Menu 1  // 2nd Menu.
4  // # of option for Sub Menu 1
Sub Menu 2  // First option, Sub Menu 1, title
2  // Type = Menu
Sub Menu 2 // Name of Menu to launch. Notice this name has spaces. The program will automatically remove spaces for variable names, so either works.
Run Function 3  // Second option, Sub Menu 1, title
1  // Type = Function
Function3  // Function to call
Return to Main Menu  // Third option, Sub Menu 1, title
2  // Type = Menu
Main Menu  // Menu to launch
Quit  // Fourth option, Sub Menu 1, title
1  // Type = Function
Quit  // Function to call
Sub Menu 2  // 3rd Menu
3  // # of options for Sub Menu 2
Run Function 4  // 1st option, Sub Menu 2, title
1  // Type = Function
Function4  // Function to call
Return to Sub Menu 1  // 2nd option, Sub Menu 2, title
2  // Type = Menu
Sub Menu 1  // Menu to launch
Quit  // 3rd option, Sub Menu 2, title
1  // Type = Function
Quit  // Function to call

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 =)