- if (getwordsfrom == FROM_FILE && !filename)
- {
- fprintf (stderr, "%s: no file specified.\n", progname);
- exit (1);
- }
-
- words = get_words();
-}
-
-static int first_time = 1;
-
-static char *
-get_words()
-{
- FILE *pp;
- static char buf[BUFSIZ];
- register char *p = buf;
-
- buf[0] = '\0';
-
- switch (getwordsfrom)
- {
- case FROM_PROGRAM:
- if ((pp = popen(program, "r")))
- {
- while (fgets(p, sizeof(buf) - strlen(buf), pp))
- {
- if (strlen(buf) + 1 < sizeof(buf))
- p = buf + strlen(buf);
- else
- break;
- }
- (void) pclose(pp);
- if (! buf[0])
- sprintf (buf, "\"%s\" produced no output!", orig_program);
- else if (!first_time &&
- (strstr (buf, ": not found") ||
- strstr (buf, ": Not found")))
- switch (random () % 20)
- {
- case 1: strcat (buf, "( Get with the program, bub. )\n");
- break;
- case 2: strcat (buf,
- "( I blow my nose at you, you silly person! ) \n"); break;
- case 3: strcat (buf,
- "\nThe resource you want to\nset is `noseguy.program'\n");
- break;
- case 4:
- strcat(buf,"\nHelp!! Help!!\nAAAAAAGGGGHHH!! \n\n"); break;
- case 5: strcpy (buf, "You have new mail.\n"); break;
- case 6:
- strcat(buf,"( Hello? Are you paying attention? )\n");break;
- case 7:
- strcat (buf, "sh: what kind of fool do you take me for? \n");
- break;
- }
- first_time = 0;
- p = buf;
- }
- else
- {
- perror(program);
- p = def_words;
- }
- break;
- case FROM_FILE:
- if ((pp = fopen(filename, "r")))
- {
- while (fgets(p, sizeof(buf) - strlen(buf), pp))
- {
- if (strlen(buf) + 1 < sizeof(buf))
- p = buf + strlen(buf);
- else
- break;
- }
- (void) fclose(pp);
- if (! buf[0])
- sprintf (buf, "file \"%s\" is empty!", filename);
- p = buf;
- }
- else
- {
- sprintf (buf, "couldn't read file \"%s\"!", filename);
- p = buf;
- }
- break;
- case FROM_RESRC:
- p = text;
- break;
- default:
- p = def_words;
- break;
- }
-
- if (!p || *p == '\0')
- p = def_words;
- return p;