version 1.21, 2010/07/16 22:33:30 |
version 1.30, 2010/09/15 13:10:30 |
|
|
/* $Id$ */ |
/* $Id$ */ |
/* |
/* |
* Copyright (c) 2009 Kristaps Dzonsons <kristaps@bsd.lv> |
* Copyright (c) 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv> |
* |
* |
* Permission to use, copy, modify, and distribute this software for any |
* Permission to use, copy, modify, and distribute this software for any |
* purpose with or without fee is hereby granted, provided that the above |
* purpose with or without fee is hereby granted, provided that the above |
|
|
struct ln { |
struct ln { |
struct ln *next; |
struct ln *next; |
const char *code; |
const char *code; |
size_t codesz; |
|
const char *ascii; |
const char *ascii; |
size_t asciisz; |
|
int unicode; |
int unicode; |
int type; |
int type; |
#define CHARS_CHAR (1 << 0) |
#define CHARS_CHAR (1 << 0) |
|
|
#define CHARS_BOTH (CHARS_CHAR | CHARS_STRING) |
#define CHARS_BOTH (CHARS_CHAR | CHARS_STRING) |
}; |
}; |
|
|
#define LINES_MAX 370 |
#define LINES_MAX 351 |
|
|
#define CHAR(in, insz, ch, chsz, code) \ |
#define CHAR(in, ch, code) \ |
{ NULL, (in), (insz), (ch), (chsz), (code), CHARS_CHAR }, |
{ NULL, (in), (ch), (code), CHARS_CHAR }, |
#define STRING(in, insz, ch, chsz, code) \ |
#define STRING(in, ch, code) \ |
{ NULL, (in), (insz), (ch), (chsz), (code), CHARS_STRING }, |
{ NULL, (in), (ch), (code), CHARS_STRING }, |
#define BOTH(in, insz, ch, chsz, code) \ |
#define BOTH(in, ch, code) \ |
{ NULL, (in), (insz), (ch), (chsz), (code), CHARS_BOTH }, |
{ NULL, (in), (ch), (code), CHARS_BOTH }, |
|
|
#define CHAR_TBL_START static struct ln lines[LINES_MAX] = { |
#define CHAR_TBL_START static struct ln lines[LINES_MAX] = { |
#define CHAR_TBL_END }; |
#define CHAR_TBL_END }; |
Line 96 chars_init(enum chars type) |
|
Line 94 chars_init(enum chars type) |
|
tab = malloc(sizeof(struct tbl)); |
tab = malloc(sizeof(struct tbl)); |
if (NULL == tab) { |
if (NULL == tab) { |
perror(NULL); |
perror(NULL); |
exit(EXIT_FAILURE); |
exit((int)MANDOCLEVEL_SYSERR); |
} |
} |
|
|
htab = calloc(PRINT_HI - PRINT_LO + 1, sizeof(struct ln **)); |
htab = calloc(PRINT_HI - PRINT_LO + 1, sizeof(struct ln **)); |
if (NULL == htab) { |
if (NULL == htab) { |
perror(NULL); |
perror(NULL); |
exit(EXIT_FAILURE); |
exit((int)MANDOCLEVEL_SYSERR); |
} |
} |
|
|
for (i = 0; i < LINES_MAX; i++) { |
for (i = 0; i < LINES_MAX; i++) { |
Line 166 chars_spec2str(void *arg, const char *p, size_t sz, si |
|
Line 164 chars_spec2str(void *arg, const char *p, size_t sz, si |
|
if (NULL == ln) |
if (NULL == ln) |
return(NULL); |
return(NULL); |
|
|
*rsz = ln->asciisz; |
*rsz = strlen(ln->ascii); |
return(ln->ascii); |
return(ln->ascii); |
} |
} |
|
|
Line 183 chars_res2str(void *arg, const char *p, size_t sz, siz |
|
Line 181 chars_res2str(void *arg, const char *p, size_t sz, siz |
|
if (NULL == ln) |
if (NULL == ln) |
return(NULL); |
return(NULL); |
|
|
*rsz = ln->asciisz; |
*rsz = strlen(ln->ascii); |
return(ln->ascii); |
return(ln->ascii); |
} |
} |
|
|
Line 196 find(struct tbl *tab, const char *p, size_t sz, int ty |
|
Line 194 find(struct tbl *tab, const char *p, size_t sz, int ty |
|
int hash; |
int hash; |
|
|
assert(p); |
assert(p); |
assert(sz > 0); |
if (0 == sz) |
|
return(NULL); |
|
|
if (p[0] < PRINT_LO || p[0] > PRINT_HI) |
if (p[0] < PRINT_LO || p[0] > PRINT_HI) |
return(NULL); |
return(NULL); |
Line 238 match(const struct ln *ln, const char *p, size_t sz, i |
|
Line 237 match(const struct ln *ln, const char *p, size_t sz, i |
|
|
|
if ( ! (ln->type & type)) |
if ( ! (ln->type & type)) |
return(0); |
return(0); |
if (ln->codesz != sz) |
if (strncmp(ln->code, p, sz)) |
return(0); |
return(0); |
return(0 == strncmp(ln->code, p, sz)); |
return('\0' == ln->code[(int)sz]); |
} |
} |