home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PROGRAMS / UTILS / DOS_HELP / ADVMSDOS.ZIP / MARK.ASM < prev    next >
Encoding:
Assembly Source File  |  1986-06-19  |  6.4 KB  |  254 lines

  1.     name    mark
  2.     page    55,132
  3.     title    'MARK --- set attribute of file'
  4.  
  5. ;
  6. ; MARK --- Utility to set attribute of file.
  7. ; Copyright (C) 1983 Ray Duncan
  8. ;
  9. ; Requires PC-DOS or MS-DOS 2.0 or greater for execution.
  10. ;
  11. ; Program is called by command of the form: 
  12. ;
  13. ;         C>MARK  path\file.ext  /x
  14. ;
  15. ; where x=R for read-only, H for hidden,
  16. ; or N for normal (all attrib bits off).  
  17. ; To assemble, link, and convert this program into 
  18. ; an EXE file, follow these steps:
  19. ;
  20. ;    C>MASM MARK;
  21. ;     C>LINK MARK;
  22. ;
  23.  
  24. cr    equ    0dh        ;ASCII carriage return
  25. lf    equ    0ah        ;ASCII line feed
  26. eom    equ    '$'        ;end of message flag 
  27.  
  28. command    equ    80h        ;Command line buffer
  29.  
  30. rd_only    equ     01h        ;file attributes
  31. hidden    equ    02h        
  32. system    equ    04h
  33. volume    equ    08h
  34. subdir    equ    10h
  35. archive    equ    20h
  36.  
  37.  
  38. cseg    segment    para public 'CODE'
  39.  
  40.     assume    cs:cseg,ds:data,es:data,ss:stack
  41.  
  42.  
  43. mark    proc    far        ;entry point from PC-DOS
  44.  
  45.     push    ds        ;save DS:0000 for final
  46.     xor    ax,ax        ;return to PC-DOS
  47.     push    ax
  48.     mov    ax,data        ;make our data segment addressable
  49.     mov    es,ax        ;via the ES register
  50.     call    infile        ;get path and name for
  51.                 ;file to be modified. 
  52.     jnc    mark1        ;jump if filename was ok
  53.     mov    dx,offset msg1    ;filename absent or illegal,
  54.     call    error        ;print error message and exit
  55.     ret
  56.  
  57. mark1:                ;filename was ok, now try
  58.     call    get_switch    ;and find the switch
  59.     jnc    mark2        ;jump if switch was ok
  60.     mov    dx,offset msg7    ;missing switch, print error
  61.     call    error        ;message and exit
  62.     ret            
  63.  
  64. mark2:                ;found legal switch, now 
  65.     push    dx        ;save addr of success message
  66.     mov    ax,es        ;make our data segment addressable
  67.     mov    ds,ax        ;via the DS register
  68.                 ;CX=attrib bits, 
  69.                 ; already set by "get_switch"
  70.                 ;DS:DX=addr of filename
  71.     mov    dx,offset input_name
  72.     mov    ah,43h        ;function 43h=CHMOD
  73.     mov     al,01        ;AL=01 for set attrib
  74.     int    21h        ;make request to PC-DOS
  75.     jnc    mark3        ;if CY=0 jump, successful call
  76.                 ;if CY=1 call failed,     
  77.     pop    dx        ;clean up stack, and
  78.     mov    dx,offset msg2    ;print error message
  79.     call    error
  80.     ret
  81.  
  82. mark3:                ;attribute was modified,
  83.     mov    dx,offset msg3    ;print 1st part of success message
  84.     mov    ah,9
  85.     int    21h
  86.                 ;print filename
  87.     mov    dx,offset input_name
  88.     call    pasciiz 
  89.     pop    dx        ;print last part of success msg.
  90.           mov    ah,9        
  91.     int    21h        
  92.     
  93.     ret            ;final exit to PC-DOS
  94. mark    endp
  95.  
  96.  
  97. pasciiz    proc    near        ;print the ASCIIZ string
  98.                 ;whose offset is in DX on
  99.                 ;the standard output device.
  100.                 ;Regs AX, BX also destroyed.
  101.     mov    bx,dx        ;let BX=offset of string
  102. pasciiz1:
  103.     mov    dl,[bx]        ;get next char from string
  104.     or    dl,dl        ;if char.=zero,end of string
  105.     jz    pasciiz9    ;jump if end
  106.     cmp    dl,'A'        ;if it is an upper-case alpha
  107.     jb    pasciiz2    ;character,fold to lower case
  108.     cmp    dl,'Z'        ;Note: Inclusive Or of an alpha
  109.     ja    pasciiz2    ;ASCII character with 20h has the
  110.     or    dl,20h        ;effect of folding to lower case.
  111. pasciiz2:
  112.     mov    ah,2        ;function 2=output char.
  113.     int    21h        ;request output by PC-DOS
  114.     inc    bx        ;advance to next string position
  115.     jmp    short pasciiz1
  116. pasciiz9:            ;done with string output,
  117.     ret            ;return to caller
  118. pasciiz endp
  119.  
  120.  
  121. infile    proc    near        ;Capture the name of a file
  122.                 ;from the command tail buffer
  123.                 ;where it was left by PC-DOS,
  124.                 ;transferring it into a local
  125.                 ;buffer in the form of an
  126.                 ;ASCIIZ string.
  127.  
  128.                 ;DS:SI <-  addr of command tail
  129.     mov    si,offset command
  130.                 ;ES:DI <-  addr of local buffer
  131.     mov    di,offset input_name
  132.     cld            ;make sure direction flag cleared
  133.     lodsb            ;first check count byte to make
  134.     or    al,al        ;sure command tail is present
  135.     jz    infile4        ;return error status if not.
  136. infile1:            ;scan over leading blanks to
  137.     lodsb            ;find the path and filename
  138.     cmp    al,cr        ;if we run into carriage return,
  139.     jz    infile4        ;filename is missing so exit.
  140.     cmp    al,20h        ;if this char is a blank,
  141.     jz    infile1        ;keep scanning.
  142. infile2:            ;found 1st char of name, 
  143.     stosb            ;transfer the name to local buffer.
  144.     lodsb            ;check next character, found
  145.     cmp    al,cr        ;end of string yet?
  146.     je    infile3        ;yes if either carriage return
  147.     cmp    al,20h     
  148.     jne    infile2
  149. infile3:            ;path and filename successfully 
  150.     xor    al,al        ;transferred to local buffer,
  151.     stosb            ;store 0 byte at end of string
  152.     clc            ;and exit with Carry flag =0
  153.     ret
  154. infile4:            ;some type of error was detected
  155.     stc            ;so exit with Carry flag =1
  156.     ret
  157. infile    endp
  158.  
  159.  
  160. get_switch proc    near        ;Scan the input line for a "/"
  161.                 ;delimiting a switch, then make
  162.                 ;sure it is legal.  
  163.                 ;Return CY=0 if legal switch, and
  164.                 ;CX=attrib byte, DX=msg addr
  165.                 ;Return CY=1 if switch no good 
  166.     mov    si,offset command+1  ; DS:SI = addr of command line
  167. get_switch1:            ;look for "/" character
  168.     lodsb
  169.     cmp    al,cr        ;if we run into a carriage return,
  170.     jz    get_switch9     ;switch missing so take error exit.
  171.     cmp    al,'/'    
  172.     jne    get_switch1    ;not '/' yet, keep looking.
  173.     lodsb            ;found '/', pick up next char.
  174.     or    al,20h        ;and fold to lower case.
  175.     cmp    al,'r'        ;R = read only
  176.     jne    get_switch2     ;not R, jump
  177.     mov    cx,rd_only    ;R so set read only attrib bit
  178.     mov    dx,offset msg5
  179.     ret            ;return CY=0 for success
  180. get_switch2:            ;check for H=hidden
  181.     cmp    al,'h'
  182.     jne    get_switch3    ;not H, jump
  183.     mov    cx,hidden    ;H so set hidden attrib bit
  184.     mov    dx,offset msg4
  185.     ret            ;return CY=0 for success
  186. get_switch3:            ;check for N=normal
  187.     cmp    al,'n'
  188.     jne    get_switch9    ;not N,jump to error exit
  189.     mov    cx,0        ;clear all attrib bits
  190.     mov    dx,offset msg6
  191.     ret            ;return CY=0 for success
  192. get_switch9:            ;missing or illegal switch,
  193.     stc            ;return CY flag=1 as alarm
  194.     ret
  195. get_switch endp
  196.  
  197.  
  198. error    proc    near        ;print error message
  199.     mov    ax,data        ;make sure data area addressable
  200.     mov    ds,ax
  201.     mov    ah,9        ;print error type
  202.     int    21h
  203.     mov    dx,offset helpmsg
  204.     mov    ah,9        ;also print HELP information
  205.     int    21h
  206.     ret            ;back to caller
  207. error    endp
  208.  
  209.  
  210. cseg    ends
  211.  
  212.  
  213. data    segment    para public 'DATA'
  214.  
  215. input_name db    64 dup (0)    ;buffer for path and file name
  216.  
  217. msg1    db    cr,lf
  218.     db    'Missing file name.',eom
  219.  
  220. msg2    db    cr,lf
  221.     db    'File not found.',eom
  222.  
  223. msg3    db    cr,lf
  224.     db    'Attribute of file ',eom
  225.  
  226. msg4    db    ' has been set to Hidden.'
  227.     db    cr,lf,eom
  228.  
  229. msg5    db    ' has been set to Read-Only.'
  230.     db    cr,lf,eom
  231.  
  232. msg6    db    ' has been set to Normal.'
  233.     db    cr,lf,eom
  234.  
  235. msg7    db    cr,lf
  236.     db    'Missing or illegal switch.',eom
  237.  
  238. helpmsg    db    '  Command should be in the form: '
  239.     db    cr,lf,lf
  240.     db    '  MARK filename /x'
  241.     db    cr,lf,lf
  242.     db    'x=N for normal, R for read-only, H for hidden.'
  243.     db    cr,lf,eom
  244.  
  245. data    ends
  246.  
  247.  
  248. stack    segment    para stack 'STACK'
  249.     db    64 dup (?) 
  250. stack    ends
  251.  
  252.     end    mark
  253.