X-Git-Url: http://git.chise.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=kagecgi%2Fkagecgi.c;h=24fb59957fbb6ef93cdd31d4d74f9b9d6e1a8868;hb=5f6d5b338d65dab4f7a893bfdedea22599eac3eb;hp=4a92461e1b5a8e2a7931162f004d19972f830bde;hpb=18f978ffb60be4b7f64c74610a08529f7bd3392d;p=chise%2Fkage.git diff --git a/kagecgi/kagecgi.c b/kagecgi/kagecgi.c index 4a92461..24fb599 100755 --- a/kagecgi/kagecgi.c +++ b/kagecgi/kagecgi.c @@ -1,204 +1,205 @@ -//kagecgi.c -// - -#include "kage.h" -#include "kagecgi.h" -#include "sysdep.h" - -int main(int argc, char *argv[]){ - GString *tmp1, *tmp2, *test1, *test2, *filename; - FILE *err; - char errbuf[errorFileSize]; - char *pos, *cur; - int dummy; - int type; - - dummy = initDB(); - - //set default - kShotai = kMincho; -// kShotai = kGothic; -// kDesign = 0; //jp - kSize = 200; - kType = 0; //png - kInput = 0; //ids or direct - kResultText = g_string_new(""); - kMode = 0; - - //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(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, "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; - else if(strncmp(tmp2->str, "type=png", 8) == 0) kType = 0; - else if(strncmp(tmp2->str, "type=svg", 8) == 0) kType = 1; - else if(strncmp(tmp2->str, "type=eps", 8) == 0) kType = 2; - else if(strncmp(tmp2->str, "type=raw", 8) == 0) kType = 3; - else if(strncmp(tmp2->str, "input=ids", 9) == 0) kInput = 0; - else if(strncmp(tmp2->str, "input=directwithadjust", 22) == 0) kInput = 2; - else if(strncmp(tmp2->str, "input=direct", 12) == 0) kInput = 1; - else if(strncmp(tmp2->str, "size=24", 7) == 0) kSize = 24; - else if(strncmp(tmp2->str, "size=200", 8) == 0) kSize = 200; - else test1 = g_string_new(tmp2->str); - if(cur == NULL) break; - pos = cur + 1; - } - } - else{ // redirected request - kInput = 0; - 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, "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; - else if(strncmp(tmp2->str, "v0.4", 4) == 0); - else test1 = g_string_new(tmp2->str); - if(cur == NULL) break; - pos = cur + 1; - } - if(strncmp(test1->str + test1->len - 4, ".png", 4) == 0) kType = 0; - if(strncmp(test1->str + test1->len - 4, ".svg", 4) == 0) kType = 1; - if(strncmp(test1->str + test1->len - 4, ".eps", 4) == 0) kType = 2; - if(strncmp(test1->str + test1->len - 4, ".raw", 4) == 0) kType = 3; - g_string_set_size(test1, test1->len - 4); - } - - //clear result buffer - test2 = g_string_new(""); - if(kType == 1){ //svg - g_string_append(kResultText, "\n"); - g_string_append(kResultText, "\n"); - g_string_append(kResultText, ""); - } - else if(kType == 2){ //eps - g_string_append(kResultText, "%!PS-Adobe-3.0 EPSF-3.0\n"); - g_string_append(kResultText, "%%BoundingBox: 0 -208 1024 816\n"); - g_string_append(kResultText, "%%Pages: 0\n"); - g_string_append(kResultText, "%%Title: "); - g_string_append(kResultText, test1->str); - g_string_append(kResultText, "\n"); - g_string_append(kResultText, "%%Creator: KAGE System\n"); - g_string_append(kResultText, "%%CreationDate: 00:00 1-1-2004\n"); - g_string_append(kResultText, "%%EndComments\n"); - g_string_append(kResultText, "%%EndProlog\n"); - g_string_append(kResultText, "%%Page \""); - g_string_append(kResultText, test1->str); - g_string_append(kResultText, "\" 1\n"); - g_string_append(kResultText, "newpath\n"); - } - kageCanvas = initPng(canvasWidth, canvasHeight); - if(kInput == 0) generateGlyph(test1, test2); - else{ - convert99(test1, test2); - // g_string_append(test2, test1->str); - } - - if(kType == 0){ //png(image) - if(test2->len != 0){ - if(kInput != 1){ //0 and 2 - test2 = CalcSizes(test2, 1); - } - DrawBox(); - drawGlyph(test2, 0); - //output to file - filename = g_string_new(pngFilePath); - if(kShotai == kMincho) g_string_append(filename, "mincho/"); - else if(kShotai == kGothic) g_string_append(filename, "gothic/");//skeleton?? - g_string_append(filename, test1->str); - g_string_append(filename, ".png"); - -//skip for adjustment mode -// fp = fopen(filename->str, "w"); -// writePng(pngWidth, pngHeight, kageCanvas, fp); -// fclose(fp); - //output to stdout - if(type != 1) fprintf(stdout, "Content-type: image/png\n\n"); - writePng(pngWidth, pngHeight, kageCanvas, stdout); - //done - closePng(pngWidth, pngHeight, kageCanvas); - } - else{ - err = fopen("error.png", "r"); - fread(errbuf, sizeof(char), errorFileSize, err); - // printf("An error occurred.\r\n"); - if(type != 1) fprintf(stdout, "Content-type: image/png\n\n"); - fwrite(errbuf, sizeof(char), errorFileSize, stdout); - fclose(err); - } - } - else if(kType == 1){ //svg(vector graphics) - if(test2->len != 0){ - test2 = CalcSizes(test2, 1); - kMode = 1; - drawGlyph(test2, 0); - g_string_append(kResultText, "\n"); - if(type != 1) fprintf(stdout, "Content-type: image/svg-xml\n\n"); - fprintf(stdout, "%s", kResultText->str); - } - else{ - if(type != 1) fprintf(stdout, "Content-type: text/plain\n\n"); - fprintf(stdout, "An error occurred."); - } - } - else if(kType == 2){ //eps(vector graphics) - if(test2->len != 0){ - test2 = CalcSizes(test2, 1); - kMode = 2; - drawGlyph(test2, 0); - g_string_append(kResultText, "fill\n"); - g_string_append(kResultText, "%%EOF\n"); - if(type != 1) fprintf(stdout, "Content-type: application/postscript\n\n"); - fprintf(stdout, "%s", kResultText->str); - } - else{ - if(type != 1) fprintf(stdout, "Content-type: text/plain\n\n"); - fprintf(stdout, "An error occurred."); - } - } - else{ //raw(text) - - if(test2->len != 0){ - test2 = CalcSizes(test2, 1); - if(type != 1) fprintf(stdout, "Content-type: text/plain\n\n"); - fprintf(stdout, "result=%s", test2->str); - } - else{ - if(type != 1) fprintf(stdout, "Content-type: text/plain\n\n"); - fprintf(stdout, "result=nodata"); - } - } - dummy = closeDB(); - - return 0; -} - +//kagecgi.c +// + +#include "kage.h" +#include "kagecgi.h" +#include "sysdep.h" + +int main(int argc, char *argv[]){ + KGString *tmp1, *tmp2, *test1, *test2, *filename; + FILE *err; + char errbuf[errorFileSize]; + char *pos, *cur; + int dummy; + int type; + + dummy = initDB(); + + //set default + kShotai = kMincho; + //kShotai = kGothic; + kSize = 200; + kType = 0; //png + kInput = 0; //ids or direct + kResultText = kg_string_new(""); + kMode = 0; + + //confirm request + type = 0; + //GET request + if(type == 0){ + tmp1 = kg_string_new((kgchar *)getenv("QUERY_STRING")); + if(tmp1->len != 0) type = 2; + } + //argv(detect after GET request) + if(type == 0){ + tmp1 = kg_string_new((kgchar *)argv[1]); + if(tmp1->len != 0) type = 1; + } + //redirect + if(type == 0){ + tmp1 = kg_string_new((kgchar *)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(type == 1 || type == 2){ //argv or GET request + while(1){ + cur = strchr(pos, '&'); + tmp2 = kg_string_new(pos); + if(cur != NULL) kg_string_set_size(tmp2, cur - pos); + //got request string + 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; + else if(strncmp(tmp2->str, "type=png", 8) == 0) kType = 0; + else if(strncmp(tmp2->str, "type=svg", 8) == 0) kType = 1; + else if(strncmp(tmp2->str, "type=eps", 8) == 0) kType = 2; + else if(strncmp(tmp2->str, "type=raw", 8) == 0) kType = 3; + else if(strncmp(tmp2->str, "input=ids", 9) == 0) kInput = 0; + else if(strncmp(tmp2->str, "input=directwithadjust", 22) == 0) kInput = 2; + else if(strncmp(tmp2->str, "input=direct", 12) == 0) kInput = 1; + else if(strncmp(tmp2->str, "size=24", 7) == 0) kSize = 24; + else if(strncmp(tmp2->str, "size=200", 8) == 0) kSize = 200; + else test1 = kg_string_new(tmp2->str); + if(cur == NULL) break; + pos = cur + 1; + } + } + else{ // redirected request + kInput = 0; + while(1){ + cur = strchr(pos, '/'); + tmp2 = kg_string_new(pos); + if(cur != NULL) kg_string_set_size(tmp2, cur - pos); + //got request string + 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; + else if(strncmp(tmp2->str, "v0.4", 4) == 0); + else test1 = kg_string_new(tmp2->str); + if(cur == NULL) break; + pos = cur + 1; + } + if(strncmp(test1->str + test1->len - 4, ".png", 4) == 0) kType = 0; + if(strncmp(test1->str + test1->len - 4, ".svg", 4) == 0) kType = 1; + if(strncmp(test1->str + test1->len - 4, ".eps", 4) == 0) kType = 2; + if(strncmp(test1->str + test1->len - 4, ".raw", 4) == 0) kType = 3; + kg_string_set_size(test1, test1->len - 4); + } + + //clear result buffer + test2 = kg_string_new(""); + if(kType == 1){ //svg + kg_string_append(kResultText, "\n"); + kg_string_append(kResultText, "\n"); + kg_string_append(kResultText, ""); + } + else if(kType == 2){ //eps + kg_string_append(kResultText, "%!PS-Adobe-3.0 EPSF-3.0\n"); + kg_string_append(kResultText, "%%BoundingBox: 0 -208 1024 816\n"); + kg_string_append(kResultText, "%%Pages: 0\n"); + kg_string_append(kResultText, "%%Title: "); + kg_string_append(kResultText, test1->str); + kg_string_append(kResultText, "\n"); + kg_string_append(kResultText, "%%Creator: KAGE System\n"); + kg_string_append(kResultText, "%%CreationDate: 00:00 1-1-2004\n"); + kg_string_append(kResultText, "%%EndComments\n"); + kg_string_append(kResultText, "%%EndProlog\n"); + kg_string_append(kResultText, "%%Page \""); + kg_string_append(kResultText, test1->str); + kg_string_append(kResultText, "\" 1\n"); + kg_string_append(kResultText, "newpath\n"); + } + kageCanvas = initPng(canvasWidth, canvasHeight); + if(kInput == 0) generateGlyph(test1, test2); + else{ + convert99(test1, test2); + // kg_string_append(test2, test1->str); + } + + if(kType == 0){ //png(image) + if(test2->len != 0){ + if(kInput != 1){ //0 and 2 + test2 = CalcSizes(test2, 1); + } + DrawBox(); + drawGlyph(test2, 0); + //output to file + filename = kg_string_new(pngFilePath); + if(kShotai == kMincho) kg_string_append(filename, "mincho/"); + else if(kShotai == kGothic) kg_string_append(filename, "gothic/");//skeleton?? + kg_string_append(filename, test1->str); + kg_string_append(filename, ".png"); + + //skip for adjustment mode + //fp = fopen(filename->str, "w"); + //writePng(pngWidth, pngHeight, kageCanvas, fp); + //fclose(fp); + //output to stdout + if(type != 1) fprintf(stdout, "Content-type: image/png\n\n"); + writePng(pngWidth, pngHeight, kageCanvas, stdout); + //done + closePng(pngWidth, pngHeight, kageCanvas); + } + else{ + err = fopen(errorFileName, "r"); + fread(errbuf, sizeof(char), errorFileSize, err); + //printf("An error occurred.\r\n"); + if(type != 1) fprintf(stdout, "Content-type: image/png\n\n"); + fwrite(errbuf, sizeof(char), errorFileSize, stdout); + fclose(err); + } + } + else if(kType == 1){ //svg(vector graphics) + if(test2->len != 0){ + test2 = CalcSizes(test2, 1); + kMode = 1; + drawGlyph(test2, 0); + kg_string_append(kResultText, "\n"); + if(type != 1) fprintf(stdout, "Content-type: image/svg-xml\n\n"); + fprintf(stdout, "%s", kResultText->str); + } + else{ + if(type != 1) fprintf(stdout, "Content-type: text/plain\n\n"); + fprintf(stdout, "An error occurred."); + } + } + else if(kType == 2){ //eps(vector graphics) + if(test2->len != 0){ + test2 = CalcSizes(test2, 1); + kMode = 2; + drawGlyph(test2, 0); + kg_string_append(kResultText, "fill\n"); + kg_string_append(kResultText, "%%EOF\n"); + if(type != 1) fprintf(stdout, "Content-type: application/postscript\n\n"); + fprintf(stdout, "%s", kResultText->str); + } + else{ + if(type != 1) fprintf(stdout, "Content-type: text/plain\n\n"); + fprintf(stdout, "An error occurred."); + } + } + else{ //raw(text) + + if(test2->len != 0){ + test2 = CalcSizes(test2, 1); + if(type != 1) fprintf(stdout, "Content-type: text/plain\n\n"); + fprintf(stdout, "result=%s", test2->str); + } + else{ + if(type != 1) fprintf(stdout, "Content-type: text/plain\n\n"); + fprintf(stdout, "result=nodata"); + } + } + dummy = closeDB(); + + return 0; +} +