From 0450a9b43031eef60dc28447b1dc4a3fd7f8d3d5 Mon Sep 17 00:00:00 2001 From: Mark Pizzolato Date: Sat, 15 Dec 2012 07:56:42 -0800 Subject: [PATCH] Compiler suggested cleanup --- scp.c | 14 +++++++---- sim_disk.c | 67 +++++++++++++--------------------------------------- sim_ether.c | 6 ++++- sim_serial.c | 3 ++- sim_sock.c | 11 +++++++-- sim_tape.c | 28 +++++++++++++--------- sim_timer.c | 2 +- 7 files changed, 60 insertions(+), 71 deletions(-) diff --git a/scp.c b/scp.c index 82ab5e92..434f7cc8 100644 --- a/scp.c +++ b/scp.c @@ -888,9 +888,10 @@ while (stat != SCPE_EXIT) { /* in case exit */ cptr = (*sim_vm_read) (cbuf, CBUFSIZE, stdin); } else cptr = read_line_p ("sim> ", cbuf, CBUFSIZE, stdin);/* read with prmopt*/ - if (cptr == NULL) /* EOF? */ + if (cptr == NULL) { /* EOF? */ if (sim_ttisatty()) continue; /* ignore tty EOF */ else break; /* otherwise exit */ + } if (*cptr == 0) /* ignore blank */ continue; sub_args (cbuf, gbuf, sizeof(gbuf), argv); @@ -1242,11 +1243,12 @@ do { if (staying && (sim_on_check[sim_do_depth]) && (stat != SCPE_OK) && - (stat != SCPE_STEP)) + (stat != SCPE_STEP)) { if ((stat <= SCPE_MAX_ERR) && sim_on_actions[sim_do_depth][stat]) sim_brk_act[sim_do_depth] = sim_on_actions[sim_do_depth][stat]; else sim_brk_act[sim_do_depth] = sim_on_actions[sim_do_depth][0]; + } if (sim_vm_post != NULL) (*sim_vm_post) (TRUE); } while (staying); @@ -2995,11 +2997,12 @@ if (uptr == NULL) return SCPE_IERR; if (!(uptr->flags & UNIT_ATTABLE)) /* attachable? */ return SCPE_NOATT; -if (!(uptr->flags & UNIT_ATT)) /* not attached? */ +if (!(uptr->flags & UNIT_ATT)) { /* not attached? */ if (sim_switches & SIM_SW_REST) /* restoring? */ return SCPE_OK; /* allow detach */ else - return SCPE_NOATT; /* complain */ + return SCPE_NOATT; /* complain */ + } if ((dptr = find_dev_from_unit (uptr)) == NULL) return SCPE_OK; if (uptr->flags & UNIT_BUF) { @@ -3672,13 +3675,14 @@ for (i = 1; (dptr = sim_devices[i]) != NULL; i++) { /* flush attached files uptr = dptr->units + j; if ((uptr->flags & UNIT_ATT) && /* attached, */ !(uptr->flags & UNIT_BUF) && /* not buffered, */ - (uptr->fileref)) /* real file, */ + (uptr->fileref)) { /* real file, */ if (uptr->io_flush) /* unit specific flush routine */ uptr->io_flush (uptr); else if (!(uptr->flags & UNIT_RAW) && /* not raw, */ !(uptr->flags & UNIT_RO)) /* not read only? */ fflush (uptr->fileref); + } } } sim_cancel (&sim_step_unit); /* cancel step timer */ diff --git a/sim_disk.c b/sim_disk.c index b5f81539..16623482 100644 --- a/sim_disk.c +++ b/sim_disk.c @@ -1028,7 +1028,7 @@ if (created) { } capac = size_function (uptr->fileref); -if (capac && (capac != (t_addr)-1)) +if (capac && (capac != (t_addr)-1)) { if (dontautosize) { if ((capac < (uptr->capac*ctx->capac_factor)) && (DKUF_F_STD != DK_GET_FMT (uptr))) { if (!sim_quiet) { @@ -1043,6 +1043,7 @@ if (capac && (capac != (t_addr)-1)) else if ((capac > (uptr->capac*ctx->capac_factor)) || (DKUF_F_STD != DK_GET_FMT (uptr))) uptr->capac = capac/ctx->capac_factor; + } #if defined (SIM_ASYNCH_IO) sim_disk_set_async (uptr, completion_delay); @@ -1182,11 +1183,11 @@ if (ctx->dptr->dctrl & reason) { if ((i > 0) && (0 == memcmp (&data[i], &data[i-16], 16))) { ++same; continue; - } + } if (same > 0) { sim_debug (reason, ctx->dptr, "%04X thru %04X same as above\n", i-(16*same), i-1); same = 0; - } + } group = (((len - i) > 16) ? 16 : (len - i)); for (sidx=oidx=0; sidxdptr->dctrl & reason) { strbuf[sidx] = data[i+sidx]; else strbuf[sidx] = '.'; - } + } outbuf[oidx] = '\0'; strbuf[sidx] = '\0'; sim_debug (reason, ctx->dptr, "%04X%-48s %s\n", i, outbuf, strbuf); - } - if (same > 0) - sim_debug (reason, ctx->dptr, "%04X thru %04X same as above\n", i-(16*same), len-1); + } + if (same > 0) { + sim_debug (reason, ctx->dptr, "%04X thru %04X same as above\n", i-(16*same), len-1); + } } } } @@ -1524,7 +1526,7 @@ return TRUE; static t_stat sim_os_disk_info_raw (FILE *Disk, uint32 *sector_size, uint32 *removable) { DWORD IoctlReturnSize; -#ifndef __GNUC__ +#ifdef IOCTL_STORAGE_GET_DEVICE_NUMBER STORAGE_DEVICE_NUMBER Device; ZeroMemory (&Device, sizeof (Device)); @@ -2192,19 +2194,9 @@ typedef struct _VHD_DynamicDiskHeader { #define VHD_BAT_FREE_ENTRY (0xFFFFFFFF) #define VHD_DATA_BLOCK_ALIGNMENT ((uint64)4096) /* Optimum when underlying storage has 4k sectors */ -static char *VHD_DiskTypes[] = - { - "None", /* 0 */ - "Reserved (deprecated)", /* 1 */ - "Fixed hard disk", /* 2 */ -#define VHD_DT_Fixed 2 - "Dynamic hard disk", /* 3 */ -#define VHD_DT_Dynamic 3 - "Differencing hard disk", /* 4 */ -#define VHD_DT_Differencing 4 - "Reserved (deprecated)", /* 5 */ - "Reserved (deprecated)", /* 6 */ - }; +#define VHD_DT_Fixed 2 /* Fixed hard disk */ +#define VHD_DT_Dynamic 3 /* Dynamic hard disk */ +#define VHD_DT_Differencing 4 /* Differencing hard disk */ static uint32 NtoHl(uint32 value); @@ -2345,13 +2337,14 @@ if (!File) { Return = errno; goto Return_Cleanup; } -if (ModifiedTimeStamp) +if (ModifiedTimeStamp) { if (stat (szVHDPath, &statb)) { Return = errno; goto Return_Cleanup; } else *ModifiedTimeStamp = NtoHl ((uint32)(statb.st_mtime-946684800)); + } position = sim_fsize_ex (File); if (((int64)position) == -1) { Return = errno; @@ -3168,11 +3161,12 @@ for (i=0; i < strlen (FullParentVHDPath); i++) ExpandToFullPath (szVHDPath, FullVHDPath, BytesPerSector); HostPathToVhdPath (FullVHDPath, FullVHDPath, BytesPerSector); for (i=0, RelativeMatch=UpDirectories=0; i 0) && (0 == memcmp(&msg[i], &msg[i-16], 16))) { ++same; @@ -551,8 +552,9 @@ void eth_packet_trace_ex(ETH_DEV* dev, const uint8 *msg, int len, char* txt, int strbuf[sidx] = '\0'; sim_debug(reason, dev->dptr, "%04X%-48s %s\n", i, outbuf, strbuf); } - if (same > 0) + if (same > 0) { sim_debug(reason, dev->dptr, "%04X thru %04X same as above\n", i-(16*same), len-1); + } } } } @@ -666,6 +668,7 @@ void eth_zero(ETH_DEV* dev) static ETH_DEV **eth_open_devices = NULL; static int eth_open_device_count = 0; +#if defined (USE_NETWORK) || defined (USE_SHARED) static void _eth_add_to_open_list (ETH_DEV* dev) { eth_open_devices = realloc(eth_open_devices, (eth_open_device_count+1)*sizeof(*eth_open_devices)); @@ -684,6 +687,7 @@ for (i=0; i= host_len) return SCPE_ARG; /* no room */ else strcpy (host, hostp); + } if (validate_addr) { struct addrinfo *ai_host, *ai_validate, *ai; t_stat status; @@ -575,7 +576,6 @@ WORD wVersionRequested; WSADATA wsaData; wVersionRequested = MAKEWORD (2, 2); - err = WSAStartup (wVersionRequested, &wsaData); /* start Winsock */ if (err != 0) printf ("Winsock: startup error %d\n", err); @@ -583,9 +583,16 @@ if (err != 0) load_ws2 (); #endif /* endif AF_INET6 */ #else /* Use native addrinfo APIs */ +#if defined(AF_INET6) p_getaddrinfo = (getaddrinfo_func)getaddrinfo; p_getnameinfo = (getnameinfo_func)getnameinfo; p_freeaddrinfo = (freeaddrinfo_func)freeaddrinfo; +#else + /* Native APIs not available, connect stubs */ + p_getaddrinfo = (getaddrinfo_func)s_getaddrinfo; + p_getnameinfo = (getnameinfo_func)s_getnameinfo; + p_freeaddrinfo = (freeaddrinfo_func)s_freeaddrinfo; +#endif /* endif AF_INET6 */ #endif /* endif _WIN32 */ #if defined (SIGPIPE) signal (SIGPIPE, SIG_IGN); /* no pipe signals */ diff --git a/sim_tape.c b/sim_tape.c index 91cf3032..3b186b95 100644 --- a/sim_tape.c +++ b/sim_tape.c @@ -496,11 +496,11 @@ if (ctx->dptr->dctrl & reason) { if ((i > 0) && (0 == memcmp (&data[i], &data[i-16], 16))) { ++same; continue; - } + } if (same > 0) { sim_debug (reason, ctx->dptr, "%04X thru %04X same as above\n", i-(16*same), i-1); same = 0; - } + } group = (((len - i) > 16) ? 16 : (len - i)); for (sidx=oidx=0; sidxdptr->dctrl & reason) { strbuf[sidx] = data[i+sidx]; else strbuf[sidx] = '.'; - } + } outbuf[oidx] = '\0'; strbuf[sidx] = '\0'; sim_debug (reason, ctx->dptr, "%04X%-48s %s\n", i, outbuf, strbuf); - } - if (same > 0) - sim_debug (reason, ctx->dptr, "%04X thru %04X same as above\n", i-(16*same), len-1); + } + if (same > 0) { + sim_debug (reason, ctx->dptr, "%04X thru %04X same as above\n", i-(16*same), len-1); + } } } } @@ -1640,8 +1641,9 @@ t_stat sim_tape_rewind (UNIT *uptr) { struct tape_context *ctx = (struct tape_context *)uptr->tape_ctx; -if (uptr->flags & UNIT_ATT) +if (uptr->flags & UNIT_ATT) { sim_debug (ctx->dbit, ctx->dptr, "sim_tape_rewind(unit=%d)\n", uptr-ctx->dptr->units); + } uptr->pos = 0; MT_CLR_PNU (uptr); return MTSE_OK; @@ -1868,10 +1870,14 @@ t_stat sim_tape_show_capac (FILE *st, UNIT *uptr, int32 val, void *desc) if (uptr->capac) { if (uptr->capac >= (t_addr) 1000000) fprintf (st, "capacity=%dMB", (uint32) (uptr->capac / ((t_addr) 1000000))); - else if (uptr->capac >= (t_addr) 1000) - fprintf (st, "capacity=%dKB", (uint32) (uptr->capac / ((t_addr) 1000))); - else fprintf (st, "capacity=%dB", (uint32) uptr->capac); + else { + if (uptr->capac >= (t_addr) 1000) + fprintf (st, "capacity=%dKB", (uint32) (uptr->capac / ((t_addr) 1000))); + else + fprintf (st, "capacity=%dB", (uint32) uptr->capac); + } } -else fprintf (st, "unlimited capacity"); +else + fprintf (st, "unlimited capacity"); return SCPE_OK; } diff --git a/sim_timer.c b/sim_timer.c index b98ce47b..5bea3eff 100644 --- a/sim_timer.c +++ b/sim_timer.c @@ -896,7 +896,7 @@ if (sim_is_active_bool (uptr)) /* already active? */ inst_per_sec = sim_timer_inst_per_sec (); inst_delay = (int32)((inst_per_sec*usec_delay)/1000000.0); #if defined(SIM_ASYNCH_IO) && defined(SIM_ASYNCH_CLOCKS) -if ((sim_calb_tmr == -1) || /* if No timer initialized +if ((sim_calb_tmr == -1) || /* if No timer initialized */ (inst_delay < rtc_currd[sim_calb_tmr]) || /* or sooner than next clock tick? */ (rtc_elapsed[sim_calb_tmr] < sim_idle_stable) || /* or not idle stable yet */ (!(sim_asynch_enabled && sim_asynch_timer))) { /* or asynch disabled */