[Serdev] xlog color patch / diff as attachment

Ingo Wolfsberger iwolfsberger at gmx.net
Sun Jun 12 21:38:39 UTC 2005


Hi

> Can you submit these as attachments?

Done.

bye,
    Ingo

> William
> 
> Ingo Wolfsberger wrote:
> 
> >Hi
> >
> >xlog is very powerfull, but finding a log entry is hard.
> >With xlog color patch it is possible to change the color (foreground,
> >background) of the log entry. An ansi color capable term(emulation) is
> >needed.
> >
> >>>From the readme:
> >     _________________________________________________________
> >1.2.1 Color Specifiers
> >
> >     *  %Cxy : Color specifier; x: foreground, y: background
> >
> >     Colors could be:
> >
> >     * s : Black
> >     * r : Red
> >     * g : Green
> >     * y : Yellow
> >     * b : Blue
> >     * p : Purple
> >     * c : Cyan
> >     * w : White
> >
> >     Writting the 1st color specifier in capitals gives bold 
> >     text.
> >     The 2nd color specifier could be left away to only change 
> >     foreground color.
> >     _________________________________________________________
> >
> >The patch:
> >     _________________________________________________________
> >Common subdirectories: modules/xlog_org/CVS and modules/xlog/CVS
> >Common subdirectories: modules/xlog_org/doc and modules/xlog/doc
> >diff modules/xlog_org/README modules/xlog/README
> >97a98,117
> >  
> >
> >>1.2.1 Color Specifiers
> >>
> >>     *  %Cxy : Color specifier; x: foreground, y: background
> >>
> >>     Colors could be:
> >>
> >>     * s : Black
> >>     * r : Red
> >>     * g : Green
> >>     * y : Yellow
> >>     * b : Blue
> >>     * p : Purple
> >>     * c : Cyan
> >>     * w : White
> >>
> >>     Writting the 1st color specifier in capitals gives bold 
> >>     text.
> >>     The 2nd color specifier could be left away to only change 
> >>     foreground color.
> >>    
> >>
> >diff -W 60 modules/xlog_org/xl_lib.c modules/xlog/xl_lib.c
> >40a41
> >  
> >
> >>#include <ctype.h>
> >>    
> >>
> >65a67,68
> >  
> >
> >>#define COL_BUF 20
> >>
> >>    
> >>
> >68a72,166
> >  
> >
> >>static int xl_get_color(struct sip_msg *msg, str *res, str *hp, int hi) 
> >>{
> >>      static char color[COL_BUF];
> >>      
> >>      /* excape sequenz */
> >>      strncpy( color, "\033[", COL_BUF);
> >>      
> >>        if (islower(hp->s[0])) {
> >>                /* normal font */
> >>                strncpy( color+strlen(color), "0;", COL_BUF);
> >>        }
> >>        else {
> >>                /* bold font */
> >>                strncpy( color+strlen(color), "1;", COL_BUF);
> >>                        hp->s[0] += 32;
> >>        }
> >>      
> >>      /* foreground */
> >>      switch(hp->s[0])
> >>      {
> >>              case 's':
> >>                      strncpy( color+strlen(color), "30;", COL_BUF);
> >>              break;
> >>              case 'r':
> >>                      strncpy( color+strlen(color), "31;", COL_BUF);
> >>              break;
> >>              case 'g':
> >>                      strncpy( color+strlen(color), "32;", COL_BUF);
> >>              break;
> >>              case 'y':
> >>                      strncpy( color+strlen(color), "33;", COL_BUF);
> >>              break;
> >>              case 'b':
> >>                      strncpy( color+strlen(color), "34;", COL_BUF);
> >>              break;
> >>              case 'p':
> >>                      strncpy( color+strlen(color), "35;", COL_BUF);
> >>              break;
> >>              case 'c':
> >>                      strncpy( color+strlen(color), "36;", COL_BUF);
> >>              break;
> >>              case 'w':
> >>                      strncpy( color+strlen(color), "37;", COL_BUF);
> >>              break;
> >>              default:
> >>                      LOG(L_ERR, "XLOG: exit foreground\n");
> >>                      return -1;
> >>      }
> >>      
> >>      /* background */
> >>      if (hp->len == 1) {
> >>              switch(hp->s[1])
> >>              {
> >>                      case 's':
> >>                              strncpy( color+strlen(color), "40",
> >>    
> >>
> >COL_BUF);
> >  
> >
> >>                      break;
> >>                      case 'r':
> >>                              strncpy( color+strlen(color), "41",
> >>    
> >>
> >COL_BUF);
> >  
> >
> >>                      break;
> >>                      case 'g':
> >>                              strncpy( color+strlen(color), "42",
> >>    
> >>
> >COL_BUF);
> >  
> >
> >>                      break;
> >>                      case 'y':
> >>                              strncpy( color+strlen(color), "43",
> >>    
> >>
> >COL_BUF);
> >  
> >
> >>                      break;
> >>                      case 'b':
> >>                              strncpy( color+strlen(color), "44",
> >>    
> >>
> >COL_BUF);
> >  
> >
> >>                      break;
> >>                      case 'p':
> >>                              strncpy( color+strlen(color), "45",
> >>    
> >>
> >COL_BUF);
> >  
> >
> >>                      break;
> >>                      case 'c':
> >>                              strncpy( color+strlen(color), "46",
> >>    
> >>
> >COL_BUF);
> >  
> >
> >>                      break;
> >>                      case 'w':
> >>                              strncpy( color+strlen(color), "47",
> >>    
> >>
> >COL_BUF);
> >  
> >
> >>                      break;
> >>                      default: 
> >>                              return -1;
> >>              }
> >>      }
> >>      else {
> >>              strncpy( color+strlen(color), "40", COL_BUF);
> >>      }
> >>
> >>      /* end */
> >>      strncpy( color+strlen(color), "m", COL_BUF);
> >>
> >>      res->s = color;
> >>      res->len = strlen(color);
> >>      return 0;
> >>}
> >>      
> >>
> >>
> >>    
> >>
> >727a826,827
> >  
> >
> >>        char buf[COL_BUF];
> >>        *buf = '\0';
> >>    
> >>
> >794a895,967
> >  
> >
> >>                      case 'C':
> >>                                p++;
> >>                              e->hparam.s = p;
> >>                              
> >>                              /* foreground */
> >>                              switch(*p)
> >>                              {
> >>                                      case 's':
> >>                                      break;
> >>                                      case 'r':
> >>                                        break;
> >>                                        case 'g':
> >>                                        break;
> >>                                        case 'y':
> >>                                        break;
> >>                                        case 'b':
> >>                                        break;
> >>                                        case 'p':
> >>                                        break;
> >>                                        case 'c':
> >>                                        break;
> >>                                        case 'w':
> >>                                        break;
> >>                                        case 'S':
> >>                                        break;
> >>                                        case 'R':
> >>                                        break;   
> >>                                        case 'G':
> >>                                        break;   
> >>                                        case 'Y':
> >>                                        break;   
> >>                                        case 'B':
> >>                                        break;   
> >>                                        case 'P':
> >>                                        break;   
> >>                                        case 'C':
> >>                                        break;   
> >>                                        case 'W':
> >>                                        break;   
> >>                                      default:
> >>                                              e->itf = xl_get_null;
> >>                                              goto error;
> >>                              }
> >>                              p++;
> >>                              
> >>                              /* background */
> >>                              switch(*p)
> >>                                {
> >>                                        case 's':
> >>                                        break;
> >>                                        case 'r':
> >>                                        break;
> >>                                        case 'g':
> >>                                        break;
> >>                                        case 'y':
> >>                                        break;
> >>                                        case 'b':
> >>                                        break;
> >>                                        case 'p':
> >>                                        break;
> >>                                        case 'c':
> >>                                        break;
> >>                                        case 'w':
> >>                                        break;
> >>                                        default:
> >>                                              p--;
> >>                                }   
> >>                              
> >>                              /* end */
> >>                              e->hparam.len = p - e->hparam.s;
> >>                              e->itf = xl_get_color;
> >>                              
> >>                      break;
> >>    
> >>
> >1057c1230
> ><       int n;
> >---
> >  
> >
> >>      int n, h;
> >>    
> >>
> >1070c1243,1244
> ><       
> >---
> >  
> >
> >>      
> >>      h = 0;
> >>    
> >>
> >1076c1250
> ><               {
> >---
> >  
> >
> >>              {       
> >>    
> >>
> >1093a1268,1273
> >  
> >
> >>                              /* check for color entries to reset later
> */
> >>                              if (*it->itf == xl_get_color) {
> >>                                      h = 1;
> >>                              }
> >>                                      
> >>    
> >>
> >1098a1279,1287
> >  
> >
> >>      
> >>      /* reset to default after entry */
> >>      if ((h == 1) && ((n+strlen("\033[0m")) < *len))
> >>      {
> >>              memcpy(cur, "\033[0m", strlen("\033[0m"));
> >>              n += strlen("\033[0m");
> >>              cur += strlen("\033[0m");
> >>      } 
> >>
> >>    
> >>
> >     _________________________________________________________
> >
> >bye,
> >    Ingo
> >
> >  
> >
> 

-- 
Weitersagen: GMX DSL-Flatrates mit Tempo-Garantie!
Ab 4,99 Euro/Monat: http://www.gmx.net/de/go/dsl
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch_xlog_color
Type: application/octet-stream
Size: 6852 bytes
Desc: not available
Url : http://lists.iptel.org/pipermail/serdev/attachments/20050612/d37bf3a9/patch_xlog_color.obj


More information about the Serdev mailing list