~ubuntu-branches/ubuntu/breezy/koffice/breezy

« back to all changes in this revision

Viewing changes to filters/kword/latex/import/parser/texparser.lex

  • Committer: Bazaar Package Importer
  • Author(s): Ben Burton
  • Date: 2004-05-09 11:33:00 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040509113300-vfrdadqsvjfuhn3b
Tags: 1:1.3.1-1
* New upstream bugfix release.
* Built against newer imagemagick (closes: #246623).
* Made koffice-libs/kformula recommend/depend on latex-xft-fonts, which
  provides mathematical fonts that the formula editor can use.  Also
  patched the kformula part to make these fonts the default.
* Changed kword menu hint from "WordProcessors" to "Word processors"
  (closes: #246209).
* Spellchecker configuration is now fixed (closes: #221256, #227568).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Ajouter une pile contenant tout les environnements.
 
3
 *
 
4
 * To compil :
 
5
 * flex -+ -otexparser.cc texparser.lex
 
6
 * g++ -o texparser texparser.cc -lfl -lm
 
7
 *
 
8
 */
 
9
 
 
10
%{
 
11
#include <stdio.h>
 
12
#include <string.h>
 
13
#include <sys/param.h>
 
14
 
 
15
#include "stack.h"
 
16
 
 
17
/* Stack handling */
 
18
void pop(int);
 
19
void push(int);
 
20
 
 
21
int ind = 0;
 
22
 
 
23
%}
 
24
 
 
25
%x MATHMODE ENV
 
26
 
 
27
commande \\[a-zA-Z]+{param}?{option}?{group}?
 
28
 
 
29
group \{[^\{]*\}
 
30
 
 
31
option \[.*\]
 
32
 
 
33
param \(.*\)
 
34
 
 
35
b_math \\\(
 
36
e_math \\\)
 
37
math \$
 
38
 
 
39
b_env \\begin\{{letter}+\}
 
40
e_env \\end\{{letter}+\}
 
41
 
 
42
display \$\$
 
43
 
 
44
comments \%.*\n
 
45
 
 
46
ws [ \n\t]
 
47
space ({ws}|\~|\\space)
 
48
texte [^\\\n\$\%]+
 
49
 
 
50
symbol ("$"("\\"{atoz}+|.)"$"|"\\#"|"\\$"|"\\%"|"\\ref")
 
51
letter [A-Za-z]
 
52
 
 
53
%%
 
54
<INITIAL,ENV>{b_env} {
 
55
        printf("Entre dans un env. : %s\n", yytext);
 
56
        push(ENV);
 
57
        BEGIN(ENV);
 
58
}
 
59
 
 
60
<ENV>{e_env} {
 
61
        printf("Sort d'un env.\n");
 
62
        pop(ENV);
 
63
        if(stackp == 0)
 
64
                BEGIN(INITIAL);
 
65
}
 
66
 
 
67
<INITIAL,ENV>{commande} {
 
68
        printf("Commande : %s\n", yytext);
 
69
        printf("%d\n", ind);
 
70
        ind++;
 
71
}
 
72
 
 
73
<INITIAL,ENV>"\n" {
 
74
        printf("Nouvelle ligne\n");
 
75
}
 
76
 
 
77
<MATHMODE>{math} {
 
78
        printf("Sort du mode math\n");
 
79
        pop(MATH);
 
80
        BEGIN(INITIAL);
 
81
}
 
82
 
 
83
<INITIAL,ENV>{math} {
 
84
        printf("Entre dans le mode math\n");
 
85
        push(MATH);
 
86
        BEGIN(MATHMODE);
 
87
}
 
88
 
 
89
 
 
90
<INITIAL,ENV>{comments} {
 
91
        printf("commentaire : %s\n", yytext);
 
92
}
 
93
 
 
94
<INITIAL,ENV>{texte} {
 
95
        printf("texte : %s\n", yytext);
 
96
}
 
97
 
 
98
<MATHMODE>{texte} {
 
99
        printf("texte mathematique : %s\n", yytext);
 
100
}
 
101
 
 
102
%%
 
103
 
 
104
 
 
105
void push(int name)
 
106
{
 
107
        if(stackp == 0)
 
108
        {
 
109
                fprintf(stdout, "init. stack!\n");
 
110
                stack = (Stack *) malloc(stack_size * sizeof(Stack));
 
111
        }
 
112
    if ( stackp == stack_size )
 
113
        {
 
114
                /* extend stack */
 
115
                stack_size *= 2;
 
116
                stack = (Stack *) realloc(stack, stack_size * sizeof(Stack));
 
117
                if ( stack == NULL )
 
118
                {
 
119
                        fprintf(stderr, "texparser: stack out of memory");
 
120
                        exit(3);
 
121
            }
 
122
                fprintf(stdout, "%d", stack);
 
123
    }
 
124
    
 
125
    /*if ( (stack[stackp].name =
 
126
                (int *) malloc(strlen(name) + 1)) == NULL )
 
127
        {
 
128
                fprintf(stderr, "texparser: out of memory\n");
 
129
                exit(3);
 
130
    }*/
 
131
 
 
132
    stack[stackp].name = name;
 
133
        fprintf(stdout, "type added in stack : %d\n", name);
 
134
    ++stackp;
 
135
}
 
136
 
 
137
 
 
138
void pop(int name)
 
139
{
 
140
    if ( stack == 0 )
 
141
    {
 
142
        fprintf(stderr, "texparser: Stack underflow\n");
 
143
                exit(4);
 
144
    }
 
145
 
 
146
        if(stack[stackp - 1].name == name)
 
147
        {
 
148
        --stackp;
 
149
            //free(stack[stackp].name);
 
150
        }
 
151
        else
 
152
        {
 
153
                fprintf(stderr, "texparser : Bad env.\n");
 
154
        }
 
155
}
 
156