diff --git a/Programs/CosmOS/README.md b/Programs/CosmOS/README.md index ae5ce24..cf6aee9 100644 --- a/Programs/CosmOS/README.md +++ b/Programs/CosmOS/README.md @@ -169,7 +169,10 @@ skipping happens before names are filled in, so `$whatever` inside a branch nobo is not a mistake, and a line nobody is running cannot fail. **Lines may be indented**, which they could not be before there was anything to indent -inside. Leading spaces are taken off before anything looks at the line. +inside. Spaces are taken off both ends of a line before anything looks at it - the leading +ones so that a block can be indented, and the trailing ones because finishing a word with +Tab leaves a space behind it, and a command that takes a file name would otherwise be +looking for one whose name ends in a space. ## Names For Things: diff --git a/Programs/CosmOS/Source/cosmos.asm b/Programs/CosmOS/Source/cosmos.asm index 56b35c9..321fbfc 100644 --- a/Programs/CosmOS/Source/cosmos.asm +++ b/Programs/CosmOS/Source/cosmos.asm @@ -3282,7 +3282,44 @@ lineTrimEmpty: SETD.0 CommandLine RSTA STA.0 + +; ---- And the space at the other end, which finishing a word leaves behind ---- +; +; Tab completion puts a space after the word it finished, because that is what you want when +; another word is coming. When nothing else is coming, that space stayed on the end of the +; line, and a command that takes a file name looked for one whose name ended in a space: +; +; load greet.sbx loaded, starting at 5000 +; load greet.sbx no such file (the same line, completed with Tab) +; +; Which took most of the good out of completion, since finishing a name and pressing Return +; is the whole of what it is for. Taken off the WHOLE LINE rather than at each command that +; takes a name, for the same reason the leading spaces are: there are a dozen of those and +; they should not each have to know. +; +; SAFE TO WALK BACKWARDS WITHOUT A GUARD, and that is worth saying because it looks like it +; is not. Everything above has already run, so the first character is not a space - either +; the line never began with one, or the move loop took them off, or the line was nothing but +; spaces and the empty test below sends it home. So the walk back always meets a character +; that stops it before it reaches the front. lineTrimDone: + SETD.0 CommandLine + LDA.0 + BRA lineTrimEnded ; An empty line has no end to tidy. +lineTrimSeek: + INCD.0 + LDA.0 + BNA lineTrimSeek ; On the zero that ends the line. +lineTrimBack: + DECD.0 + LDA.0 + INIB 0x20 + XOR + BNQ lineTrimEnded ; Not a space, so this is where the line really ends. + RSTA + STA.0 ; The space becomes the end of it, and the one before may go too. + BRI lineTrimBack +lineTrimEnded: RET ; DP0 names a line and DP1 a word. Q is zero if the line's FIRST WORD is that word - which diff --git a/SplitBit Test Manual.md b/SplitBit Test Manual.md index e0633b1..f358b24 100644 --- a/SplitBit Test Manual.md +++ b/SplitBit Test Manual.md @@ -125,7 +125,7 @@ from `make`, not from here. ### 1. Recorded output `Tests/run.sh` assembles each program named in `Tests/manifest`, runs it, and compares -everything it printed against a file in `Tests/expected`. 211 tests, of which 149 run, 35 +everything it printed against a file in `Tests/expected`. 212 tests, of which 150 run, 35 only assemble, 16 are expected to fail to assemble, and 11 boot from ROM with no image given at all. diff --git a/Tests/expected/cosmosTabPath.out b/Tests/expected/cosmosTabPath.out index 16d889f..0888a0b 100644 --- a/Tests/expected/cosmosTabPath.out +++ b/Tests/expected/cosmosTabPath.out @@ -9,9 +9,9 @@ I do not know: Sayzz where am I /Apps> cd / > echo Apps/Secho Apps/Say.sbx  -Apps/Say.sbx +Apps/Say.sbx > echo /Apps/Cecho /Apps/Copy.sbx  -/Apps/Copy.sbx +/Apps/Copy.sbx > exit halted Execution halted. diff --git a/Tests/expected/cosmosTrim.out b/Tests/expected/cosmosTrim.out new file mode 100644 index 0000000..fe61f56 --- /dev/null +++ b/Tests/expected/cosmosTrim.out @@ -0,0 +1,12 @@ +CosmOS +> load greload greet.sbx  +loaded, starting at 5000 +> load greet.sbx +loaded, starting at 5000 +> load greet.sbx +loaded, starting at 5000 +> +> exit +halted +Execution halted. +[exit 0] diff --git a/Tests/input/cosmosTrim.in b/Tests/input/cosmosTrim.in new file mode 100644 index 0000000..4a1a65c --- /dev/null +++ b/Tests/input/cosmosTrim.in @@ -0,0 +1,5 @@ +load gre +load greet.sbx + load greet.sbx + +exit diff --git a/Tests/manifest b/Tests/manifest index 19c106d..537a780 100644 --- a/Tests/manifest +++ b/Tests/manifest @@ -413,7 +413,24 @@ cosmosTab | CosmOS/Source/cosmos.asm | run | cosmosTab # look to RUN something: where you are, /Apps on the disk you are on, and /Apps on drive 0. # Offering what the shell would not find would be finishing a word into something that then # does not work. +# +# The echoed lines here have no trailing space on them, and that is the line trimming rather +# than the completion: Tab still leaves a space after the word it finished, and the shell +# takes it off the end of the line before anything reads it. So what echo is given is what +# somebody would have typed. See cosmosTrim. cosmosTabPath | CosmOS/Source/cosmos.asm | run | cosmosTabPath.in | - | disks/cosmos.img +# The spaces at the ends of a line, which the shell takes off both of now. +# +# The leading ones were always taken off, for indented blocks. The trailing ones were not, +# and Tab completion puts one there: it finishes a word and leaves a space, which is right +# when another word is coming and was fatal when one was not. "load greet.sbx" worked and +# the same line finished with Tab did not, because the shell looked for a file whose name +# ended in a space - which took most of the good out of completion. +# +# Four lines: completed with Tab and run straight away, the same trailing space typed by +# hand, spaces at both ends at once, and a line of nothing but spaces, which has to stay a +# line that does nothing rather than becoming one that fails. +cosmosTrim | CosmOS/Source/cosmos.asm | run | cosmosTrim.in | - | disks/cosmos.img # Names for things, which is what makes a script able to compose a command rather than only # to contain one. The expansion happens on every line the shell is about to run, typed or read # from a file, so no command below has to know that variables exist.