/*
Runprog.c: Uses the Ungetch() function to run another program.

Compiler: BC++ 3.1,
          Turbo C++ 1.01(3.01) (free from http://cc.codegear.com/free/cpp)
          MSC 6.0,
          MSVC 1.52.

Compile mode: Large

Project: Runprog.c
         ..\..\Lib\(8000e.Lib, 7188el.Lib or 7186el.Lib)

Hardware: i-7188/uPAC-7186/i-8000

Detail description:
    User can use menu to select to execute program or dos command,
    then they will come back the menu after finishing program.

    To test the program
    Step1. download the Hello.exe, name.exe, and Runprog.exe to the controller.

    Step2. type Runprog.exe to run demo program. (you can see menu message)

    Step3. press 1 ~ 3 key to exeute items.

    Step4. After finishing items, program will come back the menu.
           (only include: hello and Modeule name).

[Oct 30, 2008] by Liam
*/

#include "..\..\LIB\7186e.h"

void Run(char *cmd)
{
    while(*cmd)
    {
        Ungetch(*cmd++);
    }
    
    Ungetch('\r');
}

void main(void)
{
    InitLib();
    
    Print("Select a program to run...\r\n");
    Print("1:Hello.EXE\r\n");
    Print("2:Module name\r\n");
    Print("3:dir\n\r");
    Print("others:quit\r\n");
    
    switch(Getch())
    {
        case '1':
            Run("Hello.exe");
            break;
            
        case '2':               
            Run("name.exe");
            break;
            
        case '3':
            Run("dir");
            break;
            
        default:
            Print("Do not select program to run.");
            break;
    }
}