Skip to content

Commit 0cd6240

Browse files
committed
COMMON: INPUT #F; now supports up to 64 parameters
1 parent f5f6a29 commit 0cd6240

File tree

6 files changed

+44
-13
lines changed

6 files changed

+44
-13
lines changed

ChangeLog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2023-01-09 (12.26)
2+
COMMON: INPUT #F; now supports up to 64 parameters
3+
14
2023-01-09 (12.26)
25
COMMON: fix printing chr(0) into a file or network interface
36

samples/distro-examples/tests/stream-files.bas

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,29 @@ end
3939
dirwalk "./", "*.cpp" use walker(x)
4040
if (!has_main) then throw "dirwalk error"
4141

42+
' allow reading and writing of chr(0)
43+
open "output.dat" for output as #F
44+
for x = 0 to 255
45+
print #F, chr(x);
46+
next
47+
close #F
4248

49+
open "output.dat" for input as #1
50+
for x = 0 to 255
51+
d = input(1, 1)
52+
if asc(d) != x then throw "Invalid file read " + d + " <> " + x
53+
next
54+
close #1
55+
56+
' INPUT #F; now supports up to 64 parameters
57+
open "./output.dat" for output as #2
58+
print #2, "1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16"
59+
close #2
60+
open "./output.dat" for input as #2
61+
dim v[0 to 15]
62+
input #2; v[0], "|", v[1], "|", v[2], "|", v[3], "|", &
63+
v[4], "|", v[5], "|", v[6], "|", v[7], "|", &
64+
v[8], "|", v[9], "|", v[10],"|", v[11],"|", &
65+
v[12],"|", v[13],"|", v[14],"|", v[15],"|"
66+
close #2
67+
if v != [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16] then throw "invalid input"

src/common/blib.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ void cmd_input(int input) {
704704

705705
// get list of parameters
706706
par_t *ptable = NULL;
707-
int pcount = par_getpartable(&ptable, ",;");
707+
int pcount = par_getpartable(&ptable, ",;", input == PV_FILE ? MAX_PARAMS_FILE : MAX_PARAMS);
708708
if (pcount == 0) {
709709
rt_raise(ERR_INPUT_NO_VARS);
710710
}
@@ -813,7 +813,7 @@ void cmd_input(int input) {
813813
// (,)
814814
char *p;
815815
if (pcount == 1) {
816-
p = (inp_p + strlen(inp_p));
816+
p = (inp_p + (!inp_p ? 0 : strlen(inp_p)));
817817
} else {
818818
p = q_strstr(inp_p, ((next_is_const) ? v_getstr(ptable[cur_par_idx].var) : ","), "\"\"");
819819
}
@@ -830,7 +830,7 @@ void cmd_input(int input) {
830830
}
831831
} else {
832832
v_input2var(inp_p, par->var);
833-
inp_p = (inp_p + strlen(inp_p)); // go to '\0'
833+
inp_p = (inp_p + (!inp_p ? 0 : strlen(inp_p))); // go to '\0'
834834
input_is_finished = 1;
835835
}
836836
}

src/common/pproc.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
#define PV_STRING 3
3333
#define PV_NET 4
3434

35+
#define MAX_PARAMS_FILE 64
36+
#define MAX_PARAMS 8
37+
3538
#if defined(__cplusplus)
3639
extern "C" {
3740
#endif
@@ -285,7 +288,7 @@ void par_skip(void);
285288
* @return on success the number of the parameters; otherwise -1
286289
* @see par_freepartable, par_massget
287290
*/
288-
int par_getpartable(par_t **ptable_pp, const char *valid_sep);
291+
int par_getpartable(par_t **ptable_pp, const char *valid_sep, unsigned max_items);
289292

290293
/**
291294
* @ingroup par

src/common/proc.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
#include <limits.h>
1616
#include <dirent.h>
1717

18-
#define MAX_PARAM 8
19-
2018
/*
2119
* returns the last-modified time of the file
2220
*
@@ -900,15 +898,16 @@ void par_freepartable(par_t **ptable_pp, int pcount) {
900898
* YOU MUST FREE THAT TABLE BY USING par_freepartable()
901899
* IF THERE IS NO ERROR, CALL TO par_freepartable IS NOT NEEDED
902900
*/
903-
int par_getpartable(par_t **ptable_pp, const char *valid_sep) {
901+
int par_getpartable(par_t **ptable_pp, const char *valid_sep, unsigned max_items) {
904902
bcip_t ofs;
905903
char vsep[8];
906904

907905
// initialize
908906
var_t *par = NULL;
909907
byte last_sep = 0;
910908
int pcount = 0;
911-
par_t *ptable = *ptable_pp = malloc(sizeof(par_t) * MAX_PARAM);
909+
910+
par_t *ptable = *ptable_pp = malloc(sizeof(par_t) * max_items);
912911

913912
if (valid_sep) {
914913
strlcpy(vsep, valid_sep, sizeof(vsep));
@@ -954,9 +953,9 @@ int par_getpartable(par_t **ptable_pp, const char *valid_sep) {
954953
if (code_isvar()) {
955954
// push parameter
956955
ptable[pcount].var = code_getvarptr();
957-
if (++pcount == MAX_PARAM) {
956+
if (++pcount == max_items) {
958957
par_freepartable(ptable_pp, pcount);
959-
err_parfmt(__FILE__);
958+
err_parfmt(ERR_PARAM_TOO_MANY);
960959
return -1;
961960
}
962961
break;
@@ -974,9 +973,9 @@ int par_getpartable(par_t **ptable_pp, const char *valid_sep) {
974973
// push parameter
975974
ptable[pcount].var = par;
976975
ptable[pcount].flags = PAR_BYVAL;
977-
if (++pcount == MAX_PARAM) {
976+
if (++pcount == max_items) {
978977
par_freepartable(ptable_pp, pcount);
979-
err_parfmt(__FILE__);
978+
err_parfmt(ERR_PARAM_TOO_MANY);
980979
return -1;
981980
}
982981
} else {
@@ -1047,7 +1046,7 @@ int par_massget_type_check(char fmt, par_t *par) {
10471046
int par_massget(const char *fmt, ...) {
10481047
// get ptable
10491048
par_t *ptable;
1050-
int pcount = par_getpartable(&ptable, NULL);
1049+
int pcount = par_getpartable(&ptable, NULL, MAX_PARAMS);
10511050
if (pcount == -1) {
10521051
free(ptable);
10531052
return -1;

src/languages/messages.en.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@
157157
#define ERR_ARRAY_RANGE "Array: Index '%d' out of range. (Max = %d)"
158158
#define ERR_TYPE "Type mismatch"
159159
#define ERR_PARAM "Invalid parameter"
160+
#define ERR_PARAM_TOO_MANY "Too many parameters"
160161
#define ERR_NO_ARGS "Function takes no arguments"
161162
#define EVAL_VAR_IS_ARRAY "Expr/RT: Variable is an array"
162163
#define EVAL_VAR_IS_NOT_ARRAY "Expr/RT: Variable is NOT an array (Use DIM)"

0 commit comments

Comments
 (0)