Newer
Older
/*
* BRLTTY - A background process providing access to the console screen (when in
* text mode) for a blind person using a refreshable braille display.
*
* Copyright (C) 1995-2018 by The BRLTTY Developers.
*
* BRLTTY comes with ABSOLUTELY NO WARRANTY.
*
* This is free software, placed under the terms of the
* GNU Lesser General Public License, as published by the Free Software
* Foundation; either version 2.1 of the License, or (at your option) any
* later version. Please see the file LICENSE-LGPL for details.
*
* This software is maintained by Dave Mielke <dave@mielke.cc>.
*/
#include "prologue.h"
#include <stdio.h>
#include "ttb.h"
#include "ttb_internal.h"
#include "atb.h"
#include "atb_internal.h"
#include "ctb.h"
#include "ctb_internal.h"
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
typedef struct {
void *object;
const unsigned char *bytes;
size_t size;
} TableData;
typedef struct {
const char *extension;
int (*load) (const char *path, TableData *data);
void (*unload) (TableData *data);
} TableEntry;
static int
loadTextTable (const char *path, TableData *data) {
TextTable *table = compileTextTable(path);
if (!table) return 0;
data->object = table;
data->bytes = table->header.bytes;
data->size = table->size;
return 1;
}
static void
unloadTextTable (TableData *data) {
destroyTextTable(data->object);
}
static int
loadAttributesTable (const char *path, TableData *data) {
AttributesTable *table = compileAttributesTable(path);
if (!table) return 0;
data->object = table;
data->bytes = table->header.bytes;
data->size = table->size;
return 1;
}
static void
unloadAttributesTable (TableData *data) {
destroyAttributesTable(data->object);
}
static int
loadContractionTable (const char *path, TableData *data) {
ContractionTable *table = compileContractionTable(path);
if (!table) return 0;
data->object = table;
data->bytes = table->data.internal.header.bytes;
data->size = table->data.internal.size;
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
return 1;
}
static void
unloadContractionTable (TableData *data) {
destroyContractionTable(data->object);
}
static const TableEntry tableEntries[] = {
{
.extension = TEXT_TABLE_EXTENSION,
.load = loadTextTable,
.unload = unloadTextTable
}
,
{
.extension = ATTRIBUTES_TABLE_EXTENSION,
.load = loadAttributesTable,
.unload = unloadAttributesTable
}
,
{
.extension = CONTRACTION_TABLE_EXTENSION,
.load = loadContractionTable,
.unload = unloadContractionTable
}
,
{
.extension = NULL
}
};
static const TableEntry *
findTableEntry (const char *extension) {
const TableEntry *entry = tableEntries;
while (entry->extension) {
if (strcmp(entry->extension, extension) == 0) return entry;
entry += 1;
}
logMessage(LOG_ERR, "unrecognized file extension: %s", extension);
return NULL;
}
int
dumpBytes (FILE *stream, const unsigned char *bytes, size_t count) {
const unsigned char *byte = bytes;
const unsigned char *end = byte + count;
int first = 1;
int digits;
if (count) {
char buffer[0X10];
digits = snprintf(buffer, sizeof(buffer), "%X", (unsigned int)count-1);
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
} else {
digits = 1;
}
while (byte < end) {
while (!*byte && (byte < (end - 1))) byte += 1;
{
unsigned int counter = 0;
unsigned int maximum = 8;
if ((byte + maximum) != end) {
while (maximum > 1) {
if (byte[maximum-1]) break;
maximum -= 1;
}
}
while (byte < end) {
if (first) {
first = 0;
} else {
fprintf(stream, ",");
if (ferror(stream)) goto outputError;
if (!counter) {
fprintf(stream, "\n");
if (ferror(stream)) goto outputError;
}
}
if (!counter) {
fprintf(stream, "[0X%0*X] =", digits, (unsigned int)(byte-bytes));
if (ferror(stream)) goto outputError;
}
fprintf(stream, " 0X%02X", *byte++);
if (ferror(stdout)) goto outputError;
if (++counter == maximum) break;
}
}
}
if (!first) {
fprintf(stream, "\n");
if (ferror(stream)) goto outputError;
}
return 1;
outputError:
logMessage(LOG_ERR, "table write error: %s", strerror(errno));
{
static const OptionsDescriptor descriptor = {
OPTION_TABLE(programOptions),
.applicationName = "tbl2hex",
logMessage(LOG_ERR, "missing table file.");
const char *extension = locatePathExtension(path);
if (extension) {
const TableEntry *entry = findTableEntry(extension);
if (entry) {
TableData data;
if (entry->load(path, &data)) {
if (dumpBytes(stdout, data.bytes, data.size)) {
logMessage(LOG_ERR, "no file extension");
#include "ctb_internal.h"
const ContractionTableTranslationMethods *
getContractionTableTranslationMethods_native (void) {
return NULL;
}
const ContractionTableTranslationMethods *
getContractionTableTranslationMethods_external (void) {
return NULL;
}
const ContractionTableTranslationMethods *
getContractionTableTranslationMethods_louis (void) {
return NULL;
}