libgrapheme

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

emoji.c (1664B)


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