summaryrefslogtreecommitdiff
path: root/systems/msdos/tx/src/txmain.c
blob: 53d53e29bcae79f39309f063fe5270b1ec58dd4e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include "tx.h" 
#include <process.h>

extern int ExpandAction(char *, char **, char *, int) ; 
extern void UserPrompt(char *, void *, int) ; 
extern int PrintTextMenu(int) ; 
extern void TxDir(void) ; 

 
void TxMain(void) 
{ 
  int Choice,CurrentMenu = 0 ;     /* Start at main menu */ 
  char Action[MAX_ACTION] ,        /* Command to execute */ 
       *Arguments[MAX_ARGS] ,      /* Pointers to arguments to command */
       *pMenu ;                    /* Pointer to menu commands */ 
 
  do { 
    Choice = PrintTextMenu(CurrentMenu) ; 
 
    if ( Choice == -1 ) {             /* Default */ 
      if (!CurrentMenu)              /* if in main menu */ 
	exit(0) ;                   /* exit program */ 
      CurrentMenu = 0 ;              /* otherwise, go back to main menu */ 
      continue ; 
    } 
    
    pMenu = *(menu[CurrentMenu]+(2*Choice+1)) ; /* point to menu command */ 
    
    if (*pMenu != SUBST_SIGN ) {    /* User-defined action */ 
      if ( ExpandAction(Action,Arguments,pMenu,(MAX_ACTION-14)) ) 
	spawnvp(P_WAIT,Action,Arguments) ; 
      continue ; 
    } 
    
    ++pMenu ; /* Increment pointer if SUBST_SIGN in first position */ 
    
    if ( !strnicmp(pMenu,SWITCH_MENUS,L_SWITCH_MENUS) ) { /* change menu */ 
      CurrentMenu = atoi(pMenu+L_SWITCH_MENUS) ; 
      if ( ( CurrentMenu < 0) || (CurrentMenu > NumMenus) ) 
	CurrentMenu = 0 ;  /* switch to main menu if error */ 
    } 
    else if ( !strnicmp(pMenu,DOS_COMMAND,L_DOS_COMMAND) ) { /* DOS command */ 
      UserPrompt(MSG_DOSCOM,Action,80) ; 
      system(Action) ; 
    } 
    else if ( !strnicmp(pMenu,FIND_NAME,L_FIND_NAME) ) { /* select wf */ 
      TxDir() ; 
    } 
    else if ( !strnicmp(pMenu,NEW_NAME,L_NEW_NAME) ) { /* enter new wfname */ 
      int OldDrive=CurrDrive;
      char OldPath[MAXPATH];
      strcpy(OldPath,Path); 
      UserPrompt(MSG_NEW_FILE,Path,80) ; 
      SplitPath() ;
      setdisk(CurrDrive) ;
      if ( chdir(Path) ) {
	CurrDrive=OldDrive;
	setdisk(CurrDrive); 
	strcpy(Path,OldPath); 
      } 
    } 
    else if ( !strnicmp(pMenu,END_PROG,L_END_PROG) ) /* end program */ 
      exit(0) ;  /* Regular way of exiting the program */ 
    else { /* Command name begins with a SUBST_SIGN sign (!) */ 
      --pMenu ; /* reset pointer */ 
      if ( ExpandAction(Action,Arguments,pMenu,(MAX_ACTION-14)) ) 
	spawnvp(P_WAIT,Action,Arguments) ; 
    } 
  } 
  while (1) ; 
  
}