\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
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
}\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
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
// 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
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
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
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
\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
#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
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
}\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
}\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
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