Change BDB version from 1 to 3.
authorKoichi KAMICHI <kamichi@fonts.jp>
Sat, 27 Mar 2004 13:47:23 +0000 (13:47 +0000)
committerKoichi KAMICHI <kamichi@fonts.jp>
Sat, 27 Mar 2004 13:47:23 +0000 (13:47 +0000)
Fix DB read bug.
Remove some comments.

kagecgi/Makefile
kagecgi/README.en
kagecgi/kagecgi.c
kagecgi/kagedb.c
kagecgi/kagetool.c
kagecgi/sysdep.h

index 1e88ed3..df5839d 100755 (executable)
@@ -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\r
 LIBS= -L/usr/local/lib -lpng -ldb -lglib-2.0 -L/usr/X11R6/lib -lX11\r
 \r
+#for MacOSX with fink\r
+#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/\r
+#LIBS= -L/sw/lib -lpng -lglib-2.0 -L/usr/lib -ldbm -L/usr/X11R6/lib -lX11\r
+\r
 kage.cgi: kagecgi.o kagepng.o kagedf.o kagecd.o kageic.o kagepoly.o kagedb.o kageeg.o kagecomb.o kagechar.o kagetool.o\r
        $(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)\r
 \r
index eadee3d..92b99be 100644 (file)
@@ -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
 ========================
