Initial commit
This commit is contained in:
193
buildroot/share/fonts/genpages/genpages.c
Normal file
193
buildroot/share/fonts/genpages/genpages.c
Normal file
@ -0,0 +1,193 @@
|
||||
/**
|
||||
* @file genpages.c
|
||||
* @brief generate required font page files
|
||||
* @author Yunhui Fu (yhfudev@gmail.com)
|
||||
* @version 1.0
|
||||
* @date 2015-02-19
|
||||
* @copyright Yunhui Fu (2015)
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h> /* uint8_t */
|
||||
#include <stdlib.h> /* size_t */
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include "getline.h"
|
||||
|
||||
wchar_t get_val_utf82uni(uint8_t *pstart) {
|
||||
size_t cntleft;
|
||||
wchar_t retval = 0;
|
||||
|
||||
if (0 == (0x80 & *pstart)) return *pstart;
|
||||
|
||||
if (((*pstart & 0xE0) ^ 0xC0) == 0) {
|
||||
cntleft = 1;
|
||||
retval = *pstart & ~0xE0;
|
||||
}
|
||||
else if (((*pstart & 0xF0) ^ 0xE0) == 0) {
|
||||
cntleft = 2;
|
||||
retval = *pstart & ~0xF0;
|
||||
}
|
||||
else if (((*pstart & 0xF8) ^ 0xF0) == 0) {
|
||||
cntleft = 3;
|
||||
retval = *pstart & ~0xF8;
|
||||
}
|
||||
else if (((*pstart & 0xFC) ^ 0xF8) == 0) {
|
||||
cntleft = 4;
|
||||
retval = *pstart & ~0xFC;
|
||||
}
|
||||
else if (((*pstart & 0xFE) ^ 0xFC) == 0) {
|
||||
cntleft = 5;
|
||||
retval = *pstart & ~0xFE;
|
||||
}
|
||||
else {
|
||||
/* encoding error */
|
||||
cntleft = 0;
|
||||
retval = 0;
|
||||
}
|
||||
pstart++;
|
||||
for (; cntleft > 0; cntleft --) {
|
||||
retval <<= 6;
|
||||
retval |= *pstart & 0x3F;
|
||||
pstart++;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 转换 UTF-8 编码的一个字符为本地的 Unicode 字符(wchar_t)
|
||||
*
|
||||
* @param pstart : 存储 UTF-8 字符的指针
|
||||
* @param pval : 需要返回的 Unicode 字符存放地址指针
|
||||
*
|
||||
* @return 成功返回下个 UTF-8 字符的位置
|
||||
*
|
||||
* 转换 UTF-8 编码的一个字符为本地的 Unicode 字符(wchar_t)
|
||||
*/
|
||||
uint8_t* get_utf8_value(uint8_t *pstart, wchar_t *pval) {
|
||||
uint32_t val = 0;
|
||||
uint8_t *p = pstart;
|
||||
/*size_t maxlen = strlen(pstart);*/
|
||||
|
||||
assert(NULL != pstart);
|
||||
|
||||
#define NEXT_6_BITS() do{ val <<= 6; p++; val |= (*p & 0x3F); }while(0)
|
||||
|
||||
if (0 == (0x80 & *p)) {
|
||||
val = (size_t)*p;
|
||||
p++;
|
||||
}
|
||||
else if (0xC0 == (0xE0 & *p)) {
|
||||
val = *p & 0x1F;
|
||||
NEXT_6_BITS();
|
||||
p++;
|
||||
assert((wchar_t)val == get_val_utf82uni(pstart));
|
||||
}
|
||||
else if (0xE0 == (0xF0 & *p)) {
|
||||
val = *p & 0x0F;
|
||||
NEXT_6_BITS();
|
||||
NEXT_6_BITS();
|
||||
p++;
|
||||
assert((wchar_t)val == get_val_utf82uni(pstart));
|
||||
}
|
||||
else if (0xF0 == (0xF8 & *p)) {
|
||||
val = *p & 0x07;
|
||||
NEXT_6_BITS();
|
||||
NEXT_6_BITS();
|
||||
NEXT_6_BITS();
|
||||
p++;
|
||||
assert((wchar_t)val == get_val_utf82uni(pstart));
|
||||
}
|
||||
else if (0xF8 == (0xFC & *p)) {
|
||||
val = *p & 0x03;
|
||||
NEXT_6_BITS();
|
||||
NEXT_6_BITS();
|
||||
NEXT_6_BITS();
|
||||
NEXT_6_BITS();
|
||||
p++;
|
||||
assert((wchar_t)val == get_val_utf82uni(pstart));
|
||||
}
|
||||
else if (0xFC == (0xFE & *p)) {
|
||||
val = *p & 0x01;
|
||||
NEXT_6_BITS();
|
||||
NEXT_6_BITS();
|
||||
NEXT_6_BITS();
|
||||
NEXT_6_BITS();
|
||||
NEXT_6_BITS();
|
||||
p++;
|
||||
assert((wchar_t)val == get_val_utf82uni(pstart));
|
||||
}
|
||||
else if (0x80 == (0xC0 & *p)) {
|
||||
/* error? */
|
||||
for (; 0x80 == (0xC0 & *p); p++);
|
||||
}
|
||||
else {
|
||||
/* error */
|
||||
for (; ((0xFE & *p) > 0xFC); p++);
|
||||
}
|
||||
/*
|
||||
if (val == 0) {
|
||||
p = NULL;
|
||||
*/
|
||||
/*
|
||||
}
|
||||
else if (pstart + maxlen < p) {
|
||||
p = pstart;
|
||||
if (pval) *pval = 0;
|
||||
}
|
||||
*/
|
||||
|
||||
if (pval) *pval = val;
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
void usage(char *progname) {
|
||||
fprintf(stderr, "usage: %s\n", progname);
|
||||
fprintf(stderr, " read data from stdin\n");
|
||||
}
|
||||
|
||||
void utf8_parse(const char *msg, unsigned int len) {
|
||||
uint8_t *pend = NULL;
|
||||
uint8_t *p;
|
||||
uint8_t *pre;
|
||||
wchar_t val;
|
||||
int page;
|
||||
|
||||
pend = (uint8_t *)msg + len;
|
||||
for (pre = (uint8_t *)msg; pre < pend;) {
|
||||
val = 0;
|
||||
p = get_utf8_value(pre, &val);
|
||||
if (NULL == p) break;
|
||||
page = val / 128;
|
||||
if (val >= 256) {
|
||||
fprintf(stdout, "%d %d ", page, (val % 128));
|
||||
for (; pre < p; pre++) fprintf(stdout, "%c", *pre);
|
||||
fprintf(stdout, "\n");
|
||||
}
|
||||
pre = p;
|
||||
}
|
||||
}
|
||||
|
||||
int load_file(FILE *fp) {
|
||||
char * buffer = NULL;
|
||||
size_t szbuf = 0;
|
||||
|
||||
szbuf = 10000;
|
||||
buffer = (char*)malloc(szbuf);
|
||||
if (NULL == buffer) return -1;
|
||||
//pos = ftell (fp);
|
||||
while (getline( &buffer, &szbuf, fp ) > 0)
|
||||
utf8_parse((const char*)buffer, (unsigned int)strlen ((char *)buffer));
|
||||
|
||||
free(buffer);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char * argv[]) {
|
||||
if (argc > 1) {
|
||||
usage(argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
load_file(stdin);
|
||||
}
|
126
buildroot/share/fonts/genpages/getline.c
Normal file
126
buildroot/share/fonts/genpages/getline.c
Normal file
@ -0,0 +1,126 @@
|
||||
/**
|
||||
* getline.c --- Based on...
|
||||
*
|
||||
* getdelim.c --- Implementation of replacement getdelim function.
|
||||
* Copyright (C) 1994, 1996, 1997, 1998, 2001, 2003, 2005 Free
|
||||
* Software Foundation, Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301, USA.
|
||||
*/
|
||||
|
||||
/* Ported from glibc by Simon Josefsson. */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#if !HAVE_GETLINE
|
||||
|
||||
//#include "getdelim.h"
|
||||
#include <stdio.h>
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
|
||||
#ifndef SIZE_MAX
|
||||
#define SIZE_MAX ((size_t) -1)
|
||||
#endif
|
||||
#ifndef SSIZE_MAX
|
||||
#define SSIZE_MAX ((ssize_t) (SIZE_MAX / 2))
|
||||
#endif
|
||||
#if !HAVE_FLOCKFILE
|
||||
#undef flockfile
|
||||
#define flockfile(x) ((void)0)
|
||||
#endif
|
||||
#if !HAVE_FUNLOCKFILE
|
||||
#undef funlockfile
|
||||
#define funlockfile(x) ((void)0)
|
||||
#endif
|
||||
|
||||
/* Read up to (and including) a DELIMITER from FP into *LINEPTR (and
|
||||
NUL-terminate it). *LINEPTR is a pointer returned from malloc (or
|
||||
NULL), pointing to *N characters of space. It is realloc'ed as
|
||||
necessary. Returns the number of characters read (not including
|
||||
the null terminator), or -1 on error or EOF. */
|
||||
|
||||
ssize_t
|
||||
getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp) {
|
||||
ssize_t result;
|
||||
size_t cur_len = 0;
|
||||
|
||||
if (lineptr == NULL || n == NULL || fp == NULL) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
flockfile (fp);
|
||||
|
||||
if (*lineptr == NULL || *n == 0) {
|
||||
*n = 120;
|
||||
*lineptr = (char *) malloc(*n);
|
||||
if (*lineptr == NULL) {
|
||||
result = -1;
|
||||
goto unlock_return;
|
||||
}
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
int i;
|
||||
|
||||
i = getc(fp);
|
||||
if (i == EOF) {
|
||||
result = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Make enough space for len+1 (for final NUL) bytes. */
|
||||
if (cur_len + 1 >= *n) {
|
||||
size_t needed_max =
|
||||
SSIZE_MAX < SIZE_MAX ? (size_t) SSIZE_MAX + 1 : SIZE_MAX;
|
||||
size_t needed = 2 * *n + 1; /* Be generous. */
|
||||
char *new_lineptr;
|
||||
|
||||
if (needed_max < needed)
|
||||
needed = needed_max;
|
||||
if (cur_len + 1 >= needed) {
|
||||
result = -1;
|
||||
goto unlock_return;
|
||||
}
|
||||
|
||||
new_lineptr = (char *) realloc (*lineptr, needed);
|
||||
if (new_lineptr == NULL) {
|
||||
result = -1;
|
||||
goto unlock_return;
|
||||
}
|
||||
|
||||
*lineptr = new_lineptr;
|
||||
*n = needed;
|
||||
}
|
||||
|
||||
(*lineptr)[cur_len] = i;
|
||||
cur_len++;
|
||||
|
||||
if (i == delimiter) break;
|
||||
}
|
||||
(*lineptr)[cur_len] = '\0';
|
||||
result = cur_len ? (int) cur_len : (int) result;
|
||||
|
||||
unlock_return:
|
||||
funlockfile(fp);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif
|
12
buildroot/share/fonts/genpages/getline.h
Normal file
12
buildroot/share/fonts/genpages/getline.h
Normal file
@ -0,0 +1,12 @@
|
||||
#ifndef MYGETLINE_H
|
||||
#define MYGETLINE_H
|
||||
|
||||
//#include "config.h"
|
||||
|
||||
#if !HAVE_GETLINE
|
||||
#include <stdio.h>
|
||||
ssize_t getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp);
|
||||
#define getline(lineptr, n, stream) getdelim (lineptr, n, '\n', stream)
|
||||
#endif
|
||||
|
||||
#endif // MYGETLINE_H
|
Reference in New Issue
Block a user