[BACK]Return to gendoc.c CVS log [TXT][DIR] Up to [local] / OpenXM / src / cfep / package

Annotation of OpenXM/src/cfep/package/gendoc.c, Revision 1.3

1.1       takayama    1: /*
                      2:    Generates html files for help under
                      3:      ${OpenXM_HOME}/doc/cfep/html-ja_JP.utf8
                      4:    cf. ~/.cfep/html-ja_JP.utf8
                      5:
                      6:    mdimport ${OpenXM_HOME}/doc/cfep/html-ja_JP.utf8
                      7: */
                      8: #include <stdio.h>
                      9: #include <stdlib.h>
                     10: #include <string.h>
                     11: #include <sys/types.h>
                     12: #include <unistd.h>
                     13: #include <locale.h>
                     14:
                     15:
                     16: char *extractFileName(char *s);
                     17: char *extractFolderName(char *s);
                     18: int translate(char *dir,char *outputdirTop);
                     19: int Sjis = 0;
                     20:
                     21: main(int argc, char *argv[]) {
                     22:   char com[1024];
                     23:   char workdir[1024];
                     24:   char oxhome[1024];
                     25:   int i;
                     26:   if (argc < 2) {
                     27:        fprintf(stderr,"gendoc foldernameOfHtmlHelp ... \n");
                     28:        if (Sjis) fprintf(stderr,"  output to ${OpenXM_HOME}/doc/cfep/html-ja_JP.sjis\n");
                     29:        else fprintf(stderr,"  output to ${OpenXM_HOME}/doc/cfep/html-ja_JP.utf8\n");
                     30:        fprintf(stderr,"nkf is used.\n");
1.3     ! ohara      31:        fprintf(stderr,"Example: gendoc ~/OX4/OpenXM/src/asir-doc/html-ja\n");
1.1       takayama   32:        exit(0);
                     33:   }
                     34:   setlocale(LC_ALL,"C");
                     35:   /* if ja_JP.eucJP is set, 01 is added to each bytes of argv[i] on mac. cf. misc/argvtest* */
                     36:   /* A strange things will happen when japanese file names are used. */
                     37:   if (!getenv("OpenXM_HOME")) {
                     38:        fprintf(stderr,"OpenXM_HOME is not set.\n"); exit(1);
                     39:   }
                     40:   strcpy(oxhome,getenv("OpenXM_HOME"));
                     41:   if (Sjis) sprintf(workdir,"%s/doc/cfep/html-ja_JP.sjis",oxhome);
                     42:   else sprintf(workdir,"%s/doc/cfep/html-ja_JP.utf8",oxhome);
                     43:
                     44:   sprintf(com,"mkdir -p %s",workdir);
                     45:   system(com);
                     46:
                     47:   for (i=1; i<argc; i++) {
                     48:        translate(argv[i],workdir);
                     49:   }
1.2       takayama   50:   exit(0);
1.1       takayama   51: }
                     52:
                     53: int translate(char *dir,char *outputdirTop) {
                     54:   char com[1024];
                     55:   FILE *fp;
                     56:   FILE *fp2;
                     57:   int first,i;
                     58:   first = 1;
                     59:   char *folder;
                     60:   char oname[1024*3];
                     61:   char *fname;
                     62:   char longFname[1024];
                     63:   sprintf(com,"ls %s/*.html >/tmp/tmp-gendoc.txt",dir);
                     64:   system(com);
                     65:
                     66:   fp = fopen("/tmp/tmp-gendoc.txt","r");
                     67:   while (fgets(longFname,1000,fp)) {
                     68:        for (i=0; i<strlen(longFname); i++) {
                     69:          if (longFname[i] == '\n') longFname[i] = 0;
                     70:        }
                     71:        if (first) {
                     72:          folder = extractFolderName(longFname);
                     73:          sprintf(com,"mkdir -p %s/%s",outputdirTop,folder);
                     74:          fprintf(stderr,"%s\n",com);
                     75:          system(com);
                     76:          first = 0;
                     77:        }
                     78:        fname = extractFileName(longFname);
                     79:     sprintf(oname,"%s/%s/%s",outputdirTop,folder,fname);
                     80:        fp2 = fopen(oname,"w");
                     81:        if (Sjis) fprintf(fp2,"<HTML>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=SJIS\">\n");
                     82:        else fprintf(fp2,"<HTML>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n");
                     83:        fclose(fp2);
                     84:        if (Sjis) sprintf(com,"nkf -s %s | sed -e 's/<HTML>//g' >>%s",longFname,oname);
                     85:     else sprintf(com,"nkf -w %s | sed -e 's/<HTML>//g' >>%s",longFname,oname);
                     86:     printf("%s\n",com);
                     87:        system(com);
                     88:   }
                     89:   system("rm -f /tmp/tmp-gendoc.txt");
                     90:   return 0;
                     91: }
                     92:
                     93: char *extractFileName(char *s) {
                     94:   int i,n,start;
                     95:   char *ans;
                     96:   start = 0;
                     97:   n = strlen(s);
                     98:   ans = (char *)malloc(n+10);
                     99:   strcpy(ans,"tmp.html");
                    100:   for (i=n-1; i>=0; i--) {
                    101:        if (s[i] == '/') {
                    102:          start = i+1;
                    103:          break;
                    104:        }
                    105:   }
                    106:   if (start < n) strcpy(ans,&(s[start]));
                    107:   for (i=0; i<strlen(ans); i++) {
                    108:        if (ans[i] < ' ') ans[i]=0;
                    109:   }
                    110:   return ans;
                    111: }
                    112:
                    113: char *extractFolderName(char *s) {
                    114:   int i,n,start,end;
                    115:   char *ans;
                    116:   start = end = -1;
                    117:   n = strlen(s);
                    118:   ans = (char *)malloc(n+5);
                    119:   strcpy(ans,"tmp");
                    120:   for (i=n-1; i>=0; i--) {
                    121:        if (s[i] == '/') {
                    122:          i--; end = i;
                    123:          for ( ; i>=0; i--) {
                    124:                if (s[i] == '/') {
                    125:                  start = i+1;
                    126:                  break;
                    127:                }
                    128:          }
                    129:          break;
                    130:        }
                    131:   }
                    132:   if ((start>=0) && (end >=0)) strcpy(ans,&(s[start]));
                    133:   ans[end-start+1] = 0;
                    134:   for (i=0; i<strlen(ans); i++) {
                    135:        if (ans[i] < ' ') ans[i]=0;
                    136:   }
                    137:   return ans;
                    138: }
                    139:

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>