svnno****@sourc*****
svnno****@sourc*****
2010年 8月 14日 (土) 01:20:09 JST
Revision: 3991 http://sourceforge.jp/projects/ttssh2/svn/view?view=rev&revision=3991 Author: yutakapon Date: 2010-08-14 01:20:09 +0900 (Sat, 14 Aug 2010) Log Message: ----------- strreplace ã«æ£è¦è¡¨ç¾ãæå®ã§ããããã«ããã Modified Paths: -------------- trunk/doc/en/html/macro/command/strreplace.html trunk/doc/ja/html/macro/command/strreplace.html trunk/teraterm/ttpmacro/ttl.c -------------- next part -------------- Modified: trunk/doc/en/html/macro/command/strreplace.html =================================================================== --- trunk/doc/en/html/macro/command/strreplace.html 2010-08-12 15:52:42 UTC (rev 3990) +++ trunk/doc/en/html/macro/command/strreplace.html 2010-08-13 16:20:09 UTC (rev 3991) @@ -20,19 +20,31 @@ <h2>Format</h2> <pre class="macro-syntax"> -strreplace <strvar> <index> <oldstr> <newstr> +strreplace <strvar> <index> <regex> <newstr> </pre> <h2>Remarks</h2> <p> -Replaces a specified <oldstr> string in the string variable <strvar> beginning at a specified position <index>(1-origin), with another specified <newstr> string.<br> -If the <newstr> is a null character(''), the <oldstr> string is removed. +Replaces a specified <regex> string in the string variable <strvar> beginning at a specified position <index>(1-origin), with another specified <newstr> string.<br> +If the <newstr> is a null character(''), the <regex> string is removed. </p> <h2>Example</h2> <pre class="macro-example"> +src='linux.txt' +strreplace src 1 '\.txt' '.doc' +messagebox src 'result' ; linux.doc +</pre> + +<pre class="macro-example"> +src='I can do it.' +strreplace src 1 'can\s' '' +messagebox src 'result' ; 'I do it.' +</pre> + +<pre class="macro-example"> src='Microsoft Windows XP [Version 5.1.2600]' strmatch src '(Version \d+.\d+.)\d+' @@ -47,12 +59,6 @@ endif </pre> -<pre class="macro-example"> -src='I can do it.' -strreplace src 1 'can' '' -messagebox src 'result' ; 'I do it.' -</pre> - <h2>Reference</h2> <a href="strmatch.html">strmatch</a><br> Modified: trunk/doc/ja/html/macro/command/strreplace.html =================================================================== --- trunk/doc/ja/html/macro/command/strreplace.html 2010-08-12 15:52:42 UTC (rev 3990) +++ trunk/doc/ja/html/macro/command/strreplace.html 2010-08-13 16:20:09 UTC (rev 3991) @@ -20,19 +20,31 @@ <h2>`®</h2> <pre class="macro-syntax"> -strreplace <strvar> <index> <oldstr> <newstr> +strreplace <strvar> <index> <regex> <newstr> </pre> <h2>ðà</h2> <p> -¶ñÏ <strvar> Ì <index> Êui1IWj©çA¶ñ <oldstr> ðõµA¶ñ <newstr> Éu«·¦éB<br> -¶ñ <newstr> ªó('')ÌêA¶ñ <oldstr> Íí³êéB +¶ñÏ <strvar> Ì <index> Êui1IWj©çA³K\» <regex> ðõµA¶ñ <newstr> Éu«·¦éB<br> +¶ñ <newstr> ªó('')ÌêA³K\» <regex> Íí³êéB </p> <h2>á</h2> <pre class="macro-example"> +src='linux.txt' +strreplace src 1 '\.txt' '.doc' +messagebox src 'result' ; linux.doc +</pre> + +<pre class="macro-example"> +src='I can do it.' +strreplace src 1 'can\s' '' +messagebox src 'result' ; 'I do it.' +</pre> + +<pre class="macro-example"> src='Microsoft Windows XP [Version 5.1.2600]' strmatch src '(Version \d+.\d+.)\d+' @@ -47,12 +59,6 @@ endif </pre> -<pre class="macro-example"> -src='I can do it.' -strreplace src 1 'can' '' -messagebox src 'result' ; 'I do it.' -</pre> - <h2>QÆ</h2> <a href="strmatch.html">strmatch</a><br> Modified: trunk/teraterm/ttpmacro/ttl.c =================================================================== --- trunk/teraterm/ttpmacro/ttl.c 2010-08-12 15:52:42 UTC (rev 3990) +++ trunk/teraterm/ttpmacro/ttl.c 2010-08-13 16:20:09 UTC (rev 3991) @@ -3481,13 +3481,13 @@ WORD TTLStrReplace() { - WORD Err, VarId; + WORD Err, VarId, VarType; TStrVal oldstr; TStrVal newstr; - char *srcptr; + char *srcptr, *matchptr; char *p; - int srclen, oldlen; - int pos; + int srclen, oldlen, matchlen; + int pos, ret; int result = 0; memset(oldstr, 0, MaxStrLen); @@ -3510,7 +3510,10 @@ goto error; } + oldlen = strlen(oldstr); + // strptr¶ñÌ pos ¶ÚÈ~ɨ¢ÄAoldstr ðT·B +#if 0 p = strstr(srcptr + (pos - 1), oldstr); if (p == NULL) { // ©Â©çÈ©Á½êÍA"0"ÅßéB @@ -3519,12 +3522,37 @@ } // Ü¸Í oldstr ðí·é - oldlen = strlen(oldstr); remove_string(srcptr, p - srcptr + 1, oldlen); // newstr ð}ü·é insert_string(srcptr, p - srcptr + 1, newstr); +#else + p = srcptr + (pos - 1); + ret = FindRegexStringOne(oldstr, oldlen, p, strlen(p)); + // FindRegexStringOneÌÅUnlockVar()³êĵܤÌÅALockVar()µÈ¨·B + LockVar(); + if (ret == 0) { + // ©Â©çÈ©Á½êÍA"0"ÅßéB + result = 0; + goto error; + } + if (CheckVar("matchstr",&VarType,&VarId) && + (VarType==TypString)) { + matchptr = StrVarPtr(VarId); + matchlen = strlen(matchptr); + } else { + result = 0; + goto error; + } + + // Ü¸Í oldstr ðí·é + remove_string(srcptr, (pos - 1) + ret, matchlen); + + // newstr ð}ü·é + insert_string(srcptr, (pos - 1) + ret, newstr); +#endif + result = 1; error: