This repository was archived by the owner on Sep 3, 2019. It is now read-only.
forked from AsmusGerman/ABSShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMiResources.pas
More file actions
334 lines (276 loc) · 7.85 KB
/
MiResources.pas
File metadata and controls
334 lines (276 loc) · 7.85 KB
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
Unit MiResources;
Interface
Uses
crt,keyboard,MiTypes,UnixType,Unix,strutils;
procedure devolverMensaje(str:string);
procedure devolverMensajeA(str:string);
procedure Completar(var str:string;num:word);
procedure devolverDatos(info:ArrayChar);
procedure mostrar(var datos: ArrayChar);
function ConstArray(a1:String ; a2:salida): salida;
function rutaPadre(ruta:string): string;
function verificarRuta(ruta:string): byte;
function GetFilePermissions(mode: mode_t): string;
function ConcatArray(a, b: ArrayChar): ArrayChar;
function devolverInterno(str:string): integer;
Implementation
{
name: GetFilePermissions
@param
* mode: mode_t
@return
* string
* Recibe un dato de tipo mode_t y devuelve un string que muestra
* el tipo y los permisos del archivo para el usuario,
* el grupo y otros.
}
function GetFilePermissions(mode: mode_t): string; // Recibe un dato de tipo mode_t y devuelve un string que muestra
var // el tipo y los permisos del archivo para el usuario,el grupo y otros.
Resultado: string;
begin
Resultado:='';
if STAT_IFLNK and mode=STAT_IFLNK then // file type
Resultado:=Resultado+'l'
else
if STAT_IFDIR and mode=STAT_IFDIR then
Resultado:=Resultado+'d'
else
if STAT_IFBLK and mode=STAT_IFBLK then
Resultado:=Resultado+'b'
else
if STAT_IFCHR and mode=STAT_IFCHR then
Resultado:=Resultado+'c'
else
Resultado:=Resultado+'-';
if STAT_IRUSR and mode=STAT_IRUsr then // user permissions
Resultado:=Resultado+'r'
else
Resultado:=Resultado+'-';
if STAT_IWUsr and mode=STAT_IWUsr then
Resultado:=Resultado+'w'
else
Resultado:=Resultado+'-';
if STAT_IXUsr and mode=STAT_IXUsr then
Resultado:=Resultado+'x'
else
Resultado:=Resultado+'-';
if STAT_IRGRP and mode=STAT_IRGRP then // group permissions
Resultado:=Resultado+'r'
else
Resultado:=Resultado+'-';
if STAT_IWGRP and mode=STAT_IWGRP then
Resultado:=Resultado+'w'
else
Resultado:=Resultado+'-';
if STAT_IXGRP and mode=STAT_IXGRP then
Resultado:=Resultado+'x'
else
Resultado:=Resultado+'-';
if STAT_IROTH and mode=STAT_IROTH then // other permissions
Resultado:=Resultado+'r'
else
Resultado:=Resultado+'-';
if STAT_IWOTH and mode=STAT_IWOTH then
Resultado:=Resultado+'w'
else
Resultado:=Resultado+'-';
if STAT_IXOTH and mode=STAT_IXOTH then
Resultado:=Resultado+'x'
else
Resultado:=Resultado+'-';
GetFilePermissions:=Resultado;
end;
function ConstArray(a1:String ; a2:salida): salida;
var
i,r:integer;
resultado: salida;
begin
SetLength(resultado,High(a2)-Low(a2)+2);
r:=0;
resultado[r] := a1;
Inc(r);
for i := Low(a2) to High(a2) do begin
resultado[r] := a2[i];
Inc(r);
end;
ConstArray:=resultado;
end;
{
name: Completar
@param
* str: string
* num: word
@return
* Recibe un string y devuelve otro de longitud num, que posee el
* primero per que se completa con espacios (' ') hasta llegar al
* tamaño indicado Si el string que se le pasa tiene una longitud
* mayor a num devuelve el mismo
}
procedure Completar(var str:string;num:word);
begin
while length(str)<num do
begin
str:=str+' ';
end;
end;
{
name: devolverMensaje
@param
* str : string
@return
* Carga el mensaje de tipo string que se le pasa
* a la variable global dat de tipo ArrayChar del shell
}
procedure devolverMensaje(str:string);
var i,j:word;
begin
if High(dat) < 1 then
begin
i:=Low(dat);
SetLength(dat,i+1);
dat[i]:=#13;
end
else i:=High(dat)+1;
for j:=1 to length(str)+1 do
begin
inc(i);
SetLength(dat,i+1);
dat[i]:=str[j];
end;
SetLength(dat,High(dat));
end;
procedure devolverMensajeA(str:string);
var i,j:word;
begin
if High(dat) < 1 then
begin
i:=Low(dat);
SetLength(dat,i+1);
dat[i]:=#13;
end
else i:=High(dat)+1;
for j:=1 to length(str) do
begin
inc(i);
SetLength(dat,i+1);
dat[i]:=str[j];
end;
SetLength(dat,High(dat));
end;
{
name: devolverDatos
@param
* info: ArrayChar
@return
* Carga el mensaje de tipo ArrayChar que se le pasa en la variable
* global dat del mismo tipo del shell
}
procedure devolverDatos(info:ArrayChar); // Carga el mensaje de tipo ArrayChar que se le pasa en la variable global
var i,j:word; // dat del mismo tipo del shell
begin
i:=Low(dat);
if High(dat)<1 then
begin
SetLength(dat,i+1);
inc(i);
end
else i:=High(dat)+1;
j:=low(info);
while (j <= High(info)) do
begin
SetLength(dat,i+1);
dat[i]:=info[j];
inc(i);
inc(j);
end;
SetLength(dat,High(dat));
end;
{
name: mostrar
@param
* datos: ArrayChar
@return
* El procedimiento muestra en pantalla el contenido de la variable
* 'datos' de tipo ArrayChar que se le pasa
}
procedure mostrar(var datos: ArrayChar);
var i: word;
begin
if High(datos)>0 then
begin
for i:=low(datos) to High(datos) do
Write(datos[i]);
end;
Write(#10);
Write(#13);
SetLength(datos,0);
end;
{
name: rutaPadre
@param
* ruta: string
@return
* Recibe un string que posea '/' y devuelve otro en el cual ha
* eliminado el postfijo que sigue a la ultima ocurrencia de '/'
}
function rutaPadre(ruta:string): string;
begin
while copy(ruta,length(ruta),length(ruta)) <> '/' do
ruta:=copy(ruta,1,length(ruta)-1);
rutaPadre:=copy(ruta,1,length(ruta)-1);
end;
{
name: verificarRuta
@param
* ruta: string
@return
* byte
* Verifica que el string que se le pasa sea una ruta de
* directorio valida.
}
function verificarRuta(ruta:string): byte;
begin
{$I-}
ChDir (ruta);
if IOresult<>0 then
verificarRuta:=0
else
verificarRuta:=1;
end;
{
name: ConcatArray
@param
* a: ArrayChar
* b: ArrayChar
@return
* arreglo de caracteres
* concatena los arreglos a y b.
}
function ConcatArray(a, b: ArrayChar): ArrayChar;
var i: Longint;
begin
SetLength(ConcatArray, Length(a) + Length(b));
for i := 0 to High(a) do
ConcatArray[i] := a[i];
for i := 0 to High(b) do
ConcatArray[i + Length(a)] := b[i];
end;
function devolverInterno(str:string): integer;
var
indice: integer;
buscado:boolean;
Begin
indice:= 1;
buscado:=false;
while (buscado=false) and (AnsiContainsStr(Entrada,comandos[indice])=false)do
begin
buscado:= (indice>=(length(comandos)));
inc(indice);
end;
if (not buscado) then
devolverInterno:=indice
else
devolverInterno:=-1;
End;
Begin
End.