home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The CDPD Public Domain Collection for CDTV 4
/
CDPD_IV.bin
/
networking
/
uucp
/
amigauucpsrc
/
dnews
/
subs.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-06-29
|
2KB
|
133 lines
/*
* SUBS.C
*/
#include <exec/types.h>
#include "defs.h"
#include <libraries/dos.h>
#include <fcntl.h>
Prototype void FindUser(char *, int);
Prototype void ScanNewsDirs(void (*)(), long);
Prototype char *FindField(FILE *, char *);
Prototype int FileExists(char *);
void ScanSubDir(void (*)(), long, char *, short, char *);
typedef struct FileInfoBlock FIB;
void
FindUser(buf, bufsiz)
char *buf;
int bufsiz;
{
char *user;
user = GetUserName();
if (user == NULL) {
user = "FuBar";
printf("No UserName env: var or Config var !\n");
}
strncpy(buf, user, bufsiz - 1);
buf[bufsiz] = 0;
}
void
ScanNewsDirs(vect, arg)
void (*vect)();
long arg;
{
BPTR lock;
BPTR oldLock;
__aligned FIB fib;
char *cfdir = GetConfigDir(UUNEWS);
char *tmp;
if (tmp = malloc(1024)) {
if (lock = Lock(cfdir, SHARED_LOCK)) {
oldLock = CurrentDir(lock);
if (Examine(lock, &fib)) {
while (ExNext(lock, &fib)) {
if (fib.fib_DirEntryType > 0)
ScanSubDir(vect, arg, tmp, 0, fib.fib_FileName);
}
}
CurrentDir(oldLock);
UnLock(lock);
}
}
}
void
ScanSubDir(vect, arg, buf, i, segName)
void (*vect)();
long arg;
char *buf;
short i;
char *segName;
{
BPTR lock;
BPTR oldLock;
__aligned FIB fib;
if (lock = Lock(segName, SHARED_LOCK)) {
i += sprintf(buf + i, "%s%s", ((i == 0) ? "" : "."), segName);
(*vect)(segName, buf, arg);
oldLock = CurrentDir(lock);
if (Examine(lock, &fib)) {
while (ExNext(lock, &fib)) {
if (fib.fib_DirEntryType > 0) {
ScanSubDir(vect, arg, buf, i, fib.fib_FileName);
buf[i] = 0;
}
}
}
CurrentDir(oldLock);
UnLock(lock);
}
}
char *
FindField(fi, field)
FILE *fi;
char *field;
{
short len = strlen(field);
if (fi) {
rewind(fi);
while (fgets(TmpBuf, sizeof(TmpBuf), fi) && TmpBuf[0] != '\n') {
if (strnicmp(TmpBuf, field, len) == 0) {
field = TmpBuf + len;
while (*field == ' ' || *field == 9)
++field;
for (len = strlen(field) - 1; len >= 0 && (field[len] == ' ' || field[len] == 9 || field[len] == '\n'); --len);
++len;
field[len] = 0;
return(strdup(field));
}
}
}
return(NULL);
}
int
FileExists(file)
char *file;
{
int fd;
if ((fd = open(file, O_RDONLY)) >= 0) {
close(fd);
return(1);
}
return(0);
}