po: Update ca,es,de,nl,uk translations from translationproject.org.
[pspp.git] / tests / output / tex-glyphs.c
blobf0e3891e971f43fabc07d06a85fc5afb9bf7c35a
1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 2020 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 #include <config.h>
19 #include "libpspp/hmap.h"
20 #include "tex-rendering.h"
21 #include "tex-glyphs.h"
23 #include <stdio.h>
24 #include <assert.h>
25 #include <stdlib.h>
27 static void
28 tex_render (FILE *fp, const char *str)
30 fputs (str, fp);
31 fputc ('\n', fp);
34 static long macro_insertion_point = 0;
36 static void
37 tex_preamble (FILE *fp, const char *str)
39 long where = ftell (fp);
40 fseek (fp, macro_insertion_point, SEEK_SET);
41 tex_render (fp, str);
42 fputc ('\n', fp);
43 macro_insertion_point = ftell (fp);
44 fseek (fp, where, SEEK_SET);
48 int
49 main (int argc, char **argv)
51 if (argc < 2)
53 fprintf (stderr, "Usage: tex-glyphs <file>\n");
54 return 1;
57 FILE *fp = fopen (argv[1], "w");
58 if (!fp)
60 perror ("Cannot open output file");
61 return 1;
64 struct hmap macros;
65 hmap_init (&macros);
67 fseek (fp, 4096, SEEK_SET);
69 tex_render (fp, "\\raggedbottom");
71 tex_render (fp, "\\halign{{\\tt #}\\qquad&{\\font\\xx=cmr7 \\xx #}\\hfil&\\quad{\\rm #}");
72 tex_render (fp, "\\hfil&\\quad{\\sl #}");
73 tex_render (fp, "\\hfil&\\quad{\\it #}");
74 tex_render (fp, "\\hfil&\\quad{\\bf #}");
75 tex_render (fp, "\\hfil&\\quad{\\tt #}\\cr");
77 for (const struct glyph_block *gb = defined_blocks; gb->start; ++gb)
79 ucs4_t x = gb->start->code_point;
80 for (const struct glyph *g = gb->start; x < gb->n_glyphs + gb->start->code_point; ++g)
82 assert (g->code_point == x++);
83 fprintf (fp, "U+%04X&%s&M%sM", g->code_point, g->name,
84 code_point_to_tex (g->code_point, &macros));
85 fprintf (fp, "&M%sM",
86 code_point_to_tex (g->code_point, &macros));
87 fprintf (fp, "&M%sM",
88 code_point_to_tex (g->code_point, &macros));
89 fprintf (fp, "&M%sM",
90 code_point_to_tex (g->code_point, &macros));
91 fprintf (fp, "&M%sM\\cr\n",
92 code_point_to_tex (g->code_point, &macros));
97 struct tex_macro *m;
98 struct tex_macro *next;
99 HMAP_FOR_EACH_SAFE (m, next, struct tex_macro, node, &macros)
101 tex_preamble (fp, tex_macro[m->index]);
102 free (m);
105 hmap_destroy (&macros);
107 tex_render (fp, "}");
108 tex_render (fp, "\\bye");
110 fclose (fp);
111 return 0;