"Fossies" - the Fresh Open Source Software Archive

Member "sqlupdate-1.6.6/virhefiltteri.c" (25 Feb 2012, 3299 Bytes) of package /linux/privat/old/sqlupdate-1.6.6.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #include <stdio.h>
    2 #include <ctype.h>
    3 #include <string.h>
    4 int color=7;
    5 static void setcolor(int c)
    6 {
    7     if(color != c)
    8     {
    9         if((color&8) && !(c&8)){printf("\33[m");color=c^7;}
   10         else if((c&8) && (color<8))printf("\33[1m");
   11         printf("\33[3%cm", "04261537"[c&7]);
   12         color = c;
   13     }
   14 }
   15 static int kelpo(int c) { return isalnum(c) || c=='_'; }
   16 int main(void)
   17 {
   18     char Buf[2048];
   19     unsigned a;
   20     int rivialku=1;
   21     for(a=0;;)
   22     {
   23         int ch = getchar();
   24     next:
   25         if(ch == EOF)break;
   26         if(rivialku)
   27         {
   28             if(ch=='(' || ch==':')
   29             {
   30                 const char *p;
   31                 char *n;
   32                 Buf[a] = 0;
   33                 setcolor(5);
   34                 
   35                 for(;;)
   36                 {
   37                     const char *q = strstr(Buf, "/../");
   38                     if(!q)break;
   39                     for(p=q+3, n=q; n>Buf; )
   40                         if(*--n=='/')break;
   41                     while(*p)*n++ = *p++;
   42                     *n = 0;
   43                 }
   44                 
   45                 p = Buf;                
   46                 if(!strncmp(Buf, "/usr/include", 4+8))p = Buf+4+8;
   47                 else if(!strncmp(Buf, "/usr/local/include", 4+6+8))p = Buf+4+6+8;
   48                 if(p != Buf)
   49                 {
   50                     strcpy(Buf, "/inc");
   51                     for(n=Buf+4; *p; *n++=*p++);
   52                     *n=0;
   53                 }
   54                 printf("%s", Buf);
   55                 
   56                 rivialku = 0;
   57             }
   58             else
   59             {
   60                 Buf[a++] = ch;
   61                 continue;
   62             }
   63         }
   64         if(ch == '\n')
   65         {
   66             a = 0;
   67             rivialku = 1;
   68             setcolor(7);
   69             putchar(ch);
   70             continue;
   71         }
   72         if(strchr("<>,",ch))
   73         {
   74             setcolor(2);
   75             putchar(ch);
   76             continue;
   77         }
   78         if(strchr("()",ch))
   79         {
   80             setcolor(10);
   81             putchar(ch);
   82             continue;
   83         }
   84         if(isdigit(ch))
   85         {
   86             setcolor(9);
   87             for(;;)
   88             {
   89                 putchar(ch);
   90                 ch = getchar();
   91                 if(!isdigit(ch))goto next;
   92             }
   93         }
   94         if(!kelpo(ch))
   95         {
   96             setcolor(6);
   97             putchar(ch);
   98             continue;
   99         }
  100         for(a=0;;)
  101         {
  102             Buf[a++] = ch;
  103             ch = getchar();
  104             if(!kelpo(ch))break;
  105         }
  106         Buf[a] = 0;
  107 
  108         if(!strcmp(Buf, "basic_string"))
  109         {
  110             int n=0;
  111             setcolor(7);
  112             for(;;)
  113             {
  114                 // printf("n=%d,ch=%c\n", n, ch);
  115                 if(ch=='>')--n;
  116                 else if(ch=='<')++n;
  117                 if(ch==EOF || (!n && ch=='>'))break;
  118                 ch=getchar();
  119             }
  120             strcpy(Buf, "string");
  121             ch=getchar();
  122         }
  123         
  124         if(!strcmp(Buf, "void") || !strcmp(Buf, "bool")
  125         || !strcmp(Buf, "char") || !strcmp(Buf, "int")
  126         || !strcmp(Buf, "long") || !strcmp(Buf, "double"))
  127             setcolor(15);
  128         else
  129             setcolor(7);
  130         printf("%s", Buf);
  131         fflush(stdout);
  132         goto next;
  133     }
  134     setcolor(7);
  135     return 0;
  136 }