libgrapheme

grapheme cluster utility library
git clone git://git.suckless.org/libgrapheme
Log | Files | Refs | LICENSE

emo.c (1284B)


      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 = "Extended_Pictographic",
     16 		.tablename  = "extpict_table",
     17 	},
     18 };
     19 
     20 int
     21 process_line(char **field, size_t nfields, char *comment)
     22 {
     23 	size_t i;
     24 	struct range r;
     25 
     26 	(void)comment;
     27 
     28 	if (nfields < 2) {
     29 		return 1;
     30 	}
     31 
     32 	for (i = 0; i < LEN(properties); i++) {
     33 		if (!strcmp(field[1], properties[i].identifier)) {
     34 			if (range_parse(field[0], &r)) {
     35 				return 1;
     36 			}
     37 			range_list_append(&(properties[i].table),
     38 			                  &(properties[i].tablelen), &r);
     39 			break;
     40 		}
     41 	}
     42 
     43 	return 0;
     44 }
     45 
     46 int
     47 main(void)
     48 {
     49 	size_t i, j;
     50 
     51 	printf("/* Automatically generated by data/emo */\n"
     52 	       "#include <stdint.h>\n");
     53 
     54 	parse_input(process_line);
     55 
     56 	for (i = 0; i < LEN(properties); i++) {
     57 		printf("\nstatic const uint32_t %s[][2] = {\n",
     58 		       properties[i].tablename);
     59 		for (j = 0; j < properties[i].tablelen; j++) {
     60 			printf("\t{ UINT32_C(0x%06X), UINT32_C(0x%06X) },\n",
     61 			       properties[i].table[j].lower,
     62 			       properties[i].table[j].upper);
     63 		}
     64 		printf("};\n");
     65 	}
     66 
     67 	return 0;
     68 }