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

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

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

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