#include <stdio.h>
#include <stdlib.h>
#include <errno.h>

extern int errno;

#ifndef EOF
#define EOF -1
#endif

void main (int argc, char **argv) {
   char *filename;

   switch (argc) {
      case 0: printf ("This can't happen.\n");
              break;
      case 1: /* No arguments; use stdin. */
              {
	      int ch;
              while ((ch = getchar()) != EOF)
		 putchar (ch);
              break;
	      }
      case 2: {
              FILE *thefile;
	      int ch;

              thefile = fopen(argv[1],"r");
	      if (thefile) {
                 while ((ch = getc (thefile)) != EOF)
                    putchar (ch);

/* Alternate, more Pascal-ish version of this loop:	*/
/*               ch = getc (thefile);			*/
/*               while (! feof (thefile)) {		*/
/*                  putchar (ch);			*/
/*                  ch = getc (thefile);		*/
/*                  }					*/

                 }
              else {
                 fprintf (stderr, "Problem opening file: %d.\n",
                          errno);
                 perror (argv[0]);
                 }
              break;
	      }
      default: fprintf (stderr,"Too many args.\n");
      }
   }

