home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <rpcsvc/ypclnt.h>
-
- #define MAXLEN 4096
- #define randint(maxval) ((random() % (maxval)) + 1)
-
- char dom_name[BUFSIZ];
-
- main()
- {
- char *quotebuf;
- int quotelen;
- char *maxbuf;
- int maxlen;
- int maxnum = 0;
- int quotenum = 0;
- char *c;
- char *index();
-
- srandom(getpid()); /* initialize random numbers */
-
- /* who are we? */
- if (getdomainname(dom_name, BUFSIZ)) {
- fprintf(stderr, "No domainname set\n");
- exit(1);
- }
-
- /* Get the highest quote in the system */
- get_match("MAX", &maxbuf, &maxlen);
- maxnum = atoi(maxbuf);
-
- /* Generate a random number between 1 and maxnum */
- quotenum = randint(maxnum);
- if (quotenum < 0 || quotenum > maxnum) {
- fprintf(stderr, "Illegal randint value!\n");
- exit(1);
- }
-
- /* now grab that quote */
- sprintf(maxbuf,"%d",quotenum);
- get_match(maxbuf, "ebuf, "elen);
-
- /* turn all ^A characters to newlines.
- * turn all ^B characters to tabs.
- * needed to allow proper insertion into a yp database, since makedbm
- * uses both as delimiters.
- */
- while ((c = index(quotebuf,'\001')))
- *c = '\n';
-
- while ((c = index(quotebuf,'\002')))
- *c = '\t';
-
- /* print it out */
- printf("%s",quotebuf);
- }
-
- /* get the largest quote from key MAX */
-
- get_match(key, retval, retlen)
- char *key;
- char **retval;
- int *retlen;
- {
-
- if (yp_match(dom_name, "quotes", key, strlen(key), retval, retlen)) {
- fprintf(stderr, "error in ypmatch\n");
- exit(1);
- }
- }
-