--- rc_proc.c 2002/05/22 14:32:20 1.3
+++ rc_proc.c 2002/06/26 14:11:16 1.4
@@ -27,9 +27,15 @@
** rc_proc.c: Run-command processor ISO C source file
*/
-#include <stdlib.h>
+#include <stdlib.h> /* Standard system headers */
+#include <fcntl.h> /* For reading rc files */
+#include <unistd.h> /* For reading rc files */
+#include <string.h> /* For string manipulation */
-#include "rc.h" /* Public interfaces */
+/* FIXME: Remove */
+#include <sys/stat.h>
+
+#include "rc.h" /* Public interfaces */
/************************************************
@@ -41,6 +47,10 @@
rc_proc_t *pNewrc = NULL;
pNewrc = malloc(sizeof(rc_proc_t));
+ pNewrc->m_pAnal = analNew(); /* Construct a configuration analyser */
+ pNewrc->m_pScript = scriptNew(); /* Construct a run-command script */
+ analParse(pNewrc->m_pAnal); /* Preprocess the anal configuration */
+
return(pNewrc);
}
@@ -56,12 +66,89 @@
}
/************************************************
+* procPopulate(rc_proc_t *) *
+* Populate the processor with run commands *
+************************************************/
+rc_return_t procPopulate(rc_proc_t *pRc)
+{
+ int nFdrc = 0;
+ int nFdfunc = 0;
+ int nRet = 0;
+ char *szBuf = NULL;
+
+ char *szFucka = NULL;
+
+ /* FIXME: Do not hardcode location or prefix! */
+ szFucka = (char *)malloc(strlen(pRc->m_pAnal->m_szRcs) + 8);
+ strcpy(szFucka, "rcfiles/rc.");
+ strcat(szFucka, pRc->m_pAnal->m_szRcs);
+
+ szBuf = (char *)calloc(0, RC_READ_BUFSIZE);
+
+ /* Open the rc file unconditionally */
+ if ((nFdrc = open(szFucka, O_RDONLY)) == -1) {
+/* RC_THROW(RC_ERR_IO);*/
+ TRACE("Problem with procPopulate open(2)");
+ }
+
+ /* Open the func file if it belongs to the configuration */
+ if (pRc->m_pAnal->m_szFuncs) {
+ if ((nFdfunc = open(pRc->m_pAnal->m_szFuncs, O_RDONLY)) == -1) {
+ /* RC_THROW(RC_ERR_IO);*/
+ TRACE("Problem with procPopulate open(2)");
+ }
+ /* Read data from the func file */
+ while ((nRet = read(nFdfunc, szBuf, RC_READ_BUFSIZE)) > 0)
+ scriptAppend(pRc->m_pScript, szBuf, nRet);
+ if (nRet == -1) /* Handle read errors */
+ TRACE("Problem with procPopulate read(2)");
+ /* RC_THROW(RC_ERR_IO);*/
+ }
+
+ /* Read data from the rc file */
+ while ((nRet = read(nFdrc, szBuf, RC_READ_BUFSIZE)) > 0)
+ scriptAppend(pRc->m_pScript, szBuf, nRet);
+ if (nRet == -1) /* Handle read errors */
+ TRACE("Problem with procPopulate read(2)");
+/* RC_THROW(RC_ERR_IO);*/
+
+ /* Filehandle cleanups */
+ close(nFdrc);
+ close(nFdfunc);
+
+ /* Memory cleanups */
+ if (szFucka) {
+ free(szFucka);
+ szFucka = NULL;
+ }
+ if (szBuf) {
+ free(szBuf);
+ szBuf = NULL;
+ }
+
+ return(RC_THROW(RC_OK));
+}
+
+/************************************************
+* procRun(rc_proc_t *) *
+* Run the processed run-command script *
+************************************************/
+rc_return_t procRun(rc_proc_t *pRc)
+{
+ scriptDump(pRc->m_pScript);
+
+ return(RC_THROW(RC_OK));
+}
+
+/************************************************
* procDelete(rc_proc_t *) *
* Destruct a processor *
************************************************/
rc_return_t procDelete(rc_proc_t *pRc)
{
- free(pRc);
+ scriptDelete(pRc->m_pScript); /* Destroy the script */
+ analDelete(pRc->m_pAnal); /* Destroy the analyser */
+ free(pRc); /* Free the processor itself */
return(RC_THROW(RC_OK));
}
|