home *** CD-ROM | disk | FTP | other *** search
/ ftp.shrubbery.net / 2015-02-07.ftp.shrubbery.net.tar / ftp.shrubbery.net / pub / pc / unix / unx.arc / SETDIR.ASM < prev    next >
Assembly Source File  |  1985-06-10  |  2KB  |  113 lines

  1.     page    66,132
  2.     ;  narrow print
  3.     page
  4.  
  5. ;---- popdir.com ---------------------------------------------------------------
  6. ; Usage: popdir
  7. ; DRK 30 June 84
  8. ; Sets current directory to that in the file %1.
  9. ;------------------------------------------------------------------------------
  10.  
  11.     extrn    _args:near,argc:word,argv:word
  12.  
  13. stderr    equ    2
  14. envadr    equ    2ch
  15.  
  16. code    segment    public 'CODE'
  17. assume cs:code,ds:code
  18.  
  19.     org    100h
  20.  
  21. ; This is a .COM program.
  22. ;
  23. ;
  24. ; procedure Popdir;
  25. ; begin
  26. ;    get command line;
  27. ;    if (argc <> 1) error;
  28. ;    if not fopen(olddir, %1) error;
  29. ;    chdir(readln(olddir));
  30. ;    end;
  31. ;
  32.  
  33. ulen    =    fmsg - umsg
  34. flen    =    bmsg - fmsg
  35. blen    =    zmsg - bmsg
  36. odlen    equ    7        ; note: if this is placed AFTER its use,
  37.                 ; assembler generates NOP after inst using it!
  38.  
  39. popd    proc    near
  40.     ; Get arguments.
  41.     call    _args
  42.  
  43.     ; Check # of arguments- if not exactly zero, send usage message.
  44.     mov    cx, ulen
  45.     lea    dx, umsg
  46.     cmp    argc,1
  47.     jnz    error
  48.  
  49.     ; Locate the file.
  50.     mov    ax, 3d00h        ; open it for reading
  51.     mov    dx, argv[2]
  52.     int    21h
  53.     mov    cx, flen
  54.     lea    dx, fmsg
  55.     jc    error            ; file not found- return error msg.
  56.  
  57.     ; Search succeeded.  AX contains the file's handle.
  58.     ; Set the directory according to the file contents.
  59.     mov    bx,ax            ; want handle in BX
  60.     mov    ah, 3fh
  61.     mov    cx, 64            ; don't want > 64 char
  62.     mov    dx, 80h            ; put data on top of args for now
  63.     int    21h            ; do the read
  64.     mov    cx,flen
  65.     mov    dx,offset fmsg
  66.     jc    error
  67.  
  68.     ; Turn carriage return into null (assume file created by CD > file.)
  69.     mov    si, 80h
  70.     mov    cx, ax        ; ax is # of bytes read in above fn call
  71. loopc:    lodsb
  72.     cmp    al, 13
  73.     loopnz    loopc        ; it must happen before end of data read in...
  74.  
  75.     mov    byte ptr [si-1], 0    ; put null on top of carriage return
  76.  
  77.     ; Finally, set the directory.
  78.     mov    dx, 80h
  79.     mov    ah, 3bh        ; CHDIR
  80.     int    21h
  81.     mov    cx, blen
  82.     lea    dx, bmsg
  83.     jc    error
  84.  
  85.     ; We're done.  Set errorlevel to zero.
  86.     mov    al, 0
  87.  
  88. exit:    mov    ah, 4ch            ; terminate process
  89.     int    21h
  90.  
  91. error:    ; Jump here with ptr to string in DX, length of string in CX.
  92.     ; String will be printed to screen (even if output is redirected!)
  93.     push    cs
  94.     pop    ds
  95.  
  96.     mov    bx, stderr    ; write to error device...
  97.     mov    ah, 40h
  98.     int    21h
  99.     mov    al, 1        ; some sorta problem here, guys.
  100.     jmp    exit
  101.  
  102. popd    endp
  103.                     
  104. umsg    db    'Usage: setdir filespec', 13, 10
  105. fmsg    db    '?Setdir: couldnt open file', 13, 10
  106. bmsg    db    '?Setdir: file contained invalid directory name', 13, 10
  107. zmsg    db    ?
  108.  
  109. code    ends
  110.  
  111.     end    popd
  112.  
  113.