1: /* Copyright (c) 1979 Regents of the University of California */
   2: /*
   3:  * Print out a meaningful phrase depending on the time of
   4:  * day.
   5:  *
   6:  * Author: Robert Toxen (UCB) 7/10/78
   7:  */
   8: 
   9: /*
  10:  * The following structure parameterizes the
  11:  * whole she-bang.
  12:  */
  13: 
  14: struct daytime {
  15:     int d_start;        /* starting hour */
  16:     char    *d_mesg;        /* applicable message */
  17: } daytime[] {
  18:     0,  "It's late",
  19:     4,  "You really should be home in bed",
  20:     7,  "Good morning",
  21:     12, "Good afternoon",
  22:     18, "Good evening",
  23:     22, "Good night",
  24:     50, "panic: time of day bug",
  25:     -1, 0
  26: };
  27: 
  28: /*
  29:  * The special case structure:  if the hour is exactly
  30:  * one of these, print the corresponding message.
  31:  */
  32: 
  33: struct special {
  34:     int s_time;         /* Applicable hour */
  35:     char    *s_mesg;        /* Corresponding mesg */
  36: } special[] {
  37:     12, "Had lunch yet?",
  38:     17, "You should be eating dinner",
  39:     0,  "It's past midnight",
  40:     -1, 0
  41: };
  42: 
  43: main(argc, argv)
  44:     char **argv;
  45: {
  46:     register struct daytime *dp;
  47:     register struct special *sp;
  48:     register int hour;
  49:     int tv[2], *t;
  50: 
  51:     if (argc > 1)
  52:         hour = atoi(argv[1]);
  53:     else {
  54:         time(tv);
  55:         t = localtime(tv);
  56:         hour = t[2];
  57:     }
  58:     for (sp = &special[0]; sp->s_time != -1; sp++)
  59:         if (sp->s_time == hour) {
  60:             printf("%s\n", sp->s_mesg);
  61:             exit(1);
  62:         }
  63:     for (dp = &daytime[0]; dp->d_start != -1; dp++)
  64:         if (hour < (dp+1)->d_start) {
  65:             printf("%s\n", dp->d_mesg);
  66:             exit(0);
  67:         }
  68: 
  69:     /*
  70: 	 * Why didn't this thing print anything !?!
  71: 	 */
  72: 
  73:     printf("No message for time!?!\n");
  74:     abort();
  75: }

Defined functions

main defined in line 43; never used

Defined variables

daytime defined in line 17; used 1 times
  • in line 63
special defined in line 36; used 1 times
  • in line 58

Defined struct's

daytime defined in line 14; used 2 times
  • in line 46(2)
special defined in line 33; used 2 times
  • in line 47(2)
Last modified: 1979-05-09
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 745
Valid CSS Valid XHTML 1.0 Strict