gbp.c (2004B)
1 /* See LICENSE file for copyright and license details. */ 2 #include <stddef.h> 3 #include <stdio.h> 4 #include <string.h> 5 6 #include "util.h" 7 8 static struct { 9 char *identifier; 10 char *tablename; 11 struct range *table; 12 size_t tablelen; 13 } properties[] = { 14 { 15 .identifier = "CR", 16 .tablename = "cr_table", 17 }, 18 { 19 .identifier = "LF", 20 .tablename = "lf_table", 21 }, 22 { 23 .identifier = "Control", 24 .tablename = "control_table", 25 }, 26 { 27 .identifier = "Extend", 28 .tablename = "extend_table", 29 }, 30 { 31 .identifier = "ZWJ", 32 .tablename = "zwj_table", 33 }, 34 { 35 .identifier = "Regional_Indicator", 36 .tablename = "ri_table", 37 }, 38 { 39 .identifier = "Prepend", 40 .tablename = "prepend_table", 41 }, 42 { 43 .identifier = "SpacingMark", 44 .tablename = "spacingmark_table", 45 }, 46 { 47 .identifier = "L", 48 .tablename = "l_table", 49 }, 50 { 51 .identifier = "V", 52 .tablename = "v_table", 53 }, 54 { 55 .identifier = "T", 56 .tablename = "t_table", 57 }, 58 { 59 .identifier = "LV", 60 .tablename = "lv_table", 61 }, 62 { 63 .identifier = "LVT", 64 .tablename = "lvt_table", 65 }, 66 }; 67 68 int 69 process_line(char **field, size_t nfields, char *comment) 70 { 71 size_t i; 72 struct range r; 73 74 (void)comment; 75 76 if (nfields < 2) { 77 return 1; 78 } 79 80 for (i = 0; i < LEN(properties); i++) { 81 if (!strcmp(field[1], properties[i].identifier)) { 82 if (range_parse(field[0], &r)) { 83 return 1; 84 } 85 range_list_append(&(properties[i].table), 86 &(properties[i].tablelen), &r); 87 break; 88 } 89 } 90 91 return 0; 92 } 93 94 int 95 main(void) 96 { 97 size_t i, j; 98 99 printf("/* Automatically generated by data/gbp */\n" 100 "#include <stdint.h>\n"); 101 102 parse_input(process_line); 103 104 for (i = 0; i < LEN(properties); i++) { 105 printf("\nstatic const uint32_t %s[][2] = {\n", 106 properties[i].tablename); 107 for (j = 0; j < properties[i].tablelen; j++) { 108 printf("\t{ UINT32_C(0x%06X), UINT32_C(0x%06X) },\n", 109 properties[i].table[j].lower, 110 properties[i].table[j].upper); 111 } 112 printf("};\n"); 113 } 114 115 return 0; 116 }