head 1.15; access; symbols OSSP_RC_0_7_3:1.15 OSSP_RC_0_7_2:1.14 OSSP_RC_0_7_1:1.14 OSSP_RC_ALPHA_06:1.9 OSSP_RC_EXBROKEN:1.8; locks; strict; comment @ * @; 1.15 date 2003.07.11.12.43.00; author ms; state Exp; branches; next 1.14; 1.14 date 2003.07.07.13.30.51; author ms; state Exp; branches; next 1.13; 1.13 date 2003.07.07.12.55.42; author ms; state Exp; branches; next 1.12; 1.12 date 2003.07.02.15.31.38; author ms; state Exp; branches; next 1.11; 1.11 date 2003.07.02.14.45.25; author ms; state Exp; branches; next 1.10; 1.10 date 2003.06.23.16.09.47; author ms; state Exp; branches; next 1.9; 1.9 date 2003.05.27.14.51.38; author ms; state Exp; branches; next 1.8; 1.8 date 2003.05.20.17.14.17; author ms; state Exp; branches; next 1.7; 1.7 date 2003.05.15.22.22.30; author ms; state Exp; branches; next 1.6; 1.6 date 2003.05.15.12.49.11; author ms; state Exp; branches; next 1.5; 1.5 date 2002.07.29.15.07.01; author ms; state Exp; branches; next 1.4; 1.4 date 2002.05.23.18.03.20; author ms; state Exp; branches; next 1.3; 1.3 date 2002.03.26.17.11.06; author ms; state Exp; branches; next 1.2; 1.2 date 2002.02.13.19.19.28; author ms; state Exp; branches; next 1.1; 1.1 date 2002.02.08.18.36.40; author ms; state Exp; branches; next ; desc @@ 1.15 log @Don't initialize self after freeing, to be consistent with standard practices (caller should do this instead). @ text @/* OSSP rc - Run-Command Processor ** Copyright (c) 2002-2003 Ralf S. Engelschall ** Copyright (c) 2002-2003 Cable & Wireless Deutschland GmbH ** Copyright (c) 2002-2003 The OSSP Project ** ** This file is part of OSSP rc, a portable run-command processor ** which can be found at http://www.ossp.org/pkg/lib/rc/ ** ** Permission to use, copy, modify, and distribute this software for ** any purpose with or without fee is hereby granted, provided that ** the above copyright notice and this permission notice appear in all ** copies. ** ** THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED ** WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF ** MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ** IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR ** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF ** USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT ** OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF ** SUCH DAMAGE. ** ** rc_util.c: Run-Command Processor ISO C source file */ #include #include #include "rc.h" /* Error definitions */ #include "rc_const.h" /* String definitions */ /* Translate an error code to a string */ char *strErr(rc_return_t rv) { if (rv == RC_OK) return RC_ERRSTR_OK; else if (rv == RC_ERR_USE) return RC_ERRSTR_USE; else if (rv == RC_ERR_MEM) return RC_ERRSTR_MEM; else if (rv == RC_ERR_SYS) return RC_ERRSTR_SYS; else if (rv == RC_ERR_IO) return RC_ERRSTR_IO; else if (rv == RC_ERR_INT) return RC_ERRSTR_INT; else if (rv == RC_ERR_FNC) return RC_ERRSTR_FNC; else if (rv == RC_ERR_LOC) return RC_ERRSTR_LOC; else if (rv == RC_ERR_TMP) return RC_ERRSTR_TMP; else if (rv == RC_ERR_RCF) return RC_ERRSTR_RCF; else if (rv == RC_ERR_TRM) return RC_ERRSTR_TRM; else if (rv == RC_ERR_CFG) return RC_ERRSTR_CFG; else if (rv == RC_ERR_ROOT) return RC_ERRSTR_ROOT; else if (rv == RC_WRN_OWR) return RC_WRNSTR_OWR; else if (rv == RC_WRN_NUL) return RC_WRNSTR_NUL; else return RC_ERRSTR_UNK; } /* Vector copy constructor */ char **vectorCopy(const char **kpszVec) { int nSecs = 0; int nIndex = 0; size_t nBytes = 0; char **pszTemp = NULL; if (kpszVec) { for (nSecs = 0; kpszVec[nSecs]; nSecs++); /* Count the sections */ pszTemp = malloc(sizeof (char **) * nSecs + 1); for (nIndex = 0; kpszVec[nIndex]; nIndex++) { /* Copy loop */ nBytes = (strlen(kpszVec[nIndex]) + 1) * sizeof(char); /* for each */ pszTemp[nIndex] = malloc(nBytes); /* element */ memcpy(pszTemp[nIndex], kpszVec[nIndex], nBytes); /* in vector */ } pszTemp[nIndex] = NULL; /* Used later to find the end of the array */ return(pszTemp); /* Success */ } else RC_THROW(RC_ERR_USE); /* Incoming vector is NULL? */ return(NULL); /* Failure */ } /* Vector counter */ short vectorCount(const char **pszVec) { int i = 0; assert(pszVec); /* Check for unallocated incoming */ while (pszVec[i]) /* Loop through elements, */ i++; /* and count them here */ return(i); } /* Vector destructor */ rc_return_t vectorDel(char **pszVec) { int i; assert(pszVec); /* Check for unallocated incoming */ for (i = 0; pszVec[i]; i++) { /* Loop through elements */ free(pszVec[i]); /* of vector, deallocating */ pszVec[i] = NULL; /* along the way */ } free(pszVec); /* Free the vector itself */ return(RC_THROW(RC_OK)); } /* Section priority compare, to use with qsort(3) */ int priCompare(const void *pkv1, const void *pkv2) { int nOne = 0; int nTwo = 0; if (pkv1) { nOne = ((rc_section_t *)pkv1)->m_nPri; if (pkv2) nTwo = ((rc_section_t *)pkv2)->m_nPri; else return (-1); } else if (pkv2) return (1); else return (0); if (nOne) if (nTwo) if (*(int *)nOne > *(int *)nTwo) return (1); else if (*(int *)nOne < *(int *)nTwo) return (-1); else return (0); else return (-1); else if (nTwo) return (1); else return (0); } @ 1.14 log @More header corrections and improvements. @ text @a107 2 pszVec = NULL; @ 1.13 log @Correct and update copyrights and source headers. @ text @d1 1 a1 1 /* OSSP rc - Run-command processor d6 1 a6 1 ** This file is part of OSSP rc, a portable Run-command processor d27 1 a27 1 ** rc_util.c: Run-command processor ISO C source file @ 1.12 log @Add temporary directory option error logic. @ text @d2 3 a4 3 ** Copyright (c) 2002 Ralf S. Engelschall ** Copyright (c) 2002 Cable & Wireless Deutschland GmbH ** Copyright (c) 2002 The OSSP Project @ 1.11 log @Remember the error string for new root permissions. @ text @d47 2 a48 1 else if (rv == RC_ERR_DIR) return RC_ERRSTR_DIR; @ 1.10 log @Complete error handling method according to all defined error values. @ text @d40 15 a54 14 if (rv == RC_OK) return RC_ERRSTR_OK; else if (rv == RC_ERR_USE) return RC_ERRSTR_USE; else if (rv == RC_ERR_MEM) return RC_ERRSTR_MEM; else if (rv == RC_ERR_SYS) return RC_ERRSTR_SYS; else if (rv == RC_ERR_IO) return RC_ERRSTR_IO; else if (rv == RC_ERR_INT) return RC_ERRSTR_INT; else if (rv == RC_ERR_FNC) return RC_ERRSTR_FNC; else if (rv == RC_ERR_DIR) return RC_ERRSTR_DIR; else if (rv == RC_ERR_RCF) return RC_ERRSTR_RCF; else if (rv == RC_ERR_TRM) return RC_ERRSTR_TRM; else if (rv == RC_ERR_CFG) return RC_ERRSTR_CFG; else if (rv == RC_WRN_OWR) return RC_WRNSTR_OWR; else if (rv == RC_WRN_NUL) return RC_WRNSTR_NUL; else return RC_ERRSTR_UNK; @ 1.9 log @Fix vector copy terminate bug, and add checks to processor. @ text @d50 1 @ 1.8 log @Put priority scheduling back in, safeguard priCompare logic against invalid parameters, generally complete the print mode and exec mode processor operations for milestone one. @ text @d60 1 d68 3 a70 3 pszTemp[nIndex] = malloc(strlen(kpszVec[nIndex])); /* for each */ memcpy(pszTemp[nIndex], kpszVec[nIndex], /* element */ strlen(kpszVec[nIndex])); /* in vector */ @ 1.7 log @Implement priority scheduling with qsort(3) and priCompare(), adhere to naming standard, and bugfix. @ text @d112 14 a125 2 int nOne = ((rc_section_t *)pkv1)->m_nPri; int nTwo = ((rc_section_t *)pkv2)->m_nPri; @ 1.6 log @Add sectionCopy(), sectionDump(), and vectorCount(), and change the processor object's script vector to a section vector. @ text @d108 23 @ 1.5 log @Synchronize error and warning reporting with new return code additions. @ text @d80 12 @ 1.4 log @More flush work on analyzer. @ text @d46 6 @ 1.3 log @Vacation flush, mostly build configuration details. Its not building very clean right now. @ text @d30 3 d47 42 @ 1.2 log @Small corrections in both logic and build configuration. PR: Submitted by: Reviewed by: Approved by: Obtained from: @ text @d1 2 a2 1 /* rc - OSSP Run-command processor a4 1 ** Copyright (c) 2002 Ralf S. Engelschall d7 1 a7 1 ** which can be found at http://www.ossp.org/pkg/rc/ @ 1.1 log @Further abstraction and building in of the configuration logic. We now store configuration variables using OSSP val, also. PR: Submitted by: Reviewed by: Approved by: Obtained from: @ text @d33 1 @