Skip to content

Commit 9ac0382

Browse files
committed
COMMON: Unitfy HASH and UDS
1 parent fab4bba commit 9ac0382

File tree

14 files changed

+71
-425
lines changed

14 files changed

+71
-425
lines changed

src/common/Makefile.am

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ libsb_common_a_SOURCES = \
7878
str.c str.h \
7979
tasks.c tasks.h \
8080
search.c search.h \
81-
var_uds.c var_uds.h \
8281
var_hash.c var_hash.h \
8382
keymap.c keymap.h \
8483
units.c units.h \

src/common/bc.c

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -227,39 +227,30 @@ void bc_add_strn(bc_t *bc, const char *str, int len) {
227227
*/
228228
char *bc_store_string(bc_t *bc, char *src) {
229229
char *p = src;
230-
char *np = 0;
230+
char *np = NULL;
231231
char *base = src + 1;
232-
int l = 0; // total length
233-
int seglen = 0; // length of segment between escapes
232+
int len = 0;
234233

235-
p++; // == '\"'
234+
// skip past opening quotes
235+
p++;
236236
while (*p) {
237237
if (*p == '\\' && ((*(p + 1) == '\"') || *(p + 1) == '\\')) {
238238
// escaped quote " or escaped escape
239-
seglen = p - base;
240-
np = np ? tmp_realloc(np, l + seglen + 1) : tmp_alloc(seglen + 1);
241-
strncpy(np + l, base, seglen);
242-
l += seglen; // add next segment
243-
np[l] = 0;
244-
base = ++p; // include " (or \ ) in next segment
239+
int seglen = p - base;
240+
np = np ? tmp_realloc(np, len + seglen + 1) : tmp_alloc(seglen + 1);
241+
strncpy(np + len, base, seglen);
242+
// add next segment
243+
len += seglen;
244+
np[len] = 0;
245+
// include " (or \ ) in next segment
246+
base = ++p;
245247
} else if (*p == '\"') {
246248
// end of string detected
247-
seglen = p - base;
248-
np = np ? tmp_realloc(np, l + seglen + 1) : tmp_alloc(seglen + 1);
249-
strncpy(np + l, base, seglen);
250-
np[l + seglen] = 0;
251-
if (opt_cstr) {
252-
// c-style special char syntax
253-
char *cstr;
254-
cstr = cstrdup(np);
255-
tmp_free(np);
256-
bc_add_strn(bc, cstr, strlen(cstr));
257-
tmp_free(cstr);
258-
} else {
259-
// normal
260-
bc_add_strn(bc, np, strlen(np));
261-
tmp_free(np);
262-
}
249+
int seglen = p - base;
250+
np = np ? tmp_realloc(np, len + seglen + 1) : tmp_alloc(seglen + 1);
251+
memcpy(np + len, base, seglen);
252+
bc_add_strn(bc, np, len + seglen);
253+
tmp_free(np);
263254
p++;
264255
return p;
265256
}
@@ -299,10 +290,7 @@ char *bc_store_macro(bc_t *bc, char *src) {
299290
* adds an EOC mark at the current position
300291
*/
301292
void bc_eoc(bc_t *bc) {
302-
// if ( bc->count ) {
303-
// if ( bc->ptr[bc->count-1] != kwTYPE_EOC )
304293
bc_add1(bc, kwTYPE_EOC);
305-
// }
306294
}
307295

308296
/*

src/common/blib.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include "common/kw.h"
1212
#include "common/var.h"
1313
#include "common/var_hash.h"
14-
#include "common/var_uds.h"
1514
#include "common/device.h"
1615
#include "common/blib.h"
1716
#include "common/pproc.h"
@@ -1752,10 +1751,6 @@ void cmd_for() {
17521751
var_elem_ptr = hash_elem(array_p, 0);
17531752
break;
17541753

1755-
case V_UDS:
1756-
var_elem_ptr = uds_elem(array_p, 0);
1757-
break;
1758-
17591754
case V_ARRAY:
17601755
if (array_p->v.a.size > 0) {
17611756
var_elem_ptr = v_elem(array_p, 0);
@@ -1950,11 +1945,6 @@ void cmd_next() {
19501945
var_elem_ptr = hash_elem(array_p, node.x.vfor.step_expr_ip);
19511946
break;
19521947

1953-
case V_UDS:
1954-
node.x.vfor.step_expr_ip++; // element-index
1955-
var_elem_ptr = uds_elem(array_p, node.x.vfor.step_expr_ip);
1956-
break;
1957-
19581948
case V_ARRAY:
19591949
node.x.vfor.step_expr_ip++; // element-index
19601950

src/common/brun.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include "common/messages.h"
2525
#include "common/device.h"
2626
#include "common/pproc.h"
27-
#include "common/var_uds.h"
2827

2928
int brun_create_task(const char *filename, mem_t preloaded_bc, int libf);
3029
int exec_close_task();

src/common/eval.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,6 @@ static inline void eval_var(var_t *r, var_t *var_p) {
670670
v_set(r, var_p);
671671
break;
672672
case V_ARRAY:
673-
case V_UDS:
674673
case V_HASH:
675674
v_set(r, var_p);
676675
break;
@@ -1146,13 +1145,7 @@ void eval(var_t *r) {
11461145
case kwTYPE_STR:
11471146
// string - constant
11481147
V_FREE(r);
1149-
r->type = V_STR;
1150-
len = code_getstrlen();
1151-
r->v.p.ptr = tmp_alloc(len + 1);
1152-
memcpy(r->v.p.ptr, &prog_source[prog_ip], len);
1153-
*((char *) (r->v.p.ptr + len)) = '\0';
1154-
r->v.p.size = len;
1155-
IP += len;
1148+
v_eval_str(r);
11561149
break;
11571150

11581151
case kwTYPE_PTR:

src/common/hotspots.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
//
88
// Copyright(C) 2014 Chris Warren-Smith
99

10-
#include "common/var_uds.h"
1110
#include "common/var_hash.h"
1211

1312
void err_evsyntax(void);
@@ -83,8 +82,6 @@ static inline var_num_t code_getnext128f() {
8382
*/
8483
static inline var_num_t v_getval(var_t *v) {
8584
switch (v ? v->type : -1) {
86-
case V_UDS:
87-
return uds_to_int(v);
8885
case V_HASH:
8986
return hash_to_int(v);
9087
case V_PTR:
@@ -118,8 +115,6 @@ static inline var_num_t v_getval(var_t *v) {
118115
*/
119116
static inline var_int_t v_igetval(var_t *v) {
120117
switch (v ? v->type : -1) {
121-
case V_UDS:
122-
return uds_to_int(v);
123118
case V_HASH:
124119
return hash_to_int(v);
125120
case V_PTR:

src/common/proc.c

Lines changed: 46 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include "common/sys.h"
1111
#include "common/pproc.h"
1212
#include "common/messages.h"
13-
#include "common/var_uds.h"
1413
#include "common/var_hash.h"
1514
#include <limits.h>
1615

@@ -261,6 +260,51 @@ void pv_write(char *str, int method, int handle) {
261260
}
262261
}
263262

263+
/*
264+
* print the array variable
265+
*/
266+
void pv_write_array(var_t *var, int method, int handle) {
267+
pv_write("[", method, handle);
268+
269+
if (var->v.a.maxdim == 2) {
270+
int rows, cols;
271+
var_t *e;
272+
int i, j, pos;
273+
274+
// NxN
275+
rows = ABS(var->v.a.ubound[0] - var->v.a.lbound[0]) + 1;
276+
cols = ABS(var->v.a.ubound[1] - var->v.a.lbound[1]) + 1;
277+
278+
for (i = 0; i < rows; i++) {
279+
for (j = 0; j < cols; j++) {
280+
pos = i * cols + j;
281+
e = (var_t *) (var->v.a.ptr + (sizeof(var_t) * pos));
282+
pv_writevar(e, method, handle);
283+
if (j != cols - 1) {
284+
pv_write(",", method, handle); // add space?
285+
}
286+
}
287+
if (i != rows - 1) {
288+
pv_write(";", method, handle); // add space?
289+
}
290+
}
291+
} else {
292+
var_t *e;
293+
int i;
294+
295+
for (i = 0; i < var->v.a.size; i++) {
296+
e = (var_t *) (var->v.a.ptr + (sizeof(var_t) * i));
297+
pv_writevar(e, method, handle);
298+
if (i != var->v.a.size - 1) {
299+
pv_write(",", method, handle); // add space?
300+
}
301+
}
302+
}
303+
304+
// close array
305+
pv_write("]", method, handle);
306+
}
307+
264308
/*
265309
* just prints the value of variable 'var'
266310
*/
@@ -274,9 +318,6 @@ void pv_writevar(var_t *var, int method, int handle) {
274318
case V_STR:
275319
pv_write((char *)var->v.p.ptr, method, handle);
276320
break;
277-
case V_UDS:
278-
uds_write(var, method, handle);
279-
break;
280321
case V_HASH:
281322
hash_write(var, method, handle);
282323
break;
@@ -293,46 +334,7 @@ void pv_writevar(var_t *var, int method, int handle) {
293334
pv_write(tmpsb, method, handle);
294335
break;
295336
case V_ARRAY:
296-
// open array
297-
pv_write("[", method, handle);
298-
299-
if (var->v.a.maxdim == 2) {
300-
int rows, cols;
301-
var_t *e;
302-
int i, j, pos;
303-
304-
// NxN
305-
rows = ABS(var->v.a.ubound[0] - var->v.a.lbound[0]) + 1;
306-
cols = ABS(var->v.a.ubound[1] - var->v.a.lbound[1]) + 1;
307-
308-
for (i = 0; i < rows; i++) {
309-
for (j = 0; j < cols; j++) {
310-
pos = i * cols + j;
311-
e = (var_t *) (var->v.a.ptr + (sizeof(var_t) * pos));
312-
pv_writevar(e, method, handle);
313-
if (j != cols - 1) {
314-
pv_write(",", method, handle); // add space?
315-
}
316-
}
317-
if (i != rows - 1) {
318-
pv_write(";", method, handle); // add space?
319-
}
320-
}
321-
} else {
322-
var_t *e;
323-
int i;
324-
325-
for (i = 0; i < var->v.a.size; i++) {
326-
e = (var_t *) (var->v.a.ptr + (sizeof(var_t) * i));
327-
pv_writevar(e, method, handle);
328-
if (i != var->v.a.size - 1) {
329-
pv_write(",", method, handle); // add space?
330-
}
331-
}
332-
}
333-
334-
// close array
335-
pv_write("]", method, handle);
337+
pv_write_array(var, method, handle);
336338
break;
337339
}
338340
}

src/common/scan.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ extern void sc_raise2(const char *fmt, int line, const char *buff); // sberr
4040
#define LEN_QUIET STRLEN(LCN_QUIET)
4141
#define LEN_GRMODE STRLEN(LCN_GRMODE)
4242
#define LEN_TEXTMODE STRLEN(LCN_TEXTMODE)
43-
#define LEN_CSTR STRLEN(LCN_CSTR)
4443
#define LEN_COMMAND STRLEN(LCN_COMMAND)
4544
#define LEN_SHOWPAGE STRLEN(LCN_SHOWPAGE)
4645

@@ -3779,8 +3778,6 @@ char *comp_preproc_options(char *p) {
37793778
opt_graphics = 1;
37803779
} else if (strncmp(LCN_TEXTMODE, p, LEN_TEXTMODE) == 0) {
37813780
opt_graphics = 0;
3782-
} else if (strncmp(LCN_CSTR, p, LEN_CSTR) == 0) {
3783-
opt_cstr = 1;
37843781
} else if (strncmp(LCN_COMMAND, p, LEN_COMMAND) == 0) {
37853782
p += LEN_COMMAND;
37863783
SKIP_SPACES(p);

src/common/smbas.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ typedef struct {
9595
#define OPT_MOD_SZ 1024
9696

9797
EXTERN byte opt_graphics; /**< command-line option: start in graphics mode @ingroup sys */
98-
EXTERN byte opt_cstr; /**< C-style special characters by default @ingroup sys */
9998
EXTERN byte opt_quiet; /**< command-line option: quiet @ingroup sys */
10099
EXTERN int opt_retval; /**< return-value (ERRORLEVEL) @ingroup sys */
101100
EXTERN byte opt_decomp; /**< decompile @ingroup sys */

0 commit comments

Comments
 (0)