+int convert_numeric_option(char opt, int min_value)
+{
+ int value;
+ char *ptr;
+
+ value = strtol(optarg, &ptr, 0);
+ if(value<min_value || *ptr)
+ {
+ printf("Invalid option argument in -%c %s\n", opt, optarg);
+ exit(1);
+ }
+
+ return value;
+}
+
+void convert_code_point_range(char opt, int *begin, int *end)
+{
+ char *ptr;
+
+ if(!strcmp(optarg, "all"))
+ {
+ *begin = 0;
+ *end = 0x10FFFF;
+ return;
+ }
+
+ *begin = strtol(optarg, &ptr, 0);
+ if(*begin>0 && *ptr==',')
+ {
+ *end = strtol(ptr+1, &ptr, 0);
+ if(*end>0 && !*ptr)
+ return;
+ }
+
+ printf("Invalid option argument in -%c %s\n", opt, optarg);
+ exit(1);
+}
+
+void convert_size(char opt, int *width, int *height)
+{
+ char *ptr;
+
+ if(!strcmp(optarg, "auto"))
+ {
+ *width = 0;
+ *height = 0;
+ return;
+ }
+ else if(!strcmp(optarg, "autorect"))
+ {
+ *width = 0;
+ *height = 1;
+ return;
+ }
+
+ *width = strtol(optarg, &ptr, 0);
+ if(*width>0)
+ {
+ if(*ptr=='x')
+ {
+ *height = strtol(ptr+1, &ptr, 0);
+ if(*height>0 && !*ptr)
+ return;
+ }
+ else if(!*ptr)
+ {
+ *height = *width;
+ return;
+ }
+ }
+
+ printf("Invalid option argument in -%c %s\n", opt, optarg);
+ exit(1);
+}
+
+unsigned round_to_pot(unsigned n)
+{
+ n -= 1;
+ n |= n>>1;
+ n |= n>>2;
+ n |= n>>4;
+ n |= n>>8;
+ n |= n>>16;
+
+ return n+1;
+}
+
+void *alloc_image_data(size_t a, size_t b)
+{
+ void *ptr;
+
+ /* Carry out the multiplication manually so we can check for overflow. */
+ while(b>1)
+ {
+ size_t c = a;
+ a *= 2;
+ if(b&1)
+ a += c;
+ if(a<c)
+ {
+ fprintf(stderr, "Cannot allocate %lu kbytes of memory for image\n", (unsigned long)(c/1024*b));
+ return NULL;
+ }
+ b /= 2;
+ }
+ ptr = malloc(a);
+ if(!ptr)
+ fprintf(stderr, "Cannot allocate %lu kbytes of memory for image\n", (unsigned long)(a/1024*b));
+ return ptr;
+}
+
+int init_font(Font *font, FT_Face face, unsigned first, unsigned last, int autohinter)