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

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

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

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