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 -------------------------------------------------------------------------*/
35 //char *ExePathList[]= {SRCDIR "/bin",PREFIX "/bin", NULL};
36 char *ExePathList[] = {NULL, NULL}; /* First entry may be overwritten, so use two. */
39 Find the comamnd in one of predefined paths
41 NOTE: this function does't do it's job if:
42 - the program name also contains the path
43 (and it seems thet this is always true :-(()
44 - there are no spaces in cmd
45 - the program name contains space characters
47 It has to be rewritten.
51 get_path (const char *cmd)
56 argsStart = strstr (cmd, " ") - cmd;
58 // try to find the command in predefined path's
59 while (ExePathList[i])
61 cmdLine = (char *) Safe_alloc (strlen (ExePathList[i]) + strlen (cmd) + 10);
62 strcpy (cmdLine, ExePathList[i]); // the path
64 strcat (cmdLine, DIR_SEPARATOR_STRING);
65 strncat (cmdLine, cmd, argsStart); // the command
68 strcat (cmdLine, ".exe");
69 if (access(cmdLine, 0) == 0)
71 if (access(cmdLine, X_OK) == 0)
75 strcat (cmdLine, cmd + argsStart);
88 Call an external program with arguements
92 my_system (const char *cmd)
95 char *cmdLine = get_path (cmd);
97 if (options.verboseExec) {
98 printf ("+ %s\n", cmdLine ? cmdLine : cmd);
102 // command found in predefined path
103 e = system (cmdLine);
116 Pipe an external program with arguements
120 #define popen_read(cmd) _popen((cmd), "rt")
122 #define popen_read(cmd) popen((cmd), "r")
126 my_popen (const char *cmd)
129 char *cmdLine = get_path (cmd);
131 if (options.verboseExec) {
132 printf ("+ %s\n", cmdLine ? cmdLine : cmd);
136 // command found in predefined path
137 fp = popen_read (cmdLine);
142 fp = popen_read (cmd);