home *** CD-ROM | disk | FTP | other *** search
- program ChMod;
-
- (*--------------------------------------------------------------------*)
- (* This program changes the attribute of a file(s). It will *)
- (* accept drive, path and wildcard characters in the filename. *)
- (* *)
- (* Users of the incremental back-up method for hard disks may *)
- (* find this program especially useful when a number of files *)
- (* have been updated since the last back-up but are not wanted *)
- (* to be backed-up. The author is a user of Symphony and updates *)
- (* a number of .PIC files weekly but does not want them backed- *)
- (* up when doing his incremental back-up. Thus by executing *)
- (* CHMOD C:\SYMPHONY\*.PIC N turns off the archive bit in all *)
- (* of the .PIC files' attributes. *)
- (* *)
- (* Usage : *)
- (* ALTER FILENAME Attributes '); *)
- (* FILENAME - will accept drive,path & wildcard characters*)
- (* Attributes - R : Read only *)
- (* - S : System *)
- (* - H : Hidden *)
- (* - A : Archive *)
- (* - N : Normal(turns off all bits) *)
- (* ==> Use spaces to delimit filename and attributes *)
- (* EXAMPLE : ChMod C:\DOG\DOG.* R H *)
- (* ==> If no attributes are passed then file(s) attributes *)
- (* will be listed. *)
- (* ==> If no filename or invalid syntax is passed, a usage *)
- (* message is displayed(similiar to above format). *)
- (* *)
- (* This program may be freely distributed and changed to fit *)
- (* your needs. If you make changes and subsequently distribute *)
- (* ChMod, please make note of your changes in this program. *)
- (* *)
- (* A product of DOGWARE by DR. DOG - 1985. *)
- (*--------------------------------------------------------------------*)
-
- Label Quit;
-
- type
- RegPack = Record
- ax,bx,cx,dx,bp,si,di,ds,es,flags : integer;
- End;
-
- type
- FILREC = Record (* DTA layout *)
- ForD : array[1..21]of byte; (* reserved for DOS *)
- Attr : byte; (* file attribute *)
- Time : array[1..2] of Byte; (* file time *)
- Date : array[1..2] of Byte; (* file date *)
- Size : array[1..4] of byte; (* file size *)
- Name : array[1..13] of Char; (* file name *)
- Fill : array[1..85] of byte; (* filler - ????? *)
- End;
-
- var
- CmdLine : string[80] absolute Cseg:$80; (* input to ChMod *)
- ASC : String[80]; (* ASCIIZ string *)
- FIL : FILREC;
- Regs : RegPack;
- ATR : byte;
- I : integer;
- Drive : string[2]; (* Drive + ':' *)
- Path : string[80]; (* path *)
- DSN : string[80]; (* filename *)
- List : Boolean;
-
- Procedure ParseFileName; (* scan for drive and path *)
- Label Exit;
- Begin
- Drive := '';
- Path := '';
- If pos(':',ASC) = 2 then Drive := Copy(ASC,1,2) else goto Exit;
- If pos('\',ASC) <> 0 then
- Begin
- Path := ASC;
- Delete(Path,1,2); (* get rid of drive: *)
- I := Length(Path);
- Repeat
- delete(Path,I,1);
- I := I -1;
- until (Path[I] = '\') or (I = 0);
- end;
- Exit:
- End;
-
- Procedure DTA; (* set DTA transfer address *)
- Begin
- Regs.Ax := $1A00;
- Regs.DX := ofs(fil);
- Regs.DS := Dseg;
- Intr($21,regs);
- End;
-
- Procedure GetFirst; (* search for 1st matching enter *)
- Begin
- Regs.Ax := $4E00;
- Regs.Cx := $37;
- Regs.DX := ofs(ASC) + 1;
- Regs.DS := Dseg;
- Intr($21,regs);
- End;
-
- Procedure SetAttr; (* set file attribute *)
- Begin
- DSN := Drive + Path;
- I := 1;
- repeat
- DSN := DSN + Fil.Name[I];
- I := I + 1;
- until (Fil.Name[I] = #$00) or (I = 14);
- DSN[length(DSN)+1] := Chr($0);
- if not list then Regs.Ax := $4301 else Regs.Ax := $4300;
- Regs.Cx := ATR;
- Regs.Dx := Ofs(dsn) + 1;
- Regs.DS := Dseg;
- Intr($21,regs);
- End;
-
- Procedure GetNext; (* get next matching entry *)
- Begin
- Regs.ax := $4f00;
- Intr($21,regs);
- End;
-
- Procedure SyntaxErr; (* syntax/help *)
- Begin
- Writeln('ChMod FILENAME Attributes ');
- Writeln(' FILENAME - will accept drive, path and wildcard characters');
- Writeln(' Attributes - R : Read only');
- Writeln(' - S : System');
- Writeln(' - H : Hidden');
- Writeln(' - A : Archive');
- Writeln(' - N : Normal(turns off all bits)');
- Writeln('use spaces to delimit filename and attributes');
- Writeln('EXAMPLE : ChMod C:\DOG\DOG.* R H');
- Writeln('If no attributes are passed then file(s) attributes will be listed');
- End;
-
- Begin (* Main driver starts here *)
- gotoxy(1,25);
- Writeln(' DogWare by Dr. Dog - 1985');
- Writeln(' ');
- If (length(cmdline) = 0) or (Pos(' ',cmdline) = 0) then
- Begin
- SyntaxErr;
- goto Quit;
- end;
- repeat
- delete(cmdline,1,1);
- until (pos(' ',cmdline) <> 1) or (length(cmdline) = 0);
- If pos(' ',cmdline) <> 0 then
- Begin
- ASC := Copy(cmdline,1,(pos(' ',cmdline)-1));
- Delete(cmdline,1,length(ASC) + 1);
- List := False
- End
- Else
- Begin
- ASC := Cmdline;
- List := True;
- End;
- ASC[length(ASC)+1] := chr($0);
- Atr := $0;
- I := length(cmdline);
- If not List then
- Begin
- Repeat
- If cmdline[I] <> ' ' then
- Begin
- Case upcase(CmdLine[I]) of
- 'R' : Atr := Atr OR $01;
- 'H' : Atr := Atr OR $02;
- 'S' : Atr := Atr OR $04;
- 'A' : Atr := Atr OR $20;
- 'N' : Atr := Atr OR $FF;
- else
- Begin
- SyntaxErr;
- goto Quit;
- End;
- End;
- End;
- I := I - 1;
- until I = 0;
- End;
- If Atr = $0 then List := True;
- If Atr = $FF then Atr := $0;
- ParseFileName;
- DTA;
- GetFirst;
- If Lo(Regs.AX) <> 0 then
- Begin
- Writeln(ASC,' not found');
- goto Quit;
- End;
- Repeat
- If Fil.name[1] = '.' then repeat GetNext until Fil.Name[1] <> '.';
- SetAttr;
- If not list then
- Begin (* NOTE: Carry flag MUST be checked in DOS 3.0! *)
- Regs.flags := Regs.Flags AND $0001; (* get carry flag *)
- if (lo(regs.ax) in [0,255]) or (Regs.Flags = 0) then
- Writeln(DSN,' attribute changed')
- else
- Writeln(DSN,' attribute NOT CHANGED, return code = ',lo(regs.ax));
- End
- Else
- Begin
- Write(DSN,' attribute is ');
- If Regs.CX = 0 then Write('Normal ');
- If Regs.CX AND $20 <> 0 then Write('Archive ');
- If Regs.CX AND $10 <> 0 then Write('Sub-Directory ');
- If Regs.CX AND $08 <> 0 then Write('Label ');
- If Regs.CX AND $04 <> 0 then Write('System ');
- If Regs.CX AND $02 <> 0 then Write('Hidden ');
- If Regs.CX AND $01 <> 0 then Write('Read-Only ');
- Writeln(' ');
- End;
- GetNext;
- until lo(regs.ax) <> 0;
- Quit:
- Writeln('ChMod Program terminated');
- End.
-