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