home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / i / iv26_w_3.zip / EXAMPLES / DCLOCK / DCLOCK.C < prev    next >
C/C++ Source or Header  |  1992-03-27  |  4KB  |  131 lines

  1. /*
  2.  * Copyright (c) 1987, 1988, 1989 Stanford University
  3.  *
  4.  * Permission to use, copy, modify, distribute, and sell this software and its
  5.  * documentation for any purpose is hereby granted without fee, provided
  6.  * that the above copyright notice appear in all copies and that both that
  7.  * copyright notice and this permission notice appear in supporting
  8.  * documentation, and that the name of Stanford not be used in advertising or
  9.  * publicity pertaining to distribution of the software without specific,
  10.  * written prior permission.  Stanford makes no representations about
  11.  * the suitability of this software for any purpose.  It is provided "as is"
  12.  * without express or implied warranty.
  13.  *
  14.  * STANFORD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  15.  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
  16.  * IN NO EVENT SHALL STANFORD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  17.  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  18.  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  19.  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
  20.  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  21.  */
  22.  
  23. /*
  24.  * dclock - digital clock
  25.  */
  26.  
  27. #include "dclock.h"
  28. #include "dface.h"
  29. #include <stdio.h>
  30. #include <stdlib.h>
  31.  
  32. DFace *TheClock;
  33. World *world;
  34.  
  35. static void DoArgs(int argc, char *argv[]);
  36.  
  37. int IVMain (int argc, char** argv) {
  38.     world = new World("dclock", argc, argv);
  39.     DoArgs(argc, argv);
  40.     InitData();
  41.     switch (CreateMode) {
  42.     case SWEPT:
  43.         TheClock = new DFace(
  44.         ShowDate, ShowBorder, ShowTime, TimeMode
  45.         );
  46.         world->InsertApplication(TheClock);
  47.         break;
  48.     case PLACED:
  49.         TheClock = new DFace(
  50.         ShowDate, ShowBorder, ShowTime, TimeMode, Width, Height
  51.         );
  52.         world->InsertApplication(TheClock);
  53.         break;
  54.     case DEFINED:
  55.         TheClock = new DFace(
  56.         ShowDate, ShowBorder, ShowTime, TimeMode, Width, Height
  57.         );
  58.         world->InsertApplication(TheClock, XPos, YPos);
  59.         break;
  60.     }
  61.     TheClock->Run();
  62.     return 0;
  63. }
  64.  
  65. static void DoArgs( int argc, char * argv[] ) {
  66.     int i, j, p1, p2;
  67.     char* curarg;
  68.  
  69.     for (i = 1; i < argc; i++) {
  70.     curarg = argv[i];
  71.     if (sscanf(curarg, "size=%d,%d", &p1, &p2) == 2) {
  72.         if (CreateMode != DEFINED) {
  73.         CreateMode = PLACED;            // size specified
  74.         }
  75.         Width = p1;
  76.         Height = p2;
  77.     } else if (sscanf(curarg, "pos=%d,%d", &p1, &p2) == 2) {
  78.         CreateMode = DEFINED;            // position specified
  79.         XPos = p1;
  80.         YPos = p2;
  81.     } else if (sscanf(curarg, "-s%d", &p1) == 1) {
  82.         SlantPC = p1;
  83.     } else if (sscanf(curarg, "-t%d", &p1) == 1) {
  84.         ThickPC = p1;
  85.     } else if (sscanf(curarg, "-f%d", &p1) == 1) {
  86.         FadeRate = p1;
  87.     } else if (curarg[0] == '-') {
  88.         for (j = 1; curarg[j] != '\0'; j++) {
  89.         switch (curarg[j]) {
  90.             case 'c':
  91.             TimeMode = CIVIL;        // the default
  92.             break;
  93.             case 'm':
  94.             TimeMode = MIL;            // 24 hour
  95.             break;
  96.             case 'j':
  97.             JohnsFlag = true;        // tail on 9
  98.             break;
  99.             case 'd':
  100.             ShowDate = false;
  101.             break;
  102.             case 's':
  103.             SlantPC = 0;
  104.             break;
  105.             case 'f':
  106.             FadeRate = 0;
  107.             break;
  108.             case 'b':                //show date/time border
  109.             ShowBorder = true;
  110.             break;
  111.             case 'T':
  112.             ShowTime = false;        // date only
  113.             break;
  114.             default:
  115.             fprintf(stderr,
  116.                 "%s: unrecognized flag '%c'\n", argv[0], curarg[j]
  117.             );
  118.             break;
  119.         }
  120.         }
  121.     } else {
  122.         fprintf(stderr, "%s: unexpected argument '%s'\n", argv[0], curarg);
  123.         fprintf(stderr,
  124.         "usage: %s [-cmjidbT] [-s#] [-t#] [-f#] [pos=#,#] [size=#,#]\n",
  125.         argv[0]
  126.         );
  127.         exit(1);
  128.     }
  129.     }
  130. }
  131.