micromicros/pc/settings/MM_SETUP.BAS
2024-09-28 18:17:05 -05:00

139 lines
3.2 KiB
QBasic

'$FORM frmMain
' $INCLUDE: 'MM_SETUP.BI'
DECLARE SUB comLine (n, a$(), max)
DECLARE SUB showHelp ()
DECLARE SUB startup ()
CONST magic$ = "KSFGILWZ"
' UI Colors.
SCREEN.ControlPanel(DESKTOP_BACKCOLOR) = 1
SCREEN.ControlPanel(DESKTOP_FORECOLOR) = 7
SCREEN.ControlPanel(DESKTOP_PATTERN) = 32
' *** DEBUGGING ***
dialogOpen "Setup", "Loading Settings"
loadSettings
dialogClose
frmMain.Tag = magic$
frmMain.SHOW
'startup
STATIC SUB comLine (NumArgs AS INTEGER, Args$(), MaxArgs AS INTEGER)
DIM in
DIM cl$
DIM l
DIM I
DIM c$
NumArgs = 0: in = FALSE
' Get the command line using the COMMAND$ function
cl$ = COMMAND$
l = LEN(cl$)
' Go through the command line a character at a time
FOR I = 1 TO l
c$ = MID$(cl$, I, 1)
' Test for character being a blank or a tab
IF (c$ <> " " AND c$ <> CHR$(9)) THEN
' Neither blank nor tab; test if you're already inside
' an argument
IF NOT in THEN
' You've found the start of a new argument
' Test for too many arguments
IF NumArgs = MaxArgs THEN EXIT FOR
NumArgs = NumArgs + 1
in = TRUE
END IF
' Add the character to the current argument
Args$(NumArgs) = Args$(NumArgs) + c$
ELSE
' Found a blank or a tab.
' Set "Not in an argument" flag to FALSE
in = FALSE
END IF
NEXT I
END SUB
STATIC SUB showHelp ()
PRINT "This isn't helpful yet."
END SUB
SUB startup ()
'
' Read command line options from passed argument ("\ksfgilwz.$$$").
'
' After arguments are read, delete this file. If it re-appears, read
' data from Linux out of it and delete it again.
'
' For us to send data to Linux, write it to the first argument but change
' the extension to !!! ("\ksfgilwz.!!!"). Linux will delete it when it
' has been processed.
'
' If we need to execute DOS commands, write them to the second argument
' ("\ksfgilwz.bat") and exit this program.
'
DIM p$(1 TO 10)
DIM a$(1 TO 10)
DIM c$
DIM n
DIM f
' Parse command line.
CALL comLine(n, a$(), 10)
' Did we get exactly two arguments?
IF (n <> 1) OR (a$(1) <> magic$) THEN
PRINT "Do not run MM_SETUP directly. Use SETTINGS instead."
END
END IF
' Load the actual command line arguments from a file to preserve case.
n = 0
ON LOCAL ERROR RESUME NEXT
f = FREEFILE
OPEN "C:\" + magic$ + ".$$$" FOR INPUT AS f
IF ERR = 0 THEN
DO WHILE NOT EOF(f)
n = n + 1
LINE INPUT #f, p$(n)
LOOP
CLOSE f
END IF
ERR = 0
ON LOCAL ERROR GOTO 0
' Did they send us any arguments? If not, go GUI!
IF (n = 0) THEN
frmMain.Tag = magic$
frmMain.SHOW
ELSE
' Process command line arguments.
c$ = RTRIM$(LTRIM$(UCASE$(p$(1))))
SELECT CASE c$
CASE "?", "/?", "HELP", "/HELP"
showHelp
CASE ELSE
PRINT "Unknown option "; CHR$(34); c$; CHR$(34); "."
PRINT "Use "; CHR$(34); "SETTINGS HELP"; CHR$(34); " for help."
END 1
END SELECT
END IF
END SUB