/itexToMML

To download this project, use:
bzr branch http://golem.ph.utexas.edu/~distler/code/itexToMML/

« back to all changes in this revision

Viewing changes to itex-src/itex2MML.y

  • Committer: Jacques Distler
  • Date: 2016-08-14 21:56:27 UTC
  • Revision ID: distler@golem.ph.utexas.edu-20160814215627-s85ojfrb4unki05t
Tags: 1.5.3
itex2MML 1.5.3

Build fixes for Bison3 and Ruby.
Buffer length type: unsigned long => size_t.
Fix an issue on Windows (and possibly other) Ruby platforms.
  (Thanks to Rod McGuire and David Aaron Fendley)
Clean up itex_stringsupport.rb.
Update tests.

Show diffs side-by-side

added added

removed removed

1
 
/*             itex2MML 1.5.2
2
 
 *   itex2MML.y last modified 6/13/2014
 
1
/*             itex2MML 1.5.3
 
2
 *   itex2MML.y last modified 8/13/2016
3
3
 */
4
4
 
 
5
%parse-param {char **ret_str}
 
6
 
5
7
%{
6
8
#include <stdio.h>
7
9
#include <string.h>
16
18
#define yytext itex2MML_yytext
17
19
 
18
20
 extern int yylex ();
 
21
 int itex2MML_do_html_filter (const char * buffer, size_t length, const int forbid_markup);
19
22
 
20
23
 extern char * yytext;
21
24
 
27
30
 
28
31
 void (*itex2MML_error) (const char * msg) = itex2MML_default_error;
29
32
 
30
 
 static void yyerror (char * s)
 
33
 static void yyerror (char **ret_str, char * s)
31
34
   {
32
35
     char * msg = itex2MML_copy3 (s, " at token ", yytext);
33
36
     if (itex2MML_error)
37
40
 
38
41
 /* Note: If length is 0, then buffer is treated like a string; otherwise only length bytes are written.
39
42
  */
40
 
 static void itex2MML_default_write (const char * buffer, unsigned long length)
 
43
 static void itex2MML_default_write (const char * buffer, size_t length)
41
44
   {
42
45
     if (buffer)
43
46
       {
75
78
        return copy;
76
79
    }
77
80
 
78
 
 static void itex2MML_capture (const char * buffer, unsigned long length)
 
81
 static void itex2MML_capture (const char * buffer, size_t length)
79
82
    {
80
83
     if (buffer)
81
84
       {
82
85
         if (length)
83
86
           {
84
 
              unsigned long first_length = itex2MML_output_string ? strlen(itex2MML_output_string) : 0;
 
87
              size_t first_length = itex2MML_output_string ? strlen(itex2MML_output_string) : 0;
85
88
              char * copy  = (char *) malloc(first_length + length + 1);
86
89
              if (copy)
87
90
                {
114
117
         free(itex2MML_output_string);
115
118
       itex2MML_output_string = temp;
116
119
    }
117
 
    void (*itex2MML_write) (const char * buffer, unsigned long length) = itex2MML_capture;
 
120
    void (*itex2MML_write) (const char * buffer, size_t length) = itex2MML_capture;
118
121
    void (*itex2MML_write_mathml) (const char * mathml) = itex2MML_capture_mathml;
119
122
#else
120
 
    void (*itex2MML_write) (const char * buffer, unsigned long length) = itex2MML_default_write;
 
123
    void (*itex2MML_write) (const char * buffer, size_t length) = itex2MML_default_write;
121
124
    void (*itex2MML_write_mathml) (const char * mathml) = itex2MML_default_write_mathml;
122
125
#endif 
123
126
 
142
145
  */
143
146
 char * itex2MML_copy3 (const char * first, const char * second, const char * third)
144
147
   {
145
 
     int  first_length =  first ? strlen( first) : 0;
146
 
     int second_length = second ? strlen(second) : 0;
147
 
     int  third_length =  third ? strlen( third) : 0;
 
148
     size_t first_length =  first ? strlen( first) : 0;
 
149
     size_t second_length = second ? strlen(second) : 0;
 
150
     size_t third_length =  third ? strlen( third) : 0;
148
151
 
149
152
     char * copy = (char *) malloc(first_length + second_length + third_length + 1);
150
153
 
179
182
  */
180
183
 char * itex2MML_copy_escaped (const char * str)
181
184
   {
182
 
     unsigned long length = 0;
 
185
     size_t length = 0;
183
186
 
184
187
     const char * ptr1 = str;
185
188
 
1791
1794
 
1792
1795
%%
1793
1796
 
1794
 
char * itex2MML_parse (const char * buffer, unsigned long length)
 
1797
char * itex2MML_parse (const char * buffer, size_t length)
1795
1798
{
1796
1799
  char * mathml = 0;
1797
1800
 
1810
1813
  return mathml;
1811
1814
}
1812
1815
 
1813
 
int itex2MML_filter (const char * buffer, unsigned long length)
 
1816
int itex2MML_filter (const char * buffer, size_t length)
1814
1817
{
1815
1818
  itex2MML_setup (buffer, length);
1816
1819
  itex2MML_restart ();
1834
1837
  itex2MML_last_error = itex2MML_copy_escaped (msg);
1835
1838
}
1836
1839
 
1837
 
int itex2MML_html_filter (const char * buffer, unsigned long length)
1838
 
{
1839
 
  itex2MML_do_html_filter (buffer, length, 0);
1840
 
}
1841
 
 
1842
 
int itex2MML_strict_html_filter (const char * buffer, unsigned long length)
1843
 
{
1844
 
  itex2MML_do_html_filter (buffer, length, 1);
1845
 
}
1846
 
 
1847
 
int itex2MML_do_html_filter (const char * buffer, unsigned long length, const int forbid_markup)
 
1840
int itex2MML_html_filter (const char * buffer, size_t length)
 
1841
{
 
1842
  return itex2MML_do_html_filter (buffer, length, 0);
 
1843
}
 
1844
 
 
1845
int itex2MML_strict_html_filter (const char * buffer, size_t length)
 
1846
{
 
1847
  return itex2MML_do_html_filter (buffer, length, 1);
 
1848
}
 
1849
 
 
1850
int itex2MML_do_html_filter (const char * buffer, size_t length, const int forbid_markup)
1848
1851
{
1849
1852
  int result = 0;
1850
1853