home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / UTILITY / KEYBOARD / CMDED2E5.ZIP / INSTALL.ASM < prev    next >
Encoding:
Assembly Source File  |  1991-07-13  |  26.6 KB  |  905 lines

  1. ; INSTALL.ASM
  2. ; (c) 1989, 1990 Ashok P. Nadkarni
  3. ; Addition of /c,l,w,o,t & z options by David Abbott (dfa),  Nov-Dec, 1990.
  4. ; Improvements to locate_cmdedit by dfa,  Jan 1991.
  5. ; also /k option added May 1991 and /n added July 1991.
  6. ;
  7. ; This code is the installation code for CMDEDIT. This file must be
  8. ; linked last !
  9.  
  10.     INCLUDE common.inc
  11.     INCLUDE ascii.inc
  12.     INCLUDE dos.inc
  13.     INCLUDE general.inc
  14.  
  15.     PUBLIC    install_begin
  16.     PUBLIC    install
  17.     PUBLIC    file_error
  18.     PUBLIC    abort_install
  19.     PUBLIC    dirstk_error
  20.     PUBLIC    process_args
  21.  
  22. CSEG    SEGMENT    PARA PUBLIC 'CODE'
  23.     EXTRN    getargs:PROC
  24.     EXTRN    cmdlen:BYTE
  25.     EXTRN    default_imode:BYTE
  26.     EXTRN    auto_recall:BYTE
  27.     EXTRN    pgm_name:BYTE
  28.     EXTRN    silent:BYTE
  29.     EXTRN    macrosize:WORD
  30.     EXTRN    macro_ignore_char:BYTE
  31.     EXTRN    symsize:WORD
  32.     EXTRN    dossize:WORD
  33.     EXTRN    dirsize:WORD
  34.     EXTRN    mfilename:BYTE
  35.     EXTRN    mfile_seen:BYTE
  36.     EXTRN    prev_isr1b:WORD
  37.     EXTRN    enable_dircmds:BYTE
  38.     EXTRN    dos_version_major:BYTE
  39.     EXTRN    dos_version_minor:BYTE
  40.     EXTRN    old_int21vec:WORD
  41.     EXTRN    cmdedit:PROC
  42.     EXTRN    our_break_handler:PROC
  43.     EXTRN    init_over:PROC
  44.     EXTRN    cmdedit_isr:PROC
  45. ;dfa added the following
  46.     EXTRN   cursor_type:BYTE
  47.     EXTRN   disable_macro:BYTE
  48.     EXTRN   min_length:WORD
  49.     EXTRN   msg_flag:BYTE
  50.     EXTRN   cmdedit_disable:BYTE
  51.     EXTRN   TAB_key_function:WORD
  52.     EXTRN   ESC_key_function:WORD
  53.  
  54. DGROUP    GROUP    CSEG
  55.  
  56.  
  57.     ASSUME    CS:DGROUP,DS:DGROUP,ES:DGROUP,SS:DGROUP
  58.  
  59. ; install_begin MUST be start of installation code.
  60. install_begin    LABEL BYTE
  61. msg_nomem    db    '* Insufficient Memory - Reduce buffer sizes *',CR,LF,DOLLAR
  62. option_error db '* Unknown or illegal options *',CR,LF,DOLLAR
  63. file_error   db '* Error processing command file *',CR,LF,DOLLAR
  64. dirstk_error db '* Error processing directory stack commands *',CR,LF,DOLLAR
  65. inv_dosver   db '* Unsupported DOS version. *',CR,LF,DOLLAR
  66. msg_dup         db '* CMDEDIT already installed in memory. *',CR,LF,DOLLAR
  67. ;dfa added options to next line:
  68. options_dup  db '* Only options /c /g /i /l /n /o /p /r /t /z may be specified. *',CR,LF,DOLLAR
  69. msg_notdup   db '* No copy of CMDEDIT found in memory. *',CR,LF,DOLLAR
  70. msg_unload   db '* Unable to unload CMDEDIT.        *',CR,LF
  71.          db '* Uninstall TSRs in reverse order.    *',CR,LF,DOLLAR
  72. msg_memerr   db '* DOS memory allocation error! *',CR,LF,BEL
  73.          db '* Recommend you reboot!        *',CR,LF,BEL,DOLLAR
  74. msg_uninstalled db '* CMDEDIT uninstalled successfully *',CR,LF,DOLLAR
  75. msg_omode db '* Default overwrite mode enabled. *',CR,LF,DOLLAR
  76. msg_imode db '* Default insert mode enabled. *',CR,LF,DOLLAR
  77. msg_enable_autorecall db '* autorecall enabled. *',CR,LF,DOLLAR
  78. msg_disable_autorecall db '* autorecall disabled. *',CR,LF,DOLLAR
  79. msg_enable_bell db '* error bell enabled. *',CR,LF,DOLLAR
  80. msg_disable_bell db '* error bell disabled. *',CR,LF,DOLLAR
  81. msg_ignore_char db '* ignore character changed. *',CR,LF,DOLLAR
  82. ;following added by dfa
  83. ;(also removed the word "CMDEDIT" from begining of above 5 strings :
  84. msg_dcursor_type db '* default cursor types. *',CR,LF,DOLLAR
  85. msg_scursor_type db '* insert & overwrite cursors swapped. *',CR,LF,DOLLAR
  86. msg_disable_macro db '* macro translation disabled. *',CR,LF,DOLLAR
  87. msg_enable_macro db '* macro translation enabled. *',CR,LF,DOLLAR
  88. msg_length_changed db '* changed minimum history line length. *',CR,LF,DOLLAR
  89. msg_notinst db '* /o specified but CMDEDIT not previously installed. *',CR,LF,DOLLAR
  90. msg_disable db '* CMDEDIT disabled. *',CR,LF,DOLLAR
  91. msg_enable db '* CMDEDIT enabled. *',CR,LF,DOLLAR
  92.  
  93. cmdedit_seg  dw    0                ;Segment of the first copy
  94. ;                         of CMDEDIT loaded into memory.
  95.  
  96. argflags    dw  0   ;Used to remember what args have been seen.
  97.                     ;dfa changed from db to dw to allow more args.
  98. dosarg      equ 1   ;(in most cases so can flag an error if trying to
  99. applarg     equ 2   ;  change after installation)
  100. filearg        equ    4
  101. dirarg        equ    8
  102. macroarg    equ    16
  103. symarg        equ    32
  104. uninstall_arg    equ    64
  105. ignore_arg    equ    128
  106. ;added by dfa:
  107. length_arg  equ 256
  108. not_inst_arg equ 512
  109. esc_arg     equ 1024
  110. no_check_arg equ 2048
  111.  
  112. argument_buffer db    LINEBUF_SIZE DUP (?)
  113.  
  114. ;    This location is jumped to when the program is run from the DOS
  115. ;    command line. The program parses the input line, takes
  116. ;    appropriate actions, initializes buffers etc. and then TSR's
  117. ;    after taking over interrupt 21h. The memory taken up by the ISEG
  118. ;    segment will then be used for various data buffers since this
  119. ;    code is no longer needed.
  120. install proc    near
  121.     cld            ;Entire program assumes direction flag will
  122. ;                 be cleared
  123.  
  124.     ASSUME CS:DGROUP,DS:DGROUP,ES:DGROUP,SS:DGROUP
  125.     @DispStr pgm_name        ;Display program name
  126.  
  127. ; Make sure we are running DOS 2.x or higher
  128.     call    near ptr get_dosversion
  129.     cmp    dos_version_major,1        ;DOS 1.x ?
  130.     jne    @install_1
  131.     @DispStr inv_dosver
  132.     mov    ax,-1
  133.     jmp    abort_install            ;V1.x not supported.
  134.  
  135. @install_1:
  136. ; Locate the segment of the first copy of CMDEDIT in memory so that
  137. ; we can tell if this is a second copy.
  138.     call    near ptr locate_cmdedit
  139.     mov    cmdedit_seg,ax            ;Remember it
  140.  
  141. @install_5:
  142.     mov    si,offset cmdlen ;
  143.     lodsb            ;SI == line in PSP, AL == line length
  144.     mov    cl,al
  145.     xor    ch,ch        ;CX = line length
  146.     xor    ax,ax        ;Function = get argument count
  147.     push    cx        ;Save line length
  148.     call     near ptr getargs ;AX := # arguments in command line
  149.     pop    cx        ;Restore line length
  150.     mov    di,ax        ; DI == number of arguments
  151.     inc    di        ;Prime for loop
  152. @install_10:
  153.     dec    di        ;Any more arguments ?
  154.     jz    @install_20    ;No
  155.     mov    bx,offset DGROUP:argument_buffer
  156.     mov    dx,SIZE argument_buffer
  157.     mov    ax,di        ;Argument number
  158.     push    cx        ;save line length
  159.     call     near ptr getargs ;Get argument into argument_buffer
  160. ;                  (no chance of buffer being too short)
  161.     call     near ptr process_args ;Process the argument
  162.     pop    cx        ;Restore line length
  163.     jmp    short @install_10 ;loop back to process remaining args
  164.  
  165.  
  166. @install_20:
  167. ; OK now we have done all necessary parsing without errors. Now first check
  168. ; if the uninstall option was specified.
  169.     test    argflags,uninstall_arg
  170.     je    @install_21        ;Nope
  171.  
  172. ; We have to unload a previously installed copy of CMDEDIT. See if it is
  173. ; really there.
  174.     mov    ax,ds            ;Are we the only copy of CMDEDIT ?
  175.     cmp    ax,cmdedit_seg
  176.     je    @install_20_a        ;There is no other copy
  177.     jmp    uninstall
  178.  
  179. @install_20_a:
  180.     @DispStr msg_notdup        ;Indicate no copy to uninstall
  181.     mov    ax,-1
  182.     jmp    abort_install        ;Exit 
  183.  
  184. @install_21:
  185. ; No uninstall option specified. Now check if this is the only copy of
  186. ; CMDEDIT.
  187.     test argflags,no_check_arg  ;is checking disabled? (added by dfa)
  188.     jnz @install_21_a1
  189.     mov ax,ds
  190.     cmp    ax,cmdedit_seg
  191.     je  @install_21_a1       ;We are the only copy. Proceed with
  192. ;                     installation 
  193.     jmp    change_installed_options ;Else go change installed options.
  194.  
  195. @install_21_a1:             ;added by dfa
  196.     mov cmdedit_seg,ds      ;in case /n specified.
  197.     test argflags,not_inst_arg        ;Do we want to install or not?
  198.     jz @install_21_a
  199.     @DispStr msg_notinst     ;Indicate no copy installed to change.
  200.     mov ax,-1
  201.     jmp abort_install       ;Exit
  202.  
  203. @install_21_a:
  204. ; At this point all the arguments have been parsed. Now check
  205. ; that the sum total of the various buffer sizes does not exceed
  206. ; segment limits. Also check for mandatory minimum sizes.
  207. ; Finally, transfer control to the resident portion which will
  208. ; relocate buffers to overlay the installation code.
  209.  
  210.     mov    ax,OFFSET DGROUP:install_begin
  211.                     ;add starting address where buffers
  212.                     ; will begin
  213.     add    ax,STACK_SIZE
  214.     jnc    @install_23
  215.     jmp    @install_125
  216. @install_23:
  217.     cmp    macrosize,MACROSIZE_MIN
  218.     jnb    @install_22
  219.     mov    macrosize,MACROSIZE_MIN ;Ensure min buffer sizes
  220. @install_22:
  221.     add    ax,macrosize
  222.     jc    @install_125
  223.     cmp    symsize,SYMSIZE_MIN
  224.     jnb    @install_24
  225.     mov    symsize,SYMSIZE_MIN ;Ensure min buffer sizes
  226. @install_24:
  227.     add    ax,symsize
  228.     jc    @install_125
  229.     cmp    dossize,DOSSIZE_MIN
  230.     jnb    @install_26
  231.     mov    dossize,DOSSIZE_MIN ;Ensure min buffer sizes
  232. @install_26:
  233.     add    ax,dossize
  234.     jc    @install_125
  235.     cmp    dirsize,DIRSIZE_MIN
  236.     jnb    @install_30
  237.     mov    dirsize,DIRSIZE_MIN ;Ensure min buffer sizes
  238. @install_30:
  239.     add    ax,dirsize
  240.     jc    @install_125
  241. ;Enough memory, so keep resident. Install our Ctrl-Break handler.
  242.     push    es            ;Save ES
  243.     mov    ah,35h
  244.     mov    al,1bh            ;Ctrl-Break Interrupt
  245.     int    21h            ;Get current handler address
  246.     mov    CS:prev_isr1b,bx    ;Offset of previous handler
  247.     mov    CS:prev_isr1b+2,es    ;Segment of previous handler
  248.     pop    es            ;Restore es
  249.     mov    dx,offset CS:our_break_handler
  250.     push    ds            ;Save DS
  251.     mov    ax,cs
  252.     mov    ds,ax            ;DS:DX->our break handler
  253.     mov    al,1bh
  254.     mov    ah,25h            ;Set up our break handler
  255.     int    21h
  256.     pop    ds            ;Restore DS
  257. ;
  258.     jmp    near ptr init_over
  259.  
  260.  
  261.  
  262. @install_125:
  263.     @DispStr msg_nomem
  264.     mov    ax,-1
  265.     jmp    abort_install
  266.  
  267. install endp
  268.  
  269.  
  270.  
  271.  
  272. ;+
  273. ; FUNCTION : process_args
  274. ;
  275. ;    Processes the argument pointed to by BX. AX contains length 
  276. ;    of argument. If a previously seen argument is repeated, it is
  277. ;    ignored (ie. the old value is kept). Note that the argument is
  278. ;    assumed not to contain any delimiters (like space or tab).
  279. ;
  280. ;    Options start with either a '-' or '/'. Any associated value must
  281. ;    follow immediately after without any intervening space/tab.
  282. ;        /f    Macro file to be read.
  283. ;       /l  (added by dfa) minimum command length to store in buffer
  284. ;        /d    DOS history buffer size
  285. ;        /a    Application history buffer size (only if
  286. ;            separate histories maintained) (OUTDATED)
  287. ;        /m    Macro buffer size
  288. ;        /b    symbol buffer size
  289. ;        /s    Directory Stack size
  290. ;        /r    Auto recall mode
  291. ;        /i    Insert mode default
  292. ;       /c  (added by dfa) Reverse cursor type for insert/overtype mode
  293. ;       /k  (added by dfa) ESC key also used for filename completion.
  294. ;       /t  (added by dfa) Disable macro and symbol translation
  295. ;        /g    Silent mode
  296. ;        /p    macro ignore character
  297. ;        /e    Enable dir commands all the time (OUTDATED)
  298. ;        /u    Uninstall CMDEDIT
  299. ;
  300. ;
  301. ;    Invalid options result in program abortion. If an option is not
  302. ;    followed by a value, the default value for the option is assumed.
  303. ;
  304. ;    Note that this is NOT a general purpose getopt type routine.
  305. ;
  306. ; Parameters:
  307. ;    BX    = Pointer to argument
  308. ;    AX    = Number of characters in argument
  309. ;
  310. ; Returns:
  311. ;    Nothing.
  312. ;    Various globals may be set according to the specified argument.
  313. ; Register(s) BX (call to aton),CX  are destroyed.
  314. ;-
  315. process_args proc near
  316.     @save    si,di
  317.     test    argflags,uninstall_arg
  318.     jne    @process_args_5    ;If /U specified, no other arg is allowed
  319.  
  320.     xchg    ax,cx        ;CX = character count
  321.     sub    cx,2        ;Delete switch char and option letter
  322.     jb    @process_args_5    ;Error in option specification
  323.                 ;  if num chars less than 2
  324.     mov    si,bx        ;SI = arg buffer address
  325.     lodsb            ;AL = first character
  326.     cmp    al,'/'        ;Should be either '/'
  327.     je    @process_args_10 ;
  328.     cmp    al,'-'        ; or '-'
  329.     jne    short @process_args_5    ;Else error
  330.  
  331. @process_args_10:            ;Saw a valid switch char
  332.     lodsb                ;AL = option letter
  333.     or    al,32            ;Lowercase (non alphabetic will be
  334.                     ; ignored anyway)
  335.     cmp    al,'u'            ;Uninstall option ?
  336.     jne @process_args_13  ;No
  337.     or    cx,cx            ;Ok if no more chars in arg
  338.     jne    short @process_args_5    ;Else error
  339.  
  340. @process_args_11:
  341.     or    argflags,uninstall_arg    ;Indicate /U seen
  342.     jmp    @process_args_50    ;Return
  343.  
  344. ; process_args_13 added by dfa
  345. @process_args_13:
  346.     cmp al,'c'          ;swap cursor types option ?
  347.     jne @process_args_13b    ;No
  348.     jcxz    @process_args_13_a  ;Ok if no more chars in arg
  349.     jmp short @process_args_5   ;Else error
  350. @process_args_13_a:
  351.     mov cursor_type,1        ;Swap insert/overtype cursor mode
  352.     jmp @process_args_50    ;Return
  353.  
  354. @process_args_13b:
  355.     cmp al,'k'          ;Use ESC key for filename completion (as well as TAB)
  356.     jne @process_args_11_a    ;No
  357.     jcxz    @process_args_13b_a  ;Ok if no more chars in arg
  358.     jmp short @process_args_5   ;Else error
  359. @process_args_13b_a:
  360.     mov cx,TAB_key_function
  361.     mov ESC_key_function,cx  ;Make ESC do same as TAB
  362.     or  argflags,esc_arg ;Remember we've seen this option
  363.     jmp @process_args_50    ;Return
  364.  
  365. @process_args_11_a:
  366.     cmp    al,'i'            ;insert mode option ?
  367.     jne @process_args_14    ;No
  368.     jcxz    @process_args_12    ;Ok if no more chars in arg
  369. @process_args_5:
  370. ; Error processing
  371.     @DispStr option_error
  372.     mov    ax,-1
  373.     jmp    abort_install
  374. @process_args_12:
  375.     mov    default_imode,1        ;Change default insrt mode
  376.     jmp    @process_args_50    ;Return
  377.  
  378. @process_args_14:
  379.     cmp    al,'g'            ;silent mode option ?
  380.     jne    @process_args_15    ;No
  381.     jcxz    @process_args_14_a    ;Ok if no more chars in arg
  382.     jmp    short @process_args_5    ;Else error
  383. @process_args_14_a:
  384.     mov    silent,1        ;Silent mode
  385.     jmp    @process_args_50    ;Return
  386. @process_args_15:
  387.     cmp    al,'r'            ;auto-recall option ?
  388.     jne    @process_args_18    ;No
  389.     jcxz    @process_args_16    ;Ok if no more chars in arg
  390.     jmp    short @process_args_5    ;Else error
  391. @process_args_16:
  392.     mov    auto_recall,1        ;Set auto-recall mode
  393.     jmp    @process_args_50    ;Return
  394. @process_args_18:
  395.     cmp    al,'e'            ;Enable dir commands option?
  396.     jne    @process_args_18_b    ;No
  397.     jcxz    @process_args_18_a    ;OK if no more chars
  398.     jmp    short @process_args_5    ;Else error
  399. @process_args_18_a:
  400.     mov    enable_dircmds,1    ;enable directory commands
  401.     jmp    @process_args_50    ;Return
  402. @process_args_18_b:
  403.     cmp    al,'p'            ;ignore character option
  404.     jne @process_args_18_c
  405.     cmp    cx,1            ;Should be only one more char
  406.     jne    @process_args_5        ;Error
  407.     lodsb
  408.     or    argflags,ignore_arg    ;Indicate that an ignore char set
  409.     mov    macro_ignore_char,al
  410.     jmp    @process_args_50    ;Return
  411. @process_args_18_c:     ;added by dfa
  412.     cmp al,'t'          ;disable macro and symbol translation
  413.     jne @process_args_18_e
  414.     jcxz    @process_args_18_d  ;OK if no more chars
  415.     jmp short @process_args_5   ;Else error
  416. @process_args_18_d:     ;added by dfa
  417.     mov disable_macro,1 ;disable (will toggle option later if installed)
  418.     jmp @process_args_50    ;Return
  419. @process_args_18_e:     ;added by dfa
  420.     cmp al,'w'          ;alternate error message display
  421.     jne @process_args_18_g
  422.     jcxz    @process_args_18_f  ;OK if no more chars
  423.     jmp short @process_args_5   ;Else error
  424. @process_args_18_f:     ;added by dfa
  425.     mov msg_flag,1 ;disable (will toggle option later if installed)
  426.     jmp @process_args_50    ;Return
  427. @process_args_18_g:     ;added by dfa
  428.     cmp al,'o'          ;do not install
  429.     jne @process_args_18_i
  430.     jcxz    @process_args_18_h  ;OK if no more chars
  431.     jmp @process_args_5   ;Else error
  432. @process_args_18_h:     ;added by dfa
  433.     or argflags,not_inst_arg
  434.     jmp @process_args_50    ;Return
  435. @process_args_18_i:     ;added by dfa
  436.     cmp al,'z'          ;disable CMDEDIT
  437.     jne @process_args_18_k
  438.     jcxz    @process_args_18_j  ;OK if no more chars
  439.     jmp @process_args_5   ;Else error
  440. @process_args_18_j:     ;added by dfa
  441.     mov cmdedit_disable,1; (will toggle option later if installed)
  442.     jmp @process_args_50    ;Return
  443. @process_args_18_k:     ;added by dfa
  444.     cmp al,'n'          ;disable CMDEDIT
  445.     jne @process_args_19
  446.     jcxz    @process_args_18_l  ;OK if no more chars
  447.     jmp @process_args_5   ;Else error
  448. @process_args_18_l:     ;added by dfa
  449.     or argflags,no_check_arg
  450.     jmp @process_args_50    ;Return
  451.  
  452. @process_args_19:
  453.     cmp    al,'f'            ;Is it the macro file option ?
  454.     jne    @process_args_20
  455.     test    argflags,filearg    ;Already seen file argument ?
  456.     je    @process_args_19_a    ;No, then update
  457.     jmp    @process_args_50    ;Yes, then don't update
  458. @process_args_19_a:
  459.     or  argflags,filearg    ;Remember we've seen this option
  460.     ; (dfa) following 4 lines used to be just one: jcxz    @process_args_50
  461.     cmp cx,0       ;If 0 count, no file to be read
  462.     jne @process_args_19_a1
  463.     jmp @process_args_50
  464. @process_args_19_a1:
  465.     cmp    cx,63            ;Max path length must be < 64
  466.     jna @process_args_19_b  ;dfa changed ja @process_args_5 to these 3 lines.
  467.     jmp  @process_args_5     ;Error
  468. @process_args_19_b:
  469.     mov    di,offset mfilename    ;Temp storage for filename
  470.     rep    movsb            ;Copy file name
  471.     mov    byte ptr [di],0        ;Terminate with a NULL char
  472.     mov    mfile_seen,1        ;Indicate that init file specified
  473.     jmp @process_args_50    ;(dfa): was a short jump
  474. @process_args_20:
  475.     push    ax        ;Save the option letter
  476.     xchg    ax,cx        ;AX = num of char
  477.     call    near ptr aton    ;All other options are numeric values
  478.     jnc    @process_args_22 ;No Errors
  479.     jmp    @process_args_5            ;Error
  480. @process_args_22:
  481. ;AX contains numeric value
  482.     xchg    ax,cx        ;CX = numeric value
  483.     pop    ax        ;Restore option letter
  484.  
  485. ;next 4 lines added by dfa
  486.     cmp al,'l'      ;Is it the minimum length option ?
  487.     jne @process_args_25
  488.     test    argflags,length_arg ;Already seen argument ?
  489.     jne @process_args_50 ;Yes, then don't update
  490.     or  argflags,length_arg ;Remember we've seen this option
  491.     mov min_length,cx
  492.     jmp short @process_args_50
  493.     cmp    al,'d'        ;Is it the dos history size option ?
  494.     jne    @process_args_25
  495.     test    argflags,dosarg ;Already seen argument ?
  496.     jne    @process_args_50 ;Yes, then don't update
  497.     or    argflags,dosarg ;Remember we've seen this option
  498.     mov    dossize,cx
  499.     jmp short @process_args_50
  500. @process_args_25:
  501.     cmp    al,'m'        ;Is it the macro buf size option ?
  502.     jne    @process_args_35
  503.     test    argflags,macroarg ;Already seen argument ?
  504.     jne    @process_args_50 ;Yes, then don't update
  505.     or    argflags,macroarg ;Remember we've seen this option
  506.     mov    macrosize,cx
  507.     jmp    short @process_args_50
  508.  
  509. @process_args_35:
  510.     cmp    al,'b'        ;Is it the symbol buf size option ?
  511.     jne    @process_args_40
  512.     test    argflags,symarg ;Already seen argument ?
  513.     jne    @process_args_50 ;Yes, then don't update
  514.     or    argflags,symarg ;Remember we've seen this option
  515.     mov    symsize,cx
  516.     jmp    short @process_args_50
  517.  
  518. @process_args_40:
  519.     cmp    al,'s'        ;Is it the dir stack option ?
  520.     je    @process_args_55 ;Yes
  521.     jmp    @process_args_5  ;Invalid arg
  522. @process_args_55:
  523.     test    argflags,dirarg ;Already seen argument ?
  524.     jne    @process_args_50 ;Yes, then don't update
  525.     or    argflags,dirarg ;Remember we've seen this option
  526.     mov    dirsize,cx
  527.     
  528. @process_args_50:
  529.  
  530.     @restore
  531.     ret
  532. process_args endp
  533.  
  534.  
  535. ;+
  536. ; FUNCTION : aton
  537. ;
  538. ;    Returns the positive integer value of an ASCII string. The value
  539. ;    must be between 0 and 65535. If length of string is 0, then a 0
  540. ;    value is returned with no error flags.
  541. ;
  542. ; Parameters:
  543. ;    SI    := address of first character in string
  544. ;    AX    := count of characters
  545. ;
  546. ; Returns:
  547. ;    AX = 16 bit result if no errors.
  548. ;    CF = 1 if error (magnitude too large, invalid character etc.)
  549. ;         0 if no errors.
  550. ; Register(s) CX,DX  are destroyed.
  551. ;-
  552. aton    proc    near
  553.     @save    si,di
  554.     xor    di,di        ;Result
  555.     xchg    ax,cx        ;CX <- num of chars
  556.     jcxz    @aton_99    ;No chars, result = 0 (CF is also 0)
  557.     cmp    cx,6        ;Shouldn't be more'n 5 chars
  558.     cmc            ;CF=1 if error
  559.     jb    @aton_99    ;Error exit
  560. @aton_10:
  561.     lodsb            ;al = char
  562.     sub    al,'0'        ;Is ASCII value < '0'
  563.     jb    @aton_99
  564.     mov    dx,9        ;Comparison with 9, NOT '9'
  565.     cmp    dl,al
  566.     jb    @aton_99    ;Not valid char
  567.     xor    ah,ah
  568.     inc    dx        ;DX = 10 (multiplier)
  569.     xchg    ax,di        ;ax = result so far
  570.     mul    dx        ;Multiply by 10
  571.     jb    @aton_99    ;Overflow
  572.     add    ax,di        ;Add new character
  573.     jb    @aton_99    ;Overflow
  574.     xchg    ax,di        ;Remember new result in di
  575.     loop    @aton_10    ;Go onto next char
  576. @aton_99:
  577.     xchg    ax,di
  578.     @restore
  579.     ret
  580. aton    endp
  581.  
  582.  
  583. ;+
  584. ; FUNCTION : get_dosversion
  585. ;
  586. ;
  587. ; Stores DOS major and minor versions in dos_version_major and
  588. ; dos_version_minor.
  589. ;-
  590. get_dosversion proc near
  591.     mov    ah,30h
  592.     int    21h
  593.     mov    dos_version_major,al
  594.     mov    dos_version_minor,ah
  595.     ret
  596. get_dosversion endp
  597.  
  598.  
  599.  
  600.  
  601. ;+
  602. ; FUNCTION : abort_install
  603. ;
  604. ;    Called to abort program before installation. Exits to DOS.
  605. ;
  606. ; Parameters:
  607. ;    AL    = Exit code
  608. ;
  609. ; Returns:
  610. ;    Nothing.
  611. ;
  612. ; Register(s) destroyed:
  613. ;    N/A
  614. ;-
  615. abort_install proc near
  616.     @Exit
  617. abort_install endp
  618.  
  619.  
  620.  
  621. ;+
  622. ; FUNCTION : locate_cmdedit
  623. ;
  624. ;    Called to locate the first copy of CMDEDIT loaded into memory. This
  625. ;    is not foolproof in that if CMDEDIT is loaded into high memory
  626. ;    using one of the memory managers like QEMM, it will not be found.
  627. ;
  628. ; Parameters:
  629. ;    None.
  630. ;
  631. ; Returns:
  632. ;    AX - segment of first copy of CMDEDIT in memory.
  633. ;
  634. ; Register(s) destroyed:
  635. ;    <TBA>
  636. ;-
  637. locate_cmdedit proc near
  638.     mov pgm_name, 99 ; Changes first letter 'C' to 'c' so differs from any
  639.                      ; copy which may also be in memory due to disk caching
  640.                      ; or something similar.  Added by dfa.
  641.     @save    si,di,es
  642. ;    mov di,offset DGROUP:cmdedit    ;SI and DI will used for
  643. ;Line above replaced by dfa to line below so can change signature in
  644. ;running versions.
  645.     mov di,offset DGROUP:pgm_name    ;SI and DI will used for
  646.     mov    si,di                ;comparisons
  647.     xor    ax,ax                ;AX will track segments
  648.  
  649. @locate_cmdedit_5:
  650.     mov    es,ax
  651.     push    si                ;Save offsets that are
  652. ;                         compared 
  653.     mov    cx,32                ;Count to be matched
  654.     rep    cmpsb
  655.     pop    si                ;Restore offsets that are
  656. ;                         compared 
  657.     je    @locate_cmdedit_50        ;Matched
  658.     mov    di,si
  659.     inc    ax
  660.     jmp    short @locate_cmdedit_5        ;Try next segment
  661.  
  662. @locate_cmdedit_50:
  663.  
  664.     @restore
  665.     ret
  666. locate_cmdedit endp
  667.  
  668.  
  669. ;+
  670. ; FUNCTION : uninstall
  671. ;
  672. ;    Called to uninstall a previously loaded copy of CMDEDIT.
  673. ;    The routine does not return. It exits CMDEDIT.
  674. ;
  675. ; Parameters:
  676. ;    None.
  677. ;
  678. ; Returns:
  679. ;    None.
  680. ;
  681. ; Register(s) destroyed:
  682. ;    <TBA>
  683. ;-
  684. uninstall proc near
  685. ; Free up the memory occupied by the previous loaded copy of CMDEDIT.
  686. ; First give back the all interrupts that were taken over.
  687.  
  688. ; Make sure no one else has taken over the 1b break handler since we
  689. ; took it over.
  690.     mov    ax,351bh        ;Retrieve current 1b handler
  691.     int    21h
  692.     cmp    bx,offset our_break_handler ;Is the offset the ours ?
  693.     je    @uninstall_20        ;Yes
  694. @uninstall_10:
  695. ; Someone else's taken over the interrupt. Display message and exit.
  696.     @DispStr msg_unload
  697.     mov    ax,-1
  698.     jmp    abort_install
  699. @uninstall_20:
  700.     mov    ax,es            ;Now compare segment
  701.     cmp    ax,cmdedit_seg        ;Is it what we expect?
  702.     jne    @uninstall_10        ;No, display error
  703.  
  704. ; Now check the int 21h handler.
  705.     mov    ax,3521h        ;Retrieve current 1b handler
  706.     int    21h
  707.     cmp    bx,offset cmdedit_isr    ;Is the offset the ours ?
  708.     jne    @uninstall_10        ;No, error
  709.     mov    ax,es            ;Now compare segment
  710.     cmp    ax,cmdedit_seg        ;Is it what we expect?
  711.     jne    @uninstall_10        ;No, display error
  712.  
  713. ; OK, now restore both interrupts
  714.     mov    es,cmdedit_seg        ;ES<-segment of loaded CMDEDIT
  715.     mov    dx,es:prev_isr1b    ;DS:DX->original 1b handler
  716.     mov    ds,es:prev_isr1b+2
  717.     mov    ax,251bh        ;Return int 1b
  718.     int    21h
  719.  
  720.     mov    dx,es:old_int21vec    ;DS:DX->original int 21h handler
  721.     mov    ds,es:old_int21vec+2
  722.     mov    ax,2521h        ;Return int 21
  723.     int    21h
  724.  
  725.     push    cs
  726.     pop    ds            ;Restore DS
  727. ;
  728. ; Finally, return the block of memory taken up by the previous CMDEDIT copy.
  729.     mov    ah,49h            ;Release block function, ES->segment
  730.     int    21h            ;Free the block
  731.     jnc    @uninstall_90        ;No errors
  732.     @DispStr msg_memerr        ;Memory allocation error !
  733.     mov    ax,-1
  734.     jmp    abort_install
  735.  
  736. @uninstall_90:
  737.     @DispStr msg_uninstalled
  738.     xor    ax,ax
  739.  
  740.     @Exit    0            ;Exit to DOS
  741.  
  742. uninstall endp
  743.  
  744.  
  745. ;+
  746. ; FUNCTION : change_installed_options
  747. ;
  748. ;    Called to change settings on a previously installed copy of
  749. ;    CMDEDIT. The function exits to DOS.
  750. ;
  751. ;    This function allows the following options to be toggled or
  752. ;    changed:
  753. ;        /r - toggles autorecall mode
  754. ;        /i - toggles insert mode
  755. ;        /g - toggles silent mode
  756. ;        /p - sets a new ignore character
  757. ;following added by dfa:
  758. ;       /c - swaps cursor type used for insert & overtype modes.
  759. ;       /w - alternate error message display
  760. ;       /l - sets the minimum command line size stored in history buffer
  761. ;       /t - toggles macro and symbol translation off/on
  762. ;       /z - toggles CMDEDIT disable
  763. ;
  764. ;If any other option (except /n or /o) is specified, error message is displayed.
  765. ;    
  766. ; Parameters:
  767. ;    None.
  768. ;
  769. ; Returns:
  770. ;    Nothing.
  771. ;
  772. ; Register(s) destroyed:
  773. ;    <TBA>
  774. ;-
  775.  
  776. change_installed_options proc near
  777.     @DispStr msg_dup
  778.     mov ax,argflags        ;(dfa): was al here ,  but argflags is now a WORD.
  779.     and ax,NOT ignore_arg
  780.     and ax,NOT length_arg   ;added by dfa.  This option is also allowed.
  781.     and ax,NOT not_inst_arg ;added by dfa.  This option is also allowed.
  782.     je    @change_installed_options_10
  783. ; Unallowed options specified.
  784.     @DispStr options_dup
  785.     mov    ax,-1
  786.     jmp    abort_install
  787.  
  788. @change_installed_options_10:
  789.     @DispCh LF
  790. ; Change the options specified.
  791.     mov    es,cmdedit_seg        ;ES->segment of previously loaded
  792. ;                     CMDEDIT 
  793. ; First toggle the insert mode option. If /i specified, default_imode will
  794. ; be 1, else 0. Thus just xor it with the memory resident copy to toggle
  795. ; default mode.
  796.     mov    al,es:default_imode
  797.     xor    al,default_imode    
  798.     mov    es:default_imode,al    ;Toggle memory resident option
  799.     or    al,al
  800.     je    @change_installed_options_15
  801.     @DispStr msg_imode
  802.     jmp short @change_installed_options_17
  803. @change_installed_options_15:
  804.     @DispStr msg_omode
  805.  
  806. @change_installed_options_17:
  807. ;Cursor type toggle (added by dfa)
  808.     mov al,es:cursor_type
  809.     xor al,cursor_type
  810.     mov es:cursor_type,al    ;Toggle memory resident option
  811.     or  al,al
  812.     je  @change_installed_options_18
  813.     @DispStr msg_scursor_type
  814.     jmp short @change_installed_options_20
  815. @change_installed_options_18:
  816.     @DispStr msg_dcursor_type
  817.  
  818. @change_installed_options_20:
  819.     mov    al,es:auto_recall
  820.     xor    al,auto_recall
  821.     mov    es:auto_recall,al    ;Toggle memory resident option
  822.     or    al,al
  823.     jne    @change_installed_options_25
  824.     @DispStr msg_disable_autorecall
  825.     jmp    short @change_installed_options_30
  826. @change_installed_options_25:
  827.     @DispStr msg_enable_autorecall
  828.  
  829. @change_installed_options_30:
  830. ; And now for silent mode
  831.     mov    al,es:silent
  832.     xor    al,silent
  833.     mov    es:silent,al    ;Toggle memory resident option
  834.     or    al,al
  835.     je    @change_installed_options_35
  836.     @DispStr msg_disable_bell
  837.     jmp    short @change_installed_options_40
  838. @change_installed_options_35:
  839.     @DispStr msg_enable_bell
  840.  
  841. @change_installed_options_40:
  842.  
  843. ; Change the ignore character if one was specified.
  844.     test    argflags,ignore_arg
  845.     je  @change_installed_options_50 ;None specified
  846. ; Change to the new macro ignore char
  847.     mov    al,macro_ignore_char
  848.     mov    es:macro_ignore_char,al
  849.     @DispStr msg_ignore_char
  850.  
  851. @change_installed_options_50:
  852. ; And now for macro translation toggle
  853.     mov al,es:disable_macro
  854.     xor al,disable_macro
  855.     mov es:disable_macro,al    ;Toggle memory resident option
  856.     or  al,al
  857.     je  @change_installed_options_55
  858.     @DispStr msg_disable_macro
  859.     jmp short @change_installed_options_57
  860. @change_installed_options_55:
  861.     @DispStr msg_enable_macro
  862.  
  863. @change_installed_options_57:
  864. ; alternative error message display
  865.     mov al,es:msg_flag
  866.     xor al,msg_flag
  867.     mov es:msg_flag,al    ;Toggle memory resident option
  868.     or  al,al
  869.                           ;not really necessary to confirm this switch.
  870.  
  871. @change_installed_options_60:
  872. ; And now for minimum line length option if one was specified.
  873.     test    argflags,length_arg
  874.     je  @change_installed_options_70 ;None specified
  875.     mov ax,min_length
  876.     cmp ax,es:min_length    ;Is new value different from old?
  877.     je  @change_installed_options_70 ;no
  878.     mov es:min_length,ax    ;Change memory resident value
  879.     @DispStr msg_length_changed
  880.  
  881. @change_installed_options_70:
  882. ; And now for disable CMDEDIT toggle
  883.     mov al,es:cmdedit_disable
  884.     xor al,cmdedit_disable
  885.     mov es:cmdedit_disable,al    ;Toggle memory resident option
  886.     or  al,al
  887.     je  @change_installed_options_75
  888.     @DispStr msg_disable
  889.     jmp short @change_installed_options_90
  890. @change_installed_options_75:
  891.     @DispStr msg_enable
  892.  
  893. @change_installed_options_90:
  894. ; All done
  895.     @Exit    0
  896.  
  897. change_installed_options endp
  898.  
  899.  
  900.  
  901.  
  902. CSEG    ENDS
  903.  
  904.     END
  905.