📄 idosfilename.pas
字号:
var LQualifier : String;
LMaxLen : Integer;
LBuf : String;
const
MVS_FQN_MAX_LEN = 44;
MVS_MAX_QUAL_LEN = 8;
MVS_VALID_QUAL_CHARS = ['0'..'9','A'..'Z','@','$','#'];
MVS_VALID_FIRST_CHAR = ['A'..'Z'];
begin
//in MVS, there's a maximum of 44 characters and MVS prepends a prefix with the userID and
//sometimes process name. Thus, the dataset name can have 44 characters minus the user ID - 1 (for the dot)
//
//e.g. CZHOWER can have a fully qualified name with a maximum of 36 characters
// JPMUGAAS can have a fully qualified name with a maximum of 35 characters
//
//if AUseAnotherID is true, we give a fully qualified name with a prefix in '' which
//is called ticks. That permits someone to access another user's dataset.
//
//e.g. CZHOWER could access a dataset created by JPMUGAAS (named INDY.IDABOUT.PAS)
// by using the name:
//
//'JPMUGAAS.INDY.IDABOUT.PAS'
//
//JPMUGAAS can access the same data with the name:
//
//INDY.IDABOUT.PAS
//
//where the JPMUGAAS. prefix is implied.
LMaxLen := MVS_FQN_MAX_LEN - 1 - Length(AUserID);
LBuf := UpperCase(AUnixFileName);
Result := '';
repeat
LQualifier := Fetch(LBuf,'.');
if LQualifier <>'' then
begin
repeat
if ((CharIsInSet(LQualifier, 1, MVS_VALID_FIRST_CHAR))=False) then
begin
Delete(LQualifier,1,1);
if LQualifier='' then
begin
break;
end;
end
else
begin
Break;
end;
until False;
end;
//we do it this way in case the qualifier only had an invalid char such as #
if LQualifier <> '' then
begin
LQualifier := EnsureValidCharsByValidSet(LQualifier,MVS_VALID_QUAL_CHARS,'');
end;
LQualifier := Copy(LQualifier,1,MVS_MAX_QUAL_LEN);
if LQualifier <> '' then
begin
Result := Result + '.' +LQualifier;
if Result<>'' then
begin
if Result[1]='.' then
begin
Delete(Result,1,1);
end;
end;
if (Length(Result)>LMaxLen) or (LBuf='') then
begin
Result := Copy(Result,1,LMaxLen);
Break;
end;
end;
if LBuf = '' then
begin
Break;
end;
until False;
if AUseAnotherID then
begin
Result := ''''+AUserID+'.'+Result+'''';
end;
end;
function FileNameMVSToUnix(const AMVSFileName : String) : String;
begin
Result := Lowercase(AMVSFileName);
end;
{
Note that Account name does not necessarily imply a username. When logging in,
the user provides both the username and account. It's like the username is the key to
a cabnet (several people can have their keys to that cabnit.
The group name is like a drawer in a cabnet. That is only needed if you are logged in with
an account and group but wish to access a file in a different group.
That's how the manual
described it.
The MPE/iX file system is basically flat with an account, group, and file name.
}
function MPEiXValidateFIlePart(AFilePart : String) : String;
const
VALID_MPEIX_START = ['A'..'Z'];
VALID_MPEIX_FNAME = ['0'..'9']+ VALID_MPEIX_START;
begin
Result := UpperCase(AFilePart);
if IndyPos('.',Result)>1 then
begin
Result := Fetch(Result,'.');
end;
if Result<>'' then
begin
Result := EnsureValidCharsByValidSet(Result,VALID_MPEIX_FNAME,'');
repeat
if ((CharIsInSet(Result, 1, VALID_MPEIX_START))=False) then
begin
Delete(Result,1,1);
if Result='' then
begin
break;
end;
end
else
begin
Break;
end;
until False;
end;
//no more than 8 chars
Result := COpy(Result,1,8);
end;
function FileNameUnixToMPEiXTraditional(const AUnixFileName : String; const AGroupName : String=''; const AAcountName : String=''): String;
//based on http://docs.hp.com/mpeix/onlinedocs/32650-90871/32650-90871.html
//
//1) Starts with a letter - case insensitive
//2) Contains only letters and numbers
//3) No other charactors (a / is acceptable but it means a lockword which can cause
// you to be unable to retreive the file
//4) No more than 8 chars
//
//Note that fullname and groupname are 1 to 8 chars and follow the same rules
//just to eliminate some double processing for tests
var LBuf : String;
begin
Result := MPEiXValidateFIlePart(AUnixFileName);
LBuf := MPEiXValidateFIlePart(AGroupName);
if LBuf <> '' then
begin
//if no group, we skip the account part
Result := Result + '.'+LBuf;
LBuf := MPEIxValidateFilePart(AAcountName);
if LBuf <> '' then
begin
Result := Result + '.'+LBuf;
end;
end;
end;
function FileNameUnixToMPEiXHFS(const AUnixFileName : String; const IsRoot : Boolean=False): String;
//based on: http://docs.hp.com/mpeix/onlinedocs/32650-90492/32650-90492.html
{
http://docs.hp.com/mpeix/onlinedocs/32650-90492/32650-90492.html
FS pathnames differ from MPE pathnames in the following ways:
Names are separated with forward slashes (/), rather than dots.
The order of the file name, group name, and account name are presented in
reverse order compared to MPE syntax (/ACCT/GROUP/FILE versus FILE.GROUP.ACCT).
Slash (/) at the beginning of a pathname indicates the root directory.
Dot-slash (./) at the beginning of a pathname indicates the current working
directory (CWD). The CWD is the directory in which you are currently working.
Pathnames can be up to 1023 characters whereas traditional MPE names must be
less than or equal to 26 characters (names can be up to 35 characters if a
lockword is used). See Table 2-2 for CI restrictions.
Using these conventions, the format of the MPE pathname
MYFILE.PAYROLL.FINANCE appears as follows in HFS syntax:
/FINANCE/PAYROLL/MYFILE
In this example, it is assumed that MYFILE is a file under the PAYROLL group
and FINANCE account. However, FINANCE and PAYROLL need not necessarily be an
account and a group as they must in MPE syntax. Using HFS syntax, MYFILE could
be a file under the PAYROLL HFS subdirectory, which is under the FINANCE HFS
directory, which is under the root directory.
}
const MPEIX_VALID_CHARS = ['a'..'z','A'..'Z','0'..'9','.','_','-'];
MPEIX_CANTSTART = ['-'];
begin
Result := AUnixFileName;
if Result<>'' then
begin
Result := EnsureValidCharsByValidSet(Result,MPEIX_VALID_CHARS,'_');
repeat
if CharIsInSet(Result, 1, MPEIX_CANTSTART) then
begin
Delete(Result,1,1);
if Result='' then
begin
break;
end;
end
else
begin
Break;
end;
until False;
end;
//note that this for clarrifying that this is a HFS file instead of a Traditional
//MPEiX file.
//A file in the foot folder uses the / and a file in the current dir uses ./
if IsRoot then
begin
Result := '/'+Result;
end
else
begin
Result := './'+Result;
end;
Result := Copy(result,1,255);
end;
function FileNameUnixToOS9(const AUnixFileName : String) : String;
//based on:
//http://www.roug.org/soren/6809/os9guide/os9guide.pdf
{
Names can have one to 29 characters, all of which are used for matching. They
must becin with an upper- or lower-case letter followed by any combination of
the following characters:
uppercase letters: A - Z
lowercase letters: a - z
decimal digits: 0 - 9
underscore: _
period: .
}
const
OS9_MUST_START = ['a'..'z','A'..'Z'];
OS9_VALID_CHAR = OS9_MUST_START+['0'..'9','_','.'];
begin
Result := AUnixFileName;
if Result<>'' then
begin
Result := EnsureValidCharsByValidSet(Result,OS9_VALID_CHAR,'_');
repeat
if ((CharIsInSet(Result, 1, OS9_MUST_START))=False) then
begin
Delete(Result,1,1);
if Result='' then
begin
break;
end;
end
else
begin
Break;
end;
until False;
end;
Result := Copy(Result,1,29);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -