[ttssh2-commit] [9465] awcscat(), awcscats() を追加

Zurück zum Archiv-Index
scmno****@osdn***** scmno****@osdn*****
2021年 10月 14日 (木) 23:51:28 JST


Revision: 9465
          https://osdn.net/projects/ttssh2/scm/svn/commits/9465
Author:   zmatsuo
Date:     2021-10-14 23:51:28 +0900 (Thu, 14 Oct 2021)
Log Message:
-----------
awcscat(), awcscats() を追加

- 動的確保したメモリーの文字列に文字列を追加する
- buffer.c から移動

Modified Paths:
--------------
    trunk/teraterm/common/asprintf.cpp
    trunk/teraterm/common/asprintf.h
    trunk/teraterm/teraterm/buffer.c

-------------- next part --------------
Modified: trunk/teraterm/common/asprintf.cpp
===================================================================
--- trunk/teraterm/common/asprintf.cpp	2021-10-14 14:51:19 UTC (rev 9464)
+++ trunk/teraterm/common/asprintf.cpp	2021-10-14 14:51:28 UTC (rev 9465)
@@ -31,6 +31,8 @@
 #include <stdlib.h>
 #include <crtdbg.h>
 #include <assert.h>
+#include <string.h>
+#include <wchar.h>
 
 #include "asprintf.h"
 
@@ -138,3 +140,63 @@
 	va_end(ap);
 	return r;
 }
+
+/**
+ *	\x95\xB6\x8E\x9A\x97\xF1\x82\xF0\x98A\x8C\x8B\x82\xB7\x82\xE9
+ *	@param[in]	dest	malloc\x82\xB3\x82ꂽ\x97̈\xE6,\x95\xB6\x8E\x9A\x97\xF1
+ *						*dest == NULL\x82̏ꍇ\x82͐V\x82\xBD\x82ȗ̈悪\x8Am\x95ۂ\xB3\x82\xEA\x82\xE9
+ *						\x95s\x97v\x82ɂȂ\xC1\x82\xBD\x82\xE7 free() \x82\xB7\x82邱\x82\xC6
+ *	@param[in]	add		\x98A\x8C\x8B\x82\xB3\x82\xEA\x82镶\x8E\x9A\x97\xF1
+ *						NULL\x82̏ꍇ\x82͂Ȃɂ\xE0\x8Ds\x82\xED\x82Ȃ\xA2
+ */
+void awcscat(wchar_t **dest, const wchar_t *add)
+{
+	if (*dest == NULL) {
+		*dest = _wcsdup(add);
+		return;
+	}
+	else if (add == NULL) {
+		return;
+	}
+	else {
+		size_t dest_len = wcslen(*dest);
+		size_t add_len = wcslen(add);
+		size_t new_len = dest_len + add_len + 1;
+		wchar_t *new_dest = (wchar_t *)realloc(*dest, sizeof(wchar_t) * new_len);
+		if (new_dest == NULL) {
+			// \x83\x81\x83\x82\x83\x8A\x95s\x91\xAB, \x89\xBD\x82\xE0\x8Ds\x82\xED\x82Ȃ\xA2
+			return;
+		}
+		wmemcpy(new_dest + dest_len, add, add_len + 1);
+		*dest = new_dest;
+	}
+}
+
+/**
+ *	\x95\xB6\x8E\x9A\x97\xF1\x82\xF0\x98A\x91\xB1\x82\xB5\x82ĘA\x8C\x8B\x82\xB7\x82\xE9
+ *	@param[in]	dest	malloc\x82\xB3\x82ꂽ\x97̈\xE6,\x95\xB6\x8E\x9A\x97\xF1
+ *						*dest == NULL\x82̏ꍇ\x82͐V\x82\xBD\x82ȗ̈悪\x8Am\x95ۂ\xB3\x82\xEA\x82\xE9
+ *						\x95s\x97v\x82ɂȂ\xC1\x82\xBD\x82\xE7 free() \x82\xB7\x82邱\x82\xC6
+ *	@param[in]	add		\x98A\x8C\x8B\x82\xB3\x82\xEA\x82镶\x8E\x9A\x97\xF1
+ *						NULL\x82̏ꍇ\x82͂Ȃɂ\xE0\x8Ds\x82\xED\x82Ȃ\xA2
+ *				NULL \x82܂ŘA\x91\xB1\x82\xB5\x82ĘA\x8C\x8B\x82\xB3\x82\xEA\x82\xE9
+ *	\x97\xE1
+ *		wchar_t *full_path = NULL;
+ *		awcscats(&full_path, dir, L"\\", filename, NULL);
+ *		CreateFileW(full_path, ...);
+ *		Free(full_path);
+ */
+void awcscats(wchar_t **dest, const wchar_t *add, ...)
+{
+	va_list ap;
+	va_start(ap, add);
+	awcscat(dest, add);
+	for(;;) {
+		const wchar_t *ap_add = va_arg(ap, wchar_t *);
+		if (ap_add == NULL) {
+			break;
+		}
+		awcscat(dest, ap_add);
+	}
+	va_end(ap);
+}

