Module: sip-router
Branch: master
Commit: c79dffa959b325da2c579b2dce94511beac83f00
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=c79dffa…
Author: Elena-Ramona Modroiu <ramona(a)asipto.com>
Committer: Elena-Ramona Modroiu <ramona(a)asipto.com>
Date: Wed Sep 26 10:20:11 2012 +0200
xlog: use the function from core to get term color codes
---
modules_k/xlog/xlog.c | 122 ++-----------------------------------------------
1 files changed, 4 insertions(+), 118 deletions(-)
diff --git a/modules_k/xlog/xlog.c b/modules_k/xlog/xlog.c
index 2ebd4e9..8a9b8c2 100644
--- a/modules_k/xlog/xlog.c
+++ b/modules_k/xlog/xlog.c
@@ -587,134 +587,20 @@ error:
return -1;
}
-#define COL_BUF 10
-
-#define append_sstring(p, end, s) \
- do{\
- if ((p)+(sizeof(s)-1)<=(end)){\
- memcpy((p), s, sizeof(s)-1); \
- (p)+=sizeof(s)-1; \
- }else{ \
- /* overflow */ \
- LM_ERR("append_sstring overflow\n"); \
- goto error;\
- } \
- } while(0)
-
-
static int pv_get_color(struct sip_msg *msg, pv_param_t *param,
pv_value_t *res)
{
- static char color[COL_BUF];
- char* p;
- char* end;
- str s;
+ str s = {"", 0};
if(log_stderr==0 && force_color==0)
{
- s.s = "";
- s.len = 0;
+ LM_DBG("ignoring colors\n");
return pv_get_strval(msg, param, res, &s);
}
- p = color;
- end = p + COL_BUF;
-
- /* excape sequenz */
- append_sstring(p, end, "\033[");
-
- if(param->pvn.u.isname.name.s.s[0]!='_')
- {
- if (islower((int)param->pvn.u.isname.name.s.s[0]))
- {
- /* normal font */
- append_sstring(p, end, "0;");
- } else {
- /* bold font */
- append_sstring(p, end, "1;");
- param->pvn.u.isname.name.s.s[0] += 32;
- }
- }
-
- /* foreground */
- switch(param->pvn.u.isname.name.s.s[0])
- {
- case 'x':
- append_sstring(p, end, "39;");
- break;
- case 's':
- append_sstring(p, end, "30;");
- break;
- case 'r':
- append_sstring(p, end, "31;");
- break;
- case 'g':
- append_sstring(p, end, "32;");
- break;
- case 'y':
- append_sstring(p, end, "33;");
- break;
- case 'b':
- append_sstring(p, end, "34;");
- break;
- case 'p':
- append_sstring(p, end, "35;");
- break;
- case 'c':
- append_sstring(p, end, "36;");
- break;
- case 'w':
- append_sstring(p, end, "37;");
- break;
- default:
- LM_ERR("invalid foreground\n");
- return pv_get_null(msg, param, res);
- }
-
- /* background */
- switch(param->pvn.u.isname.name.s.s[1])
- {
- case 'x':
- append_sstring(p, end, "49");
- break;
- case 's':
- append_sstring(p, end, "40");
- break;
- case 'r':
- append_sstring(p, end, "41");
- break;
- case 'g':
- append_sstring(p, end, "42");
- break;
- case 'y':
- append_sstring(p, end, "43");
- break;
- case 'b':
- append_sstring(p, end, "44");
- break;
- case 'p':
- append_sstring(p, end, "45");
- break;
- case 'c':
- append_sstring(p, end, "46");
- break;
- case 'w':
- append_sstring(p, end, "47");
- break;
- default:
- LM_ERR("invalid background\n");
- return pv_get_null(msg, param, res);
- }
-
- /* end */
- append_sstring(p, end, "m");
-
- s.s = color;
- s.len = p-color;
+ dprint_term_color(param->pvn.u.isname.name.s.s[0],
+ param->pvn.u.isname.name.s.s[1], &s);
return pv_get_strval(msg, param, res, &s);
-
-error:
- return -1;
}
/**