From: Koichi KAMICHI Date: Sat, 27 Mar 2004 13:47:23 +0000 (+0000) Subject: Change BDB version from 1 to 3. X-Git-Url: http://git.chise.org/gitweb/?a=commitdiff_plain;h=18f978ffb60be4b7f64c74610a08529f7bd3392d;p=chise%2Fkage.git Change BDB version from 1 to 3. Fix DB read bug. Remove some comments. --- diff --git a/kagecgi/Makefile b/kagecgi/Makefile index 1e88ed3..df5839d 100755 --- a/kagecgi/Makefile +++ b/kagecgi/Makefile @@ -17,6 +17,10 @@ VERSION=0.0.1 CFLAGS= -I/usr/local/include -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/X11R6/include LIBS= -L/usr/local/lib -lpng -ldb -lglib-2.0 -L/usr/X11R6/lib -lX11 +#for MacOSX with fink +#CFLAGS= -I/sw/include -I/sw/include/glib-2.0 -I/sw/lib/glib-2.0/include/ -I/sw/include/libpng/ -I/usr/include -I/usr/X11R6/include/ +#LIBS= -L/sw/lib -lpng -lglib-2.0 -L/usr/lib -ldbm -L/usr/X11R6/lib -lX11 + kage.cgi: kagecgi.o kagepng.o kagedf.o kagecd.o kageic.o kagepoly.o kagedb.o kageeg.o kagecomb.o kagechar.o kagetool.o $(CC) $(CFLAGS) -o kage.cgi kagecgi.o kagepng.o kagedf.o kagecd.o kageic.o kagepoly.o kagedb.o kageeg.o kagecomb.o kagechar.o kagetool.o $(LIBS) diff --git a/kagecgi/README.en b/kagecgi/README.en index eadee3d..92b99be 100644 --- a/kagecgi/README.en +++ b/kagecgi/README.en @@ -6,7 +6,7 @@ PREREQUISITES KAGE/cgi needs following librarys: - - Berkely DB 1or2 (3 is not supported yet) + - Berkely DB 3 - libpng - glib2.0 - xlib @@ -58,6 +58,12 @@ Another examples: - kage.cgi?u7389&shotai=gothic (generate as Gothic glyph [Default: Mincho]) - kage.cgi?u4e5f&type=eps (generate as .eps file [Default: .png file]) +OR run by command prompt mode: + - % ./kage.cgi u2ff0.u6c35.u6c38 > result.png + - % ./kage.cgi u4e08-k > result.png + - % ./kage.cgi 'u7389&shotai=gothic' > result.png + - % ./kage.cgi 'u4e5f&type=eps' > result.eps + GETTING MORE INFORMATION ======================== diff --git a/kagecgi/kagecgi.c b/kagecgi/kagecgi.c index 60910f1..4a92461 100755 --- a/kagecgi/kagecgi.c +++ b/kagecgi/kagecgi.c @@ -7,11 +7,11 @@ int main(int argc, char *argv[]){ GString *tmp1, *tmp2, *test1, *test2, *filename; - FILE *err, *fp; + FILE *err; char errbuf[errorFileSize]; char *pos, *cur; int dummy; - int i; + int type; dummy = initDB(); @@ -25,25 +25,35 @@ int main(int argc, char *argv[]){ kResultText = g_string_new(""); kMode = 0; - //set some param by request -// tmp1 = g_string_new((gchar *)argv[1]); - tmp1 = g_string_new((gchar *)getenv("QUERY_STRING")); + //confirm request + type = 0; + //argv + tmp1 = g_string_new((gchar *)argv[1]); + if(tmp1->len != 0) type = 1; + //direct + if(type == 0){ + tmp1 = g_string_new((gchar *)getenv("QUERY_STRING")); + if(tmp1->len != 0) type = 2; + } + //redirect + if(type == 0){ + tmp1 = g_string_new((gchar *)getenv("REDIRECT_URL")); + if(tmp1->len != 0) type = 3; + } + //error + if(type == 0){ + fprintf(stderr, "Request Error.\n"); + return 0; + } pos = tmp1->str; //separate token - if(tmp1->len != 0){ + if(type == 1 || type == 2){ //argv or direct while(1){ cur = strchr(pos, '&'); tmp2 = g_string_new(pos); if(cur != NULL) g_string_set_size(tmp2, cur - pos); //got request string -// if(strncmp(tmp2->str, "design=jp", 9) == 0) kDesign = 0; -// else if(strncmp(tmp2->str, "design=cs", 9) == 0) kDesign = 10; -// else if(strncmp(tmp2->str, "design=ct", 9) == 0) kDesign = 11; -// else if(strncmp(tmp2->str, "design=kr", 9) == 0) kDesign = 20; -// else if(strncmp(tmp2->str, "design=vn", 9) == 0) kDesign = 30; -// else if(strncmp(tmp2->str, "design=un", 9) == 0) kDesign = 40; -// else if(strncmp(tmp2->str, "shotai=mincho", 13) == 0) kShotai = kMincho; if(strncmp(tmp2->str, "shotai=mincho", 13) == 0) kShotai = kMincho; else if(strncmp(tmp2->str, "shotai=gothic", 13) == 0) kShotai = kGothic; else if(strncmp(tmp2->str, "shotai=skeleton", 15) == 0) kShotai = kGothic; @@ -63,20 +73,11 @@ int main(int argc, char *argv[]){ } else{ // redirected request kInput = 0; - tmp1 = g_string_new((gchar *)getenv("REDIRECT_URL")); - pos = tmp1->str; while(1){ cur = strchr(pos, '/'); tmp2 = g_string_new(pos); if(cur != NULL) g_string_set_size(tmp2, cur - pos); //got request string -// if(strncmp(tmp2->str, "jp", 2) == 0) kDesign = 0; -// else if(strncmp(tmp2->str, "cs", 2) == 0) kDesign = 10; -// else if(strncmp(tmp2->str, "ct", 2) == 0) kDesign = 11; -// else if(strncmp(tmp2->str, "kr", 2) == 0) kDesign = 20; -// else if(strncmp(tmp2->str, "vn", 2) == 0) kDesign = 30; -// else if(strncmp(tmp2->str, "un", 2) == 0) kDesign = 40; -// else if(strncmp(tmp2->str, "mincho", 6) == 0) kShotai = kMincho; if(strncmp(tmp2->str, "mincho", 6) == 0) kShotai = kMincho; else if(strncmp(tmp2->str, "gothic", 6) == 0) kShotai = kGothic; else if(strncmp(tmp2->str, "skeleton", 8) == 0) kShotai = kGothic; @@ -131,12 +132,6 @@ int main(int argc, char *argv[]){ drawGlyph(test2, 0); //output to file filename = g_string_new(pngFilePath); -// if(kDesign == 0) g_string_append(filename, "jp/"); -// else if(kDesign == 10) g_string_append(filename, "cs/"); -// else if(kDesign == 11) g_string_append(filename, "ct/"); -// else if(kDesign == 20) g_string_append(filename, "kr/"); -// else if(kDesign == 30) g_string_append(filename, "vn/"); -// else if(kDesign == 40) g_string_append(filename, "un/"); if(kShotai == kMincho) g_string_append(filename, "mincho/"); else if(kShotai == kGothic) g_string_append(filename, "gothic/");//skeleton?? g_string_append(filename, test1->str); @@ -147,7 +142,7 @@ int main(int argc, char *argv[]){ // writePng(pngWidth, pngHeight, kageCanvas, fp); // fclose(fp); //output to stdout - fprintf(stdout, "Content-type: image/png\n\n"); + if(type != 1) fprintf(stdout, "Content-type: image/png\n\n"); writePng(pngWidth, pngHeight, kageCanvas, stdout); //done closePng(pngWidth, pngHeight, kageCanvas); @@ -156,7 +151,7 @@ int main(int argc, char *argv[]){ err = fopen("error.png", "r"); fread(errbuf, sizeof(char), errorFileSize, err); // printf("An error occurred.\r\n"); - fprintf(stdout, "Content-type: image/png\n\n"); + if(type != 1) fprintf(stdout, "Content-type: image/png\n\n"); fwrite(errbuf, sizeof(char), errorFileSize, stdout); fclose(err); } @@ -167,11 +162,11 @@ int main(int argc, char *argv[]){ kMode = 1; drawGlyph(test2, 0); g_string_append(kResultText, "\n"); - fprintf(stdout, "Content-type: image/svg-xml\n\n"); + if(type != 1) fprintf(stdout, "Content-type: image/svg-xml\n\n"); fprintf(stdout, "%s", kResultText->str); } else{ - fprintf(stdout, "Content-type: text/plain\n\n"); + if(type != 1) fprintf(stdout, "Content-type: text/plain\n\n"); fprintf(stdout, "An error occurred."); } } @@ -182,11 +177,11 @@ int main(int argc, char *argv[]){ drawGlyph(test2, 0); g_string_append(kResultText, "fill\n"); g_string_append(kResultText, "%%EOF\n"); - fprintf(stdout, "Content-type: application/postscript\n\n"); + if(type != 1) fprintf(stdout, "Content-type: application/postscript\n\n"); fprintf(stdout, "%s", kResultText->str); } else{ - fprintf(stdout, "Content-type: text/plain\n\n"); + if(type != 1) fprintf(stdout, "Content-type: text/plain\n\n"); fprintf(stdout, "An error occurred."); } } @@ -194,11 +189,11 @@ int main(int argc, char *argv[]){ if(test2->len != 0){ test2 = CalcSizes(test2, 1); - fprintf(stdout, "Content-type: text/plain\n\n"); + if(type != 1) fprintf(stdout, "Content-type: text/plain\n\n"); fprintf(stdout, "result=%s", test2->str); } else{ - fprintf(stdout, "Content-type: text/plain\n\n"); + if(type != 1) fprintf(stdout, "Content-type: text/plain\n\n"); fprintf(stdout, "result=nodata"); } } diff --git a/kagecgi/kagedb.c b/kagecgi/kagedb.c index efbf7b8..1d5f647 100755 --- a/kagecgi/kagedb.c +++ b/kagecgi/kagedb.c @@ -6,18 +6,19 @@ #include "sysdep.h" int initDB(){ - kDatabase = dbopen(databaseFileName, O_RDWR|O_CREAT, 0666, DB_HASH, NULL); + db_create(&kDatabase, NULL, 0); + kDatabase->open(kDatabase, databaseFileName, NULL, DB_HASH, DB_RDONLY, 0644); return 0; } int closeDB(){ - kDatabase->close(kDatabase); + kDatabase->close(kDatabase, 0); return 0; } void searchPartsData(const GString *in, GString *out){ DBT dbkey, dbdata; - char *start, *end; + char *start, *end, *buf; GString *temp, *temp2; //cut off the end '-0000' if 'in' end with it @@ -38,12 +39,13 @@ void searchPartsData(const GString *in, GString *out){ dbkey.size = temp->len; g_string_set_size(out, 0); temp2 = g_string_new(""); - kDatabase->get(kDatabase, &dbkey, &dbdata, 0); + kDatabase->get(kDatabase, NULL, &dbkey, &dbdata, 0); if(dbdata.size != 0){ - ((char *)dbdata.data)[dbdata.size] = '\0'; //set null-stop to the result data + buf = (char *)malloc(dbdata.size + 1); + strncpy(buf, dbdata.data, dbdata.size + 1); //first:search selected shotai - if(kShotai == kMincho) start = strstr(dbdata.data, ",mincho,"); - else start = strstr(dbdata.data, ",gothic,"); + if(kShotai == kMincho) start = strstr(buf, ",mincho,"); + else start = strstr(buf, ",gothic,"); if(start != NULL){ start = strchr((start+8), ','); if(start != NULL){ @@ -59,8 +61,8 @@ void searchPartsData(const GString *in, GString *out){ } } //second:search another shotai - if(kShotai == kMincho) start = strstr(dbdata.data, ",gothic,"); - else start = strstr(dbdata.data, ",mincho,"); + if(kShotai == kMincho) start = strstr(buf, ",gothic,"); + else start = strstr(buf, ",mincho,"); if(start != NULL){ start = strchr((start+8), ','); if(start != NULL){ @@ -75,12 +77,13 @@ void searchPartsData(const GString *in, GString *out){ } } } + free(buf); } } void searchAliasData(const GString *in, GString *out){ DBT dbkey, dbdata; - char *start, *end; + char *start, *end, *buf; GString *temp; //cut off the end '-0000' if 'in' end with it @@ -100,9 +103,11 @@ void searchAliasData(const GString *in, GString *out){ dbkey.data = temp->str; dbkey.size = temp->len; g_string_set_size(out, 0); - kDatabase->get(kDatabase, &dbkey, &dbdata, 0); + kDatabase->get(kDatabase, NULL, &dbkey, &dbdata, 0); if(dbdata.size != 0){ - start = strstr(dbdata.data, ",linkto,"); + buf = (char *)malloc(dbdata.size + 1); + strncpy(buf, dbdata.data, dbdata.size + 1); + start = strstr(buf, ",linkto,"); if(start != NULL){ start = strchr((start+8), ','); if(start != NULL){ diff --git a/kagecgi/kagetool.c b/kagecgi/kagetool.c index 8254e05..9c23bc8 100755 --- a/kagecgi/kagetool.c +++ b/kagecgi/kagetool.c @@ -386,7 +386,7 @@ void CalcOptions(const GString *in, int *mitsudo, int *flag, double *yoko, doubl buf = convertStroke(in->str, buf, &strokes); for(i = 0; i < strokes; i++){ if(buf[i * 11 + 0] % 10 == 0){ - if(buf[i * 11 + 1] != 0){ *yoko = (double)(buf[i * 11 + 1]) * 0.1;fprintf(stderr,"@@@@@\r\n");} + if(buf[i * 11 + 1] != 0) *yoko = (double)(buf[i * 11 + 1]) * 0.1; if(buf[i * 11 + 2] != 0) *tate = (double)(buf[i * 11 + 2]) * 0.1; if(buf[i * 11 + 3] != 0) *flag = *flag + buf[i * 11 + 3] * 16; } diff --git a/kagecgi/sysdep.h b/kagecgi/sysdep.h index cbf3e38..5732784 100755 --- a/kagecgi/sysdep.h +++ b/kagecgi/sysdep.h @@ -15,6 +15,5 @@ #include #include -#include -//#include +#include