Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site utcsri.UUCP Path: utzoo!utcsri!james From: james@utcsri.UUCP (James P. Rowell) Newsgroups: net.sources Subject: Extraordinarily simple reminder program. Message-ID: <4346@utcsri.UUCP> Date: Wed, 11-Mar-87 01:57:11 EST Article-I.D.: utcsri.4346 Posted: Wed Mar 11 01:57:11 1987 Date-Received: Wed, 11-Mar-87 03:38:21 EST Reply-To: james@utcsri.UUCP (James P. Rowell) Distribution: world Organization: CSRI, University of Toronto Lines: 118 Keywords: egg yourself on Now many of you may have written a program that does this, but since this is so simple and for me very useful, I decided to share it with you. Just cut and compile. /* * This program basically just echos the command line into a file * called .egg in your home dir. It is to leave yourself messages. * 'egg' by itself cats the file $HOME/.egg */ #include #include #include #include #define TRUE 1 #define FALSE 0 #define HOMESIZE 256 struct stat statbuf; char *progname; main (argc, argv) int argc; char *argv[]; { FILE *fp, *efopen (); char *home, *getenv(), eggfile[HOMESIZE + 6]; char *ctime (); char *timezone (); long time (); struct tm *localtime(); struct timeval tv; struct timezone tz; long clock; char date[26]; int c; progname = argv[0]; if (!(home = getenv("HOME"))) { fprintf (stderr, "%s: HOME: environment variable not set\n", progname); exit (2); } else if (strlen(home) > HOMESIZE) { fprintf (stderr, "%s: HOME: environment variable too long\n", progname); exit (3); } strcpy (eggfile, home); strcat (eggfile, "/.egg"); if (argc == 1) { fp = efopen(eggfile, "r"); if (fstat(fileno(fp), &statbuf) != 0) { perror(progname); exit (4); } if ((statbuf.st_mode & S_IFMT)==S_IFDIR) { (void) fprintf(stderr, "%s: %s is a directory.\n", progname, eggfile); exit (5); } while ((c = getc (fp)) != EOF) putchar (c); } else { fp = efopen(eggfile, "a"); if (fstat(fileno(fp), &statbuf) != 0) { perror(progname); exit (6); } if ((statbuf.st_mode & S_IFMT)==S_IFDIR) { (void) fprintf(stderr, "%s: %s is a directory.\n", progname, eggfile); exit (7); } time (&clock); gettimeofday (&tv, &tz); tv.tv_sec += tz.tz_minuteswest*60L; strcpy (date, ctime (&clock)); date[10] = date[13] = date[19] = '\0'; fprintf (fp, "%s:", date); for (;argc>1; argc--) { fprintf (fp, " %s", *(++argv)); } fprintf (fp, "\n"); } } /* * fopen file, die if can't. */ FILE *efopen (file, mode) char *file, *mode; { FILE *fp, *fopen(); char s[2*HOMESIZE+9]; if ((fp = fopen (file, mode)) != NULL) return (fp); strcpy (s, progname); strcat (s, ": "); strcat (s, file); perror (s); exit (1); } -- James Philip Rowell University of Toronto UUCP: {ihnp4 utzoo decwrl uw-beaver}!utcsri!james ARPA: james@csri.toronto.edu CSNET: james@toronto