3 MPSL - Minimum Profit Scripting Language
4 Copyright (C) 2003/2006 Angel Ortega <angel@triptico.com>
6 mpsl_f.c - Minimum Profit Scripting Language Function Library
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 http://www.triptico.com
41 #define A(n) mpdm_aget(a, n)
45 #define IA(n) mpdm_ival(A(n))
50 static mpdm_t
F_size(mpdm_t a
) { return(MPDM_I(mpdm_size(A0
))); }
51 static mpdm_t
F_clone(mpdm_t a
) { return(mpdm_clone(A0
)); }
52 static mpdm_t
F_dump(mpdm_t a
) { mpdm_dump(A0
); return(NULL
); }
53 static mpdm_t
F_cmp(mpdm_t a
) { return(MPDM_I(mpdm_cmp(A0
, A1
))); }
55 static mpdm_t
F_is_array(mpdm_t a
) { return(mpsl_boolean(MPDM_IS_ARRAY(A0
))); }
56 static mpdm_t
F_is_hash(mpdm_t a
) { return(mpsl_boolean(MPDM_IS_HASH(A0
))); }
57 static mpdm_t
F_is_exec(mpdm_t a
) { return(mpsl_boolean(MPDM_IS_EXEC(A0
))); }
59 static mpdm_t
F_splice(mpdm_t a
) { return(mpdm_splice(A0
,A1
,IA2
,IA3
)); }
60 static mpdm_t
F_expand(mpdm_t a
) { return(mpdm_expand(A0
,IA1
,IA2
)); }
61 static mpdm_t
F_collapse(mpdm_t a
) { return(mpdm_collapse(A0
,IA1
,IA2
)); }
62 static mpdm_t
F_ins(mpdm_t a
) { return(mpdm_ins(A0
,A1
,IA2
)); }
63 static mpdm_t
F_adel(mpdm_t a
) { return(mpdm_adel(A0
,IA1
)); }
64 static mpdm_t
F_shift(mpdm_t a
) { return(mpdm_shift(A0
)); }
65 static mpdm_t
F_push(mpdm_t a
) { return(mpdm_push(A0
,A1
)); }
66 static mpdm_t
F_pop(mpdm_t a
) { return(mpdm_pop(A0
)); }
67 static mpdm_t
F_queue(mpdm_t a
) { return(mpdm_queue(A0
,A1
,IA2
)); }
68 static mpdm_t
F_seek(mpdm_t a
) { return(MPDM_I(mpdm_seek(A0
,A1
,IA2
))); }
69 static mpdm_t
F_sort(mpdm_t a
) { return(mpdm_sort_cb(A0
,1,A1
)); }
70 static mpdm_t
F_split(mpdm_t a
) { return(mpdm_split(A0
,A1
)); }
71 static mpdm_t
F_join(mpdm_t a
) { return(mpdm_join(A0
,A1
)); }
73 static mpdm_t
F_hsize(mpdm_t a
) { return(MPDM_I(mpdm_hsize(A0
))); }
74 static mpdm_t
F_exists(mpdm_t a
) { return(mpsl_boolean(mpdm_exists(A0
, A1
))); }
75 static mpdm_t
F_hdel(mpdm_t a
) { return(mpdm_hdel(A0
, A1
)); }
76 static mpdm_t
F_keys(mpdm_t a
) { return(mpdm_keys(A0
)); }
78 static mpdm_t
F_open(mpdm_t a
) { return(mpdm_open(A0
, A1
)); }
79 static mpdm_t
F_close(mpdm_t a
) { return(mpdm_close(A0
)); }
80 static mpdm_t
F_read(mpdm_t a
) { return(mpdm_read(A0
)); }
81 static mpdm_t
F_write(mpdm_t a
) { return(mpsl_boolean(mpdm_write(A0
,A1
))); }
82 static mpdm_t
F_unlink(mpdm_t a
) { return(mpsl_boolean(mpdm_unlink(A0
))); }
83 static mpdm_t
F_glob(mpdm_t a
) { return(mpdm_glob(A0
)); }
84 static mpdm_t
F_encoding(mpdm_t a
) { return(MPDM_I(mpdm_encoding(A0
))); }
86 static mpdm_t
F_regex(mpdm_t a
) { return(mpdm_regex(A0
,A1
,IA2
)); }
87 static mpdm_t
F_sregex(mpdm_t a
) { return(mpdm_sregex(A0
,A1
,A2
,IA3
)); }
89 static mpdm_t
F_gettext(mpdm_t a
) { return(mpdm_gettext(A0
)); }
90 static mpdm_t
F_gettext_domain(mpdm_t a
) { return(MPDM_I(mpdm_gettext_domain(A0
, A1
))); }
92 static mpdm_t
F_load(mpdm_t a
) { return(mpdm_exec(mpsl_compile_file(A0
), NULL
)); }
93 static mpdm_t
F_error(mpdm_t a
) { return(mpsl_error(A0
)); }
95 static mpdm_t
F_eval(mpdm_t a
)
102 return(mpsl_eval(c
, a
));
105 static mpdm_t
F_print(mpdm_t a
)
109 for(n
= 0;n
< mpdm_size(a
);n
++)
110 mpdm_write_wcs(stdout
, mpdm_string(A(n
)));
118 mpdm_t (* func
)(mpdm_t
);
122 { L
"clone", F_clone
},
125 { L
"is_array", F_is_array
},
126 { L
"is_hash", F_is_hash
},
127 { L
"is_exec", F_is_exec
},
128 { L
"splice", F_splice
},
129 { L
"expand", F_expand
},
130 { L
"collapse", F_collapse
},
133 { L
"shift", F_shift
},
136 { L
"queue", F_queue
},
139 { L
"split", F_split
},
141 { L
"hsize", F_hsize
},
142 { L
"exists", F_exists
},
146 { L
"close", F_close
},
148 { L
"write", F_write
},
149 { L
"unlink", F_unlink
},
151 { L
"encoding", F_encoding
},
152 { L
"regex", F_regex
},
153 { L
"sregex", F_sregex
},
155 { L
"error", F_error
},
157 { L
"print", F_print
},
158 { L
"gettext", F_gettext
},
159 { L
"gettext_domain", F_gettext_domain
},
165 * mpsl_argv - Fills the ARGV global array.
166 * @argc: number of arguments
167 * @argv: array of string values
169 * Fills the ARGV global MPSL array with an array of arguments. These
170 * are usually the ones sent to main().
172 void mpsl_argv(int argc
, char * argv
[])
177 /* create the ARGV array */
180 for(n
= 0;n
< argc
;n
++)
181 mpdm_push(ARGV
, MPDM_MBS(argv
[n
]));
183 mpdm_hset_s(mpdm_root(), L
"ARGV", ARGV
);
188 mpdm_t
mpsl_build_opcodes(void);
192 * mpsl_startup - Initializes MPSL.
194 * Initializes the Minimum Profit Scripting Language. Returns 0 if
195 * everything went OK.
197 int mpsl_startup(void)
209 /* creates all the symbols in the CORE library */
211 for(n
= 0;mpsl_funcs
[n
].name
!= NULL
;n
++)
213 mpdm_t f
= MPDM_S(mpsl_funcs
[n
].name
);
214 mpdm_t x
= MPDM_X(mpsl_funcs
[n
].func
);
220 /* creates INC, unless already defined */
221 if(mpdm_hget_s(r
, L
"INC") == NULL
)
222 mpdm_hset_s(r
, L
"INC", MPDM_A(0));
225 mpdm_hset_s(r
, L
"TRUE", MPDM_I(1));
227 /* standard file descriptors */
228 mpdm_hset_s(r
, L
"STDIN", MPDM_F(stdin
));
229 mpdm_hset_s(r
, L
"STDOUT", MPDM_F(stdout
));
230 mpdm_hset_s(r
, L
"STDERR", MPDM_F(stderr
));
232 /* fill now the MPSL hash */
234 mpdm_hset_s(r
, L
"MPSL", m
);
236 /* store things there */
237 mpdm_hset_s(m
, L
"VERSION", MPDM_MBS(VERSION
));
238 mpdm_hset_s(m
, L
"OPCODE", mpsl_build_opcodes());
239 mpdm_hset_s(m
, L
"LOCAL", MPDM_A(0));
240 mpdm_hset_s(m
, L
"CORE", c
);
247 * mpsl_shutdown - Shuts down MPSL.
249 * Shuts down MPSL. No MPSL functions should be used from now on.
251 void mpsl_shutdown(void)