Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix error handling in peer layers
We were not detecting errors correctly in the Spectrum
peer layers.  This resulted in the code that handles
file not found errors in the editor from triggering,
which was a good thing as it was broken.  So we fix the
incorrect error detection in the peer layer and we fix
the editor.  This then fixes a long standing bug where
the contents of the editor are wiped when trying to
open a non-existent file.  Now they are preserved.

Signed-off-by: Mark Ryan <[email protected]>
  • Loading branch information
markdryan committed Feb 25, 2024
commit aeb5ed48af73d15778676489af14acb492e68454
13 changes: 12 additions & 1 deletion src/editor.c
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,7 @@ static char *prv_complete_filename_e(char *com, uint8_t len)

static uint8_t prv_long_command_e(char *com, uint8_t len)
{
specasm_error_t old_err;
uint8_t reset = 0;

if (!strcmp(com, "sel")) {
Expand All @@ -617,12 +618,22 @@ static uint8_t prv_long_command_e(char *com, uint8_t len)
reset = 1;
current_fname[0] = 0;
} else {
if (err_type == SPECASM_ERROR_OK)
old_err = err_type;
err_type = SPECASM_ERROR_OK;
if (old_err == SPECASM_ERROR_OK)
strcpy(current_fname, com);
line = row = col = select_end = select_start = 0;
specasm_cls(SPECASM_CODE_COLOUR |
SPECASM_LABEL_BACKGROUND);
prv_draw_screen(0);
if (old_err != SPECASM_ERROR_OK) {
specasm_text_set_flash(command_col,
SPECASM_MAX_ROWS, 0);
err_type = old_err;
prv_draw_error();
err_type = SPECASM_ERROR_OK;
specasm_sleep_ms(1000);
}
}
} else if (com[0] == 's' && com[1] == ' ') {
com = prv_complete_filename_e(com, len);
Expand Down
33 changes: 21 additions & 12 deletions src/peer_file_next.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ specasm_handle_t specasm_file_wopen_e(const char *fname)
{
specasm_handle_t f;

errno = 0;
f = esx_f_open(fname, ESX_MODE_W | ESX_MODE_OPEN_CREAT_TRUNC);
if (!f)
if (errno)
err_type = SPECASM_ERROR_OPEN;

return f;
Expand All @@ -34,16 +35,19 @@ specasm_handle_t specasm_file_ropen_e(const char *fname)
{
specasm_handle_t f;

errno = 0;
f = esx_f_open(fname, ESX_MODE_R);
if (!f)
if (errno)
err_type = SPECASM_ERROR_OPEN;

return f;
}

void specasm_file_write_e(specasm_handle_t f, const void *data, size_t size)
{
if (esx_f_write(f, (void *)data, size) == 0)
errno = 0;
(void) esx_f_write(f, (void *)data, size);
if (errno)
err_type = SPECASM_ERROR_WRITE;
}

Expand All @@ -61,29 +65,34 @@ void specasm_file_close_e(specasm_handle_t f) { (void)esx_f_close(f); }

specasm_dir_t specasm_opendir_e(const char *fname)
{
specasm_dir_t d = esx_f_opendir(fname);
if (!d)
specasm_dir_t d;

errno = 0;
d = esx_f_opendir(fname);
if (errno)
err_type = SPECASM_ERROR_OPEN;

return d;
}

void specasm_file_stat_e(specasm_handle_t f, specasm_stat_t *buf)
{
if (esx_f_fstat(f, buf))
errno = 0;
(void) esx_f_fstat(f, buf);
if (errno)
err_type = SPECASM_ERROR_READ;
}

uint8_t specasm_file_isdir(const char *fname)
{
specasm_handle_t f;
specasm_dir_t d;

errno = 0;
f = esx_f_open(fname, ESXDOS_MODE_R);
if (!errno) {
(void)esx_f_close(f);
d = esx_f_opendir(fname);
if (errno)
return 0;
}

return errno == ESX_EINVAL;
(void)esx_f_close(d);

return 1;
}
21 changes: 15 additions & 6 deletions src/peer_file_zx.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ specasm_handle_t specasm_file_wopen_e(const char *fname)
{
specasm_handle_t f;

errno = 0;
f = esxdos_f_open(fname, ESXDOS_MODE_W | ESXDOS_MODE_CT);
if (!f)
if (errno)
err_type = SPECASM_ERROR_OPEN;

return f;
Expand All @@ -34,16 +35,19 @@ specasm_handle_t specasm_file_ropen_e(const char *fname)
{
specasm_handle_t f;

errno = 0;
f = esxdos_f_open(fname, ESXDOS_MODE_R);
if (!f)
if (errno)
err_type = SPECASM_ERROR_OPEN;

return f;
}

void specasm_file_write_e(specasm_handle_t f, const void *data, size_t size)
{
if (esxdos_f_write(f, (void *)data, size) == 0)
errno = 0;
(void) esxdos_f_write(f, (void *)data, size);
if (errno)
err_type = SPECASM_ERROR_WRITE;
}

Expand All @@ -61,16 +65,21 @@ void specasm_file_close_e(specasm_handle_t f) { (void)esxdos_f_close(f); }

specasm_dir_t specasm_opendir_e(const char *fname)
{
specasm_dir_t d = esxdos_f_opendir(fname);
if (!d)
specasm_dir_t d;

errno = 0;
d = esxdos_f_opendir(fname);
if (errno)
err_type = SPECASM_ERROR_OPEN;

return d;
}

void specasm_file_stat_e(specasm_handle_t f, specasm_stat_t *buf)
{
if (esxdos_f_fstat(f, buf) < 0)
errno = 0;
(void) esxdos_f_fstat(f, buf);
if (errno)
err_type = SPECASM_ERROR_READ;
}

Expand Down
13 changes: 9 additions & 4 deletions src/peer_next.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,28 @@
#include "state.h"

#include <arch/zxn/esxdos.h>
#include <errno.h>
#include <intrinsic.h>

void specasm_peer_write_state_e(const char *fname, uint16_t checksum)
{
unsigned char f;

errno = 0;
f = esx_f_open(fname, ESX_MODE_W | ESX_MODE_OPEN_CREAT);
if (!f) {
if (errno) {
err_type = SPECASM_ERROR_OPEN;
return;
}

if (esx_f_write(f, &state, sizeof(state)) == 0) {
(void) esx_f_write(f, &state, sizeof(state));
if (errno) {
err_type = SPECASM_ERROR_WRITE;
goto cleanup;
}

if (esx_f_write(f, &checksum, sizeof(checksum)) == 0)
(void) esx_f_write(f, &checksum, sizeof(checksum));
if (errno)
err_type = SPECASM_ERROR_WRITE;

cleanup:
Expand All @@ -47,8 +51,9 @@ uint16_t specasm_peer_read_state_e(const char *fname)
unsigned char f;
uint16_t checksum = 0;

errno = 0;
f = esx_f_open(fname, ESX_MODE_R);
if (!f) {
if (errno) {
err_type = SPECASM_ERROR_OPEN;
return 0;
}
Expand Down
13 changes: 9 additions & 4 deletions src/peer_zx.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,28 @@
#include "state.h"

#include <arch/zx/esxdos.h>
#include <errno.h>
#include <intrinsic.h>

void specasm_peer_write_state_e(const char *fname, uint16_t checksum)
{
unsigned char f;

errno = 0;
f = esxdos_f_open(fname, ESXDOS_MODE_W | ESXDOS_MODE_OC);
if (!f) {
if (errno) {
err_type = SPECASM_ERROR_OPEN;
return;
}

if (esxdos_f_write(f, &state, sizeof(state)) == 0) {
(void) esxdos_f_write(f, &state, sizeof(state));
if (errno) {
err_type = SPECASM_ERROR_WRITE;
goto cleanup;
}

if (esxdos_f_write(f, &checksum, sizeof(checksum)) == 0)
(void) esxdos_f_write(f, &checksum, sizeof(checksum));
if (errno)
err_type = SPECASM_ERROR_WRITE;

cleanup:
Expand All @@ -47,8 +51,9 @@ uint16_t specasm_peer_read_state_e(const char *fname)
unsigned char f;
uint16_t checksum = 0;

errno = 0;
f = esxdos_f_open(fname, ESXDOS_MODE_R);
if (!f) {
if (errno) {
err_type = SPECASM_ERROR_OPEN;
return 0;
}
Expand Down