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