grapheme_boundary.c (2737B)
1 /* See LICENSE file for copyright and license details. */ 2 #include <stddef.h> 3 #include <stdio.h> 4 #include <string.h> 5 6 #include "datautil.h" 7 8 static struct { 9 char *enumname; 10 char *identifier; 11 struct range *table; 12 size_t tablelen; 13 } properties[] = { 14 { 15 /* carriage return */ 16 .enumname = "GB_PROP_CR", 17 .identifier = "CR", 18 }, 19 { 20 /* line feed */ 21 .enumname = "GB_PROP_LF", 22 .identifier = "LF", 23 }, 24 { 25 /* control character */ 26 .enumname = "GB_PROP_CONTROL", 27 .identifier = "Control", 28 }, 29 { 30 /* grapheme extender */ 31 .enumname = "GB_PROP_EXTEND", 32 .identifier = "Extend", 33 }, 34 { 35 /* zero width joiner */ 36 .enumname = "GB_PROP_ZWJ", 37 .identifier = "ZWJ", 38 }, 39 { 40 /* regional indicator */ 41 .enumname = "GB_PROP_REGIONAL_INDICATOR", 42 .identifier = "Regional_Indicator", 43 }, 44 { 45 /* prepend character */ 46 .enumname = "GB_PROP_PREPEND", 47 .identifier = "Prepend", 48 }, 49 { 50 /* spacing mark */ 51 .enumname = "GB_PROP_SPACINGMARK", 52 .identifier = "SpacingMark", 53 }, 54 { 55 /* hangul syllable type L */ 56 .enumname = "GB_PROP_L", 57 .identifier = "L", 58 }, 59 { 60 /* hangul syllable type V */ 61 .enumname = "GB_PROP_V", 62 .identifier = "V", 63 }, 64 { 65 /* hangul syllable type T */ 66 .enumname = "GB_PROP_T", 67 .identifier = "T", 68 }, 69 { 70 /* hangul syllable type LV */ 71 .enumname = "GB_PROP_LV", 72 .identifier = "LV", 73 }, 74 { 75 /* hangul syllable type LVT */ 76 .enumname = "GB_PROP_LVT", 77 .identifier = "LVT", 78 }, 79 }; 80 81 int 82 process_line(char **field, size_t nfields, char *comment) 83 { 84 size_t i; 85 struct range r; 86 87 (void)comment; 88 89 if (nfields < 2) { 90 return 1; 91 } 92 93 for (i = 0; i < LEN(properties); i++) { 94 if (!strcmp(field[1], properties[i].identifier)) { 95 if (range_parse(field[0], &r)) { 96 return 1; 97 } 98 range_list_append(&(properties[i].table), 99 &(properties[i].tablelen), &r); 100 break; 101 } 102 } 103 104 return 0; 105 } 106 107 int 108 main(void) 109 { 110 size_t i, j; 111 112 printf("/* Automatically generated by data/gbp */\n" 113 "#include <stdint.h>\n\n#include \"../src/util.h\"\n\n"); 114 115 parse_input(process_line); 116 117 /* output enum */ 118 printf("enum gb_prop {\n"); 119 for (i = 0; i < LEN(properties); i++) { 120 printf("\t%s,\n", properties[i].enumname); 121 } 122 printf("};\n\n"); 123 124 /* output table */ 125 printf("static const struct range_list gb_prop[] = {\n"); 126 for (i = 0; i < LEN(properties); i++) { 127 printf("\t[%s] = {\n\t\t.data = (struct range[]){\n", properties[i].enumname); 128 for (j = 0; j < properties[i].tablelen; j++) { 129 printf("\t\t\t{ UINT32_C(0x%06X), UINT32_C(0x%06X) },\n", 130 properties[i].table[j].lower, 131 properties[i].table[j].upper); 132 } 133 printf("\t\t},\n\t\t.len = %zu,\n\t},\n", properties[i].tablelen); 134 } 135 printf("};\n"); 136 137 return 0; 138 }