⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 idosfilename.pas

📁 photo.163.com 相册下载器 多线程下载
💻 PAS
📖 第 1 页 / 共 2 页
字号:
{ $HDR$}
{**********************************************************************}
{ Unit archived using Team Coherence                                   }
{ Team Coherence is Copyright 2002 by Quality Software Components      }
{                                                                      }
{ For further information / comments, visit our WEB site at            }
{ http://www.TeamCoherence.com                                         }
{**********************************************************************}
{}
{ $Log:  18478: IdOSFileName.pas
{
{   Rev 1.4    2004.02.03 5:45:42 PM  czhower
{ Name changes
}
{
{   Rev 1.3    24/01/2004 23:16:26  CCostelloe
{ Removed short-circuits
}
{
{   Rev 1.2    24/01/2004 19:28:28  CCostelloe
{ Cleaned up warnings
}
{
{   Rev 1.1    5/2/2003 01:16:00 PM  JPMugaas
{ Microware OS/9 and MPE/iX support.
}
{
{   Rev 1.0    4/21/2003 05:32:08 PM  JPMugaas
{ Filename converstion rourintes.  Todo:  Somehow, figure out what to do about
{ pathes and add more platform support.
}
unit IdOSFileName;

interface
uses classes, IdBaseComponent, IdFTPCommon;

function FileNameUnixToVMS(const AUnixFileName : String) : String;
function FileNameVMSToUnix(const AVMSFileName : String) : String;
function FileNameMSDOSToUnix(const AMSDOSFileName : String) : String;
function FileNameUnixToMSDOS(const AUnixFileName : String):String;
function FileNameUnixToWin32(const AUnixFileName : String):String;
function FileNameWin32ToUnix(const AWin32FileName : String): String;
function FileNameUnixToVMCMS(const AUnixFileName : String): String;
function FileNameVMCMSToUnix(const AVMCMSFileName : String): String;
function FileNameUnixToMUSICSP(const AUnixFileName : String) : String;
function FileNameMUSICSPToUnix(const AMUSICSPFileName : String) : String;
function FileNameUnixToMVS(const AUnixFileName : String; const AUserID : String;
 const AUseAnotherID : Boolean=False) : String;
function FileNameMVSToUnix(const AMVSFileName : String) : String;
function FileNameUnixToMPEiXTraditional(const AUnixFileName : String; const AGroupName : String=''; const AAcountName : String=''): String;
function FileNameUnixToMPEiXHFS(const AUnixFileName : String; const IsRoot : Boolean=False): String;
function FileNameUnixToOS9(const AUnixFileName : String) : String;

implementation

uses
  IdGlobal, SysUtils;

type
  TIdValidChars = set of AnsiChar;

function EnsureValidCharsByValidSet(const AFilePart : String; const AValidChars : TIdValidChars; const AReplaceWith : String='_'): String;
var i : Integer;
begin
  Result := '';
  for i := 1 to Length(AFilePart) do
  begin
      if CharIsInSet(AFilePart, i, AValidChars) then
      begin
        Result := Result + AFilePart[i];
      end
      else
      begin
        Result := Result + AReplaceWith;
      end;
  end;
end;

function EnsureValidCharsByInvalidSet(const AFilePart : String; const AInvalidChars : TIdValidChars; const AReplaceWith : String='_'): String;
var i : Integer;
begin
  Result := '';
  for i := 1 to Length(AFilePart) do
  begin
      if not CharIsInSet(AFilePart, i, AInValidChars) then
      begin
        Result := Result + AFilePart[i];
      end
      else
      begin
        Result := Result + AReplaceWith;
      end;
  end;
end;

function FileNameUnixToVMS(const AUnixFileName : String) : String;
var LFName, LFExt : String;
{sample VMS fully qualified filename:

DKA0:[MYDIR.SUBDIR1.SUBDIR2]MYFILE.TXT;1

Note VMS uses 39 chars for name and type

valid chars are:
letters A through Z 
numbers 0 through 9 
underscore ( _ )
hyphen ( -) 
dollar sign ( $ )

See:  http://www.uh.edu/infotech/services/documentation/vms/v0505.html
}
const VMS_VALID_CHARS : TIdValidChars = ['A'..'Z','0'..'9','_','-','$'];

begin
  //VMS is case insensitive - uppercase to simplify processing
  Result := UpperCase(AUnixFileName);
  LFName := Fetch(Result,'.');
  LFExt := Fetch(Result,'.');
  LFExt := Fetch(LFExt,';');
  LFName := Copy(LFName,1,39);
  LFName := EnsureValidCharsByValidSet(LFName,VMS_VALID_CHARS);
  LFExt := Copy(LFExt,1,39);
  LFExt := EnsureValidCharsByValidSet(LFExt,VMS_VALID_CHARS);
  Result := LFName;
  if LFExt <>'' then
  begin
    Result := Result + '.'+LFExt;
  end;
end;

function FileNameVMSToUnix(const AVMSFileName : String) : String;
begin
  Result := AVMSFileName;
  //We strip off the version marker because that doesn't make sense in
  //Win32 and Unix.  In VMS, there's a crude type of version control in the file system where
  //different versions of the same file are kept.
  //For example, if you open IDABOUT.PAS;1, make a change, and save it, it is saved
  //as IDABOUT.PAS;2.  Make a further change and save it and it will be saved as
  //IDABOUT.PAS;3.
  Result := Fetch(Result,';');
  //VMS is case insensitive
  Result := LowerCase(AVMSFileName);
end;

function FileNameMSDOSToUnix(const AMSDOSFileName : String) : String;
begin
  Result := Lowercase(AMSDOSFileName);
end;

function FileNameUnixToMSDOS(const AUnixFileName : String):String;
var LFName, LFExt : String;
//From: http://macinfo.its.queensu.ca/Mark/AMT2/AMTCrossPlatfrom.html
//Window V3.1 and DOS file names compatibility:
//Windows 3.1/DOS names cannot have more than eight characters and can
//contain only the letters A through Z, the numbers 0 through 9 and the
//following special characters:
//underscore (_), dollar sign ($), tilde (~), exclamation point (!),
//number sign (#), percent sign (%), ampersand (&), hyphen (-), braces ({}), parenthesis (), at sign (@), apostrophe ('), and the grave accent (').

//Note: Macintosh does not allow colin (:) in it's file name and supports upto 32 characters.

const MSDOS_VALID_CHARS : TIdValidChars = ['A'..'Z','0'..'9','_','$','~','!','#','%','&','-','{','}','(',')','@','''',#180];
begin
  Result := UpperCase(AUnixFileName);
  LFName := Fetch(Result,'.');
  LFName := Copy(LFName,1,8);
  LFName := EnsureValidCharsByValidSet(LFExt,MSDOS_VALID_CHARS);
  LFExt := Fetch(Result,'.');
  LFExt := Copy(LFExt,1,3);
  LFExt := EnsureValidCharsByValidSet(LFExt,MSDOS_VALID_CHARS);
  Result := LFName;
  if LFExt <> '' then
  begin
    Result := Result + '.'+LFExt;
  end;
end;

function FileNameUnixToWin32(const AUnixFileName : String):String;
//from: http://linux-ntfs.sourceforge.net/ntfs/concepts/filename_namespace.html
const WIN32_INVALID_CHARS : TIdValidChars = ['"','*','/',':','<','>','?','\','|',#0];
    WIN32_INVALID_LAST : TIdValidChars = [' ','.'];  //not permitted as the last character in Win32
begin
  Result := EnsureValidCharsByInvalidSet(AUnixFileName,WIN32_INVALID_CHARS);
  if Result <> '' then begin
    if CharIsInSet(Result, Length(Result), WIN32_INVALID_LAST) then begin
      Delete(Result,Length(Result),1);
      if Result = '' then begin
        Result := '_';
      end;
    end;
  end;
end;

function FileNameWin32ToUnix(const AWin32FileName : String): String;
//from http://linux-ntfs.sourceforge.net/ntfs/concepts/filename_namespace.html
//const UNIX_INVALID_CHARS : TIdValidChars = [#0,'/'];
begin
  Result := LowerCase(AWin32FileName);
end;

function FileNameUnixToVMCMS(const AUnixFileName : String): String;
// From: CMS Introductory Guide at the University of Kentuckey
//    http://ukcc.uky.edu/~ukccinfo.391/cmsintro.html
//      Under CMS a file is identified by a fileid with three parts:  the filename, the
//      filetype, and the filemode.  The filemode, from this point on in this guide, will
//      always be A1.  In most cases, the filemode is optional when referring to files.
//      The filename and filetype can contain from one to eight characters (letters,
//      numbers, and these seven special characters: @#$+-:_).  Choose filenames and
//      filetypes that help to identify the contents of the file.
var LFName, LFExt : String;
const VALID_VMCMS_CHARS : TIdValidChars = ['A'..'Z','0'..'9','@','#','$','+','-',':','_'];
begin
  Result := UpperCase(AUnixFileName);
  LFName := Fetch(Result,'.');
  LFName := EnsureValidCharsByValidSet(LFExt,VALID_VMCMS_CHARS);
  LFName := Copy(LFName,1,8);
  LFExt := Fetch(Result,'.');
  LFExt := EnsureValidCharsByValidSet(LFExt,VALID_VMCMS_CHARS);
  LFExt := Copy(LFExt,1,8);
  Result := LFName;
  if LFExt <> '' then
  begin
    Result := Result + '.'+LFExt;
  end;
end;

function FileNameVMCMSToUnix(const AVMCMSFileName : String): String;
begin
  Result := LowerCase(AVMCMSFileName);
end;

function FileNameUnixToMUSICSP(const AUnixFileName : String) : String;
{
Obtained from a ftphelp.txt on a Music/SP Server

The MUSIC/SP file system has a directory structure similar to that
of DOS and Unix.  The separator character between directory names
is a backslash (\), but the FTP client can use either a slash (/)
or a backslash (\).  Directory names can be up to 17 characters.
File names within a directory can be up to 17 characters.  The total
name, including directory names on the front, can be up to 50
characters.  Upper/lower case is not significant in file names.
Letters (A to Z), digits (0 to 9), and some special characters
(including $ # @ _ + - . % & !) can be used, but the first character
of each part must not be a digit or + - . % & !.
}
const VALID_MUSICSP = ['A'..'Z','0'..'9','$','#','@','_','+','-','.','%','&','!'];
  MUSICSP_CANT_START = ['0'..'9','+','-','.','%','!'];
begin
// note we have to do our vality checks before truncating the length in
// case we need to replace the default replacement char and the length changes
// because of that.
  Result := UpperCase(AUnixFileName);
  Result := EnsureValidCharsByValidSet(Result,VALID_MUSICSP);
  Result := Copy(Result,1,15);
  if Result <> '' then begin
    if CharIsInSet(Result, 1, MUSICSP_CANT_START) then begin
      if Length(Result) > 1 then begin
        Delete(Result,1,1);
      end else begin
        Result[1] := '_';
      end;
    end;
  end;
end;

function FileNameMUSICSPToUnix(const AMUSICSPFileName : String) : String;
begin
  Result := LowerCase(AMUSICSPFileName);
end;

function FileNameUnixToMVS(const AUnixFileName : String; const AUserID : String; const AUseAnotherID : Boolean=False) : String;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -