1
0
mirror of https://github.com/cclassic/model-ghdl synced 2024-11-29 09:13:28 +01:00

Bugfix preventing detection of program when called from PATH

This commit is contained in:
Markus Koch 2016-05-30 19:42:53 +02:00
parent 7a8226f44d
commit fde1671c08

14
main.c
View File

@ -22,7 +22,7 @@
#define ISOPT(cmd) (strcmp(argv[i], cmd) == 0) #define ISOPT(cmd) (strcmp(argv[i], cmd) == 0)
#define GETOPT(cmd) (strcmp(argv[i], cmd) == 0) && (++i < argc) #define GETOPT(cmd) (strcmp(argv[i], cmd) == 0) && (++i < argc)
const char *laststrstr (const char *__haystack, const char *__needle); const char *getAfter (const char *__haystack, const char *__needle);
int get_application(const char *call); int get_application(const char *call);
int vsim(int argc, char **argv); int vsim(int argc, char **argv);
int vcom(int argc, char **argv); int vcom(int argc, char **argv);
@ -89,7 +89,7 @@ int run_ghdl(char *command, ...) {
vsprintf(cmd, command, argptr); vsprintf(cmd, command, argptr);
va_end(argptr); va_end(argptr);
//printf("RUN_GHDL: %s\n", cmd); printf("RUN_GHDL: %s\n", cmd);
proc = popen(cmd, "r"); proc = popen(cmd, "r");
if (proc == NULL) { if (proc == NULL) {
@ -162,7 +162,7 @@ int run_simulation(char *command, ...) {
vsprintf(cmd, command, argptr); vsprintf(cmd, command, argptr);
va_end(argptr); va_end(argptr);
//printf("RUN_SIM: %s\n", cmd); printf("RUN_SIM: %s\n", cmd);
proc = popen(cmd, "r"); proc = popen(cmd, "r");
if (proc == NULL) { if (proc == NULL) {
@ -510,7 +510,7 @@ int main(int argc, char **argv)
// Detects which function to call depending on the program name in argv[0] // Detects which function to call depending on the program name in argv[0]
int get_application(const char *call) { int get_application(const char *call) {
char *pos; char *pos;
pos = (char*) laststrstr(call, "/") + 1; pos = (char*) getAfter(call, "/");
if (strcmp(pos, "vcom") == 0) { if (strcmp(pos, "vcom") == 0) {
return PROG_VCOM; return PROG_VCOM;
} }
@ -533,14 +533,16 @@ int get_application(const char *call) {
} }
// Returns the string after the last occurence of __needle // Returns the string after the last occurence of __needle
const char *laststrstr (const char *__haystack, const char *__needle) { const char *getAfter (const char *__haystack, const char *__needle) {
char *pos, *realPos; char *pos, *realPos;
char *haystack; char *haystack;
haystack = (char*) __haystack; haystack = (char*) __haystack;
pos = (char*) __haystack; pos = (char*) __haystack;
while (pos != NULL) { while (pos != NULL) {
realPos = pos; realPos = pos + 1;
pos = strstr(haystack, __needle); pos = strstr(haystack, __needle);
if (haystack == __haystack && pos == NULL) // If no __needle is present at all...
realPos = (char*) __haystack; // Return the entire string
haystack = pos + 1; haystack = pos + 1;
} }
return realPos; return realPos;