SCP: add sim_get_tool_path to get the expanded path to a local command
This logic was previously within the static SCP function _get_tool_version and is now exposed for use elsewhere.
This commit is contained in:
parent
c808256e87
commit
6d04cf814a
2 changed files with 26 additions and 17 deletions
42
scp.c
42
scp.c
|
@ -6361,12 +6361,10 @@ void fprint_capac (FILE *st, DEVICE *dptr, UNIT *uptr)
|
||||||
fprintf (st, "%s", sprint_capac (dptr, uptr));
|
fprintf (st, "%s", sprint_capac (dptr, uptr));
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *_get_tool_version (const char *tool)
|
const char *sim_get_tool_path (const char *tool)
|
||||||
{
|
{
|
||||||
char findcmd[PATH_MAX+1];
|
char findcmd[PATH_MAX+1];
|
||||||
char toolpath[PATH_MAX+1];
|
static char toolpath[PATH_MAX+1];
|
||||||
char versioncmd[PATH_MAX+1];
|
|
||||||
static char toolversion[PATH_MAX+1];
|
|
||||||
FILE *f;
|
FILE *f;
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
|
@ -6376,27 +6374,37 @@ FILE *f;
|
||||||
#else
|
#else
|
||||||
#define FIND_CMD "which"
|
#define FIND_CMD "which"
|
||||||
#endif
|
#endif
|
||||||
toolversion[0] = '\0';
|
memset (toolpath, 0, sizeof(toolpath));
|
||||||
snprintf (findcmd, sizeof (findcmd), "%s %s", FIND_CMD, tool);
|
snprintf (findcmd, sizeof (findcmd), "%s %s", FIND_CMD, tool);
|
||||||
if ((f = popen (findcmd, "r"))) {
|
if ((f = popen (findcmd, "r"))) {
|
||||||
memset (toolpath, 0, sizeof(toolpath));
|
|
||||||
do {
|
do {
|
||||||
if (NULL == fgets (toolpath, sizeof(toolpath)-1, f))
|
if (NULL == fgets (toolpath, sizeof(toolpath)-1, f))
|
||||||
break;
|
break;
|
||||||
sim_trim_endspc (toolpath);
|
sim_trim_endspc (toolpath);
|
||||||
} while (toolpath[0] == '\0');
|
} while (toolpath[0] == '\0');
|
||||||
pclose (f);
|
pclose (f);
|
||||||
if (toolpath[0]) {
|
}
|
||||||
snprintf (versioncmd, sizeof (versioncmd), "%s --version", tool);
|
return toolpath;
|
||||||
if ((f = popen (versioncmd, "r"))) {
|
}
|
||||||
memset (toolversion, 0, sizeof(toolversion));
|
|
||||||
do {
|
static const char *_get_tool_version (const char *tool)
|
||||||
if (NULL == fgets (toolversion, sizeof(toolversion)-1, f))
|
{
|
||||||
break;
|
const char *toolpath;
|
||||||
sim_trim_endspc (toolversion);
|
char versioncmd[PATH_MAX+1];
|
||||||
} while (toolversion[0] == '\0');
|
static char toolversion[PATH_MAX+1];
|
||||||
pclose (f);
|
FILE *f;
|
||||||
}
|
|
||||||
|
memset (toolversion, 0, sizeof(toolversion));
|
||||||
|
toolpath = sim_get_tool_path (tool);
|
||||||
|
if (toolpath[0]) {
|
||||||
|
snprintf (versioncmd, sizeof (versioncmd), "%s --version", tool);
|
||||||
|
if ((f = popen (versioncmd, "r"))) {
|
||||||
|
do {
|
||||||
|
if (NULL == fgets (toolversion, sizeof(toolversion)-1, f))
|
||||||
|
break;
|
||||||
|
sim_trim_endspc (toolversion);
|
||||||
|
} while (toolversion[0] == '\0');
|
||||||
|
pclose (f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return toolversion;
|
return toolversion;
|
||||||
|
|
1
scp.h
1
scp.h
|
@ -247,6 +247,7 @@ const char *sim_error_text (t_stat stat);
|
||||||
t_stat sim_string_to_stat (const char *cptr, t_stat *cond);
|
t_stat sim_string_to_stat (const char *cptr, t_stat *cond);
|
||||||
t_stat sim_sched_step (void);
|
t_stat sim_sched_step (void);
|
||||||
t_stat sim_cancel_step (void);
|
t_stat sim_cancel_step (void);
|
||||||
|
const char *sim_get_tool_path (const char *tool);
|
||||||
void sim_printf (const char *fmt, ...) GCC_FMT_ATTR(1, 2);
|
void sim_printf (const char *fmt, ...) GCC_FMT_ATTR(1, 2);
|
||||||
void sim_perror (const char *msg);
|
void sim_perror (const char *msg);
|
||||||
t_stat sim_messagef (t_stat stat, const char *fmt, ...) GCC_FMT_ATTR(2, 3);
|
t_stat sim_messagef (t_stat stat, const char *fmt, ...) GCC_FMT_ATTR(2, 3);
|
||||||
|
|
Loading…
Add table
Reference in a new issue