From a381501a2fbf2864471c73b87a03003ad645131a Mon Sep 17 00:00:00 2001 From: Adrien Bertrand Date: Sun, 26 Nov 2023 12:13:56 +0100 Subject: [PATCH] libticonv, libtifiles, libticables, libticalcs: apply static analysis suggestions. - Reduce scope of variables - Use const when possible - Use nullptr instead of NULL --- libticables/trunk/src/data_log.cc | 3 +- libticables/trunk/src/error.cc | 7 +- libticables/trunk/src/hex2dbus.cc | 35 +- libticables/trunk/src/hex2dusb.cc | 39 +- libticables/trunk/src/hex2nsp.cc | 35 +- libticables/trunk/src/internal.h | 4 +- libticables/trunk/src/link_nul.cc | 12 +- libticables/trunk/src/link_xxx.cc | 49 ++- libticables/trunk/src/log_dbus.cc | 15 +- libticables/trunk/src/log_dusb.cc | 15 +- libticables/trunk/src/log_hex.cc | 20 +- libticables/trunk/src/log_nsp.cc | 15 +- libticables/trunk/src/probe.cc | 57 ++- libticables/trunk/src/ticables.cc | 48 ++- libticables/trunk/src/type2str.cc | 6 +- libticables/trunk/tests/test_ticables_2.cc | 2 +- libticalcs/trunk/src/backup.cc | 74 ++-- libticalcs/trunk/src/calc_73.cc | 179 ++++----- libticalcs/trunk/src/calc_84p.cc | 236 +++++------- libticalcs/trunk/src/calc_89t.cc | 174 ++++----- libticalcs/trunk/src/calc_8x.cc | 101 ++--- libticalcs/trunk/src/calc_9x.cc | 163 +++----- libticalcs/trunk/src/calc_nsp.cc | 124 ++---- libticalcs/trunk/src/calc_xx.cc | 130 +++---- libticalcs/trunk/src/calclabequipmentdata.cc | 73 ++-- libticalcs/trunk/src/clock.cc | 4 +- libticalcs/trunk/src/cmd68k.cc | 112 +++--- libticalcs/trunk/src/cmdz80.cc | 146 +++---- libticalcs/trunk/src/cmdz80.h | 20 +- libticalcs/trunk/src/dbus_pkt.cc | 73 ++-- libticalcs/trunk/src/dirlist.cc | 147 ++++---- libticalcs/trunk/src/dusb_cmd.cc | 273 ++++++-------- libticalcs/trunk/src/dusb_rpkt.cc | 41 +- libticalcs/trunk/src/dusb_vpkt.cc | 58 ++- libticalcs/trunk/src/error.cc | 4 +- libticalcs/trunk/src/internal.h | 26 +- libticalcs/trunk/src/nsp_cmd.cc | 198 +++++----- libticalcs/trunk/src/nsp_rpkt.cc | 76 ++-- libticalcs/trunk/src/nsp_vpkt.cc | 46 +-- libticalcs/trunk/src/probe.cc | 21 +- libticalcs/trunk/src/romdump.cc | 67 ++-- libticalcs/trunk/src/screen.cc | 70 ++-- libticalcs/trunk/src/ticalcs.cc | 47 ++- libticalcs/trunk/src/type2str.cc | 8 +- libticalcs/trunk/tests/test_ticalcs_2.cc | 378 ++++++++----------- libticalcs/trunk/tests/torture_ticalcs.cc | 21 +- libticonv/trunk/src/charset.cc | 45 +-- libticonv/trunk/src/filename.cc | 44 +-- libticonv/trunk/src/ticonv.cc | 124 +++--- libticonv/trunk/src/tokens.cc | 12 +- libticonv/trunk/src/type2str.cc | 2 +- libticonv/trunk/tests/test_ticonv.cc | 24 +- libtifiles/trunk/src/cert.cc | 30 +- libtifiles/trunk/src/comments.cc | 4 +- libtifiles/trunk/src/error.cc | 4 +- libtifiles/trunk/src/files8x.cc | 163 ++++---- libtifiles/trunk/src/files9x.cc | 144 ++++--- libtifiles/trunk/src/filesnsp.cc | 43 +-- libtifiles/trunk/src/filesxx.cc | 109 +++--- libtifiles/trunk/src/filetypes.cc | 182 +++++---- libtifiles/trunk/src/grouped.cc | 121 +++--- libtifiles/trunk/src/intelhex.cc | 41 +- libtifiles/trunk/src/misc.cc | 55 ++- libtifiles/trunk/src/rwfile.cc | 12 +- libtifiles/trunk/src/rwfile.h | 12 +- libtifiles/trunk/src/tigroup.cc | 230 +++++------ libtifiles/trunk/src/type2str.cc | 4 +- libtifiles/trunk/src/types68k.cc | 2 +- libtifiles/trunk/src/types83p.cc | 2 +- libtifiles/trunk/src/typesnsp.cc | 2 +- libtifiles/trunk/src/typesoldz80.cc | 10 +- libtifiles/trunk/src/typesxx.cc | 8 +- libtifiles/trunk/src/ve_fp.cc | 62 ++- libtifiles/trunk/tests/test_tifiles_2.cc | 185 ++++----- tifileutil/src/main.cc | 18 +- 75 files changed, 2132 insertions(+), 3014 deletions(-) diff --git a/libticables/trunk/src/data_log.cc b/libticables/trunk/src/data_log.cc index db16711e5..3d829da04 100644 --- a/libticables/trunk/src/data_log.cc +++ b/libticables/trunk/src/data_log.cc @@ -47,10 +47,9 @@ int log_start(CableHandle *h) { - gchar *tmp; int ret; - tmp = g_strconcat(g_get_home_dir(), G_DIR_SEPARATOR_S, LOG_DIR, NULL); + gchar* tmp = g_strconcat(g_get_home_dir(), G_DIR_SEPARATOR_S, LOG_DIR, NULL); if (!g_mkdir_with_parents(tmp, 0750)) { ret = log_hex_start(); diff --git a/libticables/trunk/src/error.cc b/libticables/trunk/src/error.cc index af9c4c22f..37efca556 100644 --- a/libticables/trunk/src/error.cc +++ b/libticables/trunk/src/error.cc @@ -54,7 +54,7 @@ **/ int TICALL ticables_error_get(int number, char **message) { - if (message == NULL) + if (message == nullptr) { ticables_critical("ticables_error_get(NULL)\n"); return number; @@ -341,10 +341,9 @@ int TICALL ticables_error_get(int number, char **message) #ifndef __WIN32__ if (errno != 0) { - gchar *str; char * tmp = *message; - str = g_strdup_printf(" (errno = %i)", errno); + gchar* str = g_strdup_printf(" (errno = %i)", errno); *message = g_strconcat(tmp, "\n", "System: ", strerror(errno), str, "\n", NULL); g_free(tmp); g_free(str); @@ -387,7 +386,7 @@ int TICALL ticables_error_get(int number, char **message) **/ int TICALL ticables_error_free(char *message) { - if (message == NULL) + if (message == nullptr) { ticables_critical("ticables_error_free(NULL)\n"); return ERR_ILLEGAL_ARG; diff --git a/libticables/trunk/src/hex2dbus.cc b/libticables/trunk/src/hex2dbus.cc index 1d8262095..3ec89bfb9 100644 --- a/libticables/trunk/src/hex2dbus.cc +++ b/libticables/trunk/src/hex2dbus.cc @@ -98,7 +98,7 @@ static int fill_buf(FILE *f, char data, int flush) { static char buf[WIDTH]; static unsigned int cnt = 0; - unsigned int i, j; + unsigned int i; if (!flush) { @@ -116,7 +116,7 @@ static int fill_buf(FILE *f, char data, int flush) if (flush) { - for (j = i; j < WIDTH; j++) + for (unsigned int j = i; j < WIDTH; j++) { fprintf(f, " "); } @@ -142,16 +142,11 @@ int dbus_decomp(const char *filename, int resync) { char src_name[1024]; char dst_name[1024]; - FILE *fi = NULL, *fo = NULL; - long file_size; - unsigned char *buffer; + FILE *fi = nullptr, *fo = nullptr; int i; unsigned int j; int num_bytes; char str[256]; - unsigned char mid, cid; - unsigned int length; - int idx; int ret = 0; // build filenames @@ -163,7 +158,7 @@ int dbus_decomp(const char *filename, int resync) // open files fi = fopen(src_name, "rt"); - if (fi == NULL) + if (fi == nullptr) { fprintf(stderr, "Unable to open input file: %s\n", src_name); return -1; @@ -174,7 +169,7 @@ int dbus_decomp(const char *filename, int resync) fclose(fi); return -1; } - file_size = ftell(fi); + const long file_size = ftell(fi); if (file_size < 0) { fclose(fi); @@ -187,8 +182,8 @@ int dbus_decomp(const char *filename, int resync) } // allocate buffer - buffer = (unsigned char*)calloc(file_size < 131072 ? 65536 : file_size / 2, 1); - if (buffer == NULL) + unsigned char* buffer = (unsigned char*)calloc(file_size < 131072 ? 65536 : file_size / 2, 1); + if (buffer == nullptr) { fprintf(stderr, "calloc error.\n"); fclose(fi); @@ -197,7 +192,7 @@ int dbus_decomp(const char *filename, int resync) memset(buffer, 0xff, file_size/2); fo = fopen(dst_name, "wt"); - if (fo == NULL) + if (fo == nullptr) { fprintf(stderr, "Unable to open output file: %s\n", dst_name); free(buffer); @@ -208,9 +203,9 @@ int dbus_decomp(const char *filename, int resync) fprintf(fo, "TI packet decompiler for D-BUS, version 1.2\n"); // skip comments - if ( fgets(str, sizeof(str), fi) == NULL - || fgets(str, sizeof(str), fi) == NULL - || fgets(str, sizeof(str), fi) == NULL) + if ( fgets(str, sizeof(str), fi) == nullptr + || fgets(str, sizeof(str), fi) == nullptr + || fgets(str, sizeof(str), fi) == nullptr) { goto exit; } @@ -247,9 +242,9 @@ int dbus_decomp(const char *filename, int resync) for (i = 0; i < num_bytes;) { restart: - mid = buffer[i+0]; - cid = buffer[i+1]; - length = buffer[i+2]; + const unsigned char mid = buffer[i + 0]; + const unsigned char cid = buffer[i + 1]; + unsigned int length = buffer[i + 2]; length |= ((int)(buffer[i+3])) << 8; // check for valid packet @@ -260,7 +255,7 @@ int dbus_decomp(const char *filename, int resync) } // check for valid packet - idx = is_a_command_id(cid); + const int idx = is_a_command_id(cid); if (idx == -1) { ret = -2; diff --git a/libticables/trunk/src/hex2dusb.cc b/libticables/trunk/src/hex2dusb.cc index 1d5449e9a..b16e3719b 100644 --- a/libticables/trunk/src/hex2dusb.cc +++ b/libticables/trunk/src/hex2dusb.cc @@ -53,7 +53,7 @@ static const Packet packets[] = { 0x03, 1, 6, "Virtual Packet Data with Continuation" }, { 0x04, 1, 6, "Virtual Packet Data Final" }, { 0x05, 0, 2, "Virtual Packet Data Acknowledgement" }, - { 0x00, 0, 0, NULL } + { 0x00, 0, 0, nullptr } }; typedef struct @@ -85,7 +85,7 @@ static const Opcode opcodes[] = { 0xBB00, "Acknowledgement of Parameter Request"}, { 0xDD00, "End of Transmission"}, { 0xEE00, "Error"}, - { 0, NULL } + { 0, nullptr } }; /* */ @@ -107,9 +107,7 @@ static const Opcode opcodes[] = static const char* name_of_packet(uint8_t id) { - int i; - - for (i=0; packets[i].name; i++) + for (int i = 0; packets[i].name; i++) { if (id == packets[i].type) { @@ -155,9 +153,7 @@ static const char* name_of_packet(uint8_t id) static const char* name_of_data(uint16_t id) { - unsigned int i; - - for (i=0; opcodes[i].name != NULL; i++) + for (unsigned int i = 0; opcodes[i].name != nullptr; i++) { if (id == opcodes[i].type) { @@ -255,13 +251,12 @@ static int add_data_code(uint16_t code) /* */ -static FILE *hex = NULL; -static FILE *logfile = NULL; +static FILE *hex = nullptr; +static FILE *logfile = nullptr; static int hex_read(unsigned char *data) { static int idx = 0; - int ret; int data2; if (feof(hex)) @@ -269,7 +264,7 @@ static int hex_read(unsigned char *data) return -1; } - ret = fscanf(hex, "%02X", &data2); + const int ret = fscanf(hex, "%02X", &data2); if (ret < 1) { return -1; @@ -283,10 +278,8 @@ static int hex_read(unsigned char *data) if (idx >= 16) { - int i; - idx = 0; - for (i = 0; (i < 67-49) && !feof(hex); i++) + for (int i = 0; (i < 67-49) && !feof(hex); i++) { if (fgetc(hex) < 0) { @@ -310,7 +303,7 @@ static int dusb_write(int dir, uint8_t data) static int cnt; static int first = 1; - if (logfile == NULL) + if (logfile == nullptr) { return -1; } @@ -340,7 +333,7 @@ static int dusb_write(int dir, uint8_t data) case 7: if (raw_type == 5) { - uint16_t tmp = (((uint32_t)(array[5])) << 8) | ((uint32_t)(array[6])); + const uint16_t tmp = (((uint32_t)(array[5])) << 8) | ((uint32_t)(array[6])); fprintf(logfile, "\t[%04x]\n", tmp); state = 0; } @@ -349,7 +342,7 @@ static int dusb_write(int dir, uint8_t data) case 9: if (raw_type == 1 || raw_type == 2) { - uint32_t tmp = (((uint32_t)(array[5])) << 24) | (((uint32_t)(array[6])) << 16) | (((uint32_t)(array[7])) << 8) | ((uint32_t)(array[8])); + const uint32_t tmp = (((uint32_t)(array[5])) << 24) | (((uint32_t)(array[6])) << 16) | (((uint32_t)(array[7])) << 8) | ((uint32_t)(array[8])); fprintf(logfile, "\t[%08x]\n", (unsigned int)tmp); state = 0; } @@ -429,14 +422,14 @@ int dusb_decomp(const char *filename) dst_name[sizeof(dst_name) - 1] = 0; hex = fopen(src_name, "rt"); - if (hex == NULL) + if (hex == nullptr) { fprintf(stderr, "Unable to open input file: %s\n", src_name); return -1; } logfile = fopen(dst_name, "wt"); - if (logfile == NULL) + if (logfile == nullptr) { fprintf(stderr, "Unable to open output file: %s\n", dst_name); fclose(hex); @@ -446,9 +439,9 @@ int dusb_decomp(const char *filename) fprintf(logfile, "TI packet decompiler for D-USB, version 1.0\n"); // skip comments - if ( fgets(line, sizeof(line), hex) == NULL - || fgets(line, sizeof(line), hex) == NULL - || fgets(line, sizeof(line), hex) == NULL) + if ( fgets(line, sizeof(line), hex) == nullptr + || fgets(line, sizeof(line), hex) == nullptr + || fgets(line, sizeof(line), hex) == nullptr) { goto exit; } diff --git a/libticables/trunk/src/hex2nsp.cc b/libticables/trunk/src/hex2nsp.cc index 56d766608..3aa9d70c1 100644 --- a/libticables/trunk/src/hex2nsp.cc +++ b/libticables/trunk/src/hex2nsp.cc @@ -68,7 +68,7 @@ static const Address addrs[] = { 0x0000, "TI" }, { 0x6400, "PC" }, { 0x6401, "TI" }, - { 0, NULL }, + { 0, nullptr }, }; static const ServiceId sids[] = @@ -102,7 +102,7 @@ static const ServiceId sids[] = { 0x8007, "8007" }, { 0x8009, "8009" }, - { 0, NULL }, + { 0, nullptr }, }; /* */ @@ -119,9 +119,7 @@ static const ServiceId sids[] = static const char* name_of_sid(uint16_t id) { - int i; - - for (i=0; sids[i].name; i++) + for (int i = 0; sids[i].name; i++) { if (id == sids[i].value) { @@ -134,9 +132,7 @@ static const char* name_of_sid(uint16_t id) static const char* name_of_addr(uint16_t addr) { - int i; - - for (i=0; addrs[i].name; i++) + for (int i = 0; addrs[i].name; i++) { if (addr == addrs[i].value) { @@ -217,13 +213,12 @@ static int add_addr(uint16_t* array, uint16_t addr, int *count) /* */ -static FILE *hex = NULL; -static FILE *logfile = NULL; +static FILE *hex = nullptr; +static FILE *logfile = nullptr; static int hex_read(unsigned char *data) { static int idx = 0; - int ret; int data2; if (feof(hex)) @@ -231,7 +226,7 @@ static int hex_read(unsigned char *data) return -1; } - ret = fscanf(hex, "%02X", &data2); + const int ret = fscanf(hex, "%02X", &data2); if (ret < 1) { return -1; @@ -245,10 +240,8 @@ static int hex_read(unsigned char *data) if (idx >= 16) { - int i; - idx = 0; - for (i = 0; (i < 67-49) && !feof(hex); i++) + for (int i = 0; (i < 67-49) && !feof(hex); i++) { if (fgetc(hex) < 0) { @@ -275,7 +268,7 @@ static int dusb_write(int dir, uint8_t data) static int cnt; static uint8_t ascii[HEXDUMP_SIZE+1]; - if (logfile == NULL) + if (logfile == nullptr) { return -1; } @@ -414,14 +407,14 @@ int nsp_decomp(const char *filename) dst_name[sizeof(dst_name) - 1] = 0; hex = fopen(src_name, "rt"); - if (hex == NULL) + if (hex == nullptr) { fprintf(stderr, "Unable to open this file: %s\n", src_name); return -1; } logfile = fopen(dst_name, "wt"); - if (logfile == NULL) + if (logfile == nullptr) { fprintf(stderr, "Unable to open this file: %s\n", dst_name); fclose(hex); @@ -431,9 +424,9 @@ int nsp_decomp(const char *filename) fprintf(logfile, "TI packet decompiler for NSpire, version 1.0\n"); // skip comments - if ( fgets(line, sizeof(line), hex) == NULL - || fgets(line, sizeof(line), hex) == NULL - || fgets(line, sizeof(line), hex) == NULL) + if ( fgets(line, sizeof(line), hex) == nullptr + || fgets(line, sizeof(line), hex) == nullptr + || fgets(line, sizeof(line), hex) == nullptr) { goto exit; } diff --git a/libticables/trunk/src/internal.h b/libticables/trunk/src/internal.h index ef11a56b1..a82033e9e 100644 --- a/libticables/trunk/src/internal.h +++ b/libticables/trunk/src/internal.h @@ -77,12 +77,12 @@ static inline int ticables_validate_handle(CableHandle * handle) { - return handle != NULL; + return handle != nullptr; } static inline int ticables_validate_cablefncts(const CableFncts * cable) { - return cable != NULL; + return cable != nullptr; } static inline void ticables_event_fill_header(CableHandle * handle, CableEventData * event, CableEventType type, int retval, CableFnctsIdx operation) diff --git a/libticables/trunk/src/link_nul.cc b/libticables/trunk/src/link_nul.cc index 0d96e8b82..bacfec06f 100644 --- a/libticables/trunk/src/link_nul.cc +++ b/libticables/trunk/src/link_nul.cc @@ -120,13 +120,13 @@ extern const CableFncts cable_nul = N_("Dummy link used when no cable is set"), 0, &noop_prepare, - &noop_open, &noop_close, &noop_reset, &noop_probe, NULL, + &noop_open, &noop_close, &noop_reset, &noop_probe, nullptr, &noop_put, &noop_get, &noop_check, &noop_set_red_wire, &noop_set_white_wire, &noop_get_red_wire, &noop_get_white_wire, - NULL, NULL, + nullptr, nullptr, &noop_set_device, - NULL + nullptr }; /* no const ! */ CableFncts cable_ilp = @@ -137,11 +137,11 @@ extern const CableFncts cable_nul = N_("Internal Link Port cable for TiEmu (internal use)"), !0, &noop_prepare, - &noop_open, &noop_close, &noop_reset, &noop_probe, NULL, + &noop_open, &noop_close, &noop_reset, &noop_probe, nullptr, &noop_put, &noop_get, &noop_check, &noop_set_red_wire, &noop_set_white_wire, &noop_get_red_wire, &noop_get_white_wire, - NULL, NULL, + nullptr, nullptr, &noop_set_device, - NULL + nullptr }; diff --git a/libticables/trunk/src/link_xxx.cc b/libticables/trunk/src/link_xxx.cc index 521c32e26..0b2ea1446 100644 --- a/libticables/trunk/src/link_xxx.cc +++ b/libticables/trunk/src/link_xxx.cc @@ -122,7 +122,7 @@ int TICALL ticables_cable_close(CableHandle* handle) } handle->open = 0; free(handle->device); - handle->device = NULL; + handle->device = nullptr; } } @@ -184,7 +184,6 @@ int TICALL ticables_cable_reset(CableHandle* handle) **/ int TICALL ticables_cable_probe(CableHandle* handle, int* result) { - int opened; int ret = 0; VALIDATE_HANDLE(handle); @@ -192,7 +191,7 @@ int TICALL ticables_cable_probe(CableHandle* handle, int* result) const CableFncts * cable = handle->cable; VALIDATE_CABLEFNCTS(cable); - opened = handle->open; + const int opened = handle->open; // Check if device is already opened if (!opened && cable->need_open) @@ -223,7 +222,7 @@ int TICALL ticables_cable_probe(CableHandle* handle, int* result) ret = cable->probe(handle); } ret = ticables_event_send_simple_generic(handle, /* type */ CABLE_EVENT_TYPE_AFTER_GENERIC_OPERATION, /* retval */ ret, /* operation */ CABLE_FNCT_PROBE); - if (result != NULL) + if (result != nullptr) { *result = !ret; } @@ -239,8 +238,8 @@ int TICALL ticables_cable_probe(CableHandle* handle, int* result) } else if (!opened && !cable->need_open) { - free(handle->device); handle->device = NULL; - free(handle->priv2); handle->priv2 = NULL; + free(handle->device); handle->device = nullptr; + free(handle->priv2); handle->priv2 = nullptr; } } } @@ -290,7 +289,7 @@ int TICALL ticables_cable_send(CableHandle* handle, uint8_t *data, uint32_t len) if (!ret) { handle->busy = 1; - if (data != NULL) + if (data != nullptr) { handle->rate.count += len; if (cable->send) @@ -356,7 +355,7 @@ int TICALL ticables_cable_recv(CableHandle* handle, uint8_t *data, uint32_t len) if (!ret) { handle->busy = 1; - if (data != NULL) + if (data != nullptr) { handle->rate.count += len; if (cable->recv) @@ -409,7 +408,7 @@ int TICALL ticables_cable_check(CableHandle* handle, CableStatus *status) RETURN_IF_HANDLE_BUSY(handle); handle->busy = 1; - if (status != NULL) + if (status != nullptr) { if (cable->check) { @@ -879,7 +878,7 @@ ticables_pre_send_hook_type TICALL ticables_cable_get_pre_send_hook(CableHandle { ticables_critical("%s: deprecated function, does nothing anymore", __FUNCTION__); - return NULL; + return nullptr; } /** @@ -894,7 +893,7 @@ ticables_pre_send_hook_type TICALL ticables_cable_set_pre_send_hook(CableHandle { ticables_critical("%s: deprecated function, does nothing anymore", __FUNCTION__); - return NULL; + return nullptr; } /** @@ -908,7 +907,7 @@ ticables_post_send_hook_type TICALL ticables_cable_get_post_send_hook(CableHandl { ticables_critical("%s: deprecated function, does nothing anymore", __FUNCTION__); - return NULL; + return nullptr; } /** @@ -923,7 +922,7 @@ ticables_post_send_hook_type TICALL ticables_cable_set_post_send_hook(CableHandl { ticables_critical("%s: deprecated function, does nothing anymore", __FUNCTION__); - return NULL; + return nullptr; } /** @@ -937,7 +936,7 @@ ticables_pre_recv_hook_type TICALL ticables_cable_get_pre_recv_hook(CableHandle { ticables_critical("%s: deprecated function, does nothing anymore", __FUNCTION__); - return NULL; + return nullptr; } /** @@ -952,7 +951,7 @@ ticables_pre_recv_hook_type TICALL ticables_cable_set_pre_recv_hook(CableHandle { ticables_critical("%s: deprecated function, does nothing anymore", __FUNCTION__); - return NULL; + return nullptr; } /** @@ -966,7 +965,7 @@ ticables_post_recv_hook_type TICALL ticables_cable_get_post_recv_hook(CableHandl { ticables_critical("%s: deprecated function, does nothing anymore", __FUNCTION__); - return NULL; + return nullptr; } /** @@ -981,7 +980,7 @@ ticables_post_recv_hook_type TICALL ticables_cable_set_post_recv_hook(CableHandl { ticables_critical("%s: deprecated function, does nothing anymore", __FUNCTION__); - return NULL; + return nullptr; } /** @@ -996,7 +995,7 @@ ticables_event_hook_type TICALL ticables_cable_get_event_hook(CableHandle *handl if (!ticables_validate_handle(handle)) { ticables_critical("%s: handle is NULL", __FUNCTION__); - return NULL; + return nullptr; } return handle->event_hook; @@ -1012,15 +1011,13 @@ ticables_event_hook_type TICALL ticables_cable_get_event_hook(CableHandle *handl */ ticables_event_hook_type TICALL ticables_cable_set_event_hook(CableHandle *handle, ticables_event_hook_type hook) { - ticables_event_hook_type old_hook; - if (!ticables_validate_handle(handle)) { ticables_critical("%s: handle is NULL", __FUNCTION__); - return NULL; + return nullptr; } - old_hook = handle->event_hook; + const ticables_event_hook_type old_hook = handle->event_hook; handle->event_hook = hook; return old_hook; @@ -1038,7 +1035,7 @@ void * ticables_cable_get_event_user_pointer(CableHandle *handle) if (!ticables_validate_handle(handle)) { ticables_critical("%s: handle is NULL", __FUNCTION__); - return NULL; + return nullptr; } return handle->user_pointer; @@ -1054,15 +1051,13 @@ void * ticables_cable_get_event_user_pointer(CableHandle *handle) */ void * ticables_cable_set_event_user_pointer(CableHandle *handle, void * user_pointer) { - void * old_pointer; - if (!ticables_validate_handle(handle)) { ticables_critical("%s: handle is NULL", __FUNCTION__); - return NULL; + return nullptr; } - old_pointer = handle->user_pointer; + void* old_pointer = handle->user_pointer; handle->user_pointer = user_pointer; return old_pointer; diff --git a/libticables/trunk/src/log_dbus.cc b/libticables/trunk/src/log_dbus.cc index 66741fa29..59adbed02 100644 --- a/libticables/trunk/src/log_dbus.cc +++ b/libticables/trunk/src/log_dbus.cc @@ -39,8 +39,8 @@ #define LOG_DBUS_FILE "ticables-dbus.pkt" -static char *ifn = NULL; -static char *ofn = NULL; +static char *ifn = nullptr; +static char *ofn = nullptr; int log_dbus_start(void) { @@ -57,22 +57,19 @@ int log_dbus_N(int dir, const uint8_t * data, uint32_t len) int log_dbus_stop(void) { - char *r; - char * ifn2; - if (!ifn || ! ofn) { return 0; } - r = strrchr(ifn, '.'); + char* r = strrchr(ifn, '.'); if (r) { *r = '\0'; } dbus_decomp(ifn, 0); - ifn2 = g_strconcat(ifn, ".pkt", NULL); + char* ifn2 = g_strconcat(ifn, ".pkt", NULL); g_free(ifn); ifn = ifn2; @@ -83,9 +80,9 @@ int log_dbus_stop(void) } g_free(ifn); - ifn = NULL; + ifn = nullptr; g_free(ofn); - ofn = NULL; + ofn = nullptr; return 0; } diff --git a/libticables/trunk/src/log_dusb.cc b/libticables/trunk/src/log_dusb.cc index 0b382ba01..bf1f5a1ce 100644 --- a/libticables/trunk/src/log_dusb.cc +++ b/libticables/trunk/src/log_dusb.cc @@ -39,8 +39,8 @@ #define LOG_DUSB_FILE "ticables-dusb.pkt" -static char *ifn = NULL; -static char *ofn = NULL; +static char *ifn = nullptr; +static char *ofn = nullptr; int log_dusb_start(void) { @@ -57,22 +57,19 @@ int log_dusb_N(int dir, const uint8_t * data, uint32_t len) int log_dusb_stop(void) { - char *r; - char * ifn2; - if (!ifn || ! ofn) { return 0; } - r = strrchr(ifn, '.'); + char* r = strrchr(ifn, '.'); if(r) { *r = '\0'; } dusb_decomp(ifn); - ifn2 = g_strconcat(ifn, ".pkt", NULL); + char* ifn2 = g_strconcat(ifn, ".pkt", NULL); g_free(ifn); ifn = ifn2; @@ -83,9 +80,9 @@ int log_dusb_stop(void) } g_free(ifn); - ifn = NULL; + ifn = nullptr; g_free(ofn); - ofn = NULL; + ofn = nullptr; return 0; } diff --git a/libticables/trunk/src/log_hex.cc b/libticables/trunk/src/log_hex.cc index 773623937..16406356f 100644 --- a/libticables/trunk/src/log_hex.cc +++ b/libticables/trunk/src/log_hex.cc @@ -34,8 +34,8 @@ #include "data_log.h" #include "log_hex.h" -static char *ofn = NULL; -static FILE *logfile = NULL; +static char *ofn = nullptr; +static FILE *logfile = nullptr; int log_hex_start(void) { @@ -44,7 +44,7 @@ int log_hex_start(void) ofn = g_strconcat(g_get_home_dir(), G_DIR_SEPARATOR_S, LOG_DIR, G_DIR_SEPARATOR_S, HEX_FILE, NULL); logfile = fopen(ofn, "wt"); - if (logfile != NULL) + if (logfile != nullptr) { fprintf(logfile, "TiCables-2 data logger\n"); // needed by log_dbus.c fprintf(logfile, "Version %s\n", ticables_version_get()); @@ -65,7 +65,7 @@ int log_hex_1(int dir, uint8_t data) static int array[20]; static int i = 0; - if (logfile == NULL) + if (logfile == nullptr) { return 1; } @@ -75,12 +75,10 @@ int log_hex_1(int dir, uint8_t data) if ((i != 0) && !(i % 16)) { - int j; - int c; fprintf(logfile, "| "); - for (j = 0; j < 16; j++) + for (int j = 0; j < 16; j++) { - c = array[j]; + const int c = array[j]; if ((c < 32) || (c > 127)) { fprintf(logfile, " "); @@ -111,14 +109,14 @@ int log_hex_N(int dir, const uint8_t * data, uint32_t len) int log_hex_stop(void) { - if (logfile != NULL) + if (logfile != nullptr) { fclose(logfile); - logfile = NULL; + logfile = nullptr; } g_free(ofn); - ofn = NULL; + ofn = nullptr; return 0; } diff --git a/libticables/trunk/src/log_nsp.cc b/libticables/trunk/src/log_nsp.cc index b1dc00943..2938da3af 100644 --- a/libticables/trunk/src/log_nsp.cc +++ b/libticables/trunk/src/log_nsp.cc @@ -39,8 +39,8 @@ #define LOG_NSP_FILE "ticables-nsp.pkt" -static char *ifn = NULL; -static char *ofn = NULL; +static char *ifn = nullptr; +static char *ofn = nullptr; int log_nsp_start(void) { @@ -57,22 +57,19 @@ int log_nsp_N(int dir, const uint8_t * data, uint32_t len) int log_nsp_stop(void) { - char *r; - char * ifn2; - if (!ifn || ! ofn) { return 0; } - r = strrchr(ifn, '.'); + char* r = strrchr(ifn, '.'); if (r) { *r = '\0'; } nsp_decomp(ifn); - ifn2 = g_strconcat(ifn, ".pkt", NULL); + char* ifn2 = g_strconcat(ifn, ".pkt", NULL); g_free(ifn); ifn = ifn2; @@ -83,9 +80,9 @@ int log_nsp_stop(void) } g_free(ifn); - ifn = NULL; + ifn = nullptr; g_free(ofn); - ofn = NULL; + ofn = nullptr; return 0; } diff --git a/libticables/trunk/src/probe.cc b/libticables/trunk/src/probe.cc index 907e00a06..ac8fdd344 100644 --- a/libticables/trunk/src/probe.cc +++ b/libticables/trunk/src/probe.cc @@ -40,10 +40,9 @@ int TICALL ticables_probing_found(int *array) { - if (array != NULL) + if (array != nullptr) { - int i; - for (i = PORT_FIRST; i < PORT_MAX; i++) + for (int i = PORT_FIRST; i < PORT_MAX; i++) { if (array[i]) { @@ -61,14 +60,12 @@ int TICALL ticables_probing_found(int *array) void TICALL ticables_probing_show(int **array) { - if (array != NULL) + if (array != nullptr) { - int model; - - for (model = CABLE_NUL; model < CABLE_MAX; model++) + for (int model = CABLE_NUL; model < CABLE_MAX; model++) { - int * arraymodel = array[model]; - if (arraymodel != NULL) + const int * arraymodel = array[model]; + if (arraymodel != nullptr) { ticables_info(" %i: %i %i %i %i", model, array[model][PORT_1], array[model][PORT_2], array[model][PORT_3], array[model][PORT_4]); } @@ -101,20 +98,19 @@ int TICALL ticables_probing_do(int ***result, unsigned int timeout, ProbingMetho { int port; int model; - int **array; int found = 0; - if (result == NULL) + if (result == nullptr) { ticables_critical("%s: result is NULL", __FUNCTION__); return ERR_PROBE_FAILED; } - *result = NULL; + *result = nullptr; ticables_info("%s", _("Link cable probing:")); - array = (int **)calloc(CABLE_MAX + 1, sizeof(int *)); - if (array == NULL) + int** array = (int**)calloc(CABLE_MAX + 1, sizeof(int*)); + if (array == nullptr) { return ERR_PROBE_FAILED; // THIS RETURNS ! } @@ -122,7 +118,7 @@ int TICALL ticables_probing_do(int ***result, unsigned int timeout, ProbingMetho for (model = CABLE_NUL; model <= CABLE_MAX; model++) { array[model] = (int *)calloc(PORT_MAX, sizeof(int)); - if (array[model] == NULL) + if (array[model] == nullptr) { for (model = CABLE_NUL; model <= CABLE_MAX; model++) { @@ -136,11 +132,11 @@ int TICALL ticables_probing_do(int ***result, unsigned int timeout, ProbingMetho // look for USB devices (faster) if (method & PROBE_USB) { - int *list, n, i; + int *list, n; ticables_get_usb_devices(&list, &n); - for (i = 0; i < n; i++) + for (int i = 0; i < n; i++) { port = i+1; @@ -172,14 +168,13 @@ int TICALL ticables_probing_do(int ***result, unsigned int timeout, ProbingMetho { for (port = PORT_1; port < PORT_MAX; port++) { - CableHandle* handle; - int err, ret; + int ret; - handle = ticables_handle_new((CableModel)model, (CablePort)port); - if (handle != NULL) + CableHandle* handle = ticables_handle_new((CableModel)model, (CablePort)port); + if (handle != nullptr) { ticables_options_set_timeout(handle, timeout); - err = ticables_cable_probe(handle, &ret); + const int err = ticables_cable_probe(handle, &ret); array[model][port] = (ret && !err) ? 1: 0; if (array[model][port]) { @@ -211,18 +206,16 @@ int TICALL ticables_probing_do(int ***result, unsigned int timeout, ProbingMetho **/ int TICALL ticables_probing_finish(int ***result) { - int i; - - if (result != NULL && *result != NULL) + if (result != nullptr && *result != nullptr) { - for (i = CABLE_NUL; i <= CABLE_MAX; i++) + for (int i = CABLE_NUL; i <= CABLE_MAX; i++) { free((*result)[i]); - (*result)[i] = NULL; + (*result)[i] = nullptr; } free(*result); - *result = NULL; + *result = nullptr; } else { @@ -267,10 +260,10 @@ int TICALL ticables_is_usb_enabled(void) **/ int TICALL ticables_get_usb_devices(int **list, int *len) { - if (list != NULL) + if (list != nullptr) { int ret = 0; - const USBCableInfo *info = NULL; + const USBCableInfo *info = nullptr; int i, n = 0; #if defined(__WIN32__) || (defined(HAVE_LIBUSB) || defined(HAVE_LIBUSB_1_0)) @@ -441,10 +434,10 @@ void translate_usb_device_info(CableDeviceInfo *info, const USBCableInfo *usbinf **/ int TICALL ticables_get_usb_device_info(CableDeviceInfo **list, int *len) { - if (list != NULL) + if (list != nullptr) { int ret = 0; - const USBCableInfo *usbinfo = NULL; + const USBCableInfo *usbinfo = nullptr; int i, n = 0; #if defined(__WIN32__) || (defined(HAVE_LIBUSB) || defined(HAVE_LIBUSB_1_0)) diff --git a/libticables/trunk/src/ticables.cc b/libticables/trunk/src/ticables.cc index c9762fbba..0fe6e1939 100644 --- a/libticables/trunk/src/ticables.cc +++ b/libticables/trunk/src/ticables.cc @@ -87,7 +87,7 @@ static CableFncts const *const cables[] = #if !defined(NO_CABLE_TCPS) && !defined(__WIN32__) &cable_tcps, #endif - NULL + nullptr }; static const uint64_t supported_cables = @@ -195,9 +195,9 @@ int TICALL ticables_library_init(void) usb_init(); #elif defined(HAVE_LIBUSB_1_0) // init libusb, keeping track of success / failure status - libusb_working = libusb_init(NULL); + libusb_working = libusb_init(nullptr); if (libusb_working == LIBUSB_SUCCESS) { - libusb_set_debug(NULL, 3); + libusb_set_debug(nullptr, 3); } #endif @@ -219,7 +219,7 @@ int TICALL ticables_library_exit(void) #elif defined(HAVE_LIBUSB_1_0) // Must not call libusb_exit() if libusb_init() failed, or call it multiple times. if (ticables_instance == 1 && libusb_working == LIBUSB_SUCCESS) { - libusb_exit(NULL); + libusb_exit(nullptr); } #endif return (--ticables_instance); @@ -283,7 +283,7 @@ static int default_event_hook(CableHandle * handle, uint32_t event_count, const (void)user_pointer; const char * cablestr = ticables_model_to_string(ticables_get_model(handle)); const char * portstr = ticables_port_to_string(ticables_get_port(handle)); - if (getenv("TICABLES_EVENT_DEBUG") != NULL) + if (getenv("TICABLES_EVENT_DEBUG") != nullptr) { ticables_info("Event #%u type %d for cable %s port %s", event_count, event->type, cablestr, portstr); } @@ -320,7 +320,6 @@ static int default_event_hook(CableHandle * handle, uint32_t event_count, const CableHandle* TICALL ticables_handle_new(CableModel model, CablePort port) { CableHandle *handle = (CableHandle *)calloc(1, sizeof(CableHandle)); - int i; handle->model = model; handle->port = port; @@ -328,7 +327,7 @@ CableHandle* TICALL ticables_handle_new(CableModel model, CablePort port) handle->delay = DFLT_DELAY; handle->timeout = DFLT_TIMEOUT; - for (i = 0; cables[i] != NULL; i++) + for (int i = 0; cables[i] != nullptr; i++) { if (cables[i]->model == model) { @@ -337,13 +336,13 @@ CableHandle* TICALL ticables_handle_new(CableModel model, CablePort port) } } - if (handle->cable == NULL) + if (handle->cable == nullptr) { free(handle); - handle = NULL; + handle = nullptr; } - if (handle != NULL) + if (handle != nullptr) { handle->event_hook = default_event_hook; //handle->event_count = 0; @@ -365,10 +364,10 @@ int TICALL ticables_handle_del(CableHandle* handle) VALIDATE_HANDLE(handle); free(handle->priv2); - handle->priv2 = NULL; + handle->priv2 = nullptr; free(handle->device); - handle->device = NULL; + handle->device = nullptr; memset((void *)handle, 0, sizeof(*handle)); free(handle); @@ -387,13 +386,12 @@ int TICALL ticables_handle_del(CableHandle* handle) **/ unsigned int TICALL ticables_options_set_timeout(CableHandle* handle, unsigned int timeout) { - if (handle != NULL) + if (handle != nullptr) { - const CableFncts *cable; - unsigned int old_timeout = handle->timeout; + const unsigned int old_timeout = handle->timeout; handle->timeout = timeout; - cable = handle->cable; + const CableFncts* cable = handle->cable; if(!handle->open) { @@ -431,9 +429,9 @@ unsigned int TICALL ticables_options_set_timeout(CableHandle* handle, unsigned i **/ unsigned int TICALL ticables_options_set_delay(CableHandle* handle, unsigned int delay) { - if (handle != NULL) + if (handle != nullptr) { - unsigned int old_delay = handle->delay; + const unsigned int old_delay = handle->delay; handle->delay = delay; return old_delay; } @@ -454,7 +452,7 @@ unsigned int TICALL ticables_options_set_delay(CableHandle* handle, unsigned int **/ CableModel TICALL ticables_get_model(CableHandle* handle) { - if (handle != NULL) + if (handle != nullptr) { return handle->model; } @@ -475,7 +473,7 @@ CableModel TICALL ticables_get_model(CableHandle* handle) **/ CablePort TICALL ticables_get_port(CableHandle* handle) { - if (handle != NULL) + if (handle != nullptr) { return handle->port; } @@ -496,14 +494,14 @@ CablePort TICALL ticables_get_port(CableHandle* handle) **/ const char * TICALL ticables_get_device(CableHandle* handle) { - if (handle != NULL) + if (handle != nullptr) { return handle->device; } else { ticables_critical("%s(NULL)", __FUNCTION__); - return NULL; + return nullptr; } } @@ -517,7 +515,7 @@ const char * TICALL ticables_get_device(CableHandle* handle) **/ unsigned int TICALL ticables_get_timeout(CableHandle *handle) { - if (handle != NULL) + if (handle != nullptr) { return handle->timeout; } @@ -538,7 +536,7 @@ unsigned int TICALL ticables_get_timeout(CableHandle *handle) **/ unsigned int TICALL ticables_get_delay(CableHandle *handle) { - if (handle != NULL) + if (handle != nullptr) { return handle->delay; } @@ -559,7 +557,7 @@ unsigned int TICALL ticables_get_delay(CableHandle *handle) **/ int TICALL ticables_handle_show(CableHandle* handle) { - if (handle != NULL) + if (handle != nullptr) { ticables_info("%s", _("Link cable handle details:")); ticables_info(_(" model : %s"), ticables_model_to_string(handle->model)); diff --git a/libticables/trunk/src/type2str.cc b/libticables/trunk/src/type2str.cc index 655c21549..51dab3eac 100644 --- a/libticables/trunk/src/type2str.cc +++ b/libticables/trunk/src/type2str.cc @@ -64,7 +64,7 @@ const char *TICALL ticables_model_to_string(CableModel model) **/ CableModel TICALL ticables_string_to_model(const char *str) { - if (str == NULL) + if (str == nullptr) { ticables_critical("%s(NULL)", __FUNCTION__); return CABLE_NUL; @@ -129,7 +129,7 @@ const char *TICALL ticables_port_to_string(CablePort port) **/ CablePort TICALL ticables_string_to_port(const char *str) { - if (str == NULL) + if (str == nullptr) { ticables_critical("%s(NULL)", __FUNCTION__); return PORT_0; @@ -182,7 +182,7 @@ const char *TICALL ticables_usbpid_to_string(UsbPid pid) **/ UsbPid TICALL ticables_string_to_usbpid(const char *str) { - if (str == NULL) + if (str == nullptr) { ticables_critical("%s(NULL)", __FUNCTION__); return PID_UNKNOWN; diff --git a/libticables/trunk/tests/test_ticables_2.cc b/libticables/trunk/tests/test_ticables_2.cc index 6ad8a4627..c796b47f2 100644 --- a/libticables/trunk/tests/test_ticables_2.cc +++ b/libticables/trunk/tests/test_ticables_2.cc @@ -115,7 +115,7 @@ int main(int argc, char **argv) // set cable handle = ticables_handle_new(CABLE_PAR, PORT_1); - if (handle == NULL) + if (handle == nullptr) { return -1; } diff --git a/libticalcs/trunk/src/backup.cc b/libticalcs/trunk/src/backup.cc index 4d30341e4..b7225d234 100644 --- a/libticalcs/trunk/src/backup.cc +++ b/libticalcs/trunk/src/backup.cc @@ -38,17 +38,13 @@ int tixx_recv_all_vars_backup(CalcHandle* handle, FileContent* content) { - int i, j, k; - int i_max; GNode *vars, *apps; - int nvars, ivars = 0; + int ivars = 0; int b = 0; - FileContent **group; FileContent *single; - int ret; VALIDATE_HANDLE(handle); - if (content == NULL) + if (content == nullptr) { ticalcs_critical("tixx_recv_backup: content is NULL"); return -1; @@ -56,12 +52,12 @@ int tixx_recv_all_vars_backup(CalcHandle* handle, FileContent* content) VALIDATE_CALCFNCTS(handle->calc); // Do a directory list and check for something to backup - ret = handle->calc->fncts.get_dirlist(handle, &vars, &apps); + int ret = handle->calc->fncts.get_dirlist(handle, &vars, &apps); if (ret) { return ret; } - nvars = ticalcs_dirlist_ve_count(vars); + const int nvars = ticalcs_dirlist_ve_count(vars); if (!nvars) { return ERR_NO_VARS; @@ -76,19 +72,19 @@ int tixx_recv_all_vars_backup(CalcHandle* handle, FileContent* content) PAUSE(100); // needed by TI84+/USB // Create a group file - k = 0; - group = tifiles_content_create_group(nvars); + int k = 0; + FileContent** group = tifiles_content_create_group(nvars); // Receive all vars except for FLASH apps - i_max = g_node_n_children(vars); - for (i = 0; i < i_max; i++) + const int i_max = g_node_n_children(vars); + for (int i = 0; i < i_max; i++) { GNode *parent = g_node_nth_child(vars, i); - int j_max = g_node_n_children(parent); - for (j = 0; j < j_max; j++) + const int j_max = g_node_n_children(parent); + for (int j = 0; j < j_max; j++) { - GNode *node = g_node_nth_child(parent, j); + const GNode *node = g_node_nth_child(parent, j); VarEntry *ve = (VarEntry *) (node->data); handle->updat->cnt2 = handle->updat->cnt3 = ++ivars; @@ -124,7 +120,7 @@ int tixx_recv_all_vars_backup(CalcHandle* handle, FileContent* content) // Steal contents of cnt, then clean up. memcpy(content, cnt, sizeof(*content)); cnt->num_entries = 0; - cnt->entries = NULL; + cnt->entries = nullptr; tifiles_content_delete_regular(cnt); tifiles_comment_set_group_sn(content->comment, sizeof(content->comment)); @@ -156,17 +152,16 @@ int TICALL ticalcs_calc_send_tigroup(CalcHandle* handle, TigContent* content, Ti GNode *vars, *apps; int nvars = 0; int napps = 0; - int ret; VALIDATE_HANDLE(handle); - if (content == NULL) + if (content == nullptr) { ticalcs_critical("ticalcs_calc_send_tigroup: content is NULL"); return -1; } VALIDATE_CALCFNCTS(handle->calc); - ret = handle->calc->fncts.get_dirlist(handle, &vars, &apps); + int ret = handle->calc->fncts.get_dirlist(handle, &vars, &apps); if (ret) { return ret; @@ -192,7 +187,7 @@ int TICALL ticalcs_calc_send_tigroup(CalcHandle* handle, TigContent* content, Ti ret = ti89_send_VAR(handle, 0, TI89_BKUP, "main"); if (!ret) { - ret = ti89_recv_ACK(handle, NULL); + ret = ti89_recv_ACK(handle, nullptr); if (!ret) { ret = ti89_recv_CTS(handle); @@ -204,7 +199,7 @@ int TICALL ticalcs_calc_send_tigroup(CalcHandle* handle, TigContent* content, Ti ret = ti89_send_EOT(handle); if (!ret) { - ret = ti89_recv_ACK(handle, NULL); + ret = ti89_recv_ACK(handle, nullptr); } } } @@ -219,7 +214,7 @@ int TICALL ticalcs_calc_send_tigroup(CalcHandle* handle, TigContent* content, Ti { for (ptr = content->var_entries; *ptr; ptr++) { - TigEntry *te = *ptr; + const TigEntry *te = *ptr; handle->updat->cnt3++; ticalcs_update_pbar(handle); @@ -251,7 +246,7 @@ int TICALL ticalcs_calc_send_tigroup(CalcHandle* handle, TigContent* content, Ti { for (ptr = content->app_entries; *ptr; ptr++) { - TigEntry *te = *ptr; + const TigEntry *te = *ptr; VarEntry ve; handle->updat->cnt3++; @@ -297,10 +292,9 @@ int TICALL ticalcs_calc_recv_tigroup(CalcHandle* handle, TigContent* content, Ti int nvars = 0; int napps = 0; int b = 0; - int ret; VALIDATE_HANDLE(handle); - if (content == NULL) + if (content == nullptr) { ticalcs_critical("ticalcs_calc_send_tigroup: content is NULL"); return -1; @@ -311,7 +305,7 @@ int TICALL ticalcs_calc_recv_tigroup(CalcHandle* handle, TigContent* content, Ti ticalcs_update_pbar(handle); // Do a directory list and check for something to backup - ret = handle->calc->fncts.get_dirlist(handle, &vars, &apps); + int ret = handle->calc->fncts.get_dirlist(handle, &vars, &apps); if (ret) { return ret; @@ -343,17 +337,16 @@ int TICALL ticalcs_calc_recv_tigroup(CalcHandle* handle, TigContent* content, Ti // Receive all vars if ((mode & TIG_RAM) || (mode & TIG_ARCHIVE)) { - int i_max = g_node_n_children(vars); + const int i_max = g_node_n_children(vars); for (i = 0; i < i_max; i++) { GNode *parent = g_node_nth_child(vars, i); - int j_max = g_node_n_children(parent); + const int j_max = g_node_n_children(parent); for (j = 0; j < j_max; j++) { - GNode *node = g_node_nth_child(parent, j); + const GNode *node = g_node_nth_child(parent, j); VarEntry *ve = (VarEntry *) (node->data); - TigEntry *te; PAUSE(100); ret = handle->calc->fncts.is_ready(handle); @@ -383,9 +376,9 @@ int TICALL ticalcs_calc_recv_tigroup(CalcHandle* handle, TigContent* content, Ti g_free(varname); g_free(fldname); - te = tifiles_te_create(filename, TIFILE_SINGLE, handle->model); + TigEntry* te = tifiles_te_create(filename, TIFILE_SINGLE, handle->model); g_free(filename); - if (te != NULL) + if (te != nullptr) { ret = handle->calc->fncts.recv_var(handle, MODE_NORMAL, te->content.regular, ve); if (ret) @@ -408,19 +401,16 @@ int TICALL ticalcs_calc_recv_tigroup(CalcHandle* handle, TigContent* content, Ti // Receive all apps if (mode & TIG_FLASH) { - int i_max = g_node_n_children(apps); + const int i_max = g_node_n_children(apps); for(i = 0; i < i_max; i++) { GNode *parent = g_node_nth_child(apps, i); - int j_max = g_node_n_children(parent); + const int j_max = g_node_n_children(parent); for (j = 0; j < j_max; j++) { - GNode *node = g_node_nth_child(parent, j); + const GNode *node = g_node_nth_child(parent, j); VarEntry *ve = (VarEntry *) (node->data); - TigEntry *te; - char *filename; - char *basename; ret = handle->calc->fncts.is_ready(handle); if (ret) @@ -431,13 +421,13 @@ int TICALL ticalcs_calc_recv_tigroup(CalcHandle* handle, TigContent* content, Ti handle->updat->cnt3++; ticalcs_update_pbar(handle); - basename = ticonv_varname_to_filename(handle->model, ve->name, ve->type); - filename = g_strconcat(basename, ".", tifiles_vartype2fext(handle->model, ve->type), NULL); + char* basename = ticonv_varname_to_filename(handle->model, ve->name, ve->type); + char* filename = g_strconcat(basename, ".", tifiles_vartype2fext(handle->model, ve->type), NULL); g_free(basename); - te = tifiles_te_create(filename, TIFILE_FLASH, handle->model); + TigEntry* te = tifiles_te_create(filename, TIFILE_FLASH, handle->model); g_free(filename); - if (te != NULL) + if (te != nullptr) { ret = handle->calc->fncts.recv_app(handle, te->content.flash, ve); if (ret) diff --git a/libticalcs/trunk/src/calc_73.cc b/libticalcs/trunk/src/calc_73.cc index 97ad73314..d03e4d793 100644 --- a/libticalcs/trunk/src/calc_73.cc +++ b/libticalcs/trunk/src/calc_73.cc @@ -79,10 +79,9 @@ static int is_ready (CalcHandle* handle) { - int ret; uint16_t status; - ret = SEND_RDY(handle); + int ret = SEND_RDY(handle); if (!ret) { ret = RECV_ACK(handle, &status); @@ -97,16 +96,15 @@ static int is_ready (CalcHandle* handle) static int send_key (CalcHandle* handle, uint32_t key) { - int ret; uint16_t status; - ret = SEND_KEY(handle, (uint16_t)key); + int ret = SEND_KEY(handle, (uint16_t)key); if (!ret) { ret = RECV_ACK(handle, &status); // when the key is received if (!ret) { - ret = RECV_ACK(handle, NULL); // after it completes the resulting action + ret = RECV_ACK(handle, nullptr); // after it completes the resulting action } } @@ -115,8 +113,6 @@ static int send_key (CalcHandle* handle, uint32_t key) static int execute (CalcHandle* handle, VarEntry *ve, const char* args) { - int ret; - if (handle->model == CALC_TI73 && ve->type == TI73_ASM) { return ERR_VOID_FUNCTION; @@ -124,7 +120,7 @@ static int execute (CalcHandle* handle, VarEntry *ve, const char* args) // Go back to homescreen PAUSE(200); - ret = send_key(handle, KEY83P_Quit); + int ret = send_key(handle, KEY83P_Quit); if (!ret) { ret = send_key(handle, KEY83P_Clear); @@ -146,8 +142,7 @@ static int execute (CalcHandle* handle, VarEntry *ve, const char* args) ret = send_key(handle, KEY83P_Exec); if (!ret) { - unsigned int i; - for (i = 0; !ret && i < strlen(ve->name); i++) + for (unsigned int i = 0; !ret && i < strlen(ve->name); i++) { const CalcKey *ck = ticalcs_keys_83p((ve->name)[i]); ret = send_key(handle, (uint32_t)(ck->normal.value)); @@ -168,17 +163,16 @@ static int execute (CalcHandle* handle, VarEntry *ve, const char* args) static int recv_screen (CalcHandle* handle, CalcScreenCoord* sc, uint8_t** bitmap) { - int ret; uint8_t *data = (uint8_t *)ticalcs_alloc_screen(65542U); - if (data == NULL) + if (data == nullptr) { return ERR_MALLOC; } - ret = SEND_SCR(handle); + int ret = SEND_SCR(handle); if (!ret) { - ret = RECV_ACK(handle, NULL); + ret = RECV_ACK(handle, nullptr); if (!ret) { uint16_t pktsize; @@ -219,7 +213,7 @@ static int recv_screen (CalcHandle* handle, CalcScreenCoord* sc, uint8_t** bitm } *bitmap = (uint8_t *)ticalcs_realloc_screen(data, size + pktsize); - if (*bitmap != NULL) + if (*bitmap != nullptr) { data = *bitmap; memcpy(data + size, handle->buffer2, pktsize); @@ -257,7 +251,7 @@ static int recv_screen (CalcHandle* handle, CalcScreenCoord* sc, uint8_t** bitm if (ret) { ticalcs_free_screen(data); - *bitmap = NULL; + *bitmap = nullptr; } return ret; @@ -265,19 +259,16 @@ static int recv_screen (CalcHandle* handle, CalcScreenCoord* sc, uint8_t** bitm static int get_dirlist (CalcHandle* handle, GNode** vars, GNode** apps) { - int ret; - TreeInfo *ti; GNode *folder, *root, *node; uint16_t unused; uint32_t memory; - char *utf8; - ret = dirlist_init_trees(handle, vars, apps); + int ret = dirlist_init_trees(handle, vars, apps); if (ret) { return ret; } - ti = (TreeInfo *)((*vars)->data); + TreeInfo* ti = (TreeInfo*)((*vars)->data); ret = SEND_REQ(handle, 0x0000, TI73_DIR, "\0\0\0\0\0\0\0", 0x00, 0x00); if (!ret) @@ -291,7 +282,7 @@ static int get_dirlist (CalcHandle* handle, GNode** vars, GNode** apps) ret = SEND_ACK(handle); if (!ret) { - uint8_t * mem = (uint8_t *)handle->buffer2; + const uint8_t * mem = (uint8_t *)handle->buffer2; memory = (((uint32_t)(mem[1])) << 8) | mem[0]; // Clamp mem_free to a 16-bit value. } } @@ -304,12 +295,12 @@ static int get_dirlist (CalcHandle* handle, GNode** vars, GNode** apps) ti->mem_free = memory; - folder = dirlist_create_append_node(NULL, vars); + folder = dirlist_create_append_node(nullptr, vars); if (!folder) { return ERR_MALLOC; } - root = dirlist_create_append_node(NULL, apps); + root = dirlist_create_append_node(nullptr, apps); if (!root) { return ERR_MALLOC; @@ -317,13 +308,11 @@ static int get_dirlist (CalcHandle* handle, GNode** vars, GNode** apps) // Add permanent variables (Window, RclWindow, TblSet aka WINDW, ZSTO, TABLE) { - VarEntry *ve; - - ve = tifiles_ve_create(); + VarEntry* ve = tifiles_ve_create(); ve->type = TI84p_WINDW; node = dirlist_create_append_node(ve, &folder); - if (node != NULL) + if (node != nullptr) { if (handle->model != CALC_TI73) { @@ -332,7 +321,7 @@ static int get_dirlist (CalcHandle* handle, GNode** vars, GNode** apps) node = dirlist_create_append_node(ve, &folder); } - if (node != NULL) + if (node != nullptr) { ve = tifiles_ve_create(); ve->type = TI84p_TABLE; @@ -350,11 +339,10 @@ static int get_dirlist (CalcHandle* handle, GNode** vars, GNode** apps) { VarEntry *ve = tifiles_ve_create(); uint16_t ve_size; - int ret2; ret = RECV_VAR(handle, &ve_size, &ve->type, ve->name, &ve->attr, &ve->version); ve->size = ve_size; - ret2 = SEND_ACK(handle); + const int ret2 = SEND_ACK(handle); if (ret) { if (ret == ERR_EOT) @@ -386,7 +374,7 @@ static int get_dirlist (CalcHandle* handle, GNode** vars, GNode** apps) return ERR_MALLOC; } - utf8 = ticonv_varname_to_utf8(handle->model, ve->name, ve->type); + char* utf8 = ticonv_varname_to_utf8(handle->model, ve->name, ve->type); ticalcs_slprintf(handle->updat->text, sizeof(handle->updat->text), _("Parsing %s"), utf8); ticonv_utf8_free(utf8); ticalcs_update_label(handle); @@ -397,13 +385,12 @@ static int get_dirlist (CalcHandle* handle, GNode** vars, GNode** apps) static int get_memfree (CalcHandle* handle, uint32_t* ram, uint32_t* flash) { - int ret; uint16_t unused; *ram = -1; *flash = -1; - ret = SEND_REQ(handle, 0x0000, TI73_DIR, "\0\0\0\0\0\0\0", 0x00, 0x00); + int ret = SEND_REQ(handle, 0x0000, TI73_DIR, "\0\0\0\0\0\0\0", 0x00, 0x00); if (!ret) { ret = RECV_ACK(handle, &unused); @@ -415,7 +402,7 @@ static int get_memfree (CalcHandle* handle, uint32_t* ram, uint32_t* flash) ret = SEND_EOT(handle); if (!ret) { - uint8_t * mem = (uint8_t *)handle->buffer2; + const uint8_t * mem = (uint8_t *)handle->buffer2; *ram = (((uint32_t)(mem[1])) << 8) | mem[0]; // Clamp mem_free to a 16-bit value. } } @@ -428,12 +415,11 @@ static int get_memfree (CalcHandle* handle, uint32_t* ram, uint32_t* flash) static int send_backup (CalcHandle* handle, BackupContent* content) { int ret; - uint16_t length; char varname[9]; uint8_t rej_code; uint16_t status; - length = content->data_length1; + uint16_t length = content->data_length1; varname[0] = LSB(content->data_length2); varname[1] = MSB(content->data_length2); varname[2] = LSB(content->data_length3); @@ -525,7 +511,6 @@ static int send_backup (CalcHandle* handle, BackupContent* content) static int recv_backup (CalcHandle* handle, BackupContent* content) { - int ret; char varname[9]; uint8_t attr, ver; @@ -533,10 +518,10 @@ static int recv_backup (CalcHandle* handle, BackupContent* content) tifiles_comment_set_backup_sn(content->comment, sizeof(content->comment)); varname[0] = 0; - ret = SEND_REQ(handle, 0x0000, TI73_BKUP, "\0\0\0\0\0\0\0", 0x00, 0x00); + int ret = SEND_REQ(handle, 0x0000, TI73_BKUP, "\0\0\0\0\0\0\0", 0x00, 0x00); if (!ret) { - ret = RECV_ACK(handle, NULL); + ret = RECV_ACK(handle, nullptr); } if (ret) { @@ -561,7 +546,7 @@ static int recv_backup (CalcHandle* handle, BackupContent* content) ret = SEND_CTS(handle); if (!ret) { - ret = RECV_ACK(handle, NULL); + ret = RECV_ACK(handle, nullptr); } } if (ret) @@ -612,7 +597,7 @@ static int recv_backup (CalcHandle* handle, BackupContent* content) handle->updat->cnt2++; ticalcs_update_pbar(handle); - content->data_part4 = NULL; + content->data_part4 = nullptr; } while(0); return ret; @@ -621,14 +606,13 @@ static int recv_backup (CalcHandle* handle, BackupContent* content) static int send_var (CalcHandle* handle, CalcMode mode, FileContent* content) { int ret = 0; - unsigned int i; uint8_t rej_code; uint16_t status; handle->updat->cnt2 = 0; handle->updat->max2 = content->num_entries; - for (i = 0; !ret && i < content->num_entries; i++) + for (unsigned int i = 0; !ret && i < content->num_entries; i++) { VarEntry *entry = content->entries[i]; uint16_t size; @@ -727,14 +711,13 @@ static int recv_var (CalcHandle* handle, CalcMode mode, FileContent* content, V { int ret; uint16_t unused; - VarEntry *ve; uint16_t ve_size; content->model = handle->model; tifiles_comment_set_single_sn(content->comment, sizeof(content->comment)); content->num_entries = 1; content->entries = tifiles_ve_create_array(1); - ve = content->entries[0] = tifiles_ve_create(); + VarEntry* ve = content->entries[0] = tifiles_ve_create(); memcpy(ve, vr, sizeof(VarEntry)); ticonv_varname_to_utf8_sn(handle->model, vr->name, handle->updat->text, sizeof(handle->updat->text), vr->type); @@ -765,7 +748,7 @@ static int recv_var (CalcHandle* handle, CalcMode mode, FileContent* content, V ret = SEND_CTS(handle); if (!ret) { - ret = RECV_ACK(handle, NULL); + ret = RECV_ACK(handle, nullptr); } } if (ret) @@ -804,19 +787,18 @@ static int send_flash (CalcHandle* handle, FlashContent* content) { int ret = 0; FlashContent *ptr; - unsigned int i, j; uint16_t size; int cpu15mhz = 0; // search for data header - for (ptr = content; ptr != NULL; ptr = ptr->next) + for (ptr = content; ptr != nullptr; ptr = ptr->next) { if (ptr->data_type == TI83p_AMS || ptr->data_type == TI83p_APPL) { break; } } - if (ptr == NULL) + if (ptr == nullptr) { return -1; } @@ -862,7 +844,7 @@ static int send_flash (CalcHandle* handle, FlashContent* content) handle->updat->cnt2 = 0; handle->updat->max2 = ptr->data_length; - for (i = 0; !ret && i < ptr->num_pages; i++) + for (unsigned int i = 0; !ret && i < ptr->num_pages; i++) { FlashPage *fp = ptr->pages[i]; @@ -871,15 +853,15 @@ static int send_flash (CalcHandle* handle, FlashContent* content) fp->addr = 0x4000; } - for (j = 0; !ret && j < fp->size; j += size) + for (unsigned int j = 0; !ret && j < fp->size; j += size) { - uint16_t addr = fp->addr + j; + const uint16_t addr = fp->addr + j; uint8_t* data = fp->data + j; ret = SEND_VAR2(handle, size, ptr->data_type, fp->flag, addr, fp->page); if (!ret) { - ret = RECV_ACK(handle, NULL); + ret = RECV_ACK(handle, nullptr); } if (ret) { @@ -902,7 +884,7 @@ static int send_flash (CalcHandle* handle, FlashContent* content) ret = SEND_XDP(handle, size, data); if (!ret) { - ret = RECV_ACK(handle, NULL); + ret = RECV_ACK(handle, nullptr); if (!ret) { handle->updat->cnt2 += size; @@ -936,7 +918,7 @@ static int send_flash (CalcHandle* handle, FlashContent* content) ret = SEND_EOT(handle); if (!ret) { - ret = RECV_ACK(handle, NULL); + ret = RECV_ACK(handle, nullptr); } } @@ -945,8 +927,6 @@ static int send_flash (CalcHandle* handle, FlashContent* content) static int recv_flash (CalcHandle* handle, FlashContent* content, VarRequest* vr) { - int ret; - FlashPage *fp; uint16_t data_addr; uint16_t old_page = 0; uint16_t data_page; @@ -954,7 +934,6 @@ static int recv_flash (CalcHandle* handle, FlashContent* content, VarRequest* v uint8_t data_type; uint32_t size; int first_block; - int page; int offset; uint8_t buffer[FLASH_PAGE_SIZE + 4]; @@ -968,13 +947,13 @@ static int recv_flash (CalcHandle* handle, FlashContent* content, VarRequest* v content->num_pages = 2048; // TI83+ has 512 KB of FLASH max content->pages = tifiles_fp_create_array(content->num_pages); - page = 0; - fp = content->pages[page] = tifiles_fp_create(); + int page = 0; + FlashPage* fp = content->pages[page] = tifiles_fp_create(); - ret = SEND_REQ2(handle, 0x00, TI73_APPL, vr->name, 0x00); + int ret = SEND_REQ2(handle, 0x00, TI73_APPL, vr->name, 0x00); if (!ret) { - ret = RECV_ACK(handle, NULL); + ret = RECV_ACK(handle, nullptr); } if (ret) { @@ -987,10 +966,9 @@ static int recv_flash (CalcHandle* handle, FlashContent* content, VarRequest* v for (size = 0, first_block = 1, offset = 0; !ret;) { char name[9]; - int ret2; ret = RECV_VAR2(handle, &data_length, &data_type, name, &data_addr, &data_page); - ret2 = SEND_ACK(handle); + const int ret2 = SEND_ACK(handle); if (ret) { if (ret == ERR_EOT) @@ -1031,7 +1009,7 @@ static int recv_flash (CalcHandle* handle, FlashContent* content, VarRequest* v ret = SEND_CTS(handle); if (!ret) { - ret = RECV_ACK(handle, NULL); + ret = RECV_ACK(handle, nullptr); if (!ret) { ret = RECV_XDP(handle, &data_length, &buffer[offset]); @@ -1053,7 +1031,7 @@ static int recv_flash (CalcHandle* handle, FlashContent* content, VarRequest* v /* compute actual application size */ if (buffer[0] == 0x80 && buffer[1] == 0x0f) { - uint32_t len = ((uint32_t)(buffer[2])) << 24 | ((uint32_t)(buffer[3])) << 16 | ((uint32_t)(buffer[4])) << 8 | (uint32_t)(buffer[5]); + const uint32_t len = ((uint32_t)(buffer[2])) << 24 | ((uint32_t)(buffer[3])) << 16 | ((uint32_t)(buffer[4])) << 8 | (uint32_t)(buffer[5]); handle->updat->max2 = len + 75; } } @@ -1080,7 +1058,6 @@ static int recv_flash (CalcHandle* handle, FlashContent* content, VarRequest* v static int recv_idlist (CalcHandle* handle, uint8_t* id) { - int ret; uint16_t unused; uint16_t varsize; uint8_t vartype; @@ -1088,12 +1065,11 @@ static int recv_idlist (CalcHandle* handle, uint8_t* id) uint8_t varattr; uint8_t version; uint8_t data[16]; - int i; ticalcs_strlcpy(handle->updat->text, "ID-LIST", sizeof(handle->updat->text)); ticalcs_update_label(handle); - ret = SEND_REQ(handle, 0x0000, TI73_IDLIST, "\0\0\0\0\0\0\0", 0x00, 0x00); + int ret = SEND_REQ(handle, 0x0000, TI73_IDLIST, "\0\0\0\0\0\0\0", 0x00, 0x00); if (!ret) { ret = RECV_ACK(handle, &unused); @@ -1108,7 +1084,7 @@ static int recv_idlist (CalcHandle* handle, uint8_t* id) ret = SEND_CTS(handle); if (!ret) { - ret = RECV_ACK(handle, NULL); + ret = RECV_ACK(handle, nullptr); if (!ret) { ret = RECV_XDP(handle, &varsize, data); @@ -1117,7 +1093,7 @@ static int recv_idlist (CalcHandle* handle, uint8_t* id) ret = SEND_ACK(handle); if (!ret) { - i = data[9]; + int i = data[9]; data[9] = data[10]; data[10] = i; @@ -1210,7 +1186,7 @@ static int dump_rom_2 (CalcHandle* handle, CalcDumpSize size, const char *filen ret = SEND_KEY(handle, keys[i]); if (!ret) { - ret = RECV_ACK(handle, NULL); // when the key is received + ret = RECV_ACK(handle, nullptr); // when the key is received if (!ret) { PAUSE(1000); @@ -1282,7 +1258,7 @@ static int set_clock (CalcHandle* handle, CalcClock* _clock) ret = SEND_RTS(handle, 13, TI73_CLK, "\0x08\0\0\0\0\0\0\0", 0x00, 0x00); if (!ret) { - ret = RECV_ACK(handle, NULL); + ret = RECV_ACK(handle, nullptr); if (!ret) { ret = RECV_CTS(handle, 13); @@ -1294,7 +1270,7 @@ static int set_clock (CalcHandle* handle, CalcClock* _clock) ret = SEND_XDP(handle, 9, buffer); if (!ret) { - ret = RECV_ACK(handle, NULL); + ret = RECV_ACK(handle, nullptr); if (!ret) { ret = SEND_EOT(handle); @@ -1310,14 +1286,12 @@ static int set_clock (CalcHandle* handle, CalcClock* _clock) static int get_clock (CalcHandle* handle, CalcClock* _clock) { - int ret; uint16_t varsize; uint8_t vartype; uint8_t varattr; uint8_t version; char varname[9]; uint8_t * buffer = (uint8_t *)handle->buffer2; - uint32_t calc_time; struct tm ref, cur; time_t r, c, now; @@ -1325,10 +1299,10 @@ static int get_clock (CalcHandle* handle, CalcClock* _clock) ticalcs_strlcpy(handle->updat->text, _("Getting clock..."), sizeof(handle->updat->text)); ticalcs_update_label(handle); - ret = SEND_REQ(handle, 0x0000, TI73_CLK, "\0x08\0\0\0\0\0\0\0", 0x00, 0x00); + int ret = SEND_REQ(handle, 0x0000, TI73_CLK, "\0x08\0\0\0\0\0\0\0", 0x00, 0x00); if (!ret) { - ret = RECV_ACK(handle, NULL); + ret = RECV_ACK(handle, nullptr); if (!ret) { ret = RECV_VAR(handle, &varsize, &vartype, varname, &varattr, &version); @@ -1340,7 +1314,7 @@ static int get_clock (CalcHandle* handle, CalcClock* _clock) ret = SEND_CTS(handle); if (!ret) { - ret = RECV_ACK(handle, NULL); + ret = RECV_ACK(handle, nullptr); if (!ret) { ret = RECV_XDP(handle, &varsize, buffer); @@ -1357,7 +1331,8 @@ static int get_clock (CalcHandle* handle, CalcClock* _clock) if (!ret) { - calc_time = (((uint32_t)(buffer[2])) << 24) | (((uint32_t)(buffer[3])) << 16) | (((uint32_t)(buffer[4])) << 8) | (uint32_t)(buffer[5]); + const uint32_t calc_time = (((uint32_t)(buffer[2])) << 24) | (((uint32_t)(buffer[3])) << 16) | (((uint32_t)(buffer[4])) << 8) | (uint32_t)(buffer[ + 5]); //printf("<%08x>\n", time); time(&now); // retrieve current DST setting @@ -1402,21 +1377,18 @@ static int get_clock (CalcHandle* handle, CalcClock* _clock) static int del_var (CalcHandle* handle, VarRequest* vr) { - int ret; - char *utf8; - - utf8 = ticonv_varname_to_utf8(handle->model, vr->name, vr->type); + char* utf8 = ticonv_varname_to_utf8(handle->model, vr->name, vr->type); ticalcs_slprintf(handle->updat->text, sizeof(handle->updat->text), _("Deleting %s..."), utf8); ticonv_utf8_free(utf8); ticalcs_update_label(handle); - ret = SEND_DEL(handle, (uint16_t)vr->size, vr->type, vr->name, vr->attr); + int ret = SEND_DEL(handle, (uint16_t)vr->size, vr->type, vr->name, vr->attr); if (!ret) { - ret = RECV_ACK(handle, NULL); + ret = RECV_ACK(handle, nullptr); if (!ret) { - ret = RECV_ACK(handle, NULL); + ret = RECV_ACK(handle, nullptr); } } @@ -1425,20 +1397,19 @@ static int del_var (CalcHandle* handle, VarRequest* vr) static int get_version (CalcHandle* handle, CalcInfos* infos) { - int ret; uint16_t length; uint8_t * buffer = (uint8_t *)handle->buffer2; - ret = SEND_VER(handle); + int ret = SEND_VER(handle); if (!ret) { - ret = RECV_ACK(handle, NULL); + ret = RECV_ACK(handle, nullptr); if (!ret) { ret = SEND_CTS(handle); if (!ret) { - ret = RECV_ACK(handle, NULL); + ret = RECV_ACK(handle, nullptr); if (!ret) { ret = RECV_XDP(handle, &length, buffer); @@ -1500,11 +1471,10 @@ static int send_cert (CalcHandle* handle, FlashContent* content) { int ret = 0; FlashContent *ptr; - int i, nblocks; - uint16_t size = 0xE8; + const uint16_t size = 0xE8; // search for cert header - for (ptr = content; ptr != NULL; ptr = ptr->next) + for (ptr = content; ptr != nullptr; ptr = ptr->next) { if (ptr->data_type == TI83p_CERT) { @@ -1512,19 +1482,19 @@ static int send_cert (CalcHandle* handle, FlashContent* content) } } - if (ptr != NULL) + if (ptr != nullptr) { // send content ticalcs_info(_("FLASH name: \"%s\""), ptr->name); ticalcs_info(_("FLASH size: %i bytes."), ptr->data_length); - nblocks = ptr->data_length / size; + const int nblocks = ptr->data_length / size; handle->updat->max2 = nblocks; ret = SEND_VAR2(handle, size, ptr->data_type, 0x04, 0x4000, 0x00); if (!ret) { - ret = RECV_ACK(handle, NULL); + ret = RECV_ACK(handle, nullptr); if (!ret) { ret = RECV_CTS(handle, 10); @@ -1535,14 +1505,14 @@ static int send_cert (CalcHandle* handle, FlashContent* content) } } - for (i = 0; !ret && i <= nblocks; i++) + for (int i = 0; !ret && i <= nblocks; i++) { - uint16_t length = size; + const uint16_t length = size; ret = SEND_XDP(handle, length, (ptr->data_part) + length * i); if (!ret) { - ret = RECV_ACK(handle, NULL); + ret = RECV_ACK(handle, nullptr); if (!ret) { ret = RECV_CTS(handle, size); @@ -1571,7 +1541,6 @@ static int send_cert (CalcHandle* handle, FlashContent* content) static int recv_cert (CalcHandle* handle, FlashContent* content) { - int ret; int i; uint8_t buf[256]; @@ -1585,10 +1554,10 @@ static int recv_cert (CalcHandle* handle, FlashContent* content) content->num_pages = 0; content->data_part = (uint8_t *)tifiles_ve_alloc_data(2 * 1024 * 1024); // 2MB max - ret = SEND_REQ2(handle, 0x00, TI83p_GETCERT, "\0\0\0\0\0\0\0", 0x00); + int ret = SEND_REQ2(handle, 0x00, TI83p_GETCERT, "\0\0\0\0\0\0\0", 0x00); if (!ret) { - ret = RECV_ACK(handle, NULL); + ret = RECV_ACK(handle, nullptr); if (!ret) { // No need to take busy around this libticables call, it's already been taken by ticalcs_calc_recv_cert() before this is reached. @@ -1605,7 +1574,7 @@ static int recv_cert (CalcHandle* handle, FlashContent* content) ret = SEND_CTS(handle); if (!ret) { - ret = RECV_ACK(handle, NULL); + ret = RECV_ACK(handle, nullptr); if (!ret) { ret = RECV_XDP(handle, &block_size, content->data_part); diff --git a/libticalcs/trunk/src/calc_84p.cc b/libticalcs/trunk/src/calc_84p.cc index 70d040082..2a2d6e9e8 100644 --- a/libticalcs/trunk/src/calc_84p.cc +++ b/libticalcs/trunk/src/calc_84p.cc @@ -56,10 +56,9 @@ static int is_ready (CalcHandle* handle) { - int ret; static const DUSBModeSet mode = DUSB_MODE_NORMAL; - ret = dusb_cmd_s_mode_set(handle, mode); + int ret = dusb_cmd_s_mode_set(handle, mode); if (!ret) { // use PID_HOMESCREEN to return status ? @@ -71,9 +70,7 @@ static int is_ready (CalcHandle* handle) static int send_key_noack (CalcHandle* handle, uint32_t key) { - int ret; - - ret = dusb_cmd_s_execute(handle, "", "", DUSB_EID_KEY, "", (uint16_t)key); + int ret = dusb_cmd_s_execute(handle, "", "", DUSB_EID_KEY, "", (uint16_t)key); if (!ret) { ret = dusb_cmd_r_delay_ack(handle); @@ -84,9 +81,7 @@ static int send_key_noack (CalcHandle* handle, uint32_t key) static int send_key (CalcHandle* handle, uint32_t key) { - int ret; - - ret = send_key_noack(handle, key); + int ret = send_key_noack(handle, key); if (!ret) { ret = dusb_cmd_r_data_ack(handle); @@ -98,7 +93,6 @@ static int send_key (CalcHandle* handle, uint32_t key) static int execute (CalcHandle* handle, VarEntry *ve, const char *args) { uint8_t action; - int ret; switch (ve->type) { @@ -107,7 +101,7 @@ static int execute (CalcHandle* handle, VarEntry *ve, const char *args) default: action = DUSB_EID_PRGM; break; } - ret = dusb_cmd_s_execute(handle, ve->folder, ve->name, action, args, 0); + int ret = dusb_cmd_s_execute(handle, ve->folder, ve->name, action, args, 0); if (!ret) { ret = dusb_cmd_r_data_ack(handle); @@ -121,9 +115,8 @@ static int recv_screen (CalcHandle* handle, CalcScreenCoord* sc, uint8_t** bitm static const uint16_t pid[] = { DUSB_PID_SCREENSHOT }; uint32_t size; uint8_t *data; - int ret; - ret = dusb_cmd_s_param_request(handle, 1, pid); + int ret = dusb_cmd_s_param_request(handle, 1, pid); if (!ret) { ret = dusb_cmd_r_screenshot(handle, &size, &data); @@ -146,7 +139,7 @@ static int recv_screen (CalcHandle* handle, CalcScreenCoord* sc, uint8_t** bitm else { g_free(data); - *bitmap = NULL; + *bitmap = nullptr; ret = ERR_INVALID_SCREENSHOT; } break; @@ -160,7 +153,7 @@ static int recv_screen (CalcHandle* handle, CalcScreenCoord* sc, uint8_t** bitm if (ret) { ticalcs_free_screen(*bitmap); - *bitmap = NULL; + *bitmap = nullptr; ret = ERR_INVALID_SCREENSHOT; } else @@ -193,7 +186,7 @@ static int recv_screen (CalcHandle* handle, CalcScreenCoord* sc, uint8_t** bitm default: { g_free(data); - *bitmap = NULL; + *bitmap = nullptr; ret = ERR_INVALID_SCREENSHOT; break; } @@ -208,24 +201,21 @@ static int get_dirlist (CalcHandle* handle, GNode** vars, GNode** apps) { static const uint16_t aids[] = { DUSB_AID_VAR_SIZE, DUSB_AID_VAR_TYPE, DUSB_AID_ARCHIVED }; const int size = sizeof(aids) / sizeof(uint16_t); - int ret; - DUSBCalcAttr **attr; GNode *folder, *root, *node; char fldname[40], varname[40]; - char *utf8; - ret = dirlist_init_trees(handle, vars, apps); + int ret = dirlist_init_trees(handle, vars, apps); if (ret) { return ret; } - folder = dirlist_create_append_node(NULL, vars); + folder = dirlist_create_append_node(nullptr, vars); if (!folder) { return ERR_MALLOC; } - root = dirlist_create_append_node(NULL, apps); + root = dirlist_create_append_node(nullptr, apps); if (!root) { return ERR_MALLOC; @@ -233,13 +223,11 @@ static int get_dirlist (CalcHandle* handle, GNode** vars, GNode** apps) // Add permanent variables (Window, RclWin / RclWindw, TblSet aka WINDW, ZSTO, TABLE) { - VarEntry *ve; - - ve = tifiles_ve_create(); + VarEntry* ve = tifiles_ve_create(); ticalcs_strlcpy(ve->name, "Window", sizeof(ve->name)); ve->type = TI84p_WINDW; node = dirlist_create_append_node(ve, &folder); - if (node != NULL) + if (node != nullptr) { ve = tifiles_ve_create(); // Actually, "RclWindw" works even on an old 84+ running OS 2.43, but libticalcs @@ -247,7 +235,7 @@ static int get_dirlist (CalcHandle* handle, GNode** vars, GNode** apps) ticalcs_strlcpy(ve->name, (handle->model == CALC_TI84PC_USB || handle->model == CALC_TI83PCE_USB || handle->model == CALC_TI84PCE_USB || handle->model == CALC_TI82AEP_USB) ? "RclWindw" : "RclWin", sizeof(ve->name)); ve->type = TI84p_ZSTO; node = dirlist_create_append_node(ve, &folder); - if (node != NULL) + if (node != nullptr) { ve = tifiles_ve_create(); ticalcs_strlcpy(ve->name, "TblSet", sizeof(ve->name)); @@ -267,9 +255,7 @@ static int get_dirlist (CalcHandle* handle, GNode** vars, GNode** apps) { for (;;) { - VarEntry *ve; - - attr = dusb_ca_new_array(handle, size); + DUSBCalcAttr** attr = dusb_ca_new_array(handle, size); ret = dusb_cmd_r_var_header(handle, fldname, varname, attr); if (ret) { @@ -282,7 +268,7 @@ static int get_dirlist (CalcHandle* handle, GNode** vars, GNode** apps) break; } - ve = tifiles_ve_create(); + VarEntry* ve = tifiles_ve_create(); ticalcs_strlcpy(ve->name, varname, sizeof(ve->name)); ve->size = ( (((uint32_t)(attr[0]->data[0])) << 24) | (((uint32_t)(attr[0]->data[1])) << 16) @@ -299,7 +285,7 @@ static int get_dirlist (CalcHandle* handle, GNode** vars, GNode** apps) break; } - utf8 = ticonv_varname_to_utf8(handle->model, ve->name, ve->type); + char* utf8 = ticonv_varname_to_utf8(handle->model, ve->name, ve->type); ticalcs_slprintf(handle->updat->text, sizeof(handle->updat->text), _("Parsing %s"), utf8); ticonv_utf8_free(utf8); ticalcs_update_label(handle); @@ -313,11 +299,9 @@ static int get_memfree (CalcHandle* handle, uint32_t* ram, uint32_t* flash) { static const uint16_t pids[] = { DUSB_PID_FREE_RAM, DUSB_PID_FREE_FLASH }; const int size = sizeof(pids) / sizeof(uint16_t); - DUSBCalcParam **params; - int ret; - params = dusb_cp_new_array(handle, size); - ret = dusb_cmd_s_param_request(handle, size, pids); + DUSBCalcParam** params = dusb_cp_new_array(handle, size); + int ret = dusb_cmd_s_param_request(handle, size, pids); if (!ret) { ret = dusb_cmd_r_param_data(handle, size, params); @@ -340,17 +324,15 @@ static int get_memfree (CalcHandle* handle, uint32_t* ram, uint32_t* flash) static int send_backup (CalcHandle* handle, BackupContent* content) { - DUSBCalcAttr **attrs; const int nattrs = 3; - uint32_t length; - uint8_t *data, *p; + uint8_t*p; int ret = 0; static const uint16_t keys[] = { KEY83P_Quit, KEY83P_LinkIO, KEY83P_Right, KEY83P_1 }; unsigned int i; - attrs = dusb_ca_new_array(handle, nattrs); + DUSBCalcAttr** attrs = dusb_ca_new_array(handle, nattrs); attrs[0] = dusb_ca_new(handle, DUSB_AID_VAR_TYPE, 4); attrs[0]->data[0] = 0xF0; attrs[0]->data[1] = 0x07; attrs[0]->data[2] = 0x00; attrs[0]->data[3] = TI84p_BKUP; @@ -369,8 +351,8 @@ static int send_backup (CalcHandle* handle, BackupContent* content) attrs[2]->data[6] = MSB(content->mem_address); attrs[2]->data[7] = LSB(content->mem_address); - length = content->data_length1 + content->data_length2 + content->data_length3; - data = p = (uint8_t *)g_malloc(length); + const uint32_t length = content->data_length1 + content->data_length2 + content->data_length3; + uint8_t* data = p = (uint8_t*)g_malloc(length); memcpy(p, content->data_part1, content->data_length1); p += content->data_length1; memcpy(p, content->data_part2, content->data_length2); @@ -440,15 +422,12 @@ static int send_backup (CalcHandle* handle, BackupContent* content) static int send_var (CalcHandle* handle, CalcMode mode, FileContent* content) { - unsigned int i; int ret = 0; - for (i = 0; i < content->num_entries; i++) + for (unsigned int i = 0; i < content->num_entries; i++) { - DUSBCalcAttr **attrs; const int nattrs = 3; VarEntry *entry = content->entries[i]; - uint32_t size; if (!ticalcs_validate_varentry(entry)) { @@ -465,7 +444,7 @@ static int send_var (CalcHandle* handle, CalcMode mode, FileContent* content) ticonv_varname_to_utf8_sn(handle->model, entry->name, handle->updat->text, sizeof(handle->updat->text), entry->type); ticalcs_update_label(handle); - attrs = dusb_ca_new_array(handle, nattrs); + DUSBCalcAttr** attrs = dusb_ca_new_array(handle, nattrs); attrs[0] = dusb_ca_new(handle, DUSB_AID_VAR_TYPE, 4); attrs[0]->data[0] = 0xF0; attrs[0]->data[1] = 0x07; attrs[0]->data[2] = 0x00; attrs[0]->data[3] = entry->type; @@ -474,7 +453,7 @@ static int send_var (CalcHandle* handle, CalcMode mode, FileContent* content) attrs[2] = dusb_ca_new(handle, DUSB_AID_VAR_VERSION, 4); attrs[2]->data[3] = entry->version; - size = entry->size; + const uint32_t size = entry->size; if (entry->size >= 65536U) { ticalcs_critical("%s: variable size %u is suspiciously large", __FUNCTION__, size); @@ -521,22 +500,19 @@ static int recv_var (CalcHandle* handle, CalcMode mode, FileContent* content, V { static const uint16_t aids[] = { DUSB_AID_ARCHIVED, DUSB_AID_VAR_VERSION, DUSB_AID_VAR_SIZE }; const int naids = sizeof(aids) / sizeof(uint16_t); - DUSBCalcAttr **attrs; const int nattrs = 1; char fldname[40], varname[40]; uint8_t *data; - VarEntry *ve; - int ret; ticonv_varname_to_utf8_sn(handle->model, vr->name, handle->updat->text, sizeof(handle->updat->text), vr->type); ticalcs_update_label(handle); - attrs = dusb_ca_new_array(handle, nattrs); + DUSBCalcAttr** attrs = dusb_ca_new_array(handle, nattrs); attrs[0] = dusb_ca_new(handle, DUSB_AID_VAR_TYPE2, 4); attrs[0]->data[0] = 0xF0; attrs[0]->data[1] = 0x07; attrs[0]->data[2] = 0x00; attrs[0]->data[3] = vr->type; - ret = dusb_cmd_s_var_request(handle, "", vr->name, naids, aids, nattrs, CA(attrs)); + int ret = dusb_cmd_s_var_request(handle, "", vr->name, naids, aids, nattrs, CA(attrs)); dusb_ca_del_array(handle, attrs, nattrs); if (!ret) { @@ -544,7 +520,7 @@ static int recv_var (CalcHandle* handle, CalcMode mode, FileContent* content, V ret = dusb_cmd_r_var_header(handle, fldname, varname, attrs); if (!ret) { - ret = dusb_cmd_r_var_content(handle, NULL, &data); + ret = dusb_cmd_r_var_content(handle, nullptr, &data); if (!ret) { content->model = handle->model; @@ -552,7 +528,7 @@ static int recv_var (CalcHandle* handle, CalcMode mode, FileContent* content, V content->num_entries = 1; content->entries = tifiles_ve_create_array(1); - ve = content->entries[0] = tifiles_ve_create(); + VarEntry* ve = content->entries[0] = tifiles_ve_create(); memcpy(ve, vr, sizeof(VarEntry)); ve->size = ( (((uint32_t)(attrs[2]->data[0])) << 24) @@ -610,16 +586,16 @@ static int send_flash (CalcHandle* handle, FlashContent* content) uint32_t size; // search for data header - for (ptr = content; ptr != NULL; ptr = ptr->next) + for (ptr = content; ptr != nullptr; ptr = ptr->next) { if (ptr->data_type == TI83p_AMS || ptr->data_type == TI83p_APPL) { break; } } - if ( ptr == NULL - || ptr->data_type != TI83p_APPL - || ptr->pages == NULL) + if ( ptr == nullptr + || ptr->data_type != TI83p_APPL + || ptr->pages == nullptr) { return ERR_INVALID_PARAMETER; } @@ -638,7 +614,7 @@ static int send_flash (CalcHandle* handle, FlashContent* content) size = ptr->num_pages * FLASH_PAGE_SIZE; data = (uint8_t *)tifiles_fp_alloc_data(size); // must be rounded-up - if (data == NULL) + if (data == nullptr) { return ERR_MALLOC; } @@ -700,30 +676,26 @@ static int send_flash (CalcHandle* handle, FlashContent* content) static int send_flash_834pce (CalcHandle* handle, FlashContent* content) { FlashContent *ptr; - DUSBCalcAttr **attrs; const int nattrs = 2; int ret = 0; - uint8_t *data; - uint32_t size; - // search for data header - for (ptr = content; ptr != NULL; ptr = ptr->next) + for (ptr = content; ptr != nullptr; ptr = ptr->next) { if (ptr->data_type == TI83p_AMS || ptr->data_type == TI83p_APPL) { break; } } - if ( ptr == NULL - || ptr->data_type != TI83p_APPL - || ptr->data_part == NULL) + if ( ptr == nullptr + || ptr->data_type != TI83p_APPL + || ptr->data_part == nullptr) { return ERR_INVALID_PARAMETER; } - size = ptr->data_length; - data = ptr->data_part; + const uint32_t size = ptr->data_length; + uint8_t* data = ptr->data_part; handle->updat->cnt2 = 0; handle->updat->max2 = 0; @@ -732,7 +704,7 @@ static int send_flash_834pce (CalcHandle* handle, FlashContent* content) ticonv_varname_to_utf8_sn(handle->model, ptr->name, handle->updat->text, sizeof(handle->updat->text), ptr->data_type); ticalcs_update_label(handle); - attrs = dusb_ca_new_array(handle, nattrs); + DUSBCalcAttr** attrs = dusb_ca_new_array(handle, nattrs); attrs[0] = dusb_ca_new(handle, DUSB_AID_VAR_TYPE, 4); attrs[0]->data[0] = 0xF0; attrs[0]->data[1] = 0x0F; attrs[0]->data[2] = 0x00; attrs[0]->data[3] = ptr->data_type; @@ -765,26 +737,23 @@ static int recv_flash (CalcHandle* handle, FlashContent* content, VarRequest* v { static const uint16_t aids[] = { DUSB_AID_ARCHIVED, DUSB_AID_VAR_VERSION }; const int naids = sizeof(aids) / sizeof(uint16_t); - DUSBCalcAttr **attrs; const int nattrs = 1; char fldname[40], varname[40]; uint8_t *data; uint32_t data_length; int page; - uint16_t data_addr = 0x4000; + const uint16_t data_addr = 0x4000; uint16_t data_page = 0; - int r, q; - int ret; ticonv_varname_to_utf8_sn(handle->model, vr->name, handle->updat->text, sizeof(handle->updat->text), vr->type); ticalcs_update_label(handle); - attrs = dusb_ca_new_array(handle, nattrs); + DUSBCalcAttr** attrs = dusb_ca_new_array(handle, nattrs); attrs[0] = dusb_ca_new(handle, DUSB_AID_VAR_TYPE2, 4); attrs[0]->data[0] = 0xF0; attrs[0]->data[1] = 0x07; attrs[0]->data[2] = 0x00; attrs[0]->data[3] = vr->type; - ret = dusb_cmd_s_var_request(handle, "", vr->name, naids, aids, nattrs, CA(attrs)); + int ret = dusb_cmd_s_var_request(handle, "", vr->name, naids, aids, nattrs, CA(attrs)); dusb_ca_del_array(handle, attrs, nattrs); if (!ret) { @@ -801,8 +770,8 @@ static int recv_flash (CalcHandle* handle, FlashContent* content, VarRequest* v content->data_type = vr->type; content->device_type = DEVICE_TYPE_83P; - q = data_length / FLASH_PAGE_SIZE; - r = data_length % FLASH_PAGE_SIZE; + const int q = data_length / FLASH_PAGE_SIZE; + const int r = data_length % FLASH_PAGE_SIZE; content->num_pages = q + 1; content->pages = tifiles_fp_create_array(content->num_pages); @@ -851,22 +820,20 @@ static int recv_flash_834pce (CalcHandle* handle, FlashContent* content, VarReq { static const uint16_t aids[] = { DUSB_AID_ARCHIVED, DUSB_AID_VAR_VERSION }; const int naids = sizeof(aids) / sizeof(uint16_t); - DUSBCalcAttr **attrs; const int nattrs = 1; char fldname[40], varname[40]; uint8_t *data; uint32_t data_length; - int ret; ticonv_varname_to_utf8_sn(handle->model, vr->name, handle->updat->text, sizeof(handle->updat->text), vr->type); ticalcs_update_label(handle); - attrs = dusb_ca_new_array(handle, nattrs); + DUSBCalcAttr** attrs = dusb_ca_new_array(handle, nattrs); attrs[0] = dusb_ca_new(handle, DUSB_AID_VAR_TYPE2, 4); attrs[0]->data[0] = 0xF0; attrs[0]->data[1] = 0x0F; attrs[0]->data[2] = 0x00; attrs[0]->data[3] = vr->type; - ret = dusb_cmd_s_var_request(handle, "", vr->name, naids, aids, nattrs, CA(attrs)); + int ret = dusb_cmd_s_var_request(handle, "", vr->name, naids, aids, nattrs, CA(attrs)); dusb_ca_del_array(handle, attrs, nattrs); if (!ret) { @@ -897,23 +864,23 @@ static int recv_flash_834pce (CalcHandle* handle, FlashContent* content, VarReq static int send_os (CalcHandle* handle, FlashContent* content) { - DUSBModeSet mode = { 2, 1, 0, 0, 0x0fa0 }; //MODE_BASIC; + const DUSBModeSet mode = { 2, 1, 0, 0, 0x0fa0 }; //MODE_BASIC; uint32_t pkt_size = 266; uint32_t os_size = 0; FlashContent *ptr; - unsigned int i, j; + unsigned int i; int boot = 0; int ret; // search for data header - for (ptr = content; ptr != NULL; ptr = ptr->next) + for (ptr = content; ptr != nullptr; ptr = ptr->next) { if (ptr->data_type == TI83p_AMS || ptr->data_type == TI83p_APPL) { break; } } - if (ptr == NULL) + if (ptr == nullptr) { return ERR_INVALID_PARAMETER; } @@ -921,7 +888,7 @@ static int send_os (CalcHandle* handle, FlashContent* content) { return ERR_INVALID_PARAMETER; } - if (ptr->pages == NULL) + if (ptr->pages == nullptr) { return ERR_INVALID_PARAMETER; } @@ -961,7 +928,6 @@ static int send_os (CalcHandle* handle, FlashContent* content) { static const uint16_t pids[] = { DUSB_PID_OS_MODE }; const int size = sizeof(pids) / sizeof(uint16_t); - DUSBCalcParam **params; // switch to BASIC mode ret = dusb_cmd_s_mode_set(handle, mode); @@ -981,7 +947,7 @@ static int send_os (CalcHandle* handle, FlashContent* content) { break; } - params = dusb_cp_new_array(handle, size); + DUSBCalcParam** params = dusb_cp_new_array(handle, size); ret = dusb_cmd_r_param_data(handle, size, params); if (ret) { @@ -1066,7 +1032,7 @@ static int send_os (CalcHandle* handle, FlashContent* content) } else { - for (j = 0; j < fp->size; j += 256) + for (unsigned int j = 0; j < fp->size; j += 256) { ret = dusb_cmd_s_os_data(handle, (uint16_t)(fp->addr + j), (uint8_t)fp->page, fp->flag, @@ -1102,25 +1068,25 @@ static int send_os (CalcHandle* handle, FlashContent* content) static int send_os_834pce (CalcHandle* handle, FlashContent* content) { - DUSBModeSet mode = { 2, 1, 0, 0, 0x0fa0 }; //MODE_BASIC; + const DUSBModeSet mode = { 2, 1, 0, 0, 0x0fa0 }; //MODE_BASIC; uint32_t pkt_size = 0x3ff; uint32_t hdr_size = 0; uint32_t hdr_offset = 0; const uint32_t memory_offset = 0x30000U; FlashContent *ptr; uint8_t *d; - int i, r, q; + int i; int ret; // search for data header - for (ptr = content; ptr != NULL; ptr = ptr->next) + for (ptr = content; ptr != nullptr; ptr = ptr->next) { if (ptr->data_type == TI83p_AMS || ptr->data_type == TI83p_APPL) { break; } } - if (ptr == NULL) + if (ptr == nullptr) { return ERR_INVALID_PARAMETER; } @@ -1128,7 +1094,7 @@ static int send_os_834pce (CalcHandle* handle, FlashContent* content) { return ERR_INVALID_PARAMETER; } - if (ptr->data_part == NULL) + if (ptr->data_part == nullptr) { return ERR_INVALID_PARAMETER; } @@ -1177,8 +1143,8 @@ static int send_os_834pce (CalcHandle* handle, FlashContent* content) } // send OS data - q = ptr->data_length / (pkt_size - 4); - r = ptr->data_length % (pkt_size - 4); + const int q = ptr->data_length / (pkt_size - 4); + const int r = ptr->data_length % (pkt_size - 4); handle->updat->cnt2 = 0; handle->updat->max2 = q; @@ -1231,22 +1197,20 @@ static int recv_idlist (CalcHandle* handle, uint8_t* id) { static const uint16_t aids[] = { DUSB_AID_ARCHIVED, DUSB_AID_VAR_VERSION }; const int naids = sizeof(aids) / sizeof(uint16_t); - DUSBCalcAttr **attrs; const int nattrs = 1; char folder[40], name[40]; uint8_t *data; - uint32_t i, varsize; - int ret; + uint32_t varsize; ticalcs_strlcpy(handle->updat->text, "ID-LIST", sizeof(handle->updat->text)); ticalcs_update_label(handle); - attrs = dusb_ca_new_array(handle, nattrs); + DUSBCalcAttr** attrs = dusb_ca_new_array(handle, nattrs); attrs[0] = dusb_ca_new(handle, DUSB_AID_VAR_TYPE2, 4); attrs[0]->data[0] = 0xF0; attrs[0]->data[1] = 0x07; attrs[0]->data[2] = 0x00; attrs[0]->data[3] = TI83p_IDLIST; - ret = dusb_cmd_s_var_request(handle, "", "IDList", naids, aids, nattrs, CA(attrs)); + int ret = dusb_cmd_s_var_request(handle, "", "IDList", naids, aids, nattrs, CA(attrs)); dusb_ca_del_array(handle, attrs, nattrs); if (!ret) { @@ -1257,7 +1221,7 @@ static int recv_idlist (CalcHandle* handle, uint8_t* id) ret = dusb_cmd_r_var_content(handle, &varsize, &data); if (!ret) { - i = data[9]; + uint32_t i = data[9]; data[9] = data[10]; data[10] = i; @@ -1281,9 +1245,8 @@ static int get_version (CalcHandle* handle, CalcInfos* infos); static int dump_rom_1 (CalcHandle* handle) { CalcInfos infos; - int ret; - ret = get_version(handle, &infos); + int ret = get_version(handle, &infos); if (!ret) { PAUSE(100); @@ -1325,9 +1288,8 @@ static int dump_rom_1 (CalcHandle* handle) static int dump_rom_2 (CalcHandle* handle, CalcDumpSize size, const char *filename) { CalcInfos infos; - int ret; - ret = get_version(handle, &infos); + int ret = get_version(handle, &infos); if (!ret) { PAUSE(100); @@ -1335,7 +1297,6 @@ static int dump_rom_2 (CalcHandle* handle, CalcDumpSize size, const char *filen { // The TI-eZ80 series does no longer provide direct remote program launch... // Therefore, use a less sophisticated and more complicated way to queue keypresses. - unsigned int i; static const uint16_t keys[] = { 0x40, 0x09, 0x09, 0xFC9C, /* Quit, Clear, Clear, Asm( */ 0xDA, 0xAB, 0xA8, 0xA6, /* prgm, R, O, M */ @@ -1345,7 +1306,7 @@ static int dump_rom_2 (CalcHandle* handle, CalcDumpSize size, const char *filen // Launch program by remote control PAUSE(200); - for (i = 0; i < sizeof(keys) / sizeof(keys[0]); i++) + for (unsigned int i = 0; i < sizeof(keys) / sizeof(keys[0]); i++) { ret = send_key(handle, (uint32_t)(keys[i])); if (ret) @@ -1380,22 +1341,20 @@ static int set_clock (CalcHandle* handle, CalcClock* _clock) { static const uint16_t pids[2] = { DUSB_PID_CLASSIC_CLK_SUPPORT, DUSB_PID_NEW_CLK_SUPPORT }; const int size = sizeof(pids) / sizeof(uint16_t); - DUSBCalcParam **params; - int ret; // get raw clock ticalcs_strlcpy(handle->updat->text, _("Getting clock..."), sizeof(handle->updat->text)); ticalcs_update_label(handle); - params = dusb_cp_new_array(handle, size); - ret = dusb_cmd_s_param_request(handle, size, pids); + DUSBCalcParam** params = dusb_cp_new_array(handle, size); + int ret = dusb_cmd_s_param_request(handle, size, pids); if (!ret) { ret = dusb_cmd_r_param_data(handle, size, params); if (!ret) { - int classic_clock = !!params[0]->ok && !!!params[1]->ok; - int new_clock = !!!params[0]->ok && !!params[1]->ok; + const int classic_clock = !!params[0]->ok && !!!params[1]->ok; + const int new_clock = !!!params[0]->ok && !!params[1]->ok; if ((!classic_clock && !new_clock) || (classic_clock && new_clock)) { ticalcs_warning(_("Could not determine clock type: %u %u"), params[0]->ok, params[1]->ok); @@ -1530,22 +1489,20 @@ static int get_clock (CalcHandle* handle, CalcClock* _clock) DUSB_PID_CLK_SECONDS, DUSB_PID_CLK_MINUTES, DUSB_PID_CLK_HOURS, DUSB_PID_CLK_DAY, DUSB_PID_CLK_MONTH, DUSB_PID_CLK_YEAR }; const int size = sizeof(pids) / sizeof(uint16_t); - DUSBCalcParam **params; - int ret; // get raw clock ticalcs_strlcpy(handle->updat->text, _("Getting clock..."), sizeof(handle->updat->text)); ticalcs_update_label(handle); - params = dusb_cp_new_array(handle, size); - ret = dusb_cmd_s_param_request(handle, size, pids); + DUSBCalcParam** params = dusb_cp_new_array(handle, size); + int ret = dusb_cmd_s_param_request(handle, size, pids); if (!ret) { ret = dusb_cmd_r_param_data(handle, size, params); if (!ret) { - int classic_clock = !!params[0]->ok && !!!params[1]->ok; - int new_clock = !!!params[0]->ok && !!params[1]->ok; + const int classic_clock = !!params[0]->ok && !!!params[1]->ok; + const int new_clock = !!!params[0]->ok && !!params[1]->ok; if ((!classic_clock && !new_clock) || (classic_clock && new_clock)) { ticalcs_warning(_("Could not determine clock type: %u %u"), params[0]->ok, params[1]->ok); @@ -1559,8 +1516,8 @@ static int get_clock (CalcHandle* handle, CalcClock* _clock) { struct tm ref, cur; time_t r, c, now; - uint8_t * data = params[3]->data; - uint32_t calc_time = (((uint32_t)data[0]) << 24) | (((uint32_t)data[1]) << 16) | (((uint32_t)data[2]) << 8) | (data[3] << 0); + const uint8_t * data = params[3]->data; + const uint32_t calc_time = (((uint32_t)data[0]) << 24) | (((uint32_t)data[1]) << 16) | (((uint32_t)data[2]) << 8) | (data[3] << 0); ticalcs_info("%s", _("Found valid classic clock")); @@ -1617,7 +1574,7 @@ static int get_clock (CalcHandle* handle, CalcClock* _clock) && params[10]->ok && params[10]->size == 1 && params[11]->ok && params[11]->size == 2) { - uint8_t * data = params[11]->data; + const uint8_t * data = params[11]->data; ticalcs_info("%s", _("Found valid new clock")); @@ -1647,22 +1604,19 @@ static int get_clock (CalcHandle* handle, CalcClock* _clock) static int del_var (CalcHandle* handle, VarRequest* vr) { - DUSBCalcAttr **attr; const int size = 1; - char *utf8; - int ret; - utf8 = ticonv_varname_to_utf8(handle->model, vr->name, vr->type); + char* utf8 = ticonv_varname_to_utf8(handle->model, vr->name, vr->type); ticalcs_slprintf(handle->updat->text, sizeof(handle->updat->text), _("Deleting %s..."), utf8); ticonv_utf8_free(utf8); ticalcs_update_label(handle); - attr = dusb_ca_new_array(handle, size); + DUSBCalcAttr** attr = dusb_ca_new_array(handle, size); attr[0] = dusb_ca_new(handle, 0x0011, 4); attr[0]->data[0] = 0xF0; attr[0]->data[1] = 0x0B; attr[0]->data[2] = 0x00; attr[0]->data[3] = vr->type; - ret = dusb_cmd_s_var_delete(handle, "", vr->name, size, CA(attr)); + int ret = dusb_cmd_s_var_delete(handle, "", vr->name, size, CA(attr)); dusb_ca_del_array(handle, attr, size); if (!ret) { @@ -1674,16 +1628,14 @@ static int del_var (CalcHandle* handle, VarRequest* vr) static int rename_var (CalcHandle* handle, VarRequest* oldname, VarRequest* newname) { - DUSBCalcAttr **attrs; const int size = 1; - int ret; - attrs = dusb_ca_new_array(handle, size); + DUSBCalcAttr** attrs = dusb_ca_new_array(handle, size); attrs[0] = dusb_ca_new(handle, DUSB_AID_VAR_TYPE2, 4); attrs[0]->data[0] = 0xF0; attrs[0]->data[1] = 0x07; attrs[0]->data[2] = 0x00; attrs[0]->data[3] = oldname->type; - ret = dusb_cmd_s_var_modify(handle, "", oldname->name, 1, CA(attrs), "", newname->name, 0, NULL); + int ret = dusb_cmd_s_var_modify(handle, "", oldname->name, 1, CA(attrs), "", newname->name, 0, nullptr); dusb_ca_del_array(handle, attrs, size); if (!ret) { @@ -1695,21 +1647,17 @@ static int rename_var (CalcHandle* handle, VarRequest* oldname, VarRequest* new static int change_attr (CalcHandle* handle, VarRequest* vr, FileAttr attr) { - DUSBCalcAttr **srcattrs; - DUSBCalcAttr **dstattrs; - int ret; - - srcattrs = dusb_ca_new_array(handle, 1); + DUSBCalcAttr** srcattrs = dusb_ca_new_array(handle, 1); srcattrs[0] = dusb_ca_new(handle, DUSB_AID_VAR_TYPE2, 4); srcattrs[0]->data[0] = 0xF0; srcattrs[0]->data[1] = 0x07; srcattrs[0]->data[2] = 0x00; srcattrs[0]->data[3] = vr->type; - dstattrs = dusb_ca_new_array(handle, 1); + DUSBCalcAttr** dstattrs = dusb_ca_new_array(handle, 1); dstattrs[0] = dusb_ca_new(handle, DUSB_AID_ARCHIVED, 1); /* use 0xff here rather than 0x01 to work around an OS bug */ dstattrs[0]->data[0] = (attr == ATTRB_ARCHIVED ? 0xff : 0x00); - ret = dusb_cmd_s_var_modify(handle, "", vr->name, 1, CA(srcattrs), "", vr->name, 1, CA(dstattrs)); + int ret = dusb_cmd_s_var_modify(handle, "", vr->name, 1, CA(srcattrs), "", vr->name, 1, CA(dstattrs)); dusb_ca_del_array(handle, dstattrs, 1); dusb_ca_del_array(handle, srcattrs, 1); if (!ret) @@ -1732,19 +1680,17 @@ static int get_version (CalcHandle* handle, CalcInfos* infos) DUSB_PID_BATTERY_ENOUGH, DUSB_PID_MATH_CAPABILITIES, DUSB_PID_PYTHON_ON_BOARD, DUSB_PID_CLASSIC_CLK_SUPPORT }; const int size = sizeof(pids) / sizeof(uint16_t); - DUSBCalcParam **params; int i = 0; - int ret; ticalcs_strlcpy(handle->updat->text, _("Getting version..."), sizeof(handle->updat->text)); ticalcs_update_label(handle); memset(infos, 0, sizeof(CalcInfos)); - params = dusb_cp_new_array(handle, size); + DUSBCalcParam** params = dusb_cp_new_array(handle, size); // TODO rewrite this function to ask for parameters in multiple phases, starting with 0x000A, then // model-dependent sets of parameters. That's how TI-Connect CE 5.x does. - ret = dusb_cmd_s_param_request(handle, size, pids); + int ret = dusb_cmd_s_param_request(handle, size, pids); if (!ret) { ret = dusb_cmd_r_param_data(handle, size, params); diff --git a/libticalcs/trunk/src/calc_89t.cc b/libticalcs/trunk/src/calc_89t.cc index a3d6e1672..58eed865e 100644 --- a/libticalcs/trunk/src/calc_89t.cc +++ b/libticalcs/trunk/src/calc_89t.cc @@ -54,10 +54,9 @@ static int is_ready (CalcHandle* handle) { - int ret; static const DUSBModeSet mode = DUSB_MODE_NORMAL; - ret = dusb_cmd_s_mode_set(handle, mode); + int ret = dusb_cmd_s_mode_set(handle, mode); if (!ret) { ret = dusb_cmd_r_mode_ack(handle); @@ -68,10 +67,8 @@ static int is_ready (CalcHandle* handle) static int send_key (CalcHandle* handle, uint32_t key) { - int ret; - PAUSE(25); // this pause is needed between 2 keys - ret = dusb_cmd_s_execute(handle, "", "", DUSB_EID_KEY, "", (uint16_t)key); + int ret = dusb_cmd_s_execute(handle, "", "", DUSB_EID_KEY, "", (uint16_t)key); if (!ret) { ret = dusb_cmd_r_data_ack(handle); @@ -83,7 +80,6 @@ static int send_key (CalcHandle* handle, uint32_t key) static int execute (CalcHandle* handle, VarEntry *ve, const char *args) { uint8_t action; - int ret; switch (ve->type) { @@ -92,7 +88,7 @@ static int execute (CalcHandle* handle, VarEntry *ve, const char *args) default: action = DUSB_EID_PRGM; break; } - ret = dusb_cmd_s_execute(handle, ve->folder, ve->name, action, args, 0); + int ret = dusb_cmd_s_execute(handle, ve->folder, ve->name, action, args, 0); if (!ret) { ret = dusb_cmd_r_data_ack(handle); @@ -105,11 +101,9 @@ static int recv_screen (CalcHandle* handle, CalcScreenCoord* sc, uint8_t** bitm { static const uint16_t pid[] = { DUSB_PID_SCREENSHOT }; const int size = 1; - DUSBCalcParam **param; - int ret; *bitmap = (uint8_t *)ticalcs_alloc_screen(TI89T_COLS * TI89T_ROWS / 8); - if (*bitmap == NULL) + if (*bitmap == nullptr) { return ERR_MALLOC; } @@ -120,8 +114,8 @@ static int recv_screen (CalcHandle* handle, CalcScreenCoord* sc, uint8_t** bitm sc->clipped_height = TI89T_ROWS_VISIBLE; sc->pixel_format = CALC_PIXFMT_MONO; - param = dusb_cp_new_array(handle, size); - ret = dusb_cmd_s_param_request(handle, size, pid); + DUSBCalcParam** param = dusb_cp_new_array(handle, size); + int ret = dusb_cmd_s_param_request(handle, size, pid); while (!ret) { ret = dusb_cmd_r_param_data(handle, size, param); @@ -139,11 +133,11 @@ static int recv_screen (CalcHandle* handle, CalcScreenCoord* sc, uint8_t** bitm // Clip the unused part of the screen (nevertheless usable with asm programs) if (sc->format == SCREEN_CLIPPED) { - int i, j, k; + int i, j; for (i = 0, j = 0; j < TI89T_ROWS_VISIBLE; j++) { - for (k = 0; k < (TI89T_COLS_VISIBLE >> 3); k++) + for (int k = 0; k < (TI89T_COLS_VISIBLE >> 3); k++) { (*bitmap)[i++] = (*bitmap)[j * (TI89T_COLS >> 3) + k]; } @@ -161,21 +155,18 @@ static int get_dirlist (CalcHandle* handle, GNode** vars, GNode** apps) { static const uint16_t aids[] = { DUSB_AID_VAR_TYPE, DUSB_AID_ARCHIVED, DUSB_AID_4APPVAR, DUSB_AID_VAR_SIZE, DUSB_AID_LOCKED, DUSB_AID_UNKNOWN_42 }; const int size = sizeof(aids) / sizeof(uint16_t); - int ret; - DUSBCalcAttr **attr; - GNode *root, *folder = NULL; + GNode *root, *folder = nullptr; char fldname[40]; char varname[40]; char folder_name[40] = ""; - char *u1, *u2; - ret = dirlist_init_trees(handle, vars, apps); + int ret = dirlist_init_trees(handle, vars, apps); if (ret) { return ret; } - root = dirlist_create_append_node(NULL, apps); + root = dirlist_create_append_node(nullptr, apps); if (!root) { return ERR_MALLOC; @@ -186,10 +177,7 @@ static int get_dirlist (CalcHandle* handle, GNode** vars, GNode** apps) { for (;;) { - VarEntry *ve; - GNode *node; - - attr = dusb_ca_new_array(handle, size); + DUSBCalcAttr** attr = dusb_ca_new_array(handle, size); ret = dusb_cmd_r_var_header(handle, fldname, varname, attr); if (ret) { @@ -202,7 +190,7 @@ static int get_dirlist (CalcHandle* handle, GNode** vars, GNode** apps) break; } - ve = tifiles_ve_create(); + VarEntry* ve = tifiles_ve_create(); ticalcs_strlcpy(ve->folder, fldname, sizeof(ve->folder)); ticalcs_strlcpy(ve->name, varname, sizeof(ve->name)); ve->size = ( (((uint32_t)(attr[3]->data[0])) << 24) @@ -234,7 +222,7 @@ static int get_dirlist (CalcHandle* handle, GNode** vars, GNode** apps) } else { - node = dirlist_create_append_node(ve, (ve->type != TI89_APPL) ? &folder : &root); + const GNode* node = dirlist_create_append_node(ve, (ve->type != TI89_APPL) ? &folder : &root); if (!node) { ret = ERR_MALLOC; @@ -249,10 +237,10 @@ static int get_dirlist (CalcHandle* handle, GNode** vars, GNode** apps) ve->attr, ve->size); */ - if (NULL != folder) + if (nullptr != folder) { - u1 = ticonv_varname_to_utf8(handle->model, ((VarEntry *) (folder->data))->name, -1); - u2 = ticonv_varname_to_utf8(handle->model, ve->name, ve->type); + char* u1 = ticonv_varname_to_utf8(handle->model, ((VarEntry*)(folder->data))->name, -1); + char* u2 = ticonv_varname_to_utf8(handle->model, ve->name, ve->type); ticalcs_slprintf(handle->updat->text, sizeof(handle->updat->text), _("Parsing %s/%s"), u1, u2); ticonv_utf8_free(u2); ticonv_utf8_free(u1); @@ -268,11 +256,10 @@ static int get_memfree (CalcHandle* handle, uint32_t* ram, uint32_t* flash) { static const uint16_t pids[] = { DUSB_PID_FREE_RAM, DUSB_PID_FREE_FLASH }; const int size = sizeof(pids) / sizeof(uint16_t); - DUSBCalcParam **params; int ret; - params = dusb_cp_new_array(handle, size); - if (params != NULL) + DUSBCalcParam** params = dusb_cp_new_array(handle, size); + if (params != nullptr) { ret = dusb_cmd_s_param_request(handle, size, pids); if (!ret) @@ -309,19 +296,15 @@ static int get_memfree (CalcHandle* handle, uint32_t* ram, uint32_t* flash) static int send_var (CalcHandle* handle, CalcMode mode, FileContent* content) { - unsigned int i; int ret = 0; handle->updat->cnt2 = 0; handle->updat->max2 = content->num_entries; - for (i = 0; i < content->num_entries; i++) + for (unsigned int i = 0; i < content->num_entries; i++) { - DUSBCalcAttr **attrs; const int nattrs = 4; VarEntry * entry = content->entries[i]; - uint32_t pkt_size; - uint32_t size; char varname[18]; if (!ticalcs_validate_varentry(entry)) @@ -348,7 +331,7 @@ static int send_var (CalcHandle* handle, CalcMode mode, FileContent* content) ticonv_varname_to_utf8_sn(handle->model, varname, handle->updat->text, sizeof(handle->updat->text), entry->type); ticalcs_update_label(handle); - attrs = dusb_ca_new_array(handle, nattrs); + DUSBCalcAttr** attrs = dusb_ca_new_array(handle, nattrs); attrs[0] = dusb_ca_new(handle, DUSB_AID_VAR_TYPE, 4); attrs[0]->data[0] = 0xF0; attrs[0]->data[1] = 0x0C; attrs[0]->data[2] = 0x00; attrs[0]->data[3] = entry->type; @@ -359,7 +342,7 @@ static int send_var (CalcHandle* handle, CalcMode mode, FileContent* content) attrs[3] = dusb_ca_new(handle, DUSB_AID_LOCKED, 1); attrs[3]->data[0] = entry->attr == ATTRB_LOCKED ? 1 : 0; - size = entry->size; + const uint32_t size = entry->size; if (entry->size >= 65536U) { ticalcs_critical("%s: variable size %u is suspiciously large", __FUNCTION__, size); @@ -394,7 +377,7 @@ static int send_var (CalcHandle* handle, CalcMode mode, FileContent* content) */ if (size & 1) { - pkt_size = size / 10; + uint32_t pkt_size = size / 10; pkt_size >>= 1; pkt_size <<= 1; @@ -408,7 +391,7 @@ static int send_var (CalcHandle* handle, CalcMode mode, FileContent* content) { break; } - ret = dusb_recv_buf_size_alloc(handle, NULL); + ret = dusb_recv_buf_size_alloc(handle, nullptr); if (ret) { break; @@ -445,22 +428,19 @@ static int recv_var (CalcHandle* handle, CalcMode mode, FileContent* content, V { static const uint16_t aids[] = { DUSB_AID_ARCHIVED, DUSB_AID_VAR_VERSION, DUSB_AID_LOCKED }; const int naids = sizeof(aids) / sizeof(uint16_t); - DUSBCalcAttr **attrs; const int nattrs = 1; char fldname[40], varname[40]; uint8_t *data; - VarEntry *ve; - int ret; ticonv_varname_to_utf8_sn(handle->model, vr->name, handle->updat->text, sizeof(handle->updat->text), vr->type); ticalcs_update_label(handle); - attrs = dusb_ca_new_array(handle, nattrs); + DUSBCalcAttr** attrs = dusb_ca_new_array(handle, nattrs); attrs[0] = dusb_ca_new(handle, DUSB_AID_VAR_TYPE2, 4); attrs[0]->data[0] = 0xF0; attrs[0]->data[1] = 0x0C; attrs[0]->data[2] = 0x00; attrs[0]->data[3] = vr->type; - ret = dusb_cmd_s_var_request(handle, vr->folder, vr->name, naids, aids, nattrs, CA(attrs)); + int ret = dusb_cmd_s_var_request(handle, vr->folder, vr->name, naids, aids, nattrs, CA(attrs)); dusb_ca_del_array(handle, attrs, nattrs); if (!ret) { @@ -468,7 +448,7 @@ static int recv_var (CalcHandle* handle, CalcMode mode, FileContent* content, V ret = dusb_cmd_r_var_header(handle, fldname, varname, attrs); if (!ret) { - ret = dusb_cmd_r_var_content(handle, NULL, &data); + ret = dusb_cmd_r_var_content(handle, nullptr, &data); if (!ret) { content->model = handle->model; @@ -476,7 +456,7 @@ static int recv_var (CalcHandle* handle, CalcMode mode, FileContent* content, V content->num_entries = 1; content->entries = tifiles_ve_create_array(1); - ve = content->entries[0] = tifiles_ve_create(); + VarEntry* ve = content->entries[0] = tifiles_ve_create(); memcpy(ve, vr, sizeof(VarEntry)); ve->data = (uint8_t *)tifiles_ve_alloc_data(ve->size); @@ -498,13 +478,11 @@ static int send_all_vars_backup (CalcHandle* handle, FileContent* content) static int send_flash (CalcHandle* handle, FlashContent* content) { - FlashContent *ptr; - DUSBCalcAttr **attrs; const int nattrs = 4; int ret = 0; // send all headers except license - for (ptr = content; ptr != NULL; ptr = ptr->next) + for (FlashContent* ptr = content; ptr != nullptr; ptr = ptr->next) { if (ptr->data_type == TI89_LICENSE) { @@ -517,7 +495,7 @@ static int send_flash (CalcHandle* handle, FlashContent* content) ticonv_varname_to_utf8_sn(handle->model, ptr->name, handle->updat->text, sizeof(handle->updat->text), ptr->data_type); ticalcs_update_label(handle); - attrs = dusb_ca_new_array(handle, nattrs); + DUSBCalcAttr** attrs = dusb_ca_new_array(handle, nattrs); attrs[0] = dusb_ca_new(handle, DUSB_AID_VAR_TYPE, 4); attrs[0]->data[0] = 0xF0; attrs[0]->data[1] = 0x0C; attrs[0]->data[2] = 0x00; attrs[0]->data[3] = ptr->data_type; @@ -563,22 +541,20 @@ static int recv_flash (CalcHandle* handle, FlashContent* content, VarRequest* v { static const uint16_t aids[] = { DUSB_AID_ARCHIVED, DUSB_AID_VAR_VERSION, DUSB_AID_LOCKED }; const int naids = sizeof(aids) / sizeof(uint16_t); - DUSBCalcAttr **attrs; const int nattrs = 1; char fldname[40], varname[40]; uint8_t *data; uint32_t data_length; - int ret; ticonv_varname_to_utf8_sn(handle->model, vr->name, handle->updat->text, sizeof(handle->updat->text), vr->type); ticalcs_update_label(handle); - attrs = dusb_ca_new_array(handle, nattrs); + DUSBCalcAttr** attrs = dusb_ca_new_array(handle, nattrs); attrs[0] = dusb_ca_new(handle, DUSB_AID_VAR_TYPE2, 4); attrs[0]->data[0] = 0xF0; attrs[0]->data[1] = 0x0C; attrs[0]->data[2] = 0x00; attrs[0]->data[3] = vr->type; - ret = dusb_cmd_s_var_request(handle, "", vr->name, naids, aids, nattrs, CA(attrs)); + int ret = dusb_cmd_s_var_request(handle, "", vr->name, naids, aids, nattrs, CA(attrs)); dusb_ca_del_array(handle, attrs, nattrs); if (!ret) { @@ -608,24 +584,24 @@ static int recv_flash (CalcHandle* handle, FlashContent* content, VarRequest* v static int send_os (CalcHandle* handle, FlashContent* content) { - DUSBModeSet mode = { 2, 1, 0, 0, 0x0fa0 }; //MODE_BASIC; + const DUSBModeSet mode = { 2, 1, 0, 0, 0x0fa0 }; //MODE_BASIC; uint32_t pkt_size = 0x3ff; uint32_t hdr_size = 0; uint32_t hdr_offset = 0; FlashContent *ptr; uint8_t *d; - int i, r, q; + int i; int ret; // search for data header - for (ptr = content; ptr != NULL; ptr = ptr->next) + for (ptr = content; ptr != nullptr; ptr = ptr->next) { if (ptr->data_type == TI89_AMS || ptr->data_type == TI89_APPL) { break; } } - if (ptr == NULL) + if (ptr == nullptr) { return ERR_INVALID_PARAMETER; } @@ -633,7 +609,7 @@ static int send_os (CalcHandle* handle, FlashContent* content) { return ERR_INVALID_PARAMETER; } - if (ptr->data_part == NULL) + if (ptr->data_part == nullptr) { return ERR_INVALID_PARAMETER; } @@ -682,8 +658,8 @@ static int send_os (CalcHandle* handle, FlashContent* content) } // send OS data - q = ptr->data_length / 0x2000; - r = ptr->data_length % 0x2000; + const int q = ptr->data_length / 0x2000; + const int r = ptr->data_length % 0x2000; handle->updat->cnt2 = 0; handle->updat->max2 = q; @@ -736,14 +712,13 @@ static int recv_idlist (CalcHandle* handle, uint8_t* id) { static const uint16_t pid[] = { DUSB_PID_FULL_ID }; const int size = 1; - DUSBCalcParam **params; int ret; ticalcs_strlcpy(handle->updat->text, "ID-LIST", sizeof(handle->updat->text)); ticalcs_update_label(handle); - params = dusb_cp_new_array(handle, size); - if (params != NULL) + DUSBCalcParam** params = dusb_cp_new_array(handle, size); + if (params != nullptr) { ret = dusb_cmd_s_param_request(handle, size, pid); if (!ret) @@ -776,13 +751,10 @@ static int recv_idlist (CalcHandle* handle, uint8_t* id) static int dump_rom_1 (CalcHandle* handle) { - DUSBCalcParam *param; - int ret; - // Go back to HOME screen - param = dusb_cp_new(handle, DUSB_PID_HOMESCREEN, 1); + DUSBCalcParam* param = dusb_cp_new(handle, DUSB_PID_HOMESCREEN, 1); param->data[0] = 1; - ret = dusb_cmd_s_param_set(handle, param); + int ret = dusb_cmd_s_param_set(handle, param); dusb_cp_del(handle, param); if (!ret) { @@ -800,9 +772,7 @@ static int dump_rom_1 (CalcHandle* handle) static int dump_rom_2 (CalcHandle* handle, CalcDumpSize size, const char *filename) { - int ret; - - ret = dusb_cmd_s_execute(handle, "main", "romdump", DUSB_EID_ASM, "", 0); + int ret = dusb_cmd_s_execute(handle, "main", "romdump", DUSB_EID_ASM, "", 0); if (!ret) { ret = dusb_cmd_r_data_ack(handle); @@ -884,15 +854,13 @@ static int get_clock (CalcHandle* handle, CalcClock* _clock) { static const uint16_t pids[5] = { DUSB_PID_CLASSIC_CLK_SUPPORT, DUSB_PID_CLK_ON, DUSB_PID_CLK_SEC_SINCE_1997, DUSB_PID_CLK_DATE_FMT, DUSB_PID_CLK_TIME_FMT }; const int size = sizeof(pids) / sizeof(uint16_t); - DUSBCalcParam **params; - int ret; // get raw clock ticalcs_strlcpy(handle->updat->text, _("Getting clock..."), sizeof(handle->updat->text)); ticalcs_update_label(handle); - params = dusb_cp_new_array(handle, size); - ret = dusb_cmd_s_param_request(handle, size, pids); + DUSBCalcParam** params = dusb_cp_new_array(handle, size); + int ret = dusb_cmd_s_param_request(handle, size, pids); if (!ret) { ret = dusb_cmd_r_param_data(handle, size, params); @@ -913,8 +881,8 @@ static int get_clock (CalcHandle* handle, CalcClock* _clock) { struct tm ref, cur; time_t r, c, now; - uint8_t * data = params[2]->data; - uint32_t calc_time = (((uint32_t)data[0]) << 24) | (((uint32_t)data[1]) << 16) | (((uint32_t)data[2]) << 8) | (data[3] << 0); + const uint8_t * data = params[2]->data; + const uint32_t calc_time = (((uint32_t)data[0]) << 24) | (((uint32_t)data[1]) << 16) | (((uint32_t)data[2]) << 8) | (data[3] << 0); ticalcs_info("%s", _("Found valid classic clock")); @@ -969,24 +937,21 @@ static int get_clock (CalcHandle* handle, CalcClock* _clock) static int del_var (CalcHandle* handle, VarRequest* vr) { - DUSBCalcAttr **attr; const int size = 1; char varname[68]; - char *utf8; - int ret; tifiles_build_fullname(handle->model, varname, vr->folder, vr->name); - utf8 = ticonv_varname_to_utf8(handle->model, varname, vr->type); + char* utf8 = ticonv_varname_to_utf8(handle->model, varname, vr->type); ticalcs_slprintf(handle->updat->text, sizeof(handle->updat->text), _("Deleting %s..."), utf8); ticonv_utf8_free(utf8); ticalcs_update_label(handle); - attr = dusb_ca_new_array(handle, size); + DUSBCalcAttr** attr = dusb_ca_new_array(handle, size); attr[0] = dusb_ca_new(handle, DUSB_AID_VAR_TYPE2, 4); attr[0]->data[0] = 0xF0; attr[0]->data[1] = 0x0C; attr[0]->data[2] = 0x00; attr[0]->data[3] = vr->type; - ret = dusb_cmd_s_var_delete(handle, vr->folder, vr->name, size, CA(attr)); + int ret = dusb_cmd_s_var_delete(handle, vr->folder, vr->name, size, CA(attr)); dusb_ca_del_array(handle, attr, size); if (!ret) { @@ -998,27 +963,24 @@ static int del_var (CalcHandle* handle, VarRequest* vr) static int rename_var (CalcHandle* handle, VarRequest* oldname, VarRequest* newname) { - DUSBCalcAttr **attrs; const int size = 1; char varname1[68], varname2[68]; - char *utf81, *utf82; - int ret; tifiles_build_fullname(handle->model, varname1, oldname->folder, oldname->name); tifiles_build_fullname(handle->model, varname2, newname->folder, newname->name); - utf81 = ticonv_varname_to_utf8(handle->model, varname1, oldname->type); - utf82 = ticonv_varname_to_utf8(handle->model, varname2, newname->type); + char* utf81 = ticonv_varname_to_utf8(handle->model, varname1, oldname->type); + char* utf82 = ticonv_varname_to_utf8(handle->model, varname2, newname->type); ticalcs_slprintf(handle->updat->text, sizeof(handle->updat->text), _("Renaming %s to %s..."), utf81, utf82); ticonv_utf8_free(utf82); ticonv_utf8_free(utf81); ticalcs_update_label(handle); - attrs = dusb_ca_new_array(handle, size); + DUSBCalcAttr** attrs = dusb_ca_new_array(handle, size); attrs[0] = dusb_ca_new(handle, DUSB_AID_VAR_TYPE2, 4); attrs[0]->data[0] = 0xF0; attrs[0]->data[1] = 0x0C; attrs[0]->data[2] = 0x00; attrs[0]->data[3] = oldname->type; - ret = dusb_cmd_s_var_modify(handle, oldname->folder, oldname->name, 1, CA(attrs), newname->folder, newname->name, 0, NULL); + int ret = dusb_cmd_s_var_modify(handle, oldname->folder, oldname->name, 1, CA(attrs), newname->folder, newname->name, 0, nullptr); dusb_ca_del_array(handle, attrs, size); if (!ret) { @@ -1030,22 +992,19 @@ static int rename_var (CalcHandle* handle, VarRequest* oldname, VarRequest* new static int change_attr (CalcHandle* handle, VarRequest* vr, FileAttr attr) { - DUSBCalcAttr **srcattrs; - DUSBCalcAttr **dstattrs; int ret = 0; - char *utf8; - utf8 = ticonv_varname_to_utf8(handle->model, vr->folder, -1); + char* utf8 = ticonv_varname_to_utf8(handle->model, vr->folder, -1); ticalcs_slprintf(handle->updat->text, sizeof(handle->updat->text), _("Changing attributes of %s..."), utf8); ticonv_utf8_free(utf8); ticalcs_update_label(handle); - srcattrs = dusb_ca_new_array(handle, 1); + DUSBCalcAttr** srcattrs = dusb_ca_new_array(handle, 1); srcattrs[0] = dusb_ca_new(handle, DUSB_AID_VAR_TYPE2, 4); srcattrs[0]->data[0] = 0xF0; srcattrs[0]->data[1] = 0x0C; srcattrs[0]->data[2] = 0x00; srcattrs[0]->data[3] = vr->type; - dstattrs = dusb_ca_new_array(handle, 2); + DUSBCalcAttr** dstattrs = dusb_ca_new_array(handle, 2); dstattrs[0] = dusb_ca_new(handle, DUSB_AID_ARCHIVED, 1); dstattrs[0]->data[0] = (attr == ATTRB_ARCHIVED ? 0x01 : 0x00); dstattrs[1] = dusb_ca_new(handle, DUSB_AID_LOCKED, 1); @@ -1065,20 +1024,17 @@ static int change_attr (CalcHandle* handle, VarRequest* vr, FileAttr attr) static int new_folder (CalcHandle* handle, VarRequest* vr) { uint8_t data[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0x40, 0x00, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x23 }; - char *fldname = vr->folder; - DUSBCalcParam *param; - DUSBCalcAttr **attrs; + const char *fldname = vr->folder; const int nattrs = 4; - char *utf8; int ret; - utf8 = ticonv_varname_to_utf8(handle->model, vr->folder, -1); + char* utf8 = ticonv_varname_to_utf8(handle->model, vr->folder, -1); ticalcs_slprintf(handle->updat->text, sizeof(handle->updat->text), _("Creating %s..."), utf8); ticonv_utf8_free(utf8); ticalcs_update_label(handle); // send empty expression in specified folder - attrs = dusb_ca_new_array(handle, nattrs); + DUSBCalcAttr** attrs = dusb_ca_new_array(handle, nattrs); attrs[0] = dusb_ca_new(handle, DUSB_AID_VAR_TYPE, 4); attrs[0]->data[0] = 0xF0; attrs[0]->data[1] = 0x0C; attrs[0]->data[2] = 0x00; attrs[0]->data[3] = 0x00; @@ -1123,7 +1079,7 @@ static int new_folder (CalcHandle* handle, VarRequest* vr) } // go back to HOME screen - param = dusb_cp_new(handle, DUSB_PID_HOMESCREEN, 1); + DUSBCalcParam* param = dusb_cp_new(handle, DUSB_PID_HOMESCREEN, 1); param->data[0] = 1; ret = dusb_cmd_s_param_set(handle, param); dusb_cp_del(handle, param); @@ -1161,8 +1117,6 @@ static int get_version (CalcHandle* handle, CalcInfos* infos) }; // Titanium can't manage more than 16 parameters at a time const int size1 = sizeof(pids1) / sizeof(uint16_t); const int size2 = sizeof(pids2) / sizeof(uint16_t); - DUSBCalcParam **params1; - DUSBCalcParam **params2; int i = 0; int ret = 0; @@ -1170,8 +1124,8 @@ static int get_version (CalcHandle* handle, CalcInfos* infos) ticalcs_update_label(handle); memset(infos, 0, sizeof(CalcInfos)); - params1 = dusb_cp_new_array(handle, size1); - params2 = dusb_cp_new_array(handle, size2); + DUSBCalcParam** params1 = dusb_cp_new_array(handle, size1); + DUSBCalcParam** params2 = dusb_cp_new_array(handle, size2); do { diff --git a/libticalcs/trunk/src/calc_8x.cc b/libticalcs/trunk/src/calc_8x.cc index 7db2e9d7f..e1c91ec15 100644 --- a/libticalcs/trunk/src/calc_8x.cc +++ b/libticalcs/trunk/src/calc_8x.cc @@ -90,10 +90,9 @@ static int is_ready (CalcHandle* handle) { - int ret; uint16_t status; - ret = SEND_RDY(handle); + int ret = SEND_RDY(handle); if (!ret) { ret = RECV_ACK(handle, &status); @@ -108,10 +107,9 @@ static int is_ready (CalcHandle* handle) static int send_key (CalcHandle* handle, uint32_t key) { - int ret; uint16_t status; - ret = SEND_KEY(handle, (uint16_t)key); + int ret = SEND_KEY(handle, (uint16_t)key); if (!ret) { ret = RECV_ACK(handle, &status); @@ -126,11 +124,9 @@ static int send_key (CalcHandle* handle, uint32_t key) static int execute (CalcHandle* handle, VarEntry *ve, const char* args) { - int ret; - // Go back to homescreen PAUSE(200); - ret = send_key(handle, KEY83_Quit); + int ret = send_key(handle, KEY83_Quit); if (!ret) { ret = send_key(handle, KEY83_Clear); @@ -156,8 +152,7 @@ static int execute (CalcHandle* handle, VarEntry *ve, const char* args) ret = send_key(handle, KEY83_Exec); if (!ret) { - unsigned int i; - for (i = 0; !ret && i < strlen(ve->name); i++) + for (unsigned int i = 0; !ret && i < strlen(ve->name); i++) { const CalcKey *ck = ticalcs_keys_83((ve->name)[i]); ret = send_key(handle, (uint32_t)(ck->normal.value)); @@ -178,11 +173,8 @@ static int execute (CalcHandle* handle, VarEntry *ve, const char* args) static int recv_screen_80 (CalcHandle* handle, CalcScreenCoord* sc, uint8_t** bitmap) { - int ret; - uint8_t * buffer; - *bitmap = (uint8_t *)ticalcs_alloc_screen(TI80_COLS * TI80_ROWS / 8); - if (*bitmap == NULL) + if (*bitmap == nullptr) { return ERR_MALLOC; } @@ -193,21 +185,21 @@ static int recv_screen_80 (CalcHandle* handle, CalcScreenCoord* sc, uint8_t** b sc->clipped_height = TI80_ROWS; sc->pixel_format = CALC_PIXFMT_MONO; - ret = ti80_send_SCR(handle); + int ret = ti80_send_SCR(handle); if (!ret) { - ret = ti80_recv_ACK(handle, NULL); + ret = ti80_recv_ACK(handle, nullptr); if (!ret) { uint16_t max_cnt; ret = ti80_recv_XDP(handle, &max_cnt, (uint8_t *)handle->buffer); if (!ret) { - int stripe, row, i = 0; - buffer = (uint8_t *)(handle->buffer); - for (stripe = 7; stripe >= 0; stripe--) + int i = 0; + const uint8_t* buffer = (uint8_t*)(handle->buffer); + for (int stripe = 7; stripe >= 0; stripe--) { - for (row = 0; row < TI80_ROWS; row++) + for (int row = 0; row < TI80_ROWS; row++) { (*bitmap)[row * TI80_COLS / 8 + stripe] = buffer[i++]; } @@ -219,7 +211,7 @@ static int recv_screen_80 (CalcHandle* handle, CalcScreenCoord* sc, uint8_t** b if (ret) { ticalcs_free_screen(*bitmap); - *bitmap = NULL; + *bitmap = nullptr; } return ret; @@ -227,10 +219,8 @@ static int recv_screen_80 (CalcHandle* handle, CalcScreenCoord* sc, uint8_t** b static int recv_screen (CalcHandle* handle, CalcScreenCoord* sc, uint8_t** bitmap) { - int ret; - *bitmap = (uint8_t *)ticalcs_alloc_screen(65537U); - if (*bitmap == NULL) + if (*bitmap == nullptr) { return ERR_MALLOC; } @@ -265,7 +255,7 @@ static int recv_screen (CalcHandle* handle, CalcScreenCoord* sc, uint8_t** bitm } sc->pixel_format = CALC_PIXFMT_MONO; - ret = SEND_SCR(handle); + int ret = SEND_SCR(handle); if (!ret) { ret = RECV_ACK(handle, NULL); @@ -284,7 +274,7 @@ static int recv_screen (CalcHandle* handle, CalcScreenCoord* sc, uint8_t** bitm if (ret) { ticalcs_free_screen(*bitmap); - *bitmap = NULL; + *bitmap = nullptr; } return ret; @@ -292,18 +282,15 @@ static int recv_screen (CalcHandle* handle, CalcScreenCoord* sc, uint8_t** bitm static int get_dirlist (CalcHandle* handle, GNode** vars, GNode** apps) { - int ret; uint16_t unused; - TreeInfo *ti; GNode *folder, *node; - char *utf8; - ret = dirlist_init_trees(handle, vars, apps); + int ret = dirlist_init_trees(handle, vars, apps); if (ret) { return ret; } - ti = (TreeInfo *)((*vars)->data); + TreeInfo* ti = (TreeInfo*)((*vars)->data); ret = SEND_REQ(handle, 0x0000, (handle->model == CALC_TI83) ? TI83_DIR : TI86_DIR, "\0\0\0\0\0\0\0"); if (!ret) @@ -322,9 +309,9 @@ static int get_dirlist (CalcHandle* handle, GNode** vars, GNode** apps) if (!ret) { VarEntry *ve; - uint8_t * mem = (uint8_t *)handle->buffer2; + const uint8_t * mem = (uint8_t *)handle->buffer2; - folder = dirlist_create_append_node(NULL, vars); + folder = dirlist_create_append_node(nullptr, vars); if (handle->model == CALC_TI83) { @@ -334,12 +321,12 @@ static int get_dirlist (CalcHandle* handle, GNode** vars, GNode** apps) ve = tifiles_ve_create(); ve->type = TI83_WINDW; node = dirlist_create_append_node(ve, &folder); - if (node != NULL) + if (node != nullptr) { ve = tifiles_ve_create(); ve->type = TI83_ZSTO; node = dirlist_create_append_node(ve, &folder); - if (node != NULL) + if (node != nullptr) { ve = tifiles_ve_create(); ve->type = TI83_TABLE; @@ -355,22 +342,22 @@ static int get_dirlist (CalcHandle* handle, GNode** vars, GNode** apps) ve = tifiles_ve_create(); ve->type = TI86_FUNC; node = dirlist_create_append_node(ve, &folder); - if (node != NULL) + if (node != nullptr) { ve = tifiles_ve_create(); ve->type = TI86_POL; node = dirlist_create_append_node(ve, &folder); - if (node != NULL) + if (node != nullptr) { ve = tifiles_ve_create(); ve->type = TI86_PARAM; node = dirlist_create_append_node(ve, &folder); - if (node != NULL) + if (node != nullptr) { ve = tifiles_ve_create(); ve->type = TI86_DIFEQ; node = dirlist_create_append_node(ve, &folder); - if (node != NULL) + if (node != nullptr) { ve = tifiles_ve_create(); ve->type = TI86_ZRCL; @@ -390,12 +377,11 @@ static int get_dirlist (CalcHandle* handle, GNode** vars, GNode** apps) for (;;) { uint16_t ve_size; - int ret2; ve = tifiles_ve_create(); ret = RECV_VAR(handle, &ve_size, &ve->type, ve->name); ve->size = ve_size; - ret2 = SEND_ACK(handle); + const int ret2 = SEND_ACK(handle); if (ret) { if (ret == ERR_EOT) // end of transmission @@ -418,7 +404,7 @@ static int get_dirlist (CalcHandle* handle, GNode** vars, GNode** apps) return ERR_MALLOC; } - utf8 = ticonv_varname_to_utf8(handle->model, ve->name, ve->type); + char* utf8 = ticonv_varname_to_utf8(handle->model, ve->name, ve->type); ticalcs_slprintf(handle->updat->text, sizeof(handle->updat->text), _("Parsing %s"), utf8); ticonv_utf8_free(utf8); ticalcs_update_label(handle); @@ -431,13 +417,12 @@ static int get_dirlist (CalcHandle* handle, GNode** vars, GNode** apps) static int get_memfree (CalcHandle* handle, uint32_t* ram, uint32_t* flash) { - int ret; uint16_t unused; *ram = -1; *flash = -1; - ret = SEND_REQ(handle, 0x0000, (handle->model == CALC_TI83) ? TI83_DIR : TI86_DIR, "\0\0\0\0\0\0\0"); + int ret = SEND_REQ(handle, 0x0000, (handle->model == CALC_TI83) ? TI83_DIR : TI86_DIR, "\0\0\0\0\0\0\0"); if (!ret) { ret = RECV_ACK(handle, &unused); @@ -449,7 +434,7 @@ static int get_memfree (CalcHandle* handle, uint32_t* ram, uint32_t* flash) ret = SEND_EOT(handle); if (!ret) { - uint8_t * mem = (uint8_t *)handle->buffer2; + const uint8_t * mem = (uint8_t *)handle->buffer2; if (handle->model == CALC_TI83) { *ram = (((uint32_t)(mem[1])) << 8) | mem[0]; // Clamp mem_free to a 16-bit value. @@ -469,12 +454,11 @@ static int get_memfree (CalcHandle* handle, uint32_t* ram, uint32_t* flash) static int send_backup (CalcHandle* handle, BackupContent* content) { int ret; - uint16_t length; char varname[9]; uint8_t rej_code; uint16_t status; - length = content->data_length1; + uint16_t length = content->data_length1; varname[0] = LSB(content->data_length2); varname[1] = MSB(content->data_length2); varname[2] = LSB(content->data_length3); @@ -738,14 +722,14 @@ static int recv_backup (CalcHandle* handle, BackupContent* content) } else { - content->data_part3 = NULL; + content->data_part3 = nullptr; } handle->updat->cnt2++; ticalcs_update_pbar(handle); if (handle->model != CALC_TI86) { - content->data_part4 = NULL; + content->data_part4 = nullptr; } else { @@ -769,7 +753,6 @@ static int recv_backup (CalcHandle* handle, BackupContent* content) static int send_var_ns (CalcHandle* handle, CalcMode mode, FileContent* content) { - unsigned int i; int ret = 0; uint8_t rej_code; uint16_t status; @@ -783,7 +766,7 @@ static int send_var_ns (CalcHandle* handle, CalcMode mode, FileContent* content handle->updat->cnt2 = 0; handle->updat->max2 = content->num_entries; - for (i = 0; i < content->num_entries; i++) + for (unsigned int i = 0; i < content->num_entries; i++) { VarEntry *entry = content->entries[i]; uint16_t size; @@ -925,14 +908,13 @@ static int send_var_8285 (CalcHandle* handle, CalcMode mode, FileContent* conte static int send_var_8386 (CalcHandle* handle, CalcMode mode, FileContent* content) { int ret = 0; - unsigned int i; uint8_t rej_code; uint16_t status; handle->updat->cnt2 = 0; handle->updat->max2 = content->num_entries; - for (i = 0; !ret && i < content->num_entries; i++) + for (unsigned int i = 0; !ret && i < content->num_entries; i++) { VarEntry *entry = content->entries[i]; uint16_t size; @@ -1028,14 +1010,13 @@ static int recv_var (CalcHandle* handle, CalcMode mode, FileContent* content, V { int ret; uint16_t unused; - VarEntry *ve; uint16_t ve_size; content->model = handle->model; tifiles_comment_set_single_sn(content->comment, sizeof(content->comment)); content->num_entries = 1; content->entries = tifiles_ve_create_array(1); - ve = content->entries[0] = tifiles_ve_create(); + VarEntry* ve = content->entries[0] = tifiles_ve_create(); memcpy(ve, vr, sizeof(VarEntry)); ticonv_varname_to_utf8_sn(handle->model, vr->name, handle->updat->text, sizeof(handle->updat->text), vr->type); @@ -1172,7 +1153,7 @@ static int recv_var_ns (CalcHandle* handle, CalcMode mode, FileContent* content else { tifiles_comment_set_group_sn(content->comment, sizeof(content->comment)); - *vr = NULL; + *vr = nullptr; } return ret; @@ -1268,9 +1249,8 @@ static int del_var (CalcHandle* handle, VarRequest* vr) 0x04, 0x04, 0x05 /* Down, Down, Enter */ }; unsigned int i; - char *utf8; - utf8 = ticonv_varname_to_utf8(handle->model, vr->name, vr->type); + char* utf8 = ticonv_varname_to_utf8(handle->model, vr->name, vr->type); ticalcs_slprintf(handle->updat->text, sizeof(handle->updat->text), _("Deleting %s..."), utf8); ticonv_utf8_free(utf8); ticalcs_update_label(handle); @@ -1283,7 +1263,7 @@ static int del_var (CalcHandle* handle, VarRequest* vr) for (i = 0; !ret && i < strlen(vr->name); i++) { - char c = toupper(vr->name[i]); + const char c = toupper(vr->name[i]); if (isdigit(c)) { @@ -1305,12 +1285,11 @@ static int del_var (CalcHandle* handle, VarRequest* vr) static int get_version (CalcHandle* handle, CalcInfos* infos) { - int ret; static CalcLabEquipmentData lab_equipment_data_1 = { CALC_LAB_EQUIPMENT_DATA_TYPE_STRING, 4, 1, (const uint8_t *)"{7}", 0, 0, 4 }; // Request status command. CalcLabEquipmentData lab_equipment_data_2; // Use the TI-68k format because it's easier to deal with. - ret = tixx_send_lab_equipment_data(handle, CALC_TI89, &lab_equipment_data_1); + int ret = tixx_send_lab_equipment_data(handle, CALC_TI89, &lab_equipment_data_1); if (!ret) { ret = tixx_get_lab_equipment_data(handle, CALC_TI89, &lab_equipment_data_2); @@ -1329,7 +1308,7 @@ static int get_version (CalcHandle* handle, CalcInfos* infos) if (item_count >= 3) { unsigned int infos_mask = 0; - unsigned long device_code = (unsigned long)raw_values[0]; + const unsigned long device_code = (unsigned long)raw_values[0]; switch (device_code) { diff --git a/libticalcs/trunk/src/calc_9x.cc b/libticalcs/trunk/src/calc_9x.cc index a1c335d7f..ebc65bbd5 100644 --- a/libticalcs/trunk/src/calc_9x.cc +++ b/libticalcs/trunk/src/calc_9x.cc @@ -80,10 +80,9 @@ static int is_ready (CalcHandle* handle) { - int ret; uint16_t status; - ret = SEND_RDY(handle); + int ret = SEND_RDY(handle); if (!ret) { ret = RECV_ACK(handle, &status); @@ -98,10 +97,9 @@ static int is_ready (CalcHandle* handle) static int send_key (CalcHandle* handle, uint32_t key) { - int ret; uint16_t status; - ret = SEND_KEY(handle, (uint16_t)key); + int ret = SEND_KEY(handle, (uint16_t)key); if (!ret) { ret = RECV_ACK(handle, &status); @@ -210,10 +208,8 @@ static int execute (CalcHandle* handle, VarEntry *ve, const char* args) static int recv_screen (CalcHandle* handle, CalcScreenCoord* sc, uint8_t** bitmap) { - int ret; - *bitmap = (uint8_t *)ticalcs_alloc_screen(65537U); - if (*bitmap == NULL) + if (*bitmap == nullptr) { return ERR_MALLOC; } @@ -232,7 +228,7 @@ static int recv_screen (CalcHandle* handle, CalcScreenCoord* sc, uint8_t** bitm } sc->pixel_format = CALC_PIXFMT_MONO; - ret = SEND_SCR(handle); + int ret = SEND_SCR(handle); if (!ret) { ret = RECV_ACK(handle, NULL); @@ -246,11 +242,11 @@ static int recv_screen (CalcHandle* handle, CalcScreenCoord* sc, uint8_t** bitm if ( ((handle->model == CALC_TI89) || (handle->model == CALC_TI89T)) && (sc->format == SCREEN_CLIPPED)) { - int i, j, k; + int i, j; for (i = 0, j = 0; j < TI89_ROWS_VISIBLE; j++) { - for (k = 0; k < (TI89_COLS_VISIBLE >> 3); k++) + for (int k = 0; k < (TI89_COLS_VISIBLE >> 3); k++) { (*bitmap)[i++] = (*bitmap)[j * (TI89_COLS >> 3) + k]; } @@ -266,7 +262,7 @@ static int recv_screen (CalcHandle* handle, CalcScreenCoord* sc, uint8_t** bitm if (ret) { ticalcs_free_screen(*bitmap); - *bitmap = NULL; + *bitmap = nullptr; } return ret; @@ -277,18 +273,17 @@ static int get_dirlist (CalcHandle* handle, GNode** vars, GNode** apps) VarEntry info; uint16_t block_size; uint8_t * buffer = (uint8_t *)handle->buffer2; - int ret; - int i, j; - uint8_t extra = (handle->model == CALC_V200) ? 8 : 0; - GNode *root, *node = NULL; + int j; + const uint8_t extra = (handle->model == CALC_V200) ? 8 : 0; + GNode *root, *node = nullptr; - ret = dirlist_init_trees(handle, vars, apps); + int ret = dirlist_init_trees(handle, vars, apps); if (ret) { return ret; } - root = dirlist_create_append_node(NULL, apps); + root = dirlist_create_append_node(nullptr, apps); if (!root) { return ERR_MALLOC; @@ -379,11 +374,10 @@ static int get_dirlist (CalcHandle* handle, GNode** vars, GNode** apps) } // get list of variables into each folder - for (i = 0; i < (int)g_node_n_children(*vars); i++) + for (int i = 0; i < (int)g_node_n_children(*vars); i++) { GNode *folder = g_node_nth_child(*vars, i); char *folder_name = ((VarEntry *) (folder->data))->name; - char *u1, *u2; ticalcs_info(_("Directory listing in %8s..."), folder_name); @@ -446,8 +440,8 @@ static int get_dirlist (CalcHandle* handle, GNode** vars, GNode** apps) ve->attr, ve->size); - u1 = ticonv_varname_to_utf8(handle->model, ((VarEntry *) (folder->data))->name, -1); - u2 = ticonv_varname_to_utf8(handle->model, ve->name, ve->type); + char* u1 = ticonv_varname_to_utf8(handle->model, ((VarEntry*)(folder->data))->name, -1); + char* u2 = ticonv_varname_to_utf8(handle->model, ve->name, ve->type); ticalcs_slprintf(handle->updat->text, sizeof(handle->updat->text), _("Parsing %s/%s"), u1, u2); ticonv_utf8_free(u2); ticonv_utf8_free(u1); @@ -496,11 +490,10 @@ static int get_dirlist (CalcHandle* handle, GNode** vars, GNode** apps) static int get_dirlist_92 (CalcHandle* handle, GNode** vars, GNode** apps) { VarEntry info; - int ret; - GNode *folder = NULL; + GNode *folder = nullptr; char folder_name[9]; - ret = dirlist_init_trees(handle, vars, apps); + int ret = dirlist_init_trees(handle, vars, apps); if (!ret) { ret = SEND_REQ(handle, 0, TI92_RDIR, "\0\0\0\0\0\0\0"); @@ -520,7 +513,6 @@ static int get_dirlist_92 (CalcHandle* handle, GNode** vars, GNode** apps) for (;;) { - VarEntry *ve; uint8_t * buffer = (uint8_t *)handle->buffer2; uint16_t unused; @@ -544,7 +536,7 @@ static int get_dirlist_92 (CalcHandle* handle, GNode** vars, GNode** apps) break; } - ve = tifiles_ve_create(); + VarEntry* ve = tifiles_ve_create(); memcpy(ve->name, buffer + 4, 8); // skip 4 extra 00s ve->name[8] = '\0'; ve->type = buffer[12]; @@ -564,19 +556,19 @@ static int get_dirlist_92 (CalcHandle* handle, GNode** vars, GNode** apps) if (!strcmp(ve->folder, "main") && (!strcmp(ve->name, "regcoef") || !strcmp(ve->name, "regeq"))) { tifiles_ve_delete(ve); - ve = NULL; + ve = nullptr; } else { - GNode *node = dirlist_create_append_node(ve, &folder); - if (node == NULL) + const GNode *node = dirlist_create_append_node(ve, &folder); + if (node == nullptr) { return ERR_MALLOC; } } } - if (ve != NULL) + if (ve != nullptr) { ticalcs_info(_("Name: %8s | Type: %8s | Attr: %i | Size: %08X"), ve->name, @@ -599,7 +591,7 @@ static int get_dirlist_92 (CalcHandle* handle, GNode** vars, GNode** apps) } } - if (ve != NULL && folder != NULL) + if (ve != nullptr && folder != nullptr) { char * utf8 = ticonv_varname_to_utf8(handle->model, ve->name, ve->type); ticalcs_slprintf(handle->updat->text, sizeof(handle->updat->text), _("Parsing %s/%s"), ((VarEntry *) (folder->data))->name, utf8); @@ -620,23 +612,19 @@ static int get_memfree (CalcHandle* handle, uint32_t* ram, uint32_t *flash) static int send_backup (CalcHandle* handle, BackupContent* content) { - int ret; - unsigned int i; - unsigned int nblocks; - - ret = SEND_VAR(handle, content->data_length, TI92_BKUP, content->rom_version); + int ret = SEND_VAR(handle, content->data_length, TI92_BKUP, content->rom_version); if (!ret) { ret = RECV_ACK(handle, NULL); if (!ret) { handle->updat->cnt2 = 0; - nblocks = content->data_length / 1024; + const unsigned int nblocks = content->data_length / 1024; handle->updat->max2 = nblocks; - for (i = 0; !ret && i <= nblocks; i++) + for (unsigned int i = 0; !ret && i <= nblocks; i++) { - uint32_t length = (i != nblocks) ? 1024 : content->data_length % 1024; + const uint32_t length = (i != nblocks) ? 1024 : content->data_length % 1024; ret = SEND_VAR(handle, length, TI92_BKUP, content->rom_version); if (!ret) @@ -677,9 +665,8 @@ static int send_backup (CalcHandle* handle, BackupContent* content) static int recv_backup (CalcHandle* handle, BackupContent* content) { uint32_t block_size; - int block, ret = 0; + int ret = 0; uint16_t unused; - uint8_t *ptr; ret = SEND_REQ(handle, 0, TI92_BKUP, "main\\backup"); if (!ret) @@ -693,15 +680,13 @@ static int recv_backup (CalcHandle* handle, BackupContent* content) content->type = TI92_BKUP; content->data_length = 0; - for (block = 0; !ret; block++) + for (int block = 0; !ret; block++) { - int ret2; - ticalcs_slprintf(handle->updat->text, sizeof(handle->updat->text), _("Block #%2i"), block); ticalcs_update_label(handle); ret = RECV_VAR(handle, &block_size, &content->type, content->rom_version); - ret2 = SEND_ACK(handle); + const int ret2 = SEND_ACK(handle); if (ret) { @@ -723,7 +708,7 @@ static int recv_backup (CalcHandle* handle, BackupContent* content) ret = RECV_ACK(handle, NULL); if (!ret) { - ptr = content->data_part + content->data_length; + uint8_t* ptr = content->data_part + content->data_length; ret = RECV_XDP(handle, &unused, ptr); if (!ret) { @@ -746,28 +731,24 @@ static int recv_backup (CalcHandle* handle, BackupContent* content) static int send_var (CalcHandle* handle, CalcMode mode, FileContent* content) { int ret = 0; - unsigned int i; uint16_t status; handle->updat->cnt2 = 0; handle->updat->max2 = content->num_entries; - for (i = 0; !ret && i < content->num_entries; i++) + for (unsigned int i = 0; !ret && i < content->num_entries; i++) { - VarEntry *entry; uint8_t * buffer = (uint8_t *)handle->buffer2; - uint8_t vartype; char varname[18]; - uint32_t size; - entry = content->entries[i]; + VarEntry* entry = content->entries[i]; if (!ticalcs_validate_varentry(entry)) { ticalcs_critical("%s: skipping invalid content entry #%u", __FUNCTION__, i); continue; } - vartype = entry->type; + uint8_t vartype = entry->type; if (entry->action == ACT_SKIP) { @@ -796,7 +777,7 @@ static int send_var (CalcHandle* handle, CalcMode mode, FileContent* content) case ATTRB_ARCHIVED: vartype = 0x27; break; } - size = entry->size; + uint32_t size = entry->size; if (size >= 65536U) { ticalcs_critical("%s: oversized variable has size %u, clamping to 65535", __FUNCTION__, size); @@ -853,14 +834,13 @@ static int recv_var (CalcHandle* handle, CalcMode mode, FileContent* content, V { int ret = 0; uint16_t status; - VarEntry *ve; uint16_t unused; char varname[20]; content->model = handle->model; - ve = tifiles_ve_create(); + VarEntry* ve = tifiles_ve_create(); memcpy(ve, vr, sizeof(VarEntry)); - ve->data = NULL; + ve->data = nullptr; tifiles_build_fullname(handle->model, varname, vr->folder, vr->name); ticonv_varname_to_utf8_sn(handle->model, varname, handle->updat->text, sizeof(handle->updat->text), vr->type); @@ -926,10 +906,8 @@ static int recv_var (CalcHandle* handle, CalcMode mode, FileContent* content, V static int send_all_vars_backup (CalcHandle* handle, FileContent* content) { - int ret; - // erase memory - ret = SEND_VAR(handle, 0, TI89_BKUP, "main"); + int ret = SEND_VAR(handle, 0, TI89_BKUP, "main"); if (!ret) { ret = RECV_ACK(handle, NULL); @@ -962,28 +940,24 @@ static int send_all_vars_backup (CalcHandle* handle, FileContent* content) static int send_var_ns (CalcHandle* handle, CalcMode mode, FileContent* content) { int ret = 0; - unsigned int i; uint16_t status; handle->updat->cnt2 = 0; handle->updat->max2 = content->num_entries; - for (i = 0; !ret && i < content->num_entries; i++) + for (unsigned int i = 0; !ret && i < content->num_entries; i++) { - VarEntry *entry; uint8_t * buffer = (uint8_t *)handle->buffer2; - uint8_t vartype; char varname[18]; - uint32_t size; - entry = content->entries[i]; + VarEntry* entry = content->entries[i]; if (!ticalcs_validate_varentry(entry)) { ticalcs_critical("%s: skipping invalid content entry #%u", __FUNCTION__, i); continue; } - vartype = entry->type; + const uint8_t vartype = entry->type; if (entry->action == ACT_SKIP) { @@ -1005,7 +979,7 @@ static int send_var_ns (CalcHandle* handle, CalcMode mode, FileContent* content ticonv_varname_to_utf8_sn(handle->model, varname, handle->updat->text, sizeof(handle->updat->text), vartype); ticalcs_update_label(handle); - size = entry->size; + uint32_t size = entry->size; if (size >= 65536U) { ticalcs_critical("%s: oversized variable has size %u, clamping to 65535", __FUNCTION__, size); @@ -1076,12 +1050,11 @@ static int recv_var_ns (CalcHandle* handle, CalcMode mode, FileContent* content for (nvar = 0;; nvar++) { VarEntry *ve = tifiles_ve_create(); - int ret2; ticalcs_strlcpy(ve->folder, "main", sizeof(ve->folder)); ret = RECV_VAR(handle, &ve->size, &ve->type, tipath); - ret2 = SEND_ACK(handle); + const int ret2 = SEND_ACK(handle); if (ret) { @@ -1098,7 +1071,7 @@ static int recv_var_ns (CalcHandle* handle, CalcMode mode, FileContent* content } // from Christian (calculator can send varname or fldname/varname) - if ((tiname = strchr(tipath, '\\')) != NULL) + if ((tiname = strchr(tipath, '\\')) != nullptr) { *tiname = '\0'; ticalcs_strlcpy(ve->folder, tipath, sizeof(ve->folder)); @@ -1143,7 +1116,7 @@ static int recv_var_ns (CalcHandle* handle, CalcMode mode, FileContent* content if (nvar > 1) { - *vr = NULL; + *vr = nullptr; } else { @@ -1156,11 +1129,9 @@ static int recv_var_ns (CalcHandle* handle, CalcMode mode, FileContent* content static int send_flash (CalcHandle* handle, FlashContent* content) { int ret = 0; - FlashContent *ptr; - int i, nblocks; // send all headers except license - for (ptr = content; !ret && ptr != NULL; ptr = ptr->next) + for (FlashContent* ptr = content; !ret && ptr != nullptr; ptr = ptr->next) { if (ptr->data_type == TI89_LICENSE) { @@ -1191,12 +1162,12 @@ static int send_flash (CalcHandle* handle, FlashContent* content) if (!ret) { - nblocks = ptr->data_length / 65536; + const int nblocks = ptr->data_length / 65536; handle->updat->max2 = nblocks+1; - for (i = 0; !ret && i <= nblocks; i++) + for (int i = 0; !ret && i <= nblocks; i++) { - uint32_t length = (i != nblocks) ? 65536 : ptr->data_length % 65536; + const uint32_t length = (i != nblocks) ? 65536 : ptr->data_length % 65536; ret = RECV_ACK(handle, NULL); if (!ret) @@ -1244,7 +1215,6 @@ static int send_flash (CalcHandle* handle, FlashContent* content) static int recv_flash (CalcHandle* handle, FlashContent* content, VarRequest* vr) { - int ret; int i; ticonv_varname_to_utf8_sn(handle->model, vr->name, handle->updat->text, sizeof(handle->updat->text), vr->type); ticalcs_update_label(handle); @@ -1261,7 +1231,7 @@ static int recv_flash (CalcHandle* handle, FlashContent* content, VarRequest* v default: return ERR_FATAL_ERROR; } - ret = SEND_REQ(handle, 0x00, vr->type, vr->name); + int ret = SEND_REQ(handle, 0x00, vr->type, vr->name); if (!ret) { ret = RECV_ACK(handle, NULL); @@ -1327,7 +1297,6 @@ static int recv_flash (CalcHandle* handle, FlashContent* content, VarRequest* v static int recv_idlist (CalcHandle* handle, uint8_t* idlist) { - int ret; uint32_t varsize; uint16_t pktsize; uint8_t vartype; @@ -1336,7 +1305,7 @@ static int recv_idlist (CalcHandle* handle, uint8_t* idlist) ticalcs_strlcpy(handle->updat->text, "ID-LIST", sizeof(handle->updat->text)); ticalcs_update_label(handle); - ret = SEND_REQ(handle, 0x0000, TI89_IDLIST, "\0\0\0\0\0\0\0"); + int ret = SEND_REQ(handle, 0x0000, TI89_IDLIST, "\0\0\0\0\0\0\0"); if (!ret) { ret = RECV_ACK(handle, NULL); @@ -1406,7 +1375,6 @@ static int dump_rom_1 (CalcHandle* handle) static int dump_rom_2 (CalcHandle* handle, CalcDumpSize size, const char *filename) { int ret = 0; - unsigned int i; static const uint16_t keys[] = { 'm', 'a', 'i', 'n', '\\', 'r', 'o', 'm', 'd', 'u', 'm', 'p', @@ -1414,7 +1382,7 @@ static int dump_rom_2 (CalcHandle* handle, CalcDumpSize size, const char *filen }; // Launch program by remote control - for (i = 0; !ret && i < sizeof(keys) / sizeof(keys[0]); i++) + for (unsigned int i = 0; !ret && i < sizeof(keys) / sizeof(keys[0]); i++) { ret = send_key(handle, (uint32_t)(keys[i])); } @@ -1431,7 +1399,6 @@ static int dump_rom_2 (CalcHandle* handle, CalcDumpSize size, const char *filen static int set_clock (CalcHandle* handle, CalcClock* _clock) { - int ret; uint8_t buffer[16]; uint16_t status; @@ -1455,7 +1422,7 @@ static int set_clock (CalcHandle* handle, CalcClock* _clock) ticalcs_strlcpy(handle->updat->text, _("Setting clock..."), sizeof(handle->updat->text)); ticalcs_update_label(handle); - ret = SEND_RTS(handle, 0x10, TI89_CLK, "Clock"); + int ret = SEND_RTS(handle, 0x10, TI89_CLK, "Clock"); if (!ret) { ret = RECV_ACK(handle, NULL); @@ -1490,7 +1457,6 @@ static int set_clock (CalcHandle* handle, CalcClock* _clock) static int get_clock (CalcHandle* handle, CalcClock* _clock) { - int ret; uint32_t varsize; uint16_t pktsize; uint8_t vartype; @@ -1499,7 +1465,7 @@ static int get_clock (CalcHandle* handle, CalcClock* _clock) ticalcs_strlcpy(handle->updat->text, _("Getting clock..."), sizeof(handle->updat->text)); ticalcs_update_label(handle); - ret = SEND_REQ(handle, 0x0000, TI89_CLK, "Clock"); + int ret = SEND_REQ(handle, 0x0000, TI89_CLK, "Clock"); if (!ret) { ret = RECV_ACK(handle, NULL); @@ -1554,17 +1520,15 @@ static int get_clock (CalcHandle* handle, CalcClock* _clock) static int del_var (CalcHandle* handle, VarRequest* vr) { - int ret; char varname[18]; - char *utf8; tifiles_build_fullname(handle->model, varname, vr->folder, vr->name); - utf8 = ticonv_varname_to_utf8(handle->model, varname, vr->type); + char* utf8 = ticonv_varname_to_utf8(handle->model, varname, vr->type); ticalcs_slprintf(handle->updat->text, sizeof(handle->updat->text), _("Deleting %s..."), utf8); ticonv_utf8_free(utf8); ticalcs_update_label(handle); - ret = SEND_DEL(handle, vr->size, vr->type, varname); + int ret = SEND_DEL(handle, vr->size, vr->type, varname); if (!ret) { ret = RECV_ACK(handle, NULL); @@ -1588,10 +1552,9 @@ static int del_var_92 (CalcHandle* handle, VarRequest* vr) KEY92P_SPACE }; char varname[18]; - char *utf8; tifiles_build_fullname(handle->model, varname, vr->folder, vr->name); - utf8 = ticonv_varname_to_utf8(handle->model, varname, vr->type); + char* utf8 = ticonv_varname_to_utf8(handle->model, varname, vr->type); ticalcs_slprintf(handle->updat->text, sizeof(handle->updat->text), _("Deleting %s..."), utf8); ticonv_utf8_free(utf8); ticalcs_update_label(handle); @@ -1615,19 +1578,17 @@ static int del_var_92 (CalcHandle* handle, VarRequest* vr) static int new_folder (CalcHandle* handle, VarRequest* vr) { - int ret; uint8_t data[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0x40, 0x00, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x23 }; char varname[18]; - char *utf8; tifiles_build_fullname(handle->model, varname, vr->folder, "a1234567"); - utf8 = ticonv_varname_to_utf8(handle->model, vr->folder, -1); + char* utf8 = ticonv_varname_to_utf8(handle->model, vr->folder, -1); ticalcs_slprintf(handle->updat->text, sizeof(handle->updat->text), _("Creating %s..."), utf8); ticonv_utf8_free(utf8); ticalcs_update_label(handle); // send empty expression - ret = SEND_RTS(handle, 0x10, 0x00, varname); + int ret = SEND_RTS(handle, 0x10, 0x00, varname); if (!ret) { ret = RECV_ACK(handle, NULL); @@ -1669,11 +1630,10 @@ static int new_folder (CalcHandle* handle, VarRequest* vr) static int get_version (CalcHandle* handle, CalcInfos* infos) { - int ret; uint16_t length; uint8_t * buffer = (uint8_t *)handle->buffer2; - ret = SEND_VER(handle); + int ret = SEND_VER(handle); if (!ret) { ret = RECV_ACK(handle, NULL); @@ -1732,12 +1692,11 @@ static int get_version (CalcHandle* handle, CalcInfos* infos) static int get_version_92 (CalcHandle* handle, CalcInfos* infos) { - int ret; uint32_t size; uint8_t type; char name[32]; - ret = SEND_REQ(handle, 0, TI92_BKUP, "main\\version"); + int ret = SEND_REQ(handle, 0, TI92_BKUP, "main\\version"); if (!ret) { ret = RECV_ACK(handle, NULL); diff --git a/libticalcs/trunk/src/calc_nsp.cc b/libticalcs/trunk/src/calc_nsp.cc index ce5ece773..3813726c3 100644 --- a/libticalcs/trunk/src/calc_nsp.cc +++ b/libticalcs/trunk/src/calc_nsp.cc @@ -125,7 +125,6 @@ static int is_ready (CalcHandle* handle) do { static const char echostr[] = "ready"; - int old; uint32_t size; uint8_t *data; @@ -147,7 +146,7 @@ static int is_ready (CalcHandle* handle) // requests in quick succession often triggers memory corruption (hangs, reboots, // a variable amount of black pixels on the screen) on (at least) Nspire (CAS) OS 1.7... ticalcs_info(" waiting for LOGIN request (OS >= 1.2 check)..."); - old = ticables_options_set_timeout(handle->cable, 40); // 3s mini + const int old = ticables_options_set_timeout(handle->cable, 40); // 3s mini ret = nsp_cmd_r_login(handle); // no call to nsp_send_nack(handle) because nack is managed in nsp_recv_data() @@ -209,9 +208,7 @@ static int is_ready (CalcHandle* handle) static int send_key (CalcHandle* handle, uint32_t key) { - int ret; - - ret = nsp_cmd_s_key(handle, key); + const int ret = nsp_cmd_s_key(handle, key); return ret; } @@ -221,11 +218,10 @@ static int get_version (CalcHandle* handle, CalcInfos* infos); static int recv_screen (CalcHandle* handle, CalcScreenCoord* sc, uint8_t** bitmap) { - int ret; CalcInfos infos; // First of all, we have to identify the Nspire model. - ret = get_version(handle, &infos); + int ret = get_version(handle, &infos); if (!ret) { if (infos.bits_per_pixel == 4) @@ -285,9 +281,9 @@ static int recv_screen (CalcHandle* handle, CalcScreenCoord* sc, uint8_t** bitm ret = nsp_cmd_r_screen_rle(handle, &cmd, &size, &data); if (!ret) { - uint32_t len = sc->width * sc->height * infos.bits_per_pixel / 8; + const uint32_t len = sc->width * sc->height * infos.bits_per_pixel / 8; uint8_t * dst = (uint8_t *)ticalcs_alloc_screen(len); - if (dst != NULL) + if (dst != nullptr) { ret = ticalcs_screen_nspire_rle_uncompress(sc->pixel_format, data, size, dst, len); if (!ret) @@ -340,8 +336,6 @@ static int enumerate_folder(CalcHandle* handle, GNode** vars, const char * folde for (;;) { - VarEntry *fe; - GNode *node; uint32_t varsize; uint8_t vartype; @@ -362,7 +356,7 @@ static int enumerate_folder(CalcHandle* handle, GNode** vars, const char * folde break; } - fe = tifiles_ve_create(); + VarEntry* fe = tifiles_ve_create(); ticalcs_strlcpy(fe->folder, folder_name + 1, sizeof(fe->folder)); // Skip leading / fe->size = varsize; @@ -389,7 +383,7 @@ static int enumerate_folder(CalcHandle* handle, GNode** vars, const char * folde // else don't remove the extension. ticalcs_strlcpy(fe->name, varname, sizeof(fe->name)); - node = dirlist_create_append_node(fe, vars); + const GNode* node = dirlist_create_append_node(fe, vars); if (!node) { ret = ERR_MALLOC; @@ -405,8 +399,6 @@ static int enumerate_folder(CalcHandle* handle, GNode** vars, const char * folde while (!ret) { - int i; - ret = nsp_cmd_s_dir_enum_done(handle); if (ret) { @@ -419,12 +411,12 @@ static int enumerate_folder(CalcHandle* handle, GNode** vars, const char * folde } // Enumerate elements of root folder. - for (i = 0; i < (int)g_node_n_children(*vars); i++) + for (int i = 0; i < (int)g_node_n_children(*vars); i++) { char new_folder_name[FLDNAME_MAX + 4]; const char * separator_if_any; GNode * folder = g_node_nth_child(*vars, i); - uint8_t vartype = ((VarEntry *)(folder->data))->type; + const uint8_t vartype = ((VarEntry *)(folder->data))->type; // Don't recurse into regular files (type 0, TNS or e.g. themes.csv on OS 3.0+). if (vartype == NSP_TNS) @@ -463,16 +455,13 @@ static int enumerate_folder(CalcHandle* handle, GNode** vars, const char * folde static int get_dirlist (CalcHandle* handle, GNode** vars, GNode** apps) { - GNode *root; - int ret; - - ret = dirlist_init_trees(handle, vars, apps); + int ret = dirlist_init_trees(handle, vars, apps); if (ret) { return ret; } - root = g_node_new(NULL); + GNode* root = g_node_new(nullptr); if (!root) { return ERR_MALLOC; @@ -485,7 +474,7 @@ static int get_dirlist (CalcHandle* handle, GNode** vars, GNode** apps) ret = nsp_cmd_s_dir_attributes(handle, "/"); if (!ret) { - ret = nsp_cmd_r_dir_attributes(handle, NULL, NULL, NULL); + ret = nsp_cmd_r_dir_attributes(handle, nullptr, nullptr, nullptr); if (!ret) { ret = nsp_session_close(handle); @@ -510,9 +499,7 @@ static int get_dirlist (CalcHandle* handle, GNode** vars, GNode** apps) static int get_memfree (CalcHandle* handle, uint32_t* ram, uint32_t* flash) { - int ret; - - ret = nsp_session_open(handle, NSP_SID_DEV_INFOS); + int ret = nsp_session_open(handle, NSP_SID_DEV_INFOS); if (!ret) { ret = nsp_cmd_s_dev_infos(handle, NSP_CMD_DI_VERSION); @@ -556,15 +543,12 @@ static int get_memfree (CalcHandle* handle, uint32_t* ram, uint32_t* flash) static int send_var (CalcHandle* handle, CalcMode mode, FileContent* content) { uint8_t status; - gchar *path; - int ret; - VarEntry * entry; handle->updat->cnt2 = 0; handle->updat->max2 = 1; ticalcs_update_pbar(handle); - entry = content->entries[0]; + VarEntry* entry = content->entries[0]; if (!ticalcs_validate_varentry(entry)) { @@ -582,13 +566,13 @@ static int send_var (CalcHandle* handle, CalcMode mode, FileContent* content) // return ERR_ABORT; //} - ret = nsp_session_open(handle, NSP_SID_FILE_MGMT); + int ret = nsp_session_open(handle, NSP_SID_FILE_MGMT); if (ret) { return ret; } - path = build_path(handle->model, entry); + gchar* path = build_path(handle->model, entry); ticonv_varname_to_utf8_sn(handle->model, path, handle->updat->text, sizeof(handle->updat->text), entry->type); ticalcs_update_label(handle); @@ -615,16 +599,13 @@ static int send_var (CalcHandle* handle, CalcMode mode, FileContent* content) static int recv_var (CalcHandle* handle, CalcMode mode, FileContent* content, VarRequest* vr) { - char *path; - int ret; - - ret = nsp_session_open(handle, NSP_SID_FILE_MGMT); + int ret = nsp_session_open(handle, NSP_SID_FILE_MGMT); if (ret) { return ret; } - path = build_path(handle->model, vr); + char* path = build_path(handle->model, vr); ticonv_varname_to_utf8_sn(handle->model, path, handle->updat->text, sizeof(handle->updat->text), vr->type); ticalcs_update_label(handle); @@ -638,7 +619,7 @@ static int recv_var (CalcHandle* handle, CalcMode mode, FileContent* content, V ret = nsp_cmd_s_file_ok(handle); if (!ret) { - uint8_t *data = NULL; + uint8_t *data = nullptr; if (vr->size) { @@ -649,14 +630,12 @@ static int recv_var (CalcHandle* handle, CalcMode mode, FileContent* content, V ret = nsp_cmd_s_status(handle, NSP_ERR_OK); if (!ret) { - VarEntry *ve; - content->model = handle->model; tifiles_comment_set_single_sn(content->comment, sizeof(content->comment)); content->num_entries = 1; content->entries = tifiles_ve_create_array(1); - ve = content->entries[0] = tifiles_ve_create(); + VarEntry* ve = content->entries[0] = tifiles_ve_create(); memcpy(ve, vr, sizeof(VarEntry)); ve->data = (uint8_t *)tifiles_ve_alloc_data(ve->size); @@ -687,7 +666,7 @@ static int send_os (CalcHandle* handle, FlashContent* content) { int ret; - if (content == NULL) + if (content == nullptr) { return -1; } @@ -752,9 +731,7 @@ static int send_os (CalcHandle* handle, FlashContent* content) static int recv_idlist (CalcHandle* handle, uint8_t* id) { - int ret; - - ret = nsp_session_open(handle, NSP_SID_DEV_INFOS); + int ret = nsp_session_open(handle, NSP_SID_DEV_INFOS); if (!ret) { ret = nsp_cmd_s_dev_infos(handle, NSP_CMD_DI_VERSION); @@ -794,18 +771,15 @@ static int dump_rom_1 (CalcHandle* handle) static int dump_rom_2 (CalcHandle* handle, CalcDumpSize size, const char *filename) { - int ret; - FILE *f; - ticalcs_info("FIXME: make ROM dumping work above OS 1.x, using the Fron method"); - f = fopen(filename, "wb"); - if (f == NULL) + FILE* f = fopen(filename, "wb"); + if (f == nullptr) { return ERR_OPEN_FILE; } - ret = nsp_session_open(handle, NSP_SID_FILE_MGMT); + int ret = nsp_session_open(handle, NSP_SID_FILE_MGMT); if (!ret) { ret = nsp_cmd_s_get_file(handle, "../phoenix/install/TI-Nspire.tnc"); @@ -848,18 +822,14 @@ static int dump_rom_2 (CalcHandle* handle, CalcDumpSize size, const char *filen static int del_var (CalcHandle* handle, VarRequest* vr) { - char *utf8; - char *path; - int ret; - - ret = nsp_session_open(handle, NSP_SID_FILE_MGMT); + int ret = nsp_session_open(handle, NSP_SID_FILE_MGMT); if (ret) { return ret; } - path = build_path(handle->model, vr); - utf8 = ticonv_varname_to_utf8(handle->model, path, vr->type); + char* path = build_path(handle->model, vr); + char* utf8 = ticonv_varname_to_utf8(handle->model, path, vr->type); ticalcs_slprintf(handle->updat->text, sizeof(handle->updat->text), _("Deleting %s..."), utf8); ticonv_utf8_free(utf8); ticalcs_update_label(handle); @@ -878,18 +848,14 @@ static int del_var (CalcHandle* handle, VarRequest* vr) static int new_folder (CalcHandle* handle, VarRequest* vr) { - char *utf8; - char *path; - int ret; - - ret = nsp_session_open(handle, NSP_SID_FILE_MGMT); + int ret = nsp_session_open(handle, NSP_SID_FILE_MGMT); if (ret) { return ret; } - path = g_strconcat("/", vr->folder, NULL); - utf8 = ticonv_varname_to_utf8(handle->model, path, -1); + char* path = g_strconcat("/", vr->folder, NULL); + char* utf8 = ticonv_varname_to_utf8(handle->model, path, -1); ticalcs_slprintf(handle->updat->text, sizeof(handle->updat->text), _("Creating %s..."), utf8); ticonv_utf8_free(utf8); ticalcs_update_label(handle); @@ -908,9 +874,7 @@ static int new_folder (CalcHandle* handle, VarRequest* vr) static int get_version (CalcHandle* handle, CalcInfos* infos) { - int ret; - - ret = nsp_session_open(handle, NSP_SID_DEV_INFOS); + int ret = nsp_session_open(handle, NSP_SID_DEV_INFOS); if (ret) { return ret; @@ -1106,20 +1070,16 @@ static int get_version (CalcHandle* handle, CalcInfos* infos) static int rename_var (CalcHandle* handle, VarRequest* oldname, VarRequest* newname) { - char *utf81, *utf82; - char *path1, *path2; - int ret; - - ret = nsp_session_open(handle, NSP_SID_FILE_MGMT); + int ret = nsp_session_open(handle, NSP_SID_FILE_MGMT); if (ret) { return ret; } - path1 = build_path(handle->model, oldname); - path2 = build_path(handle->model, newname); - utf81 = ticonv_varname_to_utf8(handle->model, path1, oldname->type); - utf82 = ticonv_varname_to_utf8(handle->model, path2, newname->type); + char* path1 = build_path(handle->model, oldname); + char* path2 = build_path(handle->model, newname); + char* utf81 = ticonv_varname_to_utf8(handle->model, path1, oldname->type); + char* utf82 = ticonv_varname_to_utf8(handle->model, path2, newname->type); ticalcs_slprintf(handle->updat->text, sizeof(handle->updat->text), _("Renaming %s to %s..."), utf81, utf82); ticonv_utf8_free(utf82); ticonv_utf8_free(utf81); @@ -1140,18 +1100,14 @@ static int rename_var (CalcHandle* handle, VarRequest* oldname, VarRequest* new static int del_folder (CalcHandle* handle, VarRequest* vr) { - char *utf8; - char *path; - int ret; - - ret = nsp_session_open(handle, NSP_SID_FILE_MGMT); + int ret = nsp_session_open(handle, NSP_SID_FILE_MGMT); if (ret) { return ret; } - path = g_strconcat("/", vr->folder, NULL); - utf8 = ticonv_varname_to_utf8(handle->model, path, -1); + char* path = g_strconcat("/", vr->folder, NULL); + char* utf8 = ticonv_varname_to_utf8(handle->model, path, -1); ticalcs_slprintf(handle->updat->text, sizeof(handle->updat->text), _("Deleting %s..."), utf8); ticonv_utf8_free(utf8); ticalcs_update_label(handle); diff --git a/libticalcs/trunk/src/calc_xx.cc b/libticalcs/trunk/src/calc_xx.cc index 659784c55..df199986d 100644 --- a/libticalcs/trunk/src/calc_xx.cc +++ b/libticalcs/trunk/src/calc_xx.cc @@ -44,15 +44,13 @@ **/ CalcFeatures TICALL ticalcs_calc_features(CalcHandle* handle) { - const CalcFncts *calc; - - if (handle == NULL) + if (handle == nullptr) { ticalcs_critical("%s: handle is NULL", __FUNCTION__); return FTS_NONE; } - calc = handle->calc; + const CalcFncts* calc = handle->calc; if (!calc) { return FTS_NONE; @@ -76,12 +74,11 @@ CalcFeatures TICALL ticalcs_calc_features(CalcHandle* handle) **/ int TICALL ticalcs_calc_isready(CalcHandle* handle) { - const CalcFncts *calc; int ret = 0; VALIDATE_HANDLE(handle); - calc = handle->calc; + const CalcFncts* calc = handle->calc; VALIDATE_CALCFNCTS(calc); RETURN_IF_HANDLE_NOT_ATTACHED(handle); @@ -258,7 +255,7 @@ int TICALL ticalcs_calc_recv_screen_rgb888(CalcHandle* handle, CalcScreenCoord* if (!ret) { - uint8_t * bitmap2 = NULL; + uint8_t * bitmap2 = nullptr; if (sc->width > 320) { @@ -279,7 +276,7 @@ int TICALL ticalcs_calc_recv_screen_rgb888(CalcHandle* handle, CalcScreenCoord* if (ret) { ticalcs_free_screen(bitmap2); - bitmap2 = NULL; + bitmap2 = nullptr; } } *bitmap = bitmap2; @@ -311,7 +308,6 @@ void TICALL ticalcs_free_screen(uint8_t * bitmap) **/ int TICALL ticalcs_calc_get_dirlist(CalcHandle* handle, GNode** vars, GNode **apps) { - const CalcFncts *calc; int ret = 0; TreeInfo *ti; @@ -319,15 +315,15 @@ int TICALL ticalcs_calc_get_dirlist(CalcHandle* handle, GNode** vars, GNode **ap VALIDATE_NONNULL(vars); VALIDATE_NONNULL(apps); - calc = handle->calc; + const CalcFncts* calc = handle->calc; VALIDATE_CALCFNCTS(calc); RETURN_IF_HANDLE_NOT_ATTACHED(handle); RETURN_IF_HANDLE_NOT_OPEN(handle); RETURN_IF_HANDLE_BUSY(handle); - *vars = NULL; - *apps = NULL; + *vars = nullptr; + *apps = nullptr; ticalcs_info("%s", _("Requesting folder & vars & apps listing:")); handle->busy = 1; @@ -344,14 +340,14 @@ int TICALL ticalcs_calc_get_dirlist(CalcHandle* handle, GNode** vars, GNode **ap if (!ret) { - if (*vars != NULL) + if (*vars != nullptr) { ti = (TreeInfo *)((*vars)->data); ti->mem_mask |= MEMORY_USED; ti->mem_used = ticalcs_dirlist_ram_used(*vars); } - if (*apps != NULL) + if (*apps != nullptr) { ti = (TreeInfo *)((*apps)->data); ti->mem_mask |= MEMORY_USED; @@ -374,14 +370,13 @@ int TICALL ticalcs_calc_get_dirlist(CalcHandle* handle, GNode** vars, GNode **ap **/ int TICALL ticalcs_calc_get_memfree(CalcHandle* handle, uint32_t* ram, uint32_t *flash) { - const CalcFncts *calc; int ret = 0; VALIDATE_HANDLE(handle); VALIDATE_NONNULL(ram); VALIDATE_NONNULL(flash); - calc = handle->calc; + const CalcFncts* calc = handle->calc; VALIDATE_CALCFNCTS(calc); RETURN_IF_HANDLE_NOT_ATTACHED(handle); @@ -891,12 +886,11 @@ int TICALL ticalcs_calc_recv_idlist(CalcHandle* handle, uint8_t* idlist) **/ int TICALL ticalcs_calc_dump_rom_1(CalcHandle* handle) { - const CalcFncts *calc; int ret = 0; VALIDATE_HANDLE(handle); - calc = handle->calc; + const CalcFncts* calc = handle->calc; VALIDATE_CALCFNCTS(calc); RETURN_IF_HANDLE_NOT_ATTACHED(handle); @@ -931,13 +925,12 @@ int TICALL ticalcs_calc_dump_rom_1(CalcHandle* handle) **/ int TICALL ticalcs_calc_dump_rom_2(CalcHandle* handle, CalcDumpSize size, const char *filename) { - const CalcFncts *calc; int ret = 0; VALIDATE_HANDLE(handle); VALIDATE_NONNULL(filename); - calc = handle->calc; + const CalcFncts* calc = handle->calc; VALIDATE_CALCFNCTS(calc); RETURN_IF_HANDLE_NOT_ATTACHED(handle); @@ -1481,13 +1474,12 @@ int TICALL ticalcs_calc_recv_all_vars_backup(CalcHandle* handle, FileContent* co **/ int TICALL ticalcs_calc_send_lab_equipment_data(CalcHandle *handle, CalcModel model, CalcLabEquipmentData * lab_equipment_data) { - const CalcFncts *calc; int ret = 0; VALIDATE_HANDLE(handle); VALIDATE_NONNULL(lab_equipment_data); - calc = handle->calc; + const CalcFncts* calc = handle->calc; VALIDATE_CALCFNCTS(calc); RETURN_IF_HANDLE_NOT_ATTACHED(handle); @@ -1530,13 +1522,12 @@ int TICALL ticalcs_calc_send_lab_equipment_data(CalcHandle *handle, CalcModel mo **/ int TICALL ticalcs_calc_get_lab_equipment_data(CalcHandle *handle, CalcModel model, CalcLabEquipmentData * lab_equipment_data) { - const CalcFncts *calc; int ret = 0; VALIDATE_HANDLE(handle); VALIDATE_NONNULL(lab_equipment_data); - calc = handle->calc; + const CalcFncts* calc = handle->calc; VALIDATE_CALCFNCTS(calc); RETURN_IF_HANDLE_NOT_ATTACHED(handle); @@ -1700,7 +1691,7 @@ int TICALL ticalcs_calc_recv_backup2(CalcHandle* handle, const char *filename) ret = ticalcs_calc_recv_all_vars_backup(handle, content); if (!ret) { - ret = tifiles_file_write_regular(filename, content, NULL); + ret = tifiles_file_write_regular(filename, content, nullptr); } // content is not destroyed by the functions behind ticalcs_calc_recv_all_vars_backup() if an error occurs. tifiles_content_delete_regular(content); @@ -1712,9 +1703,6 @@ int TICALL ticalcs_calc_recv_backup2(CalcHandle* handle, const char *filename) // ticalcs_calc_send_var2_: core of ticalcs_calc_send_var2, the take_busy argument enables avoiding playing games with handle->busy in rd_send_dumper() / rd_send_dumper2(). int ticalcs_calc_send_var2_(CalcHandle* handle, CalcMode mode, const char* filename, int take_busy) { - FileContent *content; - int ret; - VALIDATE_HANDLE(handle); VALIDATE_NONNULL(filename); @@ -1725,8 +1713,8 @@ int ticalcs_calc_send_var2_(CalcHandle* handle, CalcMode mode, const char* filen RETURN_IF_HANDLE_BUSY(handle); } - content = tifiles_content_create_regular(handle->model); - ret = tifiles_file_read_regular(filename, content); + FileContent* content = tifiles_content_create_regular(handle->model); + int ret = tifiles_file_read_regular(filename, content); if (!ret) { ret = ticalcs_calc_send_var_(handle, mode, content, take_busy); @@ -1765,9 +1753,6 @@ int TICALL ticalcs_calc_send_var2(CalcHandle* handle, CalcMode mode, const char* **/ int TICALL ticalcs_calc_recv_var2(CalcHandle* handle, CalcMode mode, const char* filename, VarRequest* vr) { - FileContent *content; - int ret; - VALIDATE_HANDLE(handle); VALIDATE_NONNULL(filename); VALIDATE_VARREQUEST(vr); @@ -1776,11 +1761,11 @@ int TICALL ticalcs_calc_recv_var2(CalcHandle* handle, CalcMode mode, const char* RETURN_IF_HANDLE_NOT_OPEN(handle); RETURN_IF_HANDLE_BUSY(handle); - content = tifiles_content_create_regular(handle->model); - ret = ticalcs_calc_recv_var(handle, mode, content, vr); + FileContent* content = tifiles_content_create_regular(handle->model); + int ret = ticalcs_calc_recv_var(handle, mode, content, vr); if (!ret) { - ret = tifiles_file_write_regular(filename, content, NULL); + ret = tifiles_file_write_regular(filename, content, nullptr); } // content is not destroyed by the functions behind ticalcs_calc_recv_var() if an error occurs. tifiles_content_delete_regular(content); @@ -1800,7 +1785,6 @@ int TICALL ticalcs_calc_recv_var2(CalcHandle* handle, CalcMode mode, const char* **/ int TICALL ticalcs_calc_send_var_ns2(CalcHandle* handle, CalcMode mode, const char* filename) { - FileContent *content; int ret = ERR_FILE_OPEN; VALIDATE_HANDLE(handle); @@ -1810,7 +1794,7 @@ int TICALL ticalcs_calc_send_var_ns2(CalcHandle* handle, CalcMode mode, const ch RETURN_IF_HANDLE_NOT_OPEN(handle); RETURN_IF_HANDLE_BUSY(handle); - content = tifiles_content_create_regular(handle->model); + FileContent* content = tifiles_content_create_regular(handle->model); ret = tifiles_file_read_regular(filename, content); if (!ret) { @@ -1835,9 +1819,6 @@ int TICALL ticalcs_calc_send_var_ns2(CalcHandle* handle, CalcMode mode, const ch **/ int TICALL ticalcs_calc_recv_var_ns2(CalcHandle* handle, CalcMode mode, const char* filename, VarEntry** vr) { - FileContent *content; - int ret; - VALIDATE_HANDLE(handle); VALIDATE_NONNULL(filename); VALIDATE_NONNULL(vr); @@ -1846,11 +1827,11 @@ int TICALL ticalcs_calc_recv_var_ns2(CalcHandle* handle, CalcMode mode, const ch RETURN_IF_HANDLE_NOT_OPEN(handle); RETURN_IF_HANDLE_BUSY(handle); - content = tifiles_content_create_regular(handle->model); - ret = ticalcs_calc_recv_var_ns(handle, mode, content, vr); + FileContent* content = tifiles_content_create_regular(handle->model); + int ret = ticalcs_calc_recv_var_ns(handle, mode, content, vr); if (!ret) { - ret = tifiles_file_write_regular(filename, content, NULL); + ret = tifiles_file_write_regular(filename, content, nullptr); } // content is not destroyed by the functions behind ticalcs_calc_recv_var_ns() if an error occurs. tifiles_content_delete_regular(content); @@ -1869,9 +1850,6 @@ int TICALL ticalcs_calc_recv_var_ns2(CalcHandle* handle, CalcMode mode, const ch **/ int TICALL ticalcs_calc_send_app2(CalcHandle* handle, const char* filename) { - FlashContent *content; - int ret; - VALIDATE_HANDLE(handle); VALIDATE_NONNULL(filename); @@ -1879,8 +1857,8 @@ int TICALL ticalcs_calc_send_app2(CalcHandle* handle, const char* filename) RETURN_IF_HANDLE_NOT_OPEN(handle); RETURN_IF_HANDLE_BUSY(handle); - content = tifiles_content_create_flash(handle->model); - ret = tifiles_file_read_flash(filename, content); + FlashContent* content = tifiles_content_create_flash(handle->model); + int ret = tifiles_file_read_flash(filename, content); if (!ret) { ret = ticalcs_calc_send_app(handle, content); @@ -1903,9 +1881,6 @@ int TICALL ticalcs_calc_send_app2(CalcHandle* handle, const char* filename) **/ int TICALL ticalcs_calc_recv_app2(CalcHandle* handle, const char* filename, VarRequest* vr) { - FlashContent *content; - int ret; - VALIDATE_HANDLE(handle); VALIDATE_NONNULL(filename); VALIDATE_VARREQUEST(vr); @@ -1914,8 +1889,8 @@ int TICALL ticalcs_calc_recv_app2(CalcHandle* handle, const char* filename, VarR RETURN_IF_HANDLE_NOT_OPEN(handle); RETURN_IF_HANDLE_BUSY(handle); - content = tifiles_content_create_flash(handle->model); - ret = ticalcs_calc_recv_app(handle, content, vr); + FlashContent* content = tifiles_content_create_flash(handle->model); + int ret = ticalcs_calc_recv_app(handle, content, vr); if (!ret) { ret = tifiles_file_write_flash(filename, content); @@ -1937,9 +1912,6 @@ int TICALL ticalcs_calc_recv_app2(CalcHandle* handle, const char* filename, VarR **/ int TICALL ticalcs_calc_send_cert2(CalcHandle* handle, const char* filename) { - FlashContent *content; - int ret; - VALIDATE_HANDLE(handle); VALIDATE_NONNULL(filename); @@ -1947,8 +1919,8 @@ int TICALL ticalcs_calc_send_cert2(CalcHandle* handle, const char* filename) RETURN_IF_HANDLE_NOT_OPEN(handle); RETURN_IF_HANDLE_BUSY(handle); - content = tifiles_content_create_flash(handle->model); - ret = tifiles_file_read_flash(filename, content); + FlashContent* content = tifiles_content_create_flash(handle->model); + int ret = tifiles_file_read_flash(filename, content); if (!ret) { ret = ticalcs_calc_send_cert(handle, content); @@ -1970,9 +1942,6 @@ int TICALL ticalcs_calc_send_cert2(CalcHandle* handle, const char* filename) **/ int TICALL ticalcs_calc_send_os2(CalcHandle* handle, const char* filename) { - FlashContent *content; - int ret; - VALIDATE_HANDLE(handle); VALIDATE_NONNULL(filename); @@ -1980,8 +1949,8 @@ int TICALL ticalcs_calc_send_os2(CalcHandle* handle, const char* filename) RETURN_IF_HANDLE_NOT_OPEN(handle); RETURN_IF_HANDLE_BUSY(handle); - content = tifiles_content_create_flash(handle->model); - ret = tifiles_file_read_flash(filename, content); + FlashContent* content = tifiles_content_create_flash(handle->model); + int ret = tifiles_file_read_flash(filename, content); if (!ret) { ret = ticalcs_calc_send_os(handle, content); @@ -2004,7 +1973,6 @@ int TICALL ticalcs_calc_send_os2(CalcHandle* handle, const char* filename) **/ int TICALL ticalcs_calc_send_lab_equipment_data2(CalcHandle *handle, CalcModel model, uint8_t vartype, const char * data) { - int ret; CalcLabEquipmentData lab_equipment_data; VALIDATE_HANDLE(handle); @@ -2021,7 +1989,7 @@ int TICALL ticalcs_calc_send_lab_equipment_data2(CalcHandle *handle, CalcModel m lab_equipment_data.index = 0; lab_equipment_data.unknown = 0; lab_equipment_data.vartype = vartype; - ret = ticalcs_calc_send_lab_equipment_data(handle, model, &lab_equipment_data); + const int ret = ticalcs_calc_send_lab_equipment_data(handle, model, &lab_equipment_data); return ret; } @@ -2038,7 +2006,6 @@ int TICALL ticalcs_calc_send_lab_equipment_data2(CalcHandle *handle, CalcModel m **/ int TICALL ticalcs_calc_get_lab_equipment_data2(CalcHandle *handle, CalcModel model, uint8_t vartype, const char ** data) { - int ret; CalcLabEquipmentData lab_equipment_data; VALIDATE_HANDLE(handle); @@ -2055,7 +2022,7 @@ int TICALL ticalcs_calc_get_lab_equipment_data2(CalcHandle *handle, CalcModel mo lab_equipment_data.index = 0; lab_equipment_data.unknown = 0; lab_equipment_data.vartype = vartype; - ret = ticalcs_calc_get_lab_equipment_data(handle, model, &lab_equipment_data); + int ret = ticalcs_calc_get_lab_equipment_data(handle, model, &lab_equipment_data); if (!ret) { uint32_t item_count; @@ -2106,8 +2073,7 @@ void TICALL ticalcs_free_lab_equipment_data2(char * data) **/ int TICALL ticalcs_calc_recv_cert2(CalcHandle* handle, const char* filename) { - FlashContent *content = NULL; - char *ext; + FlashContent *content = nullptr; int ret; VALIDATE_HANDLE(handle); @@ -2118,21 +2084,19 @@ int TICALL ticalcs_calc_recv_cert2(CalcHandle* handle, const char* filename) RETURN_IF_HANDLE_BUSY(handle); do { - ext = tifiles_fext_get(filename); + const char* ext = tifiles_fext_get(filename); if (!strcmp(ext, "cer")) { // .cer format as generated by SDK gchar *basename = strdup(filename); - FILE *f; - gchar *e; - if (basename == NULL) + if (basename == nullptr) { ret = ERR_MALLOC; break; } - e = tifiles_fext_get(basename); + gchar* e = tifiles_fext_get(basename); memcpy(e, "crt", 3); @@ -2144,7 +2108,7 @@ int TICALL ticalcs_calc_recv_cert2(CalcHandle* handle, const char* filename) break; } - f = fopen(basename, "wb"); + FILE* f = fopen(basename, "wb"); free(basename); if (!f) { @@ -2193,9 +2157,6 @@ int TICALL ticalcs_calc_recv_cert2(CalcHandle* handle, const char* filename) **/ int TICALL ticalcs_calc_send_tigroup2(CalcHandle* handle, const char* filename, TigMode mode) { - TigContent *content; - int ret; - VALIDATE_HANDLE(handle); VALIDATE_NONNULL(filename); @@ -2203,8 +2164,8 @@ int TICALL ticalcs_calc_send_tigroup2(CalcHandle* handle, const char* filename, RETURN_IF_HANDLE_NOT_OPEN(handle); RETURN_IF_HANDLE_BUSY(handle); - content = tifiles_content_create_tigroup(handle->model, 0); - ret = tifiles_file_read_tigroup(filename, content); + TigContent* content = tifiles_content_create_tigroup(handle->model, 0); + int ret = tifiles_file_read_tigroup(filename, content); if (!ret) { ret = ticalcs_calc_send_tigroup(handle, content, mode); @@ -2227,9 +2188,6 @@ int TICALL ticalcs_calc_send_tigroup2(CalcHandle* handle, const char* filename, **/ int TICALL ticalcs_calc_recv_tigroup2(CalcHandle* handle, const char* filename, TigMode mode) { - TigContent *content; - int ret; - VALIDATE_HANDLE(handle); VALIDATE_NONNULL(filename); @@ -2237,8 +2195,8 @@ int TICALL ticalcs_calc_recv_tigroup2(CalcHandle* handle, const char* filename, RETURN_IF_HANDLE_NOT_OPEN(handle); RETURN_IF_HANDLE_BUSY(handle); - content = tifiles_content_create_tigroup(handle->model, 0); - ret = ticalcs_calc_recv_tigroup(handle, content, mode); + TigContent* content = tifiles_content_create_tigroup(handle->model, 0); + int ret = ticalcs_calc_recv_tigroup(handle, content, mode); if (!ret) { ret = tifiles_file_write_tigroup(filename, content); diff --git a/libticalcs/trunk/src/calclabequipmentdata.cc b/libticalcs/trunk/src/calclabequipmentdata.cc index 9667b6578..1e1dd655a 100644 --- a/libticalcs/trunk/src/calclabequipmentdata.cc +++ b/libticalcs/trunk/src/calclabequipmentdata.cc @@ -45,24 +45,20 @@ int tixx_convert_lab_equipment_data_string_to_ti8586_raw_list(const char * lab_equipment_data, CalcLabEquipmentData * out_data) { - int ret; - VALIDATE_NONNULL(lab_equipment_data); VALIDATE_NONNULL(out_data); - ret = ERR_UNSUPPORTED; + const int ret = ERR_UNSUPPORTED; return ret; } int tixx_convert_lab_equipment_data_string_to_tiz80_raw_list(const char * lab_equipment_data, CalcLabEquipmentData * out_data) { - int ret; - VALIDATE_NONNULL(lab_equipment_data); VALIDATE_NONNULL(out_data); - ret = ERR_UNSUPPORTED; + const int ret = ERR_UNSUPPORTED; return ret; } @@ -70,15 +66,11 @@ int tixx_convert_lab_equipment_data_string_to_tiz80_raw_list(const char * lab_eq int tixx_convert_lab_equipment_data_string_to_ti68k_raw_list(const char * lab_equipment_data, CalcLabEquipmentData * out_data) { int ret; - uint8_t * ptr; - uint8_t * orig_ptr; - unsigned int state; - uint32_t items; VALIDATE_NONNULL(lab_equipment_data); VALIDATE_NONNULL(out_data); - ptr = (uint8_t *)strdup(lab_equipment_data); + uint8_t* ptr = (uint8_t*)strdup(lab_equipment_data); if (nullptr == ptr) { return ERR_MALLOC; @@ -96,12 +88,12 @@ int tixx_convert_lab_equipment_data_string_to_ti68k_raw_list(const char * lab_eq // TODO perform more RE of the protocol using TIEmu, especially for floating-point numbers. // TODO FIXME parse floating-point numbers as well. // TODO FIXME convert leading - to unary minus, if necessary. - state = 0; - items = 0; - orig_ptr = ptr; + unsigned int state = 0; + uint32_t items = 0; + const uint8_t* orig_ptr = ptr; do { - uint8_t c = *ptr; + const uint8_t c = *ptr; switch (state) { // We'd need more states if we wanted to cope with spaces before and after '{', ',' and '}'. @@ -144,28 +136,24 @@ int tixx_convert_lab_equipment_data_string_to_ti68k_raw_list(const char * lab_eq int tixx_convert_lab_equipment_data_ti8586_raw_list_to_string(CalcLabEquipmentData * lab_equipment_data, uint32_t * item_count, double ** raw_values, const char ** out_data) { - int ret; - VALIDATE_NONNULL(lab_equipment_data); VALIDATE_NONNULL(item_count); VALIDATE_NONNULL(raw_values); VALIDATE_NONNULL(out_data); - ret = ERR_UNSUPPORTED; + const int ret = ERR_UNSUPPORTED; return ret; } int tixx_convert_lab_equipment_data_tiz80_raw_list_to_string(CalcLabEquipmentData * lab_equipment_data, uint32_t * item_count, double ** raw_values, const char ** out_data) { - int ret; - VALIDATE_NONNULL(lab_equipment_data); VALIDATE_NONNULL(item_count); VALIDATE_NONNULL(raw_values); VALIDATE_NONNULL(out_data); - ret = ERR_UNSUPPORTED; + const int ret = ERR_UNSUPPORTED; return ret; } @@ -180,9 +168,6 @@ int tixx_convert_lab_equipment_data_ti68k_raw_list_to_string(CalcLabEquipmentDat size_t deststrsize; size_t offset; double * fpvals = nullptr; - struct lconv * lc; - const char * decimal_point_str; - size_t decimal_point_len; VALIDATE_NONNULL(lab_equipment_data); VALIDATE_NONNULL(item_count); @@ -212,12 +197,12 @@ int tixx_convert_lab_equipment_data_ti68k_raw_list_to_string(CalcLabEquipmentDat return 0; } - lc = localeconv(); - decimal_point_str = lc->decimal_point; - decimal_point_len = strlen(decimal_point_str); + const struct lconv* lc = localeconv(); + const char* decimal_point_str = lc->decimal_point; + const size_t decimal_point_len = strlen(decimal_point_str); ptr = lab_equipment_data->data + 4; - deststrsize = strlen((const char *)ptr); + deststrsize = strlen((const char*)ptr); deststrsize += items * (decimal_point_len - 1); deststr = (char *)malloc(deststrsize + 1); if (nullptr == deststr) @@ -234,7 +219,7 @@ int tixx_convert_lab_equipment_data_ti68k_raw_list_to_string(CalcLabEquipmentDat goto err; } - ptr2 = (uint8_t *)strchr(deststr, '.'); + ptr2 = (uint8_t*)strchr(deststr, '.'); // Need to replace the decimal point. if (decimal_point_str[0] != '.' || decimal_point_str[1] != 0) { @@ -267,7 +252,7 @@ int tixx_convert_lab_equipment_data_ti68k_raw_list_to_string(CalcLabEquipmentDat offset = 1; for (uint16_t i = 0; i < items; i++) { - int printed = sprintf(deststr + offset, "%g,", fpvals[i]); + const int printed = sprintf(deststr + offset, "%g,", fpvals[i]); offset += printed; } deststr[offset - 1] = '}'; @@ -315,8 +300,6 @@ void tixx_free_converted_lab_equipment_data_fpvals(double * raw_values) int tixx_send_lab_equipment_data(CalcHandle* handle, CalcModel model, CalcLabEquipmentData * lab_equipment_data) { int ret; - uint8_t target1; - uint8_t target2; uint32_t size = 0; uint32_t items = 0; const uint8_t * ptr = nullptr; @@ -326,8 +309,8 @@ int tixx_send_lab_equipment_data(CalcHandle* handle, CalcModel model, CalcLabEqu VALIDATE_HANDLE(handle); VALIDATE_NONNULL(lab_equipment_data); - target1 = ti68k_model_to_dbus_mid(model); - target2 = tiz80_model_to_dbus_mid(model); + const uint8_t target1 = ti68k_model_to_dbus_mid(model); + const uint8_t target2 = tiz80_model_to_dbus_mid(model); if (target1 == DBUS_MID_PC_TIXX && target2 == DBUS_MID_PC_TIXX) { @@ -444,11 +427,10 @@ int tixx_send_lab_equipment_data(CalcHandle* handle, CalcModel model, CalcLabEqu */ do { - uint8_t * ptr2; ret = ti68k_send_VAR_lab_equipment_data(handle, size, vartype, target1); if (ret) break; - ret = ti89_recv_ACK(handle, NULL); + ret = ti89_recv_ACK(handle, nullptr); if (ret) break; ret = ti92_recv_CTS(handle); @@ -460,7 +442,7 @@ int tixx_send_lab_equipment_data(CalcHandle* handle, CalcModel model, CalcLabEqu ticalcs_info("Sending \"%s\"", ptr); // Build number of items as 32-bit little-endian. - ptr2 = (uint8_t *)handle->buffer2; + uint8_t* ptr2 = (uint8_t*)handle->buffer2; ptr2[0] = items & 0xFF; ptr2[1] = (items >> 8) & 0xFF; ptr2[2] = (items >> 16) & 0xFF; @@ -469,13 +451,13 @@ int tixx_send_lab_equipment_data(CalcHandle* handle, CalcModel model, CalcLabEqu ret = ti68k_send_XDP(handle, size + 4, ptr2, target1); if (ret) break; - ret = ti89_recv_ACK(handle, NULL); + ret = ti89_recv_ACK(handle, nullptr); if (ret) break; ret = ti68k_send_EOT(handle, target1); if (ret) break; - ret = ti89_recv_ACK(handle, NULL); + ret = ti89_recv_ACK(handle, nullptr); } while(0); } @@ -565,14 +547,12 @@ int tixx_send_lab_equipment_data(CalcHandle* handle, CalcModel model, CalcLabEqu int tixx_get_lab_equipment_data(CalcHandle* handle, CalcModel model, CalcLabEquipmentData * lab_equipment_data) { int ret; - uint8_t target1; - uint8_t target2; VALIDATE_HANDLE(handle); VALIDATE_NONNULL(lab_equipment_data); - target1 = ti68k_model_to_dbus_mid(model); - target2 = tiz80_model_to_dbus_mid(model); + const uint8_t target1 = ti68k_model_to_dbus_mid(model); + const uint8_t target2 = tiz80_model_to_dbus_mid(model); if (target1 == DBUS_MID_PC_TIXX && target2 == DBUS_MID_PC_TIXX) { @@ -619,12 +599,11 @@ int tixx_get_lab_equipment_data(CalcHandle* handle, CalcModel model, CalcLabEqui uint8_t vartype; char varname[256 + 1]; uint16_t length; - uint8_t * ptr; ret = ti92_send_REQ(handle, 0, 0x4, ""); if (ret) break; - ret = ti89_recv_ACK(handle, NULL); + ret = ti89_recv_ACK(handle, nullptr); if (ret) break; varname[0] = 0; @@ -642,7 +621,7 @@ int tixx_get_lab_equipment_data(CalcHandle* handle, CalcModel model, CalcLabEqui ret = ti68k_send_CTS(handle, target1); if (ret) break; - ret = ti89_recv_ACK(handle, NULL); + ret = ti89_recv_ACK(handle, nullptr); if (ret) break; ret = ti68k_recv_XDP(handle, &length, (uint8_t *)handle->buffer2); @@ -656,7 +635,7 @@ int tixx_get_lab_equipment_data(CalcHandle* handle, CalcModel model, CalcLabEqui ret = ti68k_send_ACK(handle, target1); if (ret) break; - ptr = (uint8_t *)handle->buffer2; + uint8_t* ptr = (uint8_t*)handle->buffer2; lab_equipment_data->type = CALC_LAB_EQUIPMENT_DATA_TYPE_TI68K_RAW_LIST; lab_equipment_data->size = varsize; lab_equipment_data->items = ptr[0] | (((uint16_t)ptr[1]) << 8); diff --git a/libticalcs/trunk/src/clock.cc b/libticalcs/trunk/src/clock.cc index 335f9a60b..b8d235034 100644 --- a/libticalcs/trunk/src/clock.cc +++ b/libticalcs/trunk/src/clock.cc @@ -124,7 +124,7 @@ int TICALL ticalcs_clock_date2format(CalcModel model, const char *format) { int i = 1; - if (format == NULL) + if (format == nullptr) { ticalcs_critical("ticalcs_clock_date2format: format is NULL"); return 0; @@ -173,7 +173,7 @@ int TICALL ticalcs_clock_date2format(CalcModel model, const char *format) **/ int TICALL ticalcs_clock_show(CalcModel model, CalcClock* s) { - if (s != NULL) + if (s != nullptr) { ticalcs_info("Date: %04i/%02i/%02i", s->year, s->month, s->day); ticalcs_info("Time: %02i/%02i/%02i", s->hours, s->minutes, s->seconds); diff --git a/libticalcs/trunk/src/cmd68k.cc b/libticalcs/trunk/src/cmd68k.cc index 426baa6fd..1ba09d80f 100644 --- a/libticalcs/trunk/src/cmd68k.cc +++ b/libticalcs/trunk/src/cmd68k.cc @@ -83,11 +83,10 @@ static const uint8_t dbus_errors[] = { 0x03, 0x25, 0x1e, 0x21, 0x07, 0x24, 0x08 static int err_code(uint8_t *data) { - int i; - int code = data[2]; + const int code = data[2]; ticalcs_info(" TI->PC: SKP (%02x)", data[0]); - for (i = 0; i < (int)(sizeof(dbus_errors) / sizeof(dbus_errors[0])); i++) + for (int i = 0; i < (int)(sizeof(dbus_errors) / sizeof(dbus_errors[0])); i++) { if(dbus_errors[i] == code) { @@ -104,13 +103,12 @@ int TICALL ti68k_send_VAR(CalcHandle* handle, uint32_t varsize, uint8_t vartype, { uint8_t buffer[32]; char trans[127]; - uint8_t extra = (target == DBUS_MID_PC_TI92) ? 0 : ((vartype == TI89_BKUP) ? 0 : 1); - uint16_t len; + const uint8_t extra = (target == DBUS_MID_PC_TI92) ? 0 : ((vartype == TI89_BKUP) ? 0 : 1); VALIDATE_HANDLE(handle); VALIDATE_NONNULL(varname); - len = (uint16_t)strlen(varname); + uint16_t len = (uint16_t)strlen(varname); if (len > 17) { ticalcs_critical("Oversized variable name has length %i, clamping to 17", len); @@ -153,7 +151,7 @@ int TICALL ti68k_send_VAR_lab_equipment_data(CalcHandle* handle, uint32_t varsiz int TICALL ti68k_send_CTS(CalcHandle* handle, uint8_t target) { - return ti68k_send_simple_cmd(handle, target, DBUS_CMD_CTS, "CTS", 2, NULL); + return ti68k_send_simple_cmd(handle, target, DBUS_CMD_CTS, "CTS", 2, nullptr); } int TICALL ti68k_send_XDP(CalcHandle* handle, uint32_t length, uint8_t * data, uint8_t target) @@ -184,32 +182,31 @@ int TICALL ti92_send_SKP(CalcHandle* handle, uint8_t rej_code) int TICALL ti68k_send_ACK(CalcHandle* handle, uint8_t target) { - return ti68k_send_simple_cmd(handle, target, DBUS_CMD_ACK, "ACK", 2, NULL); + return ti68k_send_simple_cmd(handle, target, DBUS_CMD_ACK, "ACK", 2, nullptr); } int TICALL ti68k_send_ERR(CalcHandle* handle, uint8_t target) { - return ti68k_send_simple_cmd(handle, target, DBUS_CMD_ERR, "ERR", 2, NULL); + return ti68k_send_simple_cmd(handle, target, DBUS_CMD_ERR, "ERR", 2, nullptr); } int TICALL ti68k_send_RDY(CalcHandle* handle, uint8_t target) { - return ti68k_send_simple_cmd(handle, target, DBUS_CMD_RDY, "RDY", 2, NULL); + return ti68k_send_simple_cmd(handle, target, DBUS_CMD_RDY, "RDY", 2, nullptr); } int TICALL ti68k_send_SCR(CalcHandle* handle, uint8_t target) { - return ti68k_send_simple_cmd(handle, target, DBUS_CMD_SCR, "SCR", 2, NULL); + return ti68k_send_simple_cmd(handle, target, DBUS_CMD_SCR, "SCR", 2, nullptr); } int TICALL ti68k_send_CNT(CalcHandle* handle, uint8_t target) { - return ti68k_send_simple_cmd(handle, target, DBUS_CMD_CNT, "CNT", 2, NULL); + return ti68k_send_simple_cmd(handle, target, DBUS_CMD_CNT, "CNT", 2, nullptr); } int TICALL ti68k_send_KEY(CalcHandle* handle, uint16_t scancode, uint8_t target) { - int ret; uint8_t buf[4] = { target, DBUS_CMD_KEY, LSB(scancode), MSB(scancode) }; CalcEventData event; @@ -220,8 +217,8 @@ int TICALL ti68k_send_KEY(CalcHandle* handle, uint16_t scancode, uint8_t target) SET_HANDLE_BUSY_IF_NECESSARY(handle); ticalcs_event_fill_header(handle, &event, /* type */ CALC_EVENT_TYPE_BEFORE_SEND_DBUS_PKT, /* retval */ 0, /* operation */ CALC_FNCT_LAST); - ticalcs_event_fill_dbus_pkt(&event, /* length */ scancode, /* id */ target, /* cmd */ DBUS_CMD_KEY, /* data */ NULL); - ret = ticalcs_event_send(handle, &event); + ticalcs_event_fill_dbus_pkt(&event, /* length */ scancode, /* id */ target, /* cmd */ DBUS_CMD_KEY, /* data */ nullptr); + int ret = ticalcs_event_send(handle, &event); if (!ret) { @@ -229,7 +226,7 @@ int TICALL ti68k_send_KEY(CalcHandle* handle, uint16_t scancode, uint8_t target) } ticalcs_event_fill_header(handle, &event, /* type */ CALC_EVENT_TYPE_AFTER_SEND_DBUS_PKT, /* retval */ ret, /* operation */ CALC_FNCT_LAST); - ticalcs_event_fill_dbus_pkt(&event, /* length */ scancode, /* id */ target, /* cmd */ DBUS_CMD_KEY, /* data */ NULL); + ticalcs_event_fill_dbus_pkt(&event, /* length */ scancode, /* id */ target, /* cmd */ DBUS_CMD_KEY, /* data */ nullptr); ret = ticalcs_event_send(handle, &event); CLEAR_HANDLE_BUSY_IF_NECESSARY(handle); @@ -239,17 +236,16 @@ int TICALL ti68k_send_KEY(CalcHandle* handle, uint16_t scancode, uint8_t target) int TICALL ti68k_send_EOT(CalcHandle* handle, uint8_t target) { - return ti68k_send_simple_cmd(handle, target, DBUS_CMD_EOT, "EOT", 2, NULL); + return ti68k_send_simple_cmd(handle, target, DBUS_CMD_EOT, "EOT", 2, nullptr); } int TICALL ti89_send_REQ(CalcHandle* handle, uint32_t varsize, uint8_t vartype, const char *varname) { uint8_t buffer[32]; - uint16_t len; VALIDATE_HANDLE(handle); VALIDATE_NONNULL(varname); - len = (uint16_t)strlen(varname); + uint16_t len = (uint16_t)strlen(varname); if (len > 17) { ticalcs_critical("Oversized variable name has length %i, clamping to 17", len); @@ -277,11 +273,10 @@ int TICALL ti89_send_REQ(CalcHandle* handle, uint32_t varsize, uint8_t vartype, int TICALL ti92_send_REQ(CalcHandle* handle, uint32_t varsize, uint8_t vartype, const char *varname) { uint8_t buffer[32]; - uint16_t len; VALIDATE_HANDLE(handle); VALIDATE_NONNULL(varname); - len = (uint16_t)strlen(varname); + uint16_t len = (uint16_t)strlen(varname); if (len > 17) { ticalcs_critical("Oversized variable name has length %i, clamping to 17", len); @@ -303,11 +298,10 @@ int TICALL ti92_send_REQ(CalcHandle* handle, uint32_t varsize, uint8_t vartype, int TICALL ti89_send_RTS(CalcHandle* handle, uint32_t varsize, uint8_t vartype, const char *varname) { uint8_t buffer[32]; - uint16_t len; VALIDATE_HANDLE(handle); VALIDATE_NONNULL(varname); - len = (uint16_t)strlen(varname); + uint16_t len = (uint16_t)strlen(varname); if (len > 17) { ticalcs_critical("Oversized variable name has length %i, clamping to 17", len); @@ -334,11 +328,10 @@ int TICALL ti89_send_RTS(CalcHandle* handle, uint32_t varsize, uint8_t vartype, int TICALL ti92_send_RTS(CalcHandle* handle, uint32_t varsize, uint8_t vartype, const char *varname) { uint8_t buffer[32]; - uint16_t len; VALIDATE_HANDLE(handle); VALIDATE_NONNULL(varname); - len = (uint16_t)strlen(varname); + uint16_t len = (uint16_t)strlen(varname); if (len > 17) { ticalcs_critical("Oversized variable name has length %i, clamping to 17", len); @@ -379,17 +372,16 @@ int TICALL ti89_send_RTS2(CalcHandle* handle, uint32_t varsize, uint8_t vartype, int TICALL ti89_send_VER(CalcHandle* handle) { - return ti68k_send_simple_cmd(handle, ti68k_handle_to_dbus_mid(handle), DBUS_CMD_VER, "VER", 2, NULL); + return ti68k_send_simple_cmd(handle, ti68k_handle_to_dbus_mid(handle), DBUS_CMD_VER, "VER", 2, nullptr); } int TICALL ti89_send_DEL(CalcHandle* handle, uint32_t varsize, uint8_t vartype, const char *varname) { uint8_t buffer[32]; - uint16_t len; VALIDATE_HANDLE(handle); VALIDATE_NONNULL(varname); - len = (uint16_t)strlen(varname); + uint16_t len = (uint16_t)strlen(varname); if (len > 17) { ticalcs_critical("Oversized variable name has length %i, clamping to 17", len); @@ -411,20 +403,15 @@ int TICALL ti89_send_DEL(CalcHandle* handle, uint32_t varsize, uint8_t vartype, int TICALL ti89_recv_VAR(CalcHandle* handle, uint32_t * varsize, uint8_t * vartype, char *varname) { uint8_t host = 0, cmd = 0; - uint8_t *buffer; uint16_t length = 0; - uint8_t strl; - uint8_t flag; - char * varname_nofldname; - int ret; VALIDATE_HANDLE(handle); VALIDATE_NONNULL(varsize); VALIDATE_NONNULL(vartype); VALIDATE_NONNULL(varname); - buffer = (uint8_t *)handle->buffer; - ret = dbus_recv(handle, &host, &cmd, &length, buffer); + uint8_t* buffer = (uint8_t*)handle->buffer; + const int ret = dbus_recv(handle, &host, &cmd, &length, buffer); if (ret) { return ret; @@ -446,10 +433,10 @@ int TICALL ti89_recv_VAR(CalcHandle* handle, uint32_t * varsize, uint8_t * varty *varsize = buffer[0] | (((uint32_t)buffer[1]) << 8) | (((uint32_t)buffer[2]) << 16) | (((uint32_t)buffer[3]) << 24); *vartype = buffer[4]; - strl = buffer[5]; + const uint8_t strl = buffer[5]; memcpy(varname, buffer + 6, strl); varname[strl] = '\0'; - flag = buffer[6 + strl]; + const uint8_t flag = buffer[6 + strl]; if ((length != (6 + strlen(varname))) && (length != (7 + strlen(varname)))) { @@ -457,7 +444,7 @@ int TICALL ti89_recv_VAR(CalcHandle* handle, uint32_t * varsize, uint8_t * varty } ticalcs_info(" TI->PC: VAR (size=0x%08X=%i, id=%02X, name=%s, flag=%i)", *varsize, *varsize, *vartype, varname, flag); - varname_nofldname = tifiles_get_varname(varname); + const char* varname_nofldname = tifiles_get_varname(varname); if (varname_nofldname != varname) { // This variable name contains a folder name. Erase it. @@ -471,18 +458,15 @@ int TICALL ti89_recv_VAR(CalcHandle* handle, uint32_t * varsize, uint8_t * varty int TICALL ti92_recv_VAR(CalcHandle* handle, uint32_t * varsize, uint8_t * vartype, char *varname) { uint8_t host = 0, cmd = 0; - uint8_t *buffer; uint16_t length = 0; - uint8_t strl; - int ret; VALIDATE_HANDLE(handle); VALIDATE_NONNULL(varsize); VALIDATE_NONNULL(vartype); VALIDATE_NONNULL(varname); - buffer = (uint8_t *)handle->buffer; - ret = dbus_recv(handle, &host, &cmd, &length, buffer); + uint8_t* buffer = (uint8_t*)handle->buffer; + const int ret = dbus_recv(handle, &host, &cmd, &length, buffer); if (ret) { return ret; @@ -504,7 +488,7 @@ int TICALL ti92_recv_VAR(CalcHandle* handle, uint32_t * varsize, uint8_t * varty *varsize = buffer[0] | (((uint32_t)buffer[1]) << 8) | (((uint32_t)buffer[2]) << 16) | (((uint32_t)buffer[3]) << 24); *vartype = buffer[4]; - strl = buffer[5]; + const uint8_t strl = buffer[5]; memcpy(varname, buffer + 6, strl); varname[strl] = '\0'; @@ -522,13 +506,11 @@ static int ti68k_recv_CTS(CalcHandle* handle, uint8_t is_92) { uint8_t host = 0, cmd = 0; uint16_t length = 0; - uint8_t *buffer; - int ret; VALIDATE_HANDLE(handle); - buffer = (uint8_t *)handle->buffer; - ret = dbus_recv(handle, &host, &cmd, &length, buffer); + uint8_t* buffer = (uint8_t*)handle->buffer; + const int ret = dbus_recv(handle, &host, &cmd, &length, buffer); if (ret) { return ret; @@ -566,16 +548,14 @@ int TICALL ti68k_recv_SKP(CalcHandle* handle, uint8_t * rej_code) { uint8_t host = 0, cmd = 0; uint16_t length = 0; - uint8_t *buffer; - int retval; VALIDATE_HANDLE(handle); VALIDATE_NONNULL(rej_code); - buffer = (uint8_t *)handle->buffer; + uint8_t* buffer = (uint8_t*)handle->buffer; *rej_code = 0; - retval = dbus_recv(handle, &host, &cmd, &length, buffer); + int retval = dbus_recv(handle, &host, &cmd, &length, buffer); if (retval == 0) { if (cmd == DBUS_CMD_CTS) @@ -591,7 +571,7 @@ int TICALL ti68k_recv_SKP(CalcHandle* handle, uint8_t * rej_code) else { ticalcs_info(" TI->PC: SKP (rejection code = %i)", buffer[0]); - if (rej_code != NULL) + if (rej_code != nullptr) { *rej_code = buffer[0]; } @@ -606,12 +586,11 @@ int TICALL ti68k_recv_XDP(CalcHandle* handle, uint16_t * length, uint8_t * data) { uint8_t host = 0, cmd = 0; uint16_t len = 0; - int err; VALIDATE_HANDLE(handle); VALIDATE_NONNULL(length); - err = dbus_recv(handle, &host, &cmd, &len, data); + const int err = dbus_recv(handle, &host, &cmd, &len, data); *length = len; if (cmd != DBUS_CMD_XDP) @@ -636,13 +615,11 @@ static int ti68k_recv_ACK(CalcHandle* handle, uint16_t * status, uint8_t is_92) { uint8_t host = 0, cmd = 0; uint16_t length = 0; - uint8_t *buffer; - int ret; VALIDATE_HANDLE(handle); - buffer = (uint8_t *)handle->buffer; - ret = dbus_recv(handle, &host, &cmd, &length, buffer); + uint8_t* buffer = (uint8_t*)handle->buffer; + const int ret = dbus_recv(handle, &host, &cmd, &length, buffer); if (ret) { return ret; @@ -653,7 +630,7 @@ static int ti68k_recv_ACK(CalcHandle* handle, uint16_t * status, uint8_t is_92) return ERR_CALC_ERROR1 + err_code(buffer); } - if (status != NULL) + if (status != nullptr) { *status = length; } @@ -686,11 +663,10 @@ int TICALL ti68k_recv_CNT(CalcHandle* handle) { uint8_t host = 0, cmd = 0; uint16_t sts = 0; - int ret; VALIDATE_HANDLE(handle); - ret = dbus_recv(handle, &host, &cmd, &sts, NULL); + const int ret = dbus_recv(handle, &host, &cmd, &sts, nullptr); if (ret) { return ret; @@ -715,11 +691,10 @@ int TICALL ti68k_recv_EOT(CalcHandle* handle) { uint8_t host = 0, cmd = 0; uint16_t length = 0; - int ret; VALIDATE_HANDLE(handle); - ret = dbus_recv(handle, &host, &cmd, &length, NULL); + const int ret = dbus_recv(handle, &host, &cmd, &length, nullptr); if (ret) { return ret; @@ -738,18 +713,15 @@ int TICALL ti68k_recv_EOT(CalcHandle* handle) static int ti68k_recv_RTS(CalcHandle* handle, uint32_t * varsize, uint8_t * vartype, char *varname, uint8_t is_92) { uint8_t host = 0, cmd = 0; - uint8_t *buffer; uint16_t length = 0; - uint8_t strl; - int ret; VALIDATE_HANDLE(handle); VALIDATE_NONNULL(varsize); VALIDATE_NONNULL(vartype); VALIDATE_NONNULL(varname); - buffer = (uint8_t *)handle->buffer; - ret = dbus_recv(handle, &host, &cmd, &length, buffer); + uint8_t* buffer = (uint8_t*)handle->buffer; + const int ret = dbus_recv(handle, &host, &cmd, &length, buffer); if (ret) { return ret; @@ -770,7 +742,7 @@ static int ti68k_recv_RTS(CalcHandle* handle, uint32_t * varsize, uint8_t * vart *varsize = buffer[0] | (((uint32_t)buffer[1]) << 8) | (((uint32_t)buffer[2]) << 16) | (((uint32_t)buffer[3]) << 24); *vartype = buffer[4]; - strl = buffer[5]; + const uint8_t strl = buffer[5]; memcpy(varname, buffer + 6, strl); varname[strl] = '\0'; diff --git a/libticalcs/trunk/src/cmdz80.cc b/libticalcs/trunk/src/cmdz80.cc index 2f87cf6a9..e67d62e10 100644 --- a/libticalcs/trunk/src/cmdz80.cc +++ b/libticalcs/trunk/src/cmdz80.cc @@ -213,7 +213,7 @@ int TICALL ti73_send_VAR2(CalcHandle* handle, uint32_t length, uint8_t type, uin int TICALL tiz80_send_CTS(CalcHandle* handle, uint8_t target) { - return tiz80_send_simple_cmd(handle, target, DBUS_CMD_CTS, "CTS", 0, NULL); + return tiz80_send_simple_cmd(handle, target, DBUS_CMD_CTS, "CTS", 0, nullptr); } int TICALL tiz80_send_XDP(CalcHandle* handle, uint16_t length, uint8_t * data, uint8_t target) @@ -234,32 +234,31 @@ int TICALL tiz80_send_SKP(CalcHandle* handle, uint8_t rej_code, uint8_t target) int TICALL tiz80_send_ACK(CalcHandle* handle, uint8_t target) { - return tiz80_send_simple_cmd(handle, target, DBUS_CMD_ACK, "ACK", 2, NULL); + return tiz80_send_simple_cmd(handle, target, DBUS_CMD_ACK, "ACK", 2, nullptr); } int TICALL tiz80_send_ERR(CalcHandle* handle, uint8_t target) { - return tiz80_send_simple_cmd(handle, target, DBUS_CMD_ERR, "ERR", 2, NULL); + return tiz80_send_simple_cmd(handle, target, DBUS_CMD_ERR, "ERR", 2, nullptr); } int TICALL ti73_send_RDY(CalcHandle* handle) { - return tiz80_send_simple_cmd(handle, tiz80_handle_to_dbus_mid_7383p(handle), DBUS_CMD_RDY, "RDY", 2, NULL); + return tiz80_send_simple_cmd(handle, tiz80_handle_to_dbus_mid_7383p(handle), DBUS_CMD_RDY, "RDY", 2, nullptr); } int TICALL tiz80_send_SCR(CalcHandle* handle, uint8_t target) { - return tiz80_send_simple_cmd(handle, target, DBUS_CMD_SCR, "SCR", 2, NULL); + return tiz80_send_simple_cmd(handle, target, DBUS_CMD_SCR, "SCR", 2, nullptr); } int TICALL ti80_send_SCR(CalcHandle* handle) { - return tiz80_send_simple_cmd(handle, DBUS_MID_PC_TI80, DBUS_CMD_SCR, "SCR", 0, NULL); + return tiz80_send_simple_cmd(handle, DBUS_MID_PC_TI80, DBUS_CMD_SCR, "SCR", 0, nullptr); } int TICALL tiz80_send_KEY(CalcHandle* handle, uint16_t scancode, uint8_t target) { - int ret; uint8_t buf[4] = { target, DBUS_CMD_KEY, LSB(scancode), MSB(scancode) }; CalcEventData event; @@ -270,8 +269,8 @@ int TICALL tiz80_send_KEY(CalcHandle* handle, uint16_t scancode, uint8_t target) SET_HANDLE_BUSY_IF_NECESSARY(handle); ticalcs_event_fill_header(handle, &event, /* type */ CALC_EVENT_TYPE_BEFORE_SEND_DBUS_PKT, /* retval */ 0, /* operation */ CALC_FNCT_LAST); - ticalcs_event_fill_dbus_pkt(&event, /* length */ scancode, /* id */ target, /* cmd */ DBUS_CMD_KEY, /* data */ NULL); - ret = ticalcs_event_send(handle, &event); + ticalcs_event_fill_dbus_pkt(&event, /* length */ scancode, /* id */ target, /* cmd */ DBUS_CMD_KEY, /* data */ nullptr); + int ret = ticalcs_event_send(handle, &event); if (!ret) { @@ -279,7 +278,7 @@ int TICALL tiz80_send_KEY(CalcHandle* handle, uint16_t scancode, uint8_t target) } ticalcs_event_fill_header(handle, &event, /* type */ CALC_EVENT_TYPE_AFTER_SEND_DBUS_PKT, /* retval */ ret, /* operation */ CALC_FNCT_LAST); - ticalcs_event_fill_dbus_pkt(&event, /* length */ scancode, /* id */ target, /* cmd */ DBUS_CMD_KEY, /* data */ NULL); + ticalcs_event_fill_dbus_pkt(&event, /* length */ scancode, /* id */ target, /* cmd */ DBUS_CMD_KEY, /* data */ nullptr); ret = ticalcs_event_send(handle, &event); CLEAR_HANDLE_BUSY_IF_NECESSARY(handle); @@ -289,7 +288,7 @@ int TICALL tiz80_send_KEY(CalcHandle* handle, uint16_t scancode, uint8_t target) int TICALL tiz80_send_EOT(CalcHandle* handle, uint8_t target) { - return tiz80_send_simple_cmd(handle, target, DBUS_CMD_EOT, "EOT", 2, NULL); + return tiz80_send_simple_cmd(handle, target, DBUS_CMD_EOT, "EOT", 2, nullptr); } /* REQ: request variable (std var header: NUL padded, fixed length) */ @@ -348,7 +347,6 @@ int TICALL ti85_send_REQ(CalcHandle* handle, uint16_t varsize, uint8_t vartype, { uint8_t buffer[16]; char trans[127]; - int len; VALIDATE_HANDLE(handle); VALIDATE_NONNULL(varname); @@ -373,7 +371,7 @@ int TICALL ti85_send_REQ(CalcHandle* handle, uint16_t varsize, uint8_t vartype, buffer[0] = LSB(varsize); buffer[1] = MSB(varsize); buffer[2] = vartype; - len = strlen(varname); + int len = strlen(varname); if (len > 8) { ticalcs_critical("Oversized variable name has length %d, clamping to 8", len); @@ -470,7 +468,6 @@ int TICALL ti85_send_RTS(CalcHandle* handle, uint16_t varsize, uint8_t vartype, { uint8_t buffer[16]; char trans[127]; - int len; VALIDATE_HANDLE(handle); VALIDATE_NONNULL(varname); @@ -478,7 +475,7 @@ int TICALL ti85_send_RTS(CalcHandle* handle, uint16_t varsize, uint8_t vartype, buffer[0] = LSB(varsize); buffer[1] = MSB(varsize); buffer[2] = vartype; - len = strlen(varname); + int len = strlen(varname); if (len > 8) { ticalcs_critical("Oversized variable name has length %d, clamping to 8", len); @@ -528,14 +525,7 @@ int TICALL tiz80_send_RTS_lab_equipment_data(CalcHandle* handle, uint16_t varsiz */ int ti82_send_asm_exec(CalcHandle* handle, VarEntry * var) { - int ret; - uint16_t ioData; - uint16_t errSP; - uint16_t onSP; - uint16_t tempMem; - uint16_t fpBase; uint8_t buffer[50]; - uint16_t length, offset, endptr, es, sum; CalcEventData event; VALIDATE_HANDLE(handle); @@ -547,18 +537,18 @@ int ti82_send_asm_exec(CalcHandle* handle, VarEntry * var) return ERR_UNSUPPORTED; } - ioData = (handle->model == CALC_TI82 ? 0x81fd : 0x831e); - errSP = (handle->model == CALC_TI82 ? 0x821a : 0x8338); - onSP = (handle->model == CALC_TI82 ? 0x8143 : 0x81bc); - tempMem = (handle->model == CALC_TI82 ? 0x8d0a : 0x8bdd); - fpBase = (handle->model == CALC_TI82 ? 0x8d0c : 0x8bdf); + const uint16_t ioData = (handle->model == CALC_TI82 ? 0x81fd : 0x831e); + const uint16_t errSP = (handle->model == CALC_TI82 ? 0x821a : 0x8338); + const uint16_t onSP = (handle->model == CALC_TI82 ? 0x8143 : 0x81bc); + const uint16_t tempMem = (handle->model == CALC_TI82 ? 0x8d0a : 0x8bdd); + const uint16_t fpBase = (handle->model == CALC_TI82 ? 0x8d0c : 0x8bdf); buffer[0] = (handle->model == CALC_TI82 ? DBUS_MID_PC_TI82 : DBUS_MID_PC_TI85); buffer[1] = DBUS_CMD_VAR; /* Warning: Heavy wizardry begins here. ;) */ - length = errSP + 2 - ioData; + const uint16_t length = errSP + 2 - ioData; buffer[2] = LSB(length); buffer[3] = MSB(length); @@ -567,23 +557,23 @@ int ti82_send_asm_exec(CalcHandle* handle, VarEntry * var) /* ld sp, (onSP) */ buffer[4] = 0xed; buffer[5] = 0x7b; buffer[6] = LSB(onSP); buffer[7] = MSB(onSP); /* ld hl, (endptr) */ - endptr = (var->name[0] == 0x24 ? fpBase : tempMem); + const uint16_t endptr = (var->name[0] == 0x24 ? fpBase : tempMem); buffer[8] = 0x2a; buffer[9] = LSB(endptr); buffer[10] = MSB(endptr); /* ld de, -program_size */ - offset = -(var->size - 2); + const uint16_t offset = -(var->size - 2); buffer[11] = 0x11; buffer[12] = LSB(offset); buffer[13] = MSB(offset); /* add hl, de */ buffer[14] = 0x19; /* jp (hl) */ buffer[15] = 0xe9; - es = 4 + errSP - ioData; + const uint16_t es = 4 + errSP - ioData; buffer[es] = LSB(errSP - 11); buffer[es + 1] = MSB(errSP - 11); buffer[es - 4] = (handle->model == CALC_TI82 ? 0x88 : 0); buffer[es - 3] = LSB(ioData); buffer[es - 2] = MSB(ioData); - sum = tifiles_checksum(buffer + 4, length) + 0x5555; + const uint16_t sum = tifiles_checksum(buffer + 4, length) + 0x5555; buffer[4 + length] = LSB(sum); buffer[4 + length + 1] = MSB(sum); @@ -593,7 +583,7 @@ int ti82_send_asm_exec(CalcHandle* handle, VarEntry * var) ticalcs_event_fill_header(handle, &event, /* type */ CALC_EVENT_TYPE_BEFORE_SEND_DBUS_PKT, /* retval */ 0, /* operation */ CALC_FNCT_LAST); ticalcs_event_fill_dbus_pkt(&event, /* length */ length, /* id */ buffer[0], /* cmd */ DBUS_CMD_VAR, /* data */ buffer + 4); - ret = ticalcs_event_send(handle, &event); + int ret = ticalcs_event_send(handle, &event); if (!ret) { @@ -611,7 +601,7 @@ int ti82_send_asm_exec(CalcHandle* handle, VarEntry * var) int TICALL ti73_send_VER(CalcHandle* handle) { - return tiz80_send_simple_cmd(handle, tiz80_handle_to_dbus_mid_7383p(handle), DBUS_CMD_VER, "VER", 2, NULL); + return tiz80_send_simple_cmd(handle, tiz80_handle_to_dbus_mid_7383p(handle), DBUS_CMD_VER, "VER", 2, nullptr); } int TICALL ti73_send_DEL(CalcHandle* handle, uint16_t varsize, uint8_t vartype, const char *varname, uint8_t varattr) @@ -649,32 +639,32 @@ int TICALL ti73_send_DUMP(CalcHandle* handle, uint16_t page) int TICALL ti73_send_EKE(CalcHandle* handle) { - return tiz80_send_simple_cmd(handle, tiz80_handle_to_dbus_mid_7383p(handle), DBUS_CMD_EKE, "EKE", 2, NULL); + return tiz80_send_simple_cmd(handle, tiz80_handle_to_dbus_mid_7383p(handle), DBUS_CMD_EKE, "EKE", 2, nullptr); } int TICALL ti73_send_DKE(CalcHandle* handle) { - return tiz80_send_simple_cmd(handle, tiz80_handle_to_dbus_mid_7383p(handle), DBUS_CMD_DKE, "DKE", 2, NULL); + return tiz80_send_simple_cmd(handle, tiz80_handle_to_dbus_mid_7383p(handle), DBUS_CMD_DKE, "DKE", 2, nullptr); } int TICALL ti73_send_ELD(CalcHandle* handle) { - return tiz80_send_simple_cmd(handle, tiz80_handle_to_dbus_mid_7383p(handle), DBUS_CMD_ELD, "ELD", 2, NULL); + return tiz80_send_simple_cmd(handle, tiz80_handle_to_dbus_mid_7383p(handle), DBUS_CMD_ELD, "ELD", 2, nullptr); } int TICALL ti73_send_DLD(CalcHandle* handle) { - return tiz80_send_simple_cmd(handle, tiz80_handle_to_dbus_mid_7383p(handle), DBUS_CMD_DLD, "DLD", 2, NULL); + return tiz80_send_simple_cmd(handle, tiz80_handle_to_dbus_mid_7383p(handle), DBUS_CMD_DLD, "DLD", 2, nullptr); } int TICALL ti73_send_GID(CalcHandle* handle) { - return tiz80_send_simple_cmd(handle, tiz80_handle_to_dbus_mid_7383p(handle), DBUS_CMD_GID, "GID", 2, NULL); + return tiz80_send_simple_cmd(handle, tiz80_handle_to_dbus_mid_7383p(handle), DBUS_CMD_GID, "GID", 2, nullptr); } int TICALL ti73_send_RID(CalcHandle* handle) { - return tiz80_send_simple_cmd(handle, tiz80_handle_to_dbus_mid_7383p(handle), DBUS_CMD_RID, "RID", 2, NULL); + return tiz80_send_simple_cmd(handle, tiz80_handle_to_dbus_mid_7383p(handle), DBUS_CMD_RID, "RID", 2, nullptr); } int TICALL ti73_send_SID(CalcHandle* handle, uint8_t * data) @@ -685,10 +675,8 @@ int TICALL ti73_send_SID(CalcHandle* handle, uint8_t * data) int TICALL ti73_recv_VAR(CalcHandle* handle, uint16_t * varsize, uint8_t * vartype, char *varname, uint8_t * varattr, uint8_t * version) { uint8_t host = 0, cmd = 0; - uint8_t *buffer; uint16_t length = 0; char trans[127]; - int ret; VALIDATE_HANDLE(handle); VALIDATE_NONNULL(varsize); @@ -697,9 +685,9 @@ int TICALL ti73_recv_VAR(CalcHandle* handle, uint16_t * varsize, uint8_t * varty VALIDATE_NONNULL(varattr); VALIDATE_NONNULL(version); - buffer = (uint8_t *)handle->buffer; + uint8_t* buffer = (uint8_t*)handle->buffer; memset(buffer, 0, 13); - ret = dbus_recv(handle, &host, &cmd, &length, buffer); + const int ret = dbus_recv(handle, &host, &cmd, &length, buffer); if (ret) { return ret; @@ -741,18 +729,16 @@ int TICALL ti73_recv_VAR(CalcHandle* handle, uint16_t * varsize, uint8_t * varty int TICALL ti82_recv_VAR(CalcHandle* handle, uint16_t * varsize, uint8_t * vartype, char *varname) { uint8_t host = 0, cmd = 0; - uint8_t *buffer; uint16_t length = 0; char trans[127]; - int ret; VALIDATE_HANDLE(handle); VALIDATE_NONNULL(varsize); VALIDATE_NONNULL(vartype); VALIDATE_NONNULL(varname); - buffer = (uint8_t *)handle->buffer; - ret = dbus_recv(handle, &host, &cmd, &length, buffer); + uint8_t* buffer = (uint8_t*)handle->buffer; + const int ret = dbus_recv(handle, &host, &cmd, &length, buffer); if (ret) { return ret; @@ -792,18 +778,16 @@ int TICALL ti82_recv_VAR(CalcHandle* handle, uint16_t * varsize, uint8_t * varty int TICALL ti85_recv_VAR(CalcHandle* handle, uint16_t * varsize, uint8_t * vartype, char *varname) { uint8_t host = 0, cmd = 0; - uint8_t *buffer; uint16_t length = 0; char trans[127]; - int ret; VALIDATE_HANDLE(handle); VALIDATE_NONNULL(varsize); VALIDATE_NONNULL(vartype); VALIDATE_NONNULL(varname); - buffer = (uint8_t *)handle->buffer; - ret = dbus_recv(handle, &host, &cmd, &length, buffer); + uint8_t* buffer = (uint8_t*)handle->buffer; + const int ret = dbus_recv(handle, &host, &cmd, &length, buffer); if (ret) { return ret; @@ -854,9 +838,7 @@ int TICALL ti85_recv_VAR(CalcHandle* handle, uint16_t * varsize, uint8_t * varty int TICALL ti73_recv_VAR2(CalcHandle* handle, uint16_t * length, uint8_t * type, char *name, uint16_t * offset, uint16_t * page) { uint8_t host = 0, cmd = 0; - uint8_t *buffer; uint16_t len = 0; - int ret; VALIDATE_HANDLE(handle); VALIDATE_NONNULL(length); @@ -865,8 +847,8 @@ int TICALL ti73_recv_VAR2(CalcHandle* handle, uint16_t * length, uint8_t * type, VALIDATE_NONNULL(offset); VALIDATE_NONNULL(page); - buffer = (uint8_t *)handle->buffer; - ret = dbus_recv(handle, &host, &cmd, &len, buffer); + uint8_t* buffer = (uint8_t*)handle->buffer; + const int ret = dbus_recv(handle, &host, &cmd, &len, buffer); if (ret) { return ret; @@ -909,13 +891,11 @@ int TICALL tiz80_recv_CTS(CalcHandle* handle, uint16_t length) { uint8_t host = 0, cmd = 0; uint16_t len = 0; - uint8_t *buffer; - int ret; VALIDATE_HANDLE(handle); - buffer = (uint8_t *)handle->buffer; - ret = dbus_recv(handle, &host, &cmd, &len, buffer); + uint8_t* buffer = (uint8_t*)handle->buffer; + const int ret = dbus_recv(handle, &host, &cmd, &len, buffer); if (ret) { return ret; @@ -944,15 +924,13 @@ int TICALL tiz80_recv_SKP(CalcHandle* handle, uint8_t * rej_code) { uint8_t host = 0, cmd = 0; uint16_t length = 0; - uint8_t *buffer; - int ret; VALIDATE_HANDLE(handle); VALIDATE_NONNULL(rej_code); - buffer = (uint8_t *)handle->buffer; + uint8_t* buffer = (uint8_t*)handle->buffer; *rej_code = 0; - ret = dbus_recv(handle, &host, &cmd, &length, buffer); + const int ret = dbus_recv(handle, &host, &cmd, &length, buffer); if (ret) { return ret; @@ -978,11 +956,10 @@ int TICALL tiz80_recv_SKP(CalcHandle* handle, uint8_t * rej_code) static int tiz80_recv_XDP(CalcHandle* handle, uint16_t * length, uint8_t * data, uint8_t is_73) { uint8_t host = 0, cmd = 0; - int ret; VALIDATE_HANDLE(handle); - ret = dbus_recv(handle, &host, &cmd, length, data); + const int ret = dbus_recv(handle, &host, &cmd, length, data); if (ret) { return ret; @@ -1026,9 +1003,8 @@ int TICALL ti80_recv_XDP(CalcHandle* handle, uint16_t * length, uint8_t * data) int TICALL ti73_recv_SID(CalcHandle* handle, uint16_t * length, uint8_t * data) { uint8_t host = 0, cmd = 0; - int ret; - ret = dbus_recv(handle, &host, &cmd, length, data); + const int ret = dbus_recv(handle, &host, &cmd, length, data); if (ret) { return ret; @@ -1058,19 +1034,17 @@ int TICALL tiz80_recv_ACK(CalcHandle* handle, uint16_t * status) { uint8_t host = 0, cmd = 0; uint16_t length = 0; - uint8_t *buffer; - int ret; VALIDATE_HANDLE(handle); - buffer = (uint8_t *)handle->buffer; - ret = dbus_recv(handle, &host, &cmd, &length, buffer); + uint8_t* buffer = (uint8_t*)handle->buffer; + const int ret = dbus_recv(handle, &host, &cmd, &length, buffer); if (ret) { return ret; } - if (status != NULL) + if (status != nullptr) { *status = length; } @@ -1093,17 +1067,16 @@ int TICALL ti82_recv_ERR(CalcHandle* handle, uint16_t * status) { uint8_t host = 0, cmd = 0; uint16_t sts = 0; - int ret; VALIDATE_HANDLE(handle); - ret = dbus_recv(handle, &host, &cmd, &sts, NULL); + const int ret = dbus_recv(handle, &host, &cmd, &sts, nullptr); if (ret && ret != ERR_CHECKSUM) { return ret; } - if (status != NULL) + if (status != nullptr) { *status = sts; } @@ -1121,9 +1094,7 @@ int TICALL ti82_recv_ERR(CalcHandle* handle, uint16_t * status) int TICALL ti73_recv_RTS(CalcHandle* handle, uint16_t * varsize, uint8_t * vartype, char *varname, uint8_t * varattr, uint8_t * version) { uint8_t host = 0, cmd = 0; - uint8_t *buffer; char trans[127]; - int ret; VALIDATE_HANDLE(handle); VALIDATE_NONNULL(varsize); @@ -1132,9 +1103,9 @@ int TICALL ti73_recv_RTS(CalcHandle* handle, uint16_t * varsize, uint8_t * varty VALIDATE_NONNULL(varattr); VALIDATE_NONNULL(version); - buffer = (uint8_t *)handle->buffer; + uint8_t* buffer = (uint8_t*)handle->buffer; memset(buffer, 0, 13); - ret = dbus_recv(handle, &host, &cmd, varsize, buffer); + const int ret = dbus_recv(handle, &host, &cmd, varsize, buffer); if (ret) { return ret; @@ -1166,17 +1137,15 @@ int TICALL ti73_recv_RTS(CalcHandle* handle, uint16_t * varsize, uint8_t * varty int TICALL ti82_recv_RTS(CalcHandle* handle, uint16_t * varsize, uint8_t * vartype, char *varname) { uint8_t host = 0, cmd = 0; - uint8_t *buffer; char trans[127]; - int ret; VALIDATE_HANDLE(handle); VALIDATE_NONNULL(varsize); VALIDATE_NONNULL(vartype); VALIDATE_NONNULL(varname); - buffer = (uint8_t *)handle->buffer; - ret = dbus_recv(handle, &host, &cmd, varsize, buffer); + uint8_t* buffer = (uint8_t*)handle->buffer; + const int ret = dbus_recv(handle, &host, &cmd, varsize, buffer); if (ret) { return ret; @@ -1201,18 +1170,15 @@ int TICALL ti82_recv_RTS(CalcHandle* handle, uint16_t * varsize, uint8_t * varty int TICALL ti85_recv_RTS(CalcHandle* handle, uint16_t * varsize, uint8_t * vartype, char *varname) { uint8_t host = 0, cmd = 0; - uint8_t *buffer; char trans[127]; - uint8_t strl; - int ret; VALIDATE_HANDLE(handle); VALIDATE_NONNULL(varsize); VALIDATE_NONNULL(vartype); VALIDATE_NONNULL(varname); - buffer = (uint8_t *)handle->buffer; - ret = dbus_recv(handle, &host, &cmd, varsize, buffer); + uint8_t* buffer = (uint8_t*)handle->buffer; + const int ret = dbus_recv(handle, &host, &cmd, varsize, buffer); if (ret) { return ret; @@ -1225,7 +1191,7 @@ int TICALL ti85_recv_RTS(CalcHandle* handle, uint16_t * varsize, uint8_t * varty *varsize = buffer[0] | (((uint16_t)buffer[1]) << 8); *vartype = buffer[2]; - strl = buffer[3]; + uint8_t strl = buffer[3]; if (strl > 8) { strl = 8; diff --git a/libticalcs/trunk/src/cmdz80.h b/libticalcs/trunk/src/cmdz80.h index 333beea99..6e8c0650f 100644 --- a/libticalcs/trunk/src/cmdz80.h +++ b/libticalcs/trunk/src/cmdz80.h @@ -36,24 +36,24 @@ TIEXPORT3 uint8_t TICALL tiz80_handle_to_dbus_mid(CalcHandle * handle); static inline uint8_t tiz80_handle_to_dbus_mid_7383p(CalcHandle * handle) { - return (handle != NULL) ? ((handle->model == CALC_TI73) ? DBUS_MID_PC_TI73 : DBUS_MID_PC_TI83p) : 0; + return (handle != nullptr) ? ((handle->model == CALC_TI73) ? DBUS_MID_PC_TI73 : DBUS_MID_PC_TI83p) : 0; } static inline uint8_t tiz80_handle_to_dbus_mid_8283(CalcHandle * handle) { - return (handle != NULL) ? ( (handle->model == CALC_TI82) - || (handle->model == CALC_CBL) - || (handle->model == CALC_CBR) - || (handle->model == CALC_CBL2) - || (handle->model == CALC_CBR2) - || (handle->model == CALC_LABPRO) - || (handle->model == CALC_TIPRESENTER) - ? DBUS_MID_PC_TI82 : DBUS_MID_PC_TI83) : 0; + return (handle != nullptr) ? ( (handle->model == CALC_TI82) + || (handle->model == CALC_CBL) + || (handle->model == CALC_CBR) + || (handle->model == CALC_CBL2) + || (handle->model == CALC_CBR2) + || (handle->model == CALC_LABPRO) + || (handle->model == CALC_TIPRESENTER) + ? DBUS_MID_PC_TI82 : DBUS_MID_PC_TI83) : 0; } static inline uint8_t tiz80_handle_to_dbus_mid_8586(CalcHandle * handle) { - return (handle != NULL) ? ((handle->model == CALC_TI85) ? DBUS_MID_PC_TI85 : DBUS_MID_PC_TI86) : 0; + return (handle != nullptr) ? ((handle->model == CALC_TI85) ? DBUS_MID_PC_TI85 : DBUS_MID_PC_TI86) : 0; } diff --git a/libticalcs/trunk/src/dbus_pkt.cc b/libticalcs/trunk/src/dbus_pkt.cc index 9f16b14d2..3871cf780 100644 --- a/libticalcs/trunk/src/dbus_pkt.cc +++ b/libticalcs/trunk/src/dbus_pkt.cc @@ -115,9 +115,7 @@ static const DBUSMachineInfo machine_types[] = const char* TICALL dbus_cmd2name(uint8_t id) { - unsigned int i; - - for (i = 0; i < sizeof(cmd_types) / sizeof(cmd_types[0]); i++) + for (unsigned int i = 0; i < sizeof(cmd_types) / sizeof(cmd_types[0]); i++) { if (id == cmd_types[i].id) { @@ -130,9 +128,7 @@ const char* TICALL dbus_cmd2name(uint8_t id) const char* TICALL dbus_cmd2officialname(uint8_t id) { - unsigned int i; - - for (i = 0; i < sizeof(cmd_types) / sizeof(cmd_types[0]); i++) + for (unsigned int i = 0; i < sizeof(cmd_types) / sizeof(cmd_types[0]); i++) { if (id == cmd_types[i].id) { @@ -145,9 +141,7 @@ const char* TICALL dbus_cmd2officialname(uint8_t id) const char* TICALL dbus_cmd2desc(uint8_t id) { - unsigned int i; - - for (i = 0; i < sizeof(cmd_types) / sizeof(cmd_types[0]); i++) + for (unsigned int i = 0; i < sizeof(cmd_types) / sizeof(cmd_types[0]); i++) { if (id == cmd_types[i].id) { @@ -160,9 +154,7 @@ const char* TICALL dbus_cmd2desc(uint8_t id) const char* TICALL dbus_mid2direction(uint8_t id) { - unsigned int i; - - for (i = 0; i < sizeof(machine_types) / sizeof(machine_types[0]); i++) + for (unsigned int i = 0; i < sizeof(machine_types) / sizeof(machine_types[0]); i++) { if (id == machine_types[i].id) { @@ -187,10 +179,8 @@ const char* TICALL dbus_mid2direction(uint8_t id) int TICALL dbus_send(CalcHandle* handle, uint8_t target, uint8_t cmd, uint16_t len, uint8_t* data) { int i; - uint16_t sum; - uint32_t length = (len == 0x0000) ? 65536 : len; // wrap around + const uint32_t length = (len == 0x0000) ? 65536 : len; // wrap around uint8_t *buf; - int r, q; static int ref = 0; int ret = 0; CalcEventData event; @@ -198,7 +188,7 @@ int TICALL dbus_send(CalcHandle* handle, uint8_t target, uint8_t cmd, uint16_t l VALIDATE_HANDLE(handle); buf = (uint8_t *)handle->buffer; //[65536+6]; - if (buf == NULL) + if (buf == nullptr) { ticalcs_critical("%s: handle->buffer is NULL", __FUNCTION__); return ERR_INVALID_HANDLE; @@ -214,7 +204,7 @@ int TICALL dbus_send(CalcHandle* handle, uint8_t target, uint8_t cmd, uint16_t l if (!ret) { - if (data == NULL) + if (data == nullptr) { // short packet (no data) buf[0] = target; @@ -237,7 +227,7 @@ int TICALL dbus_send(CalcHandle* handle, uint8_t target, uint8_t cmd, uint16_t l memcpy(buf+4, data, length); // add checksum of packet - sum = tifiles_checksum(data, length); + const uint16_t sum = tifiles_checksum(data, length); buf[length+4+0] = LSB(sum); buf[length+4+1] = MSB(sum); @@ -253,8 +243,8 @@ int TICALL dbus_send(CalcHandle* handle, uint8_t target, uint8_t cmd, uint16_t l handle->priv.progress_blk_size = 128; // SilverLink doesn't like small block (< 32) } - q = (length + 6) / handle->priv.progress_blk_size; - r = (length + 6) % handle->priv.progress_blk_size; + const int q = (length + 6) / handle->priv.progress_blk_size; + const int r = (length + 6) % handle->priv.progress_blk_size; handle->updat->max1 = length + 6; handle->updat->cnt1 = 0; @@ -269,7 +259,7 @@ int TICALL dbus_send(CalcHandle* handle, uint8_t target, uint8_t cmd, uint16_t l { break; } - ticables_progress_get(handle->cable, NULL, NULL, &handle->updat->rate); + ticables_progress_get(handle->cable, nullptr, nullptr, &handle->updat->rate); handle->updat->cnt1 += handle->priv.progress_blk_size; if (length > handle->priv.progress_min_size) @@ -290,7 +280,7 @@ int TICALL dbus_send(CalcHandle* handle, uint8_t target, uint8_t cmd, uint16_t l ret = ticables_cable_send(handle->cable, &buf[i*handle->priv.progress_blk_size], (uint16_t)r); if (!ret) { - ticables_progress_get(handle->cable, NULL, NULL, &handle->updat->rate); + ticables_progress_get(handle->cable, nullptr, nullptr, &handle->updat->rate); handle->updat->cnt1 += 1; if (length > handle->priv.progress_min_size) @@ -336,7 +326,7 @@ int TICALL dbus_recv_header(CalcHandle *handle, uint8_t* host, uint8_t* cmd, uin SET_HANDLE_BUSY_IF_NECESSARY(handle); ticalcs_event_fill_header(handle, &event, /* type */ CALC_EVENT_TYPE_BEFORE_RECV_DBUS_PKT_HEADER, /* retval */ 0, /* operation */ CALC_FNCT_LAST); - ticalcs_event_fill_dbus_pkt(&event, /* length */ 0, /* id */ 0, /* cmd */ 0, /* data */ NULL); + ticalcs_event_fill_dbus_pkt(&event, /* length */ 0, /* id */ 0, /* cmd */ 0, /* data */ nullptr); ret = ticalcs_event_send(handle, &event); if (!ret) @@ -365,7 +355,7 @@ int TICALL dbus_recv_header(CalcHandle *handle, uint8_t* host, uint8_t* cmd, uin } ticalcs_event_fill_header(handle, &event, /* type */ CALC_EVENT_TYPE_AFTER_RECV_DBUS_PKT_HEADER, /* retval */ ret, /* operation */ CALC_FNCT_LAST); - ticalcs_event_fill_dbus_pkt(&event, /* length */ *length, /* id */ *host, /* cmd */ *cmd, /* data */ NULL); + ticalcs_event_fill_dbus_pkt(&event, /* length */ *length, /* id */ *host, /* cmd */ *cmd, /* data */ nullptr); ret = ticalcs_event_send(handle, &event); CLEAR_HANDLE_BUSY_IF_NECESSARY(handle); @@ -377,9 +367,7 @@ int TICALL dbus_recv_data(CalcHandle *handle, uint16_t* length, uint8_t* data) { int ret = 0; int i; - uint16_t chksum; uint8_t buf[4] = { 0, 0, 0, 0 }; - int r, q; CalcEventData event; VALIDATE_HANDLE(handle); @@ -402,8 +390,8 @@ int TICALL dbus_recv_data(CalcHandle *handle, uint16_t* length, uint8_t* data) handle->priv.progress_blk_size = 1; } - q = *length / handle->priv.progress_blk_size; - r = *length % handle->priv.progress_blk_size; + const int q = *length / handle->priv.progress_blk_size; + const int r = *length % handle->priv.progress_blk_size; handle->updat->max1 = *length; handle->updat->cnt1 = 0; @@ -416,7 +404,7 @@ int TICALL dbus_recv_data(CalcHandle *handle, uint16_t* length, uint8_t* data) { break; } - ticables_progress_get(handle->cable, NULL, NULL, &handle->updat->rate); + ticables_progress_get(handle->cable, nullptr, nullptr, &handle->updat->rate); handle->updat->cnt1 += handle->priv.progress_blk_size; if (*length > handle->priv.progress_min_size) @@ -437,7 +425,7 @@ int TICALL dbus_recv_data(CalcHandle *handle, uint16_t* length, uint8_t* data) ret = ticables_cable_recv(handle->cable, &data[i*handle->priv.progress_blk_size], (uint16_t)r); if (!ret) { - ticables_progress_get(handle->cable, NULL, NULL, &handle->updat->rate); + ticables_progress_get(handle->cable, nullptr, nullptr, &handle->updat->rate); ret = ticables_cable_recv(handle->cable, buf, 2); if (!ret) { @@ -458,7 +446,7 @@ int TICALL dbus_recv_data(CalcHandle *handle, uint16_t* length, uint8_t* data) if (!ret) { // verify checksum - chksum = buf[0] | ((uint16_t)buf[1] << 8); + const uint16_t chksum = buf[0] | ((uint16_t)buf[1] << 8); if (chksum != tifiles_checksum(data, *length)) { ret = ERR_CHECKSUM; @@ -486,7 +474,6 @@ int TICALL dbus_recv_data(CalcHandle *handle, uint16_t* length, uint8_t* data) int TICALL dbus_recv(CalcHandle* handle, uint8_t* host, uint8_t* cmd, uint16_t* length, uint8_t* data) { static int ref = 0; - int ret; VALIDATE_HANDLE(handle); VALIDATE_NONNULL(host); @@ -496,7 +483,7 @@ int TICALL dbus_recv(CalcHandle* handle, uint8_t* host, uint8_t* cmd, uint16_t* // Subroutines don't take busy if it's already taken. SET_HANDLE_BUSY_IF_NECESSARY(handle); - ret = dbus_recv_header(handle, host, cmd, length); + int ret = dbus_recv_header(handle, host, cmd, length); if (!ret) { if (*cmd == DBUS_CMD_ERR || *cmd == DBUS_CMD_ERR2) @@ -546,14 +533,8 @@ int TICALL dbus_recv(CalcHandle* handle, uint8_t* host, uint8_t* cmd, uint16_t* int TICALL dbus_dissect(CalcModel model, FILE * f, const uint8_t * data, uint32_t len) { - uint8_t mid, cmd; uint16_t length = 0; uint32_t expected_length = 0; - uint16_t chksum; - uint32_t i; - const char * cmdname; - const char * cmddesc; - const char * direction; VALIDATE_NONNULL(f); VALIDATE_NONNULL(data); @@ -564,8 +545,8 @@ int TICALL dbus_dissect(CalcModel model, FILE * f, const uint8_t * data, uint32_ } // If we come here, we know that we can at least read mid + cmd. - mid = data[0]; - cmd = data[1]; + const uint8_t mid = data[0]; + const uint8_t cmd = data[1]; // Get the special case of the TI-80 2-byte packets out of the way first. if (mid == DBUS_MID_PC_TI80) @@ -631,14 +612,14 @@ int TICALL dbus_dissect(CalcModel model, FILE * f, const uint8_t * data, uint32_ return ERR_INVALID_PACKET; } - direction = dbus_mid2direction(mid); + const char* direction = dbus_mid2direction(mid); if (direction[0] == 0) { ticalcs_warning("Unknown machine ID %u (%X)", mid, mid); } - cmdname = dbus_cmd2name(cmd); - cmddesc = dbus_cmd2desc(cmd); + const char* cmdname = dbus_cmd2name(cmd); + const char* cmddesc = dbus_cmd2desc(cmd); if (cmdname[0] == 0 || cmddesc[0] == 0) { ticalcs_warning("Unknown command ID %u (%X)", cmd, cmd); @@ -649,7 +630,7 @@ int TICALL dbus_dissect(CalcModel model, FILE * f, const uint8_t * data, uint32_ if (len > 4) { - chksum = (((uint16_t)(data[4 + length + 1])) << 8) | data[4 + length]; + const uint16_t chksum = (((uint16_t)(data[4 + length + 1])) << 8) | data[4 + length]; if (chksum != tifiles_checksum(data + 4, length)) { fprintf(f, "%s", " (Checksum mismatch)"); @@ -659,7 +640,7 @@ int TICALL dbus_dissect(CalcModel model, FILE * f, const uint8_t * data, uint32_ data += 4; len -= 4; fprintf(f, "\t\t"); - for (i = 0; i < len;) + for (uint32_t i = 0; i < len;) { fprintf(f, "%02X ", *data++); if (!(++i & 15)) diff --git a/libticalcs/trunk/src/dirlist.cc b/libticalcs/trunk/src/dirlist.cc index 63bf95c16..5b7f72579 100644 --- a/libticalcs/trunk/src/dirlist.cc +++ b/libticalcs/trunk/src/dirlist.cc @@ -80,30 +80,27 @@ static gboolean free_varentry(GNode* node, gpointer data) **/ void TICALL ticalcs_dirlist_destroy(GNode** tree) { - if (tree != NULL && *tree != NULL) + if (tree != nullptr && *tree != nullptr) { - TreeInfo *ti; - - if ((*tree)->children != NULL) + if ((*tree)->children != nullptr) { - g_node_traverse(*tree, G_IN_ORDER, G_TRAVERSE_LEAVES, -1, free_varentry, NULL); + g_node_traverse(*tree, G_IN_ORDER, G_TRAVERSE_LEAVES, -1, free_varentry, nullptr); } - ti = (TreeInfo *)((*tree)->data); + TreeInfo* ti = (TreeInfo*)((*tree)->data); g_free(ti); g_node_destroy(*tree); - *tree = NULL; + *tree = nullptr; } } static void display_node(TreeInfo * info, VarEntry * ve, unsigned char type) { char * utf8 = ticonv_varname_to_utf8(info->model, ve->name, type); - int k; printf("| "); - for (k = 0; k < 8; k++) + for (int k = 0; k < 8; k++) { printf("%02X", (uint8_t) (ve->name)[k]); } @@ -125,16 +122,13 @@ static void display_node(TreeInfo * info, VarEntry * ve, unsigned char type) static void display_tree(TreeInfo * info, GNode * vars) { - int i; - //ticalcs_info("vars has %d children", (int)g_node_n_children(vars)); - for (i = 0; i < (int)g_node_n_children(vars); i++) // parse children + for (int i = 0; i < (int)g_node_n_children(vars); i++) // parse children { GNode *parent = g_node_nth_child(vars, i); VarEntry *fe = (VarEntry *) (parent->data); - int j; - if (fe != NULL) + if (fe != nullptr) { display_node(info, fe, -1); } @@ -142,9 +136,9 @@ static void display_tree(TreeInfo * info, GNode * vars) //ticalcs_info("parent has %d children", (int)g_node_n_children(parent)); if (info->model != CALC_NSPIRE) { - for (j = 0; j < (int)g_node_n_children(parent); j++) + for (int j = 0; j < (int)g_node_n_children(parent); j++) { - GNode *child = g_node_nth_child(parent, j); + const GNode *child = g_node_nth_child(parent, j); VarEntry *ve = (VarEntry *) (child->data); display_node(info, ve, ve->type); @@ -153,7 +147,7 @@ static void display_tree(TreeInfo * info, GNode * vars) else { // Recurse into sub-folder if necessary. - if (fe != NULL && fe->type == NSP_DIR) + if (fe != nullptr && fe->type == NSP_DIR) { //ticalcs_info("Recurse"); display_tree(info, parent); @@ -175,17 +169,15 @@ static void display_tree(TreeInfo * info, GNode * vars) void TICALL ticalcs_dirlist_display(GNode* tree) { GNode *vars = tree; - TreeInfo *info; - int i; - if (tree == NULL) + if (tree == nullptr) { ticalcs_critical("ticalcs_dirlist_display(NULL)"); return; } - info = (TreeInfo *)(tree->data); - if (info == NULL) + TreeInfo* info = (TreeInfo*)(tree->data); + if (info == nullptr) { return; } @@ -194,7 +186,7 @@ void TICALL ticalcs_dirlist_display(GNode* tree) printf("%s", _("| B. name | T. name |Attr|Type| Size | Folder |\n")); printf( "+------------------+----------+----+----+----------+----------+\n"); - i = (int)g_node_n_children(vars); + const int i = (int)g_node_n_children(vars); //ticalcs_info("Root has %d children", i); display_tree(info, vars); if (!i) @@ -223,40 +215,38 @@ void TICALL ticalcs_dirlist_display(GNode* tree) **/ VarEntry *TICALL ticalcs_dirlist_ve_exist(GNode* tree, VarEntry *s) { - int i, j; GNode *vars = tree; - TreeInfo *info; - if (tree == NULL || s == NULL) + if (tree == nullptr || s == nullptr) { ticalcs_critical("ticalcs_dirlist_ve_exist: an argument is NULL"); - return NULL; + return nullptr; } - info = (TreeInfo *)(tree->data); - if (info == NULL) + const TreeInfo* info = (TreeInfo*)(tree->data); + if (info == nullptr) { - return NULL; + return nullptr; } if (strcmp(info->type, VAR_NODE_NAME) && strcmp(info->type, APP_NODE_NAME)) { - return NULL; + return nullptr; } - for (i = 0; i < (int)g_node_n_children(vars); i++) // parse folders + for (int i = 0; i < (int)g_node_n_children(vars); i++) // parse folders { GNode *parent = g_node_nth_child(vars, i); - VarEntry *fe = (VarEntry *) (parent->data); + const VarEntry *fe = (VarEntry *) (parent->data); - if ((fe != NULL) && strcmp(fe->name, s->folder)) + if ((fe != nullptr) && strcmp(fe->name, s->folder)) { continue; } - for (j = 0; j < (int)g_node_n_children(parent); j++) //parse variables + for (int j = 0; j < (int)g_node_n_children(parent); j++) //parse variables { - GNode *child = g_node_nth_child(parent, j); + const GNode *child = g_node_nth_child(parent, j); VarEntry *ve = (VarEntry *) (child->data); if ( !strcmp(ve->name, s->name) @@ -271,7 +261,7 @@ VarEntry *TICALL ticalcs_dirlist_ve_exist(GNode* tree, VarEntry *s) } } - return NULL; + return nullptr; } /** @@ -284,19 +274,17 @@ VarEntry *TICALL ticalcs_dirlist_ve_exist(GNode* tree, VarEntry *s) **/ unsigned int TICALL ticalcs_dirlist_ve_count(GNode* tree) { - unsigned int i, j; GNode *vars = tree; unsigned int nvars = 0; - TreeInfo *info; - if (tree == NULL) + if (tree == nullptr) { ticalcs_critical("ticalcs_dirlist_ve_count(NULL)"); return 0; } - info = (TreeInfo *)(tree->data); - if (info == NULL) + const TreeInfo* info = (TreeInfo*)(tree->data); + if (info == nullptr) { return 0; } @@ -306,11 +294,11 @@ unsigned int TICALL ticalcs_dirlist_ve_count(GNode* tree) return 0; } - for (i = 0; i < g_node_n_children(vars); i++) // parse folders + for (unsigned int i = 0; i < g_node_n_children(vars); i++) // parse folders { GNode *parent = g_node_nth_child(vars, i); - for (j = 0; j < g_node_n_children(parent); j++) //parse variables + for (unsigned int j = 0; j < g_node_n_children(parent); j++) //parse variables { nvars++; } @@ -329,19 +317,17 @@ unsigned int TICALL ticalcs_dirlist_ve_count(GNode* tree) **/ int TICALL ticalcs_dirlist_ram_used(GNode* tree) { - int i, j; GNode *vars = tree; uint32_t mem = 0; - TreeInfo *info; - if (tree == NULL) + if (tree == nullptr) { ticalcs_critical("ticalcs_dirlist_ram_used(NULL)"); return 0; } - info = (TreeInfo *)(tree->data); - if (info == NULL) + const TreeInfo* info = (TreeInfo*)(tree->data); + if (info == nullptr) { return 0; } @@ -351,14 +337,14 @@ int TICALL ticalcs_dirlist_ram_used(GNode* tree) return 0; } - for (i = 0; i < (int)g_node_n_children(vars); i++) // parse folders + for (int i = 0; i < (int)g_node_n_children(vars); i++) // parse folders { GNode *parent = g_node_nth_child(vars, i); - for (j = 0; j < (int)g_node_n_children(parent); j++) //parse variables + for (int j = 0; j < (int)g_node_n_children(parent); j++) //parse variables { - GNode *child = g_node_nth_child(parent, j); - VarEntry *ve = (VarEntry *) (child->data); + const GNode *child = g_node_nth_child(parent, j); + const VarEntry *ve = (VarEntry *) (child->data); if (ve->attr != ATTRB_ARCHIVED) { @@ -382,18 +368,16 @@ int TICALL ticalcs_dirlist_flash_used(GNode* vars, GNode* apps) { int i, j; uint32_t mem = 0; - TreeInfo *info1; - TreeInfo *info2; - if (vars == NULL || apps == NULL) + if (vars == nullptr || apps == nullptr) { ticalcs_critical("ticalcs_dirlist_flash_used: an argument is NULL"); return 0; } - info1 = (TreeInfo *)(vars->data); - info2 = (TreeInfo *)(apps->data); - if (info1 == NULL || info2 == NULL) + const TreeInfo* info1 = (TreeInfo*)(vars->data); + const TreeInfo* info2 = (TreeInfo*)(apps->data); + if (info1 == nullptr || info2 == nullptr) { return 0; } @@ -406,8 +390,8 @@ int TICALL ticalcs_dirlist_flash_used(GNode* vars, GNode* apps) for (j = 0; j < (int)g_node_n_children(parent); j++) //parse variables { - GNode *child = g_node_nth_child(parent, j); - VarEntry *ve = (VarEntry *) (child->data); + const GNode *child = g_node_nth_child(parent, j); + const VarEntry *ve = (VarEntry *) (child->data); if (ve->attr == ATTRB_ARCHIVED) { @@ -425,8 +409,8 @@ int TICALL ticalcs_dirlist_flash_used(GNode* vars, GNode* apps) for (j = 0; j < (int)g_node_n_children(parent); j++) //parse apps { - GNode *child = g_node_nth_child(parent, i); - VarEntry *ve = (VarEntry *) (child->data); + const GNode *child = g_node_nth_child(parent, i); + const VarEntry *ve = (VarEntry *) (child->data); mem += ve->size; } @@ -447,26 +431,25 @@ int TICALL ticalcs_dirlist_flash_used(GNode* vars, GNode* apps) **/ void TICALL ticalcs_dirlist_ve_add(GNode* tree, VarEntry *entry) { - TreeInfo *info; int i, j; int found = 0; - GNode *parent = NULL; - VarEntry *fe = NULL; + GNode *parent = nullptr; + VarEntry *fe = nullptr; GNode *child; VarEntry *ve; const char *folder; - if (tree == NULL || entry == NULL) + if (tree == nullptr || entry == nullptr) { ticalcs_critical("ticalcs_dirlist_ve_add: an argument is NULL"); return; } - info = (TreeInfo *)(tree->data); - if (info == NULL) + const TreeInfo* info = (TreeInfo*)(tree->data); + if (info == nullptr) { return; } @@ -488,7 +471,7 @@ void TICALL ticalcs_dirlist_ve_add(GNode* tree, VarEntry *entry) // If TI8x tree is empty, create pseudo-folder (NULL) if (!g_node_n_children(tree) && !tifiles_has_folder(info->model)) { - parent = g_node_new(NULL); + parent = g_node_new(nullptr); g_node_append(tree, parent); } @@ -501,7 +484,7 @@ void TICALL ticalcs_dirlist_ve_add(GNode* tree, VarEntry *entry) parent = g_node_nth_child(tree, i); fe = (VarEntry *) (parent->data); - if (fe == NULL) + if (fe == nullptr) { break; } @@ -519,7 +502,7 @@ void TICALL ticalcs_dirlist_ve_add(GNode* tree, VarEntry *entry) (!g_node_n_children(tree) && tifiles_has_folder(info->model))) { fe = tifiles_ve_create(); - if (fe != NULL) + if (fe != nullptr) { ticalcs_strlcpy(fe->name, entry->folder, sizeof(fe->name)); fe->type = TI89_DIR; @@ -550,7 +533,7 @@ void TICALL ticalcs_dirlist_ve_add(GNode* tree, VarEntry *entry) if (!found) { ve = tifiles_ve_dup(entry); - if (ve != NULL) + if (ve != nullptr) { child = g_node_new(ve); g_node_append(parent, child); @@ -575,26 +558,24 @@ void TICALL ticalcs_dirlist_ve_add(GNode* tree, VarEntry *entry) **/ void TICALL ticalcs_dirlist_ve_del(GNode* tree, VarEntry *entry) { - TreeInfo *info; int i, j; int found = 0; - GNode *parent = NULL; - VarEntry *fe = NULL; + GNode *parent = nullptr; + VarEntry *fe = nullptr; - GNode *child = NULL; - VarEntry *ve; + GNode *child = nullptr; const char *folder; - if (tree == NULL || entry == NULL) + if (tree == nullptr || entry == nullptr) { ticalcs_critical("ticalcs_dirlist_ve_del: an argument is NULL"); return; } - info = (TreeInfo *)(tree->data); - if (info == NULL) + const TreeInfo* info = (TreeInfo*)(tree->data); + if (info == nullptr) { return; } @@ -619,7 +600,7 @@ void TICALL ticalcs_dirlist_ve_del(GNode* tree, VarEntry *entry) parent = g_node_nth_child(tree, i); fe = (VarEntry *) (parent->data); - if (fe == NULL) + if (fe == nullptr) { break; } @@ -640,7 +621,7 @@ void TICALL ticalcs_dirlist_ve_del(GNode* tree, VarEntry *entry) for (found = 0, j = 0; j < (int)g_node_n_children(parent); j++) { child = g_node_nth_child(parent, j); - ve = (VarEntry *) (child->data); + const VarEntry* ve = (VarEntry*)(child->data); if (!strcmp(ve->name, entry->name)) { diff --git a/libticalcs/trunk/src/dusb_cmd.cc b/libticalcs/trunk/src/dusb_cmd.cc index 48a583a70..524b81737 100644 --- a/libticalcs/trunk/src/dusb_cmd.cc +++ b/libticalcs/trunk/src/dusb_cmd.cc @@ -114,14 +114,12 @@ static const DUSBCmdParamInfo param_types[] = { DUSB_PID_STOPWATCH_VALUE1, "Stopwatch value 1" }, // 0x005B { DUSB_PID_STOPWATCH_VALUE2, "Stopwatch value 2" }, // 0x005C { DUSB_PID_PYTHON_ON_BOARD, "Python On Board" }, // 0x005D - { 0xFFFF, NULL} + { 0xFFFF, nullptr } }; const char* TICALL dusb_cmd_param_type2name(uint16_t id) { - const DUSBCmdParamInfo *p; - - for (p = param_types; p->name != NULL; p++) + for (const DUSBCmdParamInfo* p = param_types; p->name != nullptr; p++) { if (p->id == id) { @@ -141,13 +139,13 @@ DUSBCalcParam* TICALL dusb_cp_new(CalcHandle * handle, uint16_t id, uint16_t siz DUSBCalcParam* TICALL dusb_cp_new_ex(CalcHandle * handle, uint16_t id, uint16_t size, uint8_t * data) { - DUSBCalcParam* cp = NULL; + DUSBCalcParam* cp = nullptr; if (ticalcs_validate_handle(handle)) { cp = (DUSBCalcParam *)g_malloc0(sizeof(DUSBCalcParam)); - if (NULL != cp) + if (nullptr != cp) { //GList * cpca_list; @@ -169,7 +167,7 @@ DUSBCalcParam* TICALL dusb_cp_new_ex(CalcHandle * handle, uint16_t id, uint16_t void TICALL dusb_cp_fill(DUSBCalcParam * cp, uint16_t id, uint16_t size, uint8_t * data) { - if (cp != NULL) + if (cp != nullptr) { cp->id = id; cp->ok = 0; @@ -192,7 +190,7 @@ void TICALL dusb_cp_del(CalcHandle * handle, DUSBCalcParam* cp) return; } - if (cp == NULL) + if (cp == nullptr) { ticalcs_critical("%s: cp is NULL", __FUNCTION__); return; @@ -207,7 +205,7 @@ void TICALL dusb_cp_del(CalcHandle * handle, DUSBCalcParam* cp) DUSBCalcParam ** TICALL dusb_cp_new_array(CalcHandle * handle, unsigned int size) { - DUSBCalcParam ** array = NULL; + DUSBCalcParam ** array = nullptr; if (ticalcs_validate_handle(handle)) { @@ -223,7 +221,7 @@ DUSBCalcParam ** TICALL dusb_cp_new_array(CalcHandle * handle, unsigned int size DUSBCalcParam * TICALL dusb_cp_new_array2(CalcHandle * handle, unsigned int size) { - DUSBCalcParam * array = NULL; + DUSBCalcParam * array = nullptr; if (ticalcs_validate_handle(handle)) { @@ -239,21 +237,19 @@ DUSBCalcParam * TICALL dusb_cp_new_array2(CalcHandle * handle, unsigned int size void TICALL dusb_cp_del_array(CalcHandle * handle, DUSBCalcParam **params, unsigned int size) { - unsigned int i; - if (!ticalcs_validate_handle(handle)) { ticalcs_critical("%s: handle is invalid", __FUNCTION__); return; } - if (params == NULL) + if (params == nullptr) { ticalcs_critical("%s: params is NULL", __FUNCTION__); return; } - for (i = 0; i < size && params[i]; i++) + for (unsigned int i = 0; i < size && params[i]; i++) { dusb_cp_del(handle, params[i]); } @@ -262,21 +258,19 @@ void TICALL dusb_cp_del_array(CalcHandle * handle, DUSBCalcParam **params, unsig void TICALL dusb_cp_del_array2(CalcHandle * handle, DUSBCalcParam *params, unsigned int size, int is_allocated) { - unsigned int i; - if (!ticalcs_validate_handle(handle)) { ticalcs_critical("%s: handle is invalid", __FUNCTION__); return; } - if (params == NULL) + if (params == nullptr) { ticalcs_critical("%s: params is NULL", __FUNCTION__); return; } - for (i = 0; i < size; i++) + for (unsigned int i = 0; i < size; i++) { g_free(params[i].data); } @@ -301,10 +295,10 @@ DUSBCalcParam * TICALL dusb_cp_realloc_data(CalcHandle * handle, DUSBCalcParam * { return nullptr; } - if (cp != NULL) + if (cp != nullptr) { uint8_t * data = (uint8_t *)g_realloc(cp->data, size); - if (NULL != data) + if (nullptr != data) { if (size > cp->size) { @@ -314,7 +308,7 @@ DUSBCalcParam * TICALL dusb_cp_realloc_data(CalcHandle * handle, DUSBCalcParam * } else { - return NULL; + return nullptr; } } @@ -337,7 +331,7 @@ void TICALL dusb_cp_free_array_data(CalcHandle * handle, DUSBCalcParam * cp, uns return; } - if (cp == NULL) + if (cp == nullptr) { ticalcs_critical("%s: cp is NULL", __FUNCTION__); return; @@ -358,13 +352,13 @@ DUSBCalcAttr* TICALL dusb_ca_new(CalcHandle * handle, uint16_t id, uint16_t size DUSBCalcAttr* TICALL dusb_ca_new_ex(CalcHandle * handle, uint16_t id, uint16_t size, uint8_t * data) { - DUSBCalcAttr* ca = NULL; + DUSBCalcAttr* ca = nullptr; if (ticalcs_validate_handle(handle)) { ca = (DUSBCalcAttr *)g_malloc0(sizeof(DUSBCalcAttr)); - if (NULL != ca) + if (nullptr != ca) { //GList * cpca_list; @@ -386,7 +380,7 @@ DUSBCalcAttr* TICALL dusb_ca_new_ex(CalcHandle * handle, uint16_t id, uint16_t s void TICALL dusb_ca_fill(DUSBCalcAttr * ca, uint16_t id, uint16_t size, uint8_t * data) { - if (ca != NULL) + if (ca != nullptr) { ca->id = id; ca->ok = 0; @@ -409,7 +403,7 @@ void TICALL dusb_ca_del(CalcHandle * handle, DUSBCalcAttr* ca) return; } - if (ca == NULL) + if (ca == nullptr) { ticalcs_critical("%s: ca is NULL", __FUNCTION__); return; @@ -424,7 +418,7 @@ void TICALL dusb_ca_del(CalcHandle * handle, DUSBCalcAttr* ca) DUSBCalcAttr ** TICALL dusb_ca_new_array(CalcHandle * handle, unsigned int size) { - DUSBCalcAttr ** array = NULL; + DUSBCalcAttr ** array = nullptr; if (ticalcs_validate_handle(handle)) { @@ -440,7 +434,7 @@ DUSBCalcAttr ** TICALL dusb_ca_new_array(CalcHandle * handle, unsigned int size) DUSBCalcAttr * TICALL dusb_ca_new_array2(CalcHandle * handle, unsigned int size) { - DUSBCalcAttr * array = NULL; + DUSBCalcAttr * array = nullptr; if (ticalcs_validate_handle(handle)) { @@ -456,21 +450,19 @@ DUSBCalcAttr * TICALL dusb_ca_new_array2(CalcHandle * handle, unsigned int size) void TICALL dusb_ca_del_array(CalcHandle * handle, DUSBCalcAttr **attrs, unsigned int size) { - unsigned int i; - if (!ticalcs_validate_handle(handle)) { ticalcs_critical("%s: handle is invalid", __FUNCTION__); return; } - if (attrs == NULL) + if (attrs == nullptr) { ticalcs_critical("%s: attrs is NULL", __FUNCTION__); return; } - for (i = 0; i < size && attrs[i]; i++) + for (unsigned int i = 0; i < size && attrs[i]; i++) { dusb_ca_del(handle, attrs[i]); } @@ -479,21 +471,19 @@ void TICALL dusb_ca_del_array(CalcHandle * handle, DUSBCalcAttr **attrs, unsigne void TICALL dusb_ca_del_array2(CalcHandle * handle, DUSBCalcAttr *attrs, unsigned int size, int is_allocated) { - unsigned int i; - if (!ticalcs_validate_handle(handle)) { ticalcs_critical("%s: handle is invalid", __FUNCTION__); return; } - if (attrs == NULL) + if (attrs == nullptr) { ticalcs_critical("%s: attrs is NULL", __FUNCTION__); return; } - for (i = 0; i < size; i++) + for (unsigned int i = 0; i < size; i++) { g_free(attrs[i].data); } @@ -518,10 +508,10 @@ DUSBCalcAttr * TICALL dusb_ca_realloc_data(CalcHandle * handle, DUSBCalcAttr* ca { return nullptr; } - if (ca != NULL) + if (ca != nullptr) { uint8_t * data = (uint8_t *)g_realloc(ca->data, size); - if (NULL != data) + if (nullptr != data) { if (size > ca->size) { @@ -531,7 +521,7 @@ DUSBCalcAttr * TICALL dusb_ca_realloc_data(CalcHandle * handle, DUSBCalcAttr* ca } else { - return NULL; + return nullptr; } } @@ -554,7 +544,7 @@ void TICALL dusb_ca_free_array_data(CalcHandle * handle, DUSBCalcAttr * ca, unsi return; } - if (ca == NULL) + if (ca == nullptr) { ticalcs_critical("%s: ca is NULL", __FUNCTION__); return; @@ -605,9 +595,7 @@ static const uint16_t usb_errors[] = { static int err_code(uint16_t code) { - unsigned int i; - - for (i = 0; i < sizeof(usb_errors) / sizeof(usb_errors[0]); i++) + for (unsigned int i = 0; i < sizeof(usb_errors) / sizeof(usb_errors[0]); i++) { if (usb_errors[i] == code) { @@ -648,7 +636,7 @@ int dusb_check_cmd_data(CalcModel model, const uint8_t * data, uint32_t len, uin { if (len >= 2U) { - uint16_t npids = (((uint16_t)(data[0])) << 8) | ((uint16_t)(data[1])); + const uint16_t npids = (((uint16_t)(data[0])) << 8) | ((uint16_t)(data[1])); if (len == 2U + npids * 2) { ret = 0; @@ -663,21 +651,20 @@ int dusb_check_cmd_data(CalcModel model, const uint8_t * data, uint32_t len, uin { if (len >= 2U) { - uint16_t nparams = (((uint16_t)(data[0])) << 8) | ((uint16_t)(data[1])); + const uint16_t nparams = (((uint16_t)(data[0])) << 8) | ((uint16_t)(data[1])); data += 2; if (len >= 2U + 3 * nparams) { - uint16_t i; uint32_t additional_size = 0; int overrun = 0; - for (i = 0; i < nparams; i++) + for (uint16_t i = 0; i < nparams; i++) { - uint8_t ok = !(data[2]); + const uint8_t ok = !(data[2]); data += 3; if (ok) { - uint16_t size = (((uint16_t)(data[0])) << 8) | ((uint16_t)(data[1])); + const uint16_t size = (((uint16_t)(data[0])) << 8) | ((uint16_t)(data[1])); data += size + 2; additional_size += size + 2; } @@ -704,7 +691,7 @@ int dusb_check_cmd_data(CalcModel model, const uint8_t * data, uint32_t len, uin { if (len > 4U) { - uint16_t size = (((uint16_t)(data[2])) << 8) | ((uint16_t)(data[3])); + const uint16_t size = (((uint16_t)(data[2])) << 8) | ((uint16_t)(data[3])); if (len == 4U + size) { ret = 0; @@ -808,7 +795,7 @@ int dusb_check_cmd_data(CalcModel model, const uint8_t * data, uint32_t len, uin int dusb_dissect_cmd_data(CalcModel model, FILE *f, const uint8_t * data, uint32_t len, uint32_t vtl_size, uint16_t vtl_type) { - int ret = dusb_check_cmd_data(model, data, len, vtl_size, vtl_type); + const int ret = dusb_check_cmd_data(model, data, len, vtl_size, vtl_type); (void)vtl_size; if (ret) @@ -820,27 +807,26 @@ int dusb_dissect_cmd_data(CalcModel model, FILE *f, const uint8_t * data, uint32 { case DUSB_VPKT_PING: { - uint16_t arg1 = (((uint16_t)(data[0])) << 8) | ((uint16_t)(data[1])); - uint16_t arg2 = (((uint16_t)(data[2])) << 8) | ((uint16_t)(data[3])); - uint16_t arg3 = (((uint16_t)(data[4])) << 8) | ((uint16_t)(data[5])); - uint16_t arg4 = (((uint16_t)(data[6])) << 8) | ((uint16_t)(data[7])); - uint16_t arg5 = (((uint16_t)(data[8])) << 8) | ((uint16_t)(data[9])); + const uint16_t arg1 = (((uint16_t)(data[0])) << 8) | ((uint16_t)(data[1])); + const uint16_t arg2 = (((uint16_t)(data[2])) << 8) | ((uint16_t)(data[3])); + const uint16_t arg3 = (((uint16_t)(data[4])) << 8) | ((uint16_t)(data[5])); + const uint16_t arg4 = (((uint16_t)(data[6])) << 8) | ((uint16_t)(data[7])); + const uint16_t arg5 = (((uint16_t)(data[8])) << 8) | ((uint16_t)(data[9])); fprintf(f, "Set mode: { %u, %u, %u, %u, 0x%04X }\n", arg1, arg2, arg3, arg4, arg5); } break; case DUSB_VPKT_PARM_REQ: { - uint16_t npids = (((uint16_t)(data[0])) << 8) | ((uint16_t)(data[1])); - uint16_t i; + const uint16_t npids = (((uint16_t)(data[0])) << 8) | ((uint16_t)(data[1])); if (len == 2U + npids * 2) { data += 2; fprintf(f, "Requested %u (%X) parameter IDs:\n", npids, npids); - for (i = 0; i < npids; i++) + for (uint16_t i = 0; i < npids; i++) { - uint16_t pid = (((uint16_t)(data[0])) << 8) | ((uint16_t)(data[1])); + const uint16_t pid = (((uint16_t)(data[0])) << 8) | ((uint16_t)(data[1])); data += 2; fprintf(f, "\t%04X (%s)\n", pid, dusb_cmd_param_type2name(pid)); } @@ -851,25 +837,22 @@ int dusb_dissect_cmd_data(CalcModel model, FILE *f, const uint8_t * data, uint32 case DUSB_VPKT_PARM_DATA: { - uint16_t nparams = (((uint16_t)(data[0])) << 8) | ((uint16_t)(data[1])); - uint16_t i; + const uint16_t nparams = (((uint16_t)(data[0])) << 8) | ((uint16_t)(data[1])); uint32_t additional_size = 0; if (len >= 2U + 3 * nparams) { data += 2; fprintf(f, "Received %u (%X) parameter values:\n", nparams, nparams); - for (i = 0; i < nparams; i++) + for (uint16_t i = 0; i < nparams; i++) { - uint16_t pid = (((uint16_t)(data[0])) << 8) | ((uint16_t)(data[1])); - uint8_t ok; + const uint16_t pid = (((uint16_t)(data[0])) << 8) | ((uint16_t)(data[1])); data += 2; - ok = !(*data++); + const uint8_t ok = !(*data++); fprintf(f, "\t%04X (%s): ", pid, dusb_cmd_param_type2name(pid)); if (ok) { - uint16_t j; - uint16_t size = (((uint16_t)(data[0])) << 8) | ((uint16_t)(data[1])); + const uint16_t size = (((uint16_t)(data[0])) << 8) | ((uint16_t)(data[1])); data += 2; additional_size += size + 2; @@ -878,7 +861,7 @@ int dusb_dissect_cmd_data(CalcModel model, FILE *f, const uint8_t * data, uint32 break; } fprintf(f, "OK, size %04X\n\t\t", size); - for (j = 0; j < size;) + for (uint16_t j = 0; j < size;) { fprintf(f, "%02X ", *data++); if (!(++j & 15)) @@ -900,15 +883,14 @@ int dusb_dissect_cmd_data(CalcModel model, FILE *f, const uint8_t * data, uint32 case DUSB_VPKT_PARM_SET: { - uint16_t id = (((uint16_t)(data[0])) << 8) | ((uint16_t)(data[1])); - uint16_t size = (((uint16_t)(data[2])) << 8) | ((uint16_t)(data[3])); - uint16_t i; + const uint16_t id = (((uint16_t)(data[0])) << 8) | ((uint16_t)(data[1])); + const uint16_t size = (((uint16_t)(data[2])) << 8) | ((uint16_t)(data[3])); data += 4; if (len == 4U + size) { fprintf(f, "Sending value of size %04X for parameter %04X\n\t", size, id); - for (i = 0; i < size; i++) + for (uint16_t i = 0; i < size; i++) { fprintf(f, "%02X ", *data++); if (!(++i & 15)) @@ -923,14 +905,14 @@ int dusb_dissect_cmd_data(CalcModel model, FILE *f, const uint8_t * data, uint32 case DUSB_VPKT_OS_BEGIN: { - uint32_t size = (((uint32_t)data[7]) << 24) | (((uint32_t)data[8]) << 16) | (((uint32_t)data[9]) << 8) | (((uint32_t)data[10]) << 0); + const uint32_t size = (((uint32_t)data[7]) << 24) | (((uint32_t)data[8]) << 16) | (((uint32_t)data[9]) << 8) | (((uint32_t)data[10]) << 0); fprintf(f, "Size: %lu / %08lX\n", (unsigned long)size, (unsigned long)size); } break; case DUSB_VPKT_OS_ACK: { - uint32_t size = (((uint32_t)data[0]) << 24) | (((uint32_t)data[1]) << 16) | (((uint32_t)data[2]) << 8) | (((uint32_t)data[3]) << 0); + const uint32_t size = (((uint32_t)data[0]) << 24) | (((uint32_t)data[1]) << 16) | (((uint32_t)data[2]) << 8) | (((uint32_t)data[3]) << 0); fprintf(f, "Chunk size: %lu / %08lX\n", (unsigned long)size, (unsigned long)size); } break; @@ -940,12 +922,12 @@ int dusb_dissect_cmd_data(CalcModel model, FILE *f, const uint8_t * data, uint32 { if (model == CALC_TI83PCE_USB || model == CALC_TI84PCE_USB) { - uint32_t addr = (((uint32_t)data[3]) << 24) | (((uint32_t)data[2]) << 16) | (((uint32_t)data[1]) << 8) | (((uint32_t)data[0]) << 0); + const uint32_t addr = (((uint32_t)data[3]) << 24) | (((uint32_t)data[2]) << 16) | (((uint32_t)data[1]) << 8) | (((uint32_t)data[0]) << 0); fprintf(f, "Address: %08lX\n", (unsigned long)addr); } else if (model != CALC_TI89T_USB) { - uint16_t addr = (((uint16_t)data[0]) << 8) | (((uint32_t)data[1]) << 0); + const uint16_t addr = (((uint16_t)data[0]) << 8) | (((uint32_t)data[1]) << 0); fprintf(f, "Address: %04X\tPage: %02X\tFlag: %02X\n", addr, data[2], data[3]); } // else do nothing. @@ -954,14 +936,14 @@ int dusb_dissect_cmd_data(CalcModel model, FILE *f, const uint8_t * data, uint32 case DUSB_VPKT_DELAY_ACK: { - uint32_t delay = (((uint32_t)data[0]) << 24) | (((uint32_t)data[1]) << 16) | (((uint32_t)data[2]) << 8) | (data[3] << 0); + const uint32_t delay = (((uint32_t)data[0]) << 24) | (((uint32_t)data[1]) << 16) | (((uint32_t)data[2]) << 8) | (data[3] << 0); fprintf(f, "Delay: %lu\n", (unsigned long)delay); } break; case DUSB_VPKT_ERROR: { - int err = err_code((((uint16_t)data[0]) << 8) | (((uint32_t)data[1]) << 0)); + const int err = err_code((((uint16_t)data[0]) << 8) | (((uint32_t)data[1]) << 0)); fprintf(f, "Error code: %u (%04X)\n", err, err); } break; @@ -1027,7 +1009,6 @@ int dusb_dissect_cmd_data(CalcModel model, FILE *f, const uint8_t * data, uint32 // 0x0001: set mode or ping int TICALL dusb_cmd_s_mode_set(CalcHandle *handle, const DUSBModeSet mode) { - DUSBVirtualPacket* pkt; int retval = 0; VALIDATE_HANDLE(handle); @@ -1035,10 +1016,10 @@ int TICALL dusb_cmd_s_mode_set(CalcHandle *handle, const DUSBModeSet mode) retval = dusb_send_buf_size_request(handle, DUSB_DFL_BUF_SIZE); if (!retval) { - retval = dusb_recv_buf_size_alloc(handle, NULL); + retval = dusb_recv_buf_size_alloc(handle, nullptr); if (!retval) { - pkt = dusb_vtl_pkt_new_ex(handle, sizeof(mode), DUSB_VPKT_PING, (uint8_t *)dusb_vtl_pkt_alloc_data(handle, sizeof(mode))); + DUSBVirtualPacket* pkt = dusb_vtl_pkt_new_ex(handle, sizeof(mode), DUSB_VPKT_PING, (uint8_t*)dusb_vtl_pkt_alloc_data(handle, sizeof(mode))); pkt->data[0] = MSB(mode.arg1); pkt->data[1] = LSB(mode.arg1); @@ -1065,12 +1046,11 @@ int TICALL dusb_cmd_s_mode_set(CalcHandle *handle, const DUSBModeSet mode) // 0x0002: begin OS transfer int TICALL dusb_cmd_s_os_begin(CalcHandle *handle, uint32_t size) { - DUSBVirtualPacket* pkt; int retval = 0; VALIDATE_HANDLE(handle); - pkt = dusb_vtl_pkt_new_ex(handle, 11, DUSB_VPKT_OS_BEGIN, (uint8_t *)dusb_vtl_pkt_alloc_data(handle, 11)); + DUSBVirtualPacket* pkt = dusb_vtl_pkt_new_ex(handle, 11, DUSB_VPKT_OS_BEGIN, (uint8_t*)dusb_vtl_pkt_alloc_data(handle, 11)); pkt->data[7] = MSB(MSW(size)); pkt->data[8] = LSB(MSW(size)); @@ -1088,12 +1068,11 @@ int TICALL dusb_cmd_s_os_begin(CalcHandle *handle, uint32_t size) // 0x0003: acknowledgement of OS transfer int TICALL dusb_cmd_r_os_ack(CalcHandle *handle, uint32_t *size) { - DUSBVirtualPacket* pkt; int retval = 0; VALIDATE_HANDLE(handle); - pkt = dusb_vtl_pkt_new_ex(handle, 0, 0, NULL); + DUSBVirtualPacket* pkt = dusb_vtl_pkt_new_ex(handle, 0, 0, nullptr); retval = dusb_recv_data(handle, pkt); @@ -1112,7 +1091,7 @@ int TICALL dusb_cmd_r_os_ack(CalcHandle *handle, uint32_t *size) goto end; } - if (size != NULL) + if (size != nullptr) { *size = (((uint32_t)pkt->data[0]) << 24) | (((uint32_t)pkt->data[1]) << 16) | (((uint32_t)pkt->data[2]) << 8) | (((uint32_t)pkt->data[3]) << 0); ticalcs_info(" chunk size = %08x (%i)", *size, *size); @@ -1127,13 +1106,12 @@ int TICALL dusb_cmd_r_os_ack(CalcHandle *handle, uint32_t *size) static int s_os(uint8_t type, CalcHandle *handle, uint16_t addr, uint8_t page, uint8_t flag, uint32_t size, uint8_t *data) { - DUSBVirtualPacket* pkt; int retval = 0; VALIDATE_HANDLE(handle); VALIDATE_NONNULL(data); - pkt = dusb_vtl_pkt_new_ex(handle, 4 + size, type, (uint8_t *)dusb_vtl_pkt_alloc_data(handle, 4 + size)); + DUSBVirtualPacket* pkt = dusb_vtl_pkt_new_ex(handle, 4 + size, type, (uint8_t*)dusb_vtl_pkt_alloc_data(handle, 4 + size)); pkt->data[0] = MSB(addr); pkt->data[1] = LSB(addr); @@ -1163,13 +1141,12 @@ int TICALL dusb_cmd_s_os_data(CalcHandle *handle, uint16_t addr, uint8_t page, u // 0x0004: OS header int TICALL dusb_cmd_s_os_header_89(CalcHandle *handle, uint32_t size, uint8_t *data) { - DUSBVirtualPacket* pkt; int retval = 0; VALIDATE_HANDLE(handle); VALIDATE_NONNULL(data); - pkt = dusb_vtl_pkt_new_ex(handle, size, DUSB_VPKT_OS_HEADER, (uint8_t *)dusb_vtl_pkt_alloc_data(handle, size)); + DUSBVirtualPacket* pkt = dusb_vtl_pkt_new_ex(handle, size, DUSB_VPKT_OS_HEADER, (uint8_t*)dusb_vtl_pkt_alloc_data(handle, size)); memcpy(pkt->data, data, size); retval = dusb_send_data(handle, pkt); @@ -1183,13 +1160,12 @@ int TICALL dusb_cmd_s_os_header_89(CalcHandle *handle, uint32_t size, uint8_t *d // 0x0005: OS data int TICALL dusb_cmd_s_os_data_89(CalcHandle *handle, uint32_t size, uint8_t *data) { - DUSBVirtualPacket* pkt; int retval = 0; VALIDATE_HANDLE(handle); VALIDATE_NONNULL(data); - pkt = dusb_vtl_pkt_new_ex(handle, size, DUSB_VPKT_OS_DATA, (uint8_t *)dusb_vtl_pkt_alloc_data(handle, size)); + DUSBVirtualPacket* pkt = dusb_vtl_pkt_new_ex(handle, size, DUSB_VPKT_OS_DATA, (uint8_t*)dusb_vtl_pkt_alloc_data(handle, size)); memcpy(pkt->data, data, size); retval = dusb_send_data(handle, pkt); @@ -1203,13 +1179,12 @@ int TICALL dusb_cmd_s_os_data_89(CalcHandle *handle, uint32_t size, uint8_t *dat // 0x0005: OS data int TICALL dusb_cmd_s_os_data_834pce(CalcHandle *handle, uint32_t addr, uint32_t size, uint8_t *data) { - DUSBVirtualPacket* pkt; int retval = 0; VALIDATE_HANDLE(handle); VALIDATE_NONNULL(data); - pkt = dusb_vtl_pkt_new_ex(handle, 4 + size, DUSB_VPKT_OS_DATA, (uint8_t *)dusb_vtl_pkt_alloc_data(handle, 4 + size)); + DUSBVirtualPacket* pkt = dusb_vtl_pkt_new_ex(handle, 4 + size, DUSB_VPKT_OS_DATA, (uint8_t*)dusb_vtl_pkt_alloc_data(handle, 4 + size)); pkt->data[0] = (addr ) & 0xFF; pkt->data[1] = (addr >> 8) & 0xFF; @@ -1227,12 +1202,11 @@ int TICALL dusb_cmd_s_os_data_834pce(CalcHandle *handle, uint32_t addr, uint32_t // 0x0006: acknowledgement of EOT int TICALL dusb_cmd_r_eot_ack(CalcHandle *handle) { - DUSBVirtualPacket* pkt; int retval = 0; VALIDATE_HANDLE(handle); - pkt = dusb_vtl_pkt_new_ex(handle, 0, 0, NULL); + DUSBVirtualPacket* pkt = dusb_vtl_pkt_new_ex(handle, 0, 0, nullptr); retval = dusb_recv_data(handle, pkt); @@ -1259,19 +1233,18 @@ int TICALL dusb_cmd_r_eot_ack(CalcHandle *handle) // 0x0007: parameter request int TICALL dusb_cmd_s_param_request(CalcHandle *handle, unsigned int npids, const uint16_t *pids) { - DUSBVirtualPacket* pkt; - unsigned int i; int retval = 0; VALIDATE_HANDLE(handle); VALIDATE_ATTRS(npids, pids); - pkt = dusb_vtl_pkt_new_ex(handle, 2 + npids * sizeof(uint16_t), DUSB_VPKT_PARM_REQ, (uint8_t *)dusb_vtl_pkt_alloc_data(handle, 2 + npids * sizeof(uint16_t))); + DUSBVirtualPacket* pkt = dusb_vtl_pkt_new_ex(handle, 2 + npids * sizeof(uint16_t), DUSB_VPKT_PARM_REQ, + (uint8_t*)dusb_vtl_pkt_alloc_data(handle, 2 + npids * sizeof(uint16_t))); pkt->data[0] = MSB(npids); pkt->data[1] = LSB(npids); - for (i = 0; i < npids; i++) + for (unsigned int i = 0; i < npids; i++) { pkt->data[2*(i+1) + 0] = MSB(pids[i]); pkt->data[2*(i+1) + 1] = LSB(pids[i]); @@ -1288,14 +1261,13 @@ int TICALL dusb_cmd_s_param_request(CalcHandle *handle, unsigned int npids, cons // 0x0008: parameter data int TICALL dusb_cmd_r_param_data(CalcHandle *handle, unsigned int nparams, DUSBCalcParam **params) { - DUSBVirtualPacket* pkt; unsigned int i, j; int retval = 0; VALIDATE_HANDLE(handle); VALIDATE_NONNULL(params); - pkt = dusb_vtl_pkt_new_ex(handle, 0, 0, NULL); + DUSBVirtualPacket* pkt = dusb_vtl_pkt_new_ex(handle, 0, 0, nullptr); retval = dusb_recv_data(handle, pkt); @@ -1324,7 +1296,7 @@ int TICALL dusb_cmd_r_param_data(CalcHandle *handle, unsigned int nparams, DUSBC { DUSBCalcParam *s = dusb_cp_new(handle, 0, 0); - if (s != NULL) + if (s != nullptr) { s->id = ((uint16_t)pkt->data[j++]) << 8; s->id |= pkt->data[j++]; s->ok = !pkt->data[j++]; @@ -1334,7 +1306,7 @@ int TICALL dusb_cmd_r_param_data(CalcHandle *handle, unsigned int nparams, DUSBC if (s->size > 0) { s->data = (uint8_t *)g_malloc0(s->size); - if (s->data != NULL) + if (s->data != nullptr) { memcpy(s->data, &pkt->data[j], s->size); } @@ -1367,7 +1339,6 @@ int TICALL dusb_cmd_r_param_data(CalcHandle *handle, unsigned int nparams, DUSBC // 0x0008 (variant): screenshot data (for TI-84 Plus C support) int TICALL dusb_cmd_r_screenshot(CalcHandle *handle, uint32_t *size, uint8_t **data) { - DUSBVirtualPacket* pkt; uint32_t declared_size; int retval = 0; @@ -1375,7 +1346,7 @@ int TICALL dusb_cmd_r_screenshot(CalcHandle *handle, uint32_t *size, uint8_t **d VALIDATE_NONNULL(size); VALIDATE_NONNULL(data); - pkt = dusb_vtl_pkt_new_ex(handle, 0, 0, NULL); + DUSBVirtualPacket* pkt = dusb_vtl_pkt_new_ex(handle, 0, 0, nullptr); retval = dusb_recv_data_varsize(handle, pkt, &declared_size, 153600); @@ -1415,22 +1386,21 @@ int TICALL dusb_cmd_r_screenshot(CalcHandle *handle, uint32_t *size, uint8_t **d // 0x0009: request directory listing int TICALL dusb_cmd_s_dirlist_request(CalcHandle *handle, unsigned int naids, const uint16_t *aids) { - DUSBVirtualPacket* pkt; - unsigned int i; unsigned int j = 0; int retval = 0; VALIDATE_HANDLE(handle); VALIDATE_ATTRS(naids, aids); - pkt = dusb_vtl_pkt_new_ex(handle, 4 + 2 * naids + 7, DUSB_VPKT_DIR_REQ, (uint8_t *)dusb_vtl_pkt_alloc_data(handle, 4 + 2 * naids + 7)); + DUSBVirtualPacket* pkt = dusb_vtl_pkt_new_ex(handle, 4 + 2 * naids + 7, DUSB_VPKT_DIR_REQ, + (uint8_t*)dusb_vtl_pkt_alloc_data(handle, 4 + 2 * naids + 7)); pkt->data[j++] = MSB(MSW(naids)); pkt->data[j++] = LSB(MSW(naids)); pkt->data[j++] = MSB(LSW(naids)); pkt->data[j++] = LSB(LSW(naids)); - for (i = 0; i < naids; i++) + for (unsigned int i = 0; i < naids; i++) { pkt->data[j++] = MSB(aids[i]); pkt->data[j++] = LSB(aids[i]); @@ -1453,11 +1423,6 @@ int TICALL dusb_cmd_s_dirlist_request(CalcHandle *handle, unsigned int naids, co // beware: attr array contents is allocated by function int TICALL dusb_cmd_r_var_header(CalcHandle *handle, char *folder, char *name, DUSBCalcAttr **attr) { - DUSBVirtualPacket* pkt; - uint8_t fld_len; - uint8_t var_len; - int nattr; - int i, j; int retval = 0; VALIDATE_HANDLE(handle); @@ -1467,7 +1432,7 @@ int TICALL dusb_cmd_r_var_header(CalcHandle *handle, char *folder, char *name, D folder[0] = 0; name[0] = 0; - pkt = dusb_vtl_pkt_new_ex(handle, 0, 0, NULL); + DUSBVirtualPacket* pkt = dusb_vtl_pkt_new_ex(handle, 0, 0, nullptr); retval = dusb_recv_data(handle, pkt); @@ -1491,24 +1456,24 @@ int TICALL dusb_cmd_r_var_header(CalcHandle *handle, char *folder, char *name, D goto end; } - j = 0; - fld_len = pkt->data[j++]; + int j = 0; + const uint8_t fld_len = pkt->data[j++]; if (fld_len) { memcpy(folder, &pkt->data[j], fld_len + 1); j += fld_len+1; } - var_len = pkt->data[j++]; + const uint8_t var_len = pkt->data[j++]; if (var_len) { memcpy(name, &pkt->data[j], var_len + 1); j += var_len+1; } - nattr = (((int)pkt->data[j + 0]) << 8) | pkt->data[j + 1]; + const int nattr = (((int)pkt->data[j + 0]) << 8) | pkt->data[j + 1]; j += 2; - for (i = 0; i < nattr; i++) + for (int i = 0; i < nattr; i++) { DUSBCalcAttr *s = attr[i] = dusb_ca_new(handle, 0, 0); @@ -1534,8 +1499,6 @@ int TICALL dusb_cmd_r_var_header(CalcHandle *handle, char *folder, char *name, D // 0x000B: request to send static int dusb_cmd_s_rts2(CalcHandle *handle, const char *folder, const char *name, uint32_t size, unsigned int nattrs, const DUSBCalcAttr **attrs, int modeflag) { - DUSBVirtualPacket* pkt; - int pks; unsigned int i; unsigned int j = 0; int retval = 0; @@ -1545,7 +1508,7 @@ static int dusb_cmd_s_rts2(CalcHandle *handle, const char *folder, const char *n VALIDATE_NONNULL(name); VALIDATE_ATTRS(nattrs, attrs); - pks = 2 + strlen(name) + 1 + 5 + 2; + int pks = 2 + strlen(name) + 1 + 5 + 2; if (strlen(folder)) { pks += strlen(folder)+1; @@ -1555,7 +1518,7 @@ static int dusb_cmd_s_rts2(CalcHandle *handle, const char *folder, const char *n pks += 4 + attrs[i]->size; } - pkt = dusb_vtl_pkt_new_ex(handle, pks, DUSB_VPKT_RTS, (uint8_t *)dusb_vtl_pkt_alloc_data(handle, pks)); + DUSBVirtualPacket* pkt = dusb_vtl_pkt_new_ex(handle, pks, DUSB_VPKT_RTS, (uint8_t*)dusb_vtl_pkt_alloc_data(handle, pks)); if (strlen(folder)) { @@ -1614,8 +1577,6 @@ int TICALL dusb_cmd_s_rts_ns(CalcHandle *handle, const char *folder, const char // 0x000C: variable request int TICALL dusb_cmd_s_var_request(CalcHandle *handle, const char *folder, const char *name, unsigned int naids, const uint16_t *aids, unsigned int nattrs, const DUSBCalcAttr **attrs) { - DUSBVirtualPacket* pkt; - int pks; unsigned int i; unsigned int j = 0; int retval = 0; @@ -1626,7 +1587,7 @@ int TICALL dusb_cmd_s_var_request(CalcHandle *handle, const char *folder, const VALIDATE_ATTRS(naids, aids); VALIDATE_ATTRS(nattrs, attrs); - pks = 2 + strlen(name) + 1 + 5 + 2 + 2 * naids + 2; + int pks = 2 + strlen(name) + 1 + 5 + 2 + 2 * naids + 2; if (strlen(folder)) { pks += strlen(folder)+1; @@ -1637,7 +1598,7 @@ int TICALL dusb_cmd_s_var_request(CalcHandle *handle, const char *folder, const } pks += 2; - pkt = dusb_vtl_pkt_new_ex(handle, pks, DUSB_VPKT_VAR_REQ, (uint8_t *)dusb_vtl_pkt_alloc_data(handle, pks)); + DUSBVirtualPacket* pkt = dusb_vtl_pkt_new_ex(handle, pks, DUSB_VPKT_VAR_REQ, (uint8_t*)dusb_vtl_pkt_alloc_data(handle, pks)); if (strlen(folder)) { @@ -1691,13 +1652,12 @@ int TICALL dusb_cmd_s_var_request(CalcHandle *handle, const char *folder, const // 0x000D: variable contents (recv) int TICALL dusb_cmd_r_var_content(CalcHandle *handle, uint32_t *size, uint8_t **data) { - DUSBVirtualPacket* pkt; int retval = 0; VALIDATE_HANDLE(handle); VALIDATE_NONNULL(data); - pkt = dusb_vtl_pkt_new_ex(handle, 0, 0, NULL); + DUSBVirtualPacket* pkt = dusb_vtl_pkt_new_ex(handle, 0, 0, nullptr); retval = dusb_recv_data(handle, pkt); @@ -1716,13 +1676,13 @@ int TICALL dusb_cmd_r_var_content(CalcHandle *handle, uint32_t *size, uint8_t ** goto end; } - if (size != NULL) + if (size != nullptr) { *size = pkt->size; } *data = (uint8_t *)g_malloc0(pkt->size); - if (*data != NULL) + if (*data != nullptr) { memcpy(*data, pkt->data, pkt->size); } @@ -1742,13 +1702,12 @@ int TICALL dusb_cmd_r_var_content(CalcHandle *handle, uint32_t *size, uint8_t ** // 0x000D: variable contents (send) int TICALL dusb_cmd_s_var_content(CalcHandle *handle, uint32_t size, uint8_t *data) { - DUSBVirtualPacket* pkt; int retval = 0; VALIDATE_HANDLE(handle); VALIDATE_NONNULL(data); - pkt = dusb_vtl_pkt_new_ex(handle, size, DUSB_VPKT_VAR_CNTS, (uint8_t *)dusb_vtl_pkt_alloc_data(handle, size)); + DUSBVirtualPacket* pkt = dusb_vtl_pkt_new_ex(handle, size, DUSB_VPKT_VAR_CNTS, (uint8_t*)dusb_vtl_pkt_alloc_data(handle, size)); memcpy(pkt->data, data, size); retval = dusb_send_data(handle, pkt); @@ -1762,13 +1721,13 @@ int TICALL dusb_cmd_s_var_content(CalcHandle *handle, uint32_t size, uint8_t *da // 0x000E: parameter set int TICALL dusb_cmd_s_param_set(CalcHandle *handle, const DUSBCalcParam *param) { - DUSBVirtualPacket* pkt; int retval = 0; VALIDATE_HANDLE(handle); VALIDATE_NONNULL(param); - pkt = dusb_vtl_pkt_new_ex(handle, 2 + 2 + param->size, DUSB_VPKT_PARM_SET, (uint8_t *)dusb_vtl_pkt_alloc_data(handle, 2 + 2 + param->size)); + DUSBVirtualPacket* pkt = dusb_vtl_pkt_new_ex(handle, 2 + 2 + param->size, DUSB_VPKT_PARM_SET, + (uint8_t*)dusb_vtl_pkt_alloc_data(handle, 2 + 2 + param->size)); pkt->data[0] = MSB(param->id); pkt->data[1] = LSB(param->id); @@ -1791,10 +1750,8 @@ int TICALL dusb_cmd_s_var_modify(CalcHandle *handle, const char *dst_folder, const char *dst_name, unsigned int n_dst_attrs, const DUSBCalcAttr **dst_attrs) { - DUSBVirtualPacket* pkt; unsigned int i; unsigned int j = 0; - unsigned int pks; int retval = 0; VALIDATE_HANDLE(handle); @@ -1805,7 +1762,7 @@ int TICALL dusb_cmd_s_var_modify(CalcHandle *handle, VALIDATE_NONNULL(dst_name); VALIDATE_ATTRS(n_dst_attrs, dst_attrs); - pks = 2 + strlen(src_name)+1 + 2; + unsigned int pks = 2 + strlen(src_name) + 1 + 2; if (strlen(src_folder)) { pks += strlen(src_folder)+1; @@ -1830,7 +1787,7 @@ int TICALL dusb_cmd_s_var_modify(CalcHandle *handle, pks += 4 + dst_attrs[i]->size; } - pkt = dusb_vtl_pkt_new_ex(handle, pks, DUSB_VPKT_MODIF_VAR, (uint8_t *)dusb_vtl_pkt_alloc_data(handle, pks)); + DUSBVirtualPacket* pkt = dusb_vtl_pkt_new_ex(handle, pks, DUSB_VPKT_MODIF_VAR, (uint8_t*)dusb_vtl_pkt_alloc_data(handle, pks)); if (strlen(src_folder)) { @@ -1915,14 +1872,13 @@ int TICALL dusb_cmd_s_var_modify(CalcHandle *handle, int TICALL dusb_cmd_s_var_delete(CalcHandle *handle, const char *folder, const char *name, unsigned int nattrs, const DUSBCalcAttr **attrs) { - return dusb_cmd_s_var_modify(handle, folder, name, nattrs, attrs, "", "", 0, NULL); + return dusb_cmd_s_var_modify(handle, folder, name, nattrs, attrs, "", "", 0, nullptr); } // 0x0011: remote control int TICALL dusb_cmd_s_execute(CalcHandle *handle, const char *folder, const char *name, uint8_t action, const char *args, uint16_t code) { - DUSBVirtualPacket* pkt = NULL; - int pks; + DUSBVirtualPacket* pkt = nullptr; int j = 0; int retval = 0; @@ -1930,7 +1886,7 @@ int TICALL dusb_cmd_s_execute(CalcHandle *handle, const char *folder, const char VALIDATE_NONNULL(folder); VALIDATE_NONNULL(name); - pks = 3; + int pks = 3; if (handle->model == CALC_TI89T_USB && folder[0] != 0) { pks += strlen(folder) + 1; @@ -2007,12 +1963,11 @@ int TICALL dusb_cmd_s_execute(CalcHandle *handle, const char *folder, const char // 0x0012: acknowledgement of mode setting int TICALL dusb_cmd_r_mode_ack(CalcHandle *handle) { - DUSBVirtualPacket* pkt; int retval = 0; VALIDATE_HANDLE(handle); - pkt = dusb_vtl_pkt_new_ex(handle, 0, 0, NULL); + DUSBVirtualPacket* pkt = dusb_vtl_pkt_new_ex(handle, 0, 0, nullptr); retval = dusb_recv_data(handle, pkt); @@ -2039,12 +1994,11 @@ int TICALL dusb_cmd_r_mode_ack(CalcHandle *handle) // 0xAA00: acknowledgement of data int TICALL dusb_cmd_r_data_ack(CalcHandle *handle) { - DUSBVirtualPacket* pkt; int retval = 0; VALIDATE_HANDLE(handle); - pkt = dusb_vtl_pkt_new_ex(handle, 0, 0, NULL); + DUSBVirtualPacket* pkt = dusb_vtl_pkt_new_ex(handle, 0, 0, nullptr); retval = dusb_recv_data(handle, pkt); @@ -2072,12 +2026,11 @@ int TICALL dusb_cmd_r_data_ack(CalcHandle *handle) // 0xBB00: delay acknowledgement int TICALL dusb_cmd_r_delay_ack(CalcHandle *handle) { - DUSBVirtualPacket* pkt; int retval = 0; VALIDATE_HANDLE(handle); - pkt = dusb_vtl_pkt_new_ex(handle, 0, 0, NULL); + DUSBVirtualPacket* pkt = dusb_vtl_pkt_new_ex(handle, 0, 0, nullptr); retval = dusb_recv_data(handle, pkt); @@ -2104,12 +2057,11 @@ int TICALL dusb_cmd_r_delay_ack(CalcHandle *handle) // 0xDD00: end of transmission (send) int TICALL dusb_cmd_s_eot(CalcHandle *handle) { - DUSBVirtualPacket* pkt; int retval = 0; VALIDATE_HANDLE(handle); - pkt = dusb_vtl_pkt_new_ex(handle, 0, DUSB_VPKT_EOT, NULL); + DUSBVirtualPacket* pkt = dusb_vtl_pkt_new_ex(handle, 0, DUSB_VPKT_EOT, nullptr); retval = dusb_send_data(handle, pkt); @@ -2121,12 +2073,11 @@ int TICALL dusb_cmd_s_eot(CalcHandle *handle) // 0xDD00: end of transmission (recv) int TICALL dusb_cmd_r_eot(CalcHandle *handle) { - DUSBVirtualPacket* pkt; int retval = 0; VALIDATE_HANDLE(handle); - pkt = dusb_vtl_pkt_new_ex(handle, 0, 0, NULL); + DUSBVirtualPacket* pkt = dusb_vtl_pkt_new_ex(handle, 0, 0, nullptr); retval = dusb_recv_data(handle, pkt); @@ -2155,12 +2106,11 @@ int TICALL dusb_cmd_r_eot(CalcHandle *handle) // 0xEE00: error int TICALL dusb_cmd_s_error(CalcHandle *handle, uint16_t code) { - DUSBVirtualPacket* pkt; int retval = 0; VALIDATE_HANDLE(handle); - pkt = dusb_vtl_pkt_new_ex(handle, 2, DUSB_VPKT_ERROR, (uint8_t *)dusb_vtl_pkt_alloc_data(handle, 2)); + DUSBVirtualPacket* pkt = dusb_vtl_pkt_new_ex(handle, 2, DUSB_VPKT_ERROR, (uint8_t*)dusb_vtl_pkt_alloc_data(handle, 2)); pkt->data[0] = MSB(code); pkt->data[1] = LSB(code); @@ -2176,18 +2126,17 @@ int TICALL dusb_cmd_s_error(CalcHandle *handle, uint16_t code) int TICALL dusb_cmd_s_param_set_r_data_ack(CalcHandle *handle, uint16_t id, uint16_t size, const uint8_t * data) { - DUSBCalcParam *param; int retval = 0; VALIDATE_HANDLE(handle); - if (size > 0 && NULL == data) + if (size > 0 && nullptr == data) { return ERR_INVALID_PARAMETER; } - param = dusb_cp_new(handle, id, size); - if (NULL != data) + DUSBCalcParam* param = dusb_cp_new(handle, id, size); + if (nullptr != data) { memcpy(param->data, data, size); } diff --git a/libticalcs/trunk/src/dusb_rpkt.cc b/libticalcs/trunk/src/dusb_rpkt.cc index 30aefe0b6..d9d42c757 100644 --- a/libticalcs/trunk/src/dusb_rpkt.cc +++ b/libticalcs/trunk/src/dusb_rpkt.cc @@ -52,9 +52,7 @@ static const DUSBRawPacketInfo dusbrawpackets[] = const char* TICALL dusb_rpkt_type2name(uint8_t id) { - unsigned int i; - - for (i = 0; i < sizeof(dusbrawpackets) / sizeof(dusbrawpackets[0]); i++) + for (unsigned int i = 0; i < sizeof(dusbrawpackets) / sizeof(dusbrawpackets[0]); i++) { if (id == dusbrawpackets[i].id) { @@ -68,8 +66,6 @@ const char* TICALL dusb_rpkt_type2name(uint8_t id) int TICALL dusb_send(CalcHandle* handle, DUSBRawPacket* pkt) { uint8_t buf[sizeof(pkt->data) + 5]; - uint32_t size; - int ret; CalcEventData event; VALIDATE_HANDLE(handle); @@ -79,12 +75,12 @@ int TICALL dusb_send(CalcHandle* handle, DUSBRawPacket* pkt) ticalcs_event_fill_header(handle, &event, /* type */ CALC_EVENT_TYPE_BEFORE_SEND_DUSB_RPKT, /* retval */ 0, /* operation */ CALC_FNCT_LAST); ticalcs_event_fill_dusb_rpkt(&event, /* size */ pkt->size, /* type */ pkt->type, /* data */ pkt->data); - ret = ticalcs_event_send(handle, &event); + int ret = ticalcs_event_send(handle, &event); if (!ret) { memset(buf, 0, sizeof(buf)); - size = pkt->size; + uint32_t size = pkt->size; if (size > sizeof(pkt->data)) { @@ -105,7 +101,7 @@ int TICALL dusb_send(CalcHandle* handle, DUSBRawPacket* pkt) { if (size >= 128) { - ticables_progress_get(handle->cable, NULL, NULL, &handle->updat->rate); + ticables_progress_get(handle->cable, nullptr, nullptr, &handle->updat->rate); } if (handle->updat->cancel) @@ -127,7 +123,6 @@ int TICALL dusb_send(CalcHandle* handle, DUSBRawPacket* pkt) int TICALL dusb_recv(CalcHandle* handle, DUSBRawPacket* pkt) { uint8_t buf[5]; - int ret; CalcEventData event; VALIDATE_HANDLE(handle); @@ -137,7 +132,7 @@ int TICALL dusb_recv(CalcHandle* handle, DUSBRawPacket* pkt) ticalcs_event_fill_header(handle, &event, /* type */ CALC_EVENT_TYPE_BEFORE_RECV_DUSB_RPKT, /* retval */ 0, /* operation */ CALC_FNCT_LAST); ticalcs_event_fill_dusb_rpkt(&event, /* size */ 0, /* type */ 0, /* data */ pkt->data); - ret = ticalcs_event_send(handle, &event); + int ret = ticalcs_event_send(handle, &event); if (!ret) { @@ -180,7 +175,7 @@ int TICALL dusb_recv(CalcHandle* handle, DUSBRawPacket* pkt) { if (pkt->size >= 128) { - ticables_progress_get(handle->cable, NULL, NULL, &handle->updat->rate); + ticables_progress_get(handle->cable, nullptr, nullptr, &handle->updat->rate); } if (handle->updat->cancel) @@ -220,25 +215,23 @@ static const char* ep_way(uint8_t ep) int TICALL dusb_dissect(CalcModel model, FILE * f, const uint8_t * data, uint32_t len, uint8_t ep, uint8_t * first) { int ret = 0; - uint32_t raw_size; - uint8_t raw_type; VALIDATE_NONNULL(f); VALIDATE_NONNULL(data); VALIDATE_NONNULL(first); - if (len < 5 || len > sizeof(((DUSBRawPacket *)0)->data)) + if (len < 5 || len > sizeof(((DUSBRawPacket *)nullptr)->data)) { ticalcs_critical("Length %lu (%lX) is too small or too large for a valid DUSB raw packet", (unsigned long)len, (unsigned long)len); return ERR_INVALID_PACKET; } - raw_size = (((uint32_t)(data[0])) << 24) | (((uint32_t)(data[1])) << 16) | (((uint32_t)(data[2])) << 8) | ((uint32_t)(data[3])); - raw_type = data[4]; + uint32_t raw_size = (((uint32_t)(data[0])) << 24) | (((uint32_t)(data[1])) << 16) | (((uint32_t)(data[2])) << 8) | ((uint32_t)(data[3])); + const uint8_t raw_type = data[4]; fprintf(f, "%08lX (%02X)\t\t\t\t\t\t\t| %s: %s\n", (unsigned long)raw_size, (unsigned int)raw_type, ep_way(ep), dusb_rpkt_type2name(raw_type)); - if (raw_size > sizeof(((DUSBRawPacket *)0)->data) - 5) + if (raw_size > sizeof(((DUSBRawPacket *)nullptr)->data) - 5) { ticalcs_critical("Raw size %lu (%lX) is too large for a valid DUSB raw packet", (unsigned long)raw_size, (unsigned long)raw_size); return ERR_INVALID_PACKET; @@ -261,7 +254,7 @@ int TICALL dusb_dissect(CalcModel model, FILE * f, const uint8_t * data, uint32_ case DUSB_RPKT_BUF_SIZE_REQ: case DUSB_RPKT_BUF_SIZE_ALLOC: { - uint32_t tmp = (((uint32_t)(data[5])) << 24) | (((uint32_t)(data[6])) << 16) | (((uint32_t)(data[7])) << 8) | ((uint32_t)(data[8])); + const uint32_t tmp = (((uint32_t)(data[5])) << 24) | (((uint32_t)(data[6])) << 16) | (((uint32_t)(data[7])) << 8) | ((uint32_t)(data[8])); fprintf(f, "\t[%08lX]\n", (unsigned long)tmp); if (len != 5U + 4) { @@ -275,8 +268,8 @@ int TICALL dusb_dissect(CalcModel model, FILE * f, const uint8_t * data, uint32_ { if (*first) { - uint32_t vtl_size = (((uint32_t)(data[5])) << 24) | (((uint32_t)(data[6])) << 16) | (((uint32_t)(data[7])) << 8) | ((uint32_t)(data[8])); - uint16_t vtl_type = (((uint16_t)(data[9])) << 8) | ((uint16_t)(data[10])); + const uint32_t vtl_size = (((uint32_t)(data[5])) << 24) | (((uint32_t)(data[6])) << 16) | (((uint32_t)(data[7])) << 8) | ((uint32_t)(data[8])); + const uint16_t vtl_type = (((uint16_t)(data[9])) << 8) | ((uint16_t)(data[10])); fprintf(f, "\t%08lX {%04X}\t\t\t\t\t\t| CMD: %s\n", (unsigned long)vtl_size, vtl_type, dusb_vpkt_type2name(vtl_type)); if (vtl_size != raw_size - 6) @@ -290,7 +283,6 @@ int TICALL dusb_dissect(CalcModel model, FILE * f, const uint8_t * data, uint32_ } else { - uint32_t i; data += 11; len -= 11; if (len < vtl_size) @@ -302,7 +294,7 @@ int TICALL dusb_dissect(CalcModel model, FILE * f, const uint8_t * data, uint32_ fputs("(given length larger than length in packet)\n", f); } fprintf(f, "\t\t"); - for (i = 0; i < len;) + for (uint32_t i = 0; i < len;) { fprintf(f, "%02X ", *data++); if (!(++i & 15)) @@ -321,7 +313,6 @@ int TICALL dusb_dissect(CalcModel model, FILE * f, const uint8_t * data, uint32_ } else { - uint32_t i; fprintf(f, "\t%02X %02X %02X ", data[5], data[6], data[7]); data += 8; len -= 8; @@ -334,7 +325,7 @@ int TICALL dusb_dissect(CalcModel model, FILE * f, const uint8_t * data, uint32_ { fputs("(given length larger than length in packet)\n", f); } - for (i = 0; i < len;) + for (uint32_t i = 0; i < len;) { fprintf(f, "%02X ", *data++); if (!(++i & 15)) @@ -351,7 +342,7 @@ int TICALL dusb_dissect(CalcModel model, FILE * f, const uint8_t * data, uint32_ case DUSB_RPKT_VIRT_DATA_ACK: { - uint16_t tmp = (((uint16_t)(data[5])) << 8) | ((uint16_t)(data[6])); + const uint16_t tmp = (((uint16_t)(data[5])) << 8) | ((uint16_t)(data[6])); fprintf(f, "\t[%04X]\n", tmp); if (len != 5 + 2) { diff --git a/libticalcs/trunk/src/dusb_vpkt.cc b/libticalcs/trunk/src/dusb_vpkt.cc index dab6046b8..054ec4d9e 100644 --- a/libticalcs/trunk/src/dusb_vpkt.cc +++ b/libticalcs/trunk/src/dusb_vpkt.cc @@ -72,14 +72,12 @@ static const DUSBVtlPktInfo vpkt_types[] = { DUSB_VPKT_DELAY_ACK, "Delay Acknowledgment" }, { DUSB_VPKT_EOT, "End of Transmission" }, { DUSB_VPKT_ERROR, "Error" }, - { 0xFFFF, NULL} + { 0xFFFF, nullptr } }; const char* TICALL dusb_vpkt_type2name(uint16_t id) { - const DUSBVtlPktInfo *p; - - for (p = vpkt_types; p->name != NULL; p++) + for (const DUSBVtlPktInfo* p = vpkt_types; p->name != nullptr; p++) { if (p->id == id) { @@ -94,7 +92,7 @@ const char* TICALL dusb_vpkt_type2name(uint16_t id) DUSBVirtualPacket* TICALL dusb_vtl_pkt_new_ex(CalcHandle * handle, uint32_t size, uint16_t type, uint8_t * data) { - DUSBVirtualPacket* vtl = NULL; + DUSBVirtualPacket* vtl = nullptr; // RFS: it's alright if data is nullptr at this stage. @@ -102,7 +100,7 @@ DUSBVirtualPacket* TICALL dusb_vtl_pkt_new_ex(CalcHandle * handle, uint32_t size { vtl = (DUSBVirtualPacket *)g_malloc0(sizeof(DUSBVirtualPacket)); - if (NULL != vtl) + if (nullptr != vtl) { //GList * vtl_pkt_list; @@ -124,12 +122,12 @@ DUSBVirtualPacket* TICALL dusb_vtl_pkt_new_ex(CalcHandle * handle, uint32_t size DUSBVirtualPacket* TICALL dusb_vtl_pkt_new(CalcHandle * handle) { - return dusb_vtl_pkt_new_ex(handle, 0, 0, NULL); + return dusb_vtl_pkt_new_ex(handle, 0, 0, nullptr); } void TICALL dusb_vtl_pkt_fill(DUSBVirtualPacket* vtl, uint32_t size, uint16_t type, uint8_t * data) { - if (vtl != NULL) + if (vtl != nullptr) { vtl->size = size; vtl->type = type; @@ -151,7 +149,7 @@ void TICALL dusb_vtl_pkt_del(CalcHandle * handle, DUSBVirtualPacket* vtl) return; } - if (vtl == NULL) + if (vtl == nullptr) { ticalcs_critical("%s: vtl is NULL", __FUNCTION__); return; @@ -183,7 +181,7 @@ DUSBVirtualPacket * TICALL dusb_vtl_pkt_realloc_data(CalcHandle * handle, DUSBVi return nullptr; } - if (vtl != NULL) + if (vtl != nullptr) { if (size + DUSB_DH_SIZE > size) { @@ -198,7 +196,7 @@ DUSBVirtualPacket * TICALL dusb_vtl_pkt_realloc_data(CalcHandle * handle, DUSBVi } else { - return NULL; + return nullptr; } } @@ -221,7 +219,6 @@ void TICALL dusb_vtl_pkt_free_data(CalcHandle * handle, void * data) int TICALL dusb_send_buf_size_request(CalcHandle* handle, uint32_t size) { DUSBRawPacket raw; - int ret; VALIDATE_HANDLE(handle); @@ -241,7 +238,7 @@ int TICALL dusb_send_buf_size_request(CalcHandle* handle, uint32_t size) raw.data[2] = (size >> 8) & 0xFF; raw.data[3] = (size ) & 0xFF; - ret = dusb_send(handle, &raw); + const int ret = dusb_send(handle, &raw); if (!ret) { ticalcs_info(" PC->TI: Buffer Size Request (%i bytes)", size); @@ -253,7 +250,6 @@ int TICALL dusb_send_buf_size_request(CalcHandle* handle, uint32_t size) int TICALL dusb_recv_buf_size_alloc(CalcHandle* handle, uint32_t *size) { DUSBRawPacket raw; - uint32_t tmp; int ret = 0; VALIDATE_HANDLE(handle); @@ -277,7 +273,8 @@ int TICALL dusb_recv_buf_size_alloc(CalcHandle* handle, uint32_t *size) break; } - tmp = (((uint32_t)raw.data[0]) << 24) | (((uint32_t)raw.data[1]) << 16) | (((uint32_t)raw.data[2]) << 8) | (((uint32_t)raw.data[3]) << 0); + uint32_t tmp = (((uint32_t)raw.data[0]) << 24) | (((uint32_t)raw.data[1]) << 16) | (((uint32_t)raw.data[2]) << 8) | (((uint32_t)raw.data[3]) + << 0); if (tmp > sizeof(raw.data)) { ticalcs_critical("Clamping overly large buffer size allocation to %u bytes", (unsigned int)sizeof(raw.data)); @@ -304,7 +301,6 @@ int TICALL dusb_recv_buf_size_alloc(CalcHandle* handle, uint32_t *size) int TICALL dusb_recv_buf_size_request(CalcHandle* handle, uint32_t *size) { DUSBRawPacket raw; - uint32_t tmp; int ret = 0; VALIDATE_HANDLE(handle); @@ -326,7 +322,8 @@ int TICALL dusb_recv_buf_size_request(CalcHandle* handle, uint32_t *size) ret = ERR_INVALID_PACKET; } - tmp = (((uint32_t)raw.data[0]) << 24) | (((uint32_t)raw.data[1]) << 16) | (((uint32_t)raw.data[2]) << 8) | (((uint32_t)raw.data[3]) << 0); + const uint32_t tmp = (((uint32_t)raw.data[0]) << 24) | (((uint32_t)raw.data[1]) << 16) | (((uint32_t)raw.data[2]) << 8) | (((uint32_t)raw.data[3]) + << 0); if (size) { *size = tmp; @@ -340,7 +337,6 @@ int TICALL dusb_recv_buf_size_request(CalcHandle* handle, uint32_t *size) int TICALL dusb_send_buf_size_alloc(CalcHandle* handle, uint32_t size) { DUSBRawPacket raw; - int ret; VALIDATE_HANDLE(handle); @@ -360,7 +356,7 @@ int TICALL dusb_send_buf_size_alloc(CalcHandle* handle, uint32_t size) raw.data[2] = (size >> 8) & 0xFF; raw.data[3] = (size ) & 0xFF; - ret = dusb_send(handle, &raw); + const int ret = dusb_send(handle, &raw); if (!ret) { ticalcs_info(" PC->TI: Buffer Size Allocation (%i bytes)", size); @@ -399,7 +395,6 @@ int TICALL dusb_set_buf_size(CalcHandle* handle, uint32_t size) int TICALL dusb_send_acknowledge(CalcHandle* handle) { DUSBRawPacket raw; - int ret; VALIDATE_HANDLE(handle); @@ -411,7 +406,7 @@ int TICALL dusb_send_acknowledge(CalcHandle* handle) raw.data[0] = 0xE0; raw.data[1] = 0x00; - ret = dusb_send(handle, &raw); + const int ret = dusb_send(handle, &raw); if (!ret) { #if (VPKT_DBG == 2) @@ -452,15 +447,14 @@ int TICALL dusb_recv_acknowledge(CalcHandle *handle) if (raw.type == DUSB_RPKT_BUF_SIZE_REQ) { - uint32_t size; - if (raw.size != 4) { ret = ERR_INVALID_PACKET; break; } - size = (((uint32_t)raw.data[0]) << 24) | (((uint32_t)raw.data[1]) << 16) | (((uint32_t)raw.data[2]) << 8) | (((uint32_t)raw.data[3]) << 0); + const uint32_t size = (((uint32_t)raw.data[0]) << 24) | (((uint32_t)raw.data[1]) << 16) | (((uint32_t)raw.data[2]) << 8) | (((uint32_t)raw.data[3]) + << 0); ticalcs_info(" TI->PC: Buffer Size Request (%i bytes)", size); ret = dusb_send_buf_size_alloc(handle, size); @@ -539,8 +533,7 @@ static void workaround_send(CalcHandle *handle, DUSBRawPacket *raw, DUSBVirtualP int TICALL dusb_send_data(CalcHandle *handle, DUSBVirtualPacket *vtl) { DUSBRawPacket raw; - int i, r, q; - long offset; + int r, q; int ret = 0; CalcEventData event; @@ -610,7 +603,7 @@ int TICALL dusb_send_data(CalcHandle *handle, DUSBVirtualPacket *vtl) raw.data[4] = MSB(vtl->type); raw.data[5] = LSB(vtl->type); memcpy(&raw.data[DUSB_DH_SIZE], vtl->data, handle->priv.dusb_rpkt_maxlen - DUSB_DH_SIZE); - offset = handle->priv.dusb_rpkt_maxlen - DUSB_DH_SIZE; + long offset = handle->priv.dusb_rpkt_maxlen - DUSB_DH_SIZE; ret = dusb_send(handle, &raw); if (ret) @@ -633,7 +626,7 @@ int TICALL dusb_send_data(CalcHandle *handle, DUSBVirtualPacket *vtl) r = (vtl->size - offset) % handle->priv.dusb_rpkt_maxlen; // send full chunks (no header) - for (i = 1; i <= q; i++) + for (int i = 1; i <= q; i++) { raw.size = handle->priv.dusb_rpkt_maxlen; raw.type = (i != q || r != 0) ? DUSB_RPKT_VIRT_DATA : DUSB_RPKT_VIRT_DATA_LAST; @@ -757,7 +750,7 @@ int TICALL dusb_recv_data_varsize(CalcHandle* handle, DUSBVirtualPacket* vtl, ui SET_HANDLE_BUSY_IF_NECESSARY(handle); ticalcs_event_fill_header(handle, &event, /* type */ CALC_EVENT_TYPE_BEFORE_RECV_DUSB_VPKT, /* retval */ 0, /* operation */ CALC_FNCT_LAST); - ticalcs_event_fill_dusb_vpkt(&event, /* size */ 0, /* type */ 0, /* data */ NULL); + ticalcs_event_fill_dusb_vpkt(&event, /* size */ 0, /* type */ 0, /* data */ nullptr); ret = ticalcs_event_send(handle, &event); if (!ret) @@ -804,7 +797,7 @@ int TICALL dusb_recv_data_varsize(CalcHandle* handle, DUSBVirtualPacket* vtl, ui vtl->type = (((uint16_t)raw.data[4]) << 8) | (raw.data[5] << 0); vtl->data = (uint8_t *)g_realloc(vtl->data, alloc_size); - if (vtl->data != NULL) + if (vtl->data != nullptr) { memcpy(vtl->data, &raw.data[DUSB_DH_SIZE], raw.size - DUSB_DH_SIZE); } @@ -816,7 +809,7 @@ int TICALL dusb_recv_data_varsize(CalcHandle* handle, DUSBVirtualPacket* vtl, ui #elif (VPKT_DBG == 1) ticalcs_info(" TI->PC: %s", dusb_vpkt_type2name(vtl->type)); #endif - if (vtl->data != NULL && vtl->type == 0xEE00) + if (vtl->data != nullptr && vtl->type == 0xEE00) { ticalcs_info(" Error Code : %04x\n", (((int)vtl->data[0]) << 8) | vtl->data[1]); } @@ -885,14 +878,13 @@ int TICALL dusb_recv_data_varsize(CalcHandle* handle, DUSBVirtualPacket* vtl, ui int TICALL dusb_recv_data(CalcHandle* handle, DUSBVirtualPacket* vtl) { uint32_t declared_size; - int ret; VALIDATE_HANDLE(handle); VALIDATE_NONNULL(vtl); // dusb_recv_data_varsize() takes care of handle->busy. - ret = dusb_recv_data_varsize(handle, vtl, &declared_size, 0); + int ret = dusb_recv_data_varsize(handle, vtl, &declared_size, 0); // TODO MAYBE reimplement the following block as a temporary event hook ? if (!ret) { diff --git a/libticalcs/trunk/src/error.cc b/libticalcs/trunk/src/error.cc index fa200e6dd..13ee9b469 100644 --- a/libticalcs/trunk/src/error.cc +++ b/libticalcs/trunk/src/error.cc @@ -59,7 +59,7 @@ int TICALL ticalcs_error_get(int number, char **message) //dusb_cpca_purge(); //nsp_vtl_pkt_purge(); - if (message == NULL) + if (message == nullptr) { ticalcs_critical("ticalcs_error_get(NULL)\n"); return number; @@ -494,7 +494,7 @@ int TICALL ticalcs_error_get(int number, char **message) **/ int TICALL ticalcs_error_free(char *message) { - if (message == NULL) + if (message == nullptr) { ticalcs_critical("ticalcs_error_free(NULL)\n"); return ERR_INVALID_PARAMETER; diff --git a/libticalcs/trunk/src/internal.h b/libticalcs/trunk/src/internal.h index 06dab2949..2fcd9332d 100644 --- a/libticalcs/trunk/src/internal.h +++ b/libticalcs/trunk/src/internal.h @@ -199,47 +199,47 @@ static inline int ticalcs_validate_handle(CalcHandle * handle) { - return handle != NULL; + return handle != nullptr; } static inline int ticalcs_validate_calcfncts(const CalcFncts * calc) { - return calc != NULL; + return calc != nullptr; } static inline int ticalcs_validate_backupcontent(BackupContent * content) { - return content != NULL; + return content != nullptr; } static inline int ticalcs_validate_filecontent(FileContent * content) { - return content != NULL; + return content != nullptr; } static inline int ticalcs_validate_filecontent_entries(FileContent * content) { - return content->num_entries == 0 || content->entries != NULL; + return content->num_entries == 0 || content->entries != nullptr; } static inline int ticalcs_validate_flashcontent(FlashContent * content) { - return content != NULL; + return content != nullptr; } static inline int ticalcs_validate_varentry(VarEntry * var) { - return var != NULL; + return var != nullptr; } static inline int ticalcs_validate_varrequest(VarRequest * var) { - return var != NULL; + return var != nullptr; } static inline int ticalcs_validate_calcupdate(CalcUpdate * upd) { - return upd != NULL && upd->start != NULL && upd->stop != NULL && upd->refresh != NULL && upd->label != NULL && upd->pbar != NULL; + return upd != nullptr && upd->start != nullptr && upd->stop != nullptr && upd->refresh != nullptr && upd->label != nullptr && upd->pbar != nullptr; } static inline void * ticalcs_alloc_screen(size_t len) @@ -256,11 +256,11 @@ static inline int dirlist_init_tree(CalcHandle * handle, GNode ** tree, const ch { int ret = ERR_MALLOC; - (*tree) = g_node_new(NULL); - if (*tree != NULL) + (*tree) = g_node_new(nullptr); + if (*tree != nullptr) { TreeInfo *ti = (TreeInfo *)g_malloc(sizeof(TreeInfo)); - if (ti != NULL) + if (ti != nullptr) { ti->model = handle->model; ti->type = type; @@ -287,7 +287,7 @@ static inline int dirlist_init_trees(CalcHandle * handle, GNode ** vars, GNode * static inline GNode * dirlist_create_append_node(void * data, GNode ** tree) { GNode * node = g_node_new(data); - if (node != NULL) + if (node != nullptr) { g_node_append(*tree, node); } diff --git a/libticalcs/trunk/src/nsp_cmd.cc b/libticalcs/trunk/src/nsp_cmd.cc index dede12bb5..bac67bd4b 100644 --- a/libticalcs/trunk/src/nsp_cmd.cc +++ b/libticalcs/trunk/src/nsp_cmd.cc @@ -43,9 +43,7 @@ static const uint8_t usb_errors[] = { static int err_code(uint8_t code) { - int i; - - for (i = 0; i < (int)(sizeof(usb_errors) / sizeof(usb_errors[0])); i++) + for (int i = 0; i < (int)(sizeof(usb_errors) / sizeof(usb_errors[0])); i++) { if (usb_errors[i] == code) { @@ -63,7 +61,7 @@ static int err_code(uint8_t code) static int put_str(uint8_t *dst, const char *src) { size_t i, j; - size_t len = strlen(src); + const size_t len = strlen(src); for (i = 0; i < len; i++) { @@ -90,12 +88,11 @@ static int put_str(uint8_t *dst, const char *src) int TICALL nsp_cmd_r_login(CalcHandle *handle) { - NSPVirtualPacket* pkt; int retval = 0; VALIDATE_HANDLE(handle); - pkt = nsp_vtl_pkt_new(handle); + NSPVirtualPacket* pkt = nsp_vtl_pkt_new(handle); ticalcs_info(" receiving login:"); @@ -110,12 +107,12 @@ int TICALL nsp_cmd_r_login(CalcHandle *handle) int TICALL nsp_cmd_s_status(CalcHandle *handle, uint8_t status) { - NSPVirtualPacket* pkt; int retval = 0; VALIDATE_HANDLE(handle); - pkt = nsp_vtl_pkt_new_ex(handle, 1, NSP_SRC_ADDR, handle->priv.nsp_src_port, NSP_DEV_ADDR, handle->priv.nsp_dst_port, NSP_CMD_STATUS, (uint8_t *)nsp_vtl_pkt_alloc_data(handle, 1)); + NSPVirtualPacket* pkt = nsp_vtl_pkt_new_ex(handle, 1, NSP_SRC_ADDR, handle->priv.nsp_src_port, NSP_DEV_ADDR, handle->priv.nsp_dst_port, + NSP_CMD_STATUS, (uint8_t*)nsp_vtl_pkt_alloc_data(handle, 1)); ticalcs_info(" sending status (%04x):", status); @@ -129,20 +126,18 @@ int TICALL nsp_cmd_s_status(CalcHandle *handle, uint8_t status) int TICALL nsp_cmd_r_status(CalcHandle *handle, uint8_t *status) { - NSPVirtualPacket* pkt; - uint8_t value; int retval = 0; VALIDATE_HANDLE(handle); - pkt = nsp_vtl_pkt_new(handle); + NSPVirtualPacket* pkt = nsp_vtl_pkt_new(handle); ticalcs_info(" receiving status:"); retval = nsp_recv_data(handle, pkt); if (!retval) { - value = pkt->data[0]; + const uint8_t value = pkt->data[0]; if (pkt->cmd != NSP_CMD_STATUS) { @@ -171,14 +166,14 @@ int TICALL nsp_cmd_r_status(CalcHandle *handle, uint8_t *status) int TICALL nsp_cmd_s_dev_infos(CalcHandle *handle, uint8_t cmd) { - NSPVirtualPacket* pkt; int retval = 0; VALIDATE_HANDLE(handle); ticalcs_info(" requesting device information (cmd = %02x):", cmd); - pkt = nsp_vtl_pkt_new_ex(handle, 0, NSP_SRC_ADDR, handle->priv.nsp_src_port, NSP_DEV_ADDR, NSP_PORT_DEV_INFOS, cmd, (uint8_t *)nsp_vtl_pkt_alloc_data(handle, 0)); + NSPVirtualPacket* pkt = nsp_vtl_pkt_new_ex(handle, 0, NSP_SRC_ADDR, handle->priv.nsp_src_port, NSP_DEV_ADDR, NSP_PORT_DEV_INFOS, cmd, + (uint8_t*)nsp_vtl_pkt_alloc_data(handle, 0)); retval = nsp_send_data(handle, pkt); @@ -189,7 +184,6 @@ int TICALL nsp_cmd_s_dev_infos(CalcHandle *handle, uint8_t cmd) int TICALL nsp_cmd_r_dev_infos(CalcHandle *handle, uint8_t *cmd, uint32_t *size, uint8_t **data) { - NSPVirtualPacket* pkt; int retval = 0; VALIDATE_HANDLE(handle); @@ -197,7 +191,7 @@ int TICALL nsp_cmd_r_dev_infos(CalcHandle *handle, uint8_t *cmd, uint32_t *size, VALIDATE_NONNULL(size); VALIDATE_NONNULL(data); - pkt = nsp_vtl_pkt_new(handle); + NSPVirtualPacket* pkt = nsp_vtl_pkt_new(handle); ticalcs_info(" receiving device information:"); @@ -207,7 +201,7 @@ int TICALL nsp_cmd_r_dev_infos(CalcHandle *handle, uint8_t *cmd, uint32_t *size, *cmd = pkt->cmd; *data = (uint8_t *)g_malloc0(pkt->size); *size = pkt->size; - if (NULL != *data) + if (nullptr != *data) { memcpy(*data, pkt->data, pkt->size); } @@ -226,12 +220,12 @@ int TICALL nsp_cmd_r_dev_infos(CalcHandle *handle, uint8_t *cmd, uint32_t *size, int TICALL nsp_cmd_s_screen_rle(CalcHandle *handle, uint8_t cmd) { - NSPVirtualPacket* pkt; int retval = 0; VALIDATE_HANDLE(handle); - pkt = nsp_vtl_pkt_new_ex(handle, 0, NSP_SRC_ADDR, handle->priv.nsp_src_port, NSP_DEV_ADDR, NSP_PORT_SCREEN_RLE, cmd, (uint8_t *)nsp_vtl_pkt_alloc_data(handle, 0)); + NSPVirtualPacket* pkt = nsp_vtl_pkt_new_ex(handle, 0, NSP_SRC_ADDR, handle->priv.nsp_src_port, NSP_DEV_ADDR, NSP_PORT_SCREEN_RLE, cmd, + (uint8_t*)nsp_vtl_pkt_alloc_data(handle, 0)); ticalcs_info(" requesting RLE screenshot (cmd = %02x):", cmd); @@ -244,7 +238,6 @@ int TICALL nsp_cmd_s_screen_rle(CalcHandle *handle, uint8_t cmd) int TICALL nsp_cmd_r_screen_rle(CalcHandle *handle, uint8_t *cmd, uint32_t *size, uint8_t **data) { - NSPVirtualPacket* pkt; int retval = 0; VALIDATE_HANDLE(handle); @@ -252,7 +245,7 @@ int TICALL nsp_cmd_r_screen_rle(CalcHandle *handle, uint8_t *cmd, uint32_t *size VALIDATE_NONNULL(size); VALIDATE_NONNULL(data); - pkt = nsp_vtl_pkt_new(handle); + NSPVirtualPacket* pkt = nsp_vtl_pkt_new(handle); ticalcs_info(" receiving RLE screenshot:"); @@ -263,7 +256,7 @@ int TICALL nsp_cmd_r_screen_rle(CalcHandle *handle, uint8_t *cmd, uint32_t *size *cmd = pkt->cmd; *size = pkt->size; *data = (uint8_t *)g_malloc0(pkt->size); - if (NULL != *data) + if (nullptr != *data) { memcpy(*data, pkt->data, pkt->size); } @@ -282,15 +275,14 @@ int TICALL nsp_cmd_r_screen_rle(CalcHandle *handle, uint8_t *cmd, uint32_t *size int TICALL nsp_cmd_s_dir_attributes(CalcHandle *handle, const char *name) { - NSPVirtualPacket* pkt; - size_t len; int retval = 0; VALIDATE_HANDLE(handle); VALIDATE_NONNULL(name); - len = strlen(name) < 8 ? 8 : strlen(name); - pkt = nsp_vtl_pkt_new_ex(handle, 1 + len + 1, NSP_SRC_ADDR, handle->priv.nsp_src_port, NSP_DEV_ADDR, NSP_PORT_FILE_MGMT, NSP_CMD_FM_ATTRIBUTES, (uint8_t *)nsp_vtl_pkt_alloc_data(handle, 1 + len + 1)); + const size_t len = strlen(name) < 8 ? 8 : strlen(name); + NSPVirtualPacket* pkt = nsp_vtl_pkt_new_ex(handle, 1 + len + 1, NSP_SRC_ADDR, handle->priv.nsp_src_port, NSP_DEV_ADDR, NSP_PORT_FILE_MGMT, + NSP_CMD_FM_ATTRIBUTES, (uint8_t*)nsp_vtl_pkt_alloc_data(handle, 1 + len + 1)); ticalcs_info(" unknown directory list command in <%s>:", name); @@ -306,12 +298,11 @@ int TICALL nsp_cmd_s_dir_attributes(CalcHandle *handle, const char *name) int TICALL nsp_cmd_r_dir_attributes(CalcHandle *handle, uint32_t *size, uint8_t *type, uint32_t *date) { - NSPVirtualPacket* pkt; int retval = 0; VALIDATE_HANDLE(handle); - pkt = nsp_vtl_pkt_new(handle); + NSPVirtualPacket* pkt = nsp_vtl_pkt_new(handle); ticalcs_info(" unknown directory list command reply received:"); @@ -352,16 +343,15 @@ int TICALL nsp_cmd_r_dir_attributes(CalcHandle *handle, uint32_t *size, uint8_t int TICALL nsp_cmd_s_dir_enum_init(CalcHandle *handle, const char *name) { - NSPVirtualPacket* pkt; - size_t len; int retval = 0; VALIDATE_HANDLE(handle); VALIDATE_NONNULL(name); - len = strlen(name) < 8 ? 8 : strlen(name); + const size_t len = strlen(name) < 8 ? 8 : strlen(name); - pkt = nsp_vtl_pkt_new_ex(handle, len + 1, NSP_SRC_ADDR, handle->priv.nsp_src_port, NSP_DEV_ADDR, NSP_PORT_FILE_MGMT, NSP_CMD_FM_DIRLIST_INIT, (uint8_t *)nsp_vtl_pkt_alloc_data(handle, len + 1)); + NSPVirtualPacket* pkt = nsp_vtl_pkt_new_ex(handle, len + 1, NSP_SRC_ADDR, handle->priv.nsp_src_port, NSP_DEV_ADDR, NSP_PORT_FILE_MGMT, + NSP_CMD_FM_DIRLIST_INIT, (uint8_t*)nsp_vtl_pkt_alloc_data(handle, len + 1)); ticalcs_info(" initiating directory listing in <%s>:", name); @@ -376,18 +366,18 @@ int TICALL nsp_cmd_s_dir_enum_init(CalcHandle *handle, const char *name) int TICALL nsp_cmd_r_dir_enum_init(CalcHandle *handle) { - return nsp_cmd_r_status(handle, NULL); + return nsp_cmd_r_status(handle, nullptr); } int TICALL nsp_cmd_s_dir_enum_next(CalcHandle *handle) { - NSPVirtualPacket* pkt; int retval = 0; VALIDATE_HANDLE(handle); - pkt = nsp_vtl_pkt_new_ex(handle, 0, NSP_SRC_ADDR, handle->priv.nsp_src_port, NSP_DEV_ADDR, NSP_PORT_FILE_MGMT, NSP_CMD_FM_DIRLIST_NEXT, (uint8_t *)nsp_vtl_pkt_alloc_data(handle, 0)); - if (pkt != NULL) + NSPVirtualPacket* pkt = nsp_vtl_pkt_new_ex(handle, 0, NSP_SRC_ADDR, handle->priv.nsp_src_port, NSP_DEV_ADDR, NSP_PORT_FILE_MGMT, + NSP_CMD_FM_DIRLIST_NEXT, (uint8_t*)nsp_vtl_pkt_alloc_data(handle, 0)); + if (pkt != nullptr) { ticalcs_info(" requesting next directory entry:"); @@ -405,16 +395,13 @@ int TICALL nsp_cmd_s_dir_enum_next(CalcHandle *handle) int TICALL nsp_cmd_r_dir_enum_next(CalcHandle *handle, char* name, uint32_t *size, uint8_t *type) { - NSPVirtualPacket* pkt; - uint8_t data_size; //uint32_t date; - int o; int retval = 0; VALIDATE_HANDLE(handle); VALIDATE_NONNULL(name); - pkt = nsp_vtl_pkt_new(handle); + NSPVirtualPacket* pkt = nsp_vtl_pkt_new(handle); ticalcs_info(" next directory entry:"); @@ -435,9 +422,9 @@ int TICALL nsp_cmd_r_dir_enum_next(CalcHandle *handle, char* name, uint32_t *siz } } - data_size = pkt->data[1] + 2; + const uint8_t data_size = pkt->data[1] + 2; ticalcs_strlcpy(name, (char *)pkt->data + 2, data_size + 1); - o = data_size - 10; + const int o = data_size - 10; if (size) { @@ -460,12 +447,12 @@ int TICALL nsp_cmd_r_dir_enum_next(CalcHandle *handle, char* name, uint32_t *siz int TICALL nsp_cmd_s_dir_enum_done(CalcHandle *handle) { - NSPVirtualPacket* pkt; int retval = 0; VALIDATE_HANDLE(handle); - pkt = nsp_vtl_pkt_new_ex(handle, 0, NSP_SRC_ADDR, handle->priv.nsp_src_port, NSP_DEV_ADDR, NSP_PORT_FILE_MGMT, NSP_CMD_FM_DIRLIST_DONE, (uint8_t *)nsp_vtl_pkt_alloc_data(handle, 0)); + NSPVirtualPacket* pkt = nsp_vtl_pkt_new_ex(handle, 0, NSP_SRC_ADDR, handle->priv.nsp_src_port, NSP_DEV_ADDR, NSP_PORT_FILE_MGMT, + NSP_CMD_FM_DIRLIST_DONE, (uint8_t*)nsp_vtl_pkt_alloc_data(handle, 0)); ticalcs_info(" closing directory listing:"); @@ -478,28 +465,26 @@ int TICALL nsp_cmd_s_dir_enum_done(CalcHandle *handle) int TICALL nsp_cmd_r_dir_enum_done(CalcHandle *handle) { - return nsp_cmd_r_status(handle, NULL); + return nsp_cmd_r_status(handle, nullptr); } /////////////---------------- int TICALL nsp_cmd_s_put_file(CalcHandle *handle, const char *name, uint32_t size) { - NSPVirtualPacket* pkt; - int o; - size_t len; int retval = 0; VALIDATE_HANDLE(handle); VALIDATE_NONNULL(name); - len = strlen(name) < 8 ? 8 : strlen(name); - pkt = nsp_vtl_pkt_new_ex(handle, 6 + len, NSP_SRC_ADDR, handle->priv.nsp_src_port, NSP_DEV_ADDR, NSP_PORT_FILE_MGMT, NSP_CMD_FM_PUT_FILE, (uint8_t *)nsp_vtl_pkt_alloc_data(handle, 6 + len)); + const size_t len = strlen(name) < 8 ? 8 : strlen(name); + NSPVirtualPacket* pkt = nsp_vtl_pkt_new_ex(handle, 6 + len, NSP_SRC_ADDR, handle->priv.nsp_src_port, NSP_DEV_ADDR, NSP_PORT_FILE_MGMT, + NSP_CMD_FM_PUT_FILE, (uint8_t*)nsp_vtl_pkt_alloc_data(handle, 6 + len)); ticalcs_info(" sending variable:"); pkt->data[0] = 0x01; - o = put_str(pkt->data + 1, name); + int o = put_str(pkt->data + 1, name); o++; pkt->data[o+0] = MSB(MSW(size)); @@ -521,12 +506,12 @@ int TICALL nsp_cmd_r_put_file(CalcHandle *handle) int TICALL nsp_cmd_s_put_file_eot(CalcHandle *handle) { - NSPVirtualPacket* pkt; int retval = 0; VALIDATE_HANDLE(handle); - pkt = nsp_vtl_pkt_new_ex(handle, 2, NSP_SRC_ADDR, handle->priv.nsp_src_port, NSP_DEV_ADDR, NSP_PORT_FILE_MGMT, NSP_CMD_FM_PUT_FILE_EOT, (uint8_t *)nsp_vtl_pkt_alloc_data(handle, 2)); + NSPVirtualPacket* pkt = nsp_vtl_pkt_new_ex(handle, 2, NSP_SRC_ADDR, handle->priv.nsp_src_port, NSP_DEV_ADDR, NSP_PORT_FILE_MGMT, + NSP_CMD_FM_PUT_FILE_EOT, (uint8_t*)nsp_vtl_pkt_alloc_data(handle, 2)); ticalcs_info(" sending EOT:"); @@ -543,18 +528,17 @@ int TICALL nsp_cmd_s_put_file_eot(CalcHandle *handle) int TICALL nsp_cmd_s_get_file(CalcHandle *handle, const char *name) { - NSPVirtualPacket* pkt; - size_t len; int retval = 0; VALIDATE_HANDLE(handle); VALIDATE_NONNULL(name); - len = strlen(name) < 8 ? 8 : strlen(name); + const size_t len = strlen(name) < 8 ? 8 : strlen(name); ticalcs_info(" requesting variable:"); - pkt = nsp_vtl_pkt_new_ex(handle, 2 + len, NSP_SRC_ADDR, handle->priv.nsp_src_port, NSP_DEV_ADDR, NSP_PORT_FILE_MGMT, NSP_CMD_FM_GET_FILE, (uint8_t *)nsp_vtl_pkt_alloc_data(handle, 2 + len)); + NSPVirtualPacket* pkt = nsp_vtl_pkt_new_ex(handle, 2 + len, NSP_SRC_ADDR, handle->priv.nsp_src_port, NSP_DEV_ADDR, NSP_PORT_FILE_MGMT, + NSP_CMD_FM_GET_FILE, (uint8_t*)nsp_vtl_pkt_alloc_data(handle, 2 + len)); pkt->data[0] = 0x01; put_str(pkt->data + 1, name); @@ -567,12 +551,11 @@ int TICALL nsp_cmd_s_get_file(CalcHandle *handle, const char *name) int TICALL nsp_cmd_r_get_file(CalcHandle *handle, uint32_t *size) { - NSPVirtualPacket* pkt; int retval = 0; VALIDATE_HANDLE(handle); - pkt = nsp_vtl_pkt_new(handle); + NSPVirtualPacket* pkt = nsp_vtl_pkt_new(handle); ticalcs_info(" file size:"); @@ -604,15 +587,14 @@ int TICALL nsp_cmd_r_get_file(CalcHandle *handle, uint32_t *size) int TICALL nsp_cmd_s_del_file(CalcHandle *handle, const char *name) { - NSPVirtualPacket* pkt; - size_t len; int retval = 0; VALIDATE_HANDLE(handle); VALIDATE_NONNULL(name); - len = strlen(name) < 8 ? 8 : strlen(name); - pkt = nsp_vtl_pkt_new_ex(handle, 2 + len, NSP_SRC_ADDR, handle->priv.nsp_src_port, NSP_DEV_ADDR, NSP_PORT_FILE_MGMT, NSP_CMD_FM_DEL_FILE, (uint8_t *)nsp_vtl_pkt_alloc_data(handle, 2 + len)); + const size_t len = strlen(name) < 8 ? 8 : strlen(name); + NSPVirtualPacket* pkt = nsp_vtl_pkt_new_ex(handle, 2 + len, NSP_SRC_ADDR, handle->priv.nsp_src_port, NSP_DEV_ADDR, NSP_PORT_FILE_MGMT, + NSP_CMD_FM_DEL_FILE, (uint8_t*)nsp_vtl_pkt_alloc_data(handle, 2 + len)); ticalcs_info(" deleting variable:"); @@ -628,21 +610,20 @@ int TICALL nsp_cmd_s_del_file(CalcHandle *handle, const char *name) int TICALL nsp_cmd_r_del_file(CalcHandle *handle) { - return nsp_cmd_r_status(handle, NULL); + return nsp_cmd_r_status(handle, nullptr); } int TICALL nsp_cmd_s_new_folder(CalcHandle *handle, const char *name) { - NSPVirtualPacket* pkt; - size_t len; int retval = 0; VALIDATE_HANDLE(handle); VALIDATE_NONNULL(name); - len = strlen(name) < 8 ? 8 : strlen(name); + const size_t len = strlen(name) < 8 ? 8 : strlen(name); - pkt = nsp_vtl_pkt_new_ex(handle, 2 + len, NSP_SRC_ADDR, handle->priv.nsp_src_port, NSP_DEV_ADDR, NSP_PORT_FILE_MGMT, NSP_CMD_FM_NEW_FOLDER, (uint8_t *)nsp_vtl_pkt_alloc_data(handle, 2 + len)); + NSPVirtualPacket* pkt = nsp_vtl_pkt_new_ex(handle, 2 + len, NSP_SRC_ADDR, handle->priv.nsp_src_port, NSP_DEV_ADDR, NSP_PORT_FILE_MGMT, + NSP_CMD_FM_NEW_FOLDER, (uint8_t*)nsp_vtl_pkt_alloc_data(handle, 2 + len)); ticalcs_info(" creating folder:"); @@ -658,21 +639,20 @@ int TICALL nsp_cmd_s_new_folder(CalcHandle *handle, const char *name) int TICALL nsp_cmd_r_new_folder(CalcHandle *handle) { - return nsp_cmd_r_status(handle, NULL); + return nsp_cmd_r_status(handle, nullptr); } int TICALL nsp_cmd_s_del_folder(CalcHandle *handle, const char *name) { - NSPVirtualPacket* pkt; - size_t len; int retval = 0; VALIDATE_HANDLE(handle); VALIDATE_NONNULL(name); - len = strlen(name) < 8 ? 8 : strlen(name); + const size_t len = strlen(name) < 8 ? 8 : strlen(name); - pkt = nsp_vtl_pkt_new_ex(handle, 2 + len, NSP_SRC_ADDR, handle->priv.nsp_src_port, NSP_DEV_ADDR, NSP_PORT_FILE_MGMT, NSP_CMD_FM_DEL_FOLDER, (uint8_t *)nsp_vtl_pkt_alloc_data(handle, 2 + len)); + NSPVirtualPacket* pkt = nsp_vtl_pkt_new_ex(handle, 2 + len, NSP_SRC_ADDR, handle->priv.nsp_src_port, NSP_DEV_ADDR, NSP_PORT_FILE_MGMT, + NSP_CMD_FM_DEL_FOLDER, (uint8_t*)nsp_vtl_pkt_alloc_data(handle, 2 + len)); ticalcs_info(" deleting folder:"); @@ -688,24 +668,22 @@ int TICALL nsp_cmd_s_del_folder(CalcHandle *handle, const char *name) int TICALL nsp_cmd_r_del_folder(CalcHandle *handle) { - return nsp_cmd_r_status(handle, NULL); + return nsp_cmd_r_status(handle, nullptr); } int TICALL nsp_cmd_s_copy_file(CalcHandle *handle, const char *name, const char *name2) { - NSPVirtualPacket* pkt; - size_t len; - size_t len2; int retval = 0; VALIDATE_HANDLE(handle); VALIDATE_NONNULL(name); VALIDATE_NONNULL(name2); - len = strlen(name) < 8 ? 8 : strlen(name); - len2 = strlen(name2) < 8 ? 8 : strlen(name2); + const size_t len = strlen(name) < 8 ? 8 : strlen(name); + const size_t len2 = strlen(name2) < 8 ? 8 : strlen(name2); - pkt = nsp_vtl_pkt_new_ex(handle, 3 + len + len2, NSP_SRC_ADDR, handle->priv.nsp_src_port, NSP_DEV_ADDR, NSP_PORT_FILE_MGMT, NSP_CMD_FM_COPY_FILE, (uint8_t *)nsp_vtl_pkt_alloc_data(handle, 3 + len + len2)); + NSPVirtualPacket* pkt = nsp_vtl_pkt_new_ex(handle, 3 + len + len2, NSP_SRC_ADDR, handle->priv.nsp_src_port, NSP_DEV_ADDR, NSP_PORT_FILE_MGMT, + NSP_CMD_FM_COPY_FILE, (uint8_t*)nsp_vtl_pkt_alloc_data(handle, 3 + len + len2)); ticalcs_info(" copying file:"); @@ -722,26 +700,24 @@ int TICALL nsp_cmd_s_copy_file(CalcHandle *handle, const char *name, const char int TICALL nsp_cmd_r_copy_file(CalcHandle *handle) { - return nsp_cmd_r_status(handle, NULL); + return nsp_cmd_r_status(handle, nullptr); } int TICALL nsp_cmd_s_rename_file(CalcHandle *handle, const char *name, const char *name2) { - NSPVirtualPacket* pkt; - size_t len; - size_t len2; int retval = 0; VALIDATE_HANDLE(handle); VALIDATE_NONNULL(name); VALIDATE_NONNULL(name2); - len = strlen(name) < 8 ? 8 : strlen(name); - len2 = strlen(name2) < 8 ? 8 : strlen(name2); + const size_t len = strlen(name) < 8 ? 8 : strlen(name); + const size_t len2 = strlen(name2) < 8 ? 8 : strlen(name2); ticalcs_info(" renaming file:"); - pkt = nsp_vtl_pkt_new_ex(handle, 3 + len + len2, NSP_SRC_ADDR, handle->priv.nsp_src_port, NSP_DEV_ADDR, NSP_PORT_FILE_MGMT, NSP_CMD_FM_RENAME_FILE, (uint8_t *)nsp_vtl_pkt_alloc_data(handle, 3 + len + len2)); + NSPVirtualPacket* pkt = nsp_vtl_pkt_new_ex(handle, 3 + len + len2, NSP_SRC_ADDR, handle->priv.nsp_src_port, NSP_DEV_ADDR, NSP_PORT_FILE_MGMT, + NSP_CMD_FM_RENAME_FILE, (uint8_t*)nsp_vtl_pkt_alloc_data(handle, 3 + len + len2)); pkt->data[0] = 0x01; put_str(pkt->data + 1, name); put_str(pkt->data + 2 + len, name2); @@ -755,17 +731,17 @@ int TICALL nsp_cmd_s_rename_file(CalcHandle *handle, const char *name, const cha int TICALL nsp_cmd_r_rename_file(CalcHandle *handle) { - return nsp_cmd_r_status(handle, NULL); + return nsp_cmd_r_status(handle, nullptr); } int TICALL nsp_cmd_s_file_ok(CalcHandle *handle) { - NSPVirtualPacket* pkt; int retval = 0; VALIDATE_HANDLE(handle); - pkt = nsp_vtl_pkt_new_ex(handle, 0, NSP_SRC_ADDR, handle->priv.nsp_src_port, NSP_DEV_ADDR, NSP_PORT_FILE_MGMT, NSP_CMD_FM_OK, (uint8_t *)nsp_vtl_pkt_alloc_data(handle, 0)); + NSPVirtualPacket* pkt = nsp_vtl_pkt_new_ex(handle, 0, NSP_SRC_ADDR, handle->priv.nsp_src_port, NSP_DEV_ADDR, NSP_PORT_FILE_MGMT, + NSP_CMD_FM_OK, (uint8_t*)nsp_vtl_pkt_alloc_data(handle, 0)); ticalcs_info(" sending file contents:"); @@ -778,12 +754,11 @@ int TICALL nsp_cmd_s_file_ok(CalcHandle *handle) int TICALL nsp_cmd_r_file_ok(CalcHandle *handle) { - NSPVirtualPacket* pkt; int retval = 0; VALIDATE_HANDLE(handle); - pkt = nsp_vtl_pkt_new(handle); + NSPVirtualPacket* pkt = nsp_vtl_pkt_new(handle); ticalcs_info(" file status:"); @@ -814,13 +789,13 @@ int TICALL nsp_cmd_r_file_ok(CalcHandle *handle) int TICALL nsp_cmd_s_file_contents(CalcHandle *handle, uint32_t size, uint8_t *data) { - NSPVirtualPacket* pkt; int retval = 0; VALIDATE_HANDLE(handle); VALIDATE_NONNULL(data); - pkt = nsp_vtl_pkt_new_ex(handle, size, NSP_SRC_ADDR, handle->priv.nsp_src_port, NSP_DEV_ADDR, NSP_PORT_FILE_MGMT, NSP_CMD_FM_CONTENTS, (uint8_t *)nsp_vtl_pkt_alloc_data(handle, size)); + NSPVirtualPacket* pkt = nsp_vtl_pkt_new_ex(handle, size, NSP_SRC_ADDR, handle->priv.nsp_src_port, NSP_DEV_ADDR, NSP_PORT_FILE_MGMT, + NSP_CMD_FM_CONTENTS, (uint8_t*)nsp_vtl_pkt_alloc_data(handle, size)); ticalcs_info(" sending file contents:"); @@ -834,14 +809,13 @@ int TICALL nsp_cmd_s_file_contents(CalcHandle *handle, uint32_t size, uint8_t *d int TICALL nsp_cmd_r_file_contents(CalcHandle *handle, uint32_t *size, uint8_t **data) { - NSPVirtualPacket* pkt; int retval = 0; VALIDATE_HANDLE(handle); VALIDATE_NONNULL(size); VALIDATE_NONNULL(data); - pkt = nsp_vtl_pkt_new(handle); + NSPVirtualPacket* pkt = nsp_vtl_pkt_new(handle); ticalcs_info(" receiving file contents:"); @@ -864,12 +838,12 @@ int TICALL nsp_cmd_r_file_contents(CalcHandle *handle, uint32_t *size, uint8_t * int TICALL nsp_cmd_s_os_install(CalcHandle *handle, uint32_t size) { - NSPVirtualPacket* pkt; int retval = 0; VALIDATE_HANDLE(handle); - pkt = nsp_vtl_pkt_new_ex(handle, 4, NSP_SRC_ADDR, handle->priv.nsp_src_port, NSP_DEV_ADDR, NSP_PORT_OS_INSTALL, NSP_CMD_OS_INSTALL, (uint8_t *)nsp_vtl_pkt_alloc_data(handle, 4)); + NSPVirtualPacket* pkt = nsp_vtl_pkt_new_ex(handle, 4, NSP_SRC_ADDR, handle->priv.nsp_src_port, NSP_DEV_ADDR, NSP_PORT_OS_INSTALL, + NSP_CMD_OS_INSTALL, (uint8_t*)nsp_vtl_pkt_alloc_data(handle, 4)); ticalcs_info(" installing OS:"); @@ -886,12 +860,11 @@ int TICALL nsp_cmd_s_os_install(CalcHandle *handle, uint32_t size) int TICALL nsp_cmd_r_os_install(CalcHandle *handle) { - NSPVirtualPacket* pkt; int retval = 0; VALIDATE_HANDLE(handle); - pkt = nsp_vtl_pkt_new(handle); + NSPVirtualPacket* pkt = nsp_vtl_pkt_new(handle); ticalcs_info(" receiving OS installation:"); @@ -912,13 +885,13 @@ int TICALL nsp_cmd_r_os_install(CalcHandle *handle) int TICALL nsp_cmd_s_os_contents(CalcHandle *handle, uint32_t size, uint8_t *data) { - NSPVirtualPacket* pkt; int retval = 0; VALIDATE_HANDLE(handle); VALIDATE_NONNULL(data); - pkt = nsp_vtl_pkt_new_ex(handle, size, NSP_SRC_ADDR, handle->priv.nsp_src_port, NSP_DEV_ADDR, NSP_PORT_OS_INSTALL, NSP_CMD_OS_CONTENTS, (uint8_t *)nsp_vtl_pkt_alloc_data(handle, size)); + NSPVirtualPacket* pkt = nsp_vtl_pkt_new_ex(handle, size, NSP_SRC_ADDR, handle->priv.nsp_src_port, NSP_DEV_ADDR, NSP_PORT_OS_INSTALL, + NSP_CMD_OS_CONTENTS, (uint8_t*)nsp_vtl_pkt_alloc_data(handle, size)); ticalcs_info(" sending OS contents:"); @@ -932,13 +905,12 @@ int TICALL nsp_cmd_s_os_contents(CalcHandle *handle, uint32_t size, uint8_t *dat int TICALL nsp_cmd_r_progress(CalcHandle *handle, uint8_t *value) { - NSPVirtualPacket* pkt; int retval = 0; VALIDATE_HANDLE(handle); VALIDATE_NONNULL(value); - pkt = nsp_vtl_pkt_new(handle); + NSPVirtualPacket* pkt = nsp_vtl_pkt_new(handle); ticalcs_info(" OS installation status:"); @@ -970,14 +942,14 @@ int TICALL nsp_cmd_r_progress(CalcHandle *handle, uint8_t *value) int TICALL nsp_cmd_s_generic_data(CalcHandle *handle, uint32_t size, uint8_t *data, uint16_t sid, uint8_t cmd) { - NSPVirtualPacket* pkt; int retval = 0; VALIDATE_HANDLE(handle); ticalcs_info(" sending generic data of size %lu (%lX) with command %02X:", (unsigned long)size, (unsigned long)size, cmd); - pkt = nsp_vtl_pkt_new_ex(handle, size, NSP_SRC_ADDR, handle->priv.nsp_src_port, NSP_DEV_ADDR, sid, cmd, (uint8_t *)nsp_vtl_pkt_alloc_data(handle, size)); + NSPVirtualPacket* pkt = nsp_vtl_pkt_new_ex(handle, size, NSP_SRC_ADDR, handle->priv.nsp_src_port, NSP_DEV_ADDR, sid, cmd, + (uint8_t*)nsp_vtl_pkt_alloc_data(handle, size)); if (data) { @@ -992,12 +964,11 @@ int TICALL nsp_cmd_s_generic_data(CalcHandle *handle, uint32_t size, uint8_t *da int TICALL nsp_cmd_r_generic_data(CalcHandle *handle, uint32_t *size, uint8_t **data) { - NSPVirtualPacket* pkt; int retval = 0; VALIDATE_HANDLE(handle); - pkt = nsp_vtl_pkt_new(handle); + NSPVirtualPacket* pkt = nsp_vtl_pkt_new(handle); ticalcs_info(" receiving generic data:"); @@ -1043,7 +1014,6 @@ int TICALL nsp_cmd_r_echo(CalcHandle *handle, uint32_t *size, uint8_t **data) int TICALL nsp_cmd_s_key(CalcHandle *handle, uint32_t code) { - NSPVirtualPacket * pkt1, * pkt2; int retval = 0; VALIDATE_HANDLE(handle); @@ -1053,14 +1023,16 @@ int TICALL nsp_cmd_s_key(CalcHandle *handle, uint32_t code) retval = nsp_session_open(handle, NSP_SID_KEYPRESSES); if (!retval) { - pkt1 = nsp_vtl_pkt_new_ex(handle, 3, NSP_SRC_ADDR, handle->priv.nsp_src_port, NSP_DEV_ADDR, NSP_PORT_KEYPRESSES, 0x01, (uint8_t *)nsp_vtl_pkt_alloc_data(handle, 3)); + NSPVirtualPacket* pkt1 = nsp_vtl_pkt_new_ex(handle, 3, NSP_SRC_ADDR, handle->priv.nsp_src_port, NSP_DEV_ADDR, NSP_PORT_KEYPRESSES, 0x01, + (uint8_t*)nsp_vtl_pkt_alloc_data(handle, 3)); pkt1->data[2] = 0x80; retval = nsp_send_data(handle, pkt1); if (!retval) { - pkt2 = nsp_vtl_pkt_new_ex(handle, 25, NSP_SRC_ADDR, handle->priv.nsp_src_port, NSP_DEV_ADDR, NSP_PORT_KEYPRESSES, 0, (uint8_t *)nsp_vtl_pkt_alloc_data(handle, 25)); + NSPVirtualPacket* pkt2 = nsp_vtl_pkt_new_ex(handle, 25, NSP_SRC_ADDR, handle->priv.nsp_src_port, NSP_DEV_ADDR, NSP_PORT_KEYPRESSES, 0, + (uint8_t*)nsp_vtl_pkt_alloc_data(handle, 25)); pkt2->data[3] = 0x08; pkt2->data[4] = 0x02; @@ -1086,12 +1058,10 @@ int TICALL nsp_cmd_s_key(CalcHandle *handle, uint32_t code) int TICALL nsp_cmd_s_keypress_event(CalcHandle *handle, const uint8_t keycode[3]) { - uint32_t key; - VALIDATE_HANDLE(handle); VALIDATE_NONNULL(keycode); - key = ((uint32_t)(keycode[0]) << 16) | ((uint32_t)(keycode[1]) << 8) | (uint32_t)(keycode[2]); + const uint32_t key = ((uint32_t)(keycode[0]) << 16) | ((uint32_t)(keycode[1]) << 8) | (uint32_t)(keycode[2]); return nsp_cmd_s_key(handle, key); } diff --git a/libticalcs/trunk/src/nsp_rpkt.cc b/libticalcs/trunk/src/nsp_rpkt.cc index 75aa8ac80..12db706a4 100644 --- a/libticalcs/trunk/src/nsp_rpkt.cc +++ b/libticalcs/trunk/src/nsp_rpkt.cc @@ -83,9 +83,7 @@ static const NSPServiceId nspsids[] = const char* TICALL nsp_addr2name(uint16_t id) { - unsigned int i; - - for (i = 0; i < sizeof(nspaddrs) / sizeof(nspaddrs[0]); i++) + for (unsigned int i = 0; i < sizeof(nspaddrs) / sizeof(nspaddrs[0]); i++) { if (id == nspaddrs[i].id) { @@ -98,9 +96,7 @@ const char* TICALL nsp_addr2name(uint16_t id) const char* TICALL nsp_sid2name(uint16_t id) { - unsigned int i; - - for (i = 0; i < sizeof(nspsids) / sizeof(nspsids[0]); i++) + for (unsigned int i = 0; i < sizeof(nspsids) / sizeof(nspsids[0]); i++) { if (id == nspsids[i].id) { @@ -115,21 +111,18 @@ const char* TICALL nsp_sid2name(uint16_t id) static uint16_t compute_crc(uint8_t *data, uint32_t size) { uint16_t acc = 0; - uint32_t i; if (size == 0) { return 0; } - for (i = 0; i < size; i++) + for (uint32_t i = 0; i < size; i++) { - uint16_t first, second, third; - - first = (((uint16_t)data[i]) << 8) | (acc >> 8); + const uint16_t first = (((uint16_t)data[i]) << 8) | (acc >> 8); acc &= 0xff; - second = (((acc & 0x0f) << 4) ^ acc) << 8; - third = second >> 5; + const uint16_t second = (((acc & 0x0f) << 4) ^ acc) << 8; + const uint16_t third = second >> 5; acc = third >> 7; acc = (acc ^ first ^ second ^ third); } @@ -141,14 +134,13 @@ static int hexdump(uint8_t *data, uint32_t size) { #if (VPKT_DBG == 1) char str[64]; - uint32_t i; str[0] = 0; if (size <= 12) { str[0] = ' '; str[1] = ' '; str[2] = ' '; str[3] = ' '; - for (i = 0; i < size; i++) + for (uint32_t i = 0; i < size; i++) { sprintf(&str[3*i+4], "%02X ", data[i]); } @@ -191,8 +183,6 @@ static int hexdump(uint8_t *data, uint32_t size) int TICALL nsp_send(CalcHandle* handle, NSPRawPacket* pkt) { uint8_t buf[sizeof(NSPRawPacket)] = { 0 }; - uint32_t size; - int ret; CalcEventData event; VALIDATE_HANDLE(handle); @@ -203,11 +193,11 @@ int TICALL nsp_send(CalcHandle* handle, NSPRawPacket* pkt) ticalcs_event_fill_header(handle, &event, /* type */ CALC_EVENT_TYPE_BEFORE_SEND_NSP_RPKT, /* retval */ 0, /* operation */ CALC_FNCT_LAST); ticalcs_event_fill_nsp_rpkt(&event, /* src_addr */ pkt->src_addr, /* src_port */ pkt->src_port, /* dst_addr */ pkt->dst_addr, /* dst_port */ pkt->dst_port, /* data_sum */ pkt->data_sum, /* data_size */ pkt->data_size, /* ack */ pkt->ack, /* seq */ pkt->seq, /* hdr_sum */ pkt->hdr_sum, /* data */ pkt->data); - ret = ticalcs_event_send(handle, &event); + int ret = ticalcs_event_send(handle, &event); if (!ret) { - size = pkt->data_size + NSP_HEADER_SIZE; + const uint32_t size = pkt->data_size + NSP_HEADER_SIZE; pkt->data_sum = compute_crc(pkt->data, pkt->data_size); if (pkt->src_port == 0x00fe || pkt->src_port == 0x00ff || pkt->src_port == 0x00d3) @@ -257,7 +247,7 @@ int TICALL nsp_send(CalcHandle* handle, NSPRawPacket* pkt) { if (size >= 128) { - ticables_progress_get(handle->cable, NULL, NULL, &handle->updat->rate); + ticables_progress_get(handle->cable, nullptr, nullptr, &handle->updat->rate); } if (handle->updat->cancel) @@ -280,7 +270,6 @@ int TICALL nsp_send(CalcHandle* handle, NSPRawPacket* pkt) int TICALL nsp_recv(CalcHandle* handle, NSPRawPacket* pkt) { uint8_t buf[NSP_HEADER_SIZE]; - int ret; CalcEventData event; VALIDATE_HANDLE(handle); @@ -291,7 +280,7 @@ int TICALL nsp_recv(CalcHandle* handle, NSPRawPacket* pkt) ticalcs_event_fill_header(handle, &event, /* type */ CALC_EVENT_TYPE_BEFORE_RECV_NSP_RPKT, /* retval */ 0, /* operation */ CALC_FNCT_LAST); ticalcs_event_fill_nsp_rpkt(&event, /* src_addr */ 0, /* src_port */ 0, /* dst_addr */ 0, /* dst_port */ 0, /* data_sum */ 0, /* data_size */ 0, /* ack */ 0, /* seq */ 0, /* hdr_sum */ 0, /* data */ pkt->data); - ret = ticalcs_event_send(handle, &event); + int ret = ticalcs_event_send(handle, &event); if (!ret) { @@ -330,7 +319,7 @@ int TICALL nsp_recv(CalcHandle* handle, NSPRawPacket* pkt) if (pkt->data_size >= 128) { - ticables_progress_get(handle->cable, NULL, NULL, &handle->updat->rate); + ticables_progress_get(handle->cable, nullptr, nullptr, &handle->updat->rate); } } @@ -380,21 +369,8 @@ static const char* ep_way(uint8_t ep) int TICALL nsp_dissect(CalcModel model, FILE * f, const uint8_t * data, uint32_t len, uint8_t ep) { - int ret = 0; - uint16_t unused; - uint16_t src_addr; - uint16_t src_port; - uint16_t dst_addr; - uint16_t dst_port; - uint16_t data_sum; - uint8_t data_size; - uint8_t ack; - uint8_t seq; - uint8_t hdr_sum; - uint8_t cmd; + const int ret = 0; uint32_t i; - uint8_t computed_hdr_sum; - uint16_t computed_data_sum; VALIDATE_NONNULL(f); VALIDATE_NONNULL(data); @@ -405,17 +381,17 @@ int TICALL nsp_dissect(CalcModel model, FILE * f, const uint8_t * data, uint32_t return ERR_INVALID_PACKET; } - unused = (((uint16_t)data[0]) << 8) | data[1]; - src_addr = (((uint16_t)data[2]) << 8) | data[3]; - src_port = (((uint16_t)data[4]) << 8) | data[5]; - dst_addr = (((uint16_t)data[6]) << 8) | data[7]; - dst_port = (((uint16_t)data[8]) << 8) | data[9]; - data_sum = (((uint16_t)data[10]) << 8) | data[11]; - data_size = data[12]; - ack = data[13]; - seq = data[14]; - hdr_sum = data[15]; - cmd = data[16]; + const uint16_t unused = (((uint16_t)data[0]) << 8) | data[1]; + const uint16_t src_addr = (((uint16_t)data[2]) << 8) | data[3]; + const uint16_t src_port = (((uint16_t)data[4]) << 8) | data[5]; + const uint16_t dst_addr = (((uint16_t)data[6]) << 8) | data[7]; + const uint16_t dst_port = (((uint16_t)data[8]) << 8) | data[9]; + const uint16_t data_sum = (((uint16_t)data[10]) << 8) | data[11]; + const uint8_t data_size = data[12]; + const uint8_t ack = data[13]; + const uint8_t seq = data[14]; + const uint8_t hdr_sum = data[15]; + const uint8_t cmd = data[16]; fprintf(f, "%08lX\t| %s: %04X - %s (%04X - %s) -> %04X - %s (%04X - %s)\n", (unsigned long)len, ep_way(ep), src_addr, nsp_addr2name(src_addr), src_port, nsp_sid2name(src_port), @@ -435,12 +411,12 @@ int TICALL nsp_dissect(CalcModel model, FILE * f, const uint8_t * data, uint32_t return ERR_INVALID_PACKET; } - computed_hdr_sum = 0; + uint8_t computed_hdr_sum = 0; for (i = 0; i < NSP_HEADER_SIZE - 1; i++) { computed_hdr_sum += data[i]; } - computed_data_sum = tifiles_checksum(data, len); + const uint16_t computed_data_sum = tifiles_checksum(data, len); fprintf(f, "\t computed_hdr_sum=%02X computed_data_sum=%04X\n", computed_hdr_sum, computed_data_sum); if (computed_hdr_sum != hdr_sum || computed_data_sum != data_sum) { diff --git a/libticalcs/trunk/src/nsp_vpkt.cc b/libticalcs/trunk/src/nsp_vpkt.cc index 5bf3941d3..e15a08a35 100644 --- a/libticalcs/trunk/src/nsp_vpkt.cc +++ b/libticalcs/trunk/src/nsp_vpkt.cc @@ -48,18 +48,18 @@ NSPVirtualPacket* TICALL nsp_vtl_pkt_new(CalcHandle * handle) { - return nsp_vtl_pkt_new_ex(handle, 0, 0, 0, 0, 0, 0, NULL); + return nsp_vtl_pkt_new_ex(handle, 0, 0, 0, 0, 0, 0, nullptr); } NSPVirtualPacket* TICALL nsp_vtl_pkt_new_ex(CalcHandle * handle, uint32_t size, uint16_t src_addr, uint16_t src_port, uint16_t dst_addr, uint16_t dst_port, uint8_t cmd, uint8_t * data) { - NSPVirtualPacket* vtl = NULL; + NSPVirtualPacket* vtl = nullptr; if (ticalcs_validate_handle(handle)) { vtl = (NSPVirtualPacket *)g_malloc0(sizeof(NSPVirtualPacket)); - if (NULL != vtl) + if (nullptr != vtl) { //GList * vtl_pkt_list; @@ -79,7 +79,7 @@ NSPVirtualPacket* TICALL nsp_vtl_pkt_new_ex(CalcHandle * handle, uint32_t size, void TICALL nsp_vtl_pkt_fill(NSPVirtualPacket* vtl, uint32_t size, uint16_t src_addr, uint16_t src_port, uint16_t dst_addr, uint16_t dst_port, uint8_t cmd, uint8_t * data) { - if (vtl != NULL) + if (vtl != nullptr) { vtl->src_addr = src_addr; vtl->src_port = src_port; @@ -105,7 +105,7 @@ void TICALL nsp_vtl_pkt_del(CalcHandle *handle, NSPVirtualPacket* vtl) return; } - if (vtl == NULL) + if (vtl == nullptr) { ticalcs_critical("%s: vtl is NULL", __FUNCTION__); return; @@ -133,12 +133,12 @@ NSPVirtualPacket * TICALL nsp_vtl_pkt_realloc_data(CalcHandle * handle, NSPVirtu { return nullptr; } - if (vtl != NULL) + if (vtl != nullptr) { if (size + 1 > size) { uint8_t * data = (uint8_t *)g_realloc(vtl->data, size + 1); - if (NULL != data) + if (nullptr != data) { if (size > vtl->size) { @@ -150,12 +150,12 @@ NSPVirtualPacket * TICALL nsp_vtl_pkt_realloc_data(CalcHandle * handle, NSPVirtu } else { - return NULL; + return nullptr; } } else { - return NULL; + return nullptr; } } @@ -186,15 +186,13 @@ int TICALL nsp_session_open(CalcHandle *handle, uint16_t port) int TICALL nsp_session_close(CalcHandle *handle) { - int ret; - VALIDATE_HANDLE(handle); ticalcs_info(" closed session from port #%04x to port #%04x:", handle->priv.nsp_src_port, handle->priv.nsp_dst_port); SET_HANDLE_BUSY_IF_NECESSARY(handle); - ret = nsp_send_disconnect(handle); + int ret = nsp_send_disconnect(handle); if (!ret) { ret = nsp_recv_ack(handle); @@ -214,7 +212,6 @@ int TICALL nsp_session_close(CalcHandle *handle) int TICALL nsp_addr_request(CalcHandle *handle) { NSPRawPacket pkt; - int ret; VALIDATE_HANDLE(handle); @@ -223,7 +220,7 @@ int TICALL nsp_addr_request(CalcHandle *handle) memset(&pkt, 0, sizeof(pkt)); // Reset connection so that device send an address request packet - ret = handle->cable->cable->reset(handle->cable); + int ret = handle->cable->cable->reset(handle->cable); if (!ret) { handle->priv.nsp_seq_pc = 1; @@ -326,7 +323,6 @@ int TICALL nsp_send_nack_ex(CalcHandle* handle, uint16_t port) int TICALL nsp_recv_ack(CalcHandle *handle) { NSPRawPacket pkt; - uint16_t addr; int ret = 0; VALIDATE_HANDLE(handle); @@ -353,7 +349,7 @@ int TICALL nsp_recv_ack(CalcHandle *handle) if (pkt.data_size >= 2) { - addr = (((uint16_t)pkt.data[0]) << 8) | pkt.data[1]; + const uint16_t addr = (((uint16_t)pkt.data[0]) << 8) | pkt.data[1]; if (addr != handle->priv.nsp_dst_port) { ticalcs_info("XXX weird addr\n"); @@ -403,8 +399,6 @@ int TICALL nsp_send_disconnect(CalcHandle *handle) int TICALL nsp_recv_disconnect(CalcHandle *handle) { NSPRawPacket pkt; - uint16_t addr; - int ret; VALIDATE_HANDLE(handle); @@ -414,7 +408,7 @@ int TICALL nsp_recv_disconnect(CalcHandle *handle) SET_HANDLE_BUSY_IF_NECESSARY(handle); - ret = nsp_recv(handle, &pkt); + int ret = nsp_recv(handle, &pkt); if (!ret) { @@ -426,7 +420,7 @@ int TICALL nsp_recv_disconnect(CalcHandle *handle) { // nasty hacks handle->priv.nsp_dst_port = (((uint16_t)pkt.data[0]) << 8) | pkt.data[1]; - addr = pkt.dst_port; + const uint16_t addr = pkt.dst_port; ticalcs_info(" sending ack:"); @@ -456,7 +450,6 @@ int TICALL nsp_recv_disconnect(CalcHandle *handle) int TICALL nsp_send_data(CalcHandle *handle, NSPVirtualPacket *vtl) { NSPRawPacket raw; - int i, r, q; long offset = 0; int ret = 0; CalcEventData event; @@ -482,10 +475,10 @@ int TICALL nsp_send_data(CalcHandle *handle, NSPVirtualPacket *vtl) raw.dst_addr = vtl->dst_addr; raw.dst_port = vtl->dst_port; - q = (vtl->size - offset) / (NSP_DATA_SIZE-1); - r = (vtl->size - offset) % (NSP_DATA_SIZE-1); + const int q = (vtl->size - offset) / (NSP_DATA_SIZE - 1); + const int r = (vtl->size - offset) % (NSP_DATA_SIZE - 1); - for (i = 1; i <= q; i++) + for (int i = 1; i <= q; i++) { raw.data_size = NSP_DATA_SIZE; raw.data[0] = vtl->cmd; @@ -550,7 +543,6 @@ int TICALL nsp_recv_data(CalcHandle* handle, NSPVirtualPacket* vtl) { NSPRawPacket raw; long offset = 0; - uint32_t size; int ret = 0; CalcEventData event; @@ -560,14 +552,14 @@ int TICALL nsp_recv_data(CalcHandle* handle, NSPVirtualPacket* vtl) SET_HANDLE_BUSY_IF_NECESSARY(handle); ticalcs_event_fill_header(handle, &event, /* type */ CALC_EVENT_TYPE_BEFORE_RECV_NSP_VPKT, /* retval */ 0, /* operation */ CALC_FNCT_LAST); - ticalcs_event_fill_nsp_vpkt(&event, /* src_addr */ 0, /* src_port */ 0, /* dst_addr */ 0, /* dst_port */ 0, /* cmd */ 0, /* size */ 0, /* data */ NULL); + ticalcs_event_fill_nsp_vpkt(&event, /* src_addr */ 0, /* src_port */ 0, /* dst_addr */ 0, /* dst_port */ 0, /* cmd */ 0, /* size */ 0, /* data */ nullptr); ret = ticalcs_event_send(handle, &event); if (!ret) { memset(&raw, 0, sizeof(raw)); - size = vtl->size; + const uint32_t size = vtl->size; vtl->size = 0; vtl->data = (uint8_t *)g_malloc(NSP_DATA_SIZE); diff --git a/libticalcs/trunk/src/probe.cc b/libticalcs/trunk/src/probe.cc index c99a58576..03fabaa67 100644 --- a/libticalcs/trunk/src/probe.cc +++ b/libticalcs/trunk/src/probe.cc @@ -46,9 +46,8 @@ static int tixx_recv_ACK(CalcHandle* handle, uint8_t* mid) { uint8_t host = 0, cmd = 0; uint16_t length = 0; - int ret; - ret = dbus_recv(handle, &host, &cmd, &length, (uint8_t *)handle->buffer2); + int ret = dbus_recv(handle, &host, &cmd, &length, (uint8_t*)handle->buffer2); if (!ret) { ticalcs_info(" TI->PC: ACK"); @@ -71,7 +70,7 @@ static int try_ready_command(CalcHandle * handle, uint8_t mid, uint8_t * host, u for (unsigned int i = 0; i < 2; i++) { ticalcs_info(" PC->TI: RDY?"); - ret = dbus_send(handle, mid, DBUS_CMD_RDY, 2, NULL); + ret = dbus_send(handle, mid, DBUS_CMD_RDY, 2, nullptr); //uint8_t buf[4] = { mid, DBUS_CMD_RDY, 0, 0 }; //ret = ticables_cable_send(handle->cable, buf, sizeof(buf)); if (ret) @@ -129,7 +128,6 @@ static int try_ready_command(CalcHandle * handle, uint8_t mid, uint8_t * host, u **/ static int ticalcs_probe_calc_2(CalcHandle* handle, CalcModel* model) { - int err; uint8_t data; do @@ -139,7 +137,7 @@ static int ticalcs_probe_calc_2(CalcHandle* handle, CalcModel* model) /* Test for a TI86 before a TI85 */ ticalcs_info("%s", _("Check for TI86... ")); - err = dbus_send(handle, DBUS_MID_PC_TI86, DBUS_CMD_SCR, 0, NULL); + int err = dbus_send(handle, DBUS_MID_PC_TI86, DBUS_CMD_SCR, 0, nullptr); if (err) { break; @@ -163,7 +161,7 @@ static int ticalcs_probe_calc_2(CalcHandle* handle, CalcModel* model) /* Test for a TI85 */ ticalcs_info("%s", _("Check for TI85... ")); - err = dbus_send(handle, DBUS_MID_PC_TI85, DBUS_CMD_SCR, 0, NULL); + err = dbus_send(handle, DBUS_MID_PC_TI85, DBUS_CMD_SCR, 0, nullptr); if (err) { break; @@ -187,7 +185,7 @@ static int ticalcs_probe_calc_2(CalcHandle* handle, CalcModel* model) /* Test for a TI73 before a TI83 */ ticalcs_info("%s", _("Check for TI73... ")); - err = dbus_send(handle, DBUS_MID_PC_TI73, DBUS_CMD_SCR, 0, NULL); + err = dbus_send(handle, DBUS_MID_PC_TI73, DBUS_CMD_SCR, 0, nullptr); if (err) { break; @@ -211,7 +209,7 @@ static int ticalcs_probe_calc_2(CalcHandle* handle, CalcModel* model) /* Test for a TI83 before a TI82 */ ticalcs_info("%s", _("Check for TI83... ")); - err = dbus_send(handle, DBUS_MID_PC_TI83, DBUS_CMD_SCR, 0, NULL); + err = dbus_send(handle, DBUS_MID_PC_TI83, DBUS_CMD_SCR, 0, nullptr); if (err) { break; @@ -235,7 +233,7 @@ static int ticalcs_probe_calc_2(CalcHandle* handle, CalcModel* model) /* Test for a TI82 */ ticalcs_info("%s", _("Check for TI82... ")); - err = dbus_send(handle, DBUS_MID_PC_TI83, DBUS_CMD_SCR, 0, NULL); + err = dbus_send(handle, DBUS_MID_PC_TI83, DBUS_CMD_SCR, 0, nullptr); if (err) { break; @@ -583,13 +581,12 @@ int TICALL ticalcs_probe_usb_calc(CableHandle* cable, CalcModel* model) **/ int TICALL ticalcs_probe(CableModel c_model, CablePort c_port, CalcModel* model, int all) { - CableHandle *handle; int ret = 0; VALIDATE_NONNULL(model); // get handle - handle = ticables_handle_new(c_model, c_port); + CableHandle* handle = ticables_handle_new(c_model, c_port); ticables_options_set_timeout(handle, 10); do @@ -655,7 +652,7 @@ CalcModel TICALL ticalcs_device_info_to_model(const CableDeviceInfo *info) { CalcModel model = CALC_NONE; - if (info != NULL) + if (info != nullptr) { if (info->family == CABLE_FAMILY_DBUS) { diff --git a/libticalcs/trunk/src/romdump.cc b/libticalcs/trunk/src/romdump.cc index 0c1532119..46393a8ca 100644 --- a/libticalcs/trunk/src/romdump.cc +++ b/libticalcs/trunk/src/romdump.cc @@ -62,7 +62,6 @@ static int send_pkt(CalcHandle* handle, uint16_t cmd, uint16_t len, uint8_t* dat int ret = 0; CalcEventData event; - uint16_t sum; uint8_t * buf = (uint8_t *)handle->buffer; // command @@ -80,7 +79,7 @@ static int send_pkt(CalcHandle* handle, uint16_t cmd, uint16_t len, uint8_t* dat } // checksum - sum = tifiles_checksum(buf, 4 + len); + const uint16_t sum = tifiles_checksum(buf, 4 + len); buf[len+4+0] = LSB(sum); buf[len+4+1] = MSB(sum); @@ -121,8 +120,7 @@ static inline int cmd_is_valid(uint16_t cmd) static int recv_pkt(CalcHandle* handle, uint16_t* cmd, uint16_t* len, uint8_t* data) { - int i, r, q; - uint16_t sum, chksum; + int i; int ret = 0; uint8_t * buf = (uint8_t *)handle->buffer; CalcEventData event; @@ -161,8 +159,8 @@ static int recv_pkt(CalcHandle* handle, uint16_t* cmd, uint16_t* len, uint8_t* d handle->priv.progress_blk_size = 1; } - q = *len / handle->priv.progress_blk_size; - r = *len % handle->priv.progress_blk_size; + const int q = *len / handle->priv.progress_blk_size; + const int r = *len % handle->priv.progress_blk_size; handle->updat->cnt1 = 0; handle->updat->max1 = *len; @@ -174,7 +172,7 @@ static int recv_pkt(CalcHandle* handle, uint16_t* cmd, uint16_t* len, uint8_t* d { goto exit; } - ticables_progress_get(handle->cable, NULL, NULL, &handle->updat->rate); + ticables_progress_get(handle->cable, nullptr, nullptr, &handle->updat->rate); handle->updat->cnt1 += handle->priv.progress_blk_size; if (*len > handle->priv.progress_min_size) { @@ -191,7 +189,7 @@ static int recv_pkt(CalcHandle* handle, uint16_t* cmd, uint16_t* len, uint8_t* d { goto exit; } - ticables_progress_get(handle->cable, NULL, NULL, &handle->updat->rate); + ticables_progress_get(handle->cable, nullptr, nullptr, &handle->updat->rate); handle->updat->cnt1++; if (*len > handle->priv.progress_min_size) { @@ -205,8 +203,8 @@ static int recv_pkt(CalcHandle* handle, uint16_t* cmd, uint16_t* len, uint8_t* d } // verify checksum - chksum = ((uint16_t)buf[*len+4 + 1] << 8) | buf[*len+4 + 0]; - sum = tifiles_checksum(buf, *len + 4); + const uint16_t chksum = ((uint16_t)buf[*len + 4 + 1] << 8) | buf[*len + 4 + 0]; + const uint16_t sum = tifiles_checksum(buf, *len + 4); //printf("<%04x %04x>\n", sum, chksum); if (chksum != sum) @@ -236,15 +234,14 @@ static int recv_pkt(CalcHandle* handle, uint16_t* cmd, uint16_t* len, uint8_t* d static int rom_send_RDY(CalcHandle* handle) { ticalcs_info(" PC->TI: IS_READY"); - return send_pkt(handle, CMD_IS_READY, 0, NULL); + return send_pkt(handle, CMD_IS_READY, 0, nullptr); } static int rom_recv_RDY(CalcHandle* handle) { uint16_t cmd = 0, len = 0; - int ret; - ret = recv_pkt(handle, &cmd, &len, NULL); + const int ret = recv_pkt(handle, &cmd, &len, nullptr); ticalcs_info(" TI->PC: %s", ret ? "ERROR" : (cmd ? "OK" : "KO")); return ret; @@ -253,15 +250,14 @@ static int rom_recv_RDY(CalcHandle* handle) static int rom_send_EXIT(CalcHandle* handle) { ticalcs_info(" PC->TI: EXIT"); - return send_pkt(handle, CMD_EXIT, 0, NULL); + return send_pkt(handle, CMD_EXIT, 0, nullptr); } static int rom_recv_EXIT(CalcHandle* handle) { uint16_t cmd = 0, len = 0; - int ret; - ret = recv_pkt(handle, &cmd, &len, NULL); + const int ret = recv_pkt(handle, &cmd, &len, nullptr); ticalcs_info(" TI->PC: EXIT"); return ret; @@ -270,15 +266,14 @@ static int rom_recv_EXIT(CalcHandle* handle) static int rom_send_SIZE(CalcHandle* handle) { ticalcs_info(" PC->TI: REQ_SIZE"); - return send_pkt(handle, CMD_REQ_SIZE, 0, NULL); + return send_pkt(handle, CMD_REQ_SIZE, 0, nullptr); } static int rom_recv_SIZE(CalcHandle* handle, uint32_t* size) { uint16_t cmd = 0, len = 0; - int ret; - ret = recv_pkt(handle, &cmd, &len, (uint8_t *)size); + const int ret = recv_pkt(handle, &cmd, &len, (uint8_t*)size); ticalcs_info(" TI->PC: SIZE (0x%08x bytes)", *size); return ret; @@ -292,10 +287,9 @@ static int rom_send_DATA(CalcHandle* handle, uint32_t addr) static int rom_recv_DATA(CalcHandle* handle, uint16_t* size, uint8_t* data) { - uint16_t cmd = 0, rpt; - int ret; + uint16_t cmd = 0; - ret = recv_pkt(handle, &cmd, size, data); + int ret = recv_pkt(handle, &cmd, size, data); if (!ret) { if (cmd == CMD_DATA1) @@ -306,7 +300,7 @@ static int rom_recv_DATA(CalcHandle* handle, uint16_t* size, uint8_t* data) else if (cmd == CMD_DATA2) { *size = (((uint16_t)data[1]) << 8) | data[0]; - rpt = (((uint16_t)data[3]) << 8) | data[2]; + const uint16_t rpt = (((uint16_t)data[3]) << 8) | data[2]; memset(data, rpt, *size); ticalcs_info(" TI->PC: BLOCK WITH REPEATED DATA (0x%04x bytes)", *size); handle->priv.romdump_sav_blk++; @@ -331,21 +325,18 @@ static int rom_recv_DATA(CalcHandle* handle, uint16_t* size, uint8_t* data) int TICALL rd_read_dump(CalcHandle* handle, const char *filename) { - FILE *f; int ret = 0; uint32_t size; - uint32_t addr; uint16_t length; uint32_t i; - uint8_t * data; VALIDATE_HANDLE(handle); VALIDATE_NONNULL(filename); - data = (uint8_t *)handle->buffer; + uint8_t* data = (uint8_t*)handle->buffer; - f = fopen(filename, "wb"); - if (f == NULL) + FILE* f = fopen(filename, "wb"); + if (f == nullptr) { return ERR_OPEN_FILE; } @@ -381,7 +372,7 @@ int TICALL rd_read_dump(CalcHandle* handle, const char *filename) // get packets handle->priv.romdump_std_blk = handle->priv.romdump_sav_blk = 0; - for (addr = 0x0000; addr < size; ) + for (uint32_t addr = 0x0000; addr < size; ) { if (ret == ERR_ABORT) { @@ -475,13 +466,11 @@ int TICALL rd_read_dump(CalcHandle* handle, const char *filename) int TICALL rd_is_ready(CalcHandle* handle) { - int ret; - VALIDATE_HANDLE(handle); SET_HANDLE_BUSY_IF_NECESSARY(handle); - ret = rom_send_RDY(handle); + int ret = rom_send_RDY(handle); if (!ret) { ret = rom_recv_RDY(handle); @@ -494,8 +483,8 @@ int TICALL rd_is_ready(CalcHandle* handle) int TICALL rd_send_dumper(CalcHandle *handle, const char *prgname, uint16_t size, uint8_t *data) { - char *templatename, *tempfname; - int fd, ret; + char*tempfname; + int ret; VALIDATE_HANDLE(handle); VALIDATE_NONNULL(prgname); @@ -513,8 +502,8 @@ int TICALL rd_send_dumper(CalcHandle *handle, const char *prgname, uint16_t size the correct suffix or tifiles_file_read_regular will be confused) */ - templatename = g_strconcat("rdXXXXXX", strrchr(prgname, '.'), NULL); - fd = g_file_open_tmp(templatename, &tempfname, NULL); + char* templatename = g_strconcat("rdXXXXXX", strrchr(prgname, '.'), NULL); + const int fd = g_file_open_tmp(templatename, &tempfname, nullptr); g_free(templatename); if (fd == -1) { @@ -543,15 +532,13 @@ int TICALL rd_send_dumper(CalcHandle *handle, const char *prgname, uint16_t size int TICALL rd_send_dumper2(CalcHandle *handle, const char *filename) { - int ret; - VALIDATE_HANDLE(handle); VALIDATE_NONNULL(filename); // busy will be taken adequately by the subroutines. // Transfer program to calc, using special internal API, taking busy if it's not taken. - ret = ticalcs_calc_send_var2_(handle, MODE_SEND_EXEC_ASM, filename, !handle->busy); + const int ret = ticalcs_calc_send_var2_(handle, MODE_SEND_EXEC_ASM, filename, !handle->busy); return ret; } diff --git a/libticalcs/trunk/src/screen.cc b/libticalcs/trunk/src/screen.cc index 0608857a9..e1020d254 100644 --- a/libticalcs/trunk/src/screen.cc +++ b/libticalcs/trunk/src/screen.cc @@ -42,22 +42,18 @@ **/ int TICALL ticalcs_screen_convert_bw_to_rgb888(const uint8_t * src, unsigned int width, unsigned int height, uint8_t * dst) { - unsigned int i; - VALIDATE_NONNULL(src); VALIDATE_SCREENWIDTH(width); VALIDATE_SCREENHEIGHT(height); VALIDATE_NONNULL(dst); - for (i = 0; i < height; i++) + for (unsigned int i = 0; i < height; i++) { - unsigned int j; - for (j = 0; j < (width >> 3); j++) + for (unsigned int j = 0; j < (width >> 3); j++) { - uint8_t data = *src++; + const uint8_t data = *src++; uint8_t mask = 0x80; - unsigned int bit; - for (bit = 0; bit < 8; bit++) + for (unsigned int bit = 0; bit < 8; bit++) { if (data & mask) { @@ -92,22 +88,18 @@ int TICALL ticalcs_screen_convert_bw_to_rgb888(const uint8_t * src, unsigned int **/ int TICALL ticalcs_screen_convert_bw_to_blurry_rgb888(const uint8_t * src, unsigned int width, unsigned int height, uint8_t * dst) { - unsigned int i; - VALIDATE_NONNULL(src); VALIDATE_SCREENWIDTH(width); VALIDATE_SCREENHEIGHT(height); VALIDATE_NONNULL(dst); - for (i = 0; i < height; i++) + for (unsigned int i = 0; i < height; i++) { - unsigned int j; - for (j = 0; j < (width >> 3); j++) + for (unsigned int j = 0; j < (width >> 3); j++) { - uint8_t data = *src++; + const uint8_t data = *src++; uint8_t mask = 0x80; - unsigned int bit; - for (bit = 0; bit < 8; bit++) + for (unsigned int bit = 0; bit < 8; bit++) { if (data & mask) { @@ -142,21 +134,18 @@ int TICALL ticalcs_screen_convert_bw_to_blurry_rgb888(const uint8_t * src, unsig **/ int TICALL ticalcs_screen_convert_gs4_to_rgb888(const uint8_t * src, unsigned int width, unsigned int height, uint8_t * dst) { - unsigned int i; - VALIDATE_NONNULL(src); VALIDATE_SCREENWIDTH(width); VALIDATE_SCREENHEIGHT(height); VALIDATE_NONNULL(dst); - for (i = 0; i < height; i++) + for (unsigned int i = 0; i < height; i++) { - unsigned int j; - for (j = 0; j < width / 2; j++) + for (unsigned int j = 0; j < width / 2; j++) { - uint8_t data = *src++; - uint8_t hi = data >> 4; - uint8_t lo = data & 0x0f; + const uint8_t data = *src++; + const uint8_t hi = data >> 4; + const uint8_t lo = data & 0x0f; *dst++ = hi << 4; *dst++ = hi << 4; @@ -184,19 +173,16 @@ int TICALL ticalcs_screen_convert_gs4_to_rgb888(const uint8_t * src, unsigned in **/ int TICALL ticalcs_screen_convert_rgb565le_to_rgb888(const uint8_t * src, unsigned int width, unsigned int height, uint8_t * dst) { - unsigned int i; - VALIDATE_NONNULL(src); VALIDATE_SCREENWIDTH(width); VALIDATE_SCREENHEIGHT(height); VALIDATE_NONNULL(dst); - for (i = 0; i < height; i++) + for (unsigned int i = 0; i < height; i++) { - unsigned int j; - for (j = 0; j < width; j++) + for (unsigned int j = 0; j < width; j++) { - uint16_t data = (((uint16_t)(src[1])) << 8) | ((uint16_t)(src[0])); + const uint16_t data = (((uint16_t)(src[1])) << 8) | ((uint16_t)(src[0])); src += 2; *dst++ = ((data & 0xF800) >> 11) << 3; @@ -286,13 +272,13 @@ int TICALL ticalcs_screen_nspire_rle_uncompress(CalcPixelFormat format, const ui for (i = 0, j = 0, q = dst; i < input_size;) { - int8_t rec = src[i++]; + const int8_t rec = src[i++]; if (rec >= 0) { // Positive count: "repeat 8-bit value" block. - uint8_t cnt = ((uint8_t)rec) + 1; - uint8_t val = src[i++]; + const uint8_t cnt = ((uint8_t)rec) + 1; + const uint8_t val = src[i++]; if (j + cnt > max_output_size) { @@ -306,7 +292,7 @@ int TICALL ticalcs_screen_nspire_rle_uncompress(CalcPixelFormat format, const ui else { // Negative count: "verbatim" block of 8-bit values. - uint8_t cnt = ((uint8_t)-rec) + 1; + const uint8_t cnt = ((uint8_t)-rec) + 1; if (j + cnt > max_output_size) { @@ -329,14 +315,13 @@ int TICALL ticalcs_screen_nspire_rle_uncompress(CalcPixelFormat format, const ui for (i = 0, j = 0, q = dst; i < input_size;) { - int8_t rec = src[i++]; + const int8_t rec = src[i++]; if (rec >= 0) { // Positive count: "repeat 32-bit value" block. - uint8_t cnt = ((uint8_t)rec) + 1; + const uint8_t cnt = ((uint8_t)rec) + 1; uint32_t val; - uint8_t k; if (j + cnt * 4 > max_output_size) { @@ -344,7 +329,7 @@ int TICALL ticalcs_screen_nspire_rle_uncompress(CalcPixelFormat format, const ui break; } memcpy(&val, src + i, sizeof(uint32_t)); - for (k = 0; k < cnt; k++) + for (uint8_t k = 0; k < cnt; k++) { memcpy(q, &val, 4); q += 4; @@ -355,7 +340,7 @@ int TICALL ticalcs_screen_nspire_rle_uncompress(CalcPixelFormat format, const ui else { // Negative count: "verbatim" block of 32-bit values. - uint8_t cnt = ((uint8_t)-rec) + 1; + const uint8_t cnt = ((uint8_t)-rec) + 1; if (j + cnt * 4 > max_output_size) { @@ -394,8 +379,7 @@ int TICALL ticalcs_screen_nspire_rle_uncompress(CalcPixelFormat format, const ui */ int TICALL ticalcs_screen_84pcse_rle_uncompress(const uint8_t *src, uint32_t src_length, uint8_t *dst, uint32_t dst_length) { - const uint8_t *palette; - unsigned int palette_size, i, c, n; + unsigned int i, c, n; VALIDATE_NONNULL(src); VALIDATE_NONNULL(dst); @@ -407,14 +391,14 @@ int TICALL ticalcs_screen_84pcse_rle_uncompress(const uint8_t *src, uint32_t src src++; src_length--; - palette_size = src[src_length - 1]; + const unsigned int palette_size = src[src_length - 1]; if (src_length <= palette_size * 2 + 1) { return ERR_INVALID_SCREENSHOT; } src_length -= palette_size * 2 + 1; - palette = src + src_length - 2; + const uint8_t* palette = src + src_length - 2; while (src_length > 0) { diff --git a/libticalcs/trunk/src/ticalcs.cc b/libticalcs/trunk/src/ticalcs.cc index 2a1d2bd63..4a1b3a6bc 100644 --- a/libticalcs/trunk/src/ticalcs.cc +++ b/libticalcs/trunk/src/ticalcs.cc @@ -176,7 +176,7 @@ static CalcFncts const *const calcs[] = #ifndef NO_TIPRESENTER &calc_tipresenter, #endif - NULL + nullptr }; static const uint64_t supported_calcs = @@ -451,8 +451,8 @@ int ticalcs_default_event_hook(CalcHandle * handle, uint32_t event_count, const CableHandle * cable = ticalcs_cable_get(handle); const char * cablestr = ticables_model_to_string(ticables_get_model(cable)); const char * portstr = ticables_port_to_string(ticables_get_port(cable)); - int pkt_debug = (getenv("TICALCS_PKT_DEBUG") != NULL); - if (getenv("TICALCS_EVENT_DEBUG") != NULL) + const int pkt_debug = (getenv("TICALCS_PKT_DEBUG") != nullptr); + if (getenv("TICALCS_EVENT_DEBUG") != nullptr) { ticalcs_info("Event #%u %d for calc %s connected through cable %s port %s", event_count, event->type, calcstr, cablestr, portstr); } @@ -602,11 +602,10 @@ int ticalcs_default_event_hook(CalcHandle * handle, uint32_t event_count, const **/ CalcHandle* TICALL ticalcs_handle_new(CalcModel model) { - CalcHandle *handle = NULL; - CalcFncts * calc = NULL; - unsigned int i; + CalcHandle *handle = nullptr; + CalcFncts * calc = nullptr; - for (i = 0; i < sizeof(calcs) / sizeof(calcs[0]) - 1; i++) // - 1 for the terminating NULL. + for (unsigned int i = 0; i < sizeof(calcs) / sizeof(calcs[0]) - 1; i++) // - 1 for the terminating NULL. { if (calcs[i]->model == (int)model) { @@ -615,10 +614,10 @@ CalcHandle* TICALL ticalcs_handle_new(CalcModel model) } } - if (calc != NULL) + if (calc != nullptr) { handle = (CalcHandle *)g_malloc0(sizeof(CalcHandle)); - if (handle != NULL) + if (handle != nullptr) { handle->model = model; handle->calc = calc; @@ -631,17 +630,17 @@ CalcHandle* TICALL ticalcs_handle_new(CalcModel model) //handle->event_count = 0; handle->buffer = (uint8_t *)g_malloc(65536 + 6); - if (handle->buffer == NULL) + if (handle->buffer == nullptr) { g_free(handle); - handle = NULL; + handle = nullptr; } handle->buffer2 = (uint8_t *)g_malloc(65536 + 6); - if (handle->buffer2 == NULL) + if (handle->buffer2 == nullptr) { g_free(handle->buffer); g_free(handle); - handle = NULL; + handle = nullptr; } } } @@ -779,7 +778,7 @@ int TICALL ticalcs_cable_detach(CalcHandle* handle) handle->open = 0; handle->attached = 0; - handle->cable = NULL; + handle->cable = nullptr; } } @@ -803,7 +802,7 @@ CableHandle* TICALL ticalcs_cable_get(CalcHandle *handle) return handle->cable; } - return NULL; + return nullptr; } /** @@ -839,7 +838,7 @@ CalcUpdate* TICALL ticalcs_update_get(CalcHandle *handle) return handle->updat; } - return NULL; + return nullptr; } /** @@ -925,7 +924,7 @@ ticalcs_event_hook_type TICALL ticalcs_calc_get_event_hook(CalcHandle *handle) if (!ticalcs_validate_handle(handle)) { ticalcs_critical("%s: handle is NULL", __FUNCTION__); - return NULL; + return nullptr; } return handle->event_hook; @@ -941,15 +940,13 @@ ticalcs_event_hook_type TICALL ticalcs_calc_get_event_hook(CalcHandle *handle) */ ticalcs_event_hook_type TICALL ticalcs_calc_set_event_hook(CalcHandle *handle, ticalcs_event_hook_type hook) { - ticalcs_event_hook_type old_hook; - if (!ticalcs_validate_handle(handle)) { ticalcs_critical("%s: handle is NULL", __FUNCTION__); - return NULL; + return nullptr; } - old_hook = handle->event_hook; + const ticalcs_event_hook_type old_hook = handle->event_hook; handle->event_hook = hook; return old_hook; @@ -967,7 +964,7 @@ void * ticalcs_calc_get_event_user_pointer(CalcHandle *handle) if (!ticalcs_validate_handle(handle)) { ticalcs_critical("%s: handle is NULL", __FUNCTION__); - return NULL; + return nullptr; } return handle->user_pointer; @@ -983,15 +980,13 @@ void * ticalcs_calc_get_event_user_pointer(CalcHandle *handle) */ void * ticalcs_calc_set_event_user_pointer(CalcHandle *handle, void * user_pointer) { - void * old_pointer; - if (!ticalcs_validate_handle(handle)) { ticalcs_critical("%s: handle is NULL", __FUNCTION__); - return NULL; + return nullptr; } - old_pointer = handle->user_pointer; + void* old_pointer = handle->user_pointer; handle->user_pointer = user_pointer; return old_pointer; diff --git a/libticalcs/trunk/src/type2str.cc b/libticalcs/trunk/src/type2str.cc index e670bb68c..ad4993c51 100644 --- a/libticalcs/trunk/src/type2str.cc +++ b/libticalcs/trunk/src/type2str.cc @@ -67,7 +67,7 @@ const char *TICALL ticalcs_scrfmt_to_string(CalcScreenFormat format) CalcScreenFormat TICALL ticalcs_string_to_scrfmt(const char *str) { - if (str != NULL) + if (str != nullptr) { if (!strcmp(str, _("full"))) { @@ -99,7 +99,7 @@ const char *TICALL ticalcs_pathtype_to_string(CalcPathType type) CalcPathType TICALL ticalcs_string_to_pathtype(const char *str) { - if (str != NULL) + if (str != nullptr) { if (!strcmp(str, _("full"))) { @@ -131,7 +131,7 @@ const char *TICALL ticalcs_memtype_to_string(CalcMemType type) CalcMemType TICALL ticalcs_string_to_memtype(const char *str) { - if (str != NULL) + if (str != nullptr) { if (!strcmp(str, _("free"))) { @@ -148,7 +148,7 @@ CalcMemType TICALL ticalcs_string_to_memtype(const char *str) int TICALL ticalcs_infos_to_string(CalcInfos *infos, char *str, uint32_t maxlen) { - if (infos != NULL) + if (infos != nullptr) { char language_ids[25]; char device_type[6]; diff --git a/libticalcs/trunk/tests/test_ticalcs_2.cc b/libticalcs/trunk/tests/test_ticalcs_2.cc index 7677e24c9..c91edb8c8 100644 --- a/libticalcs/trunk/tests/test_ticalcs_2.cc +++ b/libticalcs/trunk/tests/test_ticalcs_2.cc @@ -160,17 +160,15 @@ static uint64_t registers[8+1] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; static int read_filename(char * filename, const char * message) { - int ret; filename[0] = 0; printf("Enter filename%s: ", message); - ret = scan_print_output_1("", "%" xstr(FILENAME_DATA_SIZE) "s", "%s", filename, filename); + const int ret = scan_print_output_1("", "%" xstr(FILENAME_DATA_SIZE) "s", "%s", filename, filename); return ret; } static int read_varname(CalcHandle* h, VarRequest *vr, const char *prompt) { char buf[256]; - const char *s; int ret = 0; char * endptr; @@ -216,8 +214,8 @@ static int read_varname(CalcHandle* h, VarRequest *vr, const char *prompt) // The string doesn't seem to be a valid numeric value. // Let's try to parse a fext instead. vr->type = tifiles_fext2vartype(h->model, buf); - s = tifiles_vartype2string(h->model, vr->type); - if (s == NULL || *s == 0) + const char* s = tifiles_vartype2string(h->model, vr->type); + if (s == nullptr || *s == 0) { vr->type = tifiles_string2vartype(h->model, buf); } @@ -230,10 +228,9 @@ static int read_varname(CalcHandle* h, VarRequest *vr, const char *prompt) static int build_raw_bytes_from_hex_string(char * buffer, uint32_t maxbuflen, unsigned char * data, uint32_t maxdatalen, uint32_t * length) { int ret = 1; - uint32_t i; uint8_t c = 0; int odd = 0; - for (i = 0; i < maxbuflen; i++) + for (uint32_t i = 0; i < maxbuflen; i++) { if (buffer[i] == 0) { @@ -375,14 +372,13 @@ static int parse_access_type(const char * datatype, unsigned int * endianness, u static int parse_check_uint32(const char * input, uint32_t * val, uint32_t maxval) { - int ret; unsigned int regno; if (nullptr == input) { return 1; } - ret = sscanf(input, "r%u", ®no); + int ret = sscanf(input, "r%u", ®no); if (ret < 1) { ret = !sscanf(input, "%" SCNi32, val); @@ -424,14 +420,13 @@ static int parse_check_uint32(const char * input, uint32_t * val, uint32_t maxva static int parse_check_uint64(const char * input, uint64_t * val) { - int ret; unsigned int regno; if (nullptr == input) { return 1; } - ret = sscanf(input, "r%u", ®no); + int ret = sscanf(input, "r%u", ®no); if (ret < 1) { ret = !sscanf(input, "%" SCNi64, val); @@ -464,10 +459,8 @@ static int parse_check_uint64(const char * input, uint64_t * val) static int parse_check_register(const char * input, unsigned int * regno) { - int ret; - *regno = 0; - ret = sscanf(input, "r%u", regno); + int ret = sscanf(input, "r%u", regno); if (ret == 1) { ret = check_regno(*regno); @@ -488,22 +481,20 @@ static int parse_check_register(const char * input, unsigned int * regno) static int parse_reg_commands_args(char * input, uint64_t * val, uint32_t * regno) { - int ret; - char * token; - char * saveptr = NULL; + char * saveptr = nullptr; - token = STRTOK(input, " ", &saveptr); - if (NULL == token) + const char* token = STRTOK(input, " ", &saveptr); + if (nullptr == token) { fputs("Missing parameter 1\n", stderr); return 1; } - ret = parse_check_uint64(token, val); + int ret = parse_check_uint64(token, val); if (ret) return 1; - token = STRTOK(NULL, " ", &saveptr); - if (NULL == token) + token = STRTOK(nullptr, " ", &saveptr); + if (nullptr == token) { fputs("Missing parameter 2\n", stderr); return 1; @@ -532,7 +523,7 @@ static void hexdump(uint8_t * ptr, uint32_t length) static void print_lc_error(int errnum) { - char *msg = NULL; + char *msg = nullptr; ticables_error_get(errnum, &msg); fprintf(stderr, "Link cable error (code %i)...\n<<%s>>\n", errnum, msg); @@ -545,7 +536,7 @@ typedef int (*FNCT_MENU) (CalcHandle*, int, char *); static int cfg_get(CalcHandle * h, int, char *) { - int ret = -1; + const int ret = -1; fputs("Not implemented\n", stderr); @@ -554,7 +545,7 @@ static int cfg_get(CalcHandle * h, int, char *) static int cfg_set(CalcHandle * h, int, char *) { - int ret = -1; + const int ret = -1; fputs("Not implemented\n", stderr); @@ -563,11 +554,10 @@ static int cfg_set(CalcHandle * h, int, char *) static int sleep(CalcHandle * h, int, char * input) { - int ret; unsigned int delay; printf("Enter delay in tenths of seconds: "); - ret = scan_print_output_1(input, "%u", "%u", &delay, delay); + int ret = scan_print_output_1(input, "%u", "%u", &delay, delay); if (ret < 1) { fputs("Missing parameters\n", stderr); @@ -590,7 +580,7 @@ static int sleep(CalcHandle * h, int, char * input) static int timeout(CalcHandle * h, int, char *) { - int ret = -1; + const int ret = -1; fputs("Not implemented\n", stderr); @@ -599,7 +589,7 @@ static int timeout(CalcHandle * h, int, char *) static int delay(CalcHandle * h, int, char *) { - int ret = -1; + const int ret = -1; fputs("Not implemented\n", stderr); @@ -610,11 +600,10 @@ static int probe_calc(CalcHandle * h, int, char * input) { int m = 0; int p = 0; - int ret; CalcModel model = CALC_NONE; printf("Enter cable & port for probing (c p): "); - ret = scan_print_output_2(input, "%d %d", "%d %d", &m, &p, m, p); + int ret = scan_print_output_2(input, "%d %d", "%d %d", &m, &p, m, p); if (ret < 2) { fputs("Missing parameters\n", stderr); @@ -631,9 +620,7 @@ static int probe_calc(CalcHandle * h, int, char * input) static int is_ready(CalcHandle * h, int, char *) { - int ret; - - ret = ticalcs_calc_isready(h); + const int ret = ticalcs_calc_isready(h); printf("%d Hand-held is %sready !\n", ret, ret ? "not " : ""); return ret; @@ -641,11 +628,10 @@ static int is_ready(CalcHandle * h, int, char *) static int send_key(CalcHandle * h, int, char * input) { - int ret; unsigned int key_value; printf("Enter key value to be sent: "); - ret = scan_print_output_1(input, "%u", "%u", &key_value, key_value); + const int ret = scan_print_output_1(input, "%u", "%u", &key_value, key_value); if (ret < 1) { fputs("Missing parameters\n", stderr); @@ -671,11 +657,10 @@ static int execute(CalcHandle * h, int, char *) static int recv_screen(CalcHandle * h, int, char *) { - int ret; CalcInfos infos; memset((void *)&infos, 0, sizeof(infos)); - ret = ticalcs_calc_get_version(h, &infos); + int ret = ticalcs_calc_get_version(h, &infos); if (!ret) { CalcScreenCoord sc = { SCREEN_CLIPPED, 0, 0, 0, 0, CALC_PIXFMT_MONO }; @@ -698,7 +683,7 @@ static int recv_screen(CalcHandle * h, int, char *) } if (!ret) { - uint8_t* bitmap = NULL; + uint8_t* bitmap = nullptr; ret = ticalcs_calc_recv_screen_rgb888(h, &sc, &bitmap); if (!ret) { @@ -712,9 +697,9 @@ static int recv_screen(CalcHandle * h, int, char *) { ret = 1; FILE * f = fopen(filename, "w+b"); - if (NULL != f) + if (nullptr != f) { - unsigned int count = sc.width * sc.height * 3; + const unsigned int count = sc.width * sc.height * 3; if (count > fwrite((void *)bitmap, 1, sc.width * sc.height * 3, f)) { fprintf(stderr, "Error writing bitmap data\n"); @@ -736,10 +721,9 @@ static int recv_screen(CalcHandle * h, int, char *) static int get_dirlist(CalcHandle * h, int, char *) { - int ret; GNode *vars, *apps; - ret = ticalcs_calc_get_dirlist(h, &vars, &apps); + const int ret = ticalcs_calc_get_dirlist(h, &vars, &apps); if (!ret) { ticalcs_dirlist_display(vars); @@ -753,10 +737,9 @@ static int get_dirlist(CalcHandle * h, int, char *) static int get_memfree(CalcHandle * h, int, char *) { - int ret; uint32_t ram, flash; - ret = ticalcs_calc_get_memfree(h, &ram, &flash); + const int ret = ticalcs_calc_get_memfree(h, &ram, &flash); if (!ret) { printf("RAM: %lu\tFlash: %lu\n", (unsigned long)ram, (unsigned long)flash); @@ -767,11 +750,10 @@ static int get_memfree(CalcHandle * h, int, char *) static int send_backup(CalcHandle * h, int, char *) { - int ret; char filename[FILENAME_DATA_SIZE + 1]; char filename2[FILENAME_DATA_SIZE + 11]; - ret = read_filename(filename, ""); + int ret = read_filename(filename, ""); if (ret < 1) { return 1; @@ -787,11 +769,10 @@ static int send_backup(CalcHandle * h, int, char *) static int recv_backup(CalcHandle * h, int, char *) { - int ret; char filename[FILENAME_DATA_SIZE + 1]; char filename2[FILENAME_DATA_SIZE + 11]; - ret = read_filename(filename, " for backup"); + int ret = read_filename(filename, " for backup"); if (ret < 1) { return 1; @@ -807,12 +788,10 @@ static int recv_backup(CalcHandle * h, int, char *) static int send_var(CalcHandle * h, int, char *) { - int ret; char filename[FILENAME_DATA_SIZE + 1]; - FileContent *content; VarEntry ve; - ret = read_filename(filename, " for variable"); + int ret = read_filename(filename, " for variable"); if (ret < 1) { return 1; @@ -828,8 +807,8 @@ static int send_var(CalcHandle * h, int, char *) } } - content = tifiles_content_create_regular(h->model); - if (content != NULL) + FileContent* content = tifiles_content_create_regular(h->model); + if (content != nullptr) { ret = tifiles_file_read_regular(filename, content); if (!ret) @@ -855,11 +834,10 @@ static int send_var(CalcHandle * h, int, char *) static int recv_var(CalcHandle * h, int, char *) { - int ret; char filename[FILENAME_DATA_SIZE + 1]; VarEntry ve; - ret = read_filename(filename, " for variable"); + int ret = read_filename(filename, " for variable"); if (ret < 1) { return 1; @@ -877,10 +855,9 @@ static int recv_var(CalcHandle * h, int, char *) static int send_var_ns(CalcHandle * h, int, char *) { - int ret; char filename[FILENAME_DATA_SIZE + 1]; - ret = read_filename(filename, " for variable"); + int ret = read_filename(filename, " for variable"); if (ret < 1) { return 1; @@ -893,11 +870,10 @@ static int send_var_ns(CalcHandle * h, int, char *) static int recv_var_ns(CalcHandle * h, int, char *) { - int ret; char filename[FILENAME_DATA_SIZE + 1]; VarRequest *ve; - ret = read_filename(filename, " for variable"); + int ret = read_filename(filename, " for variable"); if (ret < 1) { return 1; @@ -910,11 +886,10 @@ static int recv_var_ns(CalcHandle * h, int, char *) static int send_app(CalcHandle * h, int, char *) { - int ret; char filename[FILENAME_DATA_SIZE + 1]; char filename2[FILENAME_DATA_SIZE + 11]; - ret = read_filename(filename, " for app"); + int ret = read_filename(filename, " for app"); if (ret < 1) { return 1; @@ -930,11 +905,10 @@ static int send_app(CalcHandle * h, int, char *) static int recv_app(CalcHandle * h, int, char *) { - int ret; char filename[FILENAME_DATA_SIZE + 1]; VarEntry ve; - ret = read_filename(filename, " for app"); + int ret = read_filename(filename, " for app"); if (ret < 1) { return 1; @@ -958,10 +932,9 @@ static int recv_app(CalcHandle * h, int, char *) static int send_os(CalcHandle * h, int, char *) { - int ret; char filename[FILENAME_DATA_SIZE + 1]; - ret = read_filename(filename, " for OS"); + int ret = read_filename(filename, " for OS"); if (ret < 1) { return 1; @@ -974,10 +947,9 @@ static int send_os(CalcHandle * h, int, char *) static int recv_idlist(CalcHandle * h, int, char *) { - int ret; uint8_t id[32]; - ret = ticalcs_calc_recv_idlist(h, id); + const int ret = ticalcs_calc_recv_idlist(h, id); if (!ret) { printf("IDLIST: <%s>\n", id); @@ -988,10 +960,9 @@ static int recv_idlist(CalcHandle * h, int, char *) static int dump_rom(CalcHandle * h, int, char *) { - int ret; char filename[FILENAME_DATA_SIZE + 1]; - ret = read_filename(filename, " for ROM / Flash dump"); + int ret = read_filename(filename, " for ROM / Flash dump"); if (ret < 1) { return 1; @@ -1008,10 +979,9 @@ static int dump_rom(CalcHandle * h, int, char *) static int set_clock(CalcHandle * h, int, char *) { - int ret; CalcClock clk; - ret = ticalcs_calc_get_clock(h, &clk); + int ret = ticalcs_calc_get_clock(h, &clk); if (!ret) { ret = ticalcs_calc_set_clock(h, &clk); @@ -1022,10 +992,9 @@ static int set_clock(CalcHandle * h, int, char *) static int get_clock(CalcHandle * h, int, char *) { - int ret; CalcClock clk; - ret = ticalcs_calc_get_clock(h, &clk); + const int ret = ticalcs_calc_get_clock(h, &clk); if (!ret) { ticalcs_clock_show(h->model, &clk); @@ -1074,12 +1043,11 @@ static int new_folder(CalcHandle * h, int, char *) static int get_version(CalcHandle * h, int, char *) { - int ret; CalcInfos infos; char str[2048]; memset((void *)&infos, 0, sizeof(infos)); - ret = ticalcs_calc_get_version(h, &infos); + int ret = ticalcs_calc_get_version(h, &infos); if (!ret) { str[0] = 0; @@ -1095,7 +1063,7 @@ static int get_version(CalcHandle * h, int, char *) static int send_cert(CalcHandle * h, int, char *) { - int ret = -1; + const int ret = -1; fputs("Not implemented\n", stderr); @@ -1104,7 +1072,7 @@ static int send_cert(CalcHandle * h, int, char *) static int recv_cert(CalcHandle * h, int, char *) { - int ret = -1; + const int ret = -1; fputs("Not implemented\n", stderr); @@ -1174,7 +1142,7 @@ static int lock_var(CalcHandle * h, int, char *) static int send_all_vars_backup(CalcHandle * h, int, char *) { - int ret = -1; + const int ret = -1; fputs("Not implemented\n", stderr); @@ -1183,7 +1151,7 @@ static int send_all_vars_backup(CalcHandle * h, int, char *) static int recv_all_vars_backup(CalcHandle * h, int, char *) { - int ret = -1; + const int ret = -1; fputs("Not implemented\n", stderr); @@ -1192,15 +1160,12 @@ static int recv_all_vars_backup(CalcHandle * h, int, char *) static int send_lab_equipment_data(CalcHandle * h, int, char * input) { - int ret; - const uint8_t * ptr; - uint8_t * orig_ptr; CalcLabEquipmentData lab_equipment_data; int model; unsigned int vartype; printf("Enter calc model (usually 1-12, 16-17) and variable type (4 for lists): "); - ret = scan_print_output_2(input, "%d %u", "%d %u", &model, &vartype, model, vartype); + int ret = scan_print_output_2(input, "%d %u", "%d %u", &model, &vartype, model, vartype); if (ret < 2) { fputs("Missing parameters\n", stderr); @@ -1214,11 +1179,11 @@ static int send_lab_equipment_data(CalcHandle * h, int, char * input) } printf("Enter list data as '{...}': \n"); - orig_ptr = (uint8_t *)inbuf + 1024 + 4; - ptr = (const uint8_t *)fgets((char *)orig_ptr, 1024, stdin); + uint8_t* orig_ptr = (uint8_t*)inbuf + 1024 + 4; + const uint8_t* ptr = (const uint8_t*)fgets((char*)orig_ptr, 1024, stdin); ret = 1; - if (NULL != ptr) + if (nullptr != ptr) { lab_equipment_data.type = CALC_LAB_EQUIPMENT_DATA_TYPE_STRING; lab_equipment_data.size = strlen((const char *)ptr) + 1; @@ -1234,13 +1199,12 @@ static int send_lab_equipment_data(CalcHandle * h, int, char * input) static int get_lab_equipment_data(CalcHandle * h, int, char * input) { - int ret; CalcLabEquipmentData lab_equipment_data; int model; unsigned int vartype; printf("Enter calc model (usually 1-12, 16-17) and variable type (4 for lists): "); - ret = scan_print_output_2(input, "%d %u", "%d %u", &model, &vartype, model, vartype); + int ret = scan_print_output_2(input, "%d %u", "%d %u", &model, &vartype, model, vartype); if (ret < 2) { fputs("Missing parameters\n", stderr); @@ -1298,12 +1262,11 @@ static int del_folder(CalcHandle * h, int, char *) static int buffer_set_data(CalcHandle * h, int, char * input) { - int ret; uint32_t offset = 0; uint32_t length = 0; printf("Enter offset: "); - ret = parse_check_uint32(input, &offset, sizeof(pktdata) / 2); + int ret = parse_check_uint32(input, &offset, sizeof(pktdata) / 2); if (ret) return 1; ret = get_hex_input(inbuf, sizeof(inbuf), pktdata + offset, sizeof(pktdata) / 2, &length, "raw data", xstr(INBUF_DATA_SIZE)); @@ -1320,19 +1283,18 @@ static int buffer_get_data(CalcHandle * h, int, char * input) int ret = 0; uint32_t length = pktdata_len; uint32_t offset = 0; - char * token; - char * saveptr = NULL; + char * saveptr = nullptr; printf("Enter nothing, offset, or offset and length: "); - token = STRTOK(input, " ", &saveptr); - if (NULL != token) + const char* token = STRTOK(input, " ", &saveptr); + if (nullptr != token) { // There's at least an offset. ret = parse_check_uint32(token, &offset, sizeof(pktdata)); if (ret) return 1; - token = STRTOK(NULL, " ", &saveptr); - if (NULL != token) + token = STRTOK(nullptr, " ", &saveptr); + if (nullptr != token) { // There's also a length. ret = parse_check_uint32(token, &length, sizeof(pktdata)); @@ -1356,14 +1318,11 @@ static int buffer_get_data(CalcHandle * h, int, char * input) static int buffer_peek_data(CalcHandle * h, int, char * input) { - int ret; unsigned int endianness; unsigned int bytes; uint32_t offset; unsigned int regno; - uint64_t val; - char * token; - char * saveptr = NULL; + char * saveptr = nullptr; if (!pktdata_len) { @@ -1372,18 +1331,18 @@ static int buffer_peek_data(CalcHandle * h, int, char * input) } // Parse input to retrieve access type (e.g. le32), offset, destination register. - token = STRTOK(input, " ", &saveptr); - if (NULL == token) + const char* token = STRTOK(input, " ", &saveptr); + if (nullptr == token) { fputs("Missing parameter 1\n", stderr); return 1; } - ret = parse_access_type(token, &endianness, &bytes); + int ret = parse_access_type(token, &endianness, &bytes); if (ret) return 1; - token = STRTOK(NULL, " ", &saveptr); - if (NULL == token) + token = STRTOK(nullptr, " ", &saveptr); + if (nullptr == token) { fputs("Missing parameter 2\n", stderr); return 1; @@ -1392,8 +1351,8 @@ static int buffer_peek_data(CalcHandle * h, int, char * input) ret = parse_check_uint32(token, &offset, sizeof(pktdata) - bytes); if (ret) return 1; - token = STRTOK(NULL, " ", &saveptr); - if (NULL == token) + token = STRTOK(nullptr, " ", &saveptr); + if (nullptr == token) { fputs("Missing parameter 3\n", stderr); return 1; @@ -1404,11 +1363,11 @@ static int buffer_peek_data(CalcHandle * h, int, char * input) puts("Good"); - val = 0; + uint64_t val = 0; if (!endianness) { // Read LE: MSB are stored last. - uint8_t * ptr = pktdata + offset + bytes; + const uint8_t * ptr = pktdata + offset + bytes; for (unsigned int i = 0; i < bytes; i++) { val |= *--ptr; @@ -1421,7 +1380,7 @@ static int buffer_peek_data(CalcHandle * h, int, char * input) else { // Read BE: MSB are stored first. - uint8_t * ptr = pktdata + offset; + const uint8_t * ptr = pktdata + offset; for (unsigned int i = 0; i < bytes; i++) { val |= *ptr++; @@ -1439,27 +1398,25 @@ static int buffer_peek_data(CalcHandle * h, int, char * input) static int buffer_poke_data(CalcHandle * h, int, char * input) { - int ret; uint32_t offset; unsigned int endianness; unsigned int bytes; uint64_t val; - char * token; - char * saveptr = NULL; + char * saveptr = nullptr; // Parse input to retrieve access type (e.g. le32), offset, destination register. - token = STRTOK(input, " ", &saveptr); - if (NULL == token) + const char* token = STRTOK(input, " ", &saveptr); + if (nullptr == token) { fputs("Missing parameter 1\n", stderr); return 1; } - ret = parse_access_type(token, &endianness, &bytes); + int ret = parse_access_type(token, &endianness, &bytes); if (ret) return 1; - token = STRTOK(NULL, " ", &saveptr); - if (NULL == token) + token = STRTOK(nullptr, " ", &saveptr); + if (nullptr == token) { fputs("Missing parameter 2\n", stderr); return 1; @@ -1468,8 +1425,8 @@ static int buffer_poke_data(CalcHandle * h, int, char * input) ret = parse_check_uint32(token, &offset, sizeof(pktdata) - bytes); if (ret) return 1; - token = STRTOK(NULL, " ", &saveptr); - if (NULL == token) + token = STRTOK(nullptr, " ", &saveptr); + if (nullptr == token) { fputs("Missing parameter 3\n", stderr); return 1; @@ -1514,7 +1471,7 @@ static int buffer_poke_data(CalcHandle * h, int, char * input) static int buffer_clear_data(CalcHandle * h, int, char * input) { - int ret = 0; + const int ret = 0; memset((void *)pktdata, 0, sizeof(pktdata)); pktdata_len = 0; @@ -1524,11 +1481,10 @@ static int buffer_clear_data(CalcHandle * h, int, char * input) static /* __attribute__((always_inline)) */ int reg_op(CalcHandle * h, int, char * input, void (* op)(unsigned int regno, uint64_t val)) { - int ret; uint64_t val; unsigned int regno; - ret = parse_reg_commands_args(input, &val, ®no); + const int ret = parse_reg_commands_args(input, &val, ®no); if (ret) return 1; else { @@ -1570,9 +1526,7 @@ static int reg_xor(CalcHandle * h, int, char * input) static int raw_send_data(CalcHandle * h, int, char * input) { - int ret; - - ret = buffer_set_data(h, 1, (char *)"0"); + int ret = buffer_set_data(h, 1, (char*)"0"); if (!ret) { printf("raw_send_data: %u\n", pktdata_len); @@ -1587,19 +1541,18 @@ static int raw_send_data_from_buffer(CalcHandle * h, int, char * input) int ret; uint32_t offset = 0; uint32_t length = 0; - char * token; - char * saveptr = NULL; + char * saveptr = nullptr; printf("Enter nothing, offset, or offset and length: "); - token = STRTOK(input, " ", &saveptr); - if (NULL != token) + const char* token = STRTOK(input, " ", &saveptr); + if (nullptr != token) { // There's at least an offset. ret = parse_check_uint32(token, &offset, sizeof(pktdata) / 2); if (ret) return 1; - token = STRTOK(NULL, " ", &saveptr); - if (NULL != token) + token = STRTOK(nullptr, " ", &saveptr); + if (nullptr != token) { // There's also a length. ret = parse_check_uint32(token, &length, sizeof(pktdata) / 2); @@ -1616,11 +1569,10 @@ static int raw_send_data_from_buffer(CalcHandle * h, int, char * input) static int raw_recv_data(CalcHandle * h, int, char * input) { - int ret; uint32_t length; printf("Enter length of raw data to be read: "); - ret = parse_check_uint32(input, &length, sizeof(pktdata) / 2); + int ret = parse_check_uint32(input, &length, sizeof(pktdata) / 2); if (ret) return 1; fprintf(stderr, "%u\n", length); @@ -1637,7 +1589,6 @@ static int raw_recv_data(CalcHandle * h, int, char * input) static int dbus_send_pkt(CalcHandle * h, int, char * input) { - int ret; uint8_t target = 0; uint8_t cmd = 0; uint16_t slen = 0; @@ -1645,7 +1596,8 @@ static int dbus_send_pkt(CalcHandle * h, int, char * input) // Entering the length is necessary for e.g. the simple commands, see cmd68k.cc and cmdz80.cc. printf("Enter target (mid), cmd and length: "); - ret = scan_print_output_3(input, "%" SCNi8 " %" SCNi8 " %" SCNi16, "%" PRIu8 " %" PRIu8 " %" PRIu16, &target, &cmd, &slen, target, cmd, slen); + int ret = scan_print_output_3(input, "%" SCNi8 " %" SCNi8 " %" SCNi16, "%" PRIu8 " %" PRIu8 " %" PRIu16, &target, &cmd, &slen, target, cmd, + slen); if (ret < 3) { fputs("Missing parameters\n", stderr); @@ -1671,7 +1623,7 @@ static int dbus_send_pkt(CalcHandle * h, int, char * input) fputs("Note: declared length is larger than the given hex data\n", stderr); } // Special case for packets without data. - ret = dbus_send(h, target, cmd, slen, slen == 0 ? NULL : pktdata); + ret = dbus_send(h, target, cmd, slen, slen == 0 ? nullptr : pktdata); printf("%d\n", ret); } @@ -1680,11 +1632,10 @@ static int dbus_send_pkt(CalcHandle * h, int, char * input) static int dbus_recv_header(CalcHandle * h, int, char * input) { - int ret; uint32_t offset = 0; printf("Enter nothing or offset: "); - ret = parse_check_uint32(input, &offset, sizeof(pktdata) / 2); + int ret = parse_check_uint32(input, &offset, sizeof(pktdata) / 2); // Don't need to test ret here, the argument is optional ret = dbus_recv_header(h, pktdata + offset, pktdata + offset + 1, (uint16_t *)(pktdata + offset + 2)); @@ -1708,19 +1659,18 @@ static int dbus_recv_data(CalcHandle * h, int, char * input) uint32_t offset = 0; uint32_t length = 0; uint16_t slength; - char * token; - char * saveptr = NULL; + char * saveptr = nullptr; printf("Enter offset and length: "); - token = STRTOK(input, " ", &saveptr); - if (NULL != token) + const char* token = STRTOK(input, " ", &saveptr); + if (nullptr != token) { // There's at least an offset. ret = parse_check_uint32(token, &offset, sizeof(pktdata)); if (ret) return 1; - token = STRTOK(NULL, " ", &saveptr); - if (NULL != token) + token = STRTOK(nullptr, " ", &saveptr); + if (nullptr != token) { // There's also a length. ret = parse_check_uint32(token, &length, sizeof(pktdata) / 2); @@ -1762,11 +1712,10 @@ static int dbus_recv_data(CalcHandle * h, int, char * input) static int dbus_recv(CalcHandle * h, int, char * input) { - int ret; uint32_t offset = 0; printf("Enter nothing or offset: "); - ret = parse_check_uint32(input, &offset, sizeof(pktdata) / 2); + int ret = parse_check_uint32(input, &offset, sizeof(pktdata) / 2); // Don't need to test ret here, the argument is optional ret = dbus_recv(h, pktdata + offset, pktdata + offset + 1, (uint16_t *)(pktdata + offset + 2), pktdata + offset + 4); @@ -1786,7 +1735,7 @@ static int dbus_recv(CalcHandle * h, int, char * input) static int dusb_send_rpkt(CalcHandle * h, int, char *) { - int ret = -1; + const int ret = -1; fputs("Not implemented\n", stderr); @@ -1795,7 +1744,7 @@ static int dusb_send_rpkt(CalcHandle * h, int, char *) static int dusb_recv_rpkt(CalcHandle * h, int, char *) { - int ret = -1; + const int ret = -1; fputs("Not implemented\n", stderr); @@ -1804,7 +1753,7 @@ static int dusb_recv_rpkt(CalcHandle * h, int, char *) static int nsp_send_rpkt(CalcHandle * h, int, char *) { - int ret = -1; + const int ret = -1; fputs("Not implemented\n", stderr); @@ -1813,7 +1762,7 @@ static int nsp_send_rpkt(CalcHandle * h, int, char *) static int nsp_recv_rpkt(CalcHandle * h, int, char *) { - int ret = -1; + const int ret = -1; fputs("Not implemented\n", stderr); @@ -1822,10 +1771,9 @@ static int nsp_recv_rpkt(CalcHandle * h, int, char *) static int rdmp_send_dumper(CalcHandle * h, int, char * input) { - int ret; char filename[FILENAME_DATA_SIZE + 1]; - ret = read_filename(filename, " for variable"); + int ret = read_filename(filename, " for variable"); if (ret < 1) { return 1; @@ -1838,10 +1786,9 @@ static int rdmp_send_dumper(CalcHandle * h, int, char * input) static int rdmp_is_ready(CalcHandle * h, int, char * input) { - int ret; char filename[FILENAME_DATA_SIZE + 1]; - ret = read_filename(filename, " for variable"); + int ret = read_filename(filename, " for variable"); if (ret < 1) { return 1; @@ -1854,10 +1801,9 @@ static int rdmp_is_ready(CalcHandle * h, int, char * input) static int rdmp_read_dump(CalcHandle * h, int, char * input) { - int ret; char filename[FILENAME_DATA_SIZE + 1]; - ret = read_filename(filename, " for output ROM dump"); + int ret = read_filename(filename, " for output ROM dump"); if (ret < 1) { return 1; @@ -1870,12 +1816,11 @@ static int rdmp_read_dump(CalcHandle * h, int, char * input) static int dbus_dissect_pkt(CalcHandle * h, int, char * input) { - int ret; uint32_t length = 0; int model; printf("Enter calc model (usually 1-12, 16-17): "); - ret = scan_print_output_1(input, "%d", "%d", &model, model); + int ret = scan_print_output_1(input, "%d", "%d", &model, model); if (ret < 1) { fputs("Missing parameters\n", stderr); @@ -1893,14 +1838,13 @@ static int dbus_dissect_pkt(CalcHandle * h, int, char * input) static int dusb_dissect_rpkt(CalcHandle * h, int, char * input) { - int ret; - uint8_t ep = 2; // Assume PC -> TI. + const uint8_t ep = 2; // Assume PC -> TI. uint8_t first = 1; // Assume all packets are first packets. uint32_t length = 0; int model; printf("Enter calc model (usually 13, 14, 18-21): "); - ret = scan_print_output_1(input, "%d", "%d", &model, model); + int ret = scan_print_output_1(input, "%d", "%d", &model, model); if (ret < 1) { fputs("Missing parameters\n", stderr); @@ -1918,13 +1862,12 @@ static int dusb_dissect_rpkt(CalcHandle * h, int, char * input) static int nsp_dissect_rpkt(CalcHandle * h, int, char * input) { - int ret; - uint8_t ep = 2; // Assume PC -> TI. + const uint8_t ep = 2; // Assume PC -> TI. uint32_t length = 0; int model; printf("Enter calc model (usually 15): "); - ret = scan_print_output_1(input, "%d", "%d", &model, model); + int ret = scan_print_output_1(input, "%d", "%d", &model, model); if (ret < 1) { fputs("Missing parameters\n", stderr); @@ -1942,15 +1885,13 @@ static int nsp_dissect_rpkt(CalcHandle * h, int, char * input) static int ti83p_dump(CalcHandle * h, int, char * input) { - int ret; char filename[FILENAME_DATA_SIZE + 7]; int page; uint16_t length; - FILE *f; filename[0] = 0; printf("Enter page number for dumping: "); - ret = scan_print_output_1(input, "%d", "%d", &page, page); + int ret = scan_print_output_1(input, "%d", "%d", &page, page); if (ret < 1) { fputs("Missing parameters\n", stderr); @@ -1963,13 +1904,13 @@ static int ti83p_dump(CalcHandle * h, int, char * input) return 1; } - f = fopen(filename, "wb"); - if (f != NULL) + FILE* f = fopen(filename, "wb"); + if (f != nullptr) { //memset(pktdata, 0, sizeof(pktdata)); if ( (ti73_send_DUMP(h, (uint16_t)page) == 0) - && (ti73_recv_ACK(h, NULL) == 0) + && (ti73_recv_ACK(h, nullptr) == 0) && (ti73_recv_XDP(h, &length, pktdata) == 0) && (ti73_send_ACK(h) == 0)) { @@ -1983,13 +1924,11 @@ static int ti83p_dump(CalcHandle * h, int, char * input) static int ti83p_eke(CalcHandle * h, int, char *) { - int ret; - - ret = ti73_send_EKE(h); + int ret = ti73_send_EKE(h); if (!ret) { puts("EKE successfully sent"); - ret = ti73_recv_ACK(h, NULL); + ret = ti73_recv_ACK(h, nullptr); if (!ret) { puts("ACK received"); @@ -2001,13 +1940,11 @@ static int ti83p_eke(CalcHandle * h, int, char *) static int ti83p_dke(CalcHandle * h, int, char *) { - int ret; - - ret = ti73_send_DKE(h); + int ret = ti73_send_DKE(h); if (!ret) { puts("DKE successfully sent"); - ret = ti73_recv_ACK(h, NULL); + ret = ti73_recv_ACK(h, nullptr); if (!ret) { puts("ACK received"); @@ -2019,13 +1956,11 @@ static int ti83p_dke(CalcHandle * h, int, char *) static int ti83p_eld(CalcHandle * h, int, char *) { - int ret; - - ret = ti73_send_ELD(h); + int ret = ti73_send_ELD(h); if (!ret) { puts("ELD successfully sent"); - ret = ti73_recv_ACK(h, NULL); + ret = ti73_recv_ACK(h, nullptr); if (!ret) { puts("ACK received"); @@ -2037,13 +1972,11 @@ static int ti83p_eld(CalcHandle * h, int, char *) static int ti83p_dld(CalcHandle * h, int, char *) { - int ret; - - ret = ti73_send_DLD(h); + int ret = ti73_send_DLD(h); if (!ret) { puts("DLD successfully sent"); - ret = ti73_recv_ACK(h, NULL); + ret = ti73_recv_ACK(h, nullptr); if (!ret) { puts("ACK received"); @@ -2055,14 +1988,13 @@ static int ti83p_dld(CalcHandle * h, int, char *) static int ti83p_gid(CalcHandle * h, int, char *) { - int ret; uint16_t length; - ret = ti73_send_GID(h); + int ret = ti73_send_GID(h); if (!ret) { puts("GID successfully sent"); - ret = ti73_recv_ACK(h, NULL); + ret = ti73_recv_ACK(h, nullptr); if (!ret) { puts("ACK received"); @@ -2089,10 +2021,9 @@ static int ti83p_gid(CalcHandle * h, int, char *) static int ti83p_rid(CalcHandle * h, int, char *) { - int ret; uint16_t length; - ret = ti73_send_RID(h); + int ret = ti73_send_RID(h); if (!ret) { puts("RID successfully sent"); @@ -2118,10 +2049,9 @@ static int ti83p_rid(CalcHandle * h, int, char *) static int ti83p_sid(CalcHandle * h, int, char *) { - int ret; uint32_t length = 0; - ret = get_hex_input(inbuf, sizeof(inbuf), pktdata, 32, &length, "raw data", xstr(INBUF_DATA_SIZE)); + int ret = get_hex_input(inbuf, sizeof(inbuf), pktdata, 32, &length, "raw data", xstr(INBUF_DATA_SIZE)); if (!ret) { pktdata_len = length; @@ -2131,7 +2061,7 @@ static int ti83p_sid(CalcHandle * h, int, char *) if (!ret) { puts("SID successfully sent"); - ret = ti73_recv_ACK(h, NULL); + ret = ti73_recv_ACK(h, nullptr); if (!ret) { puts("ACK successfully received"); @@ -2149,17 +2079,14 @@ static int ti83p_sid(CalcHandle * h, int, char *) static int dusb_get_param_ids(CalcHandle * h, int, char *) { - int ret; uint32_t length = 0; - ret = get_hex_input(inbuf, sizeof(inbuf), pktdata2, 512 * 2, &length, "parameter IDs", xstr(INBUF_DATA_SIZE)); + int ret = get_hex_input(inbuf, sizeof(inbuf), pktdata2, 512 * 2, &length, "parameter IDs", xstr(INBUF_DATA_SIZE)); if (!ret) { if ((length & 1) == 0) { - DUSBCalcParam **params; - - params = dusb_cp_new_array(h, length / 2); + DUSBCalcParam** params = dusb_cp_new_array(h, length / 2); ret = dusb_cmd_s_param_request(h, length / 2, (uint16_t *)pktdata2); if (!ret) { @@ -2169,11 +2096,10 @@ static int dusb_get_param_ids(CalcHandle * h, int, char *) for (uint32_t i = 0; i < length / 2; i++) { printf("%04X\t%s\t%04X (%u)\n\t\t", params[i]->id, params[i]->ok ? "OK" : "NOK", params[i]->size, params[i]->size); - if (params[i]->ok && params[i]->size > 0 && params[i]->data != NULL) + if (params[i]->ok && params[i]->size > 0 && params[i]->data != nullptr) { - uint16_t j; - uint8_t * ptr = params[i]->data; - for (j = 0; j < params[i]->size;) + const uint8_t * ptr = params[i]->data; + for (uint16_t j = 0; j < params[i]->size;) { printf("%02X ", *ptr++); if (!(++j & 15)) @@ -2199,14 +2125,13 @@ static int dusb_get_param_ids(CalcHandle * h, int, char *) static int dusb_set_param_id(CalcHandle * h, int, char * input) { - int ret; uint32_t length = 0; unsigned int param_id; uint8_t * data = (uint8_t *)dusb_cp_alloc_data(h, 2048); printf("Enter DUSB parameter ID to be set (usually < 0x60): "); - ret = scan_print_output_1(input, "%u", "%u", ¶m_id, param_id); + int ret = scan_print_output_1(input, "%u", "%u", ¶m_id, param_id); if (ret < 1) { dusb_cp_free_data(h, data); @@ -2217,9 +2142,7 @@ static int dusb_set_param_id(CalcHandle * h, int, char * input) ret = get_hex_input(inbuf, sizeof(inbuf), pktdata2, sizeof(pktdata2), &length, "raw data", xstr(INBUF_DATA_SIZE)); if (!ret) { - DUSBCalcParam *param; - - param = dusb_cp_new_ex(h, param_id, length, data); + DUSBCalcParam* param = dusb_cp_new_ex(h, param_id, length, data); ret = dusb_cmd_s_param_set(h, param); dusb_cp_del(h, param); // This frees data. @@ -2269,10 +2192,9 @@ static int nsp_send_key(CalcHandle * h, int, char *) static int nsp_remote_mgmt(CalcHandle * h, int, char *) { - int ret; static uint8_t data[9] = { 0x00, 0x00, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00 }; - ret = is_ready(h, 1, NULL); + int ret = is_ready(h, 1, nullptr); if (!ret) { printf("Packet 1\n"); @@ -2281,7 +2203,7 @@ static int nsp_remote_mgmt(CalcHandle * h, int, char *) if (!ret || ret == ERR_INVALID_PACKET) { uint32_t size; - uint8_t * data2 = NULL; + uint8_t * data2 = nullptr; printf("Packet 2\n"); ret = nsp_cmd_r_generic_data(h, &size, &data2); g_free(data2); @@ -2298,7 +2220,7 @@ static int cables_event_hook(CableHandle * handle, uint32_t event_count, const C { int ret = 0; - if (NULL != handle && NULL != event) + if (nullptr != handle && nullptr != event) { // TODO } @@ -2314,7 +2236,7 @@ static int calcs_event_hook(CalcHandle * handle, uint32_t event_count, const Cal { int ret = 0; - if (NULL != handle && NULL != event) + if (nullptr != handle && nullptr != event) { // TODO } @@ -2343,8 +2265,8 @@ static menu_entry fnct_menu[] = { NULL, NULL, 0, NULL } // IMPORTANT NOTES: for backwards compatibility, after a scriptable name was defined, it shall never be changed. - { "GEN Exit now", "exit", 4, NULL }, // 0 - { "GEN Exit if previous operation failed", "exit_if_failed", 14, NULL }, + { "GEN Exit now", "exit", 4, nullptr }, // 0 + { "GEN Exit if previous operation failed", "exit_if_failed", 14, nullptr }, NULL_ENTRY, DEFINE_MENU_ENTRY("CFG Get config value", cfg_get), DEFINE_MENU_ENTRY("CFG Set config value", cfg_set), @@ -2480,12 +2402,11 @@ int main(int argc, char **argv) CableModel cable_model = CABLE_NUL; CablePort port_number = PORT_1; CalcModel calc_model = CALC_NONE; - CableHandle* cable = NULL; - CalcHandle* calc = NULL; + CableHandle* cable = nullptr; + CalcHandle* calc = nullptr; int err = 0, preverr = 0, i; unsigned int j; int do_exit = 0; - char* colon; int do_probe = 1; int quiet = 0; int first = 1; @@ -2494,7 +2415,7 @@ int main(int argc, char **argv) { if (i == 'c') { - colon = strchr(optarg, ':'); + char* colon = strchr(optarg, ':'); if (colon) { *colon = 0; @@ -2569,7 +2490,7 @@ int main(int argc, char **argv) printf("Cable is %d (%s), port is #%d\n", cable_model, ticables_model_to_string(cable_model), port_number); cable = ticables_handle_new(cable_model, port_number); - if (cable == NULL) + if (cable == nullptr) { fprintf(stderr, "ticables_handle_new failed\n"); goto end; @@ -2588,7 +2509,7 @@ int main(int argc, char **argv) printf("Calc is %d (%s)\n", calc_model, ticalcs_model_to_string(calc_model)); calc = ticalcs_handle_new(calc_model); - if (calc == NULL) + if (calc == nullptr) { fprintf(stderr, "ticalcs_handle_new failed\n"); goto end; @@ -2607,7 +2528,6 @@ int main(int argc, char **argv) do { - char * ptr; unsigned int choice; // Display menu printf("Choose an action:\n"); @@ -2615,7 +2535,7 @@ int main(int argc, char **argv) { for (i = 0, j = 0; i < (int)(sizeof(fnct_menu)/sizeof(fnct_menu[0])); i++) { - if (NULL != fnct_menu[i].desc) + if (nullptr != fnct_menu[i].desc) { printf("%2d. %-45s", j, fnct_menu[i].desc); j++; @@ -2629,10 +2549,10 @@ int main(int argc, char **argv) } inbuf2[0] = 0; - ptr = fgets(inbuf2, 128, stdin); + char* ptr = fgets(inbuf2, 128, stdin); //printf("%d %02X\n", err, inbuf2[0]); - if (NULL == ptr) + if (nullptr == ptr) { /* // Couldn't read a single char; try again, in a rate-limited way. #ifdef __WIN32__ @@ -2719,7 +2639,7 @@ int main(int argc, char **argv) { // strstr and the second check are used to cope with names which are prefixes of others, e.g. send_var / send_var_ns, // while allowing for other parameters on the same line. - if (NULL != fnct_menu[i].scriptable_name) + if (nullptr != fnct_menu[i].scriptable_name) { if ( (strstr(inbuf2, fnct_menu[i].scriptable_name) == inbuf2) && (inbuf2[fnct_menu[i].scriptable_name_len] != '_') @@ -2749,7 +2669,7 @@ int main(int argc, char **argv) { for (i = 2, j = 2; i < (int)(sizeof(fnct_menu)/sizeof(fnct_menu[0])); i++) { - if (NULL != fnct_menu[i].fnct) + if (nullptr != fnct_menu[i].fnct) { if (j == choice) { diff --git a/libticalcs/trunk/tests/torture_ticalcs.cc b/libticalcs/trunk/tests/torture_ticalcs.cc index a3bcf3821..92ed19220 100644 --- a/libticalcs/trunk/tests/torture_ticalcs.cc +++ b/libticalcs/trunk/tests/torture_ticalcs.cc @@ -28,11 +28,7 @@ FUNCTION(__VA_ARGS__); fprintf(stderr, "%d\n", __LINE__) static void torture_ticalcs() { - CalcHandle * handle; - CableHandle * cable; - CalcUpdate * update; - -// error.c + // error.c PRINTF(ticalcs_error_get, INT, -1, nullptr); PRINTFVOID(ticalcs_error_free, nullptr); // ticalcs.c @@ -40,7 +36,7 @@ static void torture_ticalcs() PRINTF(ticalcs_supported_calcs, X64); PRINTF(ticalcs_supported_protocols, X32); PRINTF(ticalcs_max_calc_function_idx, UINT); - handle = ticalcs_handle_new((CalcModel)- 1); + CalcHandle* handle = ticalcs_handle_new((CalcModel)-1); PRINTF(, PTR, handle); ticalcs_handle_del(handle); PRINTF(ticalcs_handle_del, INT, nullptr); @@ -49,10 +45,10 @@ static void torture_ticalcs() PRINTF(ticalcs_cable_attach, INT, nullptr, (CableHandle *)0x12345678); PRINTF(ticalcs_cable_detach, INT, nullptr); - cable = ticalcs_cable_get(nullptr); + CableHandle* cable = ticalcs_cable_get(nullptr); PRINTF(, PTR, cable); PRINTF(ticalcs_update_set, INT, nullptr, (CalcUpdate *)0x12345678); - update = ticalcs_update_get(nullptr); + CalcUpdate* update = ticalcs_update_get(nullptr); PRINTF(, PTR, update); PRINTF(ticalcs_model_supports_dbus, INT, CALC_NONE); PRINTF(ticalcs_model_supports_dusb, INT, CALC_NONE); @@ -277,9 +273,7 @@ static void torture_ticalcs() static void torture_nsp() { - void * ptr; - -// nsp_rpkt.c + // nsp_rpkt.c PRINTF(nsp_addr2name, STR, 0); PRINTF(nsp_sid2name, STR, 0); PRINTF(nsp_dissect, INT, CALC_NONE, nullptr, (const uint8_t*)0x12345678, 8, 2); @@ -290,7 +284,7 @@ static void torture_nsp() PRINTFVOID(nsp_vtl_pkt_fill, nullptr, 0x12345678, 0x1234, 0x1234, 0x1234, 0x1234, 0x12, nullptr); PRINTFVOID(nsp_vtl_pkt_del, nullptr, (NSPVirtualPacket*)0x12345678); PRINTFVOID(nsp_vtl_pkt_del, (CalcHandle*)0x12345678, nullptr); - ptr = nsp_vtl_pkt_alloc_data(nullptr, 0); + void* ptr = nsp_vtl_pkt_alloc_data(nullptr, 0); PRINTF(, PTR, ptr); nsp_vtl_pkt_free_data(nullptr, ptr); @@ -394,7 +388,6 @@ static void torture_nsp() static void torture_dusb() { - void* ptr; const DUSBModeSet mode = DUSB_MODE_STARTUP; // dusb_rpkt.c @@ -408,7 +401,7 @@ static void torture_dusb() PRINTFVOID(dusb_vtl_pkt_fill, nullptr, 0, 0, (uint8_t*)0x12345678); PRINTFVOID(dusb_vtl_pkt_del, nullptr, (DUSBVirtualPacket*)0x12345678); PRINTFVOID(dusb_vtl_pkt_del, (CalcHandle*)0x12345678, nullptr); - ptr = dusb_vtl_pkt_alloc_data(nullptr, 0); + void* ptr = dusb_vtl_pkt_alloc_data(nullptr, 0); PRINTF(, PTR, ptr); dusb_vtl_pkt_free_data(nullptr, ptr); diff --git a/libticonv/trunk/src/charset.cc b/libticonv/trunk/src/charset.cc index 4595a4271..45c897fb8 100644 --- a/libticonv/trunk/src/charset.cc +++ b/libticonv/trunk/src/charset.cc @@ -41,14 +41,14 @@ static unsigned short* ticonv_nonusb_to_utf16(const unsigned long * charset, con const unsigned char *p = (const unsigned char *)ti; unsigned short *q = utf16; - if (ti == NULL || utf16 == NULL) + if (ti == nullptr || utf16 == nullptr) { - return NULL; + return nullptr; } while (*p) { - unsigned long c = charset[*(p++)]; + const unsigned long c = charset[*(p++)]; if (c < 0x10000) { *(q++) = (unsigned short)c; @@ -66,17 +66,15 @@ static unsigned short* ticonv_nonusb_to_utf16(const unsigned long * charset, con static unsigned short * ticonv_usb_to_utf16(const char *ti, unsigned short *utf16) { - unsigned short *tmp; - - if (ti == NULL || utf16 == NULL) + if (ti == nullptr || utf16 == nullptr) { - return NULL; + return nullptr; } - tmp = ticonv_utf8_to_utf16(ti); - if (tmp == NULL) + unsigned short* tmp = ticonv_utf8_to_utf16(ti); + if (tmp == nullptr) { - return NULL; + return nullptr; } memcpy(utf16, tmp, 2 * ticonv_utf16_strlen(tmp)); @@ -90,9 +88,9 @@ static char * ticonv_utf16_to_nonusb(const unsigned long * charset, const unsign const unsigned short *p = utf16; unsigned char *q = (unsigned char *)ti; - if (utf16 == NULL || ti == NULL) + if (utf16 == nullptr || ti == nullptr) { - return NULL; + return nullptr; } while (*p) @@ -133,9 +131,8 @@ static char * ticonv_utf16_to_nonusb(const unsigned long * charset, const unsign } else { - unsigned int i; *q = '?'; - for (i = 0; i < 256; i++) { + for (unsigned int i = 0; i < 256; i++) { if (charset[i] == c) { *q = i; break; @@ -151,17 +148,15 @@ static char * ticonv_utf16_to_nonusb(const unsigned long * charset, const unsign static char* ticonv_utf16_to_usb(const unsigned short *utf16, char *ti) { - char *tmp; - - if (utf16 == NULL || ti == NULL) + if (utf16 == nullptr || ti == nullptr) { - return NULL; + return nullptr; } - tmp = ticonv_utf16_to_utf8(utf16); - if (tmp == NULL) + char* tmp = ticonv_utf16_to_utf8(utf16); + if (tmp == nullptr) { - return NULL; + return nullptr; } strcpy(ti, tmp); @@ -466,9 +461,9 @@ char* TICALL ticonv_utf16_to_ti80(const unsigned short *utf16, char *ti) const unsigned short *p = utf16; unsigned char *q = (unsigned char *)ti; - if (utf16 == NULL || ti == NULL) + if (utf16 == nullptr || ti == nullptr) { - return NULL; + return nullptr; } while (*p) @@ -748,9 +743,9 @@ char* TICALL ticonv_utf16_to_ti83p(const unsigned short *utf16, char *ti) const unsigned short *p = utf16; unsigned char *q = (unsigned char *)ti; - if (utf16 == NULL || ti == NULL) + if (utf16 == nullptr || ti == nullptr) { - return NULL; + return nullptr; } while (*p) diff --git a/libticonv/trunk/src/filename.cc b/libticonv/trunk/src/filename.cc index 31f57be2c..2e86cedf0 100644 --- a/libticonv/trunk/src/filename.cc +++ b/libticonv/trunk/src/filename.cc @@ -55,27 +55,27 @@ **/ char* TICALL ticonv_utf16_to_gfe(CalcModel model, const unsigned short *src) { - int is_utf8 = ticonv_environment_is_utf8(); + const int is_utf8 = ticonv_environment_is_utf8(); const char *str; - unsigned short *utf16_src, *p; - unsigned short *utf16_dst, *q; + unsigned short *utf16_src; + unsigned short *utf16_dst; char *dst; - if (src == NULL) + if (src == nullptr) { - return NULL; + return nullptr; } // detokenization to UTF-16 - p = utf16_src = (unsigned short *)src; - q = utf16_dst = (unsigned short *)g_malloc0(18*ticonv_utf16_strlen(utf16_src)+2); + unsigned short* p = utf16_src = (unsigned short*)src; + unsigned short* q = utf16_dst = (unsigned short*)g_malloc0(18 * ticonv_utf16_strlen(utf16_src) + 2); // conversion from UTF-16 to UTF-16 if (ticonv_model_is_ti68k(model) && !is_utf8) { while (*p) { - unsigned long msb = *p & 0xff00; + const unsigned long msb = *p & 0xff00; if (!msb) { @@ -83,7 +83,6 @@ char* TICALL ticonv_utf16_to_gfe(CalcModel model, const unsigned short *src) } else { - gunichar2 *str2; glong ir, iw; switch (*p) @@ -113,7 +112,7 @@ char* TICALL ticonv_utf16_to_gfe(CalcModel model, const unsigned short *src) default: str = ""; break; } - str2 = g_utf8_to_utf16(str, -1, &ir, &iw, NULL); + gunichar2* str2 = g_utf8_to_utf16(str, -1, &ir, &iw, nullptr); memcpy(q, str2, (iw+1) * sizeof(unsigned short)); g_free(str2); @@ -127,7 +126,7 @@ char* TICALL ticonv_utf16_to_gfe(CalcModel model, const unsigned short *src) { while (*p) { - unsigned long msb = *p & 0xff00; + const unsigned long msb = *p & 0xff00; if (!msb) { @@ -141,7 +140,6 @@ char* TICALL ticonv_utf16_to_gfe(CalcModel model, const unsigned short *src) } else { - gunichar2 *str2; glong ir, iw; switch(*p) @@ -171,7 +169,7 @@ char* TICALL ticonv_utf16_to_gfe(CalcModel model, const unsigned short *src) default: str = ""; break; } - str2 = g_utf8_to_utf16(str, -1, &ir, &iw, NULL); + gunichar2* str2 = g_utf8_to_utf16(str, -1, &ir, &iw, nullptr); memcpy(q, str2, (iw+1) * sizeof(gunichar2)); g_free(str2); @@ -211,12 +209,10 @@ char* TICALL ticonv_utf16_to_gfe(CalcModel model, const unsigned short *src) // UTF-16 to UTF-8 to GFE encoding { - gchar *utf8; - - utf8 = g_utf16_to_utf8(utf16_dst, -1, NULL, NULL, NULL); + gchar* utf8 = g_utf16_to_utf8(utf16_dst, -1, nullptr, nullptr, nullptr); g_free(utf16_dst); - dst = g_filename_from_utf8(utf8, -1, NULL, NULL, NULL); + dst = g_filename_from_utf8(utf8, -1, nullptr, nullptr, nullptr); g_free(utf8); } @@ -247,10 +243,10 @@ void TICALL ticonv_gfe_free(char *src) **/ char* TICALL ticonv_gfe_to_zfe(CalcModel model, const char *src_) { - char *src, *p; - char *dst, *q; + char *src; + char *dst; - if (src_ == NULL) + if (src_ == nullptr) { return g_strdup(""); } @@ -260,8 +256,8 @@ char* TICALL ticonv_gfe_to_zfe(CalcModel model, const char *src_) // ticonv_utf16_to_gfe. if (!ticonv_environment_has_utf8_filenames()) return g_strdup(src_); - p = src = (char *)src_; - q = dst = (char *)g_malloc0(18*strlen(src)+1); + const char* p = src = (char*)src_; + char* q = dst = (char*)g_malloc0(18 * strlen(src) + 1); while(*p) { @@ -335,7 +331,7 @@ int TICALL ticonv_environment_is_utf8(void) #ifdef __WIN32__ return G_WIN32_HAVE_WIDECHAR_API(); #else - return g_get_charset(NULL); + return g_get_charset(nullptr); #endif } @@ -348,5 +344,5 @@ int TICALL ticonv_environment_is_utf8(void) **/ int TICALL ticonv_environment_has_utf8_filenames(void) { - return g_get_filename_charsets(NULL); + return g_get_filename_charsets(nullptr); } diff --git a/libticonv/trunk/src/ticonv.cc b/libticonv/trunk/src/ticonv.cc index 923e75fea..02041d978 100644 --- a/libticonv/trunk/src/ticonv.cc +++ b/libticonv/trunk/src/ticonv.cc @@ -62,7 +62,7 @@ const char *TICALL ticonv_version_get(void) size_t TICALL ticonv_utf16_strlen(const unsigned short *str) { size_t l = 0; - if (str != NULL) + if (str != nullptr) { const unsigned short *p = str; while (*(p++)) @@ -87,17 +87,16 @@ size_t TICALL ticonv_utf16_strlen(const unsigned short *str) **/ unsigned short* ticonv_utf8_to_utf16(const char *str) { - gunichar2* dst; const gchar* src = str; - GError *error = NULL; + GError *error = nullptr; - if (str == NULL) + if (str == nullptr) { ticonv_critical("%s: str is NULL", __FUNCTION__); - return NULL; + return nullptr; } - dst = g_utf8_to_utf16(src, -1, NULL, NULL, &error); + gunichar2* dst = g_utf8_to_utf16(src, -1, nullptr, nullptr, &error); if (error) { ticonv_critical("%s", error->message); @@ -128,16 +127,15 @@ void TICALL ticonv_utf16_free(unsigned short *str) char* ticonv_utf16_to_utf8(const unsigned short *str) { const gunichar2* src = str; - gchar* dst; - GError *error = NULL; + GError *error = nullptr; - if (str == NULL) + if (str == nullptr) { ticonv_critical("%s: str is NULL", __FUNCTION__); - return NULL; + return nullptr; } - dst = g_utf16_to_utf8(src, -1, NULL, NULL, &error); + gchar* dst = g_utf16_to_utf8(src, -1, nullptr, nullptr, &error); if (error) { ticonv_critical("%s", error->message); @@ -171,7 +169,7 @@ void TICALL ticonv_utf8_free(char *str) **/ char* TICALL ticonv_charset_utf16_to_ti_s(CalcModel model, const unsigned short *utf16, char *ti) { - if (utf16 != NULL && ti != NULL) + if (utf16 != nullptr && ti != nullptr) { switch (model) { @@ -235,7 +233,7 @@ char* TICALL ticonv_charset_utf16_to_ti_s(CalcModel model, const unsigned short else { ticonv_critical("%s: an argument is NULL", __FUNCTION__); - return NULL; + return nullptr; } } @@ -250,12 +248,12 @@ char* TICALL ticonv_charset_utf16_to_ti_s(CalcModel model, const unsigned short **/ char* TICALL ticonv_charset_utf16_to_ti(CalcModel model, const unsigned short *utf16) { - char * out = NULL; - if (utf16 != NULL) + char * out = nullptr; + if (utf16 != nullptr) { char * ti = (char *)g_malloc0(4*ticonv_utf16_strlen(utf16) + 1); // upper bound out = ticonv_charset_utf16_to_ti_s(model, utf16, ti); - if (out == NULL) + if (out == nullptr) { ticonv_ti_free(ti); } @@ -293,7 +291,7 @@ void TICALL ticonv_ti_free(char *str) **/ unsigned short* TICALL ticonv_charset_ti_to_utf16_s(CalcModel model, const char *ti, unsigned short *utf16) { - if (ti != NULL && utf16 != NULL) + if (ti != nullptr && utf16 != nullptr) { switch (model) { @@ -352,7 +350,7 @@ unsigned short* TICALL ticonv_charset_ti_to_utf16_s(CalcModel model, const char else { ticonv_critical("%s: an argument is NULL", __FUNCTION__); - return NULL; + return nullptr; } } @@ -367,12 +365,12 @@ unsigned short* TICALL ticonv_charset_ti_to_utf16_s(CalcModel model, const char **/ unsigned short* TICALL ticonv_charset_ti_to_utf16(CalcModel model, const char *ti) { - unsigned short * out = NULL; - if (ti != NULL) + unsigned short * out = nullptr; + if (ti != nullptr) { unsigned short * utf16 = (unsigned short *)g_malloc0(4 * strlen(ti) + 2); // upper bound out = ticonv_charset_ti_to_utf16_s(model, ti, utf16); - if (out == NULL) + if (out == nullptr) { ticonv_utf16_free(utf16); } @@ -401,7 +399,7 @@ unsigned short* TICALL ticonv_charset_ti_to_utf16(CalcModel model, const char *t **/ unsigned short* TICALL ticonv_varname_to_utf16_s(CalcModel model, const char *src, unsigned short *dst, unsigned char type) { - if (src != NULL && dst != NULL) + if (src != nullptr && dst != nullptr) { char * tmp = ticonv_varname_detokenize(model, src, type); unsigned short * utf16 = ticonv_charset_ti_to_utf16_s(model, tmp, dst); @@ -411,7 +409,7 @@ unsigned short* TICALL ticonv_varname_to_utf16_s(CalcModel model, const char *sr else { ticonv_critical("%s: an argument is NULL", __FUNCTION__); - return NULL; + return nullptr; } } @@ -431,7 +429,7 @@ unsigned short* TICALL ticonv_varname_to_utf16_s(CalcModel model, const char *sr **/ unsigned short* TICALL ticonv_varname_to_utf16(CalcModel model, const char *src, unsigned char type) { - if (src != NULL) + if (src != nullptr) { char * tmp = ticonv_varname_detokenize(model, src, type); unsigned short * utf16 = ticonv_charset_ti_to_utf16(model, tmp); @@ -441,7 +439,7 @@ unsigned short* TICALL ticonv_varname_to_utf16(CalcModel model, const char *src, else { ticonv_critical("%s: an argument is NULL", __FUNCTION__); - return NULL; + return nullptr; } } @@ -463,10 +461,10 @@ unsigned short* TICALL ticonv_varname_to_utf16(CalcModel model, const char *src, **/ char* TICALL ticonv_varname_to_utf8_sn(CalcModel model, const char *src, char *dst, uint32_t maxlen, unsigned char type) { - if (src != NULL && dst != NULL && maxlen >= 1) + if (src != nullptr && dst != nullptr && maxlen >= 1) { char * tmp = ticonv_varname_to_utf8(model, src, type); - if (tmp != NULL) + if (tmp != nullptr) { strncpy(dst, tmp, maxlen - 1); dst[maxlen - 1] = 0; @@ -475,13 +473,13 @@ char* TICALL ticonv_varname_to_utf8_sn(CalcModel model, const char *src, char *d } else { - return NULL; + return nullptr; } } else { ticonv_critical("%s: an argument is invalid", __FUNCTION__); - return NULL; + return nullptr; } } @@ -502,10 +500,10 @@ char* TICALL ticonv_varname_to_utf8_sn(CalcModel model, const char *src, char *d **/ char* TICALL ticonv_varname_to_utf8_s(CalcModel model, const char *src, char *dst, unsigned char type) { - if (src != NULL && dst != NULL) + if (src != nullptr && dst != nullptr) { char * tmp = ticonv_varname_to_utf8(model, src, type); - if (tmp != NULL) + if (tmp != nullptr) { strcpy(dst, tmp); ticonv_utf8_free(tmp); @@ -513,13 +511,13 @@ char* TICALL ticonv_varname_to_utf8_s(CalcModel model, const char *src, char *ds } else { - return NULL; + return nullptr; } } else { ticonv_critical("%s: an argument is NULL", __FUNCTION__); - return NULL; + return nullptr; } } @@ -539,7 +537,7 @@ char* TICALL ticonv_varname_to_utf8_s(CalcModel model, const char *src, char *ds **/ char* TICALL ticonv_varname_to_utf8(CalcModel model, const char *src, unsigned char type) { - if (src != NULL) + if (src != nullptr) { unsigned short * utf16 = ticonv_varname_to_utf16(model, src, type); gchar * utf8 = ticonv_utf16_to_utf8(utf16); @@ -549,7 +547,7 @@ char* TICALL ticonv_varname_to_utf8(CalcModel model, const char *src, unsigned c else { ticonv_critical("%s: src is NULL", __FUNCTION__); - return NULL; + return nullptr; } } @@ -574,10 +572,10 @@ char* TICALL ticonv_varname_to_utf8(CalcModel model, const char *src, unsigned c **/ char* TICALL ticonv_varname_to_filename_sn(CalcModel model, const char *src, char *dst, uint32_t maxlen, unsigned char type) { - if (src != NULL && dst != NULL && maxlen >= 1) + if (src != nullptr && dst != nullptr && maxlen >= 1) { char * tmp = ticonv_varname_to_filename(model, src, type); - if (tmp != NULL) + if (tmp != nullptr) { strncpy(dst, tmp, maxlen - 1); dst[maxlen - 1] = 0; @@ -586,13 +584,13 @@ char* TICALL ticonv_varname_to_filename_sn(CalcModel model, const char *src, cha } else { - return NULL; + return nullptr; } } else { ticonv_critical("%s: an argument is invalid", __FUNCTION__); - return NULL; + return nullptr; } } @@ -616,10 +614,10 @@ char* TICALL ticonv_varname_to_filename_sn(CalcModel model, const char *src, cha **/ char* TICALL ticonv_varname_to_filename_s(CalcModel model, const char *src, char *dst, unsigned char type) { - if (src != NULL && dst != NULL) + if (src != nullptr && dst != nullptr) { char * tmp = ticonv_varname_to_filename(model, src, type); - if (tmp != NULL) + if (tmp != nullptr) { strcpy(dst, tmp); ticonv_gfe_free(tmp); @@ -627,13 +625,13 @@ char* TICALL ticonv_varname_to_filename_s(CalcModel model, const char *src, char } else { - return NULL; + return nullptr; } } else { ticonv_critical("%s: an argument is NULL", __FUNCTION__); - return NULL; + return nullptr; } } @@ -654,7 +652,7 @@ char* TICALL ticonv_varname_to_filename_s(CalcModel model, const char *src, char **/ char* TICALL ticonv_varname_to_filename(CalcModel model, const char *src, unsigned char type) { - if (src != NULL) + if (src != nullptr) { unsigned short * utf16 = ticonv_varname_to_utf16(model, src, type); char * gfe = ticonv_utf16_to_gfe(model, utf16); @@ -664,7 +662,7 @@ char* TICALL ticonv_varname_to_filename(CalcModel model, const char *src, unsign else { ticonv_critical("%s: src is NULL", __FUNCTION__); - return NULL; + return nullptr; } } @@ -686,7 +684,7 @@ char* TICALL ticonv_varname_to_filename(CalcModel model, const char *src, unsign **/ char* TICALL ticonv_varname_to_tifile_sn(CalcModel model, const char *src, char *dst, uint32_t maxlen, unsigned char type) { - if (src != NULL && dst != NULL && maxlen >= 1) + if (src != nullptr && dst != nullptr && maxlen >= 1) { char * tmp = ticonv_varname_to_tifile(model, src, type); if (tmp) @@ -698,13 +696,13 @@ char* TICALL ticonv_varname_to_tifile_sn(CalcModel model, const char *src, char } else { - return NULL; + return nullptr; } } else { ticonv_critical("%s: an argument is invalid", __FUNCTION__); - return NULL; + return nullptr; } } @@ -725,7 +723,7 @@ char* TICALL ticonv_varname_to_tifile_sn(CalcModel model, const char *src, char **/ char* TICALL ticonv_varname_to_tifile_s(CalcModel model, const char *src, char *dst, unsigned char type) { - if (src != NULL && dst != NULL) + if (src != nullptr && dst != nullptr) { char * tmp = ticonv_varname_to_tifile(model, src, type); if (tmp) @@ -736,13 +734,13 @@ char* TICALL ticonv_varname_to_tifile_s(CalcModel model, const char *src, char * } else { - return NULL; + return nullptr; } } else { ticonv_critical("%s: an argument is NULL", __FUNCTION__); - return NULL; + return nullptr; } } @@ -764,10 +762,10 @@ char* TICALL ticonv_varname_to_tifile(CalcModel model, const char *src, unsigned char *ti; char *dst; - if (src == NULL) + if (src == nullptr) { ticonv_critical("%s: src is NULL", __FUNCTION__); - return NULL; + return nullptr; } // Do TI-UTF-8 -> UTF-16,UTF-16 -> TI-8x/9x charset @@ -826,10 +824,10 @@ char* TICALL ticonv_varname_to_tifile(CalcModel model, const char *src, unsigned **/ char* TICALL ticonv_varname_from_tifile_sn(CalcModel model, const char *src, char *dst, uint32_t maxlen, unsigned char type) { - if (src != NULL && dst != NULL && maxlen >= 1) + if (src != nullptr && dst != nullptr && maxlen >= 1) { char * tmp = ticonv_varname_from_tifile(model, src, type); - if (tmp != NULL) + if (tmp != nullptr) { strncpy(dst, tmp, maxlen - 1); dst[maxlen - 1] = 0; @@ -838,13 +836,13 @@ char* TICALL ticonv_varname_from_tifile_sn(CalcModel model, const char *src, cha } else { - return NULL; + return nullptr; } } else { ticonv_critical("%s: an argument is invalid", __FUNCTION__); - return NULL; + return nullptr; } } @@ -865,10 +863,10 @@ char* TICALL ticonv_varname_from_tifile_sn(CalcModel model, const char *src, cha **/ char* TICALL ticonv_varname_from_tifile_s(CalcModel model, const char *src, char *dst, unsigned char type) { - if (src != NULL && dst != NULL) + if (src != nullptr && dst != nullptr) { char * tmp = ticonv_varname_from_tifile(model, src, type); - if (tmp != NULL) + if (tmp != nullptr) { strcpy(dst, tmp); ticonv_ti_free(tmp); @@ -876,13 +874,13 @@ char* TICALL ticonv_varname_from_tifile_s(CalcModel model, const char *src, char } else { - return NULL; + return nullptr; } } else { ticonv_critical("%s: an argument is NULL", __FUNCTION__); - return NULL; + return nullptr; } } @@ -904,10 +902,10 @@ char* TICALL ticonv_varname_from_tifile(CalcModel model, const char *src, unsign char *ti; char *dst; - if (src == NULL) + if (src == nullptr) { ticonv_critical("%s: src is NULL", __FUNCTION__); - return NULL; + return nullptr; } if (model == CALC_TI84P_USB || model == CALC_TI82A_USB || model == CALC_TI84PT_USB) diff --git a/libticonv/trunk/src/tokens.cc b/libticonv/trunk/src/tokens.cc index a80f3fb8e..1314c4914 100644 --- a/libticonv/trunk/src/tokens.cc +++ b/libticonv/trunk/src/tokens.cc @@ -126,7 +126,7 @@ static char *detokenize_vartype(CalcModel model, const char *src, unsigned char break; } - return NULL; + return nullptr; } // beware: raw varname is not always NUL-terminated @@ -496,7 +496,7 @@ char* TICALL ticonv_varname_detokenize(CalcModel model, const char *src, unsigne { char *dst; - if (src == NULL) + if (src == nullptr) { return g_strdup("________"); } @@ -584,9 +584,9 @@ char* TICALL ticonv_varname_tokenize(CalcModel model, const char *src_, unsigned { const unsigned char *src = (const unsigned char *)src_; - if (src == NULL) + if (src == nullptr) { - return NULL; + return nullptr; } switch(model) @@ -751,9 +751,9 @@ char* TICALL ticonv_varname_tokenize(CalcModel model, const char *src_, unsigned **/ char* TICALL ticonv_varname_strdup(char * varname) { - if (NULL == varname) + if (nullptr == varname) { - return NULL; + return nullptr; } return g_strdup(varname); } diff --git a/libticonv/trunk/src/type2str.cc b/libticonv/trunk/src/type2str.cc index f7894c047..b456c52fe 100644 --- a/libticonv/trunk/src/type2str.cc +++ b/libticonv/trunk/src/type2str.cc @@ -86,7 +86,7 @@ const char * TICALL ticonv_model_to_string(CalcModel model) CalcModel TICALL ticonv_string_to_model(const char *str) { - if (str != NULL) + if (str != nullptr) { if ( !g_ascii_strcasecmp(str, "TI-73") || !g_ascii_strcasecmp(str, "TI73") diff --git a/libticonv/trunk/tests/test_ticonv.cc b/libticonv/trunk/tests/test_ticonv.cc index ac84de976..b2c4c8b41 100644 --- a/libticonv/trunk/tests/test_ticonv.cc +++ b/libticonv/trunk/tests/test_ticonv.cc @@ -47,9 +47,8 @@ const unsigned long* charsets[8]; */ int main(int argc, char **argv) { - int i, j; unsigned int n = 0; - int is_utf8 = ticonv_environment_is_utf8(); + const int is_utf8 = ticonv_environment_is_utf8(); charsets[0] = ti73_charset; charsets[1] = ti82_charset; @@ -75,13 +74,13 @@ int main(int argc, char **argv) printf(" 0 1 2 3 4 5 6 7 8 9 A B C D E F\n"); - for(i = 0; i < 16; i++) + for(int i = 0; i < 16; i++) { printf("%x ", i); - for(j = 0; j < 16; j++) + for(int j = 0; j < 16; j++) { - unsigned long wc = charsets[n][16*i+j]; - gchar *str = NULL; + const unsigned long wc = charsets[n][16*i+j]; + gchar *str = nullptr; if (wc && wc != '\n') { @@ -92,14 +91,14 @@ int main(int argc, char **argv) if (!is_utf8 && str) { - gchar *tmp = g_locale_from_utf8(str, -1, NULL, NULL, NULL); + gchar *tmp = g_locale_from_utf8(str, -1, nullptr, nullptr, nullptr); ticonv_utf8_free(str); str = tmp; } } else { - str = NULL; + str = nullptr; } if (str) @@ -116,9 +115,6 @@ int main(int argc, char **argv) char ti82_varname[9] = { 0 }; char ti92_varname[9] = { 0 }; char ti84p_varname[36] = { 0 }; - char *utf8; - char *filename; - char *varname; ti82_varname[0] = 0x5d; // L1 ti82_varname[1] = 0x01; @@ -134,7 +130,7 @@ int main(int argc, char **argv) ti84p_varname[3] = (char)0x81; // TI -> UTF-8 - utf8 = ticonv_varname_to_utf8(CALC_TI82, ti82_varname, -1); + char* utf8 = ticonv_varname_to_utf8(CALC_TI82, ti82_varname, -1); printf("UTF-8 varname: <%s> (%i)\n", ti82_varname, (int)strlen(ti82_varname)); ticonv_utf8_free(utf8); @@ -149,7 +145,7 @@ int main(int argc, char **argv) // TI -> filename printf("raw varname: <%s> (%i)\n", ti92_varname, (int)strlen(ti92_varname)); - filename = ticonv_varname_to_filename(CALC_TI92, ti92_varname, -1); + char* filename = ticonv_varname_to_filename(CALC_TI92, ti92_varname, -1); printf("filename: <%s>\n", filename); ticonv_gfe_free(filename); @@ -165,7 +161,7 @@ int main(int argc, char **argv) // varname -> varname printf("raw varname: <%s> (%i)\n", ti84p_varname, (int)strlen(ti84p_varname)); - varname = ticonv_varname_to_tifile(CALC_TI84P_USB, ti84p_varname, -1); + char* varname = ticonv_varname_to_tifile(CALC_TI84P_USB, ti84p_varname, -1); printf("varname: <%s>\n", varname); ticonv_gfe_free(varname); } diff --git a/libtifiles/trunk/src/cert.cc b/libtifiles/trunk/src/cert.cc index eb27a860c..7e3dd8c47 100644 --- a/libtifiles/trunk/src/cert.cc +++ b/libtifiles/trunk/src/cert.cc @@ -38,17 +38,16 @@ **/ int TICALL tifiles_cert_field_get(const uint8_t *data, uint32_t length, uint16_t *field_type, const uint8_t **contents, uint32_t *field_size) { - uint16_t field_id; uint32_t field_len; uint32_t additional_len; // Initial sanity checks. - if (data == NULL) + if (data == nullptr) { tifiles_critical("%s: data is NULL", __FUNCTION__); return ERR_INVALID_PARAM; } - if (field_type == NULL && contents == NULL && field_size == NULL) + if (field_type == nullptr && contents == nullptr && field_size == nullptr) { tifiles_critical("%s: all output parameters are NULL", __FUNCTION__); return ERR_INVALID_PARAM; @@ -60,7 +59,7 @@ int TICALL tifiles_cert_field_get(const uint8_t *data, uint32_t length, uint16_t } // Retrieve field ID and number of additional bytes we need to read for the field's size. - field_id = (((uint16_t)data[0]) << 8) | data[1]; + const uint16_t field_id = (((uint16_t)data[0]) << 8) | data[1]; switch (field_id & 0xF) { case 0xD: additional_len = 1; break; @@ -109,16 +108,16 @@ int TICALL tifiles_cert_field_get(const uint8_t *data, uint32_t length, uint16_t return ERR_CERT_TRUNCATED; } - if (field_type != NULL) + if (field_type != nullptr) { // Don't mask out the size indication, it may be useful to the user. *field_type = field_id; } - if (contents != NULL) + if (contents != nullptr) { *contents = data + 2 + additional_len; } - if (field_size != NULL) + if (field_size != nullptr) { *field_size = field_len; } @@ -128,23 +127,22 @@ int TICALL tifiles_cert_field_get(const uint8_t *data, uint32_t length, uint16_t int TICALL tifiles_cert_field_next(const uint8_t **data, uint32_t *length) { - int ret; const uint8_t * contents; uint32_t field_size; // Initial sanity checks. - if (data == NULL) + if (data == nullptr) { tifiles_critical("%s: data is NULL", __FUNCTION__); return ERR_INVALID_PARAM; } - if (length == NULL) + if (length == nullptr) { tifiles_critical("%s: length is NULL", __FUNCTION__); return ERR_INVALID_PARAM; } - ret = tifiles_cert_field_get(*data, *length, NULL, &contents, &field_size); + const int ret = tifiles_cert_field_get(*data, *length, nullptr, &contents, &field_size); if (!ret) { *length -= contents + field_size - *data; @@ -160,7 +158,7 @@ int TICALL tifiles_cert_field_find(const uint8_t *data, uint32_t length, uint16_ uint16_t ft; // Initial sanity checks. - if (data == NULL) + if (data == nullptr) { tifiles_critical("%s: data is NULL", __FUNCTION__); return ERR_INVALID_PARAM; @@ -193,12 +191,12 @@ int TICALL tifiles_cert_field_find_path(const uint8_t *data, uint32_t length, co int ret = 0; // Initial sanity checks. - if (data == NULL) + if (data == nullptr) { tifiles_critical("%s: data is NULL", __FUNCTION__); return ERR_INVALID_PARAM; } - if (field_path == NULL) + if (field_path == nullptr) { tifiles_critical("%s: field_path is NULL", __FUNCTION__); return ERR_INVALID_PARAM; @@ -220,11 +218,11 @@ int TICALL tifiles_cert_field_find_path(const uint8_t *data, uint32_t length, co //tifiles_warning("%p\t%u", data, length); field_path++; field_path_len--; - if (contents != NULL) + if (contents != nullptr) { *contents = data; } - if (field_size != NULL) + if (field_size != nullptr) { *field_size = length; } diff --git a/libtifiles/trunk/src/comments.cc b/libtifiles/trunk/src/comments.cc index 879dbd0c5..19cbcd28f 100644 --- a/libtifiles/trunk/src/comments.cc +++ b/libtifiles/trunk/src/comments.cc @@ -33,10 +33,10 @@ // Helper function for factoring code. static inline char * tifiles_comment_set_sn(const char * prefix, char * comment, uint32_t maxlen) { - if (NULL != comment && maxlen > 0) + if (nullptr != comment && maxlen > 0) { char * str; - time_t t = time(NULL); + time_t t = time(nullptr); #ifdef HAVE_CTIME_R char datetime[64]; ctime_r(&t, datetime); diff --git a/libtifiles/trunk/src/error.cc b/libtifiles/trunk/src/error.cc index 844ec5cbb..01eba5ae3 100644 --- a/libtifiles/trunk/src/error.cc +++ b/libtifiles/trunk/src/error.cc @@ -45,7 +45,7 @@ **/ int TICALL tifiles_error_get(int number, char **message) { - if (message == NULL) + if (message == nullptr) { tifiles_critical("%s(NULL)", __FUNCTION__); return number; @@ -160,7 +160,7 @@ int TICALL tifiles_error_get(int number, char **message) **/ int TICALL tifiles_error_free(char *message) { - if (message == NULL) + if (message == nullptr) { tifiles_critical("tifiles_error_free(NULL)\n"); return ERR_INVALID_PARAM; diff --git a/libtifiles/trunk/src/files8x.cc b/libtifiles/trunk/src/files8x.cc index b3314a159..aeb2c48d1 100644 --- a/libtifiles/trunk/src/files8x.cc +++ b/libtifiles/trunk/src/files8x.cc @@ -118,7 +118,7 @@ int ti8x_file_read_regular(const char *filename, Ti8xRegular *content) FILE *f; uint16_t tmp = 0x000B; long offset = 0; - unsigned int i, j; + unsigned int i; int ti83p_flag = 0; uint8_t name_length = 8; // ti85/86 only uint16_t data_size, sum = 0; @@ -129,7 +129,7 @@ int ti8x_file_read_regular(const char *filename, Ti8xRegular *content) char varname[VARNAME_MAX]; int ret = ERR_FILE_IO; - if (content == NULL) + if (content == nullptr) { tifiles_critical("%s: an argument is NULL", __FUNCTION__); return ERR_INVALID_FILE; @@ -142,7 +142,7 @@ int ti8x_file_read_regular(const char *filename, Ti8xRegular *content) } f = g_fopen(filename, "rb"); - if (f == NULL) + if (f == nullptr) { tifiles_warning("Unable to open this file: %s", filename); ret = ERR_FILE_OPEN; @@ -190,7 +190,7 @@ int ti8x_file_read_regular(const char *filename, Ti8xRegular *content) for (i = 0;; i++) { - long current_offset = ftell(f); + const long current_offset = ftell(f); /* We are done finding entries once we reach the end of the data segment * as defined in the header. This works better than magic numbers, as * as there exist files in the wild with incorrect magic numbers that @@ -260,7 +260,7 @@ int ti8x_file_read_regular(const char *filename, Ti8xRegular *content) content->num_entries = i; content->entries = (VarEntry **)g_malloc0((content->num_entries + 1) * sizeof(VarEntry*)); - if (content->entries == NULL) + if (content->entries == nullptr) { ret = ERR_MALLOC; goto tfrr; @@ -293,7 +293,7 @@ int ti8x_file_read_regular(const char *filename, Ti8xRegular *content) ticonv_varname_from_tifile_sn(content->model_dst, varname, entry->name, sizeof(entry->name), entry->type); if ((content->model == CALC_TI86) && padded86) { - for (j = 0; j < 8U - name_length; j++) + for (unsigned int j = 0; j < 8U - name_length; j++) { sum += fgetc(f); } @@ -324,10 +324,10 @@ int ti8x_file_read_regular(const char *filename, Ti8xRegular *content) sum += MSB(attribute); sum += LSB(attribute); } - if (fread_word(f, NULL) < 0) goto tfrr; + if (fread_word(f, nullptr) < 0) goto tfrr; entry->data = (uint8_t *) g_malloc0(entry->size); - if (entry->data == NULL) + if (entry->data == nullptr) { ret = ERR_MALLOC; goto tfrr; @@ -388,7 +388,7 @@ int ti8x_file_read_backup(const char *filename, Ti8xBackup *content) uint8_t extra_header[3] = { 0, 0, 0 }; int ret = ERR_FILE_IO; - if (content == NULL) + if (content == nullptr) { tifiles_critical("%s: an argument is NULL", __FUNCTION__); return ERR_INVALID_FILE; @@ -401,7 +401,7 @@ int ti8x_file_read_backup(const char *filename, Ti8xBackup *content) } f = g_fopen(filename, "rb"); - if (f == NULL) + if (f == nullptr) { tifiles_info( "Unable to open this file: %s", filename); ret = ERR_FILE_OPEN; @@ -431,7 +431,7 @@ int ti8x_file_read_backup(const char *filename, Ti8xBackup *content) } if (fskip(f, 3) < 0) goto tfrb; if (fread_n_chars(f, 42, content->comment) < 0) goto tfrb; - if (fread_word(f, NULL) < 0) goto tfrb; + if (fread_word(f, nullptr) < 0) goto tfrb; if (fread_word(f, &header_size) < 0) goto tfrb; if (header_size < 9 || header_size > 12) @@ -479,18 +479,18 @@ int ti8x_file_read_backup(const char *filename, Ti8xBackup *content) } content->version = extra_header[2]; - if (fread_word(f, NULL) < 0) goto tfrb; + if (fread_word(f, nullptr) < 0) goto tfrb; content->data_part1 = (uint8_t *)g_malloc0(content->data_length1); - if (content->data_part1 == NULL) + if (content->data_part1 == nullptr) { ret = ERR_MALLOC; goto tfrb; } if (fread(content->data_part1, 1, content->data_length1, f) < content->data_length1) goto tfrb; - if (fread_word(f, NULL) < 0) goto tfrb; + if (fread_word(f, nullptr) < 0) goto tfrb; content->data_part2 = (uint8_t *)g_malloc0(content->data_length2); - if (content->data_part2 == NULL) + if (content->data_part2 == nullptr) { ret = ERR_MALLOC; goto tfrb; @@ -499,9 +499,9 @@ int ti8x_file_read_backup(const char *filename, Ti8xBackup *content) if (content->data_length3) // can be 0000 on TI86 { - if (fread_word(f, NULL) < 0) goto tfrb; + if (fread_word(f, nullptr) < 0) goto tfrb; content->data_part3 = (uint8_t *)g_malloc0(content->data_length3); - if (content->data_part3 == NULL) + if (content->data_part3 == nullptr) { ret = ERR_MALLOC; goto tfrb; @@ -511,9 +511,9 @@ int ti8x_file_read_backup(const char *filename, Ti8xBackup *content) if (content->model == CALC_TI86) { - if (fread_word(f, NULL) < 0) goto tfrb; + if (fread_word(f, nullptr) < 0) goto tfrb; content->data_part4 = (uint8_t *)g_malloc0(content->data_length4); - if (content->data_part4 == NULL) + if (content->data_part4 == nullptr) { ret = ERR_MALLOC; goto tfrb; @@ -523,7 +523,7 @@ int ti8x_file_read_backup(const char *filename, Ti8xBackup *content) else { content->data_length4 = 0; - content->data_part4 = NULL; + content->data_part4 = nullptr; } if (fread_word(f, &(content->stored_checksum)) < 0) goto tfrb; @@ -548,9 +548,8 @@ int ti8x_file_read_backup(const char *filename, Ti8xBackup *content) static int check_device_type(uint8_t id) { static const uint8_t types[] = { 0, DEVICE_TYPE_73, DEVICE_TYPE_83P }; - int i; - for (i = 1; i < (int)(sizeof(types)/sizeof(types[0])); i++) + for (int i = 1; i < (int)(sizeof(types)/sizeof(types[0])); i++) { if (types[i] == id) { @@ -564,9 +563,8 @@ static int check_device_type(uint8_t id) static int check_data_type(uint8_t id) { static const uint8_t types[] = { 0, TI83p_AMS, TI83p_APPL, TI83p_CERT, TI83p_LICENSE }; - int i; - for (i = 1; i < (int)(sizeof(types)/sizeof(types[0])); i++) + for (int i = 1; i < (int)(sizeof(types)/sizeof(types[0])); i++) { if (types[i] == id) { @@ -580,7 +578,6 @@ static int check_data_type(uint8_t id) static int get_native_app_name(const FlashContent *content, char *buffer, size_t buffer_size) { const uint8_t *data, *name; - uint16_t app_type; uint32_t size, n; if (content->num_pages > 0) @@ -596,7 +593,7 @@ static int get_native_app_name(const FlashContent *content, char *buffer, size_t if (size >= 6 && (data[0] & 0xf0) == 0x80 && data[1] == 0x0f) { - app_type = (uint16_t)(data[0]) << 8; + const uint16_t app_type = (uint16_t)(data[0]) << 8; if (!tifiles_cert_field_find(data + 6, size - 6, app_type + 0x40, &name, &n)) { if (n >= buffer_size) @@ -633,7 +630,7 @@ int ti8x_file_read_flash(const char *filename, Ti8xFlash *head) char varname[9]; int ret = ERR_FILE_IO; - if (head == NULL) + if (head == nullptr) { tifiles_critical("%s: an argument is NULL", __FUNCTION__); return ERR_INVALID_FILE; @@ -646,7 +643,7 @@ int ti8x_file_read_flash(const char *filename, Ti8xFlash *head) } f = g_fopen(filename, "rb"); - if (f == NULL) + if (f == nullptr) { tifiles_info("Unable to open this file: %s", filename); ret = ERR_FILE_OPEN; @@ -695,7 +692,7 @@ int ti8x_file_read_flash(const char *filename, Ti8xFlash *head) { // get data like TI9X content->data_part = (uint8_t *)g_malloc0(content->data_length + 256); - if (content->data_part == NULL) + if (content->data_part == nullptr) { ret = ERR_MALLOC; goto tfrf; @@ -704,7 +701,7 @@ int ti8x_file_read_flash(const char *filename, Ti8xFlash *head) memset(content->data_part, 0xff, content->data_length + 256); if (fread(content->data_part, 1, content->data_length, f) < content->data_length) goto tfrf; - content->next = NULL; + content->next = nullptr; } else if (content->data_type == TI83p_AMS || content->data_type == TI83p_APPL) { @@ -713,12 +710,12 @@ int ti8x_file_read_flash(const char *filename, Ti8xFlash *head) // This looks like a TI-Z80-style OS / FlashApp, let's try to parse Intel Hex format. // reset/initialize block reader - hex_block_read(NULL, NULL, NULL, NULL, NULL, NULL); - content->pages = NULL; + hex_block_read(nullptr, nullptr, nullptr, nullptr, nullptr, nullptr); + content->pages = nullptr; // TODO: modify this code if TI ever makes a TI-Z80 model with more than 256 Flash pages... content->pages = (FlashPage **)g_malloc0((256+1) * sizeof(Ti8xFlashPage *)); - if (content->pages == NULL) + if (content->pages == nullptr) { ret = ERR_MALLOC; goto tfrf; @@ -739,7 +736,7 @@ int ti8x_file_read_flash(const char *filename, Ti8xFlash *head) fp->data = (uint8_t *) g_malloc0(FLASH_PAGE_SIZE); memset(fp->data, 0xff, FLASH_PAGE_SIZE); - if (fp->data == NULL) + if (fp->data == nullptr) { ret = ERR_MALLOC; goto tfrf; @@ -754,14 +751,14 @@ int ti8x_file_read_flash(const char *filename, Ti8xFlash *head) content->data_length += size; } content->num_pages = i; - content->next = NULL; + content->next = nullptr; } else { // This looks like a TI-68k-style OS / FlashApp, containing flat data. content->data_part = (uint8_t *)g_malloc0(content->data_length); - if (content->data_part == NULL) + if (content->data_part == nullptr) { ret = ERR_MALLOC; goto tfrf; @@ -774,7 +771,7 @@ int ti8x_file_read_flash(const char *filename, Ti8xFlash *head) ret = ERR_INVALID_FILE; goto tfrf; } - content->next = NULL; + content->next = nullptr; } } @@ -805,7 +802,7 @@ int ti8x_file_read_flash(const char *filename, Ti8xFlash *head) if (fseek(f, -8, SEEK_CUR)) goto tfrf; content->next = (Ti8xFlash *)g_malloc0(sizeof(Ti8xFlash)); - if (content->next == NULL) + if (content->next == nullptr) { ret = ERR_MALLOC; goto tfrf; @@ -843,16 +840,14 @@ int ti8x_file_read_flash(const char *filename, Ti8xFlash *head) **/ int ti8x_file_write_regular(const char *fname, Ti8xRegular *content, char **real_fname) { - FILE *f; unsigned int i; uint16_t sum = 0; - char *filename = NULL; + char *filename = nullptr; uint32_t data_length; uint16_t packet_length = 0x0B; uint8_t name_length = 8; - uint16_t attr; - if (content->entries == NULL) + if (content->entries == nullptr) { tifiles_warning("%s: skipping content with NULL content->entries", __FUNCTION__); return 0; @@ -861,8 +856,8 @@ int ti8x_file_write_regular(const char *fname, Ti8xRegular *content, char **real // Compute data length now, so as to be able to bail out immediately if we know the data won't fit. for (i = 0, data_length = 0; i < content->num_entries; i++) { - VarEntry *entry = content->entries[i]; - if (entry == NULL) + const VarEntry *entry = content->entries[i]; + if (entry == nullptr) { tifiles_warning("%s: skipping null content entry %d", __FUNCTION__, i); continue; @@ -894,10 +889,10 @@ int ti8x_file_write_regular(const char *fname, Ti8xRegular *content, char **real return ERR_GROUP_SIZE; } - if (fname != NULL) + if (fname != nullptr) { filename = g_strdup(fname); - if (filename == NULL) + if (filename == nullptr) { return ERR_MALLOC; } @@ -911,20 +906,20 @@ int ti8x_file_write_regular(const char *fname, Ti8xRegular *content, char **real else { tifiles_warning("%s: asked to build a filename from null content->entries[0], bailing out", __FUNCTION__); - if (real_fname != NULL) + if (real_fname != nullptr) { - *real_fname = NULL; + *real_fname = nullptr; } return 0; } - if (real_fname != NULL) + if (real_fname != nullptr) { *real_fname = g_strdup(filename); } } - f = g_fopen(filename, "wb"); - if (f == NULL) + FILE* f = g_fopen(filename, "wb"); + if (f == nullptr) { tifiles_info( "Unable to open this file: %s", filename); g_free(filename); @@ -941,7 +936,7 @@ int ti8x_file_write_regular(const char *fname, Ti8xRegular *content, char **real // write data section for (i = 0, sum = 0; i < content->num_entries; i++) { - VarEntry *entry = content->entries[i]; + const VarEntry *entry = content->entries[i]; char varname[VARNAME_MAX]; if (content->model == CALC_TI85) @@ -985,7 +980,7 @@ int ti8x_file_write_regular(const char *fname, Ti8xRegular *content, char **real } if (is_ti83p(content->model)) { - attr = (uint16_t)((entry->attr == ATTRB_ARCHIVED) ? 0x8000 : 0x00) + entry->version; + const uint16_t attr = (uint16_t)((entry->attr == ATTRB_ARCHIVED) ? 0x8000 : 0x00) + entry->version; if (fwrite_word(f, attr) < 0) goto tfwr; sum += MSB(attr); sum += LSB(attr); @@ -1037,17 +1032,15 @@ int ti8x_file_write_regular(const char *fname, Ti8xRegular *content, char **real **/ int ti8x_file_write_backup(const char *filename, Ti8xBackup *content) { - FILE *f; uint16_t header_size; - uint32_t data_length; - if (filename == NULL || content == NULL) + if (filename == nullptr || content == nullptr) { tifiles_critical("%s: an argument is NULL", __FUNCTION__); return ERR_INVALID_FILE; } - data_length = content->data_length1 + content->data_length2 + content->data_length3 + 17; + uint32_t data_length = content->data_length1 + content->data_length2 + content->data_length3 + 17; if (content->model == CALC_TI86) { data_length += content->data_length4; @@ -1058,8 +1051,8 @@ int ti8x_file_write_backup(const char *filename, Ti8xBackup *content) return ERR_GROUP_SIZE; } - f = g_fopen(filename, "wb"); - if (f == NULL) + FILE* f = g_fopen(filename, "wb"); + if (f == nullptr) { tifiles_info( "Unable to open this file: %s", filename); return ERR_FILE_OPEN; @@ -1145,15 +1138,13 @@ int ti8x_file_write_backup(const char *filename, Ti8xBackup *content) **/ int ti8x_file_write_flash(const char *fname, Ti8xFlash *head, char **real_fname) { - FILE *f; - Ti8xFlash *content = head; + const Ti8xFlash *content = head; unsigned int i; int bytes_written = 0; - long pos; char *filename; char varname[VARNAME_MAX]; - if (head == NULL) + if (head == nullptr) { tifiles_critical("%s: head is NULL", __FUNCTION__); return ERR_INVALID_FILE; @@ -1162,7 +1153,7 @@ int ti8x_file_write_flash(const char *fname, Ti8xFlash *head, char **real_fname) if (fname) { filename = g_strdup(fname); - if (filename == NULL) + if (filename == nullptr) { return ERR_MALLOC; } @@ -1171,14 +1162,14 @@ int ti8x_file_write_flash(const char *fname, Ti8xFlash *head, char **real_fname) { VarEntry ve; - for (content = head; content != NULL; content = content->next) + for (content = head; content != nullptr; content = content->next) { if (content->data_type == TI83p_AMS || content->data_type == TI83p_APPL) { break; } } - if (content == NULL) + if (content == nullptr) { tifiles_critical("%s: content is NULL", __FUNCTION__); return ERR_BAD_FILE; @@ -1189,21 +1180,21 @@ int ti8x_file_write_flash(const char *fname, Ti8xFlash *head, char **real_fname) ve.type = content->data_type; filename = tifiles_build_filename(content->model_dst, &ve); - if (real_fname != NULL) + if (real_fname != nullptr) { *real_fname = g_strdup(filename); } } - f = g_fopen(filename, "wb"); - if (f == NULL) + FILE* f = g_fopen(filename, "wb"); + if (f == nullptr) { tifiles_info("Unable to open this file: %s", filename); g_free(filename); return ERR_FILE_OPEN; } - for (content = head; content != NULL; content = content->next) + for (content = head; content != nullptr; content = content->next) { // header if (fwrite_8_chars(f, "**TIFL**") < 0) goto tfwf; @@ -1235,7 +1226,7 @@ int ti8x_file_write_flash(const char *fname, Ti8xFlash *head, char **real_fname) if (fwrite_byte(f, 0) < 0) goto tfwf; } if (fwrite_byte(f, content->hw_id) < 0) goto tfwf; - pos = ftell(f); + const long pos = ftell(f); if (pos == -1L) goto tfwf; if (fwrite_long(f, content->data_length) < 0) goto tfwf; @@ -1250,12 +1241,11 @@ int ti8x_file_write_flash(const char *fname, Ti8xFlash *head, char **real_fname) if (content->hw_id == 0) { // TI-Z80-style OS / FlashApp, let's write Intel Hex format. - for (i = 0; content->pages != NULL && i < content->num_pages; i++) + for (i = 0; content->pages != nullptr && i < content->num_pages; i++) { - uint32_t app_length, page_length; int extra_bytes = 0; - page_length = content->pages[i]->size; + uint32_t page_length = content->pages[i]->size; if ( content->data_type == TI83p_APPL && i == content->num_pages - 1 && content->pages[0]->data[0] == 0x80 && content->pages[0]->data[1] == 0x0f) @@ -1269,10 +1259,10 @@ int ti8x_file_write_flash(const char *fname, Ti8xFlash *head, char **real_fname) end of the application proper. */ /* get actual app length */ - app_length = 6 + ( (((uint32_t)(content->pages[0]->data[2])) << 24) - | (((uint32_t)(content->pages[0]->data[3])) << 16) - | (((uint32_t)(content->pages[0]->data[4])) << 8) - | ((uint32_t)(content->pages[0]->data[5]))); + const uint32_t app_length = 6 + ((((uint32_t)(content->pages[0]->data[2])) << 24) + | (((uint32_t)(content->pages[0]->data[3])) << 16) + | (((uint32_t)(content->pages[0]->data[4])) << 8) + | ((uint32_t)(content->pages[0]->data[5]))); /* remove any existing padding */ while (page_length > 0 && content->pages[i]->data[page_length - 1] == 0xff) @@ -1305,7 +1295,7 @@ int ti8x_file_write_flash(const char *fname, Ti8xFlash *head, char **real_fname) } // final block - bytes_written += hex_block_write(f, 0, 0, 0, NULL, 0, 0); + bytes_written += hex_block_write(f, 0, 0, 0, nullptr, 0, 0); if (fseek(f, -bytes_written - 4, SEEK_CUR)) goto tfwf; if (fwrite_long(f, bytes_written) < 0) goto tfwf; if (fseek(f, SEEK_END, 0L) ) goto tfwf; @@ -1344,7 +1334,7 @@ int ti8x_file_write_flash(const char *fname, Ti8xFlash *head, char **real_fname) **/ int ti8x_content_display_backup(Ti8xBackup *content) { - if (content == NULL) + if (content == nullptr) { tifiles_critical("%s(NULL)", __FUNCTION__); return ERR_INVALID_FILE; @@ -1386,9 +1376,7 @@ int ti8x_content_display_backup(Ti8xBackup *content) **/ int ti8x_content_display_flash(Ti8xFlash *content) { - Ti8xFlash *ptr; - - for (ptr = content; ptr != NULL; ptr = ptr->next) + for (Ti8xFlash* ptr = content; ptr != nullptr; ptr = ptr->next) { tifiles_info("FlashContent for TI-8x: %p", ptr); tifiles_info("Model: %02X (%u)", ptr->model, ptr->model); @@ -1440,14 +1428,11 @@ int ti8x_content_display_flash(Ti8xFlash *content) **/ int ti8x_file_display(const char *filename) { - Ti8xRegular *content1; - Ti8xBackup *content2; - Ti8xFlash *content3; int ret; if (tifiles_file_is_flash(filename)) { - content3 = tifiles_content_create_flash(CALC_TI83P); + Ti8xFlash* content3 = tifiles_content_create_flash(CALC_TI83P); ret = ti8x_file_read_flash(filename, content3); if (!ret) { @@ -1457,7 +1442,7 @@ int ti8x_file_display(const char *filename) } else if (tifiles_file_is_regular(filename)) { - content1 = tifiles_content_create_regular(CALC_NONE); + Ti8xRegular* content1 = tifiles_content_create_regular(CALC_NONE); ret = ti8x_file_read_regular(filename, content1); if (!ret) { @@ -1467,7 +1452,7 @@ int ti8x_file_display(const char *filename) } else if (tifiles_file_is_backup(filename)) { - content2 = tifiles_content_create_backup(CALC_NONE); + Ti8xBackup* content2 = tifiles_content_create_backup(CALC_NONE); ret = ti8x_file_read_backup(filename, content2); if (!ret) { diff --git a/libtifiles/trunk/src/files9x.cc b/libtifiles/trunk/src/files9x.cc index 799899fdc..d4fdf5d57 100644 --- a/libtifiles/trunk/src/files9x.cc +++ b/libtifiles/trunk/src/files9x.cc @@ -77,7 +77,7 @@ int ti9x_file_read_regular(const char *filename, Ti9xRegular *content) char varname[VARNAME_MAX]; int ret = ERR_FILE_IO; - if (content == NULL) + if (content == nullptr) { tifiles_critical("%s: an argument is NULL", __FUNCTION__); return ERR_INVALID_FILE; @@ -90,7 +90,7 @@ int ti9x_file_read_regular(const char *filename, Ti9xRegular *content) } f = g_fopen(filename, "rb"); - if (f == NULL) + if (f == nullptr) { ret = ERR_FILE_OPEN; goto tfrr2; @@ -123,7 +123,7 @@ int ti9x_file_read_regular(const char *filename, Ti9xRegular *content) content->model_dst = content->model; } - if (fread_word(f, NULL) < 0) goto tfrr; // Offset 0x8 + if (fread_word(f, nullptr) < 0) goto tfrr; // Offset 0x8 if (fread_8_chars(f, default_folder) < 0) goto tfrr; // Offset 0xA ticonv_varname_from_tifile_sn(content->model_dst, default_folder, content->default_folder, sizeof(content->default_folder), -1); strncpy(current_folder, content->default_folder, sizeof(current_folder) - 1); @@ -133,7 +133,7 @@ int ti9x_file_read_regular(const char *filename, Ti9xRegular *content) content->num_entries = tmp; content->entries = (VarEntry **)g_malloc0((content->num_entries + 1) * sizeof(VarEntry*)); - if (content->entries == NULL) + if (content->entries == nullptr) { ret = ERR_MALLOC; goto tfrr; @@ -155,7 +155,7 @@ int ti9x_file_read_regular(const char *filename, Ti9xRegular *content) if (fread_byte(f, &(entry->type)) < 0) goto tfrr; // Offset N+12, 0x48 for the first entry if (fread_byte(f, &attr) < 0) goto tfrr; // Offset N+13, 0x49 for the first entry entry->attr = (attr == 2 || attr == 3) ? ATTRB_ARCHIVED : (FileAttr)attr; - if (fread_word(f, NULL) < 0) goto tfrr; // Offset N+14, 0x4A for the first entry + if (fread_word(f, nullptr) < 0) goto tfrr; // Offset N+14, 0x4A for the first entry if (entry->type == TI92_DIR) // same as TI89_DIR, TI89t_DIR, ... { @@ -186,14 +186,14 @@ int ti9x_file_read_regular(const char *filename, Ti9xRegular *content) goto tfrr; } entry->data = (uint8_t *)g_malloc0(entry->size); - if (entry->data == NULL) + if (entry->data == nullptr) { ret = ERR_MALLOC; goto tfrr; } if (fseek(f, curr_offset, SEEK_SET)) goto tfrr; - if (fread_long(f, NULL) < 0) goto tfrr; // Normally: offset N+22, 0x52 for the first entry + if (fread_long(f, nullptr) < 0) goto tfrr; // Normally: offset N+22, 0x52 for the first entry if (fread(entry->data, 1, entry->size, f) < entry->size) goto tfrr; // Normally: offset N+26, 0x56 for the first entry if (fread_word(f, &checksum) < 0) goto tfrr; @@ -246,7 +246,7 @@ int ti9x_file_read_backup(const char *filename, Ti9xBackup *content) uint16_t sum; int ret = ERR_FILE_IO; - if (content == NULL) + if (content == nullptr) { tifiles_critical("%s: an argument is NULL", __FUNCTION__); return ERR_INVALID_FILE; @@ -259,7 +259,7 @@ int ti9x_file_read_backup(const char *filename, Ti9xBackup *content) } f = g_fopen(filename, "rb"); - if (f == NULL) + if (f == nullptr) { tifiles_info( "Unable to open this file: %s", filename); ret = ERR_FILE_OPEN; @@ -287,15 +287,15 @@ int ti9x_file_read_backup(const char *filename, Ti9xBackup *content) ret = ERR_INVALID_FILE; } - if (fread_word(f, NULL) < 0) goto tfrb; - if (fread_8_chars(f, NULL) < 0) goto tfrb; + if (fread_word(f, nullptr) < 0) goto tfrb; + if (fread_8_chars(f, nullptr) < 0) goto tfrb; if (fread_n_chars(f, 40, content->comment) < 0) goto tfrb; - if (fread_word(f, NULL) < 0) goto tfrb; - if (fread_long(f, NULL) < 0) goto tfrb; + if (fread_word(f, nullptr) < 0) goto tfrb; + if (fread_long(f, nullptr) < 0) goto tfrb; if (fread_8_chars(f, content->rom_version) < 0) goto tfrb; if (fread_byte(f, &(content->type)) < 0) goto tfrb; - if (fread_byte(f, NULL) < 0) goto tfrb; - if (fread_word(f, NULL) < 0) goto tfrb; + if (fread_byte(f, nullptr) < 0) goto tfrb; + if (fread_word(f, nullptr) < 0) goto tfrb; if (fread_long(f, &file_size) < 0) goto tfrb; if (file_size > (uint32_t)cur_pos) { @@ -303,10 +303,10 @@ int ti9x_file_read_backup(const char *filename, Ti9xBackup *content) goto tfrb; } content->data_length = file_size - 0x52 - 2; - if (fread_word(f, NULL) < 0) goto tfrb; + if (fread_word(f, nullptr) < 0) goto tfrb; content->data_part = (uint8_t *)g_malloc0(content->data_length); - if (content->data_part == NULL) + if (content->data_part == nullptr) { ret = ERR_MALLOC; goto tfrb; @@ -336,9 +336,8 @@ int ti9x_file_read_backup(const char *filename, Ti9xBackup *content) static int check_device_type(uint8_t id) { static const uint8_t types[] = { 0, DEVICE_TYPE_89, DEVICE_TYPE_92P }; - int i; - for (i = 1; i < (int)(sizeof(types)/sizeof(types[0])); i++) + for (int i = 1; i < (int)(sizeof(types)/sizeof(types[0])); i++) { if (types[i] == id) { @@ -352,9 +351,8 @@ static int check_device_type(uint8_t id) static int check_data_type(uint8_t id) { static const uint8_t types[] = { 0, TI89_AMS, TI89_APPL, TI89_CERTIF, TI89_LICENSE }; - int i; - for (i = 1; i < (int)(sizeof(types)/sizeof(types[0])); i++) + for (int i = 1; i < (int)(sizeof(types)/sizeof(types[0])); i++) { if (types[i] == id) { @@ -386,7 +384,7 @@ int ti9x_file_read_flash(const char *filename, Ti9xFlash *head) char signature[9]; int ret = ERR_FILE_IO; - if (head == NULL) + if (head == nullptr) { tifiles_critical("%s: an argument is NULL", __FUNCTION__); return ERR_INVALID_FILE; @@ -402,7 +400,7 @@ int ti9x_file_read_flash(const char *filename, Ti9xFlash *head) tib = tifiles_file_is_tib(filename); f = g_fopen(filename, "rb"); - if (f == NULL) + if (f == nullptr) { tifiles_info("Unable to open this file: %s", filename); ret = ERR_FILE_OPEN; @@ -434,7 +432,7 @@ int ti9x_file_read_flash(const char *filename, Ti9xFlash *head) content->data_type = 0x23; // FLASH os content->data_part = (uint8_t *)g_malloc0(content->data_length); - if (content->data_part == NULL) + if (content->data_part == nullptr) { ret = ERR_MALLOC; goto tfrf; @@ -451,7 +449,7 @@ int ti9x_file_read_flash(const char *filename, Ti9xFlash *head) case 9: content->device_type = DEVICE_TYPE_89; break; // Titanium } - content->next = NULL; + content->next = nullptr; } else { @@ -494,7 +492,7 @@ int ti9x_file_read_flash(const char *filename, Ti9xFlash *head) } content->data_part = (uint8_t *)g_malloc0(content->data_length); - if (content->data_part == NULL) + if (content->data_part == nullptr) { ret = ERR_MALLOC; goto tfrf; @@ -507,7 +505,7 @@ int ti9x_file_read_flash(const char *filename, Ti9xFlash *head) ret = ERR_INVALID_FILE; goto tfrf; } - content->next = NULL; + content->next = nullptr; // check for end of file if (fread_8_chars(f, signature) < 0) @@ -521,7 +519,7 @@ int ti9x_file_read_flash(const char *filename, Ti9xFlash *head) if (fseek(f, -8, SEEK_CUR)) goto tfrf; content->next = (Ti9xFlash *)g_malloc0(sizeof(Ti9xFlash)); - if (content->next == NULL) + if (content->next == nullptr) { ret = ERR_MALLOC; goto tfrf; @@ -560,25 +558,23 @@ int ti9x_file_read_flash(const char *filename, Ti9xFlash *head) **/ int ti9x_file_write_regular(const char *fname, Ti9xRegular *content, char **real_fname) { - FILE *f; unsigned int i; - char *filename = NULL; + char *filename = nullptr; uint32_t offset = 0x52; - int **table; unsigned int num_folders; char default_folder[FLDNAME_MAX]; char fldname[FLDNAME_MAX], varname[VARNAME_MAX]; - if (content->entries == NULL) + if (content->entries == nullptr) { tifiles_warning("%s: skipping content with NULL content->entries", __FUNCTION__); return 0; } - if (fname != NULL) + if (fname != nullptr) { filename = g_strdup(fname); - if (filename == NULL) + if (filename == nullptr) { return ERR_MALLOC; } @@ -592,28 +588,28 @@ int ti9x_file_write_regular(const char *fname, Ti9xRegular *content, char **real else { tifiles_warning("%s: asked to build a filename from null content->entries[0], bailing out", __FUNCTION__); - if (real_fname != NULL) + if (real_fname != nullptr) { - *real_fname = NULL; + *real_fname = nullptr; } return 0; } - if (real_fname != NULL) + if (real_fname != nullptr) { *real_fname = g_strdup(filename); } } // build the table of folder & variable entries - table = tifiles_create_table_of_entries((FileContent *)content, &num_folders); - if (table == NULL) + int** table = tifiles_create_table_of_entries((FileContent*)content, &num_folders); + if (table == nullptr) { g_free(filename); return ERR_MALLOC; } - f = g_fopen(filename, "wb"); - if (f == NULL) + FILE* f = g_fopen(filename, "wb"); + if (f == nullptr) { tifiles_info( "Unable to open this file: %s", filename); tifiles_free_table_of_entries(table); @@ -643,13 +639,12 @@ int ti9x_file_write_regular(const char *fname, Ti9xRegular *content, char **real } // write table of entries - for (i = 0; table[i] != NULL; i++) + for (i = 0; table[i] != nullptr; i++) { - VarEntry *fentry; int j, idx = table[i][0]; - fentry = content->entries[idx]; + const VarEntry* fentry = content->entries[idx]; - if (fentry == NULL) + if (fentry == nullptr) { tifiles_warning("%s: skipping null content entry %d", __FUNCTION__, i); continue; @@ -668,8 +663,8 @@ int ti9x_file_write_regular(const char *fname, Ti9xRegular *content, char **real for (j = 0; table[i][j] != -1; j++) { - int idx2 = table[i][j]; - VarEntry *entry = content->entries[idx2]; + const int idx2 = table[i][j]; + const VarEntry *entry = content->entries[idx2]; uint8_t attr = ATTRB_NONE; if (fwrite_long(f, offset) < 0) goto tfwr; @@ -688,19 +683,16 @@ int ti9x_file_write_regular(const char *fname, Ti9xRegular *content, char **real if (fwrite_word(f, 0x5aa5) < 0) goto tfwr; // write data - for (i = 0; table[i] != NULL; i++) + for (i = 0; table[i] != nullptr; i++) { - int j; - - for (j = 0; table[i][j] != -1; j++) + for (int j = 0; table[i][j] != -1; j++) { - int idx = table[i][j]; - VarEntry *entry = content->entries[idx]; - uint16_t sum; + const int idx = table[i][j]; + const VarEntry *entry = content->entries[idx]; if (fwrite_long(f, 0) < 0) goto tfwr; if (fwrite(entry->data, 1, entry->size, f) < entry->size) goto tfwr; - sum = tifiles_checksum(entry->data, entry->size); + const uint16_t sum = tifiles_checksum(entry->data, entry->size); if (fwrite_word(f, sum) < 0) goto tfwr; } } @@ -729,16 +721,14 @@ int ti9x_file_write_regular(const char *fname, Ti9xRegular *content, char **real **/ int ti9x_file_write_backup(const char *filename, Ti9xBackup *content) { - FILE *f; - - if (filename == NULL || content == NULL) + if (filename == nullptr || content == nullptr) { tifiles_critical("%s: an argument is NULL", __FUNCTION__); return ERR_INVALID_FILE; } - f = g_fopen(filename, "wb"); - if (f == NULL) + FILE* f = g_fopen(filename, "wb"); + if (f == nullptr) { tifiles_info("Unable to open this file: %s", filename); return ERR_FILE_OPEN; @@ -780,11 +770,10 @@ int ti9x_file_write_backup(const char *filename, Ti9xBackup *content) **/ int ti9x_file_write_flash(const char *fname, Ti9xFlash *head, char **real_fname) { - FILE *f; - Ti9xFlash *content = head; + const Ti9xFlash *content = head; char *filename; - if (head == NULL) + if (head == nullptr) { tifiles_critical("%s: head is NULL", __FUNCTION__); return ERR_INVALID_FILE; @@ -793,7 +782,7 @@ int ti9x_file_write_flash(const char *fname, Ti9xFlash *head, char **real_fname) if (fname) { filename = g_strdup(fname); - if (filename == NULL) + if (filename == nullptr) { return ERR_MALLOC; } @@ -802,14 +791,14 @@ int ti9x_file_write_flash(const char *fname, Ti9xFlash *head, char **real_fname) { VarEntry ve; - for (content = head; content != NULL; content = content->next) + for (content = head; content != nullptr; content = content->next) { if (content->data_type == TI89_AMS || content->data_type == TI89_APPL) { break; } } - if (content == NULL) + if (content == nullptr) { tifiles_critical("%s: content is NULL", __FUNCTION__); return ERR_BAD_FILE; @@ -820,21 +809,21 @@ int ti9x_file_write_flash(const char *fname, Ti9xFlash *head, char **real_fname) ve.type = content->data_type; filename = tifiles_build_filename(content->model, &ve); - if (real_fname != NULL) + if (real_fname != nullptr) { *real_fname = g_strdup(filename); } } - f = g_fopen(filename, "wb"); - if (f == NULL) + FILE* f = g_fopen(filename, "wb"); + if (f == nullptr) { tifiles_info("Unable to open this file: %s", filename); g_free(filename); return ERR_FILE_OPEN; } - for (content = head; content != NULL; content = content->next) + for (content = head; content != nullptr; content = content->next) { if (fwrite_8_chars(f, "**TIFL**") < 0) goto tfwf; if (fwrite_byte(f, content->revision_major) < 0) goto tfwf; @@ -880,7 +869,7 @@ int ti9x_file_write_flash(const char *fname, Ti9xFlash *head, char **real_fname) **/ int ti9x_content_display_backup(Ti9xBackup *content) { - if (content == NULL) + if (content == nullptr) { tifiles_critical("%s(NULL)", __FUNCTION__); return ERR_INVALID_FILE; @@ -911,9 +900,7 @@ int ti9x_content_display_backup(Ti9xBackup *content) **/ int ti9x_content_display_flash(Ti9xFlash *content) { - Ti9xFlash *ptr; - - for (ptr = content; ptr != NULL; ptr = ptr->next) + for (Ti9xFlash* ptr = content; ptr != nullptr; ptr = ptr->next) { tifiles_info("FlashContent for TI-9x: %p", ptr); tifiles_info("Model: %02X (%u)", ptr->model, ptr->model); @@ -963,15 +950,12 @@ int ti9x_content_display_flash(Ti9xFlash *content) **/ int ti9x_file_display(const char *filename) { - Ti9xRegular *content1; - Ti9xBackup *content2; - Ti9xFlash *content3; int ret; // the testing order is important: regular before backup (due to TI89/92+) if (tifiles_file_is_flash(filename) || tifiles_file_is_tib(filename)) { - content3 = tifiles_content_create_flash(CALC_TI92); + Ti9xFlash* content3 = tifiles_content_create_flash(CALC_TI92); ret = ti9x_file_read_flash(filename, content3); if (!ret) { @@ -981,7 +965,7 @@ int ti9x_file_display(const char *filename) } else if (tifiles_file_is_regular(filename)) { - content1 = tifiles_content_create_regular(CALC_TI92); + Ti9xRegular* content1 = tifiles_content_create_regular(CALC_TI92); ret = ti9x_file_read_regular(filename, content1); if (!ret) { @@ -991,7 +975,7 @@ int ti9x_file_display(const char *filename) } else if (tifiles_file_is_backup(filename)) { - content2 = tifiles_content_create_backup(CALC_TI92); + Ti9xBackup* content2 = tifiles_content_create_backup(CALC_TI92); ret = ti9x_file_read_backup(filename, content2); if (!ret) { diff --git a/libtifiles/trunk/src/filesnsp.cc b/libtifiles/trunk/src/filesnsp.cc index e84b22de6..bb743878d 100644 --- a/libtifiles/trunk/src/filesnsp.cc +++ b/libtifiles/trunk/src/filesnsp.cc @@ -60,7 +60,7 @@ int tnsp_file_read_regular(const char *filename, FileContent *content) FILE *f; int ret = ERR_FILE_IO; - if (content == NULL) + if (content == nullptr) { tifiles_critical("%s: an argument is NULL", __FUNCTION__); return ERR_INVALID_FILE; @@ -73,7 +73,7 @@ int tnsp_file_read_regular(const char *filename, FileContent *content) } f = g_fopen(filename, "rb"); - if (f == NULL) + if (f == nullptr) { tifiles_info( "Unable to open this file: %s", filename); ret = ERR_FILE_OPEN; @@ -86,7 +86,6 @@ int tnsp_file_read_regular(const char *filename, FileContent *content) content->entries = (VarEntry **)g_malloc0((content->num_entries + 1) * sizeof(VarEntry*)); { - long cur_pos; VarEntry *entry = content->entries[0] = (VarEntry *)g_malloc0(sizeof(VarEntry)); gchar *basename = g_path_get_basename(filename); @@ -102,7 +101,7 @@ int tnsp_file_read_regular(const char *filename, FileContent *content) entry->attr = ATTRB_NONE; if (fseek(f, 0, SEEK_END) < 0) goto tfrr; - cur_pos = ftell(f); + const long cur_pos = ftell(f); if (cur_pos < 0) goto tfrr; if (fseek(f, 0, SEEK_SET) < 0) goto tfrr; @@ -152,7 +151,7 @@ int tnsp_file_read_flash(const char *filename, FlashContent *content) uint32_t file_size; int ret = ERR_FILE_IO; - if (content == NULL) + if (content == nullptr) { tifiles_critical("%s: an argument is NULL", __FUNCTION__); return ERR_INVALID_FILE; @@ -165,7 +164,7 @@ int tnsp_file_read_flash(const char *filename, FlashContent *content) } f = g_fopen(filename, "rb"); - if (f == NULL) + if (f == nullptr) { tifiles_info("Unable to open this file: %s", filename); ret = ERR_FILE_OPEN; @@ -250,14 +249,14 @@ int tnsp_file_read_flash(const char *filename, FlashContent *content) if (fseek(f, 0, SEEK_SET) < 0) goto tfrf; content->data_part = (uint8_t *)g_malloc0(content->data_length); - if (content->data_part == NULL) + if (content->data_part == nullptr) { fclose(f); tifiles_content_delete_flash(content); return ERR_MALLOC; } - content->next = NULL; + content->next = nullptr; if(fread(content->data_part, 1, content->data_length, f) < content->data_length) goto tfrf; fclose(f); @@ -291,20 +290,18 @@ int tnsp_file_read_flash(const char *filename, FlashContent *content) **/ int tnsp_file_write_regular(const char *fname, FileContent *content, char **real_fname) { - FILE *f; - char *filename = NULL; - VarEntry *entry; + char *filename = nullptr; - if (content->entries == NULL || content->entries[0] == NULL) + if (content->entries == nullptr || content->entries[0] == nullptr) { tifiles_warning("%s: skipping content with NULL content->entries or content->entries[0]", __FUNCTION__); return ERR_FILE_IO; } - if (fname != NULL) + if (fname != nullptr) { filename = g_strdup(fname); - if (filename == NULL) + if (filename == nullptr) { return ERR_MALLOC; } @@ -312,21 +309,21 @@ int tnsp_file_write_regular(const char *fname, FileContent *content, char **real else { filename = tifiles_build_filename(content->model_dst, content->entries[0]); - if (real_fname != NULL) + if (real_fname != nullptr) { *real_fname = g_strdup(filename); } } - f = g_fopen(filename, "wb"); - if (f == NULL) + FILE* f = g_fopen(filename, "wb"); + if (f == nullptr) { tifiles_info( "Unable to open this file: %s", filename); g_free(filename); return ERR_FILE_OPEN; } - entry = content->entries[0]; + const VarEntry* entry = content->entries[0]; if(fwrite(entry->data, 1, entry->size, f) < entry->size) { goto tfwr; @@ -359,13 +356,13 @@ int tnsp_content_display_flash(FlashContent *content) { FlashContent *ptr = content; - if (content == NULL) + if (content == nullptr) { tifiles_critical("%s(NULL)", __FUNCTION__); return ERR_INVALID_FILE; } - for (ptr = content; ptr != NULL; ptr = ptr->next) + for (ptr = content; ptr != nullptr; ptr = ptr->next) { tifiles_info("FlashContent for TI-Nspire: %p", ptr); tifiles_info("Model: %02X (%u)", ptr->model, ptr->model); @@ -395,13 +392,11 @@ int tnsp_content_display_flash(FlashContent *content) **/ int tnsp_file_display(const char *filename) { - FileContent *content1; - FlashContent *content3; int ret; if (tifiles_file_is_os(filename)) { - content3 = tifiles_content_create_flash(CALC_NSPIRE); + FlashContent* content3 = tifiles_content_create_flash(CALC_NSPIRE); ret = tnsp_file_read_flash(filename, content3); if (!ret) { @@ -411,7 +406,7 @@ int tnsp_file_display(const char *filename) } else if (tifiles_file_is_regular(filename)) { - content1 = tifiles_content_create_regular(CALC_NSPIRE); + FileContent* content1 = tifiles_content_create_regular(CALC_NSPIRE); ret = tnsp_file_read_regular(filename, content1); if (!ret) { diff --git a/libtifiles/trunk/src/filesxx.cc b/libtifiles/trunk/src/filesxx.cc index 8bdec8fe3..3292dfea2 100644 --- a/libtifiles/trunk/src/filesxx.cc +++ b/libtifiles/trunk/src/filesxx.cc @@ -51,7 +51,7 @@ FileContent* TICALL tifiles_content_create_regular(CalcModel model) { FileContent* content = (FileContent *)g_malloc0(sizeof(FileContent)); - if (content != NULL) + if (content != nullptr) { if ((unsigned int)model >= CALC_MAX) { @@ -78,20 +78,18 @@ FileContent* TICALL tifiles_content_create_regular(CalcModel model) **/ int TICALL tifiles_content_delete_regular(FileContent *content) { - unsigned int i; - #ifdef TRACE_CONTENT_INSTANCES tifiles_info("tifiles_content_delete_regular: %p", content); tifiles_file_display_regular(content); #endif - if (content != NULL) + if (content != nullptr) { - for (i = 0; i < content->num_entries; i++) + for (unsigned int i = 0; i < content->num_entries; i++) { VarEntry *entry = content->entries[i]; - if (entry != NULL) + if (entry != nullptr) { g_free(entry->data); g_free(entry); @@ -122,26 +120,25 @@ int TICALL tifiles_content_delete_regular(FileContent *content) **/ FileContent* TICALL tifiles_content_dup_regular(FileContent *content) { - FileContent *dup = NULL; - unsigned int i; + FileContent *dup = nullptr; - if (content != NULL) + if (content != nullptr) { dup = tifiles_content_create_regular(content->model); - if (dup != NULL) + if (dup != nullptr) { memcpy(dup, content, sizeof(FileContent)); dup->entries = tifiles_ve_create_array(content->num_entries); - if (dup->entries != NULL) + if (dup->entries != nullptr) { - for (i = 0; i < content->num_entries; i++) + for (unsigned int i = 0; i < content->num_entries; i++) { dup->entries[i] = tifiles_ve_dup(content->entries[i]); - if (dup->entries[i] == NULL) + if (dup->entries[i] == nullptr) { tifiles_content_delete_regular(dup); - dup = NULL; + dup = nullptr; break; } } @@ -150,7 +147,7 @@ FileContent* TICALL tifiles_content_dup_regular(FileContent *content) { dup->num_entries = 0; tifiles_content_delete_regular(dup); - dup = NULL; + dup = nullptr; } } } @@ -181,7 +178,7 @@ FileContent* TICALL tifiles_content_dup_regular(FileContent *content) **/ int tifiles_file_read_regular(const char *filename, FileContent *content) { - if (filename == NULL || content == NULL) + if (filename == nullptr || content == nullptr) { tifiles_critical("%s: an argument is NULL", __FUNCTION__); return ERR_INVALID_FILE; @@ -227,7 +224,7 @@ int tifiles_file_read_regular(const char *filename, FileContent *content) **/ int tifiles_file_write_regular(const char *filename, FileContent *content, char **real_fname) { - if (content == NULL || (filename == NULL && real_fname == NULL)) + if (content == nullptr || (filename == nullptr && real_fname == nullptr)) { tifiles_critical("%s: an argument is NULL", __FUNCTION__); return ERR_INVALID_FILE; @@ -267,11 +264,10 @@ int tifiles_file_write_regular(const char *filename, FileContent *content, char **/ int TICALL tifiles_file_display_regular(FileContent *content) { - unsigned int i; char trans[257]; int model_supports_folder = 1; - if (content == NULL) + if (content == nullptr) { tifiles_critical("%s(NULL)", __FUNCTION__); return ERR_INVALID_FILE; @@ -311,12 +307,12 @@ int TICALL tifiles_file_display_regular(FileContent *content) tifiles_info("Number of entries: %u", content->num_entries); tifiles_info("Entries: %p", content->entries); - if (content->entries != NULL) + if (content->entries != nullptr) { - for (i = 0; i < content->num_entries; i++) + for (unsigned int i = 0; i < content->num_entries; i++) { VarEntry * ve = content->entries[i]; - if (ve != NULL) + if (ve != nullptr) { tifiles_info("Entry #%u %p", i, ve); if (model_supports_folder) @@ -355,7 +351,7 @@ BackupContent* TICALL tifiles_content_create_backup(CalcModel model) { BackupContent* content = (BackupContent *)g_malloc0(sizeof(BackupContent)); - if (content != NULL) + if (content != nullptr) { if ((unsigned int)model >= CALC_MAX) { @@ -387,7 +383,7 @@ int TICALL tifiles_content_delete_backup(BackupContent *content) tifiles_file_display_backup(content); #endif - if (content != NULL) + if (content != nullptr) { if (tifiles_calc_is_ti9x(content->model)) { @@ -425,7 +421,7 @@ int TICALL tifiles_content_delete_backup(BackupContent *content) **/ int tifiles_file_read_backup(const char *filename, BackupContent *content) { - if (filename == NULL || content == NULL) + if (filename == nullptr || content == nullptr) { tifiles_critical("%s: an argument is NULL", __FUNCTION__); return ERR_INVALID_FILE; @@ -459,7 +455,7 @@ int tifiles_file_read_backup(const char *filename, BackupContent *content) **/ int tifiles_file_write_backup(const char *filename, BackupContent *content) { - if (filename == NULL || content == NULL) + if (filename == nullptr || content == nullptr) { tifiles_critical("%s: an argument is NULL", __FUNCTION__); return ERR_INVALID_FILE; @@ -492,7 +488,7 @@ int tifiles_file_write_backup(const char *filename, BackupContent *content) **/ int TICALL tifiles_file_display_backup(BackupContent *content) { - if (content == NULL) + if (content == nullptr) { tifiles_critical("%s(NULL)", __FUNCTION__); return ERR_INVALID_FILE; @@ -527,7 +523,7 @@ FlashContent* TICALL tifiles_content_create_flash(CalcModel model) { FlashContent* content = (FlashContent *)g_malloc0(sizeof(FlashContent)); - if (content != NULL) + if (content != nullptr) { if ((unsigned int)model >= CALC_MAX) { @@ -577,23 +573,21 @@ int TICALL tifiles_content_delete_flash(FlashContent *content) tifiles_file_display_flash(content); #endif - if (content != NULL) + if (content != nullptr) { #if !defined(DISABLE_TI8X) && !defined(DISABLE_TI9X) - FlashContent *ptr; - unsigned int i; g_free(content->data_part); - ptr = content->next; - while (ptr != NULL) + FlashContent* ptr = content->next; + while (ptr != nullptr) { FlashContent *next = ptr->next; g_free(ptr->data_part); g_free(ptr); - for (i = 0; i < content->num_pages; i++) + for (unsigned int i = 0; i < content->num_pages; i++) { g_free(content->pages[i]->data); g_free(content->pages[i]); @@ -625,13 +619,13 @@ int TICALL tifiles_content_delete_flash(FlashContent *content) **/ FlashContent* TICALL tifiles_content_dup_flash(FlashContent *content) { - FlashContent *dup = NULL; + FlashContent *dup = nullptr; FlashContent *p, *q; - if (content != NULL) + if (content != nullptr) { dup = tifiles_content_create_flash(content->model); - if (dup != NULL) + if (dup != nullptr) { for (p = content, q = dup; p; p = p->next, q = q->next) { @@ -650,11 +644,9 @@ FlashContent* TICALL tifiles_content_dup_flash(FlashContent *content) // TI-Z80 part if (tifiles_calc_is_ti8x(content->model)) { - unsigned int i; - // copy pages q->pages = tifiles_fp_create_array(p->num_pages); - for (i = 0; i < content->num_pages; i++) + for (unsigned int i = 0; i < content->num_pages; i++) { q->pages[i] = (FlashPage *)g_malloc0(sizeof(FlashPage)); memcpy(q->pages[i], p->pages[i], sizeof(FlashPage)); @@ -698,7 +690,7 @@ FlashContent* TICALL tifiles_content_dup_flash(FlashContent *content) **/ int tifiles_file_read_flash(const char *filename, FlashContent *content) { - if (filename == NULL || content == NULL) + if (filename == nullptr || content == nullptr) { tifiles_critical("%s: an argument is NULL", __FUNCTION__); return ERR_INVALID_FILE; @@ -744,7 +736,7 @@ int tifiles_file_read_flash(const char *filename, FlashContent *content) **/ int tifiles_file_write_flash2(const char *filename, FlashContent *content, char **real_fname) { - if (content == NULL || (filename == NULL && real_fname == NULL)) + if (content == nullptr || (filename == nullptr && real_fname == nullptr)) { tifiles_critical("%s: an argument is NULL", __FUNCTION__); return ERR_INVALID_FILE; @@ -779,7 +771,7 @@ int tifiles_file_write_flash2(const char *filename, FlashContent *content, char **/ int tifiles_file_write_flash(const char *filename, FlashContent *content) { - return tifiles_file_write_flash2(filename, content, NULL); + return tifiles_file_write_flash2(filename, content, nullptr); } /** @@ -792,7 +784,7 @@ int tifiles_file_write_flash(const char *filename, FlashContent *content) **/ int TICALL tifiles_file_display_flash(FlashContent *content) { - if (content == NULL) + if (content == nullptr) { tifiles_critical("%s(NULL)", __FUNCTION__); return ERR_INVALID_FILE; @@ -876,24 +868,23 @@ int** tifiles_create_table_of_entries(FileContent *content, unsigned int *nfolde { unsigned int num_folders = 0; unsigned int i, j; - char **ptr, *folder_list[32768] = { 0 }; - int **table; + char **ptr, *folder_list[32768] = { nullptr }; - if (content == NULL) + if (content == nullptr) { tifiles_critical("%s: an argument is NULL", __FUNCTION__); - return NULL; + return nullptr; } - if (content->entries != NULL) + if (content->entries != nullptr) { // determine how many folders we have for (i = 0; i < content->num_entries; i++) { - VarEntry *entry = content->entries[i]; + const VarEntry *entry = content->entries[i]; // scan for an existing folder entry - for (ptr = folder_list; *ptr != NULL; ptr++) + for (ptr = folder_list; *ptr != nullptr; ptr++) { if (!strcmp(*ptr, entry->folder)) { @@ -901,13 +892,13 @@ int** tifiles_create_table_of_entries(FileContent *content, unsigned int *nfolde break; } } - if (*ptr == NULL) + if (*ptr == nullptr) { // add new folder entry folder_list[num_folders] = (char *) g_malloc0(257); //printf("%i: adding '%s'\n", num_folders, entry->folder); strncpy(folder_list[num_folders], entry->folder, 257 - 1); folder_list[num_folders][257 - 1] = 0; - folder_list[num_folders + 1] = NULL; + folder_list[num_folders + 1] = nullptr; num_folders++; } } @@ -916,14 +907,14 @@ int** tifiles_create_table_of_entries(FileContent *content, unsigned int *nfolde num_folders++; } } - if (nfolders != NULL) + if (nfolders != nullptr) { *nfolders = num_folders; } // allocate the folder list - table = (int **) g_malloc0((num_folders + 1) * sizeof(int *)); - table[num_folders] = NULL; + int** table = (int**)g_malloc0((num_folders + 1) * sizeof(int*)); + table[num_folders] = nullptr; // for each folder, determine how many variables we have // and allocate array with indexes @@ -933,7 +924,7 @@ int** tifiles_create_table_of_entries(FileContent *content, unsigned int *nfolde for (i = 0, k = 0; i < content->num_entries; i++) { - VarEntry *entry = content->entries[i]; + const VarEntry *entry = content->entries[i]; if (!strcmp(folder_list[j], entry->folder)) { @@ -957,10 +948,10 @@ int** tifiles_create_table_of_entries(FileContent *content, unsigned int *nfolde void tifiles_free_table_of_entries(int ** table) { - if (table != NULL) + if (table != nullptr) { int ** ptr = table; - while (*ptr != NULL) + while (*ptr != nullptr) { g_free(*ptr); ptr++; diff --git a/libtifiles/trunk/src/filetypes.cc b/libtifiles/trunk/src/filetypes.cc index 2489a4e5d..e50ad2e4c 100644 --- a/libtifiles/trunk/src/filetypes.cc +++ b/libtifiles/trunk/src/filetypes.cc @@ -88,12 +88,12 @@ const char * TICALL tifiles_fext_of_group (CalcModel model) switch (model) { case CALC_NONE: - return NULL; + return nullptr; #ifndef DISABLE_TI8X case CALC_TI73: return "73g"; case CALC_TI80: - return NULL; + return nullptr; case CALC_TI82: return "82g"; case CALC_TI83: @@ -146,13 +146,13 @@ const char * TICALL tifiles_fext_of_group (CalcModel model) case CALC_CBR2: case CALC_LABPRO: case CALC_TIPRESENTER: - return NULL; + return nullptr; default: tifiles_critical("%s: invalid model argument", __FUNCTION__); break; } - return NULL; + return nullptr; } /** @@ -173,7 +173,7 @@ const char * TICALL tifiles_fext_of_backup (CalcModel model) case CALC_TI73: return "73b"; case CALC_TI80: - return NULL; + return nullptr; case CALC_TI82: return "82b"; case CALC_TI83: @@ -190,7 +190,7 @@ const char * TICALL tifiles_fext_of_backup (CalcModel model) return "8Cb"; case CALC_TI83PCE_USB: case CALC_TI84PCE_USB: - return NULL; + return nullptr; case CALC_TI85: return "85b"; case CALC_TI86: @@ -228,13 +228,13 @@ const char * TICALL tifiles_fext_of_backup (CalcModel model) case CALC_CBR2: case CALC_LABPRO: case CALC_TIPRESENTER: - return NULL; + return nullptr; default: tifiles_critical("%s: invalid model argument", __FUNCTION__); break; } - return NULL; + return nullptr; } /** @@ -255,11 +255,11 @@ const char * TICALL tifiles_fext_of_flash_app (CalcModel model) case CALC_TI73: return "73k"; case CALC_TI80: - return NULL; + return nullptr; case CALC_TI82: - return NULL; + return nullptr; case CALC_TI83: - return NULL; + return nullptr; case CALC_TI83P: case CALC_TI84P: case CALC_TI84P_USB: @@ -274,11 +274,11 @@ const char * TICALL tifiles_fext_of_flash_app (CalcModel model) case CALC_TI82A_USB: case CALC_TI84PT_USB: case CALC_TI82AEP_USB: - return NULL; + return nullptr; case CALC_TI85: - return NULL; + return nullptr; case CALC_TI86: - return NULL; + return nullptr; #endif #ifndef DISABLE_TI8X case CALC_TI89: @@ -286,7 +286,7 @@ const char * TICALL tifiles_fext_of_flash_app (CalcModel model) case CALC_TI89T_USB: return "89k"; case CALC_TI92: - return NULL; + return nullptr; case CALC_TI92P: return "9Xk"; case CALC_V200: @@ -312,13 +312,13 @@ const char * TICALL tifiles_fext_of_flash_app (CalcModel model) case CALC_CBR2: case CALC_LABPRO: case CALC_TIPRESENTER: - return NULL; + return nullptr; default: tifiles_critical("%s: invalid model argument", __FUNCTION__); break; } - return NULL; + return nullptr; } /** @@ -334,16 +334,16 @@ const char * TICALL tifiles_fext_of_flash_os(CalcModel model) switch (model) { case CALC_NONE: - return NULL; + return nullptr; #ifndef DISABLE_TI8X case CALC_TI73: return "73u"; case CALC_TI80: - return NULL; + return nullptr; case CALC_TI82: - return NULL; + return nullptr; case CALC_TI83: - return NULL; + return nullptr; case CALC_TI83P: case CALC_TI84P: case CALC_TI84P_USB: @@ -361,9 +361,9 @@ const char * TICALL tifiles_fext_of_flash_os(CalcModel model) case CALC_TI82AEP_USB: return "8Yu"; case CALC_TI85: - return NULL; + return nullptr; case CALC_TI86: - return NULL; + return nullptr; #endif #ifndef DISABLE_TI9X case CALC_TI89: @@ -371,7 +371,7 @@ const char * TICALL tifiles_fext_of_flash_os(CalcModel model) case CALC_TI89T_USB: return "89u"; case CALC_TI92: - return NULL; + return nullptr; case CALC_TI92P: return "9Xu"; case CALC_V200: @@ -408,7 +408,7 @@ const char * TICALL tifiles_fext_of_flash_os(CalcModel model) case CALC_CBL: case CALC_CBR: case CALC_CBR2: - return NULL; + return nullptr; case CALC_CBL2: case CALC_LABPRO: return "c2u"; // .hex is also seen in some OS upgraders. @@ -419,7 +419,7 @@ const char * TICALL tifiles_fext_of_flash_os(CalcModel model) break; } - return NULL; + return nullptr; } /** @@ -440,11 +440,11 @@ const char * TICALL tifiles_fext_of_certif(CalcModel model) case CALC_TI73: return "73q"; case CALC_TI80: - return NULL; + return nullptr; case CALC_TI82: - return NULL; + return nullptr; case CALC_TI83: - return NULL; + return nullptr; case CALC_TI83P: case CALC_TI84P: case CALC_TI84P_USB: @@ -459,11 +459,11 @@ const char * TICALL tifiles_fext_of_certif(CalcModel model) case CALC_TI82A_USB: case CALC_TI84PT_USB: case CALC_TI82AEP_USB: - return NULL; + return nullptr; case CALC_TI85: - return NULL; + return nullptr; case CALC_TI86: - return NULL; + return nullptr; #endif #ifndef DISABLE_TI9X case CALC_TI89: @@ -471,7 +471,7 @@ const char * TICALL tifiles_fext_of_certif(CalcModel model) case CALC_TI89T_USB: return "89q"; case CALC_TI92: - return NULL; + return nullptr; case CALC_TI92P: return "9Xq"; case CALC_V200: @@ -497,13 +497,13 @@ const char * TICALL tifiles_fext_of_certif(CalcModel model) case CALC_CBR2: case CALC_LABPRO: case CALC_TIPRESENTER: - return NULL; + return nullptr; default: tifiles_critical("%s: invalid calc_type argument", __FUNCTION__); break; } - return NULL; + return nullptr; } /** @@ -516,10 +516,10 @@ const char * TICALL tifiles_fext_of_certif(CalcModel model) **/ char * TICALL tifiles_fext_get(const char *filename) { - if (filename != NULL) + if (filename != nullptr) { char * d = (char *)strrchr(filename, '.'); - if (d != NULL) + if (d != nullptr) { return (++d); } @@ -571,20 +571,18 @@ void TICALL tifiles_fext_free(char *filename) **/ int TICALL tifiles_file_has_ti_header(const char *filename) { - FILE *f; char buf[9]; - char *p; int ret = 0; - if (filename != NULL) + if (filename != nullptr) { - f = g_fopen(filename, "rb"); - if (f != NULL) + FILE* f = g_fopen(filename, "rb"); + if (f != nullptr) { memset(buf, 0, sizeof(buf)); if (fread_8_chars(f, buf) == 0) { - for (p = buf; *p != '\0'; p++) + for (char* p = buf; *p != '\0'; p++) { *p = toupper(*p); } @@ -623,10 +621,10 @@ int TICALL tifiles_file_has_tib_header(const char *filename) char str[64]; int ret = 0; - if (filename != NULL) + if (filename != nullptr) { #ifdef CHECK_FILE_EXTENSIONS - char *e = tifiles_fext_get(filename); + const char *e = tifiles_fext_get(filename); if ( e[0] == 0 || g_ascii_strcasecmp(e, "tib")) @@ -636,7 +634,7 @@ int TICALL tifiles_file_has_tib_header(const char *filename) #endif f = g_fopen(filename, "rb"); - if (f != NULL) + if (f != nullptr) { if (fread_n_chars(f, 22 + sizeof(TIB_SIGNATURE) + 1, str) == 0) { @@ -670,10 +668,10 @@ int TICALL tifiles_file_has_tig_header(const char *filename) char str[5]; int ret = 0; - if (filename != NULL) + if (filename != nullptr) { #ifdef CHECK_FILE_EXTENSIONS - char *e = tifiles_fext_get(filename); + const char *e = tifiles_fext_get(filename); if ( e[0] == 0 || g_ascii_strcasecmp(e, "tig")) @@ -683,7 +681,7 @@ int TICALL tifiles_file_has_tig_header(const char *filename) #endif f = g_fopen(filename, "rb"); - if (f != NULL) + if (f != nullptr) { if (fread_n_chars(f, strlen(TIG_SIGNATURE), str) == 0) { @@ -711,15 +709,13 @@ int TICALL tifiles_file_has_tig_header(const char *filename) **/ int TICALL tifiles_file_has_tifl_header(const char *filename, uint8_t *dev_type, uint8_t *data_type) { - FILE *f; uint8_t buf[78]; - uint32_t len; int ret = 0; - if (filename != NULL) + if (filename != nullptr) { - f = g_fopen(filename, "rb"); - if (f != NULL) + FILE* f = g_fopen(filename, "rb"); + if (f != nullptr) { while (fread(buf, 1, 78, f) == 78) { @@ -733,16 +729,16 @@ int TICALL tifiles_file_has_tifl_header(const char *filename, uint8_t *dev_type, /* if there are multiple entries (old OS files with license agreement, old app files with certificate), return the type of the last entry */ - if (dev_type != NULL) + if (dev_type != nullptr) { *dev_type = buf[48]; } - if (data_type != NULL) + if (data_type != nullptr) { *data_type = buf[49]; } - len = buf[74] | (((uint32_t)buf[75]) << 8) | (((uint32_t)buf[76]) << 16) | (((uint32_t)buf[77]) << 24); + const uint32_t len = buf[74] | (((uint32_t)buf[75]) << 8) | (((uint32_t)buf[76]) << 16) | (((uint32_t)buf[77]) << 24); if (fseek(f, len, SEEK_CUR)) { break; @@ -784,10 +780,10 @@ int TICALL tifiles_file_has_tno_header(const char *filename) char str[1025]; int ret = 0; - if (filename != NULL) + if (filename != nullptr) { #ifdef CHECK_FILE_EXTENSIONS - char *e = tifiles_fext_get(filename); + const char *e = tifiles_fext_get(filename); if ( e[0] == 0 || ( g_ascii_strcasecmp(e, "tno") && g_ascii_strcasecmp(e, "tnc") @@ -803,7 +799,7 @@ int TICALL tifiles_file_has_tno_header(const char *filename) #endif f = g_fopen(filename, "rb"); - if (f != NULL) + if (f != nullptr) { if (fread_n_chars(f, sizeof(str) - 1, str) == 0) { @@ -828,8 +824,8 @@ int TICALL tifiles_file_has_tno_header(const char *filename) // Sadly, memmem() is not portable. unsigned int remaining = sizeof(str) - 1 - sizeof(TCO2_SIGNATURE) - 1; char * ptr1 = (char *)memchr(str, 'T', remaining); - char * ptr2 = str; - while (NULL != ptr1) + const char * ptr2 = str; + while (nullptr != ptr1) { remaining -= (ptr1 - ptr2 + 1); if ( ptr1[ 1] == 'I' && ptr1[ 2] == '-' && ptr1[ 3] == 'N' && ptr1[ 4] == 's' @@ -944,9 +940,7 @@ static int is_regfile(const char *filename) **/ int TICALL tifiles_file_is_ti(const char *filename) { - char *e; - - if (filename != NULL) + if (filename != nullptr) { // bug: check that file is not a FIFO if (!is_regfile(filename)) @@ -957,13 +951,13 @@ int TICALL tifiles_file_is_ti(const char *filename) if ( tifiles_file_has_ti_header(filename) || tifiles_file_has_tib_header(filename) || tifiles_file_has_tig_header(filename) - || tifiles_file_has_tifl_header(filename, NULL, NULL) + || tifiles_file_has_tifl_header(filename, nullptr, nullptr) || tifiles_file_has_tno_header(filename)) { return !0; } - e = tifiles_fext_get(filename); + const char* e = tifiles_fext_get(filename); #ifdef CHECK_FILE_EXTENSIONS if (e[0] == 0) @@ -1021,8 +1015,7 @@ int TICALL tifiles_file_is_single(const char *filename) **/ int TICALL tifiles_file_is_group(const char *filename) { - int i; - char *e = tifiles_fext_get(filename); + const char *e = tifiles_fext_get(filename); #ifdef CHECK_FILE_EXTENSIONS if (e[0] == 0) @@ -1035,7 +1028,7 @@ int TICALL tifiles_file_is_group(const char *filename) return 0; } - for (i = 1; i < CALC_MAX; i++) + for (int i = 1; i < CALC_MAX; i++) { if (GROUP_FILE_EXT[i][0] != 0 && !g_ascii_strcasecmp(e, GROUP_FILE_EXT[i])) { @@ -1074,8 +1067,7 @@ int TICALL tifiles_file_is_regular(const char *filename) **/ int TICALL tifiles_file_is_backup(const char *filename) { - int i; - char *e = tifiles_fext_get(filename); + const char *e = tifiles_fext_get(filename); #ifdef CHECK_FILE_EXTENSIONS if (e[0] == 0) @@ -1088,7 +1080,7 @@ int TICALL tifiles_file_is_backup(const char *filename) return 0; } - for (i = 1; i < CALC_MAX; i++) + for (int i = 1; i < CALC_MAX; i++) { if (BACKUP_FILE_EXT[i][0] != 0 && !g_ascii_strcasecmp(e, BACKUP_FILE_EXT[i])) { @@ -1118,7 +1110,7 @@ int TICALL tifiles_file_is_os(const char *filename) if ( tifiles_file_is_tib(filename) || tifiles_file_is_tno(filename) - || (tifiles_file_has_tifl_header(filename, NULL, &type) && type == TI83p_AMS)) + || (tifiles_file_has_tifl_header(filename, nullptr, &type) && type == TI83p_AMS)) { return !0; } @@ -1143,7 +1135,7 @@ int TICALL tifiles_file_is_app(const char *filename) return 0; } - if (tifiles_file_has_tifl_header(filename, NULL, &type) && type == TI83p_APPL) + if (tifiles_file_has_tifl_header(filename, nullptr, &type) && type == TI83p_APPL) { return !0; } @@ -1163,7 +1155,7 @@ int TICALL tifiles_file_is_flash(const char *filename) { return (tifiles_file_is_tib(filename) || tifiles_file_is_tno(filename) || - tifiles_file_has_tifl_header(filename, NULL, NULL)); + tifiles_file_has_tifl_header(filename, nullptr, nullptr)); } /** @@ -1222,7 +1214,7 @@ int TICALL tifiles_file_is_tno(const char *filename) **/ int TICALL tifiles_file_test(const char *filename, FileClass type, CalcModel target) { - char *e = tifiles_fext_get(filename); + const char *e = tifiles_fext_get(filename); uint8_t ctype, dtype; #ifdef CHECK_FILE_EXTENSIONS @@ -1292,11 +1284,10 @@ int TICALL tifiles_file_test(const char *filename, FileClass type, CalcModel tar } else if (target && tifiles_file_is_tib(filename)) { - FILE *f; uint8_t data[16]; - f = g_fopen(filename, "rb"); - if (f == NULL) + FILE* f = g_fopen(filename, "rb"); + if (f == nullptr) { return 0; } @@ -1373,8 +1364,7 @@ int TICALL tifiles_file_test(const char *filename, FileClass type, CalcModel tar { // No easy/light way for this part: we have to load the whole file // and to parse the TigEntry structures. - TigContent *content; - int ret, ok=0; + int ok=0; unsigned int k; if (!tifiles_file_has_tig_header(filename)) @@ -1382,8 +1372,8 @@ int TICALL tifiles_file_test(const char *filename, FileClass type, CalcModel tar return 0; } - content = tifiles_content_create_tigroup(CALC_NONE, 0); - ret = tifiles_file_read_tigroup(filename, content); + TigContent* content = tifiles_content_create_tigroup(CALC_NONE, 0); + const int ret = tifiles_file_read_tigroup(filename, content); if (ret) { tifiles_content_delete_tigroup(content); @@ -1392,7 +1382,7 @@ int TICALL tifiles_file_test(const char *filename, FileClass type, CalcModel tar for (k = 0; k < content->n_apps; k++) { - TigEntry *te = content->app_entries[k]; + const TigEntry *te = content->app_entries[k]; if(tifiles_calc_are_compat(te->content.regular->model, target)) { @@ -1402,7 +1392,7 @@ int TICALL tifiles_file_test(const char *filename, FileClass type, CalcModel tar for (k = 0; k < content->n_vars; k++) { - TigEntry *te = content->var_entries[k]; + const TigEntry *te = content->var_entries[k]; if(tifiles_calc_are_compat(te->content.regular->model, target)) { @@ -1438,7 +1428,7 @@ CalcModel TICALL tifiles_fext_to_model(const char *ext) { CalcModel type = CALC_NONE; - if (ext == NULL) + if (ext == nullptr) { tifiles_critical("%s(NULL)", __FUNCTION__); return CALC_NONE; @@ -1446,9 +1436,9 @@ CalcModel TICALL tifiles_fext_to_model(const char *ext) if (ext[0] != 0 && ext[1] != 0 && ext[2] != 0) { - char c1 = g_ascii_tolower(ext[0]); - char c2 = g_ascii_tolower(ext[1]); - char c3 = g_ascii_tolower(ext[2]); + const char c1 = g_ascii_tolower(ext[0]); + const char c2 = g_ascii_tolower(ext[1]); + const char c3 = g_ascii_tolower(ext[2]); #ifndef DISABLE_TI8X if (c1 == '7' && c2 == '3') @@ -1549,7 +1539,7 @@ CalcModel TICALL tifiles_fext_to_model(const char *ext) } else if (c2 == 'c' && c3 == 'c') { - char c4 = ext[3]; + const char c4 = ext[3]; if (c4 == 0) { type = CALC_NSPIRE_CX_CAS; @@ -1562,7 +1552,7 @@ CalcModel TICALL tifiles_fext_to_model(const char *ext) } else if (c2 == 'c' && c3 == 'o') { - char c4 = ext[3]; + const char c4 = ext[3]; if (c4 == 0) { type = CALC_NSPIRE_CX; @@ -1575,7 +1565,7 @@ CalcModel TICALL tifiles_fext_to_model(const char *ext) } else if (c2 == 'c' && c3 == 't') { - char c4 = ext[3]; + const char c4 = ext[3]; if (c4 == '2') { type = CALC_NSPIRE_CXIIT; @@ -1624,7 +1614,7 @@ CalcModel TICALL tifiles_fext_to_model(const char *ext) **/ CalcModel TICALL tifiles_file_get_model(const char *filename) { - char *e = tifiles_fext_get(filename); + const char *e = tifiles_fext_get(filename); return tifiles_fext_to_model(e); } @@ -1674,7 +1664,7 @@ FileClass TICALL tifiles_file_get_class(const char *filename) **/ const char *TICALL tifiles_file_get_type(const char *filename) { - char *e = tifiles_fext_get(filename); + const char *e = tifiles_fext_get(filename); #ifdef CHECK_FILE_EXTENSIONS if (e[0] == 0) { @@ -1798,7 +1788,7 @@ const char *TICALL tifiles_file_get_type(const char *filename) **/ const char *TICALL tifiles_file_get_icon(const char *filename) { - char *e = tifiles_fext_get(filename); + const char *e = tifiles_fext_get(filename); #ifdef CHECK_FILE_EXTENSIONS if (e[0] == 0) { diff --git a/libtifiles/trunk/src/grouped.cc b/libtifiles/trunk/src/grouped.cc index 4a0bc117b..19aa86804 100644 --- a/libtifiles/trunk/src/grouped.cc +++ b/libtifiles/trunk/src/grouped.cc @@ -62,15 +62,15 @@ FileContent** TICALL tifiles_content_create_group(unsigned int n_entries) **/ int TICALL tifiles_content_delete_group(FileContent **array) { - int i, n; + int n; - if (array != NULL) + if (array != nullptr) { // counter number of files to group - for (n = 0; array[n] != NULL; n++); + for (n = 0; array[n] != nullptr; n++); // release allocated memory in structures - for (i = 0; i < n; i++) + for (int i = 0; i < n; i++) { tifiles_content_delete_regular(array[i]); } @@ -102,16 +102,15 @@ int TICALL tifiles_content_delete_group(FileContent **array) **/ int TICALL tifiles_group_contents(FileContent **src_contents, FileContent **dst_content) { - FileContent *dst; - unsigned int i, j, n; + unsigned int n; - if (src_contents == NULL || dst_content == NULL) + if (src_contents == nullptr || dst_content == nullptr) { tifiles_critical("%s: an argument is NULL", __FUNCTION__); return ERR_INVALID_FILE; } - for (n = 0; src_contents[n] != NULL; n++) + for (n = 0; src_contents[n] != nullptr; n++) { if (ticonv_model_is_tinspire(src_contents[n]->model)) { @@ -119,8 +118,8 @@ int TICALL tifiles_group_contents(FileContent **src_contents, FileContent **dst_ } } - dst = (FileContent *)g_malloc0(sizeof(FileContent)); - if (dst == NULL) + FileContent* dst = (FileContent*)g_malloc0(sizeof(FileContent)); + if (dst == nullptr) return ERR_MALLOC; if (n > 0) @@ -130,17 +129,17 @@ int TICALL tifiles_group_contents(FileContent **src_contents, FileContent **dst_ dst->num_entries = n; dst->entries = (VarEntry **)g_malloc0((n + 1) * sizeof(VarEntry*)); - if (dst->entries == NULL) + if (dst->entries == nullptr) { g_free(dst); return ERR_MALLOC; } - for (i = 0; i < n; i++) + for (unsigned int i = 0; i < n; i++) { - FileContent *src = src_contents[i]; + const FileContent *src = src_contents[i]; - for (j = 0; j < src->num_entries; j++) + for (unsigned int j = 0; j < src->num_entries; j++) dst->entries[i] = tifiles_ve_dup(src->entries[j]); } @@ -165,9 +164,8 @@ int TICALL tifiles_group_contents(FileContent **src_contents, FileContent **dst_ int TICALL tifiles_ungroup_content(FileContent *src, FileContent ***dest) { unsigned int i; - FileContent **dst; - if (src == NULL || dest == NULL) + if (src == nullptr || dest == nullptr) { tifiles_critical("%s: an argument is NULL", __FUNCTION__); return ERR_INVALID_FILE; @@ -179,8 +177,8 @@ int TICALL tifiles_ungroup_content(FileContent *src, FileContent ***dest) } // allocate an array of FileContent structures (NULL terminated) - dst = *dest = (FileContent **)g_malloc0((src->num_entries + 1) * sizeof(FileContent *)); - if (dst == NULL) + FileContent** dst = *dest = (FileContent**)g_malloc0((src->num_entries + 1) * sizeof(FileContent*)); + if (dst == nullptr) { return ERR_MALLOC; } @@ -188,11 +186,11 @@ int TICALL tifiles_ungroup_content(FileContent *src, FileContent ***dest) // parse each entry and duplicate it into a single content for (i = 0; i < src->num_entries; i++) { - VarEntry *dst_entry = NULL; + VarEntry *dst_entry = nullptr; // allocate and duplicate content dst[i] = (FileContent *)g_malloc0(sizeof(FileContent)); - if (dst[i] == NULL) + if (dst[i] == nullptr) { return ERR_MALLOC; } @@ -207,7 +205,7 @@ int TICALL tifiles_ungroup_content(FileContent *src, FileContent ***dest) dst[i]->checksum += tifiles_checksum((uint8_t *) dst_entry, 15); dst[i]->checksum += tifiles_checksum(dst_entry->data, dst_entry->size); } - dst[i] = NULL; + dst[i] = nullptr; return 0; } @@ -228,18 +226,18 @@ int TICALL tifiles_ungroup_content(FileContent *src, FileContent ***dest) int TICALL tifiles_group_files(char **src_filenames, const char *dst_filename) { int i, n; - FileContent **src = NULL; - FileContent *dst = NULL; + FileContent **src = nullptr; + FileContent *dst = nullptr; int ret = 0; - if (src_filenames == NULL || dst_filename == NULL) + if (src_filenames == nullptr || dst_filename == nullptr) { tifiles_critical("%s: an argument is NULL", __FUNCTION__); return ERR_INVALID_FILE; } // count number of files to group, while performing several checks - for (n = 0; src_filenames[n] != NULL; n++) + for (n = 0; src_filenames[n] != nullptr; n++) { if (!tifiles_file_is_ti(src_filenames[n])) { @@ -253,7 +251,7 @@ int TICALL tifiles_group_files(char **src_filenames, const char *dst_filename) // allocate space for that src = (FileContent **)g_malloc0((n + 1) * sizeof(FileContent *)); - if (src == NULL) + if (src == nullptr) { return ERR_MALLOC; } @@ -262,7 +260,7 @@ int TICALL tifiles_group_files(char **src_filenames, const char *dst_filename) for (i = 0; i < n; i++) { src[i] = (FileContent *)g_malloc0(sizeof(FileContent)); - if (src[i] == NULL) + if (src[i] == nullptr) { ret = ERR_MALLOC; goto tgf2; @@ -274,7 +272,7 @@ int TICALL tifiles_group_files(char **src_filenames, const char *dst_filename) goto tgf2; } } - src[i] = NULL; + src[i] = nullptr; // group the array of structures ret = tifiles_group_contents(src, &dst); @@ -284,7 +282,7 @@ int TICALL tifiles_group_files(char **src_filenames, const char *dst_filename) } // write grouped file - ret = tifiles_file_write_regular(dst_filename, dst, NULL); + ret = tifiles_file_write_regular(dst_filename, dst, nullptr); if (ret) { goto tgf; @@ -316,13 +314,12 @@ int TICALL tifiles_group_files(char **src_filenames, const char *dst_filename) **/ int TICALL tifiles_ungroup_file(const char *src_filename, char ***dst_filenames) { - FileContent *src = NULL; - FileContent **ptr, **dst = NULL; - char *real_name, **p; + FileContent *src = nullptr; + FileContent **ptr, **dst = nullptr; + char *real_name; int i, n; - int ret; - if (src_filename == NULL) + if (src_filename == nullptr) { tifiles_critical("%s: an argument is NULL", __FUNCTION__); return ERR_INVALID_FILE; @@ -335,7 +332,7 @@ int TICALL tifiles_ungroup_file(const char *src_filename, char ***dst_filenames) // read group file src = tifiles_content_create_regular(CALC_NONE); - ret = tifiles_file_read_regular(src_filename, src); + int ret = tifiles_file_read_regular(src_filename, src); if (ret) { goto tuf3; @@ -349,22 +346,22 @@ int TICALL tifiles_ungroup_file(const char *src_filename, char ***dst_filenames) } // count number of structures and allocates array of strings - for (ptr = dst, n = 0; *ptr != NULL; ptr++, n++); - if (dst_filenames != NULL) + for (ptr = dst, n = 0; *ptr != nullptr; ptr++, n++); + if (dst_filenames != nullptr) { *dst_filenames = (char **)g_malloc0((n + 1) * sizeof(char *)); } // store each structure content to file - for (ptr = dst, i = 0; *ptr != NULL; ptr++, i++) + for (ptr = dst, i = 0; *ptr != nullptr; ptr++, i++) { - ret = tifiles_file_write_regular(NULL, *ptr, &real_name); + ret = tifiles_file_write_regular(nullptr, *ptr, &real_name); if (ret) { goto tuf; } - if (dst_filenames != NULL) + if (dst_filenames != nullptr) { (*dst_filenames)[i] = real_name; } @@ -378,14 +375,14 @@ int TICALL tifiles_ungroup_file(const char *src_filename, char ***dst_filenames) goto tuf2; tuf: - if (dst_filenames != NULL) + if (dst_filenames != nullptr) { - for (p = *dst_filenames; *p; p++) + for (char** p = *dst_filenames; *p; p++) { g_free(*p); } g_free(*dst_filenames); - *dst_filenames = NULL; + *dst_filenames = nullptr; } tuf2: @@ -408,10 +405,10 @@ int TICALL tifiles_ungroup_file(const char *src_filename, char ***dst_filenames) **/ int TICALL tifiles_content_add_entry(FileContent *content, VarEntry *ve) { - if (content != NULL) + if (content != nullptr) { content->entries = tifiles_ve_resize_array(content->entries, content->num_entries + 1); - if (ve == NULL) + if (ve == nullptr) { tifiles_critical("%s: adding NULL VarEntry ???", __FUNCTION__); } @@ -441,9 +438,9 @@ int TICALL tifiles_content_del_entry(FileContent *content, VarEntry *ve) { unsigned int i, j; - if (content != NULL) + if (content != nullptr) { - if (ve == NULL) + if (ve == nullptr) { tifiles_critical("%s: deleting NULL VarEntry ???", __FUNCTION__); return content->num_entries; @@ -452,7 +449,7 @@ int TICALL tifiles_content_del_entry(FileContent *content, VarEntry *ve) // Search for entry for (i = 0; i < content->num_entries; i++) { - VarEntry *s = content->entries[i]; + const VarEntry *s = content->entries[i]; if (!strcmp(s->folder, ve->folder) && !strcmp(s->name, ve->name)) { @@ -474,7 +471,7 @@ int TICALL tifiles_content_del_entry(FileContent *content, VarEntry *ve) { content->entries[j] = content->entries[j+1]; } - content->entries[j] = NULL; + content->entries[j] = nullptr; // And resize content->entries = tifiles_ve_resize_array(content->entries, content->num_entries - 1); @@ -500,14 +497,11 @@ int TICALL tifiles_content_del_entry(FileContent *content, VarEntry *ve) **/ int TICALL tifiles_group_add_file(const char *src_filename, const char *dst_filename) { - CalcModel src_model; - CalcModel dst_model; - FileContent* src_content = NULL; - FileContent* dst_content = NULL; - unsigned int i; + FileContent* src_content = nullptr; + FileContent* dst_content = nullptr; int ret = 0; - if (src_filename == NULL || dst_filename == NULL) + if (src_filename == nullptr || dst_filename == nullptr) { tifiles_critical("%s: an argument is NULL", __FUNCTION__); return ERR_INVALID_FILE; @@ -519,8 +513,8 @@ int TICALL tifiles_group_add_file(const char *src_filename, const char *dst_file return -1; } - src_model = tifiles_file_get_model(src_filename); - dst_model = tifiles_file_get_model(dst_filename); + const CalcModel src_model = tifiles_file_get_model(src_filename); + const CalcModel dst_model = tifiles_file_get_model(dst_filename); src_content = tifiles_content_create_regular(src_model); dst_content = tifiles_content_create_regular(dst_model); @@ -531,12 +525,12 @@ int TICALL tifiles_group_add_file(const char *src_filename, const char *dst_file ret = tifiles_file_read_regular(dst_filename, dst_content); if (!ret) { - for (i = 0; i < src_content->num_entries; i++) + for (unsigned int i = 0; i < src_content->num_entries; i++) { tifiles_content_add_entry(dst_content, tifiles_ve_dup(src_content->entries[i])); } - ret = tifiles_file_write_regular(dst_filename, dst_content, NULL); + ret = tifiles_file_write_regular(dst_filename, dst_content, nullptr); tifiles_content_delete_regular(dst_content); } @@ -562,11 +556,10 @@ int TICALL tifiles_group_add_file(const char *src_filename, const char *dst_file **/ int TICALL tifiles_group_del_file(VarEntry *entry, const char *dst_filename) { - CalcModel dst_model; - FileContent* dst_content = NULL; + FileContent* dst_content = nullptr; int ret = 0; - if (entry == NULL || dst_filename == NULL) + if (entry == nullptr || dst_filename == nullptr) { tifiles_critical("%s: an argument is NULL", __FUNCTION__); return ERR_INVALID_FILE; @@ -578,7 +571,7 @@ int TICALL tifiles_group_del_file(VarEntry *entry, const char *dst_filename) return -1; } - dst_model = tifiles_file_get_model(dst_filename); + const CalcModel dst_model = tifiles_file_get_model(dst_filename); dst_content = tifiles_content_create_regular(dst_model); ret = tifiles_file_read_regular(dst_filename, dst_content); if (!ret) @@ -586,7 +579,7 @@ int TICALL tifiles_group_del_file(VarEntry *entry, const char *dst_filename) tifiles_content_del_entry(dst_content, entry); tifiles_file_display_regular(dst_content); - ret = tifiles_file_write_regular(dst_filename, dst_content, NULL); + ret = tifiles_file_write_regular(dst_filename, dst_content, nullptr); tifiles_content_delete_regular(dst_content); } diff --git a/libtifiles/trunk/src/intelhex.cc b/libtifiles/trunk/src/intelhex.cc index a3f990fbc..6ac3a9356 100644 --- a/libtifiles/trunk/src/intelhex.cc +++ b/libtifiles/trunk/src/intelhex.cc @@ -79,12 +79,8 @@ static uint8_t read_byte(FILE * f) */ static int hex_packet_read(FILE *f, uint8_t *size, uint16_t *addr, uint8_t *type, uint8_t *data) { - int c, i; - uint8_t sum, checksum; - uint16_t localaddr; - - sum = 0; - c = fgetc(f); + uint8_t sum = 0; + int c = fgetc(f); if (c != ':') { printf("Unexpected char: <%c> = %02X\n", c, c); @@ -92,7 +88,7 @@ static int hex_packet_read(FILE *f, uint8_t *size, uint16_t *addr, uint8_t *type } *size = read_byte(f); - localaddr = ((uint16_t)(read_byte(f))) << 8; + uint16_t localaddr = ((uint16_t)(read_byte(f))) << 8; localaddr |= read_byte(f); *addr = localaddr; *type = read_byte(f); @@ -104,13 +100,13 @@ static int hex_packet_read(FILE *f, uint8_t *size, uint16_t *addr, uint8_t *type sum = *size + MSB(*addr) + LSB(*addr) + *type; - for (i = 0; i < *size; i++) + for (int i = 0; i < *size; i++) { data[i] = read_byte(f); sum += data[i]; } - checksum = read_byte(f); // verify checksum of block + const uint8_t checksum = read_byte(f); // verify checksum of block if (LSB(sum + checksum)) { return -3; @@ -189,17 +185,16 @@ int hex_block_read(FILE *f, uint16_t *size, uint16_t *addr, uint8_t *type, uint8 static int flag = 0x80; static uint16_t flash_page; static uint16_t flash_addr; - int i; int new_page = 0; // reset condition - if (f == NULL) + if (f == nullptr) { flag = 0x80; flash_page = flash_addr = 0; return 0; } - if (size == NULL || addr == NULL || type == NULL || data == NULL || page == NULL) + if (size == nullptr || addr == nullptr || type == nullptr || data == nullptr || page == nullptr) { return -1; } @@ -213,15 +208,14 @@ int hex_block_read(FILE *f, uint16_t *size, uint16_t *addr, uint8_t *type, uint8 *size = 0; // load data - for (i = 0; i < BLK_MAX; ) + for (int i = 0; i < BLK_MAX; ) { - int ret; uint8_t pkt_size, pkt_type; uint8_t pkt_data[PKT_MAX]; uint16_t pkt_addr; // read packet - ret = hex_packet_read(f, &pkt_size, &pkt_addr, &pkt_type, pkt_data); + const int ret = hex_packet_read(f, &pkt_size, &pkt_addr, &pkt_type, pkt_data); if(ret < 0) { return ret; // THIS RETURNS ! @@ -301,10 +295,8 @@ static int write_byte(uint8_t b, FILE * f) */ static int hex_packet_write(FILE *f, uint8_t size, uint16_t addr, uint8_t type_, uint8_t *data) { - int i; - int sum; int num = 0; - uint8_t type = (type_ == HEX_EOF ? HEX_END : type_); + const uint8_t type = (type_ == HEX_EOF ? HEX_END : type_); fputc(':', f); num++; num += write_byte((uint8_t)size, f); @@ -312,8 +304,8 @@ static int hex_packet_write(FILE *f, uint8_t size, uint16_t addr, uint8_t type_, num += write_byte(LSB(addr), f); num += write_byte(type, f); - sum = size + MSB(addr) + LSB(addr) + type; - for (i = 0; i < size; i++) + int sum = size + MSB(addr) + LSB(addr) + type; + for (int i = 0; i < size; i++) { num += write_byte(data[i], f); sum += data[i]; @@ -348,14 +340,13 @@ int hex_block_write(FILE *f, uint16_t size, uint16_t addr, uint8_t type, uint8_t { int bytes_written = 0; static int old_flag = 0x80; - int n, m; uint8_t buf[PKT_MAX]; int new_section = 0; // write end block if(!size && !addr && !type && !data && !page) { - return hex_packet_write(f, 0, 0x0000, HEX_EOF, NULL); + return hex_packet_write(f, 0, 0x0000, HEX_EOF, nullptr); } // new section (FLASH OS only) @@ -367,7 +358,7 @@ int hex_block_write(FILE *f, uint16_t size, uint16_t addr, uint8_t type, uint8_t if(old_flag != type) { old_flag = type; - bytes_written += hex_packet_write(f, 0, 0x0000, HEX_END, NULL); + bytes_written += hex_packet_write(f, 0, 0x0000, HEX_END, nullptr); } // write page @@ -386,7 +377,7 @@ int hex_block_write(FILE *f, uint16_t size, uint16_t addr, uint8_t type, uint8_t // write a block (=page) while (size > 0 || extra_bytes > 0) { - n = (size > PKT_MAX ? PKT_MAX : size); + const int n = (size > PKT_MAX ? PKT_MAX : size); if (n > 0) { memcpy(buf, data, n); @@ -394,7 +385,7 @@ int hex_block_write(FILE *f, uint16_t size, uint16_t addr, uint8_t type, uint8_t data += n; } - m = (extra_bytes > PKT_MAX - n ? PKT_MAX - n : extra_bytes); + const int m = (extra_bytes > PKT_MAX - n ? PKT_MAX - n : extra_bytes); if (m > 0) { memset(buf + n, 0xff, m); diff --git a/libtifiles/trunk/src/misc.cc b/libtifiles/trunk/src/misc.cc index 67e51ba51..c51cc3db8 100644 --- a/libtifiles/trunk/src/misc.cc +++ b/libtifiles/trunk/src/misc.cc @@ -144,15 +144,14 @@ int TICALL tifiles_has_backup(CalcModel calc_type) **/ uint16_t TICALL tifiles_checksum(const uint8_t * buffer, unsigned int size) { - unsigned int i; uint16_t c = 0; - if (buffer == NULL) + if (buffer == nullptr) { return 0; } - for (i = 0; i < size; i++) + for (unsigned int i = 0; i < size; i++) { c += buffer[i]; } @@ -171,13 +170,12 @@ uint16_t TICALL tifiles_checksum(const uint8_t * buffer, unsigned int size) int TICALL tifiles_hexdump(const uint8_t * ptr, unsigned int len) { char *str; - if (ptr != NULL) + if (ptr != nullptr) { - unsigned int i; - unsigned int alloc_len = (len < 1024) ? len : 1024; + const unsigned int alloc_len = (len < 1024) ? len : 1024; str = (char *)g_malloc(3 * alloc_len + 14); - for (i = 0; i < alloc_len; i++) + for (unsigned int i = 0; i < alloc_len; i++) { sprintf(&str[3 * i], "%02X ", ptr[i]); } @@ -207,11 +205,11 @@ int TICALL tifiles_hexdump(const uint8_t * ptr, unsigned int len) **/ char *TICALL tifiles_get_varname(const char *full_name) { - if (full_name != NULL) + if (full_name != nullptr) { char *bs = (char *)strchr(full_name, '\\'); - if (bs == NULL) + if (bs == nullptr) { return (char *) full_name; } @@ -221,7 +219,7 @@ char *TICALL tifiles_get_varname(const char *full_name) } } tifiles_critical("%s(NULL)", __FUNCTION__); - return NULL; + return nullptr; } /** @@ -248,25 +246,23 @@ char *TICALL tifiles_get_fldname(const char *full_name) **/ char *TICALL tifiles_get_fldname_s(const char *full_name, char * dest_fldname) { - int i; - - if (full_name != NULL && dest_fldname != NULL) + if (full_name != nullptr && dest_fldname != nullptr) { - char *bs = (char *)strchr(full_name, '\\'); - if (bs == NULL) + const char *bs = (char *)strchr(full_name, '\\'); + if (bs == nullptr) { dest_fldname[0] = 0; } else { - i = strlen(full_name) - strlen(bs); + const int i = strlen(full_name) - strlen(bs); strncpy(dest_fldname, full_name, i); dest_fldname[i] = '\0'; } return dest_fldname; } tifiles_critical("%s(NULL)", __FUNCTION__); - return NULL; + return nullptr; } /** @@ -283,10 +279,10 @@ char *TICALL tifiles_get_fldname_s(const char *full_name, char * dest_fldname) **/ char* TICALL tifiles_build_fullname(CalcModel model, char *full_name, const char *fldname, const char *varname) { - if (full_name == NULL || fldname == NULL || varname == NULL) + if (full_name == nullptr || fldname == nullptr || varname == nullptr) { tifiles_critical("%s: an argument is NULL", __FUNCTION__); - return NULL; + return nullptr; } if (tifiles_has_folder(model)) @@ -323,32 +319,25 @@ char* TICALL tifiles_build_filename(CalcModel model, const VarEntry *ve) { char *filename; - if (ve == NULL) + if (ve == nullptr) { tifiles_critical("%s: an argument is NULL", __FUNCTION__); - return NULL; + return nullptr; } if (tifiles_calc_is_ti8x(model) || !strcmp(ve->folder, "") || (ve->type == tifiles_flash_type(model))) { - char *part2; - const char *part3; - - part2 = ticonv_varname_to_filename(model, ve->name, ve->type); - part3 = tifiles_vartype2fext(model, ve->type); + char* part2 = ticonv_varname_to_filename(model, ve->name, ve->type); + const char* part3 = tifiles_vartype2fext(model, ve->type); filename = g_strconcat(part2, ".", part3, NULL); g_free(part2); } else { - char *part1; - char *part2; - const char *part3; - - part1 = ticonv_varname_to_filename(model, ve->folder, -1); - part2 = ticonv_varname_to_filename(model, ve->name, ve->type); - part3 = tifiles_vartype2fext(model, ve->type); + char* part1 = ticonv_varname_to_filename(model, ve->folder, -1); + char* part2 = ticonv_varname_to_filename(model, ve->name, ve->type); + const char* part3 = tifiles_vartype2fext(model, ve->type); filename = g_strconcat(part1, ".", part2, ".", part3, NULL); g_free(part1); diff --git a/libtifiles/trunk/src/rwfile.cc b/libtifiles/trunk/src/rwfile.cc index 3a87985fb..392d6ef01 100644 --- a/libtifiles/trunk/src/rwfile.cc +++ b/libtifiles/trunk/src/rwfile.cc @@ -45,19 +45,17 @@ */ int fread_n_chars(FILE * f, unsigned int n, char *s) { - unsigned int i; - if (fread_n_bytes(f, n, (uint8_t *)s) < 0) { return -1; } - if (s != NULL) + if (s != nullptr) { // set NULL terminator s[n] = '\0'; // and set unused bytes to 0 - for (i = strlen(s); i < n; i++) + for (unsigned int i = strlen(s); i < n; i++) { s[i] = '\0'; } @@ -75,9 +73,8 @@ int fread_n_chars(FILE * f, unsigned int n, char *s) int fwrite_n_chars(FILE * f, unsigned int n, const char *s) { unsigned int i; - unsigned int l; - l = strlen(s); + const unsigned int l = strlen(s); if (l > n) { tifiles_critical("string passed to 'fwrite_n_chars' is too long (>n chars).\n"); @@ -113,9 +110,8 @@ int fwrite_n_chars(FILE * f, unsigned int n, const char *s) int fwrite_n_chars2(FILE * f, unsigned int n, const char *s) { unsigned int i; - unsigned int l; - l = strlen(s); + const unsigned int l = strlen(s); if (l > n) { tifiles_critical("string passed to 'fwrite_n_chars2' is too long (>n chars).\n"); diff --git a/libtifiles/trunk/src/rwfile.h b/libtifiles/trunk/src/rwfile.h index 562e39c08..8ae4fe1ae 100644 --- a/libtifiles/trunk/src/rwfile.h +++ b/libtifiles/trunk/src/rwfile.h @@ -34,11 +34,9 @@ */ static inline int fread_n_bytes(FILE * f, unsigned int n, uint8_t *s) { - if (s == NULL) + if (s == nullptr) { - unsigned int i; - - for (i = 0; i < n; i++) + for (unsigned int i = 0; i < n; i++) { if (fgetc(f) == EOF) { @@ -98,7 +96,7 @@ static inline int fskip(FILE * f, int n) static inline int fread_byte(FILE * f, uint8_t * data) { - if (data != NULL) + if (data != nullptr) { return (fread((void *) data, sizeof(uint8_t), 1, f) < 1) ? -1 : 0; } @@ -113,7 +111,7 @@ static inline int fread_word(FILE * f, uint16_t * data) int ret = 0; uint16_t localdata; - if (data != NULL) + if (data != nullptr) { ret = (fread((void *)&localdata, sizeof(uint16_t), 1, f) < 1) ? -1 : 0; *data = GUINT16_FROM_LE(localdata); @@ -131,7 +129,7 @@ static inline int fread_long(FILE * f, uint32_t * data) int ret = 0; uint32_t localdata; - if (data != NULL) + if (data != nullptr) { ret = (fread((void *)&localdata, sizeof(uint32_t), 1, f) < 1) ? -1 : 0; *data = GUINT32_FROM_LE(localdata); diff --git a/libtifiles/trunk/src/tigroup.cc b/libtifiles/trunk/src/tigroup.cc index ef5e94a1a..e5f47dda8 100644 --- a/libtifiles/trunk/src/tigroup.cc +++ b/libtifiles/trunk/src/tigroup.cc @@ -66,12 +66,12 @@ **/ TigEntry* TICALL tifiles_te_create(const char *filename, FileClass type, CalcModel model) { - TigEntry *entry = NULL; + TigEntry *entry = nullptr; - if (filename != NULL && strcmp(filename, "")) + if (filename != nullptr && strcmp(filename, "")) { entry = (TigEntry *)g_malloc0(sizeof(TigEntry)); - if (entry != NULL) + if (entry != nullptr) { entry->filename = g_path_get_basename(filename); entry->type = type; @@ -114,7 +114,7 @@ int TICALL tifiles_te_delete(TigEntry* entry) tifiles_te_display(entry); #endif - if (entry != NULL) + if (entry != nullptr) { g_free(entry->filename); @@ -147,7 +147,7 @@ int TICALL tifiles_te_delete(TigEntry* entry) **/ int TICALL tifiles_te_display(TigEntry* entry) { - if (entry == NULL) + if (entry == nullptr) { tifiles_critical("%s(NULL)", __FUNCTION__); return ERR_INVALID_FILE; @@ -199,9 +199,9 @@ TigEntry** TICALL tifiles_te_create_array(unsigned int nelts) TigEntry** TICALL tifiles_te_resize_array(TigEntry** array, unsigned int nelts) { TigEntry ** ptr = (TigEntry **)g_realloc(array, (nelts + 1) * sizeof(TigEntry *)); - if (ptr != NULL) + if (ptr != nullptr) { - ptr[nelts] = NULL; + ptr[nelts] = nullptr; } return ptr; } @@ -216,15 +216,13 @@ TigEntry** TICALL tifiles_te_resize_array(TigEntry** array, unsigned int nelts) **/ void TICALL tifiles_te_delete_array(TigEntry** array) { - TigEntry** ptr; - #ifdef TRACE_CONTENT_INSTANCES tifiles_info("tifiles_te_delete_array: %p", array); #endif - if (array != NULL) + if (array != nullptr) { - for (ptr = array; *ptr; ptr++) + for (TigEntry** ptr = array; *ptr; ptr++) { tifiles_te_delete(*ptr); } @@ -249,11 +247,10 @@ void TICALL tifiles_te_delete_array(TigEntry** array) int TICALL tifiles_te_sizeof_array(TigEntry** array) { int i = 0; - TigEntry **p; - if (array != NULL) + if (array != nullptr) { - for (p = array; *p; p++, i++); + for (TigEntry** p = array; *p; p++, i++); } else { @@ -277,7 +274,7 @@ int TICALL tifiles_te_sizeof_array(TigEntry** array) **/ int TICALL tifiles_content_add_te(TigContent *content, TigEntry *te) { - if (content == NULL || te == NULL) + if (content == nullptr || te == nullptr) { tifiles_critical("%s: an argument is NULL", __FUNCTION__); return 0; @@ -290,7 +287,7 @@ int TICALL tifiles_content_add_te(TigContent *content, TigEntry *te) content->app_entries = tifiles_te_resize_array(content->app_entries, n + 1); content->app_entries[n++] = te; - content->app_entries[n] = NULL; + content->app_entries[n] = nullptr; content->n_apps = n; return n; @@ -302,7 +299,7 @@ int TICALL tifiles_content_add_te(TigContent *content, TigEntry *te) content->var_entries = tifiles_te_resize_array(content->var_entries, n + 1); content->var_entries[n++] = te; - content->var_entries[n] = NULL; + content->var_entries[n] = nullptr; content->n_vars = n; return n; @@ -324,7 +321,7 @@ int TICALL tifiles_content_del_te(TigContent *content, TigEntry *te) { unsigned int i, j, k; - if (content == NULL || te == NULL) + if (content == nullptr || te == nullptr) { tifiles_critical("%s: an argument is NULL", __FUNCTION__); return -1; @@ -339,7 +336,7 @@ int TICALL tifiles_content_del_te(TigContent *content, TigEntry *te) // Search for entry for (i = 0; i < content->n_vars && (te->type & TIFILE_REGULAR); i++) { - TigEntry *s = content->var_entries[i]; + const TigEntry *s = content->var_entries[i]; if (!strcmp(s->filename, te->filename)) { @@ -349,7 +346,7 @@ int TICALL tifiles_content_del_te(TigContent *content, TigEntry *te) for (j = 0; j < content->n_apps && (te->type & TIFILE_FLASH); j++) { - TigEntry *s = content->app_entries[i]; + const TigEntry *s = content->app_entries[i]; if (!strcmp(s->filename, te->filename)) { @@ -374,7 +371,7 @@ int TICALL tifiles_content_del_te(TigContent *content, TigEntry *te) { content->var_entries[k] = content->var_entries[k+1]; } - content->var_entries[k] = NULL; + content->var_entries[k] = nullptr; // And resize content->var_entries = tifiles_te_resize_array(content->var_entries, content->n_vars - 1); @@ -393,7 +390,7 @@ int TICALL tifiles_content_del_te(TigContent *content, TigEntry *te) { content->app_entries[k] = content->app_entries[k+1]; } - content->app_entries[k] = NULL; + content->app_entries[k] = nullptr; // And resize content->app_entries = tifiles_te_resize_array(content->app_entries, content->n_apps - 1); @@ -420,13 +417,10 @@ int TICALL tifiles_content_del_te(TigContent *content, TigEntry *te) **/ int TICALL tifiles_tigroup_add_file(const char *src_filename, const char *dst_filename) { - CalcModel model; - FileClass type; - TigEntry *te; - TigContent *content = NULL; + TigContent *content = nullptr; int ret = 0; - if (src_filename == NULL || dst_filename == NULL) + if (src_filename == nullptr || dst_filename == nullptr) { tifiles_critical("%s: an argument is NULL", __FUNCTION__); return -1; @@ -440,7 +434,7 @@ int TICALL tifiles_tigroup_add_file(const char *src_filename, const char *dst_fi content = tifiles_content_create_tigroup(CALC_NONE, 0); tifiles_file_write_tigroup(dst_filename, content); tifiles_content_delete_tigroup(content); - content = NULL; + content = nullptr; } } @@ -452,11 +446,11 @@ int TICALL tifiles_tigroup_add_file(const char *src_filename, const char *dst_fi } // load src file - model = tifiles_file_get_model(src_filename); - type = tifiles_file_get_class(src_filename); + const CalcModel model = tifiles_file_get_model(src_filename); + const FileClass type = tifiles_file_get_class(src_filename); - te = tifiles_te_create(src_filename, type, model); - if (te == NULL) + TigEntry* te = tifiles_te_create(src_filename, type, model); + if (te == nullptr) { ret = ERR_BAD_FILE; goto ttaf; @@ -514,10 +508,10 @@ int TICALL tifiles_tigroup_add_file(const char *src_filename, const char *dst_fi **/ int TICALL tifiles_tigroup_del_file(TigEntry *entry, const char *filename) { - TigContent* content = NULL; + TigContent* content = nullptr; int ret = 0; - if (entry == NULL || filename == NULL) + if (entry == nullptr || filename == nullptr) { tifiles_critical("%s: an argument is NULL", __FUNCTION__); return -1; @@ -555,16 +549,15 @@ int TICALL tifiles_tigroup_del_file(TigEntry *entry, const char *filename) **/ int TICALL tifiles_tigroup_contents(FileContent **src_contents1, FlashContent **src_contents2, TigContent **dst_content) { - TigContent *content; int i, m=0, n=0; CalcModel model = CALC_NONE; - if (src_contents1 == NULL && src_contents2 == NULL) + if (src_contents1 == nullptr && src_contents2 == nullptr) { return -1; } - if (dst_content == NULL) + if (dst_content == nullptr) { tifiles_critical("%s: dst_content is NULL", __FUNCTION__); return -1; @@ -572,11 +565,11 @@ int TICALL tifiles_tigroup_contents(FileContent **src_contents1, FlashContent ** if (src_contents1) { - for (m = 0; src_contents1[m] != NULL; m++); + for (m = 0; src_contents1[m] != nullptr; m++); } if (src_contents2) { - for (n = 0; src_contents2[n] != NULL; n++); + for (n = 0; src_contents2[n] != nullptr; n++); } if (src_contents2) @@ -594,7 +587,7 @@ int TICALL tifiles_tigroup_contents(FileContent **src_contents1, FlashContent ** } } - content = tifiles_content_create_tigroup(model, m+n); + TigContent* content = tifiles_content_create_tigroup(model, m + n); if (src_contents1) { @@ -613,7 +606,6 @@ int TICALL tifiles_tigroup_contents(FileContent **src_contents1, FlashContent ** { for (i = 0; i < n; i++) { - TigEntry *te; VarEntry ve; FlashContent *ptr; @@ -624,13 +616,13 @@ int TICALL tifiles_tigroup_contents(FileContent **src_contents1, FlashContent ** break; } } - if (ptr == NULL) + if (ptr == nullptr) { tifiles_critical("%s: ptr is NULL, skipping", __FUNCTION__); continue; } - te = (TigEntry *)g_malloc0(sizeof(TigEntry)); + TigEntry* te = (TigEntry*)g_malloc0(sizeof(TigEntry)); ve.folder[0] = 0; strncpy(ve.name, ptr->name, sizeof(ve.name) - 1); ve.name[sizeof(ve.name) - 1] = 0; @@ -666,12 +658,11 @@ int TICALL tifiles_tigroup_contents(FileContent **src_contents1, FlashContent ** **/ int TICALL tifiles_untigroup_content(TigContent *src_content, FileContent ***dst_contents1, FlashContent ***dst_contents2) { - TigContent *src = src_content; - FileContent **dst1 = NULL; - FlashContent **dst2 = NULL; - unsigned int i, j; + const TigContent *src = src_content; + FileContent **dst1 = nullptr; + FlashContent **dst2 = nullptr; - if (src_content == NULL || dst_contents1 == NULL || dst_contents2 == NULL) + if (src_content == nullptr || dst_contents1 == nullptr || dst_contents2 == nullptr) { tifiles_critical("%s: an argument is NULL", __FUNCTION__); return -1; @@ -684,28 +675,28 @@ int TICALL tifiles_untigroup_content(TigContent *src_content, FileContent ***dst // allocate an array of FileContent/FlashContent structures (NULL terminated) dst1 = (FileContent **)g_malloc0((src->n_vars+1) * sizeof(FileContent *)); - if (dst1 == NULL) + if (dst1 == nullptr) { return ERR_MALLOC; } dst2 = (FlashContent **)g_malloc0((src->n_apps+1) * sizeof(FlashContent *)); - if (dst2 == NULL) + if (dst2 == nullptr) { g_free(dst1); return ERR_MALLOC; } // parse each entry and duplicate it into a single content - for (i = 0; i < src->n_vars; i++) + for (unsigned int i = 0; i < src->n_vars; i++) { - TigEntry *te = src->var_entries[i]; + const TigEntry *te = src->var_entries[i]; dst1[i] = tifiles_content_dup_regular(te->content.regular); } - for (j = 0; j < src->n_apps; j++) + for (unsigned int j = 0; j < src->n_apps; j++) { - TigEntry *te = src->app_entries[j]; + const TigEntry *te = src->app_entries[j]; dst2[j] = tifiles_content_dup_flash(te->content.flash); } @@ -727,14 +718,13 @@ int TICALL tifiles_untigroup_content(TigContent *src_content, FileContent ***dst **/ int TICALL tifiles_tigroup_files(char **src_filenames, const char *dst_filename) { - FileContent **src1 = NULL; - FlashContent **src2 = NULL; - TigContent *dst = NULL; - CalcModel model; + FileContent **src1 = nullptr; + FlashContent **src2 = nullptr; + TigContent *dst = nullptr; int i, j, k, m, n; int ret = 0; - if (src_filenames == NULL || dst_filename == NULL) + if (src_filenames == nullptr || dst_filename == nullptr) { tifiles_critical("%s: an argument is NULL !", __FUNCTION__); return -1; @@ -752,17 +742,17 @@ int TICALL tifiles_tigroup_files(char **src_filenames, const char *dst_filename) n++; } } - model = tifiles_file_get_model(src_filenames[0]); + const CalcModel model = tifiles_file_get_model(src_filenames[0]); // allocate space for that src1 = (FileContent **)g_malloc0((m + 1) * sizeof(FileContent *)); - if (src1 == NULL) + if (src1 == nullptr) { return ERR_MALLOC; } src2 = (FlashContent **)g_malloc0((n + 1) * sizeof(FlashContent *)); - if (src2 == NULL) + if (src2 == nullptr) { g_free(src1); return ERR_MALLOC; @@ -832,14 +822,14 @@ int TICALL tifiles_tigroup_files(char **src_filenames, const char *dst_filename) **/ int TICALL tifiles_untigroup_file(const char *src_filename, char ***dst_filenames) { - TigContent *src = NULL; - FileContent **ptr1, **dst1 = NULL; - FlashContent **ptr2, **dst2 = NULL; + TigContent *src = nullptr; + FileContent **ptr1, **dst1 = nullptr; + FlashContent **ptr2, **dst2 = nullptr; char *real_name; unsigned int i, j; int ret = 0; - if (src_filename == NULL) + if (src_filename == nullptr) { tifiles_critical("%s: src_filename is NULL !", __FUNCTION__); return -1; @@ -861,21 +851,21 @@ int TICALL tifiles_untigroup_file(const char *src_filename, char ***dst_filename } // count number of structures and allocates array of strings - if (dst_filenames != NULL) + if (dst_filenames != nullptr) { *dst_filenames = (char **)g_malloc((src->n_vars + src->n_apps + 1) * sizeof(char *)); } // store each structure content to file - for (ptr1 = dst1, i = 0; *ptr1 != NULL || i < src->n_vars; ptr1++, i++) + for (ptr1 = dst1, i = 0; *ptr1 != nullptr || i < src->n_vars; ptr1++, i++) { - ret = tifiles_file_write_regular(NULL, *ptr1, &real_name); + ret = tifiles_file_write_regular(nullptr, *ptr1, &real_name); if (ret) { goto tuf; } - if (dst_filenames != NULL) + if (dst_filenames != nullptr) { *dst_filenames[i] = real_name; } @@ -885,15 +875,15 @@ int TICALL tifiles_untigroup_file(const char *src_filename, char ***dst_filename } } - for (ptr2 = dst2, j = 0; *ptr2 != NULL || j < src->n_apps; ptr2++, j++) + for (ptr2 = dst2, j = 0; *ptr2 != nullptr || j < src->n_apps; ptr2++, j++) { - ret = tifiles_file_write_flash2(NULL, *ptr2, &real_name); + ret = tifiles_file_write_flash2(nullptr, *ptr2, &real_name); if (ret) { goto tuf; } - if (dst_filenames != NULL) + if (dst_filenames != nullptr) { *dst_filenames[i+j] = real_name; } @@ -939,7 +929,7 @@ int TICALL tifiles_untigroup_file(const char *src_filename, char ***dst_filename TigContent* TICALL tifiles_content_create_tigroup(CalcModel model, unsigned int n) { TigContent* content = (TigContent *)g_malloc0(sizeof(*content)); - if (content != NULL) + if (content != nullptr) { char comment[43]; content->model = content->model_dst = model; @@ -974,9 +964,9 @@ int TICALL tifiles_content_delete_tigroup(TigContent *content) tifiles_file_display_tigcontent(content); #endif - if (content != NULL) + if (content != nullptr) { - if (content->var_entries != NULL) + if (content->var_entries != nullptr) { for (i = 0; i < content->n_vars; i++) { @@ -986,7 +976,7 @@ int TICALL tifiles_content_delete_tigroup(TigContent *content) g_free(content->var_entries); } - if (content->app_entries != NULL) + if (content->app_entries != nullptr) { for (i = 0; i < content->n_apps; i++) { @@ -1011,24 +1001,20 @@ int TICALL tifiles_content_delete_tigroup(TigContent *content) /* Open a temporary file */ static int open_temp_file(const char *orig_name, char **temp_name) { - const char *suffix; - char *templ; - int fd; - - *temp_name = NULL; - suffix = strrchr(orig_name, '.'); + *temp_name = nullptr; + const char* suffix = strrchr(orig_name, '.'); if (suffix && (strchr(suffix, '/') || strchr(suffix, '\\'))) { - suffix = NULL; + suffix = nullptr; } - templ = g_strconcat("tigXXXXXX", suffix, NULL); + char* templ = g_strconcat("tigXXXXXX", suffix, NULL); - fd = g_file_open_tmp(templ, temp_name, NULL); + const int fd = g_file_open_tmp(templ, temp_name, nullptr); g_free(templ); if (fd == -1) { g_free(*temp_name); - *temp_name = NULL; + *temp_name = nullptr; } return fd; @@ -1048,21 +1034,19 @@ static int open_temp_file(const char *orig_name, char **temp_name) **/ int TICALL tifiles_file_read_tigroup(const char *filename, TigContent *content) { - FILE *tigf; struct archive *arc; struct archive_entry *entry; - const char *filename_inzip; int ret = 0; - if (filename == NULL || content == NULL) + if (filename == nullptr || content == nullptr) { tifiles_critical("%s: an argument is NULL", __FUNCTION__); return -1; } // Open ZIP archive - tigf = g_fopen(filename, "rb"); - if (tigf == NULL) + FILE* tigf = g_fopen(filename, "rb"); + if (tigf == nullptr) { return ERR_FILE_OPEN; } @@ -1096,9 +1080,8 @@ int TICALL tifiles_file_read_tigroup(const char *filename, TigContent *content) while (archive_read_next_header(arc, &entry) == ARCHIVE_OK) { gchar *fname; - int fd; - filename_inzip = archive_entry_pathname(entry); + const char* filename_inzip = archive_entry_pathname(entry); if (!filename_inzip) { tifiles_warning("archive contains a file with no name"); @@ -1107,7 +1090,7 @@ int TICALL tifiles_file_read_tigroup(const char *filename, TigContent *content) } // create a temporary file - fd = open_temp_file(filename_inzip, &fname); + const int fd = open_temp_file(filename_inzip, &fname); if (fd == -1) { ret = ERR_FILE_IO; @@ -1127,7 +1110,7 @@ int TICALL tifiles_file_read_tigroup(const char *filename, TigContent *content) // add to TigContent { - CalcModel model = tifiles_file_get_model(fname); + const CalcModel model = tifiles_file_get_model(fname); if (content->model == CALC_NONE) { @@ -1138,7 +1121,7 @@ int TICALL tifiles_file_read_tigroup(const char *filename, TigContent *content) { TigEntry *tigentry = tifiles_te_create(filename_inzip, tifiles_file_get_class(fname), content->model); - if (tigentry != NULL) + if (tigentry != nullptr) { ret = tifiles_file_read_regular(fname, tigentry->content.regular); if (ret) @@ -1156,7 +1139,7 @@ int TICALL tifiles_file_read_tigroup(const char *filename, TigContent *content) { TigEntry *tigentry = tifiles_te_create(filename_inzip, tifiles_file_get_class(fname), content->model); - if (tigentry != NULL) + if (tigentry != nullptr) { ret = tifiles_file_read_flash(fname, tigentry->content.flash); if (ret) @@ -1193,23 +1176,21 @@ int TICALL tifiles_file_read_tigroup(const char *filename, TigContent *content) static int zip_write(struct archive *arc, CalcModel model, const char *origfname, const char *tempfname) { - char *filenameinzip; - struct archive_entry *entry; struct stat st; int err = 0; - FILE *f = NULL; + FILE *f = nullptr; int size_read; - void* buf=NULL; + void* buf= nullptr; - if (arc == NULL) + if (arc == nullptr) { tifiles_critical("zip_write: arc is NULL !"); return ERR_FILE_ZIP; } // Set metadata - entry = archive_entry_new(); - if (entry == NULL) + struct archive_entry* entry = archive_entry_new(); + if (entry == nullptr) { tifiles_critical("zip_write: cannot allocate archive entry"); return ERR_FILE_ZIP; @@ -1224,13 +1205,13 @@ static int zip_write(struct archive *arc, CalcModel model, const char *origfname archive_entry_copy_stat(entry, &st); // ZIP archives don't like greek chars - filenameinzip = ticonv_gfe_to_zfe(model, origfname); + char* filenameinzip = ticonv_gfe_to_zfe(model, origfname); archive_entry_set_pathname(entry, filenameinzip); g_free(filenameinzip); // missing tmp file ! f = g_fopen(tempfname, "rb"); - if (f == NULL) + if (f == nullptr) { tifiles_critical("zip_write: cannot read temporary file"); archive_entry_free(entry); @@ -1298,7 +1279,7 @@ int TICALL tifiles_file_write_tigroup(const char *filename, TigContent *content) int err = 0; TigEntry **ptr; - if (filename == NULL || content == NULL) + if (filename == nullptr || content == nullptr) { tifiles_critical("%s: an argument is NULL", __FUNCTION__); return -1; @@ -1311,7 +1292,7 @@ int TICALL tifiles_file_write_tigroup(const char *filename, TigContent *content) // Open ZIP archive tigf = g_fopen(filename, "wb"); - if (tigf == NULL) + if (tigf == nullptr) { return ERR_FILE_OPEN; } @@ -1348,12 +1329,11 @@ int TICALL tifiles_file_write_tigroup(const char *filename, TigContent *content) // Parse entries and store for (ptr = content->var_entries; *ptr && !err; ptr++) { - TigEntry* entry = *ptr; - char *fname = NULL; - int fd; + const TigEntry* entry = *ptr; + char *fname = nullptr; // write TI file into tmp folder - fd = open_temp_file(entry->filename, &fname); + const int fd = open_temp_file(entry->filename, &fname); if (fd == -1) { g_free(fname); @@ -1362,7 +1342,7 @@ int TICALL tifiles_file_write_tigroup(const char *filename, TigContent *content) } close(fd); - err = tifiles_file_write_regular(fname, entry->content.regular, NULL); + err = tifiles_file_write_regular(fname, entry->content.regular, nullptr); if (!err) { err = zip_write(arc, content->model, entry->filename, fname); @@ -1374,12 +1354,11 @@ int TICALL tifiles_file_write_tigroup(const char *filename, TigContent *content) for (ptr = content->app_entries; *ptr && !err; ptr++) { - TigEntry* entry = *ptr; - char *fname = NULL; - int fd; + const TigEntry* entry = *ptr; + char *fname = nullptr; // write TI file into tmp folder - fd = open_temp_file(entry->filename, &fname); + const int fd = open_temp_file(entry->filename, &fname); if (fd == -1) { g_free(fname); @@ -1418,18 +1397,17 @@ int TICALL tifiles_file_write_tigroup(const char *filename, TigContent *content) **/ int TICALL tifiles_file_display_tigroup(const char *filename) { - FILE *tigf; struct archive *arc; struct archive_entry *entry; - if (filename == NULL) + if (filename == nullptr) { tifiles_critical("%s(NULL)", __FUNCTION__); return -1; } - tigf = g_fopen(filename, "rb"); - if (tigf == NULL) + FILE* tigf = g_fopen(filename, "rb"); + if (tigf == nullptr) { return ERR_FILE_OPEN; } @@ -1454,7 +1432,7 @@ int TICALL tifiles_file_display_tigroup(const char *filename) { const char *name = archive_entry_pathname(entry); char *dispname = g_filename_display_name(name); - unsigned long size = (unsigned long) archive_entry_size(entry); + const unsigned long size = (unsigned long) archive_entry_size(entry); tifiles_info(" %-7lu %s", size, dispname); archive_read_data_skip(arc); g_free(dispname); @@ -1477,7 +1455,7 @@ int TICALL tifiles_file_display_tigcontent(TigContent *content) { unsigned int i; - if (content == NULL) + if (content == nullptr) { tifiles_critical("%s(NULL)", __FUNCTION__); return ERR_INVALID_FILE; @@ -1492,7 +1470,7 @@ int TICALL tifiles_file_display_tigcontent(TigContent *content) tifiles_info("Number of vars: %u", content->n_vars); tifiles_info("Var entries: %p", content->var_entries); - if (content->var_entries != NULL) + if (content->var_entries != nullptr) { for (i = 0; i < content->n_vars; i++) { @@ -1503,7 +1481,7 @@ int TICALL tifiles_file_display_tigcontent(TigContent *content) tifiles_info("Number of apps: %u", content->n_apps); tifiles_info("Apps entries: %p", content->app_entries); - if (content->app_entries != NULL) + if (content->app_entries != nullptr) { for (i = 0; i < content->n_apps; i++) { diff --git a/libtifiles/trunk/src/type2str.cc b/libtifiles/trunk/src/type2str.cc index 4c2e1e117..8323e917e 100644 --- a/libtifiles/trunk/src/type2str.cc +++ b/libtifiles/trunk/src/type2str.cc @@ -81,7 +81,7 @@ const char *TICALL tifiles_attribute_to_string(FileAttr attrb) **/ FileAttr TICALL tifiles_string_to_attribute(const char *str) { - if (str != NULL) + if (str != nullptr) { if(!g_ascii_strcasecmp(str, _("none "))) return ATTRB_NONE; @@ -130,7 +130,7 @@ const char *TICALL tifiles_class_to_string(FileClass klass) **/ FileClass TICALL tifiles_string_to_class(const char *str) { - if (str != NULL) + if (str != nullptr) { if(!g_ascii_strcasecmp(str, _("single"))) return TIFILE_SINGLE; diff --git a/libtifiles/trunk/src/types68k.cc b/libtifiles/trunk/src/types68k.cc index 27e9b6e06..1e14ca1c0 100644 --- a/libtifiles/trunk/src/types68k.cc +++ b/libtifiles/trunk/src/types68k.cc @@ -84,7 +84,7 @@ const TI68k_DATA TI68k_CONST[TI89_MAXTYPES + 1] = {"", "89?", "92?", "9x?", "v2?", "Unknown", N_("Unknown")}, {"", "89?", "92?", "9x?", "v2?", "Unknown", N_("Unknown")}, {"", "89?", "92?", "9x?", "v2?", "Unknown", N_("Unknown")}, - {NULL, NULL, NULL, NULL, NULL, NULL, NULL} + { nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr } }; #endif diff --git a/libtifiles/trunk/src/types83p.cc b/libtifiles/trunk/src/types83p.cc index bcc3780cb..b84cbaf57 100644 --- a/libtifiles/trunk/src/types83p.cc +++ b/libtifiles/trunk/src/types83p.cc @@ -80,7 +80,7 @@ const TI83p_DATA TI83p_CONST[TI83p_MAXTYPES + 1] = {"", "8X?", "8X?", "8X?", "8X?", "8X?", "8X?", "8X?", "Unknown", N_("Unknown")}, // 45, 0x2D {"", "8X?", "8X?", "8X?", "8X?", "8X?", "8X?", "8X?", "Unknown", N_("Unknown")}, {"", "8X?", "8X?", "8X?", "8X?", "8X?", "8X?", "8X?", "Unknown", N_("Unknown")}, - {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL} + { nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr } }; #endif diff --git a/libtifiles/trunk/src/typesnsp.cc b/libtifiles/trunk/src/typesnsp.cc index 1f41d04b8..6c762de14 100644 --- a/libtifiles/trunk/src/typesnsp.cc +++ b/libtifiles/trunk/src/typesnsp.cc @@ -32,5 +32,5 @@ const TIXX_DATA NSP_CONST[NSP_MAXTYPES + 1] = { {"TNS", "tns", "TIicon1", N_("Document")}, {"DIR", "???", "Directory", N_("Directory")}, - {NULL, NULL, NULL, NULL} + { nullptr, nullptr, nullptr, nullptr } }; diff --git a/libtifiles/trunk/src/typesoldz80.cc b/libtifiles/trunk/src/typesoldz80.cc index 7f7596b98..b50432d8d 100644 --- a/libtifiles/trunk/src/typesoldz80.cc +++ b/libtifiles/trunk/src/typesoldz80.cc @@ -85,7 +85,7 @@ const TIXX_DATA TI73_CONST[TI73_MAXTYPES + 1] = {"", "73?", "Unknown", N_("Unknown")}, {"", "73?", "Unknown", N_("Unknown")}, {"", "73?", "Unknown", N_("Unknown")}, - {NULL, NULL, NULL, NULL} + { nullptr, nullptr, nullptr, nullptr } }; const TIXX_DATA TI82_CONST[TI82_MAXTYPES + 1] = @@ -138,7 +138,7 @@ const TIXX_DATA TI82_CONST[TI82_MAXTYPES + 1] = {"", "82?", "Unknown", N_("Unknown")}, {"", "82?", "Unknown", N_("Unknown")}, {"", "82?", "Unknown", N_("Unknown")}, - {NULL, NULL, NULL, NULL} + { nullptr, nullptr, nullptr, nullptr } }; const TIXX_DATA TI83_CONST[TI83_MAXTYPES + 1] = @@ -191,7 +191,7 @@ const TIXX_DATA TI83_CONST[TI83_MAXTYPES + 1] = {"", "83?", "Unknown", N_("Unknown")}, {"", "83?", "Unknown", N_("Unknown")}, {"", "83?", "Unknown", N_("Unknown")}, - {NULL, NULL, NULL, NULL} + { nullptr, nullptr, nullptr, nullptr } }; const TIXX_DATA TI85_CONST[TI85_MAXTYPES + 1] = @@ -244,7 +244,7 @@ const TIXX_DATA TI85_CONST[TI85_MAXTYPES + 1] = {"", "85?", "Unknown", N_("Unknown")}, {"", "85?", "Unknown", N_("Unknown")}, {"", "85?", "Unknown", N_("Unknown")}, - {NULL, NULL, NULL, NULL}, + { nullptr, nullptr, nullptr, nullptr }, }; const TIXX_DATA TI86_CONST[TI86_MAXTYPES + 1] = @@ -297,7 +297,7 @@ const TIXX_DATA TI86_CONST[TI86_MAXTYPES + 1] = {"", "86?", "Unknown", N_("Unknown")}, {"", "86?", "Unknown", N_("Unknown")}, {"", "86?", "Unknown", N_("Unknown")}, - {NULL, NULL, NULL, NULL}, + { nullptr, nullptr, nullptr, nullptr }, }; #endif diff --git a/libtifiles/trunk/src/typesxx.cc b/libtifiles/trunk/src/typesxx.cc index 0d7da22c2..8cdb758da 100644 --- a/libtifiles/trunk/src/typesxx.cc +++ b/libtifiles/trunk/src/typesxx.cc @@ -128,7 +128,7 @@ const char *TICALL tifiles_vartype2string(CalcModel model, uint8_t data) **/ uint8_t TICALL tifiles_string2vartype(CalcModel model, const char *s) { - if (s == NULL) + if (s == nullptr) { tifiles_critical("%s: invalid string !", __FUNCTION__); return 0; @@ -300,7 +300,7 @@ const char *TICALL tifiles_vartype2fext(CalcModel model, uint8_t data) **/ uint8_t TICALL tifiles_fext2vartype(CalcModel model, const char *s) { - if (s == NULL) + if (s == nullptr) { tifiles_critical("%s: invalid string !", __FUNCTION__); return 0; @@ -871,7 +871,7 @@ const char *TICALL tifiles_calctype2signature(CalcModel model) break; } - return NULL; + return nullptr; } /** @@ -884,7 +884,7 @@ const char *TICALL tifiles_calctype2signature(CalcModel model) **/ CalcModel TICALL tifiles_signature2calctype(const char *s) { - if (s != NULL) + if (s != nullptr) { if (!g_ascii_strcasecmp(s, "**TI73**")) return CALC_TI73; diff --git a/libtifiles/trunk/src/ve_fp.cc b/libtifiles/trunk/src/ve_fp.cc index b673ed56a..dc9d2bd6e 100644 --- a/libtifiles/trunk/src/ve_fp.cc +++ b/libtifiles/trunk/src/ve_fp.cc @@ -54,7 +54,7 @@ VarEntry* TICALL tifiles_ve_create(void) VarEntry* TICALL tifiles_ve_create_alloc_data(uint32_t size) { VarEntry* ve = tifiles_ve_create(); - if (ve != NULL) + if (ve != nullptr) { ve->data = (uint8_t *)g_malloc0(size); } @@ -85,7 +85,7 @@ VarEntry* TICALL tifiles_ve_create_with_data(uint32_t size) VarEntry* TICALL tifiles_ve_create_with_data2(uint32_t size, uint8_t * data) { VarEntry* ve = tifiles_ve_create(); - if (ve != NULL) + if (ve != nullptr) { ve->data = data; ve->size = size; @@ -104,7 +104,7 @@ VarEntry* TICALL tifiles_ve_create_with_data2(uint32_t size, uint8_t * data) **/ void TICALL tifiles_ve_delete(VarEntry* ve) { - if (ve != NULL) + if (ve != nullptr) { g_free(ve->data); g_free(ve); @@ -138,7 +138,7 @@ void * TICALL tifiles_ve_alloc_data(size_t size) **/ VarEntry * TICALL tifiles_ve_realloc_data(VarEntry* ve, size_t size) { - if (ve != NULL) + if (ve != nullptr) { uint8_t * data = (uint8_t *)g_realloc(ve->data, (size+1) * sizeof(uint8_t)); if (size > ve->size) @@ -188,9 +188,9 @@ VarEntry** TICALL tifiles_ve_create_array(unsigned int nelts) VarEntry** TICALL tifiles_ve_resize_array(VarEntry** array, unsigned int nelts) { VarEntry ** ptr = (VarEntry **)g_realloc(array, (nelts + 1) * sizeof(VarEntry *)); - if (ptr != NULL) + if (ptr != nullptr) { - ptr[nelts] = NULL; + ptr[nelts] = nullptr; } return ptr; } @@ -205,11 +205,9 @@ VarEntry** TICALL tifiles_ve_resize_array(VarEntry** array, unsigned int nelts) **/ void TICALL tifiles_ve_delete_array(VarEntry** array) { - VarEntry** ptr; - - if (array != NULL) + if (array != nullptr) { - for (ptr = array; *ptr; ptr++) + for (VarEntry** ptr = array; *ptr; ptr++) { tifiles_ve_delete(*ptr); } @@ -233,25 +231,23 @@ void TICALL tifiles_ve_delete_array(VarEntry** array) **/ VarEntry* TICALL tifiles_ve_copy(VarEntry* dst, VarEntry* src) { - int alloc; - - if (src != NULL && dst != NULL) + if (src != nullptr && dst != nullptr) { - alloc = (dst->data == NULL); + const int alloc = (dst->data == nullptr); memcpy(dst, src, sizeof(VarEntry)); if (alloc) { dst->data = (uint8_t *)g_malloc0(dst->size); - if (dst->data == NULL) - return NULL; + if (dst->data == nullptr) + return nullptr; } memcpy(dst->data, src->data, src->size); } else { tifiles_critical("%s(): an argument is NULL", __FUNCTION__); - return NULL; + return nullptr; } return dst; @@ -267,17 +263,17 @@ VarEntry* TICALL tifiles_ve_copy(VarEntry* dst, VarEntry* src) **/ VarEntry* TICALL tifiles_ve_dup(VarEntry* src) { - VarEntry* dst = NULL; + VarEntry* dst = nullptr; - if (src != NULL) + if (src != nullptr) { dst = (VarEntry *)g_malloc0(sizeof(VarEntry)); - if (dst != NULL) + if (dst != nullptr) { memcpy(dst, src, sizeof(VarEntry)); dst->data = (uint8_t *)g_malloc0(dst->size); - if (src->data != NULL && dst->data != NULL) + if (src->data != nullptr && dst->data != nullptr) { memcpy(dst->data, src->data, dst->size); } @@ -315,10 +311,8 @@ FlashPage* TICALL tifiles_fp_create(void) **/ void * TICALL tifiles_fp_alloc_data(size_t size) { - uint8_t *data; - - data = (uint8_t *)g_malloc0((size+1) * sizeof(uint8_t)); - if (data != NULL) + uint8_t* data = (uint8_t*)g_malloc0((size + 1) * sizeof(uint8_t)); + if (data != nullptr) { memset(data, 0xFF, size); } @@ -336,7 +330,7 @@ void * TICALL tifiles_fp_alloc_data(size_t size) **/ FlashPage * TICALL tifiles_fp_realloc_data(FlashPage* fp, size_t size) { - if (fp != NULL) + if (fp != nullptr) { uint8_t * data = (uint8_t *)g_realloc(fp->data, (size+1) * sizeof(uint8_t)); if (size > fp->size) @@ -370,7 +364,7 @@ void TICALL tifiles_fp_free_data(void * data) FlashPage* TICALL tifiles_fp_create_alloc_data(uint32_t size) { FlashPage* ve = tifiles_fp_create(); - if (ve != NULL) + if (ve != nullptr) { ve->data = (uint8_t *)g_malloc0(size); } @@ -401,7 +395,7 @@ FlashPage* TICALL tifiles_fp_create_with_data(uint32_t size) FlashPage* TICALL tifiles_fp_create_with_data2(uint32_t size, uint8_t * data) { FlashPage* ve = tifiles_fp_create(); - if (ve != NULL) + if (ve != nullptr) { ve->data = data; ve->size = size; @@ -437,9 +431,9 @@ FlashPage** TICALL tifiles_fp_create_array(unsigned int nelts) FlashPage** TICALL tifiles_fp_resize_array(FlashPage** array, unsigned int nelts) { FlashPage ** ptr = (FlashPage **)g_realloc(array, (nelts + 1) * sizeof(FlashPage *)); - if (ptr != NULL) + if (ptr != nullptr) { - ptr[nelts] = NULL; + ptr[nelts] = nullptr; } return ptr; } @@ -454,7 +448,7 @@ FlashPage** TICALL tifiles_fp_resize_array(FlashPage** array, unsigned int nelts **/ void TICALL tifiles_fp_delete(FlashPage* fp) { - if (fp != NULL) + if (fp != nullptr) { g_free(fp->data); g_free(fp); @@ -475,11 +469,9 @@ void TICALL tifiles_fp_delete(FlashPage* fp) **/ void TICALL tifiles_fp_delete_array(FlashPage** array) { - FlashPage** ptr; - - if (array != NULL) + if (array != nullptr) { - for (ptr = array; *ptr; ptr++) + for (FlashPage** ptr = array; *ptr; ptr++) { tifiles_fp_delete(*ptr); } diff --git a/libtifiles/trunk/tests/test_tifiles_2.cc b/libtifiles/trunk/tests/test_tifiles_2.cc index e50713888..ac6ec8727 100644 --- a/libtifiles/trunk/tests/test_tifiles_2.cc +++ b/libtifiles/trunk/tests/test_tifiles_2.cc @@ -43,19 +43,18 @@ // Compare 2 files bytes per bytes and show differences static int compare_files(const char *src, const char *dst) { - FILE *fs, *fd; int i; int s, d; - fs = fopen(src, "rb"); - if (fs == NULL) + FILE* fs = fopen(src, "rb"); + if (fs == nullptr) { printf("Unable to open file <%s>\n", src); return -1; } - fd = fopen(dst, "rb"); - if (fd == NULL) + FILE* fd = fopen(dst, "rb"); + if (fd == nullptr) { printf("Unable to open file: <%s>\n", dst); fclose(fs); @@ -131,14 +130,13 @@ static int test_tixx_backup_support(const char * message, const char * input_file, const char * output_file) { - BackupContent *content; int ret = -1; printf("%s", message); tifiles_file_display(input_file); - content = tifiles_content_create_backup(calculator); - if (content != NULL) + BackupContent* content = tifiles_content_create_backup(calculator); + if (content != nullptr) { ret = tifiles_file_read_backup(input_file, content); if (!ret) @@ -160,15 +158,14 @@ static int test_tixx_regular_support_single(const char * message, const char * input_file, const char * output_file) { - FileContent *content; - char *unused = NULL; + char *unused = nullptr; int ret = -1; printf("%s", message); tifiles_file_display(input_file); - content = tifiles_content_create_regular(calculator); - if (content != NULL) + FileContent* content = tifiles_content_create_regular(calculator); + if (content != nullptr) { ret = tifiles_file_read_regular(input_file, content); if (!ret) @@ -191,15 +188,14 @@ static int test_tixx_regular_support_group(const char * message, const char * input_group, const char * output_group) { - FileContent *content; - char *unused = NULL; + char *unused = nullptr; int ret = -1; printf("%s", message); tifiles_file_display(input_group); - content = tifiles_content_create_regular(calculator); - if (content != NULL) + FileContent* content = tifiles_content_create_regular(calculator); + if (content != nullptr) { ret = tifiles_file_read_regular(input_group, content); if (!ret) @@ -224,7 +220,7 @@ static int test_tixx_group_support(const char * message, const char * output_group_file) { char files[2][1024]; - char *array[3] = { 0 }; + char *array[3] = { nullptr }; int ret = -1; strncpy(files[0], input_file_1, 1023); @@ -254,9 +250,8 @@ static int test_tixx_ungroup_support(const char * message, const char * input_file_3, const char * input_file_4) { - int ret; printf("%s", message); - ret = tifiles_ungroup_file(input_group, NULL); + int ret = tifiles_ungroup_file(input_group, nullptr); if (!ret) { rename(input_file_1, dest_file_1); @@ -276,14 +271,13 @@ static int test_tixx_flash_support(const char * message, const char * input_file, const char * output_file) { - FlashContent *content; int ret = -1; printf("%s", message); tifiles_file_display(input_file); - content = tifiles_content_create_flash(calculator); - if (content != NULL) + FlashContent* content = tifiles_content_create_flash(calculator); + if (content != nullptr) { ret = tifiles_file_read_flash(input_file, content); if (!ret) @@ -314,12 +308,10 @@ static int test_ti73_backup_support() static int test_ti73_regular_support() { - int ret; - - ret = test_tixx_regular_support_single("--> Testing TI73 regular support (single)...\n", - CALC_TI73, - "ti73/romdump.73p", - "ti73/romdump.73p_"); + int ret = test_tixx_regular_support_single("--> Testing TI73 regular support (single)...\n", + CALC_TI73, + "ti73/romdump.73p", + "ti73/romdump.73p_"); if (!ret) { @@ -368,12 +360,10 @@ static int test_ti82_backup_support() static int test_ti82_regular_support() { - int ret; - - ret = test_tixx_regular_support_single("--> Testing TI82 regular support (single)...\n", - CALC_TI82, - "ti82/math.82p", - "ti82/math.82p_"); + int ret = test_tixx_regular_support_single("--> Testing TI82 regular support (single)...\n", + CALC_TI82, + "ti82/math.82p", + "ti82/math.82p_"); if (!ret) { @@ -422,12 +412,10 @@ static int test_ti83_backup_support() static int test_ti83_regular_support() { - int ret; - - ret = test_tixx_regular_support_single("--> Testing ti83 regular support (single)...\n", - CALC_TI83, - "ti83/romdump.83p", - "ti83/romdump.83p_"); + int ret = test_tixx_regular_support_single("--> Testing ti83 regular support (single)...\n", + CALC_TI83, + "ti83/romdump.83p", + "ti83/romdump.83p_"); if (!ret) { @@ -468,12 +456,10 @@ static int test_ti83_ungroup_support() static int test_ti84p_regular_support() { - int ret; - - ret = test_tixx_regular_support_single("--> Testing TI84+ regular support (single)...\n", - CALC_TI84P, - "ti84p/romdump.8Xp", - "ti84p/romdump.8Xp_"); + int ret = test_tixx_regular_support_single("--> Testing TI84+ regular support (single)...\n", + CALC_TI84P, + "ti84p/romdump.8Xp", + "ti84p/romdump.8Xp_"); if (!ret) { @@ -509,12 +495,10 @@ static int test_ti84p_ungroup_support() static int test_ti84p_flash_support() { - int ret; - - ret = test_tixx_flash_support("--> Testing TI84+ flashapp support...\n", - CALC_TI84P, - "ti84p/LogIn_1.8Xk", - "ti84p/LogIn_1.8Xk_"); + int ret = test_tixx_flash_support("--> Testing TI84+ flashapp support...\n", + CALC_TI84P, + "ti84p/LogIn_1.8Xk", + "ti84p/LogIn_1.8Xk_"); if (!ret) { @@ -542,12 +526,10 @@ static int test_ti84p_flash_support() static int test_ti85_regular_support() { - int ret; - - ret = test_tixx_regular_support_single("--> Testing TI85 regular support (single)...\n", - CALC_TI85, - "ti85/AA.85n", - "ti85/AA.85n_"); + int ret = test_tixx_regular_support_single("--> Testing TI85 regular support (single)...\n", + CALC_TI85, + "ti85/AA.85n", + "ti85/AA.85n_"); if (!ret) { @@ -575,12 +557,10 @@ static int test_ti86_backup_support() static int test_ti86_regular_support() { - int ret; - - ret = test_tixx_regular_support_single("--> Testing TI86 regular support (single)...\n", - CALC_TI86, - "ti86/prgm.86p", - "ti86/prgm.86p_"); + int ret = test_tixx_regular_support_single("--> Testing TI86 regular support (single)...\n", + CALC_TI86, + "ti86/prgm.86p", + "ti86/prgm.86p_"); if (!ret) { @@ -636,12 +616,10 @@ static int test_ti92_backup_support() static int test_ti92_regular_support() { - int ret; - - ret = test_tixx_regular_support_single("--> Testing TI92 regular support (single)...\n", - CALC_TI92, - "ti92/str.92s", - "ti92/str.92s_"); + int ret = test_tixx_regular_support_single("--> Testing TI92 regular support (single)...\n", + CALC_TI92, + "ti92/str.92s", + "ti92/str.92s_"); if (!ret) { @@ -681,24 +659,20 @@ static int test_ti92_ungroup_support() static int test_ti89_regular_support() { - int ret; - - ret = test_tixx_regular_support_group("--> Testing TI89 regular support (group)...\n", - CALC_TI89, - "ti89/group.89g", - "ti89/group.89g_"); + const int ret = test_tixx_regular_support_group("--> Testing TI89 regular support (group)...\n", + CALC_TI89, + "ti89/group.89g", + "ti89/group.89g_"); return ret; } static int test_ti89_flash_support() { - int ret; - - ret = test_tixx_flash_support("--> Testing TI89 flashapp support...\n", - CALC_TI89, - "ti89/ticabfra.89k", - "ti89/ticabfra.89k_"); + const int ret = test_tixx_flash_support("--> Testing TI89 flashapp support...\n", + CALC_TI89, + "ti89/ticabfra.89k", + "ti89/ticabfra.89k_"); return ret; } @@ -706,12 +680,10 @@ static int test_ti89_flash_support() static int test_v200_regular_support() { - int ret; - - ret = test_tixx_regular_support_group("--> Testing V200 regular support (group)...\n", - CALC_V200, - "./v200/xy.v2g", - "./v200/xy.v2g_"); + const int ret = test_tixx_regular_support_group("--> Testing V200 regular support (group)...\n", + CALC_V200, + "./v200/xy.v2g", + "./v200/xy.v2g_"); return ret; } @@ -722,24 +694,20 @@ static int test_v200_regular_support() static int test_ti8x_cert_support() { - int ret; - - ret = test_tixx_flash_support("--> Testing TI8X certif support...\n", - CALC_TI84P, - "certs/celsheet1.8Xk", - "certs/celsheet1.8Xk_"); + const int ret = test_tixx_flash_support("--> Testing TI8X certif support...\n", + CALC_TI84P, + "certs/celsheet1.8Xk", + "certs/celsheet1.8Xk_"); return ret; } static int test_ti9x_cert_support() { - int ret; - - ret = test_tixx_flash_support("--> Testing TI9X certif support...\n", - CALC_TI92P, - "certs/ticsheet.9xk", - "certs/ticsheet.9xk_"); + const int ret = test_tixx_flash_support("--> Testing TI9X certif support...\n", + CALC_TI92P, + "certs/ticsheet.9xk", + "certs/ticsheet.9xk_"); return ret; } @@ -747,10 +715,9 @@ static int test_ti9x_cert_support() static int test_ti8x_group_merge() { VarEntry ve; - int ret; printf("--> Testing add/del from group support (r/w)...\n"); - ret = tifiles_group_add_file("misc/group1.8Xg", "misc/group2.8Xg"); + int ret = tifiles_group_add_file("misc/group1.8Xg", "misc/group2.8Xg"); if (!ret) { strncpy(ve.name, "A", sizeof(ve.name) - 1); @@ -773,11 +740,11 @@ static int test_ti8x_group_merge() static int test_tigroup() { - TigContent *content = NULL; - TigEntry te = { NULL, TIFILE_NONE, { NULL } }; + TigContent *content = nullptr; + TigEntry te = { nullptr, TIFILE_NONE, {nullptr} }; int ret = -1; - // SVN can't handle file like 'pépé'. You will have to rename it from pepe to pépé and + // SVN can't handle file like 'p?p?'. You will have to rename it from pepe to p?p? and // uncomment line below and another line. //char *name = g_filename_from_utf8("tig/p\xC3\xA9p\xC3\xA9.tig", -1, NULL, NULL, NULL); @@ -788,7 +755,7 @@ static int test_tigroup() tifiles_file_display_tigroup("tig/test.tig"); content = tifiles_content_create_tigroup(CALC_NONE, 0); - if (content != NULL) + if (content != nullptr) { ret = tifiles_file_read_tigroup("tig/test2.tig", content); if (!ret) @@ -801,7 +768,7 @@ static int test_tigroup() if (!ret) { content = tifiles_content_create_tigroup(CALC_NONE, 0); - if (content != NULL) + if (content != nullptr) { ret = tifiles_file_read_tigroup("tig/test.tig", content); if (!ret) @@ -855,7 +822,7 @@ static int test_tigroup() if (!ret) { tifiles_file_display("tig/test_.tig"); - ret = tifiles_untigroup_file("tig/test.tig", NULL); + ret = tifiles_untigroup_file("tig/test.tig", nullptr); if (!ret) { rename("A.8Xn", "tig/AA.8Xn"); @@ -875,7 +842,7 @@ static int test_tigroup() // The main function int main(int argc, char **argv) { - char *msg = NULL; + char *msg = nullptr; char buffer[256]; int i; int ret; diff --git a/tifileutil/src/main.cc b/tifileutil/src/main.cc index 9b37d06c3..dd192d8d3 100644 --- a/tifileutil/src/main.cc +++ b/tifileutil/src/main.cc @@ -499,7 +499,7 @@ static int tifileutil_wrap(int * argc, char *** argv, unsigned int offset) // tifiles_content_add_entry returns the number of entries. i = !tifiles_content_add_entry(fc, ve); if (!i) { - i = err_print("tifiles_file_write_regular", tifiles_file_write_regular(outfilename, fc, 0)); + i = err_print("tifiles_file_write_regular", tifiles_file_write_regular(outfilename, fc, nullptr)); if (!i && verbose) { tifiles_file_display_regular(fc); @@ -548,11 +548,9 @@ static int tifileutil_unwrap(int * argc, char *** argv, unsigned int offset) int deep = 0; int verbose = 0; - int i, j; - - for (i = offset + 1; i < *argc; i++) { + for (int i = offset + 1; i < *argc; i++) { if ((*argv)[i][0] == '-' && (*argv)[i][1]) { - for (j = 1; (*argv)[i][j]; j++) { + for (int j = 1; (*argv)[i][j]; j++) { switch ((*argv)[i][j]) { case 'o': if ((*argv)[i][++j]) { @@ -634,7 +632,7 @@ static int tifileutil_dump(int * argc, char *** argv, unsigned int offset) int verbose = 0; FILE * infile, * outfile = nullptr; struct stat st; - unsigned long length, lenread, itemsperline = 8, minsize = 64; + unsigned long itemsperline = 8, minsize = 64; unsigned char data[65636]; // +100 for the header and footer. unsigned long i, j; @@ -759,9 +757,9 @@ static int tifileutil_dump(int * argc, char *** argv, unsigned int offset) } fstat(fileno(infile), &st); - length = st.st_size; + const unsigned long length = st.st_size; - lenread = fread(data, sizeof(char), length < sizeof(data) ? length : sizeof(data), infile); + const unsigned long lenread = fread(data, sizeof(char), length < sizeof(data) ? length : sizeof(data), infile); if (infile != stdin) { fclose(infile); @@ -860,11 +858,9 @@ OPTIONS for set mode may include (multiple options at a time): static int tifileutil_metadata(int * argc, char *** argv, unsigned int offset) { - int ret; - tifileutil_critical("%s: metadata not implemented yet.\n", (*argv)[0]); - ret = 1; + const int ret = 1; return ret; }