Subversion Repositories wimsdev

Rev

Rev 5578 | Rev 7673 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5578 Rev 5595
Line 18... Line 18...
18
 
18
 
19
int mathml(char *p, int option ){
19
int mathml(char *p, int option ){
20
    if (strlen(p)==0) return 1 ;
20
    if (strlen(p)==0) return 1 ;
21
    if( mathalign_base <= 1){
21
    if( mathalign_base <= 1){
22
      internal_error(" why is wims trying mathml()?\n");
22
      internal_error(" why is wims trying mathml()?\n");
23
      return 0; // got to insmath with gifs
23
      return 0; // go to insmath with gifs
24
    }
24
    }
25
    if(strlen(p) > MAX_LINELEN ){ // too big ? probably too big for gifs as well ; but error signalling is better in gif-methods
25
    if(strlen(p) > MAX_LINELEN ){ // too big ? probably too big for gifs as well ; but error signalling is better in gif-methods
26
      mathalign_base = 1;// 0 or 1 position of tex_gifs
26
      mathalign_base = 1;// 0 or 1 position of tex_gifs
27
      return 0; // got to insmath with gifs
27
      return 0; // go to insmath with gifs
28
    }
28
    }
29
    //singlespace(p); // needed for check unbalanced \left\right in wims_mathml.cc --> insmath.c
29
    //singlespace(p); // needed for check unbalanced \left\right in wims_mathml.cc --> insmath.c
30
    singlespace(p);
30
    singlespace(p);
31
    int my_pipe[2];
31
    int my_pipe[2];
32
    pid_t pid;
32
    pid_t pid;
33
    if(pipe(my_pipe)){// pipe could not be opened...
33
    if(pipe(my_pipe)){// pipe could not be opened...
34
      internal_error("mathml(): pipe() failure.\n");
34
      internal_error("mathml(): pipe() failure.\n");
35
      mathalign_base = 1;
35
      mathalign_base = 1;
36
      return 0; // got to insmath with gifs
36
      return 0; // go to insmath with gifs
37
    }
37
    }
38
    else
38
    else
39
    {
39
    {
40
      pid = fork();
40
      pid = fork();
41
      if (pid == (pid_t) 0){
41
      if (pid == (pid_t) 0){
Line 99... Line 99...
99
          dup2(my_pipe[1], 2);  // send stderr to the pipe
99
          dup2(my_pipe[1], 2);  // send stderr to the pipe
100
          close(my_pipe[1]);
100
          close(my_pipe[1]);
101
          execv("../bin/wims_mathml",argv);
101
          execv("../bin/wims_mathml",argv);
102
          internal_error("could not execute wims_mathml\n");
102
          internal_error("could not execute wims_mathml\n");
103
          mathalign_base = 1;
103
          mathalign_base = 1;
104
          return 0; // got to insmath with gifs
104
          return 0; // go to insmath with gifs
105
      }
105
      }
106
      else
106
      else
107
      {
107
      {
108
          if (pid < (pid_t) 0){
108
          if (pid < (pid_t) 0){
109
            close(my_pipe[0]);  // close the read end of the pipe in the parent
109
            close(my_pipe[0]);  // close the read end of the pipe in the parent
110
            close(my_pipe[1]);  // close the write end of the pipe in the parent
110
            close(my_pipe[1]);  // close the write end of the pipe in the parent
111
            internal_error("mathml(): fork() failure.\n");
111
            internal_error("mathml(): fork() failure.\n");
112
            mathalign_base = 1;
112
            mathalign_base = 1;
113
            return 0; // got to insmath with gifs
113
            return 0; // go to insmath with gifs
114
          }
114
          }
115
          else
115
          else
116
          {
116
          {
-
 
117
            int status;
117
            FILE *stream;
118
            FILE *stream;
118
            close(my_pipe[1]);  // close the write end of the pipe in the parent
119
            close(my_pipe[1]);  // close the write end of the pipe in the parent
119
            stream = fdopen (my_pipe[0], "r");
120
            stream = fdopen (my_pipe[0], "r");
120
            char buffer[MAX_LINELEN+1];
121
            char buffer[MAX_LINELEN+1];
121
            // make buffer filled with 'zero/null'
122
            // make buffer filled with 'zero/null'
Line 125... Line 126...
125
                *p=0;
126
                *p=0;
126
                while ( fgets(buffer, MAX_LINELEN, stream) != NULL ){
127
                while ( fgets(buffer, MAX_LINELEN, stream) != NULL ){
127
                    if(strcmp(buffer,"ERROR") != 0){
128
                    if(strcmp(buffer,"ERROR") != 0){
128
                        mystrncpy(p, buffer, MAX_LINELEN-1);
129
                        mystrncpy(p, buffer, MAX_LINELEN-1);
129
                    }
130
                    }
130
                    else
131
                    else // ERROR close stream; close pipe; wait for clean exit
131
                    {
132
                    {
-
 
133
                        fclose (stream); // do not know if this is really needed... but it won't hurt ?
-
 
134
                        close(my_pipe[0]);
-
 
135
                        waitpid(pid, &status, 0);
132
                        mathalign_base=1;
136
                        mathalign_base=1; // go to insmath with gifs
133
                        return 0;
137
                        return 0;
134
                    }
138
                    }
135
                }
139
                }
136
            }
140
            }
137
            else
141
            else // this will probably not used ? remove it ?
138
            {
142
            {
139
                while ( fgets(buffer, MAX_LINELEN, stream) != NULL ){
143
                while ( fgets(buffer, MAX_LINELEN, stream) != NULL ){
140
                    if(strcmp(buffer,"ERROR") != 0){
144
                    if(strcmp(buffer,"ERROR") != 0){
141
                        output("%s", buffer);
145
                        output("%s", buffer);
142
                    }
146
                    }
Line 147... Line 151...
147
                    }
151
                    }
148
                }
152
                }
149
            }
153
            }
150
            fclose (stream);
154
            fclose (stream);
151
            close(my_pipe[0]);
155
            close(my_pipe[0]);
152
            int status;
-
 
153
            waitpid(pid, &status, 0);
156
            waitpid(pid, &status, 0);
154
          }
157
          }
155
       }
158
       }
156
    }
159
    }
157
    return 1;
160
    return 1;