home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / osr5 / sco / scripts / segclock < prev    next >
Encoding:
Text File  |  1997-08-26  |  2.8 KB  |  99 lines

  1. :
  2. # @(#) segclock.sh 2.0 92/09/15
  3. # 91/10/12 john h. dubois iii (john@armory.com)
  4. # 92/02/16 added help
  5. # 92/09/11 Rewrote & converted to gawk script
  6. # 92/09/15 Pass options to segfont.  Use default size of 4.
  7.  
  8. # Use gawk instead of awk to get strftime(), sprintf("%c",n), and /dev/std...
  9. gawk '
  10. BEGIN {
  11.     sleep = 1
  12.     size = 4
  13.     if (ARGC > 1) {
  14.     if (ARGV[ARGC - 1] ~ "^[0-9]+$") {
  15.         sleep = ARGV[1]
  16.         if (!sleep) {
  17.         print "Bad sleep time.  Use +h for help." > "/dev/stderr"
  18.         exit 1
  19.         }
  20.         ARGC--
  21.     }
  22.     for (i = 1; i < ARGC; i++) {
  23.         Opt = ARGV[i]
  24.         if (Opt ~ "^[-+]")
  25.         Opt = substr(Opt,2)
  26.         if (Opt == "r")
  27.         SegArgs = SegArgs " -r3"
  28.         else if (Opt ~ "^c.?$")
  29.         SegArgs = SegArgs " -" Opt
  30.         else if (Opt ~ "^c[0-9][0-9]+$")
  31.         SegArgs = SegArgs " -c" sprintf("%c",substr(Opt,2) + 0)
  32.         else if (Opt ~ "^s[0-9]*$")
  33.         size = substr(Opt,2)
  34.         else if (Opt == "h") {
  35.         system("sleep 1")
  36.         print \
  37. "segclock: display a clock in a 25-segment-display font.\r\n" \
  38. "Usage: segclock [cx] [r] [s<size>] [<sec>]\r\n" \
  39. "If <sec> is given, segclock updates the display every <sec> seconds.\r\n" \
  40. "If it is not, segclock updates the display every second.\r" > "/dev/stderr"
  41.         print \
  42. "Options:\r\n" \
  43. "cx sets the character that characters are constructed from to x.\r\n" \
  44. "If x is a multidigit sequence, the charcter whose ascii value is x is used."\
  45. "\r\n" \
  46. "If x is not given, each character is built from the character it represents."\
  47. "\r\n" \
  48. "r rotates the characters so that, if you upended the display,\r\n" \
  49. "they would be printed down the screen and look ugly.\r\n" \
  50. "s<size> sets the font segment size to <size>.  The default is 4.\r\n" \
  51. "More than that will not work with an 80-column display." > "/dev/stderr"
  52.         exit 0
  53.         }
  54.         else {
  55.         system("sleep 1")
  56.         print Opt ": bad option." > "/dev/stderr"
  57.         exit 1
  58.         }
  59.     }
  60.     }
  61.     Dimension = size * 2 + 3
  62.     Cmd = "echo \"0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n:\" | segfont -kew1000 -s" \
  63.     size SegArgs "; :"
  64.     for (n = 0; n <= 9; n++) {
  65.     for (line = 1; line <= Dimension; line++)
  66.         Cmd | getline Chars[n,line]
  67.     Cmd | getline blank
  68.     }
  69.     for (line = 1; line <= Dimension; line++) {
  70.     Cmd | getline ColonLine
  71.     gsub(" +"," ",ColonLine)
  72.     Chars[":",line] = ColonLine
  73.     }
  74.     close(Cmd)
  75.     Cmd = \
  76.     sprintf("(timer %d || while :; do echo ""; sleep %d; done) 2>/dev/null",
  77.     sleep * 1000,sleep)
  78.     while (1) {
  79.     Time = strftime("%T")
  80.     for (Line = 1; Line <= Dimension; Line++) {
  81.         for (i = 1; i < 8; i++) {
  82.         if (i == 3 || i == 6)
  83.             Dim = 3
  84.         else
  85.             Dim = Dimension
  86.         printf "%-" Dim "s ",
  87.         Chars[substr(Time,i,1),Line] > "/dev/stdout"
  88.         }
  89.         printf "%-" Dim "s",
  90.         Chars[substr(Time,i,1),Line] > "/dev/stdout"
  91.         print "" > "/dev/stdout"
  92.     }
  93.     printf "\014" > "/dev/stdout"
  94.     close("/dev/stdout")
  95.     Cmd | getline
  96.     }
  97. }
  98. ' "$@" | scrnopt
  99.