index 60910f1..4a92461 100755 (executable)
@@ -7,11 +7,11 @@
 \r
 int main(int argc, char *argv[]){\r
        GString *tmp1, *tmp2, *test1, *test2, *filename;\r
-       FILE *err, *fp;\r
+       FILE *err;\r
        char errbuf[errorFileSize];\r
        char *pos, *cur;\r
        int dummy;\r
-       int i;\r
+       int type;\r
 \r
        dummy = initDB();\r
 \r
@@ -25,25 +25,35 @@ int main(int argc, char *argv[]){
        kResultText = g_string_new("");\r
        kMode = 0;\r
        \r
-       //set some param by request\r
-//     tmp1 = g_string_new((gchar *)argv[1]);\r
-       tmp1 = g_string_new((gchar *)getenv("QUERY_STRING"));\r
+       //confirm request\r
+       type = 0;\r
+       //argv\r
+       tmp1 = g_string_new((gchar *)argv[1]);\r
+       if(tmp1->len != 0) type = 1;\r
+       //direct\r
+       if(type == 0){\r
+         tmp1 = g_string_new((gchar *)getenv("QUERY_STRING"));\r
+         if(tmp1->len != 0) type = 2;\r
+       }\r
+       //redirect\r
+       if(type == 0){\r
+         tmp1 = g_string_new((gchar *)getenv("REDIRECT_URL"));\r
+         if(tmp1->len != 0) type = 3;\r
+       }\r
+       //error\r
+       if(type == 0){\r
+         fprintf(stderr, "Request Error.\n");\r
+         return 0;\r
+       }\r
        pos = tmp1->str;\r
        \r
        //separate token\r
-       if(tmp1->len != 0){\r
+       if(type == 1 || type == 2){ //argv or direct\r
                while(1){\r
                        cur = strchr(pos, '&');\r
                        tmp2 = g_string_new(pos);\r
                        if(cur != NULL) g_string_set_size(tmp2, cur - pos);\r
                        //got request string\r
-//                     if(strncmp(tmp2->str, "design=jp", 9) == 0) kDesign = 0;\r
-//                     else if(strncmp(tmp2->str, "design=cs", 9) == 0) kDesign = 10;\r
-//                     else if(strncmp(tmp2->str, "design=ct", 9) == 0) kDesign = 11;\r
-//                     else if(strncmp(tmp2->str, "design=kr", 9) == 0) kDesign = 20;\r
-//                     else if(strncmp(tmp2->str, "design=vn", 9) == 0) kDesign = 30;\r
-//                     else if(strncmp(tmp2->str, "design=un", 9) == 0) kDesign = 40;\r
-//                     else if(strncmp(tmp2->str, "shotai=mincho", 13) == 0) kShotai = kMincho;\r
                        if(strncmp(tmp2->str, "shotai=mincho", 13) == 0) kShotai = kMincho;\r
                        else if(strncmp(tmp2->str, "shotai=gothic", 13) == 0) kShotai = kGothic;\r
                        else if(strncmp(tmp2->str, "shotai=skeleton", 15) == 0) kShotai = kGothic;\r
@@ -63,20 +73,11 @@ int main(int argc, char *argv[]){
        }\r
        else{ // redirected request\r
                kInput = 0;\r
-               tmp1 = g_string_new((gchar *)getenv("REDIRECT_URL"));\r
-               pos = tmp1->str;\r
                while(1){\r
                        cur = strchr(pos, '/');\r
                        tmp2 = g_string_new(pos);\r
                        if(cur != NULL) g_string_set_size(tmp2, cur - pos);\r
                        //got request string\r
-//                     if(strncmp(tmp2->str, "jp", 2) == 0) kDesign = 0;\r
-//                     else if(strncmp(tmp2->str, "cs", 2) == 0) kDesign = 10;\r
-//                     else if(strncmp(tmp2->str, "ct", 2) == 0) kDesign = 11;\r
-//                     else if(strncmp(tmp2->str, "kr", 2) == 0) kDesign = 20;\r
-//                     else if(strncmp(tmp2->str, "vn", 2) == 0) kDesign = 30;\r
-//                     else if(strncmp(tmp2->str, "un", 2) == 0) kDesign = 40;\r
-//                     else if(strncmp(tmp2->str, "mincho", 6) == 0) kShotai = kMincho;\r
                        if(strncmp(tmp2->str, "mincho", 6) == 0) kShotai = kMincho;\r
                        else if(strncmp(tmp2->str, "gothic", 6) == 0) kShotai = kGothic;\r
                        else if(strncmp(tmp2->str, "skeleton", 8) == 0) kShotai = kGothic;\r
@@ -131,12 +132,6 @@ int main(int argc, char *argv[]){
                        drawGlyph(test2, 0);\r
                        //output to file\r
                        filename = g_string_new(pngFilePath);\r
-//                     if(kDesign == 0) g_string_append(filename, "jp/");\r
-//                     else if(kDesign == 10) g_string_append(filename, "cs/");\r
-//                     else if(kDesign == 11) g_string_append(filename, "ct/");\r
-//                     else if(kDesign == 20) g_string_append(filename, "kr/");\r
-//                     else if(kDesign == 30) g_string_append(filename, "vn/");\r
-//                     else if(kDesign == 40) g_string_append(filename, "un/");\r
                        if(kShotai == kMincho) g_string_append(filename, "mincho/");\r
                        else if(kShotai == kGothic) g_string_append(filename, "gothic/");//skeleton??\r
                        g_string_append(filename, test1->str);\r
@@ -147,7 +142,7 @@ int main(int argc, char *argv[]){
 //                     writePng(pngWidth, pngHeight, kageCanvas, fp);\r
 //                     fclose(fp);\r
                        //output to stdout\r
-                       fprintf(stdout, "Content-type: image/png\n\n");\r
+                       if(type != 1) fprintf(stdout, "Content-type: image/png\n\n");\r
                        writePng(pngWidth, pngHeight, kageCanvas, stdout);\r
                        //done\r
                        closePng(pngWidth, pngHeight, kageCanvas);\r
@@ -156,7 +151,7 @@ int main(int argc, char *argv[]){
                        err = fopen("error.png", "r");\r
                        fread(errbuf, sizeof(char), errorFileSize, err);\r
                //      printf("An error occurred.\r\n");\r
-                       fprintf(stdout, "Content-type: image/png\n\n");\r
+                       if(type != 1) fprintf(stdout, "Content-type: image/png\n\n");\r
                        fwrite(errbuf, sizeof(char), errorFileSize, stdout);\r
                        fclose(err);\r
                }\r
@@ -167,11 +162,11 @@ int main(int argc, char *argv[]){
                        kMode = 1;\r
                        drawGlyph(test2, 0);\r
                        g_string_append(kResultText, "</svg>\n");\r
-                       fprintf(stdout, "Content-type: image/svg-xml\n\n");\r
+                       if(type != 1) fprintf(stdout, "Content-type: image/svg-xml\n\n");\r
                        fprintf(stdout, "%s", kResultText->str);\r
                }\r
                else{\r
-                       fprintf(stdout, "Content-type: text/plain\n\n");\r
+                       if(type != 1) fprintf(stdout, "Content-type: text/plain\n\n");\r
                        fprintf(stdout, "An error occurred.");\r
                }\r
        }\r
@@ -182,11 +177,11 @@ int main(int argc, char *argv[]){
                        drawGlyph(test2, 0);\r
                        g_string_append(kResultText, "fill\n");\r
                        g_string_append(kResultText, "%%EOF\n");\r
-                       fprintf(stdout, "Content-type: application/postscript\n\n");\r
+                       if(type != 1) fprintf(stdout, "Content-type: application/postscript\n\n");\r
                        fprintf(stdout, "%s", kResultText->str);\r
                }\r
                else{\r
-                       fprintf(stdout, "Content-type: text/plain\n\n");\r
+                       if(type != 1) fprintf(stdout, "Content-type: text/plain\n\n");\r
                        fprintf(stdout, "An error occurred.");\r
                }\r
        }\r
@@ -194,11 +189,11 @@ int main(int argc, char *argv[]){
 \r
                if(test2->len != 0){\r
                        test2 = CalcSizes(test2, 1);\r
-                       fprintf(stdout, "Content-type: text/plain\n\n");\r
+                       if(type != 1) fprintf(stdout, "Content-type: text/plain\n\n");\r
                        fprintf(stdout, "result=%s", test2->str);\r
                }\r
                else{\r
-                       fprintf(stdout, "Content-type: text/plain\n\n");\r
+                       if(type != 1) fprintf(stdout, "Content-type: text/plain\n\n");\r
                        fprintf(stdout, "result=nodata");\r
                }\r
        }\r
index efbf7b8..1d5f647 100755 (executable)
@@ -6,18 +6,19 @@
 #include "sysdep.h"\r
 \r
 int initDB(){\r
-       kDatabase = dbopen(databaseFileName, O_RDWR|O_CREAT, 0666, DB_HASH, NULL);\r
+       db_create(&kDatabase, NULL, 0);
+       kDatabase->open(kDatabase, databaseFileName, NULL, DB_HASH, DB_RDONLY, 0644);\r
        return 0;\r
 }\r
 \r
 int closeDB(){\r
-       kDatabase->close(kDatabase);\r
+       kDatabase->close(kDatabase, 0);\r
        return 0;\r
 }\r
 \r
 void searchPartsData(const GString *in, GString *out){\r
        DBT dbkey, dbdata;\r
-       char *start, *end;\r
+       char *start, *end, *buf;\r
        GString *temp, *temp2;\r
        \r
        //cut off the end '-0000' if 'in' end with it\r
@@ -38,12 +39,13 @@ void searchPartsData(const GString *in, GString *out){
        dbkey.size = temp->len;\r
        g_string_set_size(out, 0);\r
        temp2 = g_string_new("");\r
-       kDatabase->get(kDatabase, &dbkey, &dbdata, 0);\r
+       kDatabase->get(kDatabase, NULL, &dbkey, &dbdata, 0);\r
        if(dbdata.size != 0){\r
-         ((char *)dbdata.data)[dbdata.size] = '\0'; //set null-stop to the result data\r
+               buf = (char *)malloc(dbdata.size + 1);
+               strncpy(buf, dbdata.data, dbdata.size + 1); 
                //first:search selected shotai\r
-               if(kShotai == kMincho) start = strstr(dbdata.data, ",mincho,");\r
-               else start = strstr(dbdata.data, ",gothic,");\r
+               if(kShotai == kMincho) start = strstr(buf, ",mincho,");\r
+               else start = strstr(buf, ",gothic,");\r
                if(start != NULL){\r
                        start = strchr((start+8), ',');\r
                        if(start != NULL){\r
@@ -59,8 +61,8 @@ void searchPartsData(const GString *in, GString *out){
                        }\r
                }\r
                //second:search another shotai\r
-               if(kShotai == kMincho) start = strstr(dbdata.data, ",gothic,");\r
-               else start = strstr(dbdata.data, ",mincho,");\r
+               if(kShotai == kMincho) start = strstr(buf, ",gothic,");\r
+               else start = strstr(buf, ",mincho,");\r
                if(start != NULL){\r
                        start = strchr((start+8), ',');\r
                        if(start != NULL){\r
@@ -75,12 +77,13 @@ void searchPartsData(const GString *in, GString *out){
                                }\r
                        }\r
                }\r
+               free(buf);
        }\r
 }\r
 \r
 void searchAliasData(const GString *in, GString *out){\r
        DBT dbkey, dbdata;\r
-       char *start, *end;\r
+       char *start, *end, *buf;\r
        GString *temp;\r
        \r
        //cut off the end '-0000' if 'in' end with it\r
@@ -100,9 +103,11 @@ void searchAliasData(const GString *in, GString *out){
        dbkey.data = temp->str;\r
        dbkey.size = temp->len;\r
        g_string_set_size(out, 0);\r
-       kDatabase->get(kDatabase, &dbkey, &dbdata, 0);\r
+       kDatabase->get(kDatabase, NULL, &dbkey, &dbdata, 0);\r
        if(dbdata.size != 0){\r
-               start = strstr(dbdata.data, ",linkto,");\r
+               buf = (char *)malloc(dbdata.size + 1);
+               strncpy(buf, dbdata.data, dbdata.size + 1); 
+               start = strstr(buf, ",linkto,");\r
                if(start != NULL){\r
                        start = strchr((start+8), ',');\r
                        if(start != NULL){\r
index 8254e05..9c23bc8 100755 (executable)
@@ -386,7 +386,7 @@ void CalcOptions(const GString *in, int *mitsudo, int *flag, double *yoko, doubl
        buf = convertStroke(in->str, buf, &strokes);\r
        for(i = 0; i < strokes; i++){\r
         if(buf[i * 11 + 0] % 10 == 0){\r
-            if(buf[i * 11 + 1] != 0){ *yoko = (double)(buf[i * 11 + 1]) * 0.1;fprintf(stderr,"@@@@@\r\n");}\r
+            if(buf[i * 11 + 1] != 0) *yoko = (double)(buf[i * 11 + 1]) * 0.1;\r
             if(buf[i * 11 + 2] != 0) *tate = (double)(buf[i * 11 + 2]) * 0.1;\r
             if(buf[i * 11 + 3] != 0) *flag = *flag + buf[i * 11 + 3] * 16;\r
         }\r
index cbf3e38..5732784 100755 (executable)
@@ -15,6 +15,5 @@
 #include <X11/Xlib.h>\r
 #include <X11/Xutil.h>\r
 \r
-#include <db1/db.h>\r
-//#include <db2/db_185.h>\r
+#include <db.h>\r
 \r