;---------------------------------------------------------------------------
; CDAPP.COM - Program to change dir/drive in CONFIG.SYS as an INSTALL=
; because OS/2 TrapDoor won't be using a normal COMMAND.COM that would be
; running AUTOEXEC.BAT.  For OS/2 TrapDoor, everything *MUST* be handled
; in CONFIG.SYS.
;
; Usage:  CDAPP  [drive:][path]
;---------------------------------------------------------------------------
; Created 4/14/95 - Tony Ingenoso
;---------------------------------------------------------------------------

cdapp   segment para public 'code'
        assume  cs:cdapp, ds:cdapp, es:cdapp, ss:cdapp
        org     100h

start   label   near
        cld                             ;
        mov     di, 81h                 ; Find 0Dh terminator in command line
        push    di                      ;
        mov     cx, -1                  ;
        mov     al, 0Dh                 ;
        repne   scasb                   ;
        dec     di                      ;
        mov     byte ptr [di], 0        ; Turn it to NULL
        pop     di                      ; DI=0081h

        ; Loop skipping over white space on command line

TryAgain:
        cmp     byte ptr [di], ' '      ; Skip blanks
        je      SkipWhite               ;
        cmp     byte ptr [di], 9        ; Skip TABs
        je      SkipWhite               ;

        ; White space is gone - now we're left with the string.
        ; Is there even a string?

        cmp     byte ptr [di],0         ; Is *anything* there?
        je      WereDone                ; Nope, we hit the NULL...

        ; OK, there's some sort of string, let's CHDIR to it.

        mov     dx, di                  ; DI-->First non-whitespace char
        mov     ah, 3Bh                 ; CHDIR to this string
        int     21h                     ;

        ; Find the drive letter (if present)

        cmp     byte ptr ds:[di+1], ':' ; Drive letter?
        jne     WereDone                ; Nope...

;;;;;;;;cmp     byte ptr ds:[di+2], '\' ; Path sep?
;;;;;;;;jne     WereDone                ; Nope...

        ; Upper case the letter if necessary

        mov     dl,ds:[di]              ; Get drive letter
        cmp     dl, 61h                 ; Lower case?
        jb      ItsUpper                ;
        sub     dl, 20h                 ; Convert to upper case
ItsUpper:

        ; Now normalize it to zero for DOS.

        sub     dl,41h                  ; Normalize to zero for DOS

        ; Now try to change to that drive.

        mov     ah,0Eh                  ; Change to specified drive
        int     21h                     ;

        ; Terminate - nothing stays resident...

WereDone:
        mov     ax, 4C00h               ; Terminate
        int     21h                     ; Exit, RC=0

        ; Skip over a white space character on the command line

SkipWhite:
        inc     di                      ; Move index along...
        jmp     TryAgain                ;

        db      "Copyright (C) 1995 IBM Corp."

cdapp   ends
        end     start
