Main Page | Alphabetical List | Data Structures | File List | Data Fields | Globals

term.c File Reference

#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <string.h>
#include <sys/time.h>
#include <signal.h>
#include <errno.h>
#include <unistd.h>
#include <asterisk/term.h>
#include <asterisk/options.h>
#include "asterisk.h"

Go to the source code of this file.

Functions

int term_init (void)
char * term_color (char *outbuf, const char *inbuf, int fgcolor, int bgcolor, int maxout)
char * term_prompt (char *outbuf, const char *inbuf, int maxout)
char * term_prep (void)
char * term_end (void)
char * term_quit (void)


Function Documentation

char* term_color char *  outbuf,
const char *  inbuf,
int  fgcolor,
int  bgcolor,
int  maxout
 

Definition at line 56 of file term.c.

References ATTR_BRIGHT, COLOR_BLACK, COLOR_WHITE, and ESC.

Referenced by ast_frame_dump(), ast_load_resource(), ast_log(), ast_register_application(), ast_register_translator(), load_modules(), and main().

00057 {
00058    int attr=0;
00059    char tmp[40];
00060    if (!vt100compat) {
00061       strncpy(outbuf, inbuf, maxout -1);
00062       return outbuf;
00063    }
00064    if (!fgcolor && !bgcolor) {
00065       strncpy(outbuf, inbuf, maxout - 1);
00066       return outbuf;
00067    }
00068    if ((fgcolor & 128) && (bgcolor & 128)) {
00069       /* Can't both be highlighted */
00070       strncpy(outbuf, inbuf, maxout - 1);
00071       return outbuf;
00072    }
00073    if (!bgcolor)
00074       bgcolor = COLOR_BLACK;
00075 
00076    if (bgcolor) {
00077       bgcolor &= ~128;
00078       bgcolor += 10;
00079    }
00080    if (fgcolor & 128) {
00081       attr = ATTR_BRIGHT;
00082       fgcolor &= ~128;
00083    }
00084    if (fgcolor && bgcolor) {
00085       snprintf(tmp, sizeof(tmp), "%d;%d", fgcolor, bgcolor);
00086    } else if (bgcolor) {
00087       snprintf(tmp, sizeof(tmp), "%d", bgcolor);
00088    } else if (fgcolor) {
00089       snprintf(tmp, sizeof(tmp), "%d", fgcolor);
00090    }
00091    if (attr) {
00092       snprintf(outbuf, maxout, "%c[%d;%sm%s%c[0;%d;%dm", ESC, attr, tmp, inbuf, ESC, COLOR_WHITE, COLOR_BLACK + 10);
00093    } else {
00094       snprintf(outbuf, maxout, "%c[%sm%s%c[0;%d;%dm", ESC, tmp, inbuf, ESC, COLOR_WHITE, COLOR_BLACK + 10);
00095    }
00096    return outbuf;
00097 }

char* term_end void   ) 
 

Definition at line 118 of file term.c.

Referenced by main().

00119 {
00120    return enddata;
00121 }

int term_init void   ) 
 

Definition at line 32 of file term.c.

References ATTR_BRIGHT, ATTR_RESET, COLOR_BLACK, COLOR_BROWN, COLOR_WHITE, ESC, option_console, option_nocolor, and option_nofork.

Referenced by main().

00033 {
00034    char *term = getenv("TERM");
00035    if (!term)
00036       return 0;
00037    if (!option_console || option_nocolor || !option_nofork)
00038       return 0;
00039    if (!strncasecmp(term, "linux", 5)) 
00040       vt100compat = 1; else
00041    if (!strncasecmp(term, "xterm", 5))
00042       vt100compat = 1; else
00043    if (!strncasecmp(term, "crt", 3))
00044       vt100compat = 1; else
00045    if (!strncasecmp(term, "vt", 2))
00046       vt100compat = 1;
00047    if (vt100compat) {
00048       /* Make commands show up in nice colors */
00049       snprintf(prepdata, sizeof(prepdata), "%c[%d;%d;%dm", ESC, ATTR_BRIGHT, COLOR_BROWN, COLOR_BLACK + 10);
00050       snprintf(enddata, sizeof(enddata), "%c[%d;%d;%dm", ESC, ATTR_RESET, COLOR_WHITE, COLOR_BLACK + 10);
00051       snprintf(quitdata, sizeof(quitdata), "%c[0m", ESC);
00052    }
00053    return 0;
00054 }

char* term_prep void   ) 
 

Definition at line 113 of file term.c.

00114 {
00115    return prepdata;
00116 }

char* term_prompt char *  outbuf,
const char *  inbuf,
int  maxout
 

Definition at line 99 of file term.c.

References ATTR_BRIGHT, COLOR_BLACK, COLOR_BLUE, COLOR_WHITE, and ESC.

00100 {
00101    if (!vt100compat) {
00102       strncpy(outbuf, inbuf, maxout -1);
00103       return outbuf;
00104    }
00105    snprintf(outbuf, maxout, "%c[%d;%d;%dm%c%c[%d;%d;%dm%s",
00106       ESC, ATTR_BRIGHT, COLOR_BLUE, COLOR_BLACK + 10,
00107       inbuf[0],
00108       ESC, 0, COLOR_WHITE, COLOR_BLACK + 10,
00109       inbuf + 1);
00110    return outbuf;
00111 }

char* term_quit void   ) 
 

Definition at line 123 of file term.c.

Referenced by main().

00124 {
00125    return quitdata;
00126 }


Generated on Fri Feb 27 12:19:53 2004 for Asterisk by doxygen 1.3.5