| 1 | // |
|---|
| 2 | // TxWin, Textmode Windowing Library |
|---|
| 3 | // |
|---|
| 4 | // Original code Copyright (c) 1995-2005 Fsys Software and Jan van Wijk |
|---|
| 5 | // |
|---|
| 6 | // ========================================================================== |
|---|
| 7 | // |
|---|
| 8 | // This file contains Original Code and/or Modifications of Original Code as |
|---|
| 9 | // defined in and that are subject to the GNU Lesser General Public License. |
|---|
| 10 | // You may not use this file except in compliance with the License. |
|---|
| 11 | // BY USING THIS FILE YOU AGREE TO ALL TERMS AND CONDITIONS OF THE LICENSE. |
|---|
| 12 | // A copy of the License is provided with the Original Code and Modifications, |
|---|
| 13 | // and is also available at http://www.dfsee.com/txwin/lgpl.htm |
|---|
| 14 | // |
|---|
| 15 | // This library is free software; you can redistribute it and/or modify |
|---|
| 16 | // it under the terms of the GNU Lesser General Public License as published |
|---|
| 17 | // by the Free Software Foundation; either version 2.1 of the License, |
|---|
| 18 | // or (at your option) any later version. |
|---|
| 19 | // |
|---|
| 20 | // This library is distributed in the hope that it will be useful, |
|---|
| 21 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 22 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|---|
| 23 | // See the GNU Lesser General Public License for more details. |
|---|
| 24 | // |
|---|
| 25 | // You should have received a copy of the GNU Lesser General Public License |
|---|
| 26 | // along with this library; (lgpl.htm) if not, write to the Free Software |
|---|
| 27 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 28 | // |
|---|
| 29 | // Questions on TxWin licensing can be directed to: txwin@fsys.nl |
|---|
| 30 | // |
|---|
| 31 | // ========================================================================== |
|---|
| 32 | // |
|---|
| 33 | // TX-library and TXWindowing test program |
|---|
| 34 | // |
|---|
| 35 | // Author: J. van Wijk |
|---|
| 36 | // |
|---|
| 37 | |
|---|
| 38 | #include <txlib.h> // TX library interface |
|---|
| 39 | |
|---|
| 40 | #include <fcntl.h> // low-level I/O |
|---|
| 41 | |
|---|
| 42 | #include <txtver.h> // TXT version info |
|---|
| 43 | #include <txtwin.h> // windowed entry point |
|---|
| 44 | #include <txt.h> // TXT navigation and defs |
|---|
| 45 | |
|---|
| 46 | #if defined (DUMP) |
|---|
| 47 | #define TXT_TRACE "TXTSTTRACE" // Trace startup values |
|---|
| 48 | #endif |
|---|
| 49 | |
|---|
| 50 | #define TXT_STARTCMD "say Hello to the TXT test program" |
|---|
| 51 | |
|---|
| 52 | |
|---|
| 53 | TXTINF txt_anchor = |
|---|
| 54 | { |
|---|
| 55 | FALSE, // batch-mode disabled |
|---|
| 56 | TRUE, // dialogs will be used |
|---|
| 57 | TXAO_NORMAL, // normal verbosity |
|---|
| 58 | TXAE_CONFIRM, // confirmed quit on errors |
|---|
| 59 | 0, // overall return-code |
|---|
| 60 | 80, 22, // visible screen area |
|---|
| 61 | FALSE, // auto quit on fdisk/setboot |
|---|
| 62 | TRUE, // reg confirm required |
|---|
| 63 | FALSE, // running in classic mode |
|---|
| 64 | NULL, // SB buffer |
|---|
| 65 | 0, // SB size |
|---|
| 66 | 0, // scroll-buffer window handle |
|---|
| 67 | 0, // command handling window |
|---|
| 68 | FALSE, // no automatic menu at start |
|---|
| 69 | TRUE, // automatic pulldown drop |
|---|
| 70 | 0, // default drop-down menu |
|---|
| 71 | 0, // worklevel |
|---|
| 72 | NULL, // selection list, Color schemes |
|---|
| 73 | #if defined (DOS32) |
|---|
| 74 | FALSE, // Windows-9x DosBox detected |
|---|
| 75 | #endif |
|---|
| 76 | }; |
|---|
| 77 | |
|---|
| 78 | TXTINF *txta = &txt_anchor; // TXT anchor block |
|---|
| 79 | |
|---|
| 80 | static char *separator; |
|---|
| 81 | |
|---|
| 82 | char *switchhelp[] = |
|---|
| 83 | { |
|---|
| 84 | " [global-txtst-switches] [TXTst-multi-command]", |
|---|
| 85 | "", |
|---|
| 86 | #if defined (DUMP) |
|---|
| 87 | " -123[t][s][n] = set trace level to 123, TXTst internal function trace;", |
|---|
| 88 | " [t]imestamp lines; trace to [s]creen too; [n]o tracefile", |
|---|
| 89 | #endif |
|---|
| 90 | "", |
|---|
| 91 | " -? = help on TXTst commandline switches (this text)", |
|---|
| 92 | " -7 = Use 7-bit ASCII only (no 'graphic' characters)", |
|---|
| 93 | " -a = switch off usage of ANSI escape characters for color", |
|---|
| 94 | " -b = batch option, automatic 'batch on' command at startup", |
|---|
| 95 | " -e or -e- = Include or surpress (-e-) command echo before each cmd", |
|---|
| 96 | " -E:[c|i|q] = default error strategy Confirm, Ignore or Quit", |
|---|
| 97 | " -f = frame, use a border-frame on scroll-buffer and desktop", |
|---|
| 98 | " -f- = do not use border-frames. (default NO on 80x25 screen)", |
|---|
| 99 | " -l:logfile = start logging immediately to 'logfile.log'", |
|---|
| 100 | " -menu = automatic menu at startup and after each menu-selection", |
|---|
| 101 | " -O:[n|v|q|m] = default output verbosity Normal, Verbose, Quiet, Maximum", |
|---|
| 102 | " -P- = don't use prompting and input dialog windows by default", |
|---|
| 103 | " -q = quiet option, automatic 'screen off' command at startup", |
|---|
| 104 | " -Q = quit automatically after executing specified command", |
|---|
| 105 | " -Q- = do NOT quit automatically on normally autoquiting commands", |
|---|
| 106 | " -r:regfile = registration filename with optional path and extension", |
|---|
| 107 | " -S = Shell mode, do not allow quit from TXTst (use as shell)", |
|---|
| 108 | " -s:separator = specify a command-separator character, default is '#'", |
|---|
| 109 | " -t or -t- = Include or surpress (-t-) timestamp before each command", |
|---|
| 110 | " -scheme:name = Window scheme: grey|3d|nobl|cmdr|half|full|white|black|dfsee", |
|---|
| 111 | " -color:value = Output colors, 0..7 add any: 0=std 1=invert 2=bright 4=blue", |
|---|
| 112 | " -style:value = Line style, 0..3: 0=std-double 1=3d 2=halfblock 3=fullblock", |
|---|
| 113 | " -w or -w+ = use windowing, even if command would surpress that", |
|---|
| 114 | " -w- = do NOT use windowing, default is -w+ (windowing)", |
|---|
| 115 | " -W:[sl] = Screen resize dialog if screen is more than [sl] lines", |
|---|
| 116 | #if defined (WIN32) |
|---|
| 117 | " -W:0 or -W = Screen resize dialog if scrollbars are present on window", |
|---|
| 118 | #else |
|---|
| 119 | " -W:0 or -W = Screen resize dialog if scrollbars are likely (lines > 40)", |
|---|
| 120 | #endif |
|---|
| 121 | "", |
|---|
| 122 | " For help on TXTst commands, use the '?' command and use the <F1>", |
|---|
| 123 | " key when shown at bottom line", |
|---|
| 124 | "", |
|---|
| 125 | NULL |
|---|
| 126 | }; |
|---|
| 127 | |
|---|
| 128 | |
|---|
| 129 | char *cmdhelptxt[] = |
|---|
| 130 | { |
|---|
| 131 | " ? [*] = Show list of generic commands with short description", |
|---|
| 132 | " alloc [size] = Allocate memory, default is in Mib, -k is Kib", |
|---|
| 133 | " boot [cold] = Reboot the system, warm or cold", |
|---|
| 134 | " cd [path] = Change current directory an current drive", |
|---|
| 135 | " conf [text] = Display confirmation dialog window with 'text'", |
|---|
| 136 | " cursor [col,row] = Show, and optionally set the cursor position", |
|---|
| 137 | " dlg = pop-up a test dialog from windowed mode", |
|---|
| 138 | " display = Show display size, rows and columns", |
|---|
| 139 | " help [*] = Show list of generic commands with short description", |
|---|
| 140 | " log [file] = Log (append) to 'file' (.log); (No file => stop logging)", |
|---|
| 141 | " lines [number] = Write lines of text, for display performance tests", |
|---|
| 142 | " listbox = Start listbox test dialog window", |
|---|
| 143 | " mode [x,y] [-w-] = Set screen size and windowing mode, -w- is non-windowed", |
|---|
| 144 | " msgbox [text] = Show a MessageBox with the supplied text", |
|---|
| 145 | " opt option-char = Show value for option-char as set by last 'parse'", |
|---|
| 146 | " pack in [o][m] = Compress file 'in' to [o], using method [m]", |
|---|
| 147 | " parse cmd-string = Parse command string to options and arguments", |
|---|
| 148 | " pdrop [all] = Drop one or all levels of parsed commands", |
|---|
| 149 | " pshow [all] = Show one or all levels of parsed commands", |
|---|
| 150 | " prompt [quest] = Prompt for a value using the 'quest' text as question", |
|---|
| 151 | " pbuf [$]s/f [m] = Compress+Decompress string/file using method [m]", |
|---|
| 152 | " prep [$]s [c][s] = Measure compress string/file [cnt] times, size [s] Kib", |
|---|
| 153 | " screen [on|off] = Switch output to the screen on or off", |
|---|
| 154 | " setansi [on|off] = Set use of ANSI escape-sequences (colors) on or off", |
|---|
| 155 | " sbnum = Number lines in scroll-buffer for testing", |
|---|
| 156 | " scrfile [fn] [l] = Save screen-buffer to file [fn], last [l] lines", |
|---|
| 157 | " unpack in [o][m] = De-compress file 'in' to [o], using method [m]", |
|---|
| 158 | " vol [floppy] = Show all volumes, optional including floppies", |
|---|
| 159 | " vols [floppy] = Show all volumes, as a single string", |
|---|
| 160 | #if defined (DUMP) |
|---|
| 161 | " trace [lvl] = Set trace level for TXT internal function tracing", |
|---|
| 162 | #endif |
|---|
| 163 | #if defined (DEV32) |
|---|
| 164 | " run macro = Run a TXT macro in a .TXT file", |
|---|
| 165 | #else |
|---|
| 166 | #endif |
|---|
| 167 | " q = Quit", |
|---|
| 168 | NULL |
|---|
| 169 | }; |
|---|
| 170 | |
|---|
| 171 | |
|---|
| 172 | static char txtMsgTitle[] = " Test Message box "; |
|---|
| 173 | static char txtMsgText[] = |
|---|
| 174 | "This is message text to test the txwMessageBox. It has some long lines that " |
|---|
| 175 | "need to be split by the Box and also some that are short enough already.\n" |
|---|
| 176 | "So let us see if that works, with an empty line:\n\nAnd a last one ..."; |
|---|
| 177 | |
|---|
| 178 | static char txtPromptTitle[] = " Test Prompt box "; |
|---|
| 179 | static char txtPromptText[] = |
|---|
| 180 | "This is message text to test the txwPromptBox. Fill in any value ..."; |
|---|
| 181 | |
|---|
| 182 | |
|---|
| 183 | |
|---|
| 184 | // Interactive TXT mode |
|---|
| 185 | static ULONG txtInteractive |
|---|
| 186 | ( |
|---|
| 187 | char *cmdstring // IN initial command |
|---|
| 188 | ); |
|---|
| 189 | |
|---|
| 190 | // Interpret and execute TXTst command; |
|---|
| 191 | static ULONG txtSingleCommand |
|---|
| 192 | ( |
|---|
| 193 | char *txtcmd, // IN TXT command |
|---|
| 194 | BOOL echo, // IN Echo command |
|---|
| 195 | BOOL quiet // IN screen-off during cmd |
|---|
| 196 | ); |
|---|
| 197 | |
|---|
| 198 | |
|---|
| 199 | int main (int argc, char *argv[]); |
|---|
| 200 | |
|---|
| 201 | /*****************************************************************************/ |
|---|
| 202 | /* Main function of the program, handle commandline-arguments */ |
|---|
| 203 | /*****************************************************************************/ |
|---|
| 204 | int main (int argc, char *argv[]) |
|---|
| 205 | { |
|---|
| 206 | ULONG rc = NO_ERROR; // function return |
|---|
| 207 | char *exename = argv[0]; // save before INITmain |
|---|
| 208 | |
|---|
| 209 | TxINITmain( TXT_TRACE, "TXT", FALSE, 0); // TX Init code, incl tracing |
|---|
| 210 | // argv/argc modified if TRACE |
|---|
| 211 | |
|---|
| 212 | if (TxaExeSwitch('l')) // start logfile now ? |
|---|
| 213 | { |
|---|
| 214 | TxAppendToLogFile( TxaExeSwitchStr( 'l', "txt Logfile", "TXTest")); |
|---|
| 215 | } |
|---|
| 216 | if (TxaExeSwitch('?')) // switch help requested |
|---|
| 217 | { |
|---|
| 218 | TxPrint( "\nUsage: %s ", exename); |
|---|
| 219 | TxShowTxt( switchhelp); |
|---|
| 220 | } |
|---|
| 221 | else |
|---|
| 222 | { |
|---|
| 223 | TXLN ar; // arguments |
|---|
| 224 | |
|---|
| 225 | strcpy( ar, TXT_STARTCMD); // default command |
|---|
| 226 | |
|---|
| 227 | if (TxaExeSwitch('Q')) |
|---|
| 228 | { |
|---|
| 229 | txta->autoquit = TRUE; // auto quit after cmd |
|---|
| 230 | txta->nowindow = TRUE; // default no win on autoquit |
|---|
| 231 | } |
|---|
| 232 | |
|---|
| 233 | if (TxaExeSwitch('b')) |
|---|
| 234 | { |
|---|
| 235 | txta->batch = TRUE; // set global force on |
|---|
| 236 | } |
|---|
| 237 | separator = TxaExeSwitchStr( 's', "SeparatorCh", "#"); |
|---|
| 238 | txta->eStrategy = TxaErrorStrategy( 'E', txta->batch); |
|---|
| 239 | txta->verbosity = TxaOutputVerbosity( 'O'); |
|---|
| 240 | |
|---|
| 241 | if (rc == NO_ERROR) |
|---|
| 242 | { |
|---|
| 243 | if (TxaExeArgc() > 1) // arguments given |
|---|
| 244 | { |
|---|
| 245 | char qstring[3] = "?q"; |
|---|
| 246 | |
|---|
| 247 | qstring[0] = separator[0]; // use current separator |
|---|
| 248 | |
|---|
| 249 | TxaGetArgString( TXA_1ST, 1, TXA_ALL, TXMAXLN, ar); |
|---|
| 250 | if (strstr( ar, qstring) != NULL) |
|---|
| 251 | { |
|---|
| 252 | txta->nowindow = TRUE; // don't use windowing |
|---|
| 253 | } |
|---|
| 254 | else if ((TxaExeArgc() > 1) && |
|---|
| 255 | (strnicmp( TxaExeArgv(1), "nonag", 5) == 0)) |
|---|
| 256 | { |
|---|
| 257 | if (strnicmp( TxaExeArgv(1), "query", 5) == 0) |
|---|
| 258 | { |
|---|
| 259 | txta->regconfirm = FALSE; // no reg-nagging for now ... |
|---|
| 260 | } |
|---|
| 261 | if (!TxaExeSwitchUnSet('Q')) // no -Q- |
|---|
| 262 | { |
|---|
| 263 | txta->nowindow = TRUE; // don't use windowing |
|---|
| 264 | txta->autoquit = TRUE; // auto quit after cmd |
|---|
| 265 | } |
|---|
| 266 | } |
|---|
| 267 | } |
|---|
| 268 | |
|---|
| 269 | if (TxaExeSwitchSet('w')) // explicit windowing setting |
|---|
| 270 | { |
|---|
| 271 | if (TxaOption('w')) // set windowing on |
|---|
| 272 | { |
|---|
| 273 | txta->nowindow = FALSE; // use windowing |
|---|
| 274 | } |
|---|
| 275 | else |
|---|
| 276 | { |
|---|
| 277 | txta->nowindow = TRUE; // don't use windowing |
|---|
| 278 | } |
|---|
| 279 | } |
|---|
| 280 | do |
|---|
| 281 | { |
|---|
| 282 | if (txta->nowindow) |
|---|
| 283 | { |
|---|
| 284 | txta->dialogs = FALSE; // dialogs not supported |
|---|
| 285 | txtInteractive( ar); // non windowed interface |
|---|
| 286 | } |
|---|
| 287 | else |
|---|
| 288 | { |
|---|
| 289 | txta->dialogs = !TxaExeSwitchUnSet('P'); |
|---|
| 290 | txtWindowed( ar); // windowed interface |
|---|
| 291 | } |
|---|
| 292 | strcpy( ar, "display"); // new initial command |
|---|
| 293 | |
|---|
| 294 | } while (txta->retc == TX_DISPLAY_CHANGE); |
|---|
| 295 | |
|---|
| 296 | rc = txta->retc; |
|---|
| 297 | // TxrRegistrationInfo( TXREG_CONFIRM_ONLY, TXT_V, txta->regconfirm); |
|---|
| 298 | } |
|---|
| 299 | } |
|---|
| 300 | TxEXITmain(rc); // TX Exit code, incl tracing |
|---|
| 301 | } // end 'main' |
|---|
| 302 | /*---------------------------------------------------------------------------*/ |
|---|
| 303 | |
|---|
| 304 | |
|---|
| 305 | /*****************************************************************************/ |
|---|
| 306 | // Print TXTst logo+status, do startup checks, run startup commands + profile |
|---|
| 307 | /*****************************************************************************/ |
|---|
| 308 | ULONG txtStartupLogo // RET Checks and firstcmd RC |
|---|
| 309 | ( |
|---|
| 310 | char *firstcmd // IN initial command |
|---|
| 311 | ) |
|---|
| 312 | { |
|---|
| 313 | ULONG rc = NO_ERROR; |
|---|
| 314 | FILE *fp; |
|---|
| 315 | TXTM osd; // OS description string |
|---|
| 316 | TXLN msg; |
|---|
| 317 | |
|---|
| 318 | ENTER(); |
|---|
| 319 | TRACES(("Startup command is '%s'\n", firstcmd)); |
|---|
| 320 | |
|---|
| 321 | TxPrint( "\n TxWindows Test program; version %s %s\n", TXT_V, TXT_C); |
|---|
| 322 | TxPrint( " ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ[ www.dfsee.com" |
|---|
| 323 | " ]ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ\n\n"); |
|---|
| 324 | |
|---|
| 325 | if (TxaExeSwitch('S')) |
|---|
| 326 | { |
|---|
| 327 | TxPrint( "%16.16sRun as SHELL %s-S%s, quit and <F3> are disabled\n\n", |
|---|
| 328 | "", CBC, CNN); |
|---|
| 329 | } |
|---|
| 330 | |
|---|
| 331 | (void) TxOsVersion( osd); // get/check OS version info |
|---|
| 332 | strcpy( msg, ""); |
|---|
| 333 | #if defined (WIN32) |
|---|
| 334 | if (strstr( osd, "Windows-9") != NULL) // Win-9x detected |
|---|
| 335 | { |
|---|
| 336 | strcpy( msg, "Windows-9x is not supported by this " |
|---|
| 337 | "version of TXTst! Use TXTDOS.EXE after " |
|---|
| 338 | "'Restart in MS-DOS mode' or use a DOS bootdisk."); |
|---|
| 339 | } |
|---|
| 340 | #elif defined (DOS32) |
|---|
| 341 | if (strstr( osd, "DosBox") != NULL) // Win or OS/2 DosBox (VDM) |
|---|
| 342 | { |
|---|
| 343 | if (strstr( osd, "Windows-9") != NULL) // Win-9x detected |
|---|
| 344 | { |
|---|
| 345 | txta->win9x = TRUE; |
|---|
| 346 | |
|---|
| 347 | strcpy( msg, "Running TXTDOS.EXE in a Win9x DosBox might " |
|---|
| 348 | "give unpredictable results! Use TXTDOS.EXE after " |
|---|
| 349 | "'Restart in MS-DOS mode' or use a DOS bootdisk."); |
|---|
| 350 | } |
|---|
| 351 | else |
|---|
| 352 | { |
|---|
| 353 | sprintf( msg, "Running TXTDOS.EXE in a virtual DosBox " |
|---|
| 354 | "might give unpredictable results! Please use " |
|---|
| 355 | "the native version TXT%s.EXE when possible.", |
|---|
| 356 | (strstr( osd, "Win")) ? "WIN" : "OS2"); |
|---|
| 357 | } |
|---|
| 358 | } |
|---|
| 359 | else if (strstr( osd, "MemMgr") != NULL) // EMM386 or other manager |
|---|
| 360 | { |
|---|
| 361 | strcpy( msg, "Running TXTDOS.EXE under a Memory Manager like " |
|---|
| 362 | "EMM386 or QEMM might give unpredictable results! " |
|---|
| 363 | "For maximum reliability, run without any external " |
|---|
| 364 | "memory manager (check autoexec.bat and config.sys)."); |
|---|
| 365 | } |
|---|
| 366 | #else |
|---|
| 367 | //- OS2 and LINUX versions |
|---|
| 368 | #endif |
|---|
| 369 | |
|---|
| 370 | txtBEGINWORK(); |
|---|
| 371 | if (strlen( msg) != 0) // OS versus TXTst mismatch |
|---|
| 372 | { |
|---|
| 373 | if (txta->batch) // just show to screen/log |
|---|
| 374 | { |
|---|
| 375 | strcat( msg, "\n\n"); |
|---|
| 376 | TxMessage( FALSE, 5004, msg); |
|---|
| 377 | } |
|---|
| 378 | else // interactive, confirm |
|---|
| 379 | { |
|---|
| 380 | strcat( msg, "\n\nDo you want to take the risk and continue with the program ? [Y/N]: "); |
|---|
| 381 | if (!TxConfirm( 5004, msg)) |
|---|
| 382 | { |
|---|
| 383 | rc = TXT_QUIT; |
|---|
| 384 | } |
|---|
| 385 | } |
|---|
| 386 | } |
|---|
| 387 | |
|---|
| 388 | if (rc == NO_ERROR) // not aborted yet ... |
|---|
| 389 | { |
|---|
| 390 | if ((fp = fopen( TXT_PROFILE, "r")) != NULL) |
|---|
| 391 | { |
|---|
| 392 | TXLN command; |
|---|
| 393 | |
|---|
| 394 | fclose( fp); |
|---|
| 395 | sprintf( command, "run %s", TXT_PROFILE); |
|---|
| 396 | txtMultiCommand( command, TRUE, FALSE, FALSE); // exec profile |
|---|
| 397 | } |
|---|
| 398 | |
|---|
| 399 | if (strlen( firstcmd)) |
|---|
| 400 | { |
|---|
| 401 | if (strstr( firstcmd, "about") == NULL) // no about in command |
|---|
| 402 | { |
|---|
| 403 | txtMultiCommand( "about -c- -P-", FALSE, FALSE, FALSE); |
|---|
| 404 | } |
|---|
| 405 | rc = txtMultiCommand( firstcmd, TRUE, FALSE, FALSE); // execute command |
|---|
| 406 | } |
|---|
| 407 | } |
|---|
| 408 | txtENDWORK(); |
|---|
| 409 | RETURN (rc); |
|---|
| 410 | } // end 'txtStartupLogo' |
|---|
| 411 | /*---------------------------------------------------------------------------*/ |
|---|
| 412 | |
|---|
| 413 | |
|---|
| 414 | /*****************************************************************************/ |
|---|
| 415 | // Use classic text mode and accept interactive display commands |
|---|
| 416 | /*****************************************************************************/ |
|---|
| 417 | static ULONG txtInteractive |
|---|
| 418 | ( |
|---|
| 419 | char *cmdstring // IN initial command |
|---|
| 420 | ) |
|---|
| 421 | { |
|---|
| 422 | ULONG rc; |
|---|
| 423 | TXLN command; // txt command |
|---|
| 424 | |
|---|
| 425 | ENTER(); |
|---|
| 426 | |
|---|
| 427 | rc = txtStartupLogo( cmdstring); |
|---|
| 428 | while ((rc != TXT_QUIT) && !txta->autoquit) |
|---|
| 429 | { |
|---|
| 430 | TxPrint("%s; cmd/SN : ", TXT_N); |
|---|
| 431 | fflush( stdout); |
|---|
| 432 | memset( command, 0, TXMAXLN); |
|---|
| 433 | fgets( command, TXMAXLN, stdin); // get next command |
|---|
| 434 | TxRepl( command, '\n', 0); |
|---|
| 435 | TxCancelAbort(); // reset pending abort status |
|---|
| 436 | rc = txtMultiCommand( command, TRUE, TRUE, FALSE); |
|---|
| 437 | } |
|---|
| 438 | RETURN ( txta->retc); |
|---|
| 439 | } // end 'txtInteractive' |
|---|
| 440 | /*---------------------------------------------------------------------------*/ |
|---|
| 441 | |
|---|
| 442 | |
|---|
| 443 | /*****************************************************************************/ |
|---|
| 444 | // Execute multiple txt-commands separated by # characters |
|---|
| 445 | /*****************************************************************************/ |
|---|
| 446 | ULONG txtMultiCommand |
|---|
| 447 | ( |
|---|
| 448 | char *cmdstring, // IN multiple command |
|---|
| 449 | BOOL echo, // IN Echo before execute |
|---|
| 450 | BOOL prompt, // IN prompt after execute |
|---|
| 451 | BOOL quiet // IN screen-off during cmd |
|---|
| 452 | ) |
|---|
| 453 | { |
|---|
| 454 | ULONG rc = NO_ERROR; |
|---|
| 455 | TXLN cmdcopy; // modifyable copy |
|---|
| 456 | char *nextcmd; // next of multiple commands |
|---|
| 457 | char *command; // txt command |
|---|
| 458 | |
|---|
| 459 | ENTER(); |
|---|
| 460 | |
|---|
| 461 | txtBEGINWORK(); // signal work starting |
|---|
| 462 | TRACES(("Worklevel: %lu Cmdstring: '%s'\n", txta->worklevel, cmdstring)); |
|---|
| 463 | if (strlen( cmdstring) != 0) // replace empty by space |
|---|
| 464 | { |
|---|
| 465 | strcpy( cmdcopy, cmdstring); |
|---|
| 466 | for ( command = cmdcopy; |
|---|
| 467 | (command != NULL) && !TxAbort(); // abort from long multi |
|---|
| 468 | command = nextcmd) // cmds must be possible! |
|---|
| 469 | { |
|---|
| 470 | if ((nextcmd = strchr( command, separator[0])) != NULL) |
|---|
| 471 | { |
|---|
| 472 | *nextcmd = '\0'; // remove separator |
|---|
| 473 | nextcmd++; |
|---|
| 474 | } |
|---|
| 475 | TxCancelAbort(); // reset pending abort status |
|---|
| 476 | TRACES(("Command: '%s' Nextcmd: '%s'\n", command, (nextcmd) ? nextcmd : "")); |
|---|
| 477 | rc = txtSingleCommand( command, echo, quiet); |
|---|
| 478 | if (nextcmd != NULL) |
|---|
| 479 | { |
|---|
| 480 | *(nextcmd -1) = separator[0]; // put separator back |
|---|
| 481 | } |
|---|
| 482 | } |
|---|
| 483 | } |
|---|
| 484 | else |
|---|
| 485 | { |
|---|
| 486 | rc = txtSingleCommand( " ", TRUE, FALSE); // default cmd, <ENTER> |
|---|
| 487 | } |
|---|
| 488 | txtENDWORK(); // signal work done |
|---|
| 489 | if ((rc == TXT_QUIT) && (TxaExeSwitch('S'))) |
|---|
| 490 | { |
|---|
| 491 | TxPrint( "\nTXTst is running in SHELL mode, quit is not allowed ...\n"); |
|---|
| 492 | rc = NO_ERROR; |
|---|
| 493 | } |
|---|
| 494 | RETURN (rc); |
|---|
| 495 | } // end 'txtMultiCommand' |
|---|
| 496 | /*---------------------------------------------------------------------------*/ |
|---|
| 497 | |
|---|
| 498 | |
|---|
| 499 | /*****************************************************************************/ |
|---|
| 500 | // Interpret and execute DHPFS command; |
|---|
| 501 | /*****************************************************************************/ |
|---|
| 502 | static ULONG txtSingleCommand |
|---|
| 503 | ( |
|---|
| 504 | char *txtcmd, // IN TXT command |
|---|
| 505 | BOOL echo, // IN Echo command |
|---|
| 506 | BOOL quiet // IN screen-off during cmd |
|---|
| 507 | ) |
|---|
| 508 | { |
|---|
| 509 | ULONG rc; |
|---|
| 510 | TXLN dc; |
|---|
| 511 | int cc = 0; // command string count |
|---|
| 512 | char *c0, *c1, *c2, *c3, *c4; // parsed command parts |
|---|
| 513 | TXLN s0, s1; // temporary string space |
|---|
| 514 | char *pp; // parameter pointers |
|---|
| 515 | USHORT ml = 0; // mixed string length |
|---|
| 516 | USHORT cp = 0; // cursor position |
|---|
| 517 | ULONG size; |
|---|
| 518 | ULONG count; |
|---|
| 519 | FILE *fi; |
|---|
| 520 | int fh; // low-level file handle |
|---|
| 521 | TXHANDLE ph = 0; // parse handle |
|---|
| 522 | BOOL l_force = FALSE; // local batch-mode used |
|---|
| 523 | BOOL l_dialogs = FALSE; // local dialogs set |
|---|
| 524 | BOOL v_dialogs; // saved dialogs copy |
|---|
| 525 | BOOL l_errst = FALSE; // local error strategy |
|---|
| 526 | int v_errst; // saved copy |
|---|
| 527 | BOOL l_verbo = FALSE; // local verbosity |
|---|
| 528 | ULONG v_verbo; // saved copy |
|---|
| 529 | DEVICE_STATE v_screen; // saved copy screen state |
|---|
| 530 | |
|---|
| 531 | ENTER(); |
|---|
| 532 | |
|---|
| 533 | TxaParseCommandString( txtcmd, TRUE, NULL); // parse, free-format |
|---|
| 534 | pp = TxaGetArgString( TXA_CUR, 0, 0, TXMAXLN, dc); // dc = pp => cmd from arg 0 |
|---|
| 535 | cc = TxaArgCount( ); // number of parameters |
|---|
| 536 | c0 = TxaArgValue(0); |
|---|
| 537 | c1 = TxaArgValue(1); |
|---|
| 538 | c2 = TxaArgValue(2); |
|---|
| 539 | c3 = TxaArgValue(3); |
|---|
| 540 | c4 = TxaArgValue(4); |
|---|
| 541 | |
|---|
| 542 | for (pp = &(dc[0]) + strlen(c0); *pp == ' '; pp++) {}; |
|---|
| 543 | |
|---|
| 544 | if (TxaOption('-')) // option -- |
|---|
| 545 | { |
|---|
| 546 | TxPrint("Command : '%s'\n", dc); |
|---|
| 547 | TxaShowParsedCommand( TRUE); // option diagnostic |
|---|
| 548 | } |
|---|
| 549 | if (TxaOption('Q')) // locally forced quiet |
|---|
| 550 | { |
|---|
| 551 | quiet = TRUE; // force input parameter |
|---|
| 552 | } |
|---|
| 553 | if (TxaOption('B')) // local batch mode |
|---|
| 554 | { |
|---|
| 555 | if (txta->batch == FALSE) // no global force yet |
|---|
| 556 | { |
|---|
| 557 | txta->batch = TRUE; // register force globally |
|---|
| 558 | l_force = TRUE; // use local force |
|---|
| 559 | } |
|---|
| 560 | } |
|---|
| 561 | if ((txta->batch) || (TxaOptSet('P'))) // batch or local -P option |
|---|
| 562 | { |
|---|
| 563 | v_dialogs = txta->dialogs; // save old value |
|---|
| 564 | l_dialogs = TRUE; // and signal restore |
|---|
| 565 | |
|---|
| 566 | txta->dialogs = (TxaOption('P') != 0); |
|---|
| 567 | } |
|---|
| 568 | if (TxaOptValue('E') != NULL) // local error strategy |
|---|
| 569 | { |
|---|
| 570 | v_errst = txta->eStrategy; |
|---|
| 571 | l_errst = TRUE; |
|---|
| 572 | txta->eStrategy = TxaErrorStrategy( 'E', txta->batch); |
|---|
| 573 | } |
|---|
| 574 | if (TxaOptValue('O') != NULL) // local output verbosity |
|---|
| 575 | { |
|---|
| 576 | v_verbo = txta->verbosity; |
|---|
| 577 | l_verbo = TRUE; |
|---|
| 578 | txta->verbosity = TxaOutputVerbosity( 'O'); |
|---|
| 579 | } |
|---|
| 580 | |
|---|
| 581 | TRACES(("batch: %lu eStrategy: %u Verbosity: %lu\n", |
|---|
| 582 | txta->batch, txta->eStrategy, txta->verbosity)); |
|---|
| 583 | |
|---|
| 584 | if ((echo == TRUE) && (stricmp(c0, "screen" ) != 0) |
|---|
| 585 | && (stricmp(c0, "say" ) != 0)) |
|---|
| 586 | { |
|---|
| 587 | if (!TxaExeSwitchUnSet('e')) // no surpress echo ? |
|---|
| 588 | { |
|---|
| 589 | TxPrint("%s%s version : %4.4s executing: %s%s%s\n", |
|---|
| 590 | (quiet) ? "" : "\n", TXT_N, TXT_V, CBG, |
|---|
| 591 | (cc == 0) ? "<Enter>" : txtcmd, CNN); |
|---|
| 592 | } |
|---|
| 593 | |
|---|
| 594 | if ( (TxaExeSwitch('t') || TxaExeSwitch('q') || TxaExeSwitch('l')) && |
|---|
| 595 | (!TxaExeSwitchUnSet('t'))) // no surpress timestamp ? |
|---|
| 596 | { |
|---|
| 597 | time_t tt = time( &tt); // current date/time |
|---|
| 598 | |
|---|
| 599 | strftime( s0, TXMAXLN, "%A %d-%m-%Y %H:%M:%S", localtime( &tt)); |
|---|
| 600 | TxPrint( "Execute timestamp : %s\n", s0); |
|---|
| 601 | } |
|---|
| 602 | } |
|---|
| 603 | |
|---|
| 604 | v_screen = TxScreenState( DEVICE_TEST); |
|---|
| 605 | if (quiet) |
|---|
| 606 | { |
|---|
| 607 | TxScreenState( DEVICE_OFF); |
|---|
| 608 | } |
|---|
| 609 | |
|---|
| 610 | TRACES(("cc: %u c0:'%s' c1:'%s' c2:'%s' c3:'%s' c4:'%s' pp:'%s'\n", |
|---|
| 611 | cc, c0, c1, c2, c3, c4, pp)); |
|---|
| 612 | |
|---|
| 613 | rc = TxStdCommand(); |
|---|
| 614 | if ((rc == TX_PENDING) || (rc == TX_CMD_UNKNOWN)) |
|---|
| 615 | { |
|---|
| 616 | rc = NO_ERROR; |
|---|
| 617 | if (stricmp(c0, "sep" ) == 0) |
|---|
| 618 | { |
|---|
| 619 | if (cc > 1) |
|---|
| 620 | { |
|---|
| 621 | separator[0] = c1[0]; |
|---|
| 622 | } |
|---|
| 623 | } |
|---|
| 624 | else if (stricmp(c0, "menu" ) == 0) |
|---|
| 625 | { |
|---|
| 626 | if (TxaOption('?') || (c1[0] == '?')) // explicit help request |
|---|
| 627 | { |
|---|
| 628 | TxPrint("\nActivate the menu with default or selected pulldown\n"); |
|---|
| 629 | TxPrint("\n Usage: %s [pulldown-select-letter]\n\n" |
|---|
| 630 | " f = File\n" |
|---|
| 631 | " t = Test\n" |
|---|
| 632 | " d = Display\n" |
|---|
| 633 | " s = Settings\n" |
|---|
| 634 | " h = Help\n", c0); |
|---|
| 635 | } |
|---|
| 636 | else |
|---|
| 637 | { |
|---|
| 638 | if (txta->automenu) |
|---|
| 639 | { |
|---|
| 640 | txta->menuOwner = TXHWND_DESKTOP; |
|---|
| 641 | } |
|---|
| 642 | txta->menuopen = (ULONG) c1[0]; |
|---|
| 643 | } |
|---|
| 644 | } |
|---|
| 645 | else if (stricmp(c0, "about" ) == 0) |
|---|
| 646 | { |
|---|
| 647 | BOOL plaintext; |
|---|
| 648 | TX1K about; // about text |
|---|
| 649 | TXLN text; // one line of text |
|---|
| 650 | TXTS alead; // leader text |
|---|
| 651 | |
|---|
| 652 | plaintext = (TxaOptUnSet('P') || (!txwIsWindow( TXHWND_DESKTOP))); |
|---|
| 653 | strcpy( alead, (plaintext) ? " " : ""); |
|---|
| 654 | if (!TxaOptUnSet('c')) // show program copyright ? |
|---|
| 655 | { |
|---|
| 656 | sprintf( about, "%s Details on this " |
|---|
| 657 | "Fsys Software program\n\n%s %s : %s %s\n", |
|---|
| 658 | alead, alead, TXT_N, TXT_V, TXT_C); |
|---|
| 659 | } |
|---|
| 660 | else |
|---|
| 661 | { |
|---|
| 662 | strcpy( about, ""); |
|---|
| 663 | } |
|---|
| 664 | sprintf( text, "%sUI TxWindows : %s\n", alead, txVersionString()); |
|---|
| 665 | strcat( about, text); |
|---|
| 666 | sprintf( text, "%s'C' compiler : ", alead); |
|---|
| 667 | strcat( about, text); |
|---|
| 668 | #if defined (__WATCOMC__) |
|---|
| 669 | if (__WATCOMC__ > 1100) // must be OpenWatcom |
|---|
| 670 | { |
|---|
| 671 | sprintf( text, "OpenWatcom %4.2lf (c) 1988-2004: " |
|---|
| 672 | "Sybase & openwatcom.org\n", |
|---|
| 673 | ((double) ( __WATCOMC__ - 1100)) / 100); |
|---|
| 674 | } |
|---|
| 675 | else |
|---|
| 676 | { |
|---|
| 677 | sprintf( text, "Watcom C/C++ version : %4.2lf\n", |
|---|
| 678 | ((double) ( __WATCOMC__ )) / 100); |
|---|
| 679 | } |
|---|
| 680 | #else |
|---|
| 681 | #if defined (DEV32) |
|---|
| 682 | sprintf( text, "VisualAge 3.65 (c) 1991-1997: IBM Corporation\n"); |
|---|
| 683 | #else |
|---|
| 684 | sprintf( text, "Visual C++ 5.0 (c) 1986-1997: Microsoft Corporation\n"); |
|---|
| 685 | #endif |
|---|
| 686 | #endif |
|---|
| 687 | strcat( about, text); |
|---|
| 688 | sprintf( text, "%sEXE compress : ", alead); |
|---|
| 689 | strcat( about, text); |
|---|
| 690 | #if defined (DEV32) |
|---|
| 691 | sprintf( text, "lxLite 1.33 (c) 1996-2003: Max Alekseyev\n"); |
|---|
| 692 | #else |
|---|
| 693 | sprintf( text, "UPX 1.20 (c) 1996-2002: Markus Oberhumer\n"); |
|---|
| 694 | #endif |
|---|
| 695 | strcat( about, text); |
|---|
| 696 | #if defined (DOS32) |
|---|
| 697 | sprintf( text, "%sDOS extender : %s\n", alead, txDosExtVersion()); |
|---|
| 698 | strcat( about, text); |
|---|
| 699 | #endif |
|---|
| 700 | (void) TxOsVersion( s0); // Get operating system version |
|---|
| 701 | sprintf( text, "%sOS version : %s\n", alead, s0); |
|---|
| 702 | strcat( about, text); |
|---|
| 703 | #if defined (DOS32) |
|---|
| 704 | sprintf( text, "%sDPMI version : %s\n", alead, txDosExtDpmiInfo()); |
|---|
| 705 | strcat( about, text); |
|---|
| 706 | #endif |
|---|
| 707 | /* |
|---|
| 708 | if (!TxaOptUnSet('c')) // show program copyright and |
|---|
| 709 | { // short registration info ? |
|---|
| 710 | sprintf( text, "\n%sRegistration : ", alead); |
|---|
| 711 | strcat( about, text); |
|---|
| 712 | strcat( about, TxrRegistrationString( text)); |
|---|
| 713 | } |
|---|
| 714 | else // seperate (c) and reg confirm |
|---|
| 715 | { |
|---|
| 716 | TxrRegistrationInfo( TXREG_DISPLAY_CONFIRM, TXT_V, txta->regconfirm); |
|---|
| 717 | } |
|---|
| 718 | */ |
|---|
| 719 | strcat( about, "\n"); |
|---|
| 720 | |
|---|
| 721 | TxMessage( !(txta->batch || plaintext), 5003, about); |
|---|
| 722 | } |
|---|
|