[Simh] [PATCH 02 of 14] sim_printf_log() changes for core

Peter Lund firefly at vax64.dk
Mon Sep 10 17:09:36 EDT 2007


3 files changed, 26 insertions(+), 72 deletions(-)
scp.c       |   22 ++++++-------------
sim_ether.c |   68 +++++++++++++----------------------------------------------
sim_timer.c |    8 ++----


# HG changeset patch
# User Peter Lund <firefly at vax64.dk>
# Date 1189306443 -7200
# Node ID 88f8539ad85b749ffad9a3c556381e5aa31e4a4e
# Parent  f8cf640ba8d125df32b4bf141bece456e3545c3a
sim_printf_log() changes for core

diff -r f8cf640ba8d1 -r 88f8539ad85b scp.c
--- a/scp.c	Sun Sep 09 04:53:23 2007 +0200
+++ b/scp.c	Sun Sep 09 04:54:03 2007 +0200
@@ -670,9 +670,7 @@ while (stat != SCPE_EXIT) {             
         stat = cmdp->action (cmdp->arg, cptr);          /* if found, exec */
     else stat = SCPE_UNK;
     if (stat >= SCPE_BASE) {                            /* error? */
-        printf ("%s\n", scp_error_messages[stat - SCPE_BASE]);
-        if (sim_log) fprintf (sim_log, "%s\n",
-            scp_error_messages[stat - SCPE_BASE]);
+        sim_printf_log ("%s\n", scp_error_messages[stat - SCPE_BASE]);
         }
     if (sim_vm_post != NULL) (*sim_vm_post) (TRUE);
     }                                                   /* end while */
@@ -729,8 +727,7 @@ if (*cptr) {
     cptr = get_glyph (cptr, gbuf, 0);
     if (*cptr) return SCPE_2MARG;
     if (cmdp = find_cmd (gbuf)) {
-        printf (cmdp->help);
-        if (sim_log) fprintf (sim_log, cmdp->help);
+        sim_printf_log (cmdp->help);
         }
     else return SCPE_ARG;
     }
@@ -752,6 +749,7 @@ if ((cptr == NULL) || (strlen (cptr) == 
 #endif
 fflush(stdout);                                         /* flush stdout */
 if (sim_log) fflush (sim_log);                          /* flush log if enabled */
+if (sim_deb) fflush (sim_deb);                          /* flush log if enabled */
 system (cptr);
 #if defined (VMS)
 printf ("\n");
@@ -764,8 +762,7 @@ return SCPE_OK;
 
 t_stat echo_cmd (int32 flag, char *cptr)
 {
-puts (cptr);
-if (sim_log) fprintf (sim_log, "%s\n", cptr);
+sim_printf_log("%s\n", cptr);
 return SCPE_OK;
 }
 
@@ -845,8 +842,7 @@ do {
         break;
         }
     if (*cptr == 0) continue;                           /* ignore blank */
-    if (echo) printf("do> %s\n", cptr);                 /* echo if -v */
-    if (echo && sim_log) fprintf (sim_log, "do> %s\n", cptr);
+    if (echo) sim_printf_log("do> %s\n", cptr);         /* echo if -v */
     cptr = get_glyph (cptr, gbuf, 0);                   /* get command glyph */
     sim_switches = 0;                                   /* init switches */
     isdo = FALSE;
@@ -866,17 +862,13 @@ do {
         (stat != SCPE_STEP)) {
         if (!echo && !sim_quiet &&                      /* report if not echoing */
             (!isdo || (stat & SCPE_DOFAILED))) {        /* and not from DO return */
-            printf("%s> %s\n", do_arg[0], ocptr);
-            if (sim_log)
-                fprintf (sim_log, "%s> %s\n", do_arg[0], ocptr);
+            sim_printf_log("%s> %s\n", do_arg[0], ocptr);
             }
         stat = stat & ~SCPE_DOFAILED;                   /* remove possible flag */
         }
     if ((staying || !interactive) &&                    /* report error if staying */
         (stat >= SCPE_BASE)) {                          /* or in cmdline file */
-        printf ("%s\n", scp_error_messages[stat - SCPE_BASE]);
-        if (sim_log) fprintf (sim_log, "%s\n",
-            scp_error_messages[stat - SCPE_BASE]);
+        sim_printf_log ("%s\n", scp_error_messages[stat - SCPE_BASE]);
         }
     if (sim_vm_post != NULL) (*sim_vm_post) (TRUE);
     } while (staying);
diff -r f8cf640ba8d1 -r 88f8539ad85b sim_ether.c
--- a/sim_ether.c	Sun Sep 09 04:53:23 2007 +0200
+++ b/sim_ether.c	Sun Sep 09 04:54:03 2007 +0200
@@ -242,8 +242,7 @@
 #include <ctype.h>
 #include "sim_ether.h"
 #include "sim_sock.h"
-
-extern FILE *sim_log;
+#include "sim_console.h"
 
 
 /*============================================================================*/
@@ -543,9 +542,7 @@ t_stat ethq_init(ETH_QUE* que, int max)
       memset(que->item, 0, size);
     } else {
       /* failed to allocate memory */
-      char* msg = "EthQ: failed to allocate dynamic queue[%d]\r\n";
-      printf(msg, max);
-      if (sim_log) fprintf(sim_log, msg, max);
+      sim_printf_log("EthQ: failed to allocate dynamic queue[%d]\r\n", max);
       return SCPE_MEM;
     };
   };
