Пример #1
0
int main(int argc, char* argv[]) {
	time_t mtime, ttime; 
	char *newsfile;
	int sleeptime;

	if (argc != 3)
		fprintf(stderr, "Usage: %s newsgroup sleeptime\n", argv[0]);

	newsfile = convertnews(argv[1]);
	sleeptime = atoi(argv[2]);

	if ((mtime = lastmod(newsfile)) == -1) {
		fprintf(stderr, "Couldn't access newsgroup file\n");
		return 1;
	}
	printf("%s last updated %s", argv[1], ctime(&mtime)); /* ctime appends \n */
	
	while ( FOREVER ) {
		sleep(sleeptime);
		if ((ttime = lastmod(newsfile)) == -1) {
			fprintf(stderr, "Couldn't access newsgroup file: %s\n", newsfile);
			return 1;
		}
		if ( difftime(ttime,  mtime) > 0 ) {
			mtime = ttime;
			printf("%s updated %s", argv[1], ctime(&mtime));
		} 
	}
	return 0;
}
Пример #2
0
int 
main(int argc, char **argv)
{
	void   *lib = 0;
	void    (*func) (int argc, char **argv);
	time_t  mod = 0;

	mod = lastmod(THELIB);
	if (mod > 0) {
		_log("Last modified: %s", ctime(&mod));
	}
	_log("Opening " THELIB);
	/* initial dl opening */
	lib = dlopen(THELIB, RTLD_LAZY);
	if (lib == NULL) {
		char *err;
		err=dlerror();
		if(err) {
			_log("Error opening %s, reason unknown.", THELIB);
		} else {
			_log("Error opening %s:  %s", THELIB, err);
		}
	}
	for (;;) {
		/* If it's been modified since we last recorded mod date... */
		if (lastmod(THELIB) > mod) {
			_log("Last modified: %s", ctime(&mod));
			/* record a new mod date */
			mod = lastmod(THELIB);
			/* close the library */
			if(lib)
				dlclose(lib);
			/* open a new one. we don't care if it succeeds after start */
			lib = dlopen(THELIB, RTLD_LAZY);
		}
		func = getfunc(lib);
		if (func != NULL) {
			func(argc, argv);
		} else {
			/* Emergency function, just read and report an error */
			emergency();
		}
	}

	/* close it, we're leaving now, not that any of this will ever happen */
	/* NOTREACHED */
	if(lib)
		dlclose(lib);
	return(0);
}
Пример #3
0
extern OBJREC *			/* find an object's actual material */
findmaterial(register OBJREC *o)
{
	while (!ismaterial(o->otype)) {
		if (o->otype == MOD_ALIAS && o->oargs.nsargs) {
			OBJECT  aobj;
			OBJREC  *ao;
			aobj = lastmod(objndx(o), o->oargs.sarg[0]);
			if (aobj < 0)
				objerror(o, USER, "bad reference");
			ao = objptr(aobj);
			if (ismaterial(ao->otype))
				return(ao);
			if (ao->otype == MOD_ALIAS) {
				o = ao;
				continue;
			}
		}
		if (o->omod == OVOID)
			return(NULL);
		o = objptr(o->omod);
	}
	return(o);		/* mixtures will return NULL */
}
Пример #4
0
OBJREC *	
findmaterial(OBJREC *o)			/* find an object's actual material */
{
	while (!ismaterial(o->otype)) {
		if (o->otype == MOD_ALIAS && o->oargs.nsargs) {
			OBJECT  aobj;
			OBJREC  *ao;
			aobj = lastmod(objndx(o), o->oargs.sarg[0]);
			if (aobj < 0)
				objerror(o, USER, "bad reference");
					/* recursive check on alias branch */
			if ((ao = findmaterial(objptr(aobj))) != NULL)
				return(ao);
		}
		if (o->omod == OVOID) {
					/* void mixture de facto material? */
			if (ismixture(o->otype))
				break;
			return(NULL);	/* else no material found */
		}
		o = objptr(o->omod);
	}
	return(o);
}