home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gold Fish 2
/
goldfish_vol2_cd1.bin
/
files
/
comm
/
misc
/
cyberpager
/
source
/
spooler
/
dogroup.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-02-07
|
3KB
|
135 lines
#include "spooler.h"
#include "/include/memory.h"
#define TEMPLATE "TARGETS/M,GROUP/K"
enum templateArgs {
ARG_TARGET,
ARG_GROUP,
ARG_sizeof
};
int DoGroup(STRPTR target, STRPTR pageText)
{
ULONG line = 0;
BPTR fh;
STRPTR ptr;
STRPTR *targets;
BOOL foundGroup, leave;
LONG groupCount;
int result = 0;
struct RDArgs *ArgsPtr, *MyArgs;
char *ArgArray[ARG_sizeof];
foundGroup = FALSE;
groupCount = 0;
if (fh = Open("pager:groups", MODE_OLDFILE)) {
/* loop reading lines looking for a group that matches */
leave = FALSE;
while (!result && !leave && FGets(fh, inputBuffer, sizeof(inputBuffer) - 1)) {
line++;
/*
* check to make sure the line isn't all blank
*/
ptr = inputBuffer;
while (isspace(*ptr))
ptr++;
if (!*ptr)
continue;
/*
* check for comment character at beginning of line
*/
if (*ptr == ';')
continue;
/* setup to call ReadArgs() to parse the line */
if (MyArgs = (struct RDArgs *)AllocDosObject(DOS_RDARGS, TAG_DONE)) {
MyArgs->RDA_Flags |= RDAF_NOPROMPT;
MyArgs->RDA_Source.CS_Buffer = inputBuffer;
MyArgs->RDA_Source.CS_Length = strlen(inputBuffer);
MyArgs->RDA_Source.CS_CurChr = 0L;
memset((char *)ArgArray, 0, sizeof(ArgArray));
if (ArgsPtr = ReadArgs(TEMPLATE, (LONG *)&ArgArray, MyArgs)) {
/*
* if we are inside the group we are
* looking for and find a line with a
* new GROUP entry then we know we
* are at the end of the list and
* should return. otherwise we need
* to check if this is the group we
* are looking for.
*/
if (ArgArray[ARG_GROUP]) {
if (foundGroup)
leave = TRUE;
else if (stricmp(target, ArgArray[ARG_GROUP]) == 0)
foundGroup = TRUE;
}
if (!leave && foundGroup && ArgArray[ARG_TARGET]) {
targets = (STRPTR *)ArgArray[ARG_TARGET];
while (*targets && !result)
if (!(result = DoDest(*targets++, pageText)))
groupCount++;
}
FreeArgs(ArgsPtr);
}
else {
Fault(IoErr(), NULL, inputBuffer, sizeof(inputBuffer) - 1);
ErrorMsg("Error in groups file - line %ld: %s", line, inputBuffer);
ULog(ph, -1, "Error in groups file - line %ld: %s", line, inputBuffer);
result = 15;
}
FreeDosObject(DOS_RDARGS, MyArgs);
}
else {
ErrorMsg("out of memory!");
result = 15;
}
}
Close(fh);
}
else {
if (IoErr() != ERROR_OBJECT_NOT_FOUND) {
ErrorMsg("Error trying to open groups file.");
ULog(ph, -1, "Error trying to open groups file.");
}
}
if (!result)
if (foundGroup) {
if (groupCount == 0) {
ErrorMsg("warning - no members in group \"%s\"", target);
ULog(ph, 0, "warning - no members in group \"%s\"", target);
}
}
else {
/*
* if the target doesn't exist as a group entry then
* call DoDest() on it to process it as an
* alias/non-alias
*/
result = DoDest(target, pageText);
}
return result;
}