diff --git a/Makefile.in b/Makefile.in index ee27aaa..19addca 100644 --- a/Makefile.in +++ b/Makefile.in @@ -73,8 +73,8 @@ install: all fi; \ done -bas.pot: [a-b]*.[ch] [e-s]*.[ch] v*.[ch] - xgettext --add-comments --keyword=_ [a-b]*.[ch] [e-s]*.[ch] v*.[ch] && test -f messages.po && mv messages.po $@ +bas.pot: src + xgettext --add-comments --keyword=_ src/[a-b]*.[ch] src/[e-s]*.[ch] src/v*.[ch] && test -f messages.po && mv messages.po $@ bas.pdf: bas.1 groff -Tps -t -man bas.1 | ps2pdf - $@ diff --git a/NEWS b/NEWS index e8e3bae..689a390 100644 --- a/NEWS +++ b/NEWS @@ -1,14 +1,3 @@ -Changes compared to version 2.4 +Changes compared to version 2.5 -o truncate bug fixed -o Multi line if with hanging comment works now -o Add files command -o Fixed bug in expression parser -o OPTION BASE bug fixed -o Matrix inversion test improved -o WIDTH 0 bug fixed -o Missing error check on multi assignments added -o Wrong FOR loop management fixed -o Replaced wrong int assignment with long assignment for integers -o unnum bugs fixed -o HP-UX build works again +o STEP expression only evaluated once diff --git a/bas.1.in b/bas.1.in index 0bbbf33..c0f1ca6 100644 --- a/bas.1.in +++ b/bas.1.in @@ -220,20 +220,20 @@ Only the meta characters \fB*?[]\fP are passed through. .\"}}} .IP "\fBfor\fP \fIlvalue\fP \fB=\fP \fIexpression\fP \fBto\fP \fIexpression\fP [\fBstep\fP \fIexpression\fP]" \"{{{ .IP "\fBnext\fP \fIlvalue\fP{\fB,\fP\fIlvalue\fP}" -The \fBfor\fP loop performs the initial variable assignment and then -executes the statements inside the loop, if the variable is lower or equal -than the limit (or greater than for negative steps). The \fBnext\fP -statement verifies if the variable already reached the value of the -\fBto\fP \fIexpression\fP. If not, it increments if by the value of -the \fBstep\fP \fIexpression\fP and causes a new repetition. A missing -\fBstep\fP \fIexpression\fP is treated as \fBstep 1\fP. The \fBnext\fP -statement may be followed by a list of lvalues. Due to the dynamic variable -geometry, the lvalues themselves -are only checked for belonging to the same variable as those in \fBfor\fP. -If no lvalues are given, the -innermost loop is terminated. For loops can be left by \fBexit for\fP. -Note: That statement is not offered by all BASIC dialects and most restrict -loop variables to scalar variables. +The \fBfor\fP loop performs the initial variable assignment and evaluates +the \fBstep\fP \fIexpression\fP, storing the value. Then it executes the +statements inside the loop, if the variable is lower or equal than the +limit (or greater than for negative steps). The \fBnext\fP statement +verifies if the variable already reached the value of the \fBto\fP +\fIexpression\fP. If not, it increments if by the evaluated \fBstep\fP +value and causes a new repetition. A missing \fBstep\fP \fIexpression\fP +is treated as \fBstep 1\fP. The \fBnext\fP statement may be followed +by a list of lvalues. Due to the dynamic variable geometry, the lvalues +themselves are only checked for belonging to the same variable as those +in \fBfor\fP. If no lvalues are given, the innermost loop is terminated. +For loops can be left by \fBexit for\fP. Note: That statement is not +offered by all BASIC dialects and most restrict loop variables to scalar +variables. .\"}}} .IP "\fBget\fP [\fB#\fP]\fIchannel%\fP [\fB,\fP\fIrecord\fP]" \"{{{ Read the record buffer of \fIchannel%\fP from the file it is connected to, diff --git a/bas.pdf b/bas.pdf index ee13545..9190e6a 100644 Binary files a/bas.pdf and b/bas.pdf differ diff --git a/bas.pot b/bas.pot index 9ae8f57..7bd06e2 100644 --- a/bas.pot +++ b/bas.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-04-23 20:56+0200\n" +"POT-Creation-Date: 2019-07-02 20:25+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -95,7 +95,7 @@ msgstr "" msgid "length" msgstr "" -#: bas.c:801 bas.c:848 statement.c:1720 +#: bas.c:801 bas.c:848 statement.c:1723 msgid "rhs" msgstr "" @@ -807,11 +807,11 @@ msgstr "" msgid "time" msgstr "" -#: global.c:763 global.c:780 statement.c:179 statement.c:1037 statement.c:1257 -#: statement.c:1436 statement.c:1639 statement.c:1844 statement.c:2193 -#: statement.c:2313 statement.c:2528 statement.c:2859 statement.c:2866 -#: statement.c:2938 statement.c:3086 statement.c:3876 statement.c:3998 -#: statement.c:4032 statement.c:4091 +#: global.c:763 global.c:780 statement.c:179 statement.c:1037 statement.c:1260 +#: statement.c:1439 statement.c:1642 statement.c:1847 statement.c:2196 +#: statement.c:2316 statement.c:2531 statement.c:2856 statement.c:2863 +#: statement.c:2935 statement.c:3083 statement.c:3873 statement.c:3995 +#: statement.c:4029 statement.c:4088 msgid "channel" msgstr "" @@ -824,7 +824,7 @@ msgstr "" msgid "Logarithm of negative value" msgstr "" -#: global.c:1208 statement.c:2659 +#: global.c:1208 statement.c:2662 msgid "limit" msgstr "" @@ -952,8 +952,8 @@ msgstr "" msgid "string" msgstr "" -#: statement.c:570 statement.c:1404 statement.c:1532 statement.c:2598 -#: statement.c:2606 statement.c:2869 statement.c:3478 +#: statement.c:570 statement.c:1407 statement.c:1535 statement.c:2601 +#: statement.c:2609 statement.c:2866 statement.c:3475 msgid "file name" msgstr "" @@ -977,117 +977,113 @@ msgstr "" msgid "file specification" msgstr "" -#: statement.c:1236 +#: statement.c:1239 msgid "implicit STEP 1:" msgstr "" -#: statement.c:1276 +#: statement.c:1279 msgid "record number" msgstr "" -#: statement.c:1294 +#: statement.c:1297 msgid "`put'/`get' data" msgstr "" -#: statement.c:1469 statement.c:1879 statement.c:2249 +#: statement.c:1472 statement.c:1882 statement.c:2252 msgid "end of file" msgstr "" -#: statement.c:1605 statement.c:1611 +#: statement.c:1608 statement.c:1614 msgid "row" msgstr "" -#: statement.c:1616 statement.c:1622 +#: statement.c:1619 statement.c:1625 msgid "column" msgstr "" -#: statement.c:1677 statement.c:1777 statement.c:3906 statement.c:3966 +#: statement.c:1680 statement.c:1780 statement.c:3903 statement.c:3963 msgid "condition" msgstr "" -#: statement.c:1952 +#: statement.c:1955 msgid "Too much input data\n" msgstr "" -#: statement.c:2041 +#: statement.c:2044 msgid "factor" msgstr "" #. }}} -#: statement.c:2181 +#: statement.c:2184 msgid "matrix" msgstr "" -#: statement.c:2335 statement.c:3108 +#: statement.c:2338 statement.c:3105 msgid "format string" msgstr "" -#: statement.c:2665 -msgid "step" -msgstr "" - -#: statement.c:2746 statement.c:3515 +#: statement.c:2743 statement.c:3512 msgid "selector" msgstr "" -#: statement.c:2836 +#: statement.c:2833 msgid "mode or file" msgstr "" -#: statement.c:2879 statement.c:2891 statement.c:2964 statement.c:2976 +#: statement.c:2876 statement.c:2888 statement.c:2961 statement.c:2973 msgid "record length" msgstr "" -#: statement.c:3018 +#: statement.c:3015 msgid "array subscript base" msgstr "" -#: statement.c:3054 statement.c:3927 +#: statement.c:3051 statement.c:3924 msgid "address" msgstr "" -#: statement.c:3059 +#: statement.c:3056 msgid "output value" msgstr "" -#: statement.c:3176 +#: statement.c:3173 msgid "count" msgstr "" -#: statement.c:3247 +#: statement.c:3244 msgid "random number generator seed" msgstr "" -#: statement.c:3290 +#: statement.c:3287 msgid "source file" msgstr "" -#: statement.c:3303 +#: statement.c:3300 msgid "destination file" msgstr "" -#: statement.c:3742 statement.c:3749 +#: statement.c:3739 statement.c:3746 msgid "pause" msgstr "" -#: statement.c:3829 +#: statement.c:3826 msgid "Quit without saving? (y/n) " msgstr "" -#: statement.c:3836 +#: statement.c:3833 msgid "yes" msgstr "" -#: statement.c:3932 +#: statement.c:3929 msgid "mask" msgstr "" -#: statement.c:3938 +#: statement.c:3935 msgid "select" msgstr "" #. }}} -#: statement.c:4014 statement.c:4097 +#: statement.c:4011 statement.c:4094 msgid "zone width" msgstr "" diff --git a/configure b/configure index fe1999a..a6eca8f 100755 --- a/configure +++ b/configure @@ -2229,8 +2229,8 @@ IFS=$ac_save_IFS case $host_os in *\ *) host_os=`echo "$host_os" | sed 's/ /-/g'`;; esac -VERSION=2.5 -UPDATED='April 23, 2019' +VERSION=2.6 +UPDATED='July 2, 2019' ALL_LINGUAS="de" diff --git a/configure.in b/configure.in index b0bf1c8..e1d04d2 100644 --- a/configure.in +++ b/configure.in @@ -1,8 +1,8 @@ AC_INIT(src/bas.c) AC_CONFIG_HEADER(config.h) AC_CANONICAL_HOST -VERSION=2.5 -UPDATED='April 23, 2019' +VERSION=2.6 +UPDATED='July 2, 2019' ALL_LINGUAS="de" diff --git a/de.po b/de.po index f66f077..ecebbe5 100644 --- a/de.po +++ b/de.po @@ -2,7 +2,7 @@ msgid "" msgstr "" "Project-Id-Version: bas 1.2\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-04-23 20:56+0200\n" +"POT-Creation-Date: 2019-07-02 20:25+0200\n" "PO-Revision-Date: 2002-11-09 18:26+0100\n" "Last-Translator: Michael Haardt \n" "Language-Team: Deutsch \n" @@ -89,7 +89,7 @@ msgstr "Position" msgid "length" msgstr "Länge" -#: bas.c:801 bas.c:848 statement.c:1720 +#: bas.c:801 bas.c:848 statement.c:1723 msgid "rhs" msgstr "rechte Seite" @@ -807,11 +807,11 @@ msgstr "Argumentnummer" msgid "time" msgstr "Zeit" -#: global.c:763 global.c:780 statement.c:179 statement.c:1037 statement.c:1257 -#: statement.c:1436 statement.c:1639 statement.c:1844 statement.c:2193 -#: statement.c:2313 statement.c:2528 statement.c:2859 statement.c:2866 -#: statement.c:2938 statement.c:3086 statement.c:3876 statement.c:3998 -#: statement.c:4032 statement.c:4091 +#: global.c:763 global.c:780 statement.c:179 statement.c:1037 statement.c:1260 +#: statement.c:1439 statement.c:1642 statement.c:1847 statement.c:2196 +#: statement.c:2316 statement.c:2531 statement.c:2856 statement.c:2863 +#: statement.c:2935 statement.c:3083 statement.c:3873 statement.c:3995 +#: statement.c:4029 statement.c:4088 msgid "channel" msgstr "Kanal" @@ -824,7 +824,7 @@ msgstr "Start" msgid "Logarithm of negative value" msgstr "Logarithmus von negativem Wert" -#: global.c:1208 statement.c:2659 +#: global.c:1208 statement.c:2662 msgid "limit" msgstr "Grenze" @@ -959,8 +959,8 @@ msgstr "Rahmenfarbe" msgid "string" msgstr "Zeichenkette" -#: statement.c:570 statement.c:1404 statement.c:1532 statement.c:2598 -#: statement.c:2606 statement.c:2869 statement.c:3478 +#: statement.c:570 statement.c:1407 statement.c:1535 statement.c:2601 +#: statement.c:2609 statement.c:2866 statement.c:3475 msgid "file name" msgstr "Dateiname" @@ -984,117 +984,113 @@ msgstr "Feldbreite" msgid "file specification" msgstr "" -#: statement.c:1236 +#: statement.c:1239 msgid "implicit STEP 1:" msgstr "Impliziter Schritt 1:" -#: statement.c:1276 +#: statement.c:1279 msgid "record number" msgstr "Datensatznummer" -#: statement.c:1294 +#: statement.c:1297 msgid "`put'/`get' data" msgstr "`put'/`get' Daten" -#: statement.c:1469 statement.c:1879 statement.c:2249 +#: statement.c:1472 statement.c:1882 statement.c:2252 msgid "end of file" msgstr "Dateiende" -#: statement.c:1605 statement.c:1611 +#: statement.c:1608 statement.c:1614 msgid "row" msgstr "Zeile" -#: statement.c:1616 statement.c:1622 +#: statement.c:1619 statement.c:1625 msgid "column" msgstr "Spalte" -#: statement.c:1677 statement.c:1777 statement.c:3906 statement.c:3966 +#: statement.c:1680 statement.c:1780 statement.c:3903 statement.c:3963 msgid "condition" msgstr "Bedingung" -#: statement.c:1952 +#: statement.c:1955 msgid "Too much input data\n" msgstr "Zu viele Eingabedaten\n" -#: statement.c:2041 +#: statement.c:2044 msgid "factor" msgstr "Faktor" #. }}} -#: statement.c:2181 +#: statement.c:2184 msgid "matrix" msgstr "Matrix" -#: statement.c:2335 statement.c:3108 +#: statement.c:2338 statement.c:3105 msgid "format string" msgstr "Formatzeichenkette" -#: statement.c:2665 -msgid "step" -msgstr "Schrittweite" - -#: statement.c:2746 statement.c:3515 +#: statement.c:2743 statement.c:3512 msgid "selector" msgstr "Auswahl" -#: statement.c:2836 +#: statement.c:2833 msgid "mode or file" msgstr "Modus oder Datei" -#: statement.c:2879 statement.c:2891 statement.c:2964 statement.c:2976 +#: statement.c:2876 statement.c:2888 statement.c:2961 statement.c:2973 msgid "record length" msgstr "Satzlänge" -#: statement.c:3018 +#: statement.c:3015 msgid "array subscript base" msgstr "Feldindexbasis" -#: statement.c:3054 statement.c:3927 +#: statement.c:3051 statement.c:3924 msgid "address" msgstr "Adresse" -#: statement.c:3059 +#: statement.c:3056 msgid "output value" msgstr "Ausgabewert" -#: statement.c:3176 +#: statement.c:3173 msgid "count" msgstr "Anzahl" -#: statement.c:3247 +#: statement.c:3244 msgid "random number generator seed" msgstr "Zufallszahlengenerator Start" -#: statement.c:3290 +#: statement.c:3287 msgid "source file" msgstr "Quelldatei" -#: statement.c:3303 +#: statement.c:3300 msgid "destination file" msgstr "Zieldatei" -#: statement.c:3742 statement.c:3749 +#: statement.c:3739 statement.c:3746 msgid "pause" msgstr "Pause" -#: statement.c:3829 +#: statement.c:3826 msgid "Quit without saving? (y/n) " msgstr "Beenden ohne zu speichern? (j/n) " -#: statement.c:3836 +#: statement.c:3833 msgid "yes" msgstr "ja" -#: statement.c:3932 +#: statement.c:3929 msgid "mask" msgstr "Maske" -#: statement.c:3938 +#: statement.c:3935 msgid "select" msgstr "Auswahl" #. }}} -#: statement.c:4014 statement.c:4097 +#: statement.c:4011 statement.c:4094 msgid "zone width" msgstr "Zonenbreite" @@ -1110,6 +1106,9 @@ msgstr "Unpaariges \\ im Format" msgid "array index" msgstr "Feldindex" +#~ msgid "step" +#~ msgstr "Schrittweite" + #~ msgid "operand" #~ msgstr "Operand" diff --git a/src/statement.c b/src/statement.c index 2486c31..e5fb1ba 100644 --- a/src/statement.c +++ b/src/statement.c @@ -1174,19 +1174,22 @@ struct Value *stmt_FOR(struct Value *value) /*{{{*/ assert(limit.type!=V_ERROR); if (pc.token->type==T_STEP) /* STEP x */ /*{{{*/ { - struct Pc stepPc; + struct Pc stepPc,stepValuePc; - ++pc.token; stepPc=pc; + ++pc.token; + stepValuePc=pc; if (eval(&stepValue,"`step'")->type==V_ERROR) { Value_destroy(value); *value=stepValue; - pc=stepPc; + pc=stepValuePc; return value; } Value_retype(&stepValue,value->type); assert(stepValue.type!=V_ERROR); + Value_destroy(&stepPc.token->u.step); + Value_clone(&stepPc.token->u.step,&stepValue); } /*}}}*/ else /* implicit numeric STEP */ /*{{{*/ @@ -2723,13 +2726,7 @@ struct Value *stmt_NEXT(struct Value *value) /*{{{*/ assert(value->type!=V_ERROR); if (pc.token->type==T_STEP) { - ++pc.token; - if (eval(&inc,_("step"))->type==V_ERROR) - { - Value_destroy(value); - *value=inc; - return value; - } + Value_clone(&inc,&pc.token->u.step); } else VALUE_NEW_INTEGER(&inc,1); VALUE_RETYPE(&inc,l->type); diff --git a/src/token.h b/src/token.h index 2d5f04b..ac0539e 100644 --- a/src/token.h +++ b/src/token.h @@ -412,7 +412,7 @@ struct Token /* T_SHELL */ /* T_SLEEP */ /* T_SPC */ - /* T_STEP */ + /* T_STEP */ struct Value step; /* T_STOP */ /* T_STRING */ struct String *string; /* T_SUB */ /* struct Symbol *localSyms; */ diff --git a/src/token.l b/src/token.l index ca5511a..743fa83 100644 --- a/src/token.l +++ b/src/token.l @@ -1002,7 +1002,13 @@ end[ \t]+function { return T_SLEEP; } "spc" return T_SPC; -"step" return T_STEP; +"step" { + if (cur) + { + Value_new_NIL(&cur->u.step); + } + return T_STEP; + } "stop" { if (cur) { @@ -1479,7 +1485,7 @@ void Token_destroy(struct Token *token) /*{{{*/ case T_SHELL: break; case T_SLEEP: break; case T_SPC: break; - case T_STEP: break; + case T_STEP: Value_destroy(&r->u.step); break; case T_STOP: break; case T_STRING: String_destroy(r->u.string); free(r->u.string); break; case T_SUB: break; diff --git a/test/test56 b/test/test56 new file mode 100755 index 0000000..27622d5 --- /dev/null +++ b/test/test56 @@ -0,0 +1,36 @@ +#!/bin/sh + +echo -n $0: 'FOR STEP evaluation... ' + +cat >test.bas <<'eof' +10 let I1=-3 +20 let K=1 +30 for I1=I1 to -20 step I1 +40 print K,I1 +50 let K=K+1 +60 next I1 +70 print "AFTER: ",I1 +80 end +eof + +cat >test.ref <<'eof' + 1 -3 + 2 -6 + 3 -9 + 4 -12 + 5 -15 + 6 -18 +AFTER: -21 +eof + +sh ./test/runbas test.bas >test.data + +if cmp test.ref test.data +then + rm -f test.* + echo passed +else + echo failed + exit 1 +fi +