[BACK]Return to repl.c CVS log [TXT][DIR] Up to [local] / OpenXM / rc

Annotation of OpenXM/rc/repl.c, Revision 1.19

1.19    ! takayama    1: /* $OpenXM: OpenXM/rc/repl.c,v 1.18 2019/03/29 02:49:48 takayama Exp $ */
1.8       maekawa     2:
1.1       takayama    3: #include <stdio.h>
1.8       maekawa     4: #include <stdlib.h>
1.9       maekawa     5:
                      6: #include <errno.h>
1.11      maekawa     7: #include <fcntl.h>
1.9       maekawa     8: #include <string.h>
1.1       takayama    9: #include <unistd.h>
                     10:
                     11: #define BUFSIZE 10000
1.15      takayama   12: #define SSIZE  1024
1.8       maekawa    13:
1.15      takayama   14: /* If you make the following two strings longer, increase the number SSIZE */
1.14      takayama   15: #define        REPL_IMGFILE    "repl_test.img"
                     16: #define        REPL_PSFILE         "repl_test.ps"
1.11      maekawa    17:
1.8       maekawa    18: int
1.4       takayama   19: main(int argc,char *argv[]) {
1.1       takayama   20:   char s[BUFSIZE];
                     21:   char cwd[BUFSIZE];
1.3       noro       22:   char *slash;
1.4       takayama   23:   char type = 'b';
                     24:   FILE *fp;
1.17      takayama   25:   int fd,i;
1.14      takayama   26:   char sss_png[SSIZE];
                     27:   char sss_gif[SSIZE];
1.4       takayama   28:
1.9       maekawa    29:   if (getcwd(cwd, sizeof(cwd)) == NULL) {
                     30:        fprintf(stderr, "getcwd: %s\n", strerror(errno));
1.11      maekawa    31:        exit(EXIT_FAILURE);
1.9       maekawa    32:   }
1.10      maekawa    33:   if ((slash = strrchr(cwd, '/')) == cwd) {
                     34:        fprintf(stderr, "The current working directory is /.\n");
1.11      maekawa    35:        exit(EXIT_FAILURE);
1.10      maekawa    36:   }
1.3       noro       37:   *slash = 0;
1.17      takayama   38:
                     39:   for (i=1; i<argc; i++) {
                     40:     if (strcmp(argv[i],"csh")==0) {
                     41:       type = 'c';
                     42:     }else if (strcmp(argv[i],"bash")==0) {
                     43:       type = 'b';
                     44:     }else if (strcmp(argv[i],"--prefix")==0) {
                     45:       i++;
                     46:       strcpy(cwd,argv[i]);
                     47:          strcat(cwd,"/OpenXM");
                     48:       if (cwd[0] != '/') {
                     49:         fprintf(stderr,"Warning: prefix must start with /\n");
1.19    ! takayama   50:         fprintf(stderr,"Your prefix is %s\n",cwd);
1.17      takayama   51:       }
                     52:     }else{
                     53:       fprintf(stderr,"Warning: Unknown option.\n");
                     54:     }
                     55:   }
                     56:
1.1       takayama   57:   while (fgets(s,BUFSIZE,stdin) != NULL) {
                     58:        if (strcmp(s,"OpenXM_HOME=$HOME/OpenXM\n") == 0) {
1.3       noro       59:          printf("OpenXM_HOME=%s\n",cwd);
1.1       takayama   60:        }else if (strcmp(s,"setenv OpenXM_HOME $HOME/OpenXM\n") == 0) {
1.3       noro       61:          printf("setenv OpenXM_HOME %s\n",cwd);
1.18      takayama   62:        }else if (strcmp(s,"OpenXM_HOME=$(HOME)/OpenXM\n") == 0) {
                     63:          printf("OpenXM_HOME=%s\n",cwd);
                     64:        }else if (strcmp(s,"setenv OpenXM_HOME \"$(HOME)\"/OpenXM\n") == 0) {
                     65:          printf("setenv OpenXM_HOME %s\n",cwd);
                     66:        }else if (strcmp(s,"OpenXM_HOME=\"${HOME}\"/OpenXM\n") == 0) {
                     67:          printf("OpenXM_HOME=%s\n",cwd);
1.1       takayama   68:        }else{
                     69:          printf("%s",s);
                     70:        }
                     71:   }
1.4       takayama   72:
                     73:   /* Configuring environmental variables. */
                     74:   /* Check if pstoimg (src/asir-contrib) supports png format. */
1.14      takayama   75:   if ((fp = fopen(REPL_PSFILE,"w")) == NULL) {
                     76:        fprintf(stderr, "fopen: %s", strerror(errno));
1.11      maekawa    77:        exit(EXIT_FAILURE);
                     78:   }
                     79:   fprintf(fp,"/Times-Roman findfont 10 scalefont setfont\n");
                     80:   fprintf(fp," 390 290 moveto  (F) show \n");
                     81:   fprintf(fp,"showpage \n");
1.13      maekawa    82:   while (fclose(fp) != 0) {
                     83:        if (errno == EINTR)
                     84:                continue;
                     85:        break;
                     86:   }
1.11      maekawa    87:
1.15      takayama   88:   sprintf(sss_png,"pstoimg -type png %s -out %s >/dev/null",REPL_PSFILE,REPL_IMGFILE);
                     89:   sprintf(sss_gif,"pstoimg -type gif %s -out %s >/dev/null",REPL_PSFILE,REPL_IMGFILE);
1.14      takayama   90:
                     91:   if (!system(sss_png)) {
1.4       takayama   92:        if (type == 'b') {
                     93:          printf("export OpenXM_PSTOIMG_TYPE=png\n");
                     94:        }else{
                     95:          printf("setenv OpenXM_PSTOIMG_TYPE png\n");
                     96:        }
1.14      takayama   97:   }else if (!system(sss_gif)) {
1.4       takayama   98:        if (type == 'b') {
1.5       takayama   99:          printf("OpenXM_PSTOIMG_TYPE=gif\n");
                    100:       printf("export OpenXM_PSTOIMG_TYPE\n");
1.4       takayama  101:        }else{
                    102:          printf("setenv OpenXM_PSTOIMG_TYPE=gif\n");
                    103:        }
                    104:   }else {
1.16      takayama  105:     if (type == 'b') {
                    106:       printf("OpenXM_PSTOIMG_TYPE=no\n");
                    107:       printf("export OpenXM_PSTOIMG_TYPE\n");
                    108:     }else{
                    109:       printf("setenv OpenXM_PSTOIMG_TYPE no\n");
                    110:     }
1.4       takayama  111:   }
                    112:
1.12      maekawa   113:   while (unlink(REPL_IMGFILE) != 0) {
                    114:        if (errno == EINTR)
                    115:                continue;
                    116:        break;
                    117:   }
                    118:   while (unlink(REPL_PSFILE) != 0) {
                    119:        if (errno == EINTR)
                    120:                continue;
                    121:        break;
                    122:   }
1.8       maekawa   123:
1.11      maekawa   124:   exit(EXIT_SUCCESS);
1.1       takayama  125: }

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