Subversion Repositories wimsdev

Rev

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

Rev 5595 Rev 7673
Line 1... Line 1...
1
/*    Copyright (C) 2012 WIMSDEV
1
/*    Copyright (C) 2012 WIMSDEV
2
 *    This file is part of the WIMS package.
2
 *    This file is part of the WIMS package.
3
 *
3
 *
4
 *  This program is free software; you can redistribute it and/or modify
4
 *  This program is free software; you can redistribute it and/or modify
5
 *  it under the terms of the GNU General Public License as published by
5
 *  it under the terms of the GNU General Public License as published by
6
 *  the Free Software Foundation; either version 2 of the License, or
6
 *  the Free Software Foundation; either version 2 of the License, or
Line 42... Line 42...
42
          // this buffer should probably be set to 0.5 * MAX_LINELEN : mathml is very big !
42
          // this buffer should probably be set to 0.5 * MAX_LINELEN : mathml is very big !
43
          // if output mathml string larger ;ERROR will be signaled by wims_matml.
43
          // if output mathml string larger ;ERROR will be signaled by wims_matml.
44
          char mml_buffer[MAX_LINELEN+1];
44
          char mml_buffer[MAX_LINELEN+1];
45
          sprintf(mml_buffer, "%d", MAX_LINELEN);// int --> char
45
          sprintf(mml_buffer, "%d", MAX_LINELEN);// int --> char
46
          // setting --tex-size argument to wims_mathml.cc
46
          // setting --tex-size argument to wims_mathml.cc
47
          char mathml_tex_size[64];//this should be a string like "250%" 
47
          char mathml_tex_size[64];//this should be a string like "250%"
48
          int texsize_list[]={20,30,50,70,90,100,120,130,150,180,220,300};
48
          int texsize_list[]={20,30,50,70,90,100,120,130,150,180,220,300};
49
          // analogue to  mathfonts.c but now we talk %  and we could make any amount of changes
49
          // analogue to  mathfonts.c but now we talk %  and we could make any amount of changes
50
          // not limited by font-size !! 
50
          // not limited by font-size !!
51
          // when math_with_gifs is removed from wims, we can rethink / improve this 
51
          // when math_with_gifs is removed from wims, we can rethink / improve this
52
          int idx = 6;
52
          int idx = 6;
53
          int use_js_zoom = 0; // default js-zoom in mathml if disabled
53
          int use_js_zoom = 0; // default js-zoom in mathml if disabled
54
          // enable via adm/light
54
          // enable via adm/light
55
          // next code is stolen from wims.c 
55
          // next code is stolen from wims.c
56
          if(getvar("useropts") != NULL || getvar("wims_useropts") != NULL){
56
          if(getvar("useropts") != NULL || getvar("wims_useropts") != NULL){
57
            char *u;
57
            char *u;
58
            u = getvar("useropts"); // set via adm/light or via cookie?
58
            u = getvar("useropts"); // set via adm/light or via cookie?
59
            if(u == NULL || *u == 0){ u=getvar("wims_useropts");} // wims_user? look into def file
59
            if(u == NULL || *u == 0){ u=getvar("wims_useropts");} // wims_user? look into def file
60
            if(u != NULL && *u != 0){
60
            if(u != NULL && *u != 0){
61
                if(myisdigit(u[0])){ //2 digit code : 12,22,32,...,92  [tex_size mathalignbase] 
61
                if(myisdigit(u[0])){ //2 digit code : 12,22,32,...,92  [tex_size mathalignbase]
62
                  idx = u[0] - '0';
62
                  idx = u[0] - '0';
63
                  if(idx < 0 || idx > 11){ idx = 6; } // the default value 120%
63
                  if(idx < 0 || idx > 11){ idx = 6; } // the default value 120%
64
                }
64
                }
65
                if(myisdigit(u[2]) && u[2]!=0){ // suppose we add 0 or 1 to useropts for using js-zoom on mathml?
65
                if(myisdigit(u[2]) && u[2]!=0){ // suppose we add 0 or 1 to useropts for using js-zoom on mathml?
66
                // 3 digitcode:  621 == fontsize idx=6 & use mathml & use zoom
66
                // 3 digitcode:  621 == fontsize idx=6 & use mathml & use zoom
Line 78... Line 78...
78
          }
78
          }
79
          // check is a module wants to disable zooming (eg drag&drop or others )
79
          // check is a module wants to disable zooming (eg drag&drop or others )
80
          // !set disable_zoom=yes
80
          // !set disable_zoom=yes
81
          // if not set: disable_zoom="no"; see config.c
81
          // if not set: disable_zoom="no"; see config.c
82
          if( strcmp( getvar("disable_zoom") , "yes" ) == 0 ){
82
          if( strcmp( getvar("disable_zoom") , "yes" ) == 0 ){
83
            use_js_zoom = 0;
83
             use_js_zoom = 0;
84
          }
84
          }
85
          // now write the "char" 200% into variable "mathml_tex_size"
85
          // now write the "char" 200% into variable "mathml_tex_size"
86
          snprintf(mathml_tex_size,sizeof(mathml_tex_size),"%d%%",texsize_list[idx]);
86
          snprintf(mathml_tex_size,sizeof(mathml_tex_size),"%d%%",texsize_list[idx]);
87
          // int --> char : added % sign (needed for mathml) [%% = escaped %]
87
          // int --> char : added % sign (needed for mathml) [%% = escaped %]
88
          if(mathml_tex_size == NULL || strlen(mathml_tex_size) == 0 ){ // this should not happen
88
          if(mathml_tex_size == NULL || strlen(mathml_tex_size) == 0 ){ // this should not happen
89
            sprintf(mathml_tex_size,"%s","120%");
89
            sprintf(mathml_tex_size,"%s","120%");
90
            // if it goes wrong we set 120% 
90
            // if it goes wrong we set 120%
91
            // default in itex2MML was 110% : but we thought it was too small... ?
91
            // default in itex2MML was 110% : but we thought it was too small... ?
92
          }
92
          }
93
          char zoom[2];
93
          char zoom[2];
94
          snprintf(zoom, 2 ,"%d",use_js_zoom);// int --> char : "0" or "1"
94
          snprintf(zoom, 2 ,"%d",use_js_zoom);// int --> char : "0" or "1"
95
          char *argv[]={"wims_mathml","--use-zoom",zoom,"--tex-size",mathml_tex_size,"--max-mml-size",mml_buffer,"--tex-string",p,NULL};
95
          char *argv[]={"wims_mathml","--use-zoom",zoom,"--tex-size",mathml_tex_size,"--max-mml-size",mml_buffer,"--tex-string",p,NULL};
Line 112... Line 112...
112
            mathalign_base = 1;
112
            mathalign_base = 1;
113
            return 0; // go to insmath with gifs
113
            return 0; // go to insmath with gifs
114
          }
114
          }
115
          else
115
          else
116
          {
116
          {
117
            int status;
117
             int status;
118
            FILE *stream;
118
            FILE *stream;
119
            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
120
            stream = fdopen (my_pipe[0], "r");
120
            stream = fdopen (my_pipe[0], "r");
121
            char buffer[MAX_LINELEN+1];
121
            char buffer[MAX_LINELEN+1];
122
            // make buffer filled with 'zero/null'
122
            // make buffer filled with 'zero/null'
123
            memset(buffer,'\0',MAX_LINELEN);//bzero(buffer,maxsize);
123
            memset(buffer,'\0',MAX_LINELEN);//bzero(buffer,maxsize);
124
            /* read output from program line by line*/
