w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

scripting.h
Go to the documentation of this file.
1 /* Copyright (C) 2005-2008 by George Williams */
2 /*
3  * Redistribution and use in source and binary forms, with or without
4  * modification, are permitted provided that the following conditions are met:
5 
6  * Redistributions of source code must retain the above copyright notice, this
7  * list of conditions and the following disclaimer.
8 
9  * Redistributions in binary form must reproduce the above copyright notice,
10  * this list of conditions and the following disclaimer in the documentation
11  * and/or other materials provided with the distribution.
12 
13  * The name of the author may not be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15 
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19  * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #ifndef _SCRIPTING_H
29 #define _SCRIPTING_H
30 
31 #include "fontforgevw.h"
32 #include <setjmp.h>
33 #include <stdarg.h>
34 
35 /* If users want to write user defined scripting built-in functions they will */
36 /* need this file. The most relevant structure is the Context */
37 
38 struct dictentry {
39  char *name;
41 };
42 
43 struct dictionary {
44  struct dictentry *entries;
45  int cnt, max;
46 };
47 
48 typedef struct array {
49  int argc;
52 
53 #define TOK_MAX 256
55  tt_lparen, tt_rparen, tt_comma, tt_eos, /* eos is end of statement, semicolon, newline */
62 
65 
67 
68  tt_error = -1
69 };
70 
71 typedef struct context {
72  struct context *caller; /* The context of the script that called us */
73  Array a; /* The argument array */
74  Array **dontfree; /* Irrelevant for user defined funcs */
75  struct dictionary locals; /* Irrelevant for user defined funcs */
76  FILE *script; /* Irrelevant for user defined funcs */
77  unsigned int backedup: 1; /* Irrelevant for user defined funcs */
78  unsigned int donteval: 1; /* Irrelevant for user defined funcs */
79  unsigned int returned: 1; /* Irrelevant for user defined funcs */
80  unsigned int broken: 1; /* Irrelevant for user defined funcs */
81  char tok_text[TOK_MAX+1]; /* Irrelevant for user defined funcs */
82  enum token_type tok; /* Irrelevant for user defined funcs */
83  Val tok_val; /* Irrelevant for user defined funcs */
84  Val return_val; /* Initialized to void. If user wants */
85  /* return something set the return */
86  /* value here */
87  Val trace; /* Irrelevant for user defined funcs */
88  Val argsval; /* Irrelevant for user defined funcs */
89  char *filename; /* Irrelevant for user defined funcs */
90  int lineno; /* Irrelevant for user defined funcs */
91  int ungotch; /* Irrelevant for user defined funcs */
92  FontViewBase *curfv; /* Current fontview */
93  jmp_buf *err_env; /* place to longjump to on an error */
95 
96 void arrayfree(Array *);
97 
99 
100  /* Adds a user defined scripting function to the interpretter */
101  /* (you can't override a built-in name) */
102  /* (you can replace a previous user defined function */
103  /* Most functions will require a font to be loaded, but a few do not */
104  /* Open(), Exit(), Sin() don't. ff uses the needs_font flag to perform */
105  /* this check for you */
106  /* Returns 1 if the addition was successful, 2 if it replaced a previous func */
107  /* Returns 0 on failure (ie. if it attempts to replace a builtin function) */
109 extern int AddScriptingCommand(char *name,UserDefScriptFunc func,int needs_font);
110 
111  /* Returns whether a user defined scripting command already exists with the */
112  /* given name */
114 
115  /* Scripts used to be in latin1, and we still support that if the user sets */
116  /* an environment variable. Now scripts are by default utf8. These two funcs */
117  /* will interconvert between latin1 & utf8 if appropriate, or just make a */
118  /* utf8 copy if not. They always make a copy. */
119 extern char *utf82script_copy(const char *ustr);
120 extern char *script2utf8_copy(const char *str);
121 
122  /* Various error routines. */
123 void ScriptError( Context *c, const char *msg );
124  /* Prints an error message and exits. msg is in the script's encoding */
125 void ScriptErrorString( Context *c, const char *msg, const char *name);
126  /* Prints an error message followed by a string and exits. */
127  /* both strings are in the script's encoding */
128 void ScriptErrorF( Context *c, const char *fmt, ... );
129  /* Standard printf-style spec. All string arguments assumed to be in */
130  /* utf8 */
131 
132 extern int running_script;
133 
134 /* Hooks so a scripting dlg can execute fontforge's legacy scripting language */
135 extern void ff_VerboseCheck(void);
136 extern enum token_type ff_NextToken(Context *c);
137 extern void ff_backuptok(Context *c);
138 extern void ff_statement(Context*);
139 
140 #endif /* _SCRIPTING_H */
#define width(a)
Definition: aptex-macros.h:198
#define name
#define height(a)
Definition: aptex-macros.h:200
Definition: Array.h:29
static void
Definition: fpif.c:118
#define c(n)
Definition: gpos-common.c:150
UserDefScriptFunc HasUserScriptingCommand(char *name)
void FontImage(SplineFont *sf, char *filename, Array *arr, int width, int height)
int running_script
char * utf82script_copy(const char *ustr)
void ScriptErrorString(Context *c, const char *msg, const char *name)
void ff_statement(Context *)
char * script2utf8_copy(const char *str)
void ff_backuptok(Context *c)
void ScriptErrorF(Context *c, const char *fmt,...)
struct array Array
#define TOK_MAX
Definition: scripting.h:53
void arrayfree(Array *)
void(* UserDefScriptFunc)(Context *)
Definition: scripting.h:108
void ff_VerboseCheck(void)
enum token_type ff_NextToken(Context *c)
int AddScriptingCommand(char *name, UserDefScriptFunc func, int needs_font)
void ScriptError(Context *c, const char *msg)
struct context Context
token_type
Definition: scripting.h:54
@ tt_muleq
Definition: scripting.h:60
@ tt_if
Definition: scripting.h:63
@ tt_comma
Definition: scripting.h:55
@ tt_endloop
Definition: scripting.h:63
@ tt_eos
Definition: scripting.h:55
@ tt_eq
Definition: scripting.h:59
@ tt_gt
Definition: scripting.h:59
@ tt_eof
Definition: scripting.h:66
@ tt_foreach
Definition: scripting.h:63
@ tt_rbracket
Definition: scripting.h:56
@ tt_mul
Definition: scripting.h:58
@ tt_minuseq
Definition: scripting.h:60
@ tt_ne
Definition: scripting.h:59
@ tt_not
Definition: scripting.h:57
@ tt_pluseq
Definition: scripting.h:60
@ tt_break
Definition: scripting.h:64
@ tt_return
Definition: scripting.h:64
@ tt_or
Definition: scripting.h:58
@ tt_unicode
Definition: scripting.h:54
@ tt_shift
Definition: scripting.h:64
@ tt_lt
Definition: scripting.h:59
@ tt_diveq
Definition: scripting.h:60
@ tt_ge
Definition: scripting.h:59
@ tt_while
Definition: scripting.h:63
@ tt_modeq
Definition: scripting.h:60
@ tt_le
Definition: scripting.h:59
@ tt_else
Definition: scripting.h:63
@ tt_div
Definition: scripting.h:58
@ tt_decr
Definition: scripting.h:61
@ tt_xor
Definition: scripting.h:58
@ tt_lparen
Definition: scripting.h:55
@ tt_minus
Definition: scripting.h:57
@ tt_rparen
Definition: scripting.h:55
@ tt_bitor
Definition: scripting.h:58
@ tt_bitand
Definition: scripting.h:58
@ tt_name
Definition: scripting.h:54
@ tt_plus
Definition: scripting.h:57
@ tt_elseif
Definition: scripting.h:63
@ tt_assign
Definition: scripting.h:60
@ tt_bitnot
Definition: scripting.h:57
@ tt_number
Definition: scripting.h:54
@ tt_and
Definition: scripting.h:58
@ tt_string
Definition: scripting.h:54
@ tt_lbracket
Definition: scripting.h:56
@ tt_mod
Definition: scripting.h:58
@ tt_error
Definition: scripting.h:68
@ tt_endif
Definition: scripting.h:63
@ tt_incr
Definition: scripting.h:61
@ tt_real
Definition: scripting.h:54
@ tt_colon
Definition: scripting.h:57
static luaL_Reg func[]
Definition: except.c:32
char * filename[256]
Definition: pbmtopk.c:46
#define str(s)
Definition: sh6.c:399
int argc
Definition: scripting.h:49
Val * vals
Definition: scripting.h:50
Val argsval
Definition: scripting.h:88
jmp_buf * err_env
Definition: scripting.h:93
enum token_type tok
Definition: scripting.h:82
Val tok_val
Definition: scripting.h:83
int ungotch
Definition: scripting.h:91
Val return_val
Definition: scripting.h:84
char * filename
Definition: scripting.h:89
unsigned int broken
Definition: scripting.h:80
unsigned int donteval
Definition: scripting.h:78
FILE * script
Definition: scripting.h:76
int lineno
Definition: scripting.h:90
struct dictionary locals
Definition: scripting.h:75
Val trace
Definition: scripting.h:87
struct context * caller
Definition: scripting.h:72
unsigned int returned
Definition: scripting.h:79
char tok_text[256+1]
Definition: scripting.h:81
FontViewBase * curfv
Definition: scripting.h:92
Array ** dontfree
Definition: scripting.h:74
unsigned int backedup
Definition: scripting.h:77
Array a
Definition: scripting.h:73
char * name
Definition: scripting.h:39
Val val
Definition: scripting.h:40
struct dictentry * entries
Definition: scripting.h:44
Definition: texview.c:48
Definition: tfmaux.c:31
Definition: strexpr.c:21
#define FILE
Definition: t1stdio.h:34
char fmt[256]
Definition: tex4ht.c:3925