xspice, introduce cm_message_printf()
This commit is contained in:
parent
137f8e9641
commit
885e7df8a5
|
|
@ -85,6 +85,13 @@ int cm_event_queue(double time);
|
||||||
char *cm_message_get_errmsg(void);
|
char *cm_message_get_errmsg(void);
|
||||||
int cm_message_send(char *msg);
|
int cm_message_send(char *msg);
|
||||||
|
|
||||||
|
#ifdef __GNUC__
|
||||||
|
int cm_message_printf(const char *fmt, ...) __attribute__ ((format (__printf__, 1, 2)));
|
||||||
|
#else
|
||||||
|
int cm_message_printf(const char *fmt, ...);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
double cm_netlist_get_c(void);
|
double cm_netlist_get_c(void);
|
||||||
double cm_netlist_get_l(void);
|
double cm_netlist_get_l(void);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -179,9 +179,7 @@ void cm_filesource(ARGS) /* structure holding parms, inputs, outputs, etc.
|
||||||
free(p);
|
free(p);
|
||||||
}
|
}
|
||||||
if (!loc->state->fp) {
|
if (!loc->state->fp) {
|
||||||
char msg[512];
|
cm_message_printf("cannot open file %s", PARAM(file));
|
||||||
snprintf(msg, sizeof(msg), "cannot open file %s", PARAM(file));
|
|
||||||
cm_message_send(msg);
|
|
||||||
loc->state->atend = 1;
|
loc->state->atend = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -936,11 +936,8 @@ void cm_d_source(ARGS)
|
||||||
source = fopen(p, "r");
|
source = fopen(p, "r");
|
||||||
free(p);
|
free(p);
|
||||||
}
|
}
|
||||||
if (!source) {
|
if (!source)
|
||||||
char msg[512];
|
cm_message_printf("cannot open file %s", PARAM(input_file));
|
||||||
snprintf(msg, sizeof(msg), "cannot open file %s", PARAM(input_file));
|
|
||||||
cm_message_send(msg);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* increment counter if not a comment until EOF reached... */
|
/* increment counter if not a comment until EOF reached... */
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,8 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
@ -452,3 +454,41 @@ FILE *fopen_with_path(const char *path, const char *mode)
|
||||||
fp = fopen(path, mode);
|
fp = fopen(path, mode);
|
||||||
return fp;
|
return fp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
cm_message_printf(const char *fmt, ...)
|
||||||
|
{
|
||||||
|
char buf[1024];
|
||||||
|
char *p = buf;
|
||||||
|
int size = sizeof(buf);
|
||||||
|
int rv;
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
|
||||||
|
int nchars;
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
nchars = vsnprintf(p, (size_t) size, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
if (nchars == -1) { // compatibility to old implementations
|
||||||
|
size *= 2;
|
||||||
|
} else if (size < nchars + 1) {
|
||||||
|
size = nchars + 1;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (p == buf)
|
||||||
|
p = tmalloc((size_t) size * sizeof(char));
|
||||||
|
else
|
||||||
|
p = trealloc(p, (size_t) size * sizeof(char));
|
||||||
|
}
|
||||||
|
|
||||||
|
rv = cm_message_send(p);
|
||||||
|
if (p != buf)
|
||||||
|
txfree(p);
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue