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

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

1.16    ! takayama    1: /* $OpenXM: OpenXM/rc/repl.c,v 1.15 2004/02/13 03:10:19 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.11      maekawa    25:   int fd;
1.14      takayama   26:   char sss_png[SSIZE];
                     27:   char sss_gif[SSIZE];
1.4       takayama   28:
                     29:   if (argc >= 2) {
                     30:        if (strcmp(argv[1],"csh")==0) {
                     31:          type = 'c';
                     32:        }
                     33:   }
1.3       noro       34:
1.9       maekawa    35:   if (getcwd(cwd, sizeof(cwd)) == NULL) {
                     36:        fprintf(stderr, "getcwd: %s\n", strerror(errno));
1.11      maekawa    37:        exit(EXIT_FAILURE);
1.9       maekawa    38:   }
1.10      maekawa    39:   if ((slash = strrchr(cwd, '/')) == cwd) {
                     40:        fprintf(stderr, "The current working directory is /.\n");
1.11      maekawa    41:        exit(EXIT_FAILURE);
1.10      maekawa    42:   }
1.3       noro       43:   *slash = 0;
1.1       takayama   44:   while (fgets(s,BUFSIZE,stdin) != NULL) {
                     45:        if (strcmp(s,"OpenXM_HOME=$HOME/OpenXM\n") == 0) {
1.3       noro       46:          printf("OpenXM_HOME=%s\n",cwd);
1.1       takayama   47:        }else if (strcmp(s,"setenv OpenXM_HOME $HOME/OpenXM\n") == 0) {
1.3       noro       48:          printf("setenv OpenXM_HOME %s\n",cwd);
1.1       takayama   49:        }else{
                     50:          printf("%s",s);
                     51:        }
                     52:   }
1.4       takayama   53:
                     54:   /* Configuring environmental variables. */
                     55:   /* Check if pstoimg (src/asir-contrib) supports png format. */
1.14      takayama   56:   if ((fp = fopen(REPL_PSFILE,"w")) == NULL) {
                     57:        fprintf(stderr, "fopen: %s", strerror(errno));
1.11      maekawa    58:        exit(EXIT_FAILURE);
                     59:   }
                     60:   fprintf(fp,"/Times-Roman findfont 10 scalefont setfont\n");
                     61:   fprintf(fp," 390 290 moveto  (F) show \n");
                     62:   fprintf(fp,"showpage \n");
1.13      maekawa    63:   while (fclose(fp) != 0) {
                     64:        if (errno == EINTR)
                     65:                continue;
                     66:        break;
                     67:   }
1.11      maekawa    68:
1.15      takayama   69:   sprintf(sss_png,"pstoimg -type png %s -out %s >/dev/null",REPL_PSFILE,REPL_IMGFILE);
                     70:   sprintf(sss_gif,"pstoimg -type gif %s -out %s >/dev/null",REPL_PSFILE,REPL_IMGFILE);
1.14      takayama   71:
                     72:   if (!system(sss_png)) {
1.4       takayama   73:        if (type == 'b') {
                     74:          printf("export OpenXM_PSTOIMG_TYPE=png\n");
                     75:        }else{
                     76:          printf("setenv OpenXM_PSTOIMG_TYPE png\n");
                     77:        }
1.14      takayama   78:   }else if (!system(sss_gif)) {
1.4       takayama   79:        if (type == 'b') {
1.5       takayama   80:          printf("OpenXM_PSTOIMG_TYPE=gif\n");
                     81:       printf("export OpenXM_PSTOIMG_TYPE\n");
1.4       takayama   82:        }else{
                     83:          printf("setenv OpenXM_PSTOIMG_TYPE=gif\n");
                     84:        }
                     85:   }else {
1.16    ! takayama   86:     if (type == 'b') {
        !            87:       printf("OpenXM_PSTOIMG_TYPE=no\n");
        !            88:       printf("export OpenXM_PSTOIMG_TYPE\n");
        !            89:     }else{
        !            90:       printf("setenv OpenXM_PSTOIMG_TYPE no\n");
        !            91:     }
1.4       takayama   92:   }
                     93:
1.12      maekawa    94:   while (unlink(REPL_IMGFILE) != 0) {
                     95:        if (errno == EINTR)
                     96:                continue;
                     97:        break;
                     98:   }
                     99:   while (unlink(REPL_PSFILE) != 0) {
                    100:        if (errno == EINTR)
                    101:                continue;
                    102:        break;
                    103:   }
1.8       maekawa   104:
1.11      maekawa   105:   exit(EXIT_SUCCESS);
1.1       takayama  106: }

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