git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2363
4a8a32a2-be11-0410-ad9d-
d568d2c75423
-------------------------------------------------------------------------*/
#include "common.h"
-------------------------------------------------------------------------*/
#include "common.h"
-#include <sys/stat.h>
-#endif
-
-
-#if !defined(__BORLANDC__) && !defined(_MSC_VER)
-#else
-// No unistd.h in Borland C++
-extern int access (const char *, int);
-#define X_OK 1
-/*!
-Call an external program with arguements
-*/
//char *ExePathList[]= {SRCDIR "/bin",PREFIX "/bin", NULL};
char *ExePathList[] = {NULL, NULL}; /* First entry may be overwritten, so use two. */
//char *ExePathList[]= {SRCDIR "/bin",PREFIX "/bin", NULL};
char *ExePathList[] = {NULL, NULL}; /* First entry may be overwritten, so use two. */
-int
-my_system (const char *cmd)
+/*!
+Find the comamnd in one of predefined paths
+
+NOTE: this function does't do it's job if:
+- the program name also contains the path
+ (and it seems thet this is always true :-(()
+- there are no spaces in cmd
+- the program name contains space characters
+
+It has to be rewritten.
+*/
+
+static char *
+get_path (const char *cmd)
- int argsStart, e, i = 0;
char *cmdLine = NULL;
argsStart = strstr (cmd, " ") - cmd;
char *cmdLine = NULL;
argsStart = strstr (cmd, " ") - cmd;
strcat (cmdLine, DIR_SEPARATOR_STRING);
strncat (cmdLine, cmd, argsStart); // the command
strcat (cmdLine, DIR_SEPARATOR_STRING);
strncat (cmdLine, cmd, argsStart); // the command
strcat (cmdLine, ".exe");
strcat (cmdLine, ".exe");
+ if (access(cmdLine, 0) == 0)
+#else
+ if (access(cmdLine, X_OK) == 0)
-
- if (access (cmdLine, X_OK) == 0)
{
// the arguments
strcat (cmdLine, cmd + argsStart);
{
// the arguments
strcat (cmdLine, cmd + argsStart);
- if (options.verboseExec)
- {
+ return cmdLine;
+}
+
+
+/*!
+Call an external program with arguements
+*/
+
+int
+my_system (const char *cmd)
+{
+ int e;
+ char *cmdLine = get_path (cmd);
+
+ if (options.verboseExec) {
printf ("+ %s\n", cmdLine ? cmdLine : cmd);
printf ("+ %s\n", cmdLine ? cmdLine : cmd);
// command found in predefined path
e = system (cmdLine);
Safe_free (cmdLine);
// command found in predefined path
e = system (cmdLine);
Safe_free (cmdLine);
// trust on $PATH
e = system (cmd);
// trust on $PATH
e = system (cmd);
+
+/*!
+Pipe an external program with arguements
+*/
+
+#ifdef _WIN32
+#define popen_read(cmd) _popen((cmd), "rt")
+#else
+#define popen_read(cmd) popen((cmd), "r")
+#endif
+
+FILE *
+my_popen (const char *cmd)
+{
+ FILE *fp;
+ char *cmdLine = get_path (cmd);
+
+ if (options.verboseExec) {
+ printf ("+ %s\n", cmdLine ? cmdLine : cmd);
+ }
+
+ if (cmdLine) {
+ // command found in predefined path
+ fp = popen_read (cmdLine);
+ Safe_free (cmdLine);
+ }
+ else {
+ // trust on $PATH
+ fp = popen_read (cmd);
+ }
+
+ return fp;
+}
#define __MYSYSTEM_H
int my_system (const char *cmd) ;
#define __MYSYSTEM_H
int my_system (const char *cmd) ;
+FILE *my_popen (const char *cmd) ;
extern char *ExePathList[] ; // List of paths to try to locate exeucatbles
extern char *ExePathList[] ; // List of paths to try to locate exeucatbles