program test_f_name(input,output); type string31=packed array[1..31]of char; var filename:string31; function fnok(s:string31;write_to:boolean):boolean; var i,dot,sub:integer;fail,ftype:packed array[0..4]of boolean;done:boolean; function my_file(s:string31):boolean; const userad=2359296;{str6} type str6=packed array[0..6]of char; cheat=record dummyi:integer; case boolean of true:(addr:integer); false:(ptr:^str6) end; var peeker:cheat;me,owner:str6;i:integer; begin peeker.addr:=userad; me:=peeker.ptr^; owner[0]:=chr(6); for i:=1 to 6 do owner[i]:=s[i]; { writeln('OWNER=',owner,' ME=',me,' result=',me=owner); } my_file:=owner=me; end; function alphabetical(ch:char):boolean; begin alphabetical:=((ord('A')<=ord(ch))and(ord(ch)<=ord('Z'))); end; function alphanumeric(ch:char):boolean; begin alphanumeric:=((ord('0')<=ord(ch))and(ord(ch)<=ord('9')))or alphabetical(ch); end; begin for i:=0 to 4 do begin ftype[i]:=false;fail[i]:=false; end; dot:=0;sub:=0; for i:=1 to 31 do if s[i]='.' then dot:=i; for i:=31 downto 1 do if s[i]='_' then sub:=i; fail[1]:=((dot<>0)and(dot<>7))or((sub<>0)and(dot+1>=sub)); if dot<>0 then if not fail[1] then for i:=1 to 6 do fail[1]:=fail[1] or not alphanumeric(s[i]); ftype[1]:=not fail[1] and (dot<>0); fail[0]:=fail[1]; if not fail[0] then begin i:=dot+1;fail[2]:=not alphabetical(s[i]); repeat i:=i+1;done:=(s[i]=' ')or(s[i]='_'); fail[2]:=not (alphanumeric(s[i])or(s[i]='#')or done)or fail[2]; until done or fail[2] or (i=dot+12); fail[2]:=fail[2] or not done; end; fail[0]:=fail[1] or fail[2]; if not fail[0] then begin ftype[3]:=sub<>0; if ftype[3] then begin i:=sub+1; fail[3]:=not alphabetical(s[i]); { repeat } { done:=s[i]=' '; } { fail[3]:=NOT DONE AND(fail[3] or not (alphanumeric(s[i]))); } { i:=i+1; } { until done or fail[3] or (i=sub+12); } while not (fail[3] or done or (i=sub+12))do begin i:=i+1;done:=s[i]=' '; fail[3]:=not done and not alphanumeric(s[i]); end; fail[3]:=fail[3] or not done; end; end; fail[0]:=fail[1] or fail[2] or fail[3]; if fail[0] then begin write('Invalid '); if fail[1] then write('username ') else if fail[2] then write('filename ') else if fail[3] then write('member name '); writeln(s); end else begin if write_to then begin if ftype[1] and not my_file(s) then begin writeln('Invalid access - you can''t write to another user''s file'); fail[4]:=true; end else begin if ftype[3] then begin writeln('Invalid access - you can''t write to a partitioned file member '); fail[4]:=true; end; end; end; end; fnok:=not(fail[1] or fail[2] or fail[3] or fail[4]); end; procedure readstr(var s:string31); var i:integer; begin for i:=1 to 31 do s[i]:=' '; i:=1; while input^=' ' do get(input); while (i<=31) and not eoln do begin read(s[i]);i:=succ(i);end; if i=1 then readstr(s); end; begin repeat readstr(filename); if fnok(filename,false) then writeln(filename,'an be read'); if fnok(filename,true) then writeln(filename,'can be written to'); until false; end.