X-Git-Url: http://git.chise.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=kagecgi%2Fkagecgi.c;h=24fb59957fbb6ef93cdd31d4d74f9b9d6e1a8868;hb=5f6d5b338d65dab4f7a893bfdedea22599eac3eb;hp=93f74c93c2089ac565076336a8238c504ca7fed6;hpb=5aa6025ee73510a18f93edfd37001a60a5a331e0;p=chise%2Fkage.git
diff --git a/kagecgi/kagecgi.c b/kagecgi/kagecgi.c
index 93f74c9..24fb599 100755
--- a/kagecgi/kagecgi.c
+++ b/kagecgi/kagecgi.c
@@ -1,207 +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, *fp;
- char errbuf[errorFileSize];
- char *pos, *cur;
- int dummy;
- int i;
-
- 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;
-
- //set some param by request
-// tmp1 = g_string_new((gchar *)argv[1]);
- tmp1 = g_string_new((gchar *)getenv("QUERY_STRING"));
- pos = tmp1->str;
-
- //separate token
- if(tmp1->len != 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, "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;
- 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;
- 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;
- 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, "\n");
- fprintf(stdout, "Content-type: image/svg-xml\n\n");
- fprintf(stdout, "%s", kResultText->str);
- }
- else{
- 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");
- fprintf(stdout, "Content-type: application/postscript\n\n");
- fprintf(stdout, "%s", kResultText->str);
- }
- else{
- fprintf(stdout, "Content-type: text/plain\n\n");
- fprintf(stdout, "An error occurred.");
- }
- }
- else{ //raw(text)
- if(test2->len != 0){
- fprintf(stdout, "Content-type: text/plain\n\n");
- fprintf(stdout, "result=%s", test2->str);
- }
- else{
- 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, "\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;
+}
+