svnno****@sourc*****
svnno****@sourc*****
2010年 12月 23日 (木) 12:18:55 JST
Revision: 4252 http://sourceforge.jp/projects/ttssh2/svn/view?view=rev&revision=4252 Author: maya Date: 2010-12-23 12:18:55 +0900 (Thu, 23 Dec 2010) Log Message: ----------- basename, dirname ãã¯ãã³ãã³ãã追å Modified Paths: -------------- trunk/teraterm/common/ttlib.c trunk/teraterm/common/ttlib.h trunk/teraterm/ttpmacro/ttl.c trunk/teraterm/ttpmacro/ttmparse.c trunk/teraterm/ttpmacro/ttmparse.h -------------- next part -------------- Modified: trunk/teraterm/common/ttlib.c =================================================================== --- trunk/teraterm/common/ttlib.c 2010-12-22 14:39:59 UTC (rev 4251) +++ trunk/teraterm/common/ttlib.c 2010-12-23 03:18:55 UTC (rev 4252) @@ -125,6 +125,21 @@ } } +// Delete slashes at the end of a path name +void DeleteSlash(PCHAR Path) +{ + size_t i; + for (i=strlen(Path)-1; i>=0; i--) { + if (i ==0 && Path[i] == '\\' || + Path[i] == '\\' && !_ismbblead(Path[i-1])) { + Path[i] = '\0'; + } + else { + break; + } + } +} + void Str2Hex(PCHAR Str, PCHAR Hex, int Len, int MaxHexLen, BOOL ConvSP) { BYTE b, low; Modified: trunk/teraterm/common/ttlib.h =================================================================== --- trunk/teraterm/common/ttlib.h 2010-12-22 14:39:59 UTC (rev 4251) +++ trunk/teraterm/common/ttlib.h 2010-12-23 03:18:55 UTC (rev 4252) @@ -13,6 +13,7 @@ BOOL ExtractDirName(PCHAR PathName, PCHAR DirName); void FitFileName(PCHAR FileName, int destlen, PCHAR DefExt); void AppendSlash(PCHAR Path, int destlen); +void DeleteSlash(PCHAR Path); void Str2Hex(PCHAR Str, PCHAR Hex, int Len, int MaxHexLen, BOOL ConvSP); BYTE ConvHexChar(BYTE b); int Hex2Str(PCHAR Hex, PCHAR Str, int MaxLen); Modified: trunk/teraterm/ttpmacro/ttl.c =================================================================== --- trunk/teraterm/ttpmacro/ttl.c 2010-12-22 14:39:59 UTC (rev 4251) +++ trunk/teraterm/ttpmacro/ttl.c 2010-12-23 03:18:55 UTC (rev 4252) @@ -2385,6 +2385,84 @@ return Err; } +static void basedirname(char *fullpath, char *dest_base, int base_len, char *dest_dir, int dir_len) { + char drive[_MAX_DRIVE], dir[_MAX_DIR], fname[_MAX_FNAME], ext[_MAX_EXT]; + char dirname[MAX_PATH]; + char basename[MAX_PATH]; + + _splitpath_s(fullpath, drive, sizeof(drive), dir, sizeof(dir), fname, sizeof(fname), ext, sizeof(ext)); + strncpy_s(dirname, sizeof(dirname), drive, _TRUNCATE); + strncat_s(dirname, sizeof(dirname), dir, _TRUNCATE); + DeleteSlash(dirname); // öÌ \ ðæè + if (strlen(fname) == 0 && strlen(ext) == 0) { + _splitpath_s(dirname, drive, sizeof(drive), dir, sizeof(dir), fname, sizeof(fname), ext, sizeof(ext)); + strncpy_s(dirname, sizeof(dirname), drive, _TRUNCATE); + strncat_s(dirname, sizeof(dirname), dir, _TRUNCATE); + DeleteSlash(dirname); // öÌ \ ðæè + strncpy_s(basename, sizeof(basename), fname, _TRUNCATE); + strncat_s(basename, sizeof(basename), ext, _TRUNCATE); + } + else { + strncpy_s(basename, sizeof(basename), fname, _TRUNCATE); + strncat_s(basename, sizeof(basename), ext, _TRUNCATE); + } + + if (dest_dir != NULL) { + strncpy_s(dest_dir, dir_len, dirname, _TRUNCATE); + } + if (dest_base != NULL) { + strncpy_s(dest_base, base_len, basename, _TRUNCATE); + } +} + +static void basename(char *fullpath, char *dest, int len) { + basedirname(fullpath, dest, len, NULL, 0); +} + +static void dirname(char *fullpath, char *dest, int len) { + basedirname(fullpath, NULL, 0, dest, len); +} + +WORD TTLBasename() +{ + WORD VarId, Err; + TStrVal Src, Name; + + Err = 0; + GetStrVar(&VarId,&Err); + GetStrVal(Src,&Err); + if ((Err==0) && + (GetFirstChar()!=0)) + Err = ErrSyntax; + + if (Err!=0) return Err; + + basename(Src, Name, sizeof(Name)); + SetStrVal(VarId, Name); + + return Err; +} + +WORD TTLDirname() +{ + WORD VarId, Err; + TStrVal Src, Dir; + + Err = 0; + GetStrVar(&VarId,&Err); + GetStrVal(Src,&Err); + if ((Err==0) && + (GetFirstChar()!=0)) + Err = ErrSyntax; + + if (Err!=0) return Err; + + dirname(Src, Dir, sizeof(Dir)); + SetStrVal(VarId, Dir); + + return Err; +} + #define IdMsgBox 1 #define IdYesNoBox 2 #define IdStatusBox 3 @@ -4420,6 +4498,8 @@ if (GetReservedWord(&WId)) switch (WId) { + case RsvBasename: + Err = TTLBasename(); break; case RsvBeep: Err = TTLBeep(); break; case RsvBPlusRecv: @@ -4453,6 +4533,8 @@ Err = TTLCrc32File(); break; case RsvDelPassword: Err = TTLDelPassword(); break; + case RsvDirname: + Err = TTLDirname(); break; case RsvDisconnect: Err = TTLDisconnect(); break; case RsvDispStr: Modified: trunk/teraterm/ttpmacro/ttmparse.c =================================================================== --- trunk/teraterm/ttpmacro/ttmparse.c 2010-12-22 14:39:59 UTC (rev 4251) +++ trunk/teraterm/ttpmacro/ttmparse.c 2010-12-23 03:18:55 UTC (rev 4252) @@ -131,6 +131,7 @@ else if (_stricmp(Str,"bplusrecv")==0) *WordId = RsvBPlusRecv; else if (_stricmp(Str,"bplussend")==0) *WordId = RsvBPlusSend; else if (_stricmp(Str,"break")==0) *WordId = RsvBreak; + else if (_stricmp(Str,"basename")==0) *WordId = RsvBasename; break; case 'c': if (_stricmp(Str,"call")==0) *WordId = RsvCall; @@ -151,6 +152,7 @@ else if (_stricmp(Str,"disconnect")==0) *WordId = RsvDisconnect; else if (_stricmp(Str,"dispstr")==0) *WordId = RsvDispStr; else if (_stricmp(Str,"do")==0) *WordId = RsvDo; + else if (_stricmp(Str,"dirname")==0) *WordId = RsvDirname; break; case 'e': if (_stricmp(Str,"else")==0) *WordId = RsvElse; Modified: trunk/teraterm/ttpmacro/ttmparse.h =================================================================== --- trunk/teraterm/ttpmacro/ttmparse.h 2010-12-22 14:39:59 UTC (rev 4251) +++ trunk/teraterm/ttpmacro/ttmparse.h 2010-12-23 03:18:55 UTC (rev 4252) @@ -202,6 +202,8 @@ #define RsvStrSplit 184 #define RsvStrJoin 185 #define RsvStrSpecial 186 +#define RsvBasename 187 +#define RsvDirname 188 #define RsvOperator 1000 #define RsvBNot 1001