]>
Commit | Line | Data |
---|---|---|
9c72faab | 1 | //======================================================================== |
2 | // | |
3 | // Params.cc | |
4 | // | |
5 | // Copyright 1996 Derek B. Noonburg | |
6 | // | |
7 | //======================================================================== | |
8 | ||
9 | #include <stdlib.h> | |
10 | #include <stddef.h> | |
11 | #include <stdio.h> | |
12 | #include <string.h> | |
13 | #include "gtypes.h" | |
14 | #include "gmem.h" | |
15 | #include "GString.h" | |
16 | #include "gfile.h" | |
17 | #include "Params.h" | |
18 | ||
b5cb0608 | 19 | const char **fontPath = NULL; |
9c72faab | 20 | static int fontPathLen, fontPathSize; |
21 | ||
22 | DevFontMapEntry *devFontMap = NULL; | |
23 | static int devFontMapLen, devFontMapSize; | |
24 | ||
b5cb0608 | 25 | void initParams(const char *configFile) { |
9c72faab | 26 | GString *fileName; |
27 | FILE *f; | |
28 | char buf[256]; | |
29 | char *p, *q; | |
30 | ||
31 | // initialize font path and font map | |
b5cb0608 | 32 | fontPath = (const char **)gmalloc((fontPathSize = 8) * sizeof(const char *)); |
9c72faab | 33 | fontPath[fontPathLen = 0] = NULL; |
34 | devFontMap = (DevFontMapEntry *)gmalloc((devFontMapSize = 8) * | |
35 | sizeof(DevFontMapEntry)); | |
36 | devFontMap[devFontMapLen = 0].pdfFont = NULL; | |
37 | ||
38 | // read config file | |
39 | fileName = appendToPath(getHomeDir(), configFile); | |
40 | if ((f = fopen(fileName->getCString(), "r"))) { | |
41 | while (fgets(buf, sizeof(buf)-1, f)) { | |
42 | buf[sizeof(buf)-1] = '\0'; | |
43 | p = strtok(buf, " \t\n\r"); | |
44 | if (p && !strcmp(p, "fontpath")) { | |
45 | if (fontPathLen+1 >= fontPathSize) | |
b5cb0608 | 46 | fontPath = (const char **) |
47 | grealloc(fontPath, (fontPathSize += 8) * sizeof(const char *)); | |
9c72faab | 48 | p = strtok(NULL, " \t\n\r"); |
49 | fontPath[fontPathLen++] = copyString(p); | |
50 | } else if (p && !strcmp(p, "fontmap")) { | |
51 | if (devFontMapLen+1 >= devFontMapSize) | |
52 | devFontMap = (DevFontMapEntry *) | |
53 | grealloc(devFontMap, | |
54 | (devFontMapSize += 8) * sizeof(DevFontMapEntry)); | |
55 | p = strtok(NULL, " \t\n\r"); | |
56 | devFontMap[devFontMapLen].pdfFont = copyString(p); | |
57 | p = strtok(NULL, "\t\n\r"); | |
58 | while (*p == ' ') | |
59 | ++p; | |
60 | for (q = p + strlen(p) - 1; q >= p && *q == ' '; --q) ; | |
61 | q[1] = '\0'; | |
62 | devFontMap[devFontMapLen++].devFont = copyString(p); | |
63 | } | |
64 | } | |
65 | fclose(f); | |
66 | fontPath[fontPathLen] = NULL; | |
67 | devFontMap[devFontMapLen].pdfFont = NULL; | |
68 | } | |
69 | delete fileName; | |
70 | } | |
71 | ||
72 | void freeParams() { | |
73 | int i; | |
74 | ||
75 | if (fontPath) { | |
76 | for (i = 0; i < fontPathLen; ++i) | |
b5cb0608 | 77 | gfree((void *)fontPath[i]); |
78 | gfree((void *)fontPath); | |
9c72faab | 79 | } |
80 | if (devFontMap) { | |
81 | for (i = 0; i < devFontMapLen; ++i) { | |
b5cb0608 | 82 | gfree((void *)devFontMap[i].pdfFont); |
83 | gfree((void *)devFontMap[i].devFont); | |
9c72faab | 84 | } |
b5cb0608 | 85 | gfree((void *)devFontMap); |
9c72faab | 86 | } |
87 | } |