| 1 |
/* |
| 2 |
tables.c |
| 3 |
Produce figures illustrating fancynum |
| 4 |
Part of the fancynum package |
| 5 |
Copyright (c) J.J.Green 1999. |
| 6 |
[email protected] |
| 7 |
$Id: tables.c,v 1.7 2000/03/15 18:53:47 ap1jjg Exp $ |
| 8 |
*/ |
| 9 |
|
| 10 |
|
| 11 |
#include <stdlib.h> |
| 12 |
#include <stdio.h> |
| 13 |
|
| 14 |
/* |
| 15 |
static constants |
| 16 |
*/ |
| 17 |
|
| 18 |
static const double sampledouble = 3.141592653589793238462643383; |
| 19 |
|
| 20 |
static const char table_line[] = |
| 21 |
"\\verb|\%%%s| & \\verb|%s| & $\\fnum{%s}$"; |
| 22 |
static char texformat[100]; |
| 23 |
|
| 24 |
/* |
| 25 |
static prototypes |
| 26 |
*/ |
| 27 |
|
| 28 |
static void maketable(char*, |
| 29 |
char* (*)(char*,const char*), |
| 30 |
const char**, |
| 31 |
char*, |
| 32 |
char*); |
| 33 |
static void tabulate(FILE*, |
| 34 |
char* (*)(char*,const char*), |
| 35 |
const char**, |
| 36 |
char*, |
| 37 |
char*); |
| 38 |
static char* dblsample(char*,const char*); |
| 39 |
|
| 40 |
int main(void) |
| 41 |
{ |
| 42 |
const char* dblformats[] = |
| 43 |
{"%f","%e","%g","%.9f","%.9e","%.9g",NULL}; |
| 44 |
|
| 45 |
maketable( |
| 46 |
"dbltable.tex", |
| 47 |
dblsample, |
| 48 |
dblformats, |
| 49 |
"Double conversions for $\\pi$", |
| 50 |
"dbltable"); |
| 51 |
|
| 52 |
return EXIT_SUCCESS; |
| 53 |
} |
| 54 |
|
| 55 |
static void maketable( |
| 56 |
char* filename, |
| 57 |
char* (*linefn)(char*,const char*), |
| 58 |
const char** samples, |
| 59 |
char* title, |
| 60 |
char* label) |
| 61 |
{ |
| 62 |
FILE* texfile; |
| 63 |
|
| 64 |
texfile = fopen(filename,"w"); |
| 65 |
if (texfile == NULL) return; |
| 66 |
|
| 67 |
tabulate(texfile,linefn,samples,title,label); |
| 68 |
(void)fclose(texfile);; |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
static char* dblsample(char* buffer,const char* format) |
| 73 |
{ |
| 74 |
double a = sampledouble; |
| 75 |
|
| 76 |
sprintf(texformat,table_line,format,format,format); |
| 77 |
sprintf(buffer,(const char*)texformat,a,a); |
| 78 |
|
| 79 |
return buffer; |
| 80 |
} |
| 81 |
|
| 82 |
static void tabulate( |
| 83 |
FILE* texfile, |
| 84 |
char* (*linefn)(char*,const char*), |
| 85 |
const char** samples, |
| 86 |
char* title, |
| 87 |
char* label) |
| 88 |
{ |
| 89 |
char* line; |
| 90 |
char buffer[500]; |
| 91 |
|
| 92 |
fprintf(texfile,"%% automatically generated by tables.c\n"); |
| 93 |
fprintf(texfile,"\\begin{table}[tbh]\n"); |
| 94 |
fprintf(texfile,"\\begin{center}\n"); |
| 95 |
fprintf(texfile,"\\begin{tabular}{|c|c|c|}\n"); |
| 96 |
fprintf(texfile,"\\hline\n"); |
| 97 |
fprintf(texfile,"Format & Output & Typeset \\\\ \\hline \n"); |
| 98 |
while (*samples != NULL) |
| 99 |
{ |
| 100 |
line = linefn(buffer,*samples); |
| 101 |
fprintf(texfile,"%s \\\\\n",line); |
| 102 |
samples++; |
| 103 |
} |
| 104 |
fprintf(texfile,"\\hline\n"); |
| 105 |
fprintf(texfile,"\\end{tabular}\n"); |
| 106 |
fprintf(texfile,"\\end{center}\n"); |
| 107 |
fprintf(texfile,"\\caption{%s\\label{%s}}\n",title,label); |
| 108 |
fprintf(texfile,"\\end{table}\n"); |
| 109 |
} |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|