Modified: trunk/teraterm/common/asprintf.h
===================================================================
--- trunk/teraterm/common/asprintf.h	2021-10-14 14:51:19 UTC (rev 9464)
+++ trunk/teraterm/common/asprintf.h	2021-10-14 14:51:28 UTC (rev 9465)
@@ -52,6 +52,9 @@
 int vasprintf(char **strp, const char *fmt, va_list ap);
 int vaswprintf(wchar_t **strp, const wchar_t *fmt, va_list ap);
 
+void awcscat(wchar_t **dest, const wchar_t *add);
+void awcscats(wchar_t **dest, const wchar_t *add, ...);
+
 #ifdef __cplusplus
 }
 #endif

Modified: trunk/teraterm/teraterm/buffer.c
===================================================================
--- trunk/teraterm/teraterm/buffer.c	2021-10-14 14:51:19 UTC (rev 9464)
+++ trunk/teraterm/teraterm/buffer.c	2021-10-14 14:51:28 UTC (rev 9465)
@@ -5392,29 +5392,6 @@
 }
 
 /**
- *	\x95\xB6\x8E\x9A\x97\xF1\x82\xF0\x98A\x8C\x8B\x82\xB7\x82\xE9
- *	@param[in]	dest	malloc\x82\xB3\x82ꂽ\x97̈\xE6
- *						*dest == NULL\x82̏ꍇ\x82͐V\x82\xBD\x82ȗ̈悪\x8Am\x95ۂ\xB3\x82\xEA\x82\xE9
- *						\x95s\x97v\x82ɂȂ\xC1\x82\xBD\x82\xE7 free() \x82\xB7\x82邱\x82\xC6
- *	@param[in]	add		\x98A\x8C\x8B\x82\xB3\x82\xEA\x82镶\x8E\x9A\x97\xF1
- */
-static void awcscat(wchar_t **dest, const wchar_t *add)
-{
-	if (*dest == NULL) {
-		*dest = _wcsdup(add);
-		return;
-	}
-	else {
-		size_t dest_len = wcslen(*dest);
-		size_t add_len = wcslen(add);
-		size_t new_len = dest_len + add_len + 1;
-		wchar_t *new_dest = realloc(*dest, sizeof(wchar_t ) * new_len);
-		wcscat(new_dest, add);
-		*dest = new_dest;
-	}
-}
-
-/**
  *	\x8Ew\x92\xE8\x88ʒu\x82̕\xB6\x8E\x9A\x8F\xEE\x95\xF1\x82𕶎\x9A\x97\xF1\x82ŕԂ\xB7
  *	\x83f\x83o\x83O\x97p\x93r
  *


ttssh2-commit メーリングリストの案内
Zurück zum Archiv-Index