Subversion Repositories wimsdev

Rev

Rev 9618 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 9618 Rev 12226
Line 16... Line 16...
16
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
 */
17
 */
18
#include "wims.h"
18
#include "wims.h"
19
int disable_mathml;
19
int disable_mathml;
20
int mathml(char *p, int option ){
20
int mathml(char *p, int option ){
21
    if (strlen(p)==0) return 1 ;
21
  if (strlen(p)==0) return 1 ;
22
    if( mathalign_base <= 1){
22
  if( mathalign_base <= 1){
23
      internal_error(" why is wims trying mathml()?\n");
23
    internal_error(" why is wims trying mathml()?\n");
24
      return 0; // go to insmath with gifs
24
    return 0; // go to insmath with gifs
25
    }
25
  }
26
    if( disable_mathml==1 || atoi(getvar("disable_mathml"))==1) return 0;
26
  if( disable_mathml==1 || atoi(getvar("disable_mathml"))==1) return 0;
27
    if(strlen(p) > MAX_LINELEN ){ // too big ? probably too big for gifs as well ; but error signalling is better in gif-methods
27
  if(strlen(p) > MAX_LINELEN ){ // too big ? probably too big for gifs as well ; but error signalling is better in gif-methods
28
      mathalign_base = 1;// 0 or 1 position of tex_gifs
28
    mathalign_base = 1;// 0 or 1 position of tex_gifs
29
      return 0; // go to insmath with gifs
29
    return 0; // go to insmath with gifs
30
    }
30
  }
31
    //singlespace(p); // needed for check unbalanced \left\right in wims_mathml.cc --> insmath.c
31
//singlespace(p); // needed for check unbalanced \left\right in wims_mathml.cc --> insmath.c
32
    singlespace(p);
32
  singlespace(p);
33
    int my_pipe[2];
33
  int my_pipe[2];
34
    pid_t pid;
34
  pid_t pid;
35
    if(pipe(my_pipe)){// pipe could not be opened...
35
  if(pipe(my_pipe)){// pipe could not be opened...
36
      internal_error("mathml(): pipe() failure.\n");
36
    internal_error("mathml(): pipe() failure.\n");
37
      mathalign_base = 1;
37
    mathalign_base = 1;
38
      return 0; // go to insmath with gifs
38
    return 0; // go to insmath with gifs
39
    }
39
  }
40
    else
40
  else
41
    {
41
  {
42
      pid = fork();
42
    pid = fork();
43
      if (pid == (pid_t) 0){
43
    if (pid == (pid_t) 0){
44
          /*
44
          /*
45
           this buffer should probably be set to 0.5 * MAX_LINELEN : mathml is very big !
45
           this buffer should probably be set to 0.5 * MAX_LINELEN : mathml is very big !
46
           if output mathml string larger ;ERROR will be signaled by wims_mathml.
46
           if output mathml string larger ;ERROR will be signaled by wims_mathml.
47
          */
47
          */
48
          char mml_buffer[MAX_LINELEN+1];
48
      char mml_buffer[MAX_LINELEN+1];
49
          sprintf(mml_buffer, "%d", MAX_LINELEN);// int --> char
49
      sprintf(mml_buffer, "%d", MAX_LINELEN);// int --> char
50
          /* setting --tex-size argument to wims_mathml.cc */
50
          /* setting --tex-size argument to wims_mathml.cc */
51
          char mathml_tex_size[64];/*this should be a string like "250%"*/
51
      char mathml_tex_size[64];/*this should be a string like "250%"*/
52
          int texsize_list[]={20,30,50,70,90,100,120,130,150,180,220,300};
52
      int texsize_list[]={20,30,50,70,90,100,120,130,150,180,220,300};
53
          /*
53
          /*
54
          analogue to  mathfonts.c but now we talk %  and we could make any amount of changes
54
          analogue to  mathfonts.c but now we talk %  and we could make any amount of changes
55
          not limited by font-size !!
55
          not limited by font-size !!
56
          when math_with_gifs is removed from wims, we can rethink / improve this
56
          when math_with_gifs is removed from wims, we can rethink / improve this
57
          */
57
          */
58
          int idx = 5;
58
      int idx = 5;
59
          int use_js_zoom = 0;
59
      int use_js_zoom = 0;
60
          /*
60
          /*
61
          default js-zoom in mathml if disabled
61
          default js-zoom in mathml if disabled
62
          enable via adm/light
62
          enable via adm/light
63
          next code is stolen from wims.c
63
          next code is stolen from wims.c
64
          */
64
          */
65
          if(getvar("useropts") != NULL || getvar("wims_useropts") != NULL){
65
      if(getvar("useropts") != NULL || getvar("wims_useropts") != NULL){
66
            char *u;
66
        char *u;
67
            u = getvar("useropts");
67
        u = getvar("useropts");
68
            /* set via adm/light or via cookie? */
68
            /* set via adm/light or via cookie? */
69
            if(u == NULL || *u == 0){ u=getvar("wims_useropts");} /* wims_user? look into def file */
69
        if(u == NULL || *u == 0) u=getvar("wims_useropts"); /* wims_user? look into def file */
70
            if(u != NULL && *u != 0){
70
        if(u != NULL && *u != 0){
71
                if(myisdigit(u[0])){ /* 2 digit code : 12,22,32,...,92  [tex_size mathalignbase] */
71
          if(myisdigit(u[0])){ /* 2 digit code : 12,22,32,...,92  [tex_size mathalignbase] */
72
                  idx = u[0] - '0';
72
            idx = u[0] - '0';
73
                  if(idx < 0 || idx > 11){ idx = 5; } /* the default value 100% */
73
            if(idx < 0 || idx > 11) idx = 5; /* the default value 100% */
74
                }
74
          }
75
                if(myisdigit(u[2]) && u[2]!=0){
75
          if(myisdigit(u[2]) && u[2]!=0){
76
                /*
76
                /*
77
                 suppose we add 0 or 1 to useropts for using js-zoom on mathml?
77
                 suppose we add 0 or 1 to useropts for using js-zoom on mathml?
78
                 3 digitcode:  621 == fontsize idx=6 & use mathml & use zoom
78
                 3 digitcode:  621 == fontsize idx=6 & use mathml & use zoom
79
                */
79
                */
80
                  use_js_zoom = u[2] - '0';
80
             use_js_zoom = u[2] - '0';
81
                  if(use_js_zoom > 1 || use_js_zoom < 0){
81
            if(use_js_zoom > 1 || use_js_zoom < 0){
82
                      use_js_zoom = 0;
82
              use_js_zoom = 0;
83
                      /* disable js-zooming of mathml */
83
                      /* disable js-zooming of mathml */
84
                  }
-
 
85
                }
-
 
86
            }
84
            }
87
          }
85
          }
-
 
86
        }
-
 
87
      }
88
          else
88
      else
89
          { /* we take the default setting from adm/management config */
89
      { /* we take the default setting from adm/management config */
90
            idx = atoi(getvar("wims_texbasesize")) ;
90
        idx = atoi(getvar("wims_texbasesize")) ;
91
            if(idx < 0 || idx > 11){ idx = 5; } /* the default value 100% */
91
        if(idx < 0 || idx > 11){ idx = 5; } /* the default value 100% */
92
          }
92
      }
93
          /*
93
          /*
94
           check is a module wants to disable zooming (eg drag&drop or others )
94
           check is a module wants to disable zooming (eg drag&drop or others )
95
           !set disable_zoom=yes
95
           !set disable_zoom=yes
96
           if not set: disable_zoom="no"; see config.c
96
           if not set: disable_zoom="no"; see config.c
97
          */
97
          */
98
          if( strcmp( getvar("disable_zoom") , "yes" ) == 0 ){
98
      if( strcmp( getvar("disable_zoom") , "yes" ) == 0 ) use_js_zoom = 0;
99
             use_js_zoom = 0;
-
 
100
          }
-
 
101
          /* now write the "char" 100% into variable "mathml_tex_size" */
99
          /* now write the "char" 100% into variable "mathml_tex_size" */
102
          snprintf(mathml_tex_size,sizeof(mathml_tex_size),"%d%%",texsize_list[idx]);
100
      snprintf(mathml_tex_size,sizeof(mathml_tex_size),"%d%%",texsize_list[idx]);
103
          /* int --> char : added % sign (needed for mathml) [%% = escaped %] */
101
          /* int --> char : added % sign (needed for mathml) [%% = escaped %] */
104
          if(strlen(mathml_tex_size) == 0 ){ // this should not happen
102
      if(strlen(mathml_tex_size) == 0 ){ // this should not happen
105
            sprintf(mathml_tex_size,"%s","100%");
103
        sprintf(mathml_tex_size,"%s","100%");
106
            /* if it goes wrong we set 100% */
104
            /* if it goes wrong we set 100% */
107
          }
105
      }
108
          char zoom[2];
106
      char zoom[2];
109
          snprintf(zoom, 2 ,"%d",use_js_zoom);/* int --> char : "0" or "1" */
107
      snprintf(zoom, 2 ,"%d",use_js_zoom);/* int --> char : "0" or "1" */
110
/*
108
/*
111
jm.evers 30/9/2015
109
jm.evers 30/9/2015
112
 
110
 
113
FOR TESTING SYNCHRONISATION FONTSIZE HTML--MATHML
111
FOR TESTING SYNCHRONISATION FONTSIZE HTML--MATHML
114
SET DEFAULT tex-size = 100 %
112
SET DEFAULT tex-size = 100 %
115
and use a
113
and use a
116
<span style="fonst-size:1em" ><math .. > ... </math></span>
114
<span style="fonst-size:1em" ><math .. > ... </math></span>
117
in wims_mathml.y
115
in wims_mathml.y
118
 
116
 
119
zooming will be adressed (rewritten) when things are OK !!
117
zooming will be adressed (rewritten) when things are OK !!
120
since zooming is only interesting in native MathML browsers (FireFox and Gecko family)
118
since zooming is only interesting in native MathML browsers (FireFox and Gecko family)
121
the zooming could be prepared in exec.c (where mathjax is included for all other browsers)
119
the zooming could be prepared in exec.c (where mathjax is included for all other browsers)
122
by adding a zoom function and mouselistener on span element (wims_mathml.y)
120
by adding a zoom function and mouselistener on span element (wims_mathml.y)
123
 
121
 
124
see forum post of Eric Reyssat
122
see forum post of Eric Reyssat
125
http://wimsedu.info/?topic=unites-de-mesure-et-mathml/#post-3105
123
http://wimsedu.info/?topic=unites-de-mesure-et-mathml/#post-3105
126
 
124
 
127
*/
125
*/
128
          char *argv[]={"wims_mathml","--use-zoom",zoom,"--tex-size 100%","--max-mml-size",mml_buffer,"--tex-string",p,NULL};
126
      char *argv[]={"wims_mathml","--use-zoom",zoom,"--tex-size 100%","--max-mml-size",mml_buffer,"--tex-string",p,NULL};
129
          /* This is the child process. Close other end first. */
127
  /* This is the child process. Close other end first. */
130
          close(my_pipe[0]);
128
      close(my_pipe[0]);
131
          dup2(my_pipe[1], 1);  /* send stdout to the pipe */
129
      dup2(my_pipe[1], 1);  /* send stdout to the pipe */
132
          dup2(my_pipe[1], 2);  /* send stderr to the pipe */
130
      dup2(my_pipe[1], 2);  /* send stderr to the pipe */
133
          close(my_pipe[1]);
131
      close(my_pipe[1]);
134
          execv("../bin/wims_mathml",argv);
132
      execv("../bin/wims_mathml",argv);
135
          internal_error("could not execute wims_mathml\n");
133
      internal_error("could not execute wims_mathml\n");
-
 
134
      mathalign_base = 1;
-
 
135
      return 0; /* go to insmath with gifs ! */
-
 
136
    }
-
 
137
    else
-
 
138
    {
-
 
139
      if (pid < (pid_t) 0){
-
 
140
        close(my_pipe[0]);  /* close the read end of the pipe in the parent */
-
 
141
        close(my_pipe[1]);  /* close the write end of the pipe in the parent */
-
 
142
        internal_error("mathml(): fork() failure.\n");
136
          mathalign_base = 1;
143
        mathalign_base = 1;
137
          return 0; /* go to insmath with gifs ! */
144
        return 0; /* go to insmath with gifs */
138
      }
145
      }
139
      else
146
      else
140
      {
147
      {
141
          if (pid < (pid_t) 0){
-
 
142
            close(my_pipe[0]);  /* close the read end of the pipe in the parent */
-
 
143
            close(my_pipe[1]);  /* close the write end of the pipe in the parent */
-
 
144
            internal_error("mathml(): fork() failure.\n");
-
 
145
            mathalign_base = 1;
-
 
146
            return 0; /* go to insmath with gifs */
-
 
147
          }
-
 
148
          else
-
 
149
          {
-
 
150
             int status;
148
        int status;
151
            FILE *stream;
149
        FILE *stream;
152
            close(my_pipe[1]);  /* close the write end of the pipe in the parent */
150
        close(my_pipe[1]);  /* close the write end of the pipe in the parent */
153
            stream = fdopen (my_pipe[0], "r");
151
        stream = fdopen (my_pipe[0], "r");
154
            char buffer[MAX_LINELEN+1];
152
        char buffer[MAX_LINELEN+1];
155
            /* make buffer filled with 'zero/null' */
153
            /* make buffer filled with 'zero/null' */
156
            memset(buffer,'\0',MAX_LINELEN); /* or use bzero(buffer,maxsize); */
154
            memset(buffer,'\0',MAX_LINELEN); /* or use bzero(buffer,maxsize); */
157
            /* read output from program line by line */
155
            /* read output from program line by line */
158
            if (option == 1) {
156
        if (option == 1) {
159
                *p=0;
157
          *p=0;
160
                while ( fgets(buffer, MAX_LINELEN, stream) != NULL ){
158
          while ( fgets(buffer, MAX_LINELEN, stream) != NULL ){
161
                     if(strcmp(buffer,"ERROR") != 0){
159
            if(strcmp(buffer,"ERROR") != 0)
162
                      mystrncpy(p, buffer, MAX_LINELEN-1);
160
              mystrncpy(p, buffer, MAX_LINELEN-1);
163
                     }
-
 
164
                    else /* ERROR close stream; close pipe; wait for clean exit */
161
            else /* ERROR close stream; close pipe; wait for clean exit */
165
                    {
-
 
166
                  fclose (stream); /* do not know if this is really needed... but it won't hurt ? */
-
 
167
                  close(my_pipe[0]);
-
 
168
                  waitpid(pid, &status, 0);
-
 
169
                     mathalign_base=1; /* go to insmath with gifs */
-
 
170
                     return 0;
-
 
171
                    }
-
 
172
                }
-
 
173
            }
-
 
174
            else /* this will probably not used ? remove it ? */
-
 
175
            {
162
            {
176
             while ( fgets(buffer, MAX_LINELEN, stream) != NULL ){
163
              fclose (stream); /* do not know if this is really needed... but it won't hurt ? */
177
                 if(strcmp(buffer,"ERROR") != 0){
164
              close(my_pipe[0]);
178
                  output("%s", buffer);
165
              waitpid(pid, &status, 0);
-
 
166
              mathalign_base=1; /* go to insmath with gifs */
179
                 }
167
              return 0;
180
                    else
168
            }
181
                    {
169
          }
-
 
170
        }
182
                     mathalign_base=1;
171
        else /* this will probably not used ? remove it ? */
-
 
172
        {
-
 
173
          while ( fgets(buffer, MAX_LINELEN, stream) != NULL ){
-
 
174
            if(strcmp(buffer,"ERROR") != 0) output("%s", buffer);
183
                     return 0;
175
            else
184
                    }
176
            {
-
 
177
              mathalign_base=1;
185
                }
178
              return 0;
186
            }
179
            }
187
            fclose (stream);
-
 
188
            close(my_pipe[0]);
-
 
189
            waitpid(pid, &status, 0);
-
 
190
          }
180
          }
191
       }
181
        }
-
 
182
        fclose (stream);
-
 
183
        close(my_pipe[0]);
-
 
184
        waitpid(pid, &status, 0);
-
 
185
      }
192
    }
186
    }
-
 
187
  }
193
    return 1;
188
  return 1;
194
}
189
}