aboutsummaryrefslogtreecommitdiffstats
path: root/main/term.c
diff options
context:
space:
mode:
authorrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2008-11-01 21:10:07 +0000
committerrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2008-11-01 21:10:07 +0000
commitb1f91b97d2085cc845d0f57bd9907de50c995105 (patch)
tree9c836ac808552d20be6bd2baa3a3c29f642eda53 /main/term.c
parentc5d084051f21e943fcbcc347fc80b166885f298d (diff)
Merge changes from team/group/appdocsxml
This commit introduces the first phase of an effort to manage documentation of the interfaces in Asterisk in an XML format. Currently, a new format is available for applications and dialplan functions. A good number of conversions to the new format are also included. For more information, see the following message to asterisk-dev: http://lists.digium.com/pipermail/asterisk-dev/2008-October/034968.html git-svn-id: http://svn.digium.com/svn/asterisk/trunk@153365 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main/term.c')
-rw-r--r--main/term.c64
1 files changed, 52 insertions, 12 deletions
diff --git a/main/term.c b/main/term.c
index d12135f24..7f38ee5ce 100644
--- a/main/term.c
+++ b/main/term.c
@@ -199,32 +199,72 @@ char *term_color(char *outbuf, const char *inbuf, int fgcolor, int bgcolor, int
return outbuf;
}
-char *term_color_code(char *outbuf, int fgcolor, int bgcolor, int maxout)
+static void check_fgcolor(int *fgcolor, int *attr)
{
- int attr = 0;
- if ((!vt100compat) || (!fgcolor)) {
- *outbuf = '\0';
- return outbuf;
+ if (*fgcolor & 128) {
+ *attr = ast_opt_light_background ? 0 : ATTR_BRIGHT;
+ *fgcolor &= ~128;
+ }
+
+ if (ast_opt_light_background) {
+ *fgcolor = opposite(*fgcolor);
}
+}
- if (fgcolor & 128) {
- attr = ast_opt_light_background ? 0 : ATTR_BRIGHT;
- fgcolor &= ~128;
+static void check_bgcolor(int *bgcolor)
+{
+ if (*bgcolor) {
+ *bgcolor &= ~128;
}
+}
- if (ast_opt_light_background) {
- fgcolor = opposite(fgcolor);
+static int check_colors_allowed(int fgcolor)
+{
+ return (!vt100compat || !fgcolor) ? 0 : 1;
+}
+
+int ast_term_color_code(struct ast_str **str, int fgcolor, int bgcolor)
+{
+ int attr = 0;
+
+ if (!check_colors_allowed(fgcolor)) {
+ return -1;
}
- if (bgcolor) {
- bgcolor &= ~128;
+ check_fgcolor(&fgcolor, &attr);
+ check_bgcolor(&bgcolor);
+
+ if (ast_opt_force_black_background) {
+ ast_str_append(str, 0, "%c[%d;%d;%dm", ESC, attr, fgcolor, COLOR_BLACK + 10);
+ } else if (bgcolor) {
+ ast_str_append(str, 0, "%c[%d;%d;%dm", ESC, attr, fgcolor, bgcolor + 10);
+ } else {
+ ast_str_append(str, 0, "%c[%d;%dm", ESC, attr, fgcolor);
}
+ return 0;
+}
+
+char *term_color_code(char *outbuf, int fgcolor, int bgcolor, int maxout)
+{
+ int attr = 0;
+
+ if (!check_colors_allowed(fgcolor)) {
+ *outbuf = '\0';
+ return outbuf;
+ }
+
+ check_fgcolor(&fgcolor, &attr);
+ check_bgcolor(&bgcolor);
+
if (ast_opt_force_black_background) {
+ snprintf(outbuf, maxout, "%c[%d;%d;%dm", ESC, attr, fgcolor, COLOR_BLACK + 10);
+ } else if (bgcolor) {
snprintf(outbuf, maxout, "%c[%d;%d;%dm", ESC, attr, fgcolor, bgcolor + 10);
} else {
snprintf(outbuf, maxout, "%c[%d;%dm", ESC, attr, fgcolor);
}
+
return outbuf;
}