~ubuntu-branches/ubuntu/jaunty/luatex/jaunty

« back to all changes in this revision

Viewing changes to src/texk/web2c/luatexdir/lua/luanode.c

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Preining
  • Date: 2008-07-07 11:01:13 UTC
  • mfrom: (1.1.5 upstream) (4.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080707110113-1y7lam37zbbb7bbt
Tags: 0.28.0-1
* two new upstream releases, see the respective ANNOUCE files
* add luasocket license statement to debian/copyright
* activate the pdfluatex format
* prepare for latex based formats
  - add the ini files from TeX Live
  - add debian/formats file
  - adjust dh_installtex incantation
  the problem is that luatex dies when loading ukrhypmp.tex from 
  texlive-lang-cyrillic, but we don't want to conflict with it by now.
* policy 3.8.0, rename README.Debian-source to README.source, and add
  notes about quilt usage
* disable patch fix-pwd-inclusion (it was from svn)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: luanode.c 1013 2008-02-14 00:09:02Z oneiros $ */
 
1
/* luanode.c
 
2
   
 
3
   Copyright 2006-2008 Taco Hoekwater <taco@luatex.org>
 
4
 
 
5
   This file is part of LuaTeX.
 
6
 
 
7
   LuaTeX is free software; you can redistribute it and/or modify it under
 
8
   the terms of the GNU General Public License as published by the Free
 
9
   Software Foundation; either version 2 of the License, or (at your
 
10
   option) any later version.
 
11
 
 
12
   LuaTeX is distributed in the hope that it will be useful, but WITHOUT
 
13
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 
14
   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
 
15
   License for more details.
 
16
 
 
17
   You should have received a copy of the GNU General Public License along
 
18
   with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */
2
19
 
3
20
#include "luatex-api.h"
4
21
#include <ptexlib.h>
5
22
#include "nodes.h"
6
23
 
7
 
#undef link /* defined by cpascal.h */
 
24
static const char _svn_version[] =
 
25
    "$Id: luanode.c 1226 2008-05-02 16:11:02Z oneiros $ $URL: http://scm.foundry.supelec.fr/svn/luatex/tags/beta-0.28.0/src/texk/web2c/luatexdir/lua/luanode.c $";
 
26
 
 
27
#undef link                     /* defined by cpascal.h */
8
28
#define info(a)    fixmem[(a)].hhlh
9
29
#define link(a)    fixmem[(a)].hhrh
10
30
 
11
31
 
12
32
static char *group_code_names[] = {
13
 
  "",
14
 
  "simple",
15
 
  "hbox",
16
 
  "adjusted_hbox",
17
 
  "vbox",
18
 
  "vtop",
19
 
  "align",
20
 
  "no_align",
21
 
  "output",
22
 
  "math",
23
 
  "disc",
24
 
  "insert",
25
 
  "vcenter",
26
 
  "math_choice",
27
 
  "semi_simple",
28
 
  "math_shift",
29
 
  "math_left",
30
 
  "local_box" ,
31
 
  "split_off",
32
 
  "split_keep",
33
 
  "preamble",
34
 
  "align_set",
35
 
  "fin_row"};
36
 
 
37
 
char *pack_type_name[] = { "exactly", "additional"};
38
 
 
39
 
 
40
 
void
41
 
lua_node_filter_s (int filterid, char *extrainfo, halfword head_node, halfword *tail_node) {
42
 
  halfword ret;  
43
 
  int a;
44
 
  lua_State *L = Luas[0];
45
 
  int callback_id = callback_defined(filterid);
46
 
  if (head_node==null || vlink(head_node)==null || callback_id==0)
47
 
    return;
48
 
  lua_rawgeti(L,LUA_REGISTRYINDEX,callback_callbacks_id);
49
 
  lua_rawgeti(L,-1, callback_id);
50
 
  if (!lua_isfunction(L,-1)) {
51
 
    lua_pop(L,2);
52
 
    return;
53
 
  }
54
 
  nodelist_to_lua(L,vlink(head_node)); /* arg 1 */
55
 
  lua_pushstring(L,extrainfo);         /* arg 2 */
56
 
  if (lua_pcall(L,2,1,0) != 0) { /* no arg, 1 result */
57
 
    fprintf(stdout,"error: %s\n",lua_tostring(L,-1));
58
 
    lua_pop(L,2);
59
 
    error();
60
 
    return;
61
 
  }
62
 
  if (lua_isboolean(L,-1)) {
63
 
    if (lua_toboolean(L,-1)!=1) {
64
 
      flush_node_list(vlink(head_node));
65
 
      vlink(head_node) = null;
66
 
    }
67
 
  } else {
68
 
    a = nodelist_from_lua(L);
69
 
    vlink(head_node)= a;
70
 
  }
71
 
  lua_pop(L,2); /* result and callback container table */
72
 
  if (fix_node_lists)
73
 
        fix_node_list(head_node);
74
 
  ret = vlink(head_node); 
75
 
  if (ret!=null) {
76
 
    while (vlink(ret)!=null)
77
 
      ret=vlink(ret); 
78
 
    *tail_node=ret;
79
 
  } else {
80
 
    *tail_node=head_node;
81
 
  }
82
 
  return ;
83
 
}
84
 
 
85
 
void
86
 
lua_node_filter (int filterid, int extrainfo, halfword head_node, halfword *tail_node) {
87
 
  lua_node_filter_s(filterid, group_code_names[extrainfo], head_node, tail_node);
88
 
  return ;
89
 
}
90
 
 
91
 
 
92
 
 
93
 
halfword
94
 
lua_hpack_filter (halfword head_node, scaled size, int pack_type, int extrainfo) {
95
 
  halfword ret;  
96
 
  lua_State *L = Luas[0];
97
 
  int callback_id = callback_defined(hpack_filter_callback);
98
 
  if (head_node==null || callback_id == 0)
99
 
    return head_node;
100
 
  lua_rawgeti(L,LUA_REGISTRYINDEX,callback_callbacks_id);
101
 
  lua_rawgeti(L,-1, callback_id);
102
 
  if (!lua_isfunction(L,-1)) {
103
 
    lua_pop(L,2);
104
 
    return head_node;
105
 
  }
106
 
 
107
 
  nodelist_to_lua(L,head_node);
108
 
  lua_pushstring(L,group_code_names[extrainfo]);
109
 
  lua_pushnumber(L,size);
110
 
  lua_pushstring(L,pack_type_name[pack_type]);
111
 
  if (lua_pcall(L,4,1,0) != 0) { /* no arg, 1 result */
112
 
    fprintf(stdout,"error: %s\n",lua_tostring(L,-1));
113
 
    lua_pop(L,2);
114
 
    error();
115
 
    return head_node;
116
 
  }
117
 
  ret = head_node;
118
 
  if (lua_isboolean(L,-1)) {
119
 
    if (lua_toboolean(L,-1)!=1) {
120
 
      flush_node_list(head_node);
121
 
      ret = null;
122
 
    }
123
 
  } else {
124
 
    ret = nodelist_from_lua(L);
125
 
  }
126
 
  lua_pop(L,2); /* result and callback container table */
127
 
  /*  lua_gc(L,LUA_GCSTEP, LUA_GC_STEP_SIZE);*/
128
 
  if (fix_node_lists)
129
 
        fix_node_list(ret);
130
 
  return ret;
131
 
}
132
 
 
133
 
halfword
134
 
lua_vpack_filter (halfword head_node, scaled size, int pack_type, scaled maxd, int extrainfo) {
135
 
  halfword ret;  
136
 
  integer callback_id ; 
137
 
  lua_State *L = Luas[0];
138
 
  if (head_node==null)
139
 
        return head_node;
140
 
  if (strcmp("output",group_code_names[extrainfo])==0) {
141
 
    callback_id = callback_defined(pre_output_filter_callback);
142
 
  } else {
143
 
    callback_id = callback_defined(vpack_filter_callback);
144
 
  }
145
 
  if (callback_id==0) {
146
 
    return head_node;
147
 
  }
148
 
  lua_rawgeti(L,LUA_REGISTRYINDEX,callback_callbacks_id);
149
 
  lua_rawgeti(L,-1, callback_id);
150
 
  if (!lua_isfunction(L,-1)) {
151
 
    lua_pop(L,2);
152
 
    return head_node;
153
 
  }
154
 
  nodelist_to_lua(L,head_node);
155
 
  lua_pushstring(L,group_code_names[extrainfo]);
156
 
  lua_pushnumber(L,size);
157
 
  lua_pushstring(L,pack_type_name[pack_type]);
158
 
  lua_pushnumber(L,maxd);
159
 
  if (lua_pcall(L,5,1,0) != 0) { /* no arg, 1 result */
160
 
    fprintf(stdout,"error: %s\n",lua_tostring(L,-1));
161
 
    lua_pop(L,2);
162
 
    error();
163
 
    return head_node;
164
 
  }
165
 
  ret = head_node;
166
 
  if (lua_isboolean(L,-1)) {
167
 
    if (lua_toboolean(L,-1)!=1) {
168
 
      flush_node_list(head_node);
169
 
      ret = null;
170
 
    }
171
 
  } else {
172
 
    ret = nodelist_from_lua(L);
173
 
  }
174
 
  lua_pop(L,2); /* result and callback container table */
175
 
  /*  lua_gc(L,LUA_GCSTEP, LUA_GC_STEP_SIZE);*/
176
 
  if (fix_node_lists)
177
 
        fix_node_list(ret);
178
 
  return ret;
 
33
    "",
 
34
    "simple",
 
35
    "hbox",
 
36
    "adjusted_hbox",
 
37
    "vbox",
 
38
    "vtop",
 
39
    "align",
 
40
    "no_align",
 
41
    "output",
 
42
    "math",
 
43
    "disc",
 
44
    "insert",
 
45
    "vcenter",
 
46
    "math_choice",
 
47
    "semi_simple",
 
48
    "math_shift",
 
49
    "math_left",
 
50
    "local_box",
 
51
    "split_off",
 
52
    "split_keep",
 
53
    "preamble",
 
54
    "align_set",
 
55
    "fin_row"
 
56
};
 
57
 
 
58
char *pack_type_name[] = { "exactly", "additional" };
 
59
 
 
60
 
 
61
void
 
62
lua_node_filter_s(int filterid, char *extrainfo, halfword head_node,
 
63
                  halfword * tail_node)
 
64
{
 
65
    halfword ret;
 
66
    int a;
 
67
    lua_State *L = Luas[0];
 
68
    int callback_id = callback_defined(filterid);
 
69
    if (head_node == null || vlink(head_node) == null || callback_id == 0)
 
70
        return;
 
71
    lua_rawgeti(L, LUA_REGISTRYINDEX, callback_callbacks_id);
 
72
    lua_rawgeti(L, -1, callback_id);
 
73
    if (!lua_isfunction(L, -1)) {
 
74
        lua_pop(L, 2);
 
75
        return;
 
76
    }
 
77
    nodelist_to_lua(L, vlink(head_node));       /* arg 1 */
 
78
    lua_pushstring(L, extrainfo);       /* arg 2 */
 
79
    if (lua_pcall(L, 2, 1, 0) != 0) {   /* no arg, 1 result */
 
80
        fprintf(stdout, "error: %s\n", lua_tostring(L, -1));
 
81
        lua_pop(L, 2);
 
82
        error();
 
83
        return;
 
84
    }
 
85
    if (lua_isboolean(L, -1)) {
 
86
        if (lua_toboolean(L, -1) != 1) {
 
87
            flush_node_list(vlink(head_node));
 
88
            vlink(head_node) = null;
 
89
        }
 
90
    } else {
 
91
        a = nodelist_from_lua(L);
 
92
        vlink(head_node) = a;
 
93
    }
 
94
    lua_pop(L, 2);              /* result and callback container table */
 
95
    if (fix_node_lists)
 
96
        fix_node_list(head_node);
 
97
    ret = vlink(head_node);
 
98
    if (ret != null) {
 
99
        while (vlink(ret) != null)
 
100
            ret = vlink(ret);
 
101
        *tail_node = ret;
 
102
    } else {
 
103
        *tail_node = head_node;
 
104
    }
 
105
    return;
 
106
}
 
107
 
 
108
void
 
109
lua_node_filter(int filterid, int extrainfo, halfword head_node,
 
110
                halfword * tail_node)
 
111
{
 
112
    lua_node_filter_s(filterid, group_code_names[extrainfo], head_node,
 
113
                      tail_node);
 
114
    return;
 
115
}
 
116
 
 
117
 
 
118
 
 
119
halfword
 
120
lua_hpack_filter(halfword head_node, scaled size, int pack_type, int extrainfo)
 
121
{
 
122
    halfword ret;
 
123
    lua_State *L = Luas[0];
 
124
    int callback_id = callback_defined(hpack_filter_callback);
 
125
    if (head_node == null || callback_id == 0)
 
126
        return head_node;
 
127
    lua_rawgeti(L, LUA_REGISTRYINDEX, callback_callbacks_id);
 
128
    lua_rawgeti(L, -1, callback_id);
 
129
    if (!lua_isfunction(L, -1)) {
 
130
        lua_pop(L, 2);
 
131
        return head_node;
 
132
    }
 
133
 
 
134
    nodelist_to_lua(L, head_node);
 
135
    lua_pushstring(L, group_code_names[extrainfo]);
 
136
    lua_pushnumber(L, size);
 
137
    lua_pushstring(L, pack_type_name[pack_type]);
 
138
    if (lua_pcall(L, 4, 1, 0) != 0) {   /* no arg, 1 result */
 
139
        fprintf(stdout, "error: %s\n", lua_tostring(L, -1));
 
140
        lua_pop(L, 2);
 
141
        error();
 
142
        return head_node;
 
143
    }
 
144
    ret = head_node;
 
145
    if (lua_isboolean(L, -1)) {
 
146
        if (lua_toboolean(L, -1) != 1) {
 
147
            flush_node_list(head_node);
 
148
            ret = null;
 
149
        }
 
150
    } else {
 
151
        ret = nodelist_from_lua(L);
 
152
    }
 
153
    lua_pop(L, 2);              /* result and callback container table */
 
154
    /*  lua_gc(L,LUA_GCSTEP, LUA_GC_STEP_SIZE); */
 
155
    if (fix_node_lists)
 
156
        fix_node_list(ret);
 
157
    return ret;
 
158
}
 
159
 
 
160
halfword
 
161
lua_vpack_filter(halfword head_node, scaled size, int pack_type, scaled maxd,
 
162
                 int extrainfo)
 
163
{
 
164
    halfword ret;
 
165
    integer callback_id;
 
166
    lua_State *L = Luas[0];
 
167
    if (head_node == null)
 
168
        return head_node;
 
169
    if (strcmp("output", group_code_names[extrainfo]) == 0) {
 
170
        callback_id = callback_defined(pre_output_filter_callback);
 
171
    } else {
 
172
        callback_id = callback_defined(vpack_filter_callback);
 
173
    }
 
174
    if (callback_id == 0) {
 
175
        return head_node;
 
176
    }
 
177
    lua_rawgeti(L, LUA_REGISTRYINDEX, callback_callbacks_id);
 
178
    lua_rawgeti(L, -1, callback_id);
 
179
    if (!lua_isfunction(L, -1)) {
 
180
        lua_pop(L, 2);
 
181
        return head_node;
 
182
    }
 
183
    nodelist_to_lua(L, head_node);
 
184
    lua_pushstring(L, group_code_names[extrainfo]);
 
185
    lua_pushnumber(L, size);
 
186
    lua_pushstring(L, pack_type_name[pack_type]);
 
187
    lua_pushnumber(L, maxd);
 
188
    if (lua_pcall(L, 5, 1, 0) != 0) {   /* no arg, 1 result */
 
189
        fprintf(stdout, "error: %s\n", lua_tostring(L, -1));
 
190
        lua_pop(L, 2);
 
191
        error();
 
192
        return head_node;
 
193
    }
 
194
    ret = head_node;
 
195
    if (lua_isboolean(L, -1)) {
 
196
        if (lua_toboolean(L, -1) != 1) {
 
197
            flush_node_list(head_node);
 
198
            ret = null;
 
199
        }
 
200
    } else {
 
201
        ret = nodelist_from_lua(L);
 
202
    }
 
203
    lua_pop(L, 2);              /* result and callback container table */
 
204
    /*  lua_gc(L,LUA_GCSTEP, LUA_GC_STEP_SIZE); */
 
205
    if (fix_node_lists)
 
206
        fix_node_list(ret);
 
207
    return ret;
179
208
}
180
209
 
181
210
 
184
213
 * eTeX manual for the expected return values.
185
214
 */
186
215
 
187
 
int 
188
 
visible_last_node_type (int n) {
189
 
  int i = type(n);
190
 
  if ((i!=math_node) && (i<=unset_node))  
191
 
    return i+1;
192
 
  if (i==glyph_node)
193
 
    return -1; 
194
 
  if (i==whatsit_node && subtype(n)==local_par_node)
195
 
    return -1;  
196
 
  if (i==255)
197
 
    return -1 ; /* this is not right, probably dir nodes! */
198
 
  return last_known_node +1 ;
 
216
int visible_last_node_type(int n)
 
217
{
 
218
    int i = type(n);
 
219
    if ((i != math_node) && (i <= unset_node))
 
220
        return i + 1;
 
221
    if (i == glyph_node)
 
222
        return -1;
 
223
    if (i == whatsit_node && subtype(n) == local_par_node)
 
224
        return -1;
 
225
    if (i == 255)
 
226
        return -1;              /* this is not right, probably dir nodes! */
 
227
    return last_known_node + 1;
199
228
}
200