"Fossies" - the Fresh Open Source Software Archive

Member "teapot-2.3.0/htmlio.c" (6 Feb 2012, 3777 Bytes) of package /linux/privat/old/teapot-2.3.0.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 "htmlio.c" see the Fossies "Dox" file reference documentation.

    1 /* #includes */ /*{{{C}}}*//*{{{*/
    2 #ifndef NO_POSIX_SOURCE
    3 #undef _POSIX_SOURCE
    4 #define _POSIX_SOURCE   1
    5 #undef _POSIX_C_SOURCE
    6 #define _POSIX_C_SOURCE 2
    7 #endif
    8 
    9 #ifdef DMALLOC
   10 #include "dmalloc.h"
   11 #endif
   12 
   13 #include <assert.h>
   14 #include <errno.h>
   15 #include <limits.h>
   16 #include <stdio.h>
   17 #include <stdlib.h>
   18 #include <string.h>
   19 
   20 
   21 #include "htmlio.h"
   22 #include "main.h"
   23 #include "misc.h"
   24 /*}}}*/
   25 
   26 /* savehtml      -- save as HTML table */ /*{{{*/
   27 const char *savehtml(Sheet *sheet, const char *name, int body, int x1, int y1, int z1, int x2, int y2, int z2, unsigned int *count)
   28 {
   29   /* variables */ /*{{{*/
   30   FILE *fp=(FILE*)0; /* cause runtime error */
   31   int x,y,z;
   32   char buf[1024];
   33   char num[20];
   34   char fullname[PATH_MAX];
   35   /*}}}*/
   36   
   37   /* asserts */ /*{{{*/
   38   assert(sheet!=(Sheet*)0);
   39   assert(name!=(const char*)0);
   40   /*}}}*/
   41   *count=0;
   42   for (z=z1; z<=z2; ++z) for (y=y1; y<=y2; ++y) if (shadowed(sheet,x1,y,z)) return _("Shadowed cells in first column");
   43   if (!body && (fp=fopen(name,"w"))==(FILE*)0) return strerror(errno);
   44   for (z=z1; z<=z2; ++z)
   45   {
   46     if (body) /* open new file */ /*{{{*/
   47     {
   48       sprintf(num,".%d",z);
   49 
   50       fullname[sizeof(fullname)-strlen(num)-1]='\0';
   51       (void)strncpy(fullname,name,sizeof(fullname)-strlen(num)-1);
   52       fullname[sizeof(fullname)-1]='\0';
   53       (void)strncat(fullname,num,sizeof(fullname)-strlen(num)-1);
   54       fullname[sizeof(fullname)-1]='\0';  
   55       if ((fp=fopen(fullname,"w"))==(FILE*)0) return strerror(errno);
   56     }
   57     /*}}}*/
   58     else /* print header */ /*{{{*/
   59     if (fputs_close("<html>\n<head>\n<title>\n</title>\n</head>\n<body>\n",fp)==EOF) return strerror(errno);
   60     /*}}}*/
   61 
   62     if (fputs_close("<table>\n",fp)==EOF) return strerror(errno);
   63     for (y=y1; y<=y2; ++y) /* print contents */ /*{{{*/
   64     {
   65       if (fputs_close("<tr>",fp)==EOF) return strerror(errno);
   66       for (x=x1; x<=x2; )
   67       {
   68         int multicols;
   69         char *bufp;
   70       
   71         for (multicols=x+1; multicols<sheet->dimx && shadowed(sheet,multicols,y,z); ++multicols);
   72         multicols=multicols-x;
   73         if (multicols>1) fprintf(fp,"<td colspan=%d",multicols);
   74         else fprintf(fp,"<td");
   75         switch (getadjust(sheet,x,y,z))
   76         {
   77           case LEFT: if (fputs_close(" align=left>",fp)==EOF) return strerror(errno); break;
   78           case RIGHT: if (fputs_close(" align=right>",fp)==EOF) return strerror(errno); break;
   79           case CENTER: if (fputs_close(" align=center>",fp)==EOF) return strerror(errno); break;
   80           default: assert(0);
   81         }
   82         printvalue(buf,sizeof(buf),0,0,getscientific(sheet,x,y,z),getprecision(sheet,x,y,z),sheet,x,y,z);
   83         if (transparent(sheet,x,y,z))
   84         {
   85           if (fputs_close(buf,fp)==EOF) return strerror(errno);
   86         }
   87         else for (bufp=buf; *bufp; ++bufp) switch (*bufp)
   88         {
   89           case '<': if (fputs_close("&lt;",fp)==EOF) return strerror(errno); break;
   90           case '>': if (fputs_close("&gt;",fp)==EOF) return strerror(errno); break;
   91           case '&': if (fputs_close("&amp;",fp)==EOF) return strerror(errno); break;
   92           case '"': if (fputs_close("&quot;",fp)==EOF) return strerror(errno); break;
   93           default: if (fputc_close(*bufp,fp)==EOF) return strerror(errno);
   94         }
   95         if (fputs_close("</td>",fp)==EOF) return strerror(errno);
   96         x+=multicols;
   97         ++*count;
   98       }
   99       if (fputs_close("</tr>\n",fp)==EOF) return strerror(errno);
  100     }
  101     /*}}}*/
  102     if (fputs_close("</table>\n",fp)==EOF) return strerror(errno);
  103     if (body)
  104     {
  105       if (fclose(fp)==EOF) return strerror(errno);
  106     }
  107   }
  108   if (!body)
  109   {
  110     if (fputs_close("</body>\n</html>\n",fp)==EOF) return strerror(errno);
  111     if (fclose(fp)==EOF) return strerror(errno);
  112   }
  113   return (const char*)0;
  114 }
  115 /*}}}*/