From 9f6a77c2d17128a44bf2fc9fead449a05354def5 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Wed, 11 Mar 2009 22:02:49 +0100 Subject: Rename and prune some files and functions. --- Jamrules | 6 +- fitz/Jamfile | 3 +- fitz/base_cleanname.c | 52 --------------- fitz/base_memory.c | 66 ++++--------------- fitz/base_rune.c | 174 -------------------------------------------------- fitz/base_unicode.c | 174 ++++++++++++++++++++++++++++++++++++++++++++++++++ fitz/filt_flate.c | 14 ++-- fitz/fitz_base.h | 22 ------- fitzdraw/pathscan.c | 6 ++ 9 files changed, 207 insertions(+), 310 deletions(-) delete mode 100644 fitz/base_cleanname.c delete mode 100644 fitz/base_rune.c create mode 100644 fitz/base_unicode.c diff --git a/Jamrules b/Jamrules index 99ddf6fb..f8632436 100644 --- a/Jamrules +++ b/Jamrules @@ -16,7 +16,7 @@ # libraries are in c:/local/include and c:/local/lib. # # MacOS X builds assume that you have third party libraries installed -# from MacPorts in /opt/local. +# in /usr/local or some other system known location. # # Linux builds assume that you have freetype-config to find the paths # to the freetype library. @@ -81,8 +81,8 @@ if $(OS) = MACOSX BUILD_X11APP = true ; - THIRDPARTYINC ?= -I/opt/local/include -I/opt/local/include/freetype2 -I/usr/X11R6/include ; - THIRDPARTYLIB ?= -L/opt/local/lib -L/usr/X11R6/lib ; + THIRDPARTYINC ?= -I/usr/X11/include ; + THIRDPARTYLIB ?= -L/usr/X11/lib ; CCFLAGS = -Wall -std=c99 $(THIRDPARTYINC) ; LINKFLAGS = $(THIRDPARTYLIB) ; diff --git a/fitz/Jamfile b/fitz/Jamfile index 61f2583d..c0d0fb2d 100644 --- a/fitz/Jamfile +++ b/fitz/Jamfile @@ -16,9 +16,8 @@ Library libfitz : base_matrix.c base_memory.c base_rect.c - base_rune.c base_string.c - base_cleanname.c + base_unicode.c ; if $(NEED_GETOPT) { Library libfitz : util_getopt.c ; } diff --git a/fitz/base_cleanname.c b/fitz/base_cleanname.c deleted file mode 100644 index 54764630..00000000 --- a/fitz/base_cleanname.c +++ /dev/null @@ -1,52 +0,0 @@ -/* - * In place, rewrite name to compress multiple /, eliminate ., and process .. - */ - -#define SEP(x) ((x)=='/' || (x) == 0) - -char * -cleanname(char *name) -{ - char *p, *q, *dotdot; - int rooted; - - rooted = name[0] == '/'; - - /* - * invariants: - * p points at beginning of path element we're considering. - * q points just past the last path element we wrote (no slash). - * dotdot points just past the point where .. cannot backtrack - * any further (no slash). - */ - p = q = dotdot = name+rooted; - while(*p) { - if(p[0] == '/') /* null element */ - p++; - else if(p[0] == '.' && SEP(p[1])) - p += 1; /* don't count the separator in case it is nul */ - else if(p[0] == '.' && p[1] == '.' && SEP(p[2])) { - p += 2; - if(q > dotdot) { /* can backtrack */ - while(--q > dotdot && *q != '/') - ; - } else if(!rooted) { /* /.. is / but ./../ is .. */ - if(q != name) - *q++ = '/'; - *q++ = '.'; - *q++ = '.'; - dotdot = q; - } - } else { /* real path element */ - if(q != name+rooted) - *q++ = '/'; - while((*q = *p) != '/' && *q != 0) - p++, q++; - } - } - if(q == name) /* empty string is really ``.'' */ - *q++ = '.'; - *q = '\0'; - return name; -} - diff --git a/fitz/base_memory.c b/fitz/base_memory.c index cd6de8cb..21effdc1 100644 --- a/fitz/base_memory.c +++ b/fitz/base_memory.c @@ -1,71 +1,31 @@ #include "fitz_base.h" -/* Make this thread local storage if you wish. */ - -static void *stdmalloc(fz_memorycontext *mem, int n) -{ - return malloc(n); -} - -static void *stdrealloc(fz_memorycontext *mem, void *p, int n) -{ - return realloc(p, n); -} - -static void stdfree(fz_memorycontext *mem, void *p) -{ - free(p); -} - -static fz_memorycontext defmem = { stdmalloc, stdrealloc, stdfree }; -static fz_memorycontext *curmem = &defmem; - -fz_memorycontext * -fz_currentmemorycontext() -{ - return curmem; -} - -void -fz_setmemorycontext(fz_memorycontext *mem) -{ - curmem = mem; -} - -void * -fz_malloc(int n) +void * fz_malloc(int n) { - fz_memorycontext *mem = fz_currentmemorycontext(); - void *p = mem->malloc(mem, n); + void *p = malloc(n); if (!p) - fz_warn("cannot malloc %d bytes", n); + fz_throw("cannot malloc %d bytes", n); return p; } -void * -fz_realloc(void *p, int n) +void * fz_realloc(void *p, int n) { - fz_memorycontext *mem = fz_currentmemorycontext(); - void *np = mem->realloc(mem, p, n); + void *np = realloc(p, n); if (np == nil) - fz_warn("cannot realloc %d bytes", n); + fz_throw("cannot realloc %d bytes", n); return np; } -void -fz_free(void *p) +void fz_free(void *p) { - fz_memorycontext *mem = fz_currentmemorycontext(); - mem->free(mem, p); + free(p); } -char * -fz_strdup(char *s) +char * fz_strdup(char *s) { - int len = strlen(s); - char *ns = fz_malloc(len + 1); - if (ns) - strcpy(ns, s); - return ns; + char *ns = strdup(s); + if (!ns) + fz_throw("cannot strdup %d bytes", strlen(s) + 1); + return ns; } diff --git a/fitz/base_rune.c b/fitz/base_rune.c deleted file mode 100644 index 32168792..00000000 --- a/fitz/base_rune.c +++ /dev/null @@ -1,174 +0,0 @@ -enum -{ - UTFmax = 3, /* maximum bytes per rune */ - Runesync = 0x80, /* cannot represent part of a UTF sequence (<) */ - Runeself = 0x80, /* rune and UTF sequences are the same (<) */ - Runeerror = 0x80 /* decoding error in UTF */ -}; - -enum -{ - Bit1 = 7, - Bitx = 6, - Bit2 = 5, - Bit3 = 4, - Bit4 = 3, - - T1 = ((1<<(Bit1+1))-1) ^ 0xFF, /* 0000 0000 */ - Tx = ((1<<(Bitx+1))-1) ^ 0xFF, /* 1000 0000 */ - T2 = ((1<<(Bit2+1))-1) ^ 0xFF, /* 1100 0000 */ - T3 = ((1<<(Bit3+1))-1) ^ 0xFF, /* 1110 0000 */ - T4 = ((1<<(Bit4+1))-1) ^ 0xFF, /* 1111 0000 */ - - Rune1 = (1<<(Bit1+0*Bitx))-1, /* 0000 0000 0111 1111 */ - Rune2 = (1<<(Bit2+1*Bitx))-1, /* 0000 0111 1111 1111 */ - Rune3 = (1<<(Bit3+2*Bitx))-1, /* 1111 1111 1111 1111 */ - - Maskx = (1< T1 - */ - c = *(unsigned char*)str; - if (c < Tx) - { - *rune = c; - return 1; - } - - /* - * two character sequence - * 0080-07FF => T2 Tx - */ - c1 = *(unsigned char*)(str+1) ^ Tx; - if (c1 & Testx) - goto bad; - if (c < T3) - { - if (c < T2) - goto bad; - l = ((c << Bitx) | c1) & Rune2; - if (l <= Rune1) - goto bad; - *rune = l; - return 2; - } - - /* - * three character sequence - * 0800-FFFF => T3 Tx Tx - */ - c2 = *(unsigned char*)(str+2) ^ Tx; - if (c2 & Testx) - goto bad; - if (c < T4) - { - l = ((((c << Bitx) | c1) << Bitx) | c2) & Rune3; - if (l <= Rune2) - goto bad; - *rune = l; - return 3; - } - - /* - * bad decoding - */ -bad: - *rune = Bad; - return 1; -} - -int -runetochar(char *str, int *rune) -{ - int c; - - /* - * one character sequence - * 00000-0007F => 00-7F - */ - c = *rune; - if (c <= Rune1) - { - str[0] = c; - return 1; - } - - /* - * two character sequence - * 0080-07FF => T2 Tx - */ - if (c <= Rune2) - { - str[0] = T2 | (c >> 1*Bitx); - str[1] = Tx | (c & Maskx); - return 2; - } - - /* - * three character sequence - * 0800-FFFF => T3 Tx Tx - */ - str[0] = T3 | (c >> 2*Bitx); - str[1] = Tx | ((c >> 1*Bitx) & Maskx); - str[2] = Tx | (c & Maskx); - return 3; -} - -int -runelen(int c) -{ - int rune; - char str[10]; - - rune = c; - return runetochar(str, &rune); -} - -int -runenlen(int *r, int nrune) -{ - int nb, c; - - nb = 0; - while (nrune--) - { - c = *r++; - if (c <= Rune1) - nb++; - else if (c <= Rune2) - nb += 2; - else - nb += 3; - } - return nb; -} - -int -fullrune(char *str, int n) -{ - int c; - - if (n > 0) - { - c = *(unsigned char*)str; - if (c < Tx) - return 1; - if (n > 1) - if (c < T3 || n > 2) - return 1; - } - return 0; -} - diff --git a/fitz/base_unicode.c b/fitz/base_unicode.c new file mode 100644 index 00000000..32168792 --- /dev/null +++ b/fitz/base_unicode.c @@ -0,0 +1,174 @@ +enum +{ + UTFmax = 3, /* maximum bytes per rune */ + Runesync = 0x80, /* cannot represent part of a UTF sequence (<) */ + Runeself = 0x80, /* rune and UTF sequences are the same (<) */ + Runeerror = 0x80 /* decoding error in UTF */ +}; + +enum +{ + Bit1 = 7, + Bitx = 6, + Bit2 = 5, + Bit3 = 4, + Bit4 = 3, + + T1 = ((1<<(Bit1+1))-1) ^ 0xFF, /* 0000 0000 */ + Tx = ((1<<(Bitx+1))-1) ^ 0xFF, /* 1000 0000 */ + T2 = ((1<<(Bit2+1))-1) ^ 0xFF, /* 1100 0000 */ + T3 = ((1<<(Bit3+1))-1) ^ 0xFF, /* 1110 0000 */ + T4 = ((1<<(Bit4+1))-1) ^ 0xFF, /* 1111 0000 */ + + Rune1 = (1<<(Bit1+0*Bitx))-1, /* 0000 0000 0111 1111 */ + Rune2 = (1<<(Bit2+1*Bitx))-1, /* 0000 0111 1111 1111 */ + Rune3 = (1<<(Bit3+2*Bitx))-1, /* 1111 1111 1111 1111 */ + + Maskx = (1< T1 + */ + c = *(unsigned char*)str; + if (c < Tx) + { + *rune = c; + return 1; + } + + /* + * two character sequence + * 0080-07FF => T2 Tx + */ + c1 = *(unsigned char*)(str+1) ^ Tx; + if (c1 & Testx) + goto bad; + if (c < T3) + { + if (c < T2) + goto bad; + l = ((c << Bitx) | c1) & Rune2; + if (l <= Rune1) + goto bad; + *rune = l; + return 2; + } + + /* + * three character sequence + * 0800-FFFF => T3 Tx Tx + */ + c2 = *(unsigned char*)(str+2) ^ Tx; + if (c2 & Testx) + goto bad; + if (c < T4) + { + l = ((((c << Bitx) | c1) << Bitx) | c2) & Rune3; + if (l <= Rune2) + goto bad; + *rune = l; + return 3; + } + + /* + * bad decoding + */ +bad: + *rune = Bad; + return 1; +} + +int +runetochar(char *str, int *rune) +{ + int c; + + /* + * one character sequence + * 00000-0007F => 00-7F + */ + c = *rune; + if (c <= Rune1) + { + str[0] = c; + return 1; + } + + /* + * two character sequence + * 0080-07FF => T2 Tx + */ + if (c <= Rune2) + { + str[0] = T2 | (c >> 1*Bitx); + str[1] = Tx | (c & Maskx); + return 2; + } + + /* + * three character sequence + * 0800-FFFF => T3 Tx Tx + */ + str[0] = T3 | (c >> 2*Bitx); + str[1] = Tx | ((c >> 1*Bitx) & Maskx); + str[2] = Tx | (c & Maskx); + return 3; +} + +int +runelen(int c) +{ + int rune; + char str[10]; + + rune = c; + return runetochar(str, &rune); +} + +int +runenlen(int *r, int nrune) +{ + int nb, c; + + nb = 0; + while (nrune--) + { + c = *r++; + if (c <= Rune1) + nb++; + else if (c <= Rune2) + nb += 2; + else + nb += 3; + } + return nb; +} + +int +fullrune(char *str, int n) +{ + int c; + + if (n > 0) + { + c = *(unsigned char*)str; + if (c < Tx) + return 1; + if (n > 1) + if (c < T3 || n > 2) + return 1; + } + return 0; +} + diff --git a/fitz/filt_flate.c b/fitz/filt_flate.c index 73105800..65a84711 100644 --- a/fitz/filt_flate.c +++ b/fitz/filt_flate.c @@ -17,6 +17,12 @@ zmalloc(void *opaque, unsigned int items, unsigned int size) return fz_malloc(items * size); } +static void +zfree(void *opaque, void *ptr) +{ + fz_free(ptr); +} + fz_error fz_newflated(fz_filter **fp, fz_obj *params) { @@ -28,8 +34,8 @@ fz_newflated(fz_filter **fp, fz_obj *params) FZ_NEWFILTER(fz_flate, f, flated); f->z.zalloc = zmalloc; - f->z.zfree = (void(*)(void*,void*))fz_currentmemorycontext()->free; - f->z.opaque = fz_currentmemorycontext(); + f->z.zfree = zfree; + f->z.opaque = nil; f->z.next_in = nil; f->z.avail_in = 0; @@ -133,8 +139,8 @@ fz_newflatee(fz_filter **fp, fz_obj *params) } f->z.zalloc = zmalloc; - f->z.zfree = (void(*)(void*,void*))fz_currentmemorycontext()->free; - f->z.opaque = fz_currentmemorycontext(); + f->z.zfree = zfree; + f->z.opaque = nil; f->z.next_in = nil; f->z.avail_in = 0; diff --git a/fitz/fitz_base.h b/fitz/fitz_base.h index 211ed8dc..6bee3ecb 100644 --- a/fitz/fitz_base.h +++ b/fitz/fitz_base.h @@ -173,12 +173,9 @@ int runetochar(char *str, int *rune); int runelen(long c); int runenlen(int *r, int nrune); int fullrune(char *str, int n); -char *cleanname(char *name); typedef int fz_error; -#define fz_outofmem ((fz_error)-1) - #define fz_throw(...) fz_throwimp(__func__, __FILE__, __LINE__, __VA_ARGS__) #define fz_rethrow(cause, ...) fz_rethrowimp(cause, __func__, __FILE__, __LINE__, __VA_ARGS__) #define fz_catch(cause, ...) fz_catchimp(cause, __func__, __FILE__, __LINE__, __VA_ARGS__) @@ -189,22 +186,9 @@ fz_error fz_throwimp(const char *func, const char *file, int line, char *fmt, .. fz_error fz_rethrowimp(fz_error cause, const char *func, const char *file, int line, char *fmt, ...) __printflike(5, 6); fz_error fz_catchimp(fz_error cause, const char *func, const char *file, int line, char *fmt, ...) __printflike(5, 6); -typedef struct fz_memorycontext_s fz_memorycontext; - -struct fz_memorycontext_s -{ - void * (*malloc)(fz_memorycontext *, int); - void * (*realloc)(fz_memorycontext *, void *, int); - void (*free)(fz_memorycontext *, void *); -}; - -fz_memorycontext *fz_currentmemorycontext(void); -void fz_setmemorycontext(fz_memorycontext *memorycontext); - void *fz_malloc(int n); void *fz_realloc(void *p, int n); void fz_free(void *p); - char *fz_strdup(char *s); /* @@ -232,12 +216,6 @@ void *fz_hashgetval(fz_hashtable *table, int idx); #define fz_floor(x) floor(x) #define fz_ceil(x) ceil(x) -/* divide and floor towards -inf */ -static inline int fz_idiv(int a, int b) -{ - return a < 0 ? (a - b + 1) / b : a / b; -} - typedef struct fz_matrix_s fz_matrix; typedef struct fz_point_s fz_point; typedef struct fz_rect_s fz_rect; diff --git a/fitzdraw/pathscan.c b/fitzdraw/pathscan.c index dec7c73f..2ab7d5b6 100644 --- a/fitzdraw/pathscan.c +++ b/fitzdraw/pathscan.c @@ -2,6 +2,12 @@ #include "fitz_tree.h" #include "fitz_draw.h" +/* divide and floor towards -inf */ +static inline int fz_idiv(int a, int b) +{ + return a < 0 ? (a - b + 1) / b : a / b; +} + enum { HSCALE = 17, VSCALE = 15, SF = 1 }; /* -- cgit v1.2.3