@@ -671,9 +668,7 @@ void load_function(char* function, void*
 void load_function(char* function, void** func_ptr) {
 	*func_ptr = GetProcAddress(hDll, function);
 	if (*func_ptr == 0) {
-	    char* msg = "Eth: Failed to find function '%s' in wpcap.dll\r\n";
-		printf (msg, function);
-		if (sim_log) fprintf (sim_log, msg, function);
+		sim_printf_log ("Eth: Failed to find function '%s' in wpcap.dll\r\n", function);
 		dll_loaded = 3;
 	}
 }
@@ -686,14 +681,8 @@ int load_wpcap(void) {
 			hDll = LoadLibrary(TEXT("wpcap.dll"));
 			if (hDll == 0) {
 				/* failed to load DLL */
-			    char* msg  = "Eth: Failed to load wpcap.dll\r\n";
-			    char* msg2 = "Eth: You must install WinPcap 4.x to use networking\r\n";
-				printf (msg);
-				printf (msg2);
-				if (sim_log) {
-					fprintf (sim_log, msg);
-				    fprintf (sim_log, msg2);
-				}
+				sim_printf_log ("Eth: Failed to load wpcap.dll\r\n");
+				sim_printf_log ("Eth: You must install WinPcap 4.x to use networking\r\n");
 				dll_loaded = 2;
 				break;
 			} else {
@@ -718,10 +707,7 @@ int load_wpcap(void) {
 
 			if (dll_loaded == 1) {
 				/* log successful load */
-				char* version = p_pcap_lib_version();
-				printf("%s\n", version);
-				if (sim_log)
-					fprintf(sim_log, "%s\n", version);
+				sim_printf_log("%s\n", p_pcap_lib_version());
 			}
 			break;
 		default:								/* loaded or failed */
@@ -927,14 +913,10 @@ t_stat eth_open(ETH_DEV* dev, char* name
   memset(errbuf, 0, sizeof(errbuf));
   dev->handle = (void*) pcap_open_live(savname, bufsz, ETH_PROMISC, PCAP_READ_TIMEOUT, errbuf);
   if (!dev->handle) { /* can't open device */
-    msg = "Eth: pcap_open_live error - %s\r\n";
-    printf (msg, errbuf);
-    if (sim_log) fprintf (sim_log, msg, errbuf);
+    sim_printf_log ("Eth: pcap_open_live error - %s\r\n", errbuf);
     return SCPE_OPENERR;
   } else {
-    msg = "Eth: opened %s\r\n";
-    printf (msg, savname);
-    if (sim_log) fprintf (sim_log, msg, savname);
+    sim_printf_log ("Eth: opened %s\r\n", savname);
   }
 
   /* save name of device */
@@ -969,9 +951,7 @@ t_stat eth_open(ETH_DEV* dev, char* name
 #ifdef USE_SETNONBLOCK
   /* set ethernet device non-blocking so pcap_dispatch() doesn't hang */
   if (pcap_setnonblock (dev->handle, 1, errbuf) == -1) {
-    msg = "Eth: Failed to set non-blocking: %s\r\n";
-    printf (msg, errbuf);
-    if (sim_log) fprintf (sim_log, msg, errbuf);
+    sim_printf_log ("Eth: Failed to set non-blocking: %s\r\n", errbuf);
   }
 #endif
 #endif /* !defined (USE_READER_THREAD */
@@ -980,7 +960,6 @@ t_stat eth_open(ETH_DEV* dev, char* name
 
 t_stat eth_close(ETH_DEV* dev)
 {
-  char* msg = "Eth: closed %s\r\n";
   pcap_t *pcap;
 
   /* make sure device exists */
@@ -990,8 +969,7 @@ t_stat eth_close(ETH_DEV* dev)
   pcap = (pcap_t *)dev->handle;
   dev->handle = NULL;
   pcap_close(pcap);
-  printf (msg, dev->name);
-  if (sim_log) fprintf (sim_log, msg, dev->name);
+  sim_printf_log ("Eth: closed %s\r\n", dev->name);
 
 #if defined (USE_READER_THREAD)
   pthread_join (dev->reader_thread, NULL);
@@ -1026,12 +1004,9 @@ t_stat eth_reflect(ETH_DEV* dev, ETH_MAC
   /* send the packet */
   status = eth_write (dev, &send, NULL);
   if (status != SCPE_OK) {
-    char *msg;
-    msg = "Eth: Error Transmitting packet: %s\r\n"
+    sim_printf_log("Eth: Error Transmitting packet: %s\r\n"
           "You may need to run as root, or install a libpcap version\r\n"
-          "which is at least 0.9 from www.tcpdump.org\r\n";
-    printf(msg, strerror(errno));
-    if (sim_log) fprintf (sim_log, msg, strerror(errno));
+          "which is at least 0.9 from www.tcpdump.org\r\n", strerror(errno));
     return status;
   }
 
@@ -1209,7 +1184,6 @@ t_stat eth_filter(ETH_DEV* dev, int addr
   t_stat status;
 #ifdef USE_BPF
   struct bpf_program bpf;
-  char* msg;
 #endif
 
   /* make sure device exists */
@@ -1319,21 +1293,13 @@ t_stat eth_filter(ETH_DEV* dev, int addr
 #ifdef USE_BPF
   /* compile filter string */
   if ((status = pcap_compile(dev->handle, &bpf, buf, 1, bpf_netmask)) < 0) {
-    sprintf(errbuf, "%s", pcap_geterr(dev->handle));
-    msg = "Eth: pcap_compile error: %s\r\n";
-    printf(msg, errbuf);
-    if (sim_log) fprintf (sim_log, msg, errbuf);
+    sim_printf_log("Eth: pcap_compile error: %s\r\n", pcap_geterr(dev->handle));
     /* show erroneous BPF string */
-    msg = "Eth: BPF string is: |%s|\r\n";
-    printf (msg, buf);
-    if (sim_log) fprintf (sim_log, msg, buf);
+    sim_printf_log("Eth: BPF string is: |%s|\r\n", buf);
   } else {
     /* apply compiled filter string */
     if ((status = pcap_setfilter(dev->handle, &bpf)) < 0) {
-      sprintf(errbuf, "%s", pcap_geterr(dev->handle));
-      msg = "Eth: pcap_setfilter error: %s\r\n";
-      printf(msg, errbuf);
-      if (sim_log) fprintf (sim_log, msg, errbuf);
+      sim_printf_log("Eth: pcap_setfilter error: %s\r\n", pcap_geterr(dev->handle));
     } else {
 #ifdef USE_SETNONBLOCK
       /* set file non-blocking */
@@ -1439,9 +1405,7 @@ int eth_devices(int max, ETH_LIST* list)
 #ifndef DONT_USE_PCAP_FINDALLDEVS
   /* retrieve the device list */
   if (pcap_findalldevs(&alldevs, errbuf) == -1) {
-    char* msg = "Eth: error in pcap_findalldevs: %s\r\n";
-    printf (msg, errbuf);
-    if (sim_log) fprintf (sim_log, msg, errbuf);
+    sim_printf_log ("Eth: error in pcap_findalldevs: %s\r\n", errbuf);
   } else {
     /* copy device list into the passed structure */
     for (i=0, dev=alldevs; dev; dev=dev->next) {
diff -r f8cf640ba8d1 -r 88f8539ad85b sim_timer.c
--- a/sim_timer.c	Sun Sep 09 04:53:23 2007 +0200
+++ b/sim_timer.c	Sun Sep 09 04:54:03 2007 +0200
@@ -47,6 +47,7 @@
 
 #include "sim_defs.h"
 #include <ctype.h>
+#include "sim_console.h"
 
 t_bool sim_idle_enab = FALSE;                           /* global flag */
 
@@ -58,7 +59,6 @@ static uint32 sim_throt_state = 0;
 static uint32 sim_throt_state = 0;
 static int32 sim_throt_wait = 0;
 extern int32 sim_interval, sim_switches;
-extern FILE *sim_log;
 extern UNIT *sim_clock_queue;
 
 t_stat sim_throt_svc (UNIT *uptr);
@@ -481,8 +481,7 @@ sim_idle_enab = TRUE;
 sim_idle_enab = TRUE;
 if (sim_throt_type != SIM_THROT_NONE) {
     sim_set_throt (0, NULL);
-    printf ("Throttling disabled\n");
-    if (sim_log) fprintf (sim_log, "Throttling disabled\n");
+    sim_printf_log ("Throttling disabled\n");
     }
 return SCPE_OK;
 }
@@ -527,8 +526,7 @@ else {
         sim_throt_type = SIM_THROT_PCT;
     else return SCPE_ARG;
     if (sim_idle_enab) {
-        printf ("Idling disabled\n");
-        if (sim_log) fprintf (sim_log, "Idling disabled\n");
+        sim_printf_log ("Idling disabled\n");
         sim_clr_idle (NULL, 0, NULL, NULL);
         }
     sim_throt_val = (uint32) val;



More information about the Simh mailing list