47void load_tld_file(
char * filename)
49 tld_file_free(&g_tld_file);
50 tld_file_error err(tld_file_load(filename, &g_tld_file));
51 if(err != TLD_FILE_ERROR_NONE)
55 <<
"error: could not load TLD file \""
65 if(g_tld_file ==
nullptr)
69 <<
"error: not loaded TLD file, try --input before other options.\n";
77void print_string(
int index,
bool newline =
true)
85 const char *str = tld_file_string(g_tld_file, index, &l);
86 std::string s(str, l);
88 std::cout <<
"tld_string[" << index <<
"] = \"" << s <<
"\".";
95void print_tag(
int index,
bool one_line =
false)
102 const tld_tag *tag(tld_file_tag(g_tld_file, index));
109 <<
"] not found (index too large?).\n";
113 std::cout <<
"tag[" << index <<
"].f_name = ";
114 print_string(tag->f_tag_name, !one_line);
117 std::cout <<
" .f_value = ";
118 print_string(tag->f_tag_value);
122 std::cout <<
"tag[" << index <<
"].f_value = ";
123 print_string(tag->f_tag_value);
127void print_tld(
int index)
141 <<
"] not found (index too large?).\n";
145 std::cout <<
"tld[" << index <<
"].f_status = "
146 <<
static_cast<int>(
tld->f_status)
151 std::cout <<
"tld[" << index <<
"].f_exception_level = "
152 <<
static_cast<int>(
tld->f_exception_level)
155 if(
tld->f_exception_apply_to != SHRT_MAX)
157 std::cout <<
"tld[" << index <<
"].f_exception_apply_to =\n\n";
158 print_tld(
tld->f_exception_apply_to);
162 std::cout <<
"tld[" << index <<
"].f_start_offset = "
163 <<
tld->f_start_offset
166 std::cout <<
"tld[" << index <<
"].f_end_offset = "
170 std::cout <<
"tld[" << index <<
"].f_tld = ";
171 print_string(
tld->f_tld);
173 for(uint16_t idx(0); idx <
tld->f_tags_count; ++idx)
175 std::cout <<
"tld[" << index <<
"].f_tags[" << idx <<
"] = ";
176 print_tag(
tld->f_tags + idx * 2,
true);
188 std::cout <<
"Number of ...\n"
189 <<
"... descriptions: " << g_tld_file->f_descriptions_count <<
"\n"
190 <<
"... tags: " << g_tld_file->f_tags_size <<
"\n"
191 <<
"... strings: " << g_tld_file->f_strings_count <<
"\n"
192 <<
"... characters: " << g_tld_file->f_strings_end - g_tld_file->f_strings <<
"\n"
197int main(
int argc,
char * argv[])
199 for(
int i(1); i < argc; ++i)
201 if(argv[i][0] ==
'-')
203 if(strcmp(argv[i],
"-h") == 0
204 || strcmp(argv[i],
"--help") == 0)
206 std::cout <<
"Usage: extract-tld <opts>\n"
207 "where <opts> is one or more of:\n"
208 " --help | -h print this help screen\n"
209 " --tag | -T <index> print tag at that index out of all the tags\n"
210 " --tld | -t <offset> retrieve that specific TLD\n"
211 " --string | -s <index> print string at that index\n"
212 " --version | -V print out the version and exit\n"
213 " --input <filename> use <filename> as the TLD file to read from\n"
217 else if(strcmp(argv[i],
"-V") == 0
218 || strcmp(argv[i],
"--version") == 0)
223 else if(strcmp(argv[i],
"-s") == 0
224 || strcmp(argv[i],
"--string") == 0)
231 <<
"error: argument missing for --string.\n";
235 print_string(atoi(argv[i]));
238 else if(strcmp(argv[i],
"-T") == 0
239 || strcmp(argv[i],
"--tag") == 0)
246 <<
"error: argument missing for --tag.\n";
250 print_tag(atoi(argv[i]));
253 else if(strcmp(argv[i],
"-t") == 0
254 || strcmp(argv[i],
"--tld") == 0)
261 <<
"error: argument missing for --tld.\n";
265 print_tld(atoi(argv[i]));
268 else if(strcmp(argv[i],
"--sizes") == 0)
272 else if(strcmp(argv[i],
"--input") == 0)
279 <<
"error: argument missing for --input.\n";
283 load_tld_file(argv[i]);
290 <<
"error: unknown command line option \""
299 <<
"error: unknown command line option \""
305 return g_errcnt > 0 ? 1 : 0;
[internal] The description of one TLD.
The public header of the libtld library.
LIBTLD_EXPORT enum tld_result tld(const char *uri, struct tld_info *info)
Get information about the TLD for the specified URI.
#define LIBTLD_VERSION
The version of the library as a string.
LIBTLD_EXPORT const char * tld_status_to_string(enum tld_status status)
Transform the status to a string.
Declaration of the TLD file structures.