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