124
            /* read output from program line by line*/
125
            if (option == 1) {
125
            if (option == 1) {
126
                *p=0;
126
                *p=0;
127
                while ( fgets(buffer, MAX_LINELEN, stream) != NULL ){
127
                while ( fgets(buffer, MAX_LINELEN, stream) != NULL ){
128
                    if(strcmp(buffer,"ERROR") != 0){
128
                     if(strcmp(buffer,"ERROR") != 0){
129
                        mystrncpy(p, buffer, MAX_LINELEN-1);
129
                      mystrncpy(p, buffer, MAX_LINELEN-1);
130
                    }
130
                     }
131
                    else // ERROR close stream; close pipe; wait for clean exit
131
                    else // ERROR close stream; close pipe; wait for clean exit
132
                    {
132
                    {
133
                        fclose (stream); // do not know if this is really needed... but it won't hurt ?
133
                  fclose (stream); // do not know if this is really needed... but it won't hurt ?
134
                        close(my_pipe[0]);
134
                  close(my_pipe[0]);
135
                        waitpid(pid, &status, 0);
135
                  waitpid(pid, &status, 0);
136
                        mathalign_base=1; // go to insmath with gifs
136
                     mathalign_base=1; // go to insmath with gifs
137
                        return 0;
137
                     return 0;
138
                    }
138
                    }
139
                }
139
                }
140
            }
140
            }
141
            else // this will probably not used ? remove it ?
141
            else // this will probably not used ? remove it ?
142
            {
142
            {
143
                while ( fgets(buffer, MAX_LINELEN, stream) != NULL ){
143
             while ( fgets(buffer, MAX_LINELEN, stream) != NULL ){
144
                    if(strcmp(buffer,"ERROR") != 0){
144
                 if(strcmp(buffer,"ERROR") != 0){
145
                        output("%s", buffer);
145
                  output("%s", buffer);
146
                    }
146
                 }
147
                    else
147
                    else
148
                    {
148
                    {
149
                        mathalign_base=1;
149
                     mathalign_base=1;
150
                        return 0;
150
                     return 0;
151
                    }
151
                    }
152
                }
152
                }
153
            }
153
            }
154
            fclose (stream);
154
            fclose (stream);
155
            close(my_pipe[0]);
155
            close(my_pipe[0]);