From: jtvolpe Date: Sun, 20 May 2001 03:33:47 +0000 (+0000) Subject: Added support functions BuildCmdLine and my_system to utilities X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=a6fca54fef56ee58479ea160f6d229de445337c1;p=fw%2Fsdcc Added support functions BuildCmdLine and my_system to utilities git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@835 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/support/Util/BuildCmd.c b/support/Util/BuildCmd.c new file mode 100644 index 00000000..2d0b051f --- /dev/null +++ b/support/Util/BuildCmd.c @@ -0,0 +1,90 @@ +/*------------------------------------------------------------------------- + BuildCmd - SDCC Support function + + Written By - Sandeep Dutta . sandeep.dutta@usa.net (1999) + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + In other words, you are welcome to use, share and improve this program. + You are forbidden to forbid anyone else to use, share and improve + what you give them. Help stamp out software-hoarding! +-------------------------------------------------------------------------*/ + +/*! Build a command line with parameter substitution +*/ + +#include +#include + +void +buildCmdLine (char *into, const char **cmds, + const char *p1, const char *p2, + const char *p3, const char **list) +{ + const char *p, *from; + + *into = '\0'; + + while (*cmds) + { + from = *cmds; + cmds++; + + /* See if it has a '$' anywhere - if not, just copy */ + if ((p = strchr (from, '$'))) + { + strncat (into, from, p - from); + /* seperate it */ + strcat (into, " "); + from = p + 2; + p++; + switch (*p) + { + case '1': + if (p1) + strcat (into, p1); + break; + case '2': + if (p2) + strcat (into, p2); + break; + case '3': + if (p3) + strcat (into, p3); + break; + case 'l': + { + const char **tmp = list; + if (tmp) + { + while (*tmp) + { + strcat (into, *tmp); + strcat (into, " "); + tmp++; + } + } + break; + } + default: + assert (0); + } + } + strcat (into, from); // this includes the ".asm" from "$1.asm" + + strcat (into, " "); + } +} + diff --git a/support/Util/BuildCmd.h b/support/Util/BuildCmd.h new file mode 100644 index 00000000..0dc403e0 --- /dev/null +++ b/support/Util/BuildCmd.h @@ -0,0 +1,34 @@ +/*------------------------------------------------------------------------- + BuildCmd - SDCC Support function + + Written By - Sandeep Dutta . sandeep.dutta@usa.net (1999) + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + In other words, you are welcome to use, share and improve this program. + You are forbidden to forbid anyone else to use, share and improve + what you give them. Help stamp out software-hoarding! +-------------------------------------------------------------------------*/ + +#if !defined(__BUILDCMD_H) + +#define __BUILDCMD_H + +void +buildCmdLine (char *into, const char **cmds, + const char *p1, const char *p2, + const char *p3, const char **list) ; + +#endif diff --git a/support/Util/MySystem.c b/support/Util/MySystem.c new file mode 100644 index 00000000..bae66caa --- /dev/null +++ b/support/Util/MySystem.c @@ -0,0 +1,88 @@ +/*------------------------------------------------------------------------- + MySystem - SDCC Support function + + Written By - Sandeep Dutta . sandeep.dutta@usa.net (1999) + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + In other words, you are welcome to use, share and improve this program. + You are forbidden to forbid anyone else to use, share and improve + what you give them. Help stamp out software-hoarding! +-------------------------------------------------------------------------*/ + +#include "common.h" +#include "newalloc.h" +#include + +#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. */ + +int +my_system (const char *cmd) +{ + int argsStart, e, i = 0; + char *cmdLine = NULL; + + argsStart = strstr (cmd, " ") - cmd; + + // try to find the command in predefined path's + while (ExePathList[i]) + { + cmdLine = (char *) Safe_malloc (strlen (ExePathList[i]) + strlen (cmd) + 10); + strcpy (cmdLine, ExePathList[i]); // the path + + strcat (cmdLine, DIR_SEPARATOR_STRING); + strncat (cmdLine, cmd, argsStart); // the command + +#if NATIVE_WIN32 + strcat (cmdLine, ".exe"); +#endif + + if (access (cmdLine, X_OK) == 0) + { + // the arguments + strcat (cmdLine, cmd + argsStart); + break; + } + free (cmdLine); + cmdLine = NULL; + i++; + } + + if (verboseExec) + { + printf ("+ %s\n", cmdLine ? cmdLine : cmd); + } + + if (cmdLine) + { + // command found in predefined path + e = system (cmdLine); + free (cmdLine); + } + else + { + // trust on $PATH + e = system (cmd); + } + return e; +} + diff --git a/support/Util/MySystem.h b/support/Util/MySystem.h new file mode 100644 index 00000000..93eb07f2 --- /dev/null +++ b/support/Util/MySystem.h @@ -0,0 +1,32 @@ +/*------------------------------------------------------------------------- + MySystem - SDCC Support function + + Written By - Sandeep Dutta . sandeep.dutta@usa.net (1999) + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + In other words, you are welcome to use, share and improve this program. + You are forbidden to forbid anyone else to use, share and improve + what you give them. Help stamp out software-hoarding! +-------------------------------------------------------------------------*/ + +#if !defined(__MYSYSTEM_H) +#define __MYSYSTEM_H + +int my_system (const char *cmd) ; + +extern char *ExePathList[] ; // List of paths to try to locate exeucatbles + +#endif