[138939] trunk/base/src/pextlib1.0
raimue at macports.org
raimue at macports.org
Fri Jul 24 03:26:50 PDT 2015
Revision: 138939
https://trac.macports.org/changeset/138939
Author: raimue at macports.org
Date: 2015-07-24 03:26:49 -0700 (Fri, 24 Jul 2015)
Log Message:
-----------
pextlib: Move implementation of ui_* wrappers from tracelib to Pextlib, replacing the previous implementation
Modified Paths:
--------------
trunk/base/src/pextlib1.0/Pextlib.c
trunk/base/src/pextlib1.0/Pextlib.h
trunk/base/src/pextlib1.0/tracelib.c
Modified: trunk/base/src/pextlib1.0/Pextlib.c
===================================================================
--- trunk/base/src/pextlib1.0/Pextlib.c 2015-07-24 09:50:07 UTC (rev 138938)
+++ trunk/base/src/pextlib1.0/Pextlib.c 2015-07-24 10:26:49 UTC (rev 138939)
@@ -105,74 +105,73 @@
#include "setmode.h"
#endif
-static char *
-ui_escape(const char *source)
-{
- char *d, *dest;
- const char *s;
- size_t dlen;
+__printflike(3, 0)
+static void ui_message(Tcl_Interp *interp, const char *severity, const char *format, va_list va) {
+ char buf[1024], tclcmd[32];
- s = source;
- dlen = strlen(source) * 2 + 1;
- d = dest = malloc(dlen);
- if (dest == NULL) {
- return NULL;
+ vsnprintf(buf, sizeof(buf), format, va);
+
+ snprintf(tclcmd, sizeof(tclcmd), "ui_%s $warn", severity);
+
+ Tcl_SetVar(interp, "warn", buf, 0);
+ if (TCL_OK != Tcl_Eval(interp, tclcmd)) {
+ fprintf(stderr, "Error evaluating tcl statement `%s': %s\n", tclcmd, Tcl_GetStringResult(interp));
}
- while(*s != '\0') {
- switch(*s) {
- case '\\':
- case '}':
- case '{':
- *d = '\\';
- d++;
- *d = *s;
- d++;
- s++;
- break;
- case '\n':
- s++;
- break;
- default:
- *d = *s;
- d++;
- s++;
- break;
- }
- }
- *d = '\0';
- return dest;
+ Tcl_UnsetVar(interp, "warn", 0);
}
-int
-ui_info(Tcl_Interp *interp, char *mesg)
-{
- const char ui_proc_start[] = "ui_info [subst -nocommands -novariables {";
- const char ui_proc_end[] = "}]";
- char *script, *string;
- size_t scriptlen, len, remaining;
- int rval;
+__printflike(2, 3)
+void ui_error(Tcl_Interp *interp, const char *format, ...) {
+ va_list va;
+ va_start(va, format);
+ ui_message(interp, "error", format, va);
+ va_end(va);
+}
- string = ui_escape(mesg);
- if (string == NULL)
- return TCL_ERROR;
+__printflike(2, 3)
+void ui_warn(Tcl_Interp *interp, const char *format, ...) {
+ va_list va;
- len = strlen(string);
- scriptlen = sizeof(ui_proc_start) + len + sizeof(ui_proc_end) - 1;
- script = malloc(scriptlen);
- if (script == NULL)
- return TCL_ERROR;
+ va_start(va, format);
+ ui_message(interp, "warn", format, va);
+ va_end(va);
+}
- memcpy(script, ui_proc_start, sizeof(ui_proc_start));
- remaining = scriptlen - sizeof(ui_proc_start);
- strncat(script, string, remaining);
- remaining -= len;
- strncat(script, ui_proc_end, remaining);
- free(string);
- rval = Tcl_EvalEx(interp, script, -1, 0);
- free(script);
- return rval;
+__printflike(2, 3)
+void ui_msg(Tcl_Interp *interp, const char *format, ...) {
+ va_list va;
+ va_start(va, format);
+ ui_message(interp, "msg", format, va);
+ va_end(va);
}
+__printflike(2, 3)
+void ui_notice(Tcl_Interp *interp, const char *format, ...) {
+ va_list va;
+
+ va_start(va, format);
+ ui_message(interp, "notice", format, va);
+ va_end(va);
+}
+
+__printflike(2, 3)
+void ui_info(Tcl_Interp *interp, const char *format, ...) {
+ va_list va;
+
+ va_start(va, format);
+ ui_message(interp, "info", format, va);
+ va_end(va);
+}
+
+__printflike(2, 3)
+void ui_debug(Tcl_Interp *interp, const char *format, ...) {
+ va_list va;
+
+ va_start(va, format);
+ ui_message(interp, "debug", format, va);
+ va_end(va);
+}
+
int StrsedCmd(ClientData clientData UNUSED, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
{
char *pattern, *string, *res;
Modified: trunk/base/src/pextlib1.0/Pextlib.h
===================================================================
--- trunk/base/src/pextlib1.0/Pextlib.h 2015-07-24 09:50:07 UTC (rev 138938)
+++ trunk/base/src/pextlib1.0/Pextlib.h 2015-07-24 10:26:49 UTC (rev 138939)
@@ -30,4 +30,9 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-int ui_info(Tcl_Interp *, char *);
+void ui_error(Tcl_Interp *interp, const char *format, ...) __printflike(2, 3);
+void ui_warn(Tcl_Interp *interp, const char *format, ...) __printflike(2, 3);
+void ui_msg(Tcl_Interp *interp, const char *format, ...) __printflike(2, 3);
+void ui_notice(Tcl_Interp *interp, const char *format, ...) __printflike(2, 3);
+void ui_info(Tcl_Interp *interp, const char *format, ...) __printflike(2, 3);
+void ui_debug(Tcl_Interp *interp, const char *format, ...) __printflike(2, 3);
Modified: trunk/base/src/pextlib1.0/tracelib.c
===================================================================
--- trunk/base/src/pextlib1.0/tracelib.c 2015-07-24 09:50:07 UTC (rev 138938)
+++ trunk/base/src/pextlib1.0/tracelib.c 2015-07-24 10:26:49 UTC (rev 138939)
@@ -63,6 +63,8 @@
#include "tracelib.h"
+#include "Pextlib.h"
+
#include "strlcat.h"
#ifdef HAVE_TRACEMODE_SUPPORT
@@ -106,12 +108,6 @@
} sandbox_violation_t;
static void sandbox_violation(int sock, const char *path, sandbox_violation_t type);
-static void ui_warn(const char *format, ...) __printflike(1, 2);
-#if 0
-static void ui_info(const char *format, ...) __printflike(1, 2);
-#endif
-static void ui_error(const char *format, ...) __printflike(1, 2);
-
#define MAX_SOCKETS (1024)
#define BUFSIZE (4096)
@@ -420,7 +416,7 @@
reg_error error;
if (NULL == (reg = registry_for(interp, reg_attached))) {
- ui_error("%s", Tcl_GetStringResult(interp));
+ ui_error(interp, "%s", Tcl_GetStringResult(interp));
/* send unexpected output to make the build fail */
answer(sock, "#");
}
@@ -438,7 +434,7 @@
/* find the port's name to compare with out list */
if (!reg_entry_propget(&entry, "name", &port, &error)) {
/* send unexpected output to make the build fail */
- ui_error("%s", error.description);
+ ui_error(interp, "%s", error.description);
answer(sock, "#");
}
@@ -455,50 +451,6 @@
answer(sock, "!");
}
-__printflike(2, 0)
-static void ui_msg(const char *severity, const char *format, va_list va) {
- char buf[1024], tclcmd[32];
-
- vsnprintf(buf, sizeof(buf), format, va);
-
- snprintf(tclcmd, sizeof(tclcmd), "ui_%s $warn", severity);
-
- Tcl_SetVar(interp, "warn", buf, 0);
- if (TCL_OK != Tcl_Eval(interp, tclcmd)) {
- fprintf(stderr, "Error evaluating tcl statement `%s': %s\n", tclcmd, Tcl_GetStringResult(interp));
- }
- Tcl_UnsetVar(interp, "warn", 0);
-
-}
-
-__printflike(1, 2)
-static void ui_warn(const char *format, ...) {
- va_list va;
-
- va_start(va, format);
- ui_msg("warn", format, va);
- va_end(va);
-}
-
-#if 0
-__printflike(1, 2)
-static void ui_info(const char *format, ...) {
- va_list va;
-
- va_start(va, format);
- ui_msg("info", format, va);
- va_end(va);
-}
-#endif
-
-__printflike(1, 2)
-static void ui_error(const char *format, ...) {
- va_list va;
- va_start(va, format);
- ui_msg("error", format, va);
- va_end(va);
-}
-
static int TracelibOpenSocketCmd(Tcl_Interp *in) {
struct sockaddr_un sun;
struct rlimit rl;
@@ -520,7 +472,7 @@
/* raise the limit of open files to the maximum from the default soft limit
* of 256 */
if (getrlimit(RLIMIT_NOFILE, &rl) == -1) {
- ui_warn("getrlimit failed (%d), skipping setrlimit", errno);
+ ui_warn(interp, "getrlimit failed (%d), skipping setrlimit", errno);
} else {
#ifdef OPEN_MAX
if (rl.rlim_max > OPEN_MAX) {
@@ -529,7 +481,7 @@
#endif
rl.rlim_cur = rl.rlim_max;
if (setrlimit(RLIMIT_NOFILE, &rl) == -1) {
- ui_warn("setrlimit failed (%d)", errno);
+ ui_warn(interp, "setrlimit failed (%d)", errno);
}
}
@@ -720,7 +672,7 @@
flags = fcntl(s, F_GETFL, 0);
if (-1 == fcntl(s, F_SETFL, flags & ~O_NONBLOCK)) {
- ui_warn("tracelib: couldn't mark socket as blocking");
+ ui_warn(interp, "tracelib: couldn't mark socket as blocking");
close(s);
continue;
}
@@ -728,7 +680,7 @@
/* register the new socket in the kqueue */
EV_SET(&kev, s, EVFILT_READ, EV_ADD | EV_RECEIPT, 0, 0, NULL);
if (1 != kevent(kq, &kev, 1, &kev, 1, NULL)) {
- ui_warn("tracelib: error adding socket to kqueue");
+ ui_warn(interp, "tracelib: error adding socket to kqueue");
close(s);
continue;
}
@@ -736,7 +688,7 @@
* always be returned. When a filter is successfully added, the data field
* will be zero. */
if ((kev.flags & EV_ERROR) == 0 || ((kev.flags & EV_ERROR) > 0 && kev.data != 0)) {
- ui_warn("tracelib: error adding socket to kqueue");
+ ui_warn(interp, "tracelib: error adding socket to kqueue");
close(s);
continue;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/macports-changes/attachments/20150724/46591a3e/attachment.html>
More information about the macports-changes
mailing list