Menu

[b84aab]: / src / common / pproc.h  Maximize  Restore  History

Download this file

481 lines (426 with data), 10.6 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
// This file is part of SmallBASIC
//
// RTL API (Parameter's API)
//
// This program is distributed under the terms of the GPL v2.0 or later
// Download the GNU Public License (GPL) from www.gnu.org
//
// Copyright(C) 2000 Nicholas Christopoulos
/**
* @defgroup par Parameters
*/
#if !defined(_sb_proc_h)
#define _sb_proc_h
#include "common/sys.h"
#include "common/str.h"
#include "common/kw.h"
#include "common/panic.h"
#include "common/var.h"
#include "common/device.h"
#include "common/blib.h"
#include "common/sberr.h"
#include "common/smbas.h"
#if !defined(PI)
#define PI 3.14159265358979323846 /**< isn't the � ? :) @ingroup sys */
#endif
/*
* known also, as 'output' or 'method' for pv_* functions
*/
#define PV_CONSOLE 0
#define PV_FILE 1
#define PV_LOG 2
#define PV_STRING 3
#if defined(__cplusplus)
extern "C" {
#endif
#define pfree(a) { if ((a)) tmp_free((a)); }
/**< simple macro for free() @ingroup par */
#define pfree2(a,b) { pfree((a)); pfree((b)); }
/**< simple macro for free() 2 ptrs @ingroup par */
#define pfree3(a,b,c) { pfree2((a),(b)); pfree((c)); }
/**< simple macro for free() 3 ptrs @ingroup par */
#define pfree4(a,b,c,d) { pfree3((a),(b),(c)); pfree((d)); }
/**< simple macro for free() 4 ptrs @ingroup par */
/*
* low-level
*/
/**
* @ingroup exec
*
* proceed to a recursive execution-loop
*
* @note avoid to use it
*/
void bc_loop(int isf);
/**
* @ingroup exec
*
* evaluate the next expression (starting from current instruction).
* put the result on 'result' variable.
*
* @param result the variable to store the result.
*/
void eval(var_t *result);
/**
* @ingroup exec
*
* allocate stack for eval(). used only by brun().
*
* @note avoid to use it
*/
void eval_alloc_stack(void);
/**
* @ingroup exec
*
* free eval()'s stack. used only by brun().
*
* @note avoid to use it
*/
void eval_free_stack(void);
/**
* @ingroup exec
*
* sets the data-p. the data-p is used for READ/DATA commands.
* actually it is points to the next position of which the READ will use.
*/
void set_dataip(word label_id) SEC(BLIB);
#if defined(_PalmOS)
void pv_write(char *str, int method, unsigned long int handle) SEC(BIO2);
void pv_writevar(var_t *var, int method, unsigned long int handle) SEC(BIO2);
#else
/**
* @ingroup exec
*
* write a string by using a specific method
*
* @note avoid to use it
*/
void pv_write(char *str, int method, int handle) SEC(BIO2);
/**
* @ingroup exec
*
* write a variable-contents by using a specific method
*
* @note avoid to use it
*/
void pv_writevar(var_t *var, int method, int handle) SEC(BIO2);
#endif
/**
* @ingroup exec
*
* prints a variable's contents in console
*
* @param var is the variable
*/
void print_var(var_t *var) SEC(BIO2);
/**
* @ingroup exec
*
* writes a variable's contents in a file
*
* @param var is the variable
* @param handle is the file-handle
*/
void fprint_var(int handle, var_t *var) SEC(BIO2);
/**
* @ingroup exec
*
* prints a variable's contents to log-file
*
* @param var is the variable
*/
void logprint_var(var_t *var) SEC(BIO2);
/*
* Parameter's API
*
* Use these functions
*/
/**
* @ingroup par
* @typedef par_t
* Parameter structure, used in 'partables'
*/
typedef struct {
var_t *var; /**< a var_t pointer; the data */
byte prev_sep; /**< previous separator (default '\0') */
byte next_sep; /**< next separator (default '\0') */
byte flags; /**< 0x1 = its a 'byval' and the 'var' must be released */
} par_t;
/* par_t flags */
#define PAR_BYVAL 1
/**< pat_t::flags, parameter was an expression
(var = the temporary copy of the result) @ingroup par */
/*
* low-level parameters parser
*/
/**
* @ingroup par
*
* get next parameter as any-value (variable).
* moves IP to the next position.
*
* @param var the variable to copy the data
*/
void par_getvar(var_t *var) SEC(BLIB);
/**
* @ingroup par
*
* get next parameter as variable's pointer.
* moves IP to the next position.
*
* @return the var_t pointer
*/
var_t *par_getvar_ptr(void) SEC(BLIB);
/**
* @ingroup par
*
* get next parameter as string-var_t
* moves IP to the next position.
*
* @param var the variable to copy the data
*/
void par_getstr(var_t *var) SEC(BLIB);
/**
* @ingroup par
*
* get next parameter as integer
* moves IP to the next position.
*
* @return the integer
*/
var_int_t par_getint(void) SEC(BLIB);
/**
* @ingroup par
*
* get next parameter as double
* moves IP to the next position.
*
* @return the number
*/
var_num_t par_getnum(void) SEC(BLIB);
#define par_getreal() par_getnum()
/**
* @ingroup par
*
* no-error if the next byte is a separator.
* moves IP to the next position.
*
* @return the separator
*/
int par_getsep(void) SEC(BLIB);
/**
* @ingroup par
*
* no-error if the next byte is the separator ','.
* moves IP to the next position.
*/
void par_getcomma(void) SEC(BLIB);
/**
* @ingroup par
*
* no-error if the next byte is the separator '#'.
* moves IP to the next position.
*/
void par_getsharp(void) SEC(BLIB);
/**
* @ingroup par
*
* no-error if the next byte is the separator ';'.
* moves IP to the next position.
*/
void par_getsemicolon(void) SEC(BLIB);
/**
* @ingroup par
*
* get next parameter as variable-pointer of an array.
* moves IP to the next position.
*
* @return the var_t pointer
*/
var_t *par_getvarray(void) SEC(BLIB);
/**
* @ingroup par
*
* returns true if the following code is descibing one var code
* usefull for optimization
* (one var can be used by the pointer; more than one it must be evaluated)
*
* @note ignore it for now
* @return true if the following code is descibing one var code
*/
int par_isonevar(void) SEC(BLIB);
/**
* @ingroup par
*
* skip parameter.
* moves IP to the next position.
*/
void par_skip(void) SEC(BLIB);
/*
* high-level parameters parser
*/
/**
* @ingroup par
*
* builds a parameter table
*
* ptable_pp = pointer to an ptable
* valid_sep = valid separators (,;)
*
* returns the number of the parameters, OR, -1 on error
*
* YOU MUST FREE THAT TABLE BY USING par_freepartable()
* IF THERE IS AN ERROR THE CALL TO par_freepartable IS NOT NEEDED
*
* moves IP to the next position.
*
* @param ptable_pp pointer to a par_t table
* @param valid_sep the valid parameter separators
* @return on success the number of the parameters; otherwise -1
* @see par_freepartable, par_massget
*/
int par_getpartable(par_t ** ptable_pp, const char *valid_sep) SEC(BLIB);
/**
* @ingroup par
*
* frees a parameters-table
*
* @param ptable_pp pointer to a par_t table
* @param pcount the number of the parameters
* @see par_getpartable, par_massget
*/
void par_freepartable(par_t ** ptable_pp, int pcount) SEC(BLIB);
/**
* @ingroup par
*
* parsing parameters with scanf-style. returns the parameter-count or -1 (error)
*
* this is the preferred method for any command except statements.
*
<pre>
* Format:
* --------
* capital character = the parameter is required
* small character = optional parameter
*
* I = integer (int32 )
* F = double (double*)
* S = string (char* )
* P = variable's ptr (var_t* )
</pre>
*
* <b>Example</b>
*
@code
int32 i1, i2 = -1; // -1 is the default value for i2
char *s1 = NULL; // NULL is the default value for s1
var_t *v = NULL; // NULL is the default value for v
// the first integer is required, the second is optional
// the string is optional too
pc = par_massget("Iisp", &i1, &i2, &s1, &v);
if ( pc != -1 ) { // no error; also, you can use prog_error because par_massget() will call rt_raise() on error
printf("required integer = %d\n", i1);
// if there is no optional parameters, the default value will be returned
if ( i2 != -1 ) printf("optional integer found = %d\n", i2);
if ( s1 ) printf("optional string found = %s\n", s1);
if ( v ) { printf("optional variable's ptr found"); v_free(v); }
}
pfree2(s1, v);
@endcode
*
* moves IP to the next position.
*
* @param fmt the par_massget's format
* @param ... the format's parameters
* @return on success the parameter-count; otherwise -1
*/
int par_massget(const char *fmt, ...) SEC(BLIB);
/**
* @ingroup par
*
* execute a user's expression (using one variable).
* the result will be stored in 'var'.
*
* @note the keyword USE
*
* @param var the variable (the X)
* @param ip the expression's address
*/
void exec_usefunc(var_t *var, addr_t ip) SEC(BLIB); // one parameter (x)
/**
* @ingroup par
*
* execute a user's expression (using two variables).
* the result will be stored in 'var1'.
*
* @note the keyword USE
*
* @param var1 the variable (the X)
* @param var2 the variable (the Y)
* @param ip the expression's address
*/
void exec_usefunc2(var_t *var1, var_t *var2, addr_t ip) SEC(BLIB); // two
// parameters
// (x,y)
/**
* @ingroup par
*
* execute a user's expression (using three variables).
* the result will be stored in 'var1'.
*
* @note the keyword USE
*
* @param var1 the variable (the X)
* @param var2 the variable (the Y)
* @param var3 the variable (the Z)
* @param ip the expression's address
*/
void exec_usefunc3(var_t *var1, var_t *var2, var_t *var3, addr_t ip) SEC(BLIB); // three
//
// parameters
// (x,y,z)
/*
* Special parameters
*/
/**
* @ingroup par
*
* retrieve a 2D point (double).
* moves IP to the next position.
*
* @return a pt_t point structure
*/
pt_t par_getpt(void) SEC(BIO2); // get a point parameter
/**
* @ingroup par
*
* retrieve a 2D polyline (double).
* moves IP to the next position.
*
* @param poly pointer to a table of real-points
* @return on success the number of points; otherwise 0
*/
int par_getpoly(pt_t ** poly) SEC(BIO2); // get a polyline
/**
* @ingroup par
*
* retrieve a 2D point (integer).
* moves IP to the next position.
*
* @return a ipt_t point structure
*/
ipt_t par_getipt(void) SEC(BIO2);
/**
* @ingroup par
*
* retrieve a 2D polyline (integers).
* moves IP to the next position.
*
* @param poly pointer to a table of integer-points
* @return on success the number of points; otherwise 0
*/
int par_getipoly(ipt_t ** poly) SEC(BIO2); // get a polyline (integers)
#if defined(__cplusplus)
}
#endif
#endif
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.