• Please review our updated Terms and Rules here

Menu maker / batch file?

ajrossnz

Member
Joined
Dec 30, 2019
Messages
19
Location
Wellington, NZ
Hi all,

In Linux, this would be an easy task, but in DOS, not so simple for me (either because I may have forgotten how to do this sort of stuff, or because you can't do it with simple batch scripts).

I have a text file, 5 columns: column 1 has a unique ID number, column 2 has the name of a BBS I want to connect to, column 3 has the telnet hostname for the BBS, column 4 has the appropriate port number. I also have a fifth column with notes which isn't of much consequence, but could be displayed if needed.

The idea of the batch file is simple:
1) Display the contents of each line of the text file.
2) Ask for input for the user for the number of the unique ID related to the BBS I want to connect to
3) Execute mtelnet <hostname> <portnum>

I've looked at menu makers on google for a while as well, but couldn't find anything that would do what I need. If

Thanks in advance
 
I don't think you can do exactly that with a batch file, though others may correct me on this. I'd look to do it in basic with Quick Basic.
 
Not DOS batch, per se, but a good old add-on, called CENVID. Basically, interpreted C as a batch program. I used it a lot back in the day.

Here's an example, HEXDUMP.BAT:

Code:
@echo off
REM **********************************************************************
REM *** HexDump.bat - Hexidecimal dump of the contents of a file. This ***
REM ***               examples program uses the CEnvi file routines.   ***
REM **********************************************************************
cenvi %0.bat %1 %2
GOTO CENVI_EXIT

main(argc,argv)
{
   if ( 2 != argc ) {
      Instructions()
   } else if ( NULL == (fp = fopen(argv[1],"rb")) ) {
      printf("Could not open file \"%s\" for hex output.\a\n",argv[1])
   } else {
      dump(fp)
      fclose(fp)
   }
}

dump(file)
{
   Unprintables = "\a\b\t\r\n\032\033"
   for ( offset = 0; 0 < (count = fread(data,16,file)); offset += 16 ) {
      // display hex offset in file
      printf("%06X  ",offset)
      // display hex value for each number
      for ( i = 0; i < count; i++ )
         printf("%02X ",data[i])
      // fill in any extra gaps if count < 16
      while( i++ < 16 )
         printf("   ")
      // display ascii value for each printable character
      // substitute a period for unprintable characters
      data[count] = 0; // string must be null-terminated
      while( (UnprintableIndex = strcspn(data,Unprintables)) < count )
         data[UnprintableIndex] = '.';
      printf("   %s\n",data)
      if ( count < 16 )
         break
   }
}

:CENVI_EXIT
 
Might be able to do it with DOS 6's CHOICE command. Something like

Code:
TYPE phonenum.txt
CHOICE /C:1234 "ENTER NUMBER TO CALL"
IF ERRORLEVEL 1 GOTO ONE

:ONE
metelnet <correct command line>
GOTO END

:END

Each command line would need to be set up manually with this example and additional ERRORLEVEL branches for each line in the text file would be needed.
 
Might be able to do it with DOS 6's CHOICE command. Something like

Code:
TYPE phonenum.txt
CHOICE /C:1234 "ENTER NUMBER TO CALL"
IF ERRORLEVEL 1 GOTO ONE

:ONE
metelnet <correct command line>
GOTO END

:END

Each command line would need to be set up manually with this example and additional ERRORLEVEL branches for each line in the text file would be needed.

This would not read and display the options from OP's text file and ask for a choice from the user. I am reasonably sure you could not do that in a batch file. So other tools would be needed, such as what Chuck suggests or writing it in a language of some sort (Basic, Pascal, C etc).
 
For number 1: why not simply TYPE the text file?

I think OP wants to use the text file as the menu items list and not re-create it in the batch file. So just typing it would display the contents, but then you'd have to build in a ton of if statements to accommodate the input Doing this could work, but it would double the work needed to add or remove anything.
 
The truly easy way would be if the program had its own macro language that accepted command line switches. Then one could
TYPE the data file
CHOICE the line to launch
PROGRAM launch-macro errorlevel from choice which would start the program using the matching line

Everything else would require some effort; either to build the conditional responses or to parse the data structure to create a command line.
 
The truly easy way would be if the program had its own macro language that accepted command line switches. Then one could
TYPE the data file
CHOICE the line to launch
PROGRAM launch-macro errorlevel from choice which would start the program using the matching line

Everything else would require some effort; either to build the conditional responses or to parse the data structure to create a command line.

How would this work is the data file contained more than 35 CHOICEs ?
 
Not quite sure what you want but the most basic 'menu' batchfile would be to TYPE the textfile. Then for each unique id, make a batch file with the name of the id.
 
Not quite sure what you want but the most basic 'menu' batchfile would be to TYPE the textfile. Then for each unique id, make a batch file with the name of the id.

There were some softwares that did this back in the day. Used the PROMPT command to change the prompt, then echo out some options and have a corresponding batch file for that option (eg 1.bat, 2.bat, 3.bat etc). It does work, and is a decent solution in some cases, but it really won't scale very well and maintenance would be a nightmare of the menu was even slightly dynamic or fast growing.
 
...it really won't scale very well and maintenance would be a nightmare of the menu was even slightly dynamic or fast growing.

I did say 'most basic'. It is a starting point. It isn't strictly 'A' batchfile as well. I once tried to program a maze game using only simple batch file commands in a lunch hour. It quickly became a nightmare:)

BTW the Simtel archive has loads of batch file helper programs and menu programs. Used to use these for all sorts of batch file madness. There also used to be a website that had some simple helper ASM programs you could compile with DEBUG from within a batchfile. I used to see how far I could make batch files go to being a proper programming language. Of cause it was tremendous slow compared to a C program but was fun.
 
Back
Top