"Fossies" - the Fresh Open Source Software Archive

Member "opensips-3.0.1/utils/db_oracle/outres.c" (16 Apr 2019, 1546 Bytes) of package /linux/misc/opensips-3.0.1.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. For more information about "outres.c" see the Fossies "Dox" file reference documentation.

    1 #include "orasel.h"
    2 
    3 //-----------------------------------------------------------------------------
    4 static void out_delim(const unsigned* pl, unsigned nc)
    5 {
    6     unsigned i;
    7 
    8     for(i = 0; i < nc; i++) {
    9         unsigned j = pl[i] + 2;
   10 
   11         putchar('+');
   12         do putchar('-'); while(--j);
   13     }
   14     printf("+\n");
   15 }
   16 
   17 //-----------------------------------------------------------------------------
   18 void out_res(const res_t* _r)
   19 {
   20     unsigned* pl = NULL;
   21     unsigned  nc = _r->col_n, nr = _r->row_n, i, j;
   22     Str**     ps = _r->names;
   23 
   24     if(!outmode.raw) {
   25         pl = safe_malloc(nc * sizeof(unsigned));
   26         for(i = 0; i < nc; i++)
   27             pl[i] = ps[i]->len;
   28         for(j = 0; j < nr; j++) {
   29             ps = _r->rows[j];
   30             for(i = 0; i < nc; i++)
   31                 if(pl[i] < ps[i]->len) pl[i] = ps[i]->len;
   32         }
   33 
   34         out_delim(pl, nc);
   35     }
   36     if(!outmode.hdr) {
   37         ps = _r->names;
   38         for(i = 0; i < nc; i++) {
   39             if(!outmode.raw) {
   40                 printf("| %-*.*s ", pl[i], ps[i]->len, ps[i]->s);
   41             } else {
   42                 if(i) putchar('\t');
   43                 printf("%.*s", ps[i]->len, ps[i]->s);
   44             }
   45         }
   46         if(outmode.raw) putchar('\n');
   47         else {
   48             printf("|\n");
   49             out_delim(pl, nc);
   50         }
   51     }
   52     for(j = 0; j < nr; j++) {
   53         ps = _r->rows[j];
   54         if(!outmode.raw) {
   55             for(i = 0; i < nc; i++)
   56                 printf(_r->types[i] ? "| %-*.*s " : "| %*.*s ",
   57                     pl[i], ps[i]->len, ps[i]->s);
   58             printf("|\n");
   59         } else {
   60             for(i = 0; i < nc; i++) {
   61                 if(i) putchar('\t');
   62                 printf("%.*s", ps[i]->len, ps[i]->s);
   63             }
   64             putchar('\n');
   65         }
   66     }
   67     if(!outmode.raw) out_delim(pl, nc);
   68 }
   69 
   70 //-----------------------------------------------------------------------------