-
Notifications
You must be signed in to change notification settings - Fork 0
/
ATTR.PAS
191 lines (180 loc) · 5.16 KB
/
ATTR.PAS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
{ @author: Sylvain Maltais ([email protected])
@created: 2023
@website(https://www.gladir.com/os9-0)
@abstract(Target: Turbo Pascal, Free Pascal)
}
Program Attr;
Uses DOS;
Var
Language:(_French,_English,_Germany,_Italian,_Spain);
IsAttrSetting:Array[Byte]of Boolean;
AttrAdd,AttrRemove:Word;
I:Byte;
SubDirectory,ShowChanged:Boolean;
CurrAttr:Word;
TmpLanguage:String;
Function StrToUpper(S:String):String;
Var
I:Byte;
Begin
For I:=1 to Length(S)do Begin
If S[I] in['a'..'z']Then S[I]:=Chr(Ord(S[I])-32);
End;
StrToUpper:=S;
End;
Function Path2Dir(Const Path:String):String;
Var
D:DirStr;
N:NameStr;
E:ExtStr;
Begin
Path2Dir:='';
If Path=''Then Exit;
FSplit(Path,D,N,E);
If E=''Then Begin
If D[Length(D)]<>'\'Then D:=D+'\';
D:=D+E;
End;
If D=''Then Path2Dir:='' Else
If D[Length(D)]<>'\'Then D:=D+'\';
Path2Dir:=D;
End;
Function SetPath4AddFile(Path:String):String;Begin
If Path=''Then GetDir(0,Path);
If Path[Length(Path)]<>'\'Then Path:=Path+'\';
SetPath4AddFile:=Path;
End;
Procedure SetAttribut(Var F:File);
Begin
GetFAttr(F,CurrAttr);
If AttrRemove and ReadOnly=ReadOnly Then CurrAttr:=CurrAttr and Not ReadOnly;
If AttrRemove and Archive=Archive Then CurrAttr:=CurrAttr and Not Archive;
If AttrRemove and Hidden=Hidden Then CurrAttr:=CurrAttr and Not Hidden;
If AttrRemove and SysFile=SysFile Then CurrAttr:=CurrAttr and Not SysFile;
If AttrAdd and ReadOnly=ReadOnly Then CurrAttr:=CurrAttr or ReadOnly;
If AttrAdd and Archive=Archive Then CurrAttr:=CurrAttr or Archive;
If AttrAdd and Hidden=Hidden Then CurrAttr:=CurrAttr or Hidden;
If AttrAdd and SysFile=SysFile THen CurrAttr:=CurrAttr or SysFile;
SetFAttr(F,CurrAttr);
End;
Procedure SetAttributFiles(FileSpec:String);
Var
Info:SearchRec;
CurrFile:File;
Found:Boolean;
Begin
FileSpec:=FExpand(FileSpec);
FindFirst(FileSpec,AnyFile,Info);
Found:=False;
While DOSError=0 do Begin
Found:=True;
If Info.Attr and Directory=Directory Then Begin
If(SubDirectory)Then Begin
If Not((Info.Name='.')or(Info.Name='..')or(Info.Name=''))Then Begin
SetAttributFiles(SetPath4AddFile(Path2Dir(FileSpec)+Info.Name)+'*.*');
End;
End;
End
Else
Begin
Assign(CurrFile,Path2Dir(FileSpec)+Info.Name);
SetAttribut(CurrFile);
If(ShowChanged)Then Begin
If CurrAttr and ReadOnly=ReadOnly Then WriteLn('r')
Else WriteLn(' ');
End;
End;
FindNext(Info);
End;
If Not Found Then WriteLn('Aucun resultat trouve');
End;
Procedure ShowAttribut;
Var
Info:SearchRec;
Begin
FindFirst('*.*',AnyFile and Not Directory,Info);
While DOSError=0 do Begin
If Info.Attr and ReadOnly=ReadOnly Then Write('r') Else Write('-');
If Info.Attr and SysFile=SysFile Then Write('s') Else Write('-');
If Info.Attr and Archive=Archive Then Write('a') Else Write('-');
If Info.Attr and Hidden=Hidden Then Write('h') Else Write('-');
If Info.Attr and VolumeID=VolumeID Then Write('v') Else Write('-');
If Info.Attr and Directory=Directory Then Write('d') Else Write('-');
Write(' ');
WriteLn(Info.Name);
FindNext(Info);
End;
End;
BEGIN
Language:=_French;
TmpLanguage:=GetEnv('LANGUAGE');
If TmpLanguage<>''Then Begin
If TmpLanguage[1]='"'Then TmpLanguage:=Copy(TmpLanguage,2,255);
If StrToUpper(Copy(TmpLanguage,1,2))='EN'Then Language:=_English Else
If StrToUpper(Copy(TmpLanguage,1,2))='GR'Then Language:=_Germany Else
If StrToUpper(Copy(TmpLanguage,1,2))='IT'Then Language:=_Italian Else
If StrToUpper(Copy(TmpLanguage,1,2))='SP'Then Language:=_Spain;
End;
If ParamStr(1)='/?'Then Begin
Case Language of
_English:Begin
WriteLn('ATTR - This command allow to request or change the attribute of a file.');
WriteLn;
WriteLn('Syntax: ATTR filename [r|-r]');
WriteLn;
WriteLn(' -r Clear read only attribut');
WriteLn(' r Set read only attribut');
End;
_Germany:Begin
WriteLn('ATTR - Zeigt Dateiattribute an oder „ndert sie.');
WriteLn;
WriteLn('ATTR [r|-r] [[Laufwerk:][Pfad]Dateiname]');
WriteLn;
WriteLn(' - L”scht ein Attribut.');
WriteLn(' r Attribut fr ''Schreibgeschtzte Datei''');
End;
Else Begin
WriteLn('ATTR - Cette commande permet de demander ou changer l''attribut d''un fichier');
WriteLn;
WriteLn('Syntaxe : ATTR nomdufichier [r|-r] [-a]');
WriteLn;
WriteLn(' -r Enleve de l''attribut de lecture seulement');
WriteLn(' r Ajout de l''attribut de lecture seulement');
WriteLn;
WriteLn(' -a N''affiche pas le changement');
End;
End;
End
Else
If ParamCount=0Then ShowAttribut
Else
If ParamCount>0Then Begin
ShowChanged:=True;
FillChar(IsAttrSetting,SizeOf(IsAttrSetting),0);
AttrAdd:=0;
AttrRemove:=0;
SubDirectory:=False;
For I:=1to ParamCount do Begin
If StrToUpper(ParamStr(I))='R'Then Begin
AttrAdd:=ReadOnly;
IsAttrSetting[I]:=True;
End
Else
If StrToUpper(ParamStr(I))='-R'Then Begin
AttrRemove:=ReadOnly;
IsAttrSetting[I]:=True;
End
Else
If StrToUpper(ParamStr(I))='-A'Then Begin
ShowChanged:=False;
IsAttrSetting[I]:=True;
End;
End;
For I:=1to ParamCount do Begin
If Not IsAttrSetting[I]Then Begin
SetAttributFiles(ParamStr(I));
End;
If I=255Then Exit;
End;
End;
END.