1 /*-------------------------------------------------------------------------
2 MySystem - SDCC Support function
4 Written By - Sandeep Dutta . sandeep.dutta@usa.net (1999)
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 In other words, you are welcome to use, share and improve this program.
21 You are forbidden to forbid anyone else to use, share and improve
22 what you give them. Help stamp out software-hoarding!
23 -------------------------------------------------------------------------*/
34 #if !defined(__BORLANDC__) && !defined(_MSC_VER)
37 // No unistd.h in Borland C++
38 extern int access (const char *, int);
43 Call an external program with arguements
46 //char *ExePathList[]= {SRCDIR "/bin",PREFIX "/bin", NULL};
47 char *ExePathList[] = {NULL, NULL}; /* First entry may be overwritten, so use two. */
50 my_system (const char *cmd)
52 int argsStart, e, i = 0;
55 argsStart = strstr (cmd, " ") - cmd;
57 // try to find the command in predefined path's
58 while (ExePathList[i])
60 cmdLine = (char *) Safe_alloc (strlen (ExePathList[i]) + strlen (cmd) + 10);
61 strcpy (cmdLine, ExePathList[i]); // the path
63 strcat (cmdLine, DIR_SEPARATOR_STRING);
64 strncat (cmdLine, cmd, argsStart); // the command
67 strcat (cmdLine, ".exe");
70 if (access (cmdLine, X_OK) == 0)
73 strcat (cmdLine, cmd + argsStart);
83 printf ("+ %s\n", cmdLine ? cmdLine : cmd);
88 // command found in predefined path