Annotation of OpenXM/rc/repl.c, Revision 1.12
1.12 ! maekawa 1: /* $OpenXM: OpenXM/rc/repl.c,v 1.11 2003/01/17 00:41:05 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");
64: fclose(fp);
65:
1.12 ! maekawa 66: if (!system("pstoimg -type png /tmp/repl_test.ps -out /tmp/repl_test.img >/dev/null")) {
1.4 takayama 67: if (type == 'b') {
68: printf("export OpenXM_PSTOIMG_TYPE=png\n");
69: }else{
70: printf("setenv OpenXM_PSTOIMG_TYPE png\n");
71: }
1.12 ! maekawa 72: }else if (!system("pstoimg -type gif /tmp/repl_test.ps -out /tmp/repl_test.img >/dev/null")) {
1.4 takayama 73: if (type == 'b') {
1.5 takayama 74: printf("OpenXM_PSTOIMG_TYPE=gif\n");
75: printf("export OpenXM_PSTOIMG_TYPE\n");
1.4 takayama 76: }else{
77: printf("setenv OpenXM_PSTOIMG_TYPE=gif\n");
78: }
79: }else {
1.5 takayama 80: printf("OpenXM_PSTOIMG_TYPE=no\n");
81: printf("export OpenXM_PSTOIMG_TYPE\n");
1.4 takayama 82: }
83:
1.12 ! maekawa 84: while (unlink(REPL_IMGFILE) != 0) {
! 85: if (errno == EINTR)
! 86: continue;
! 87: break;
! 88: }
! 89: while (unlink(REPL_PSFILE) != 0) {
! 90: if (errno == EINTR)
! 91: continue;
! 92: break;
! 93: }
1.8 maekawa 94:
1.11 maekawa 95: exit(EXIT_SUCCESS);
1.1 takayama 96: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>