      INTEGER I,J,CLOCK
      INTEGER CTOI,PARSTM,EQUAL,EQUIS,GETARG
      INTEGER * 4 VALUE,NOW,THEN
      INTEGER * 4 TIMEO0,CURTI0,GOAL
      INTEGER HRS,MIN,SEC
      INTEGER ARG(128)
      INTEGER AAAAA0(3)
      INTEGER AAAAB0(3)
      INTEGER AAAAC0(8)
      INTEGER AAAAD0(8)
      INTEGER AAAAE0(6)
      INTEGER AAAAF0(37)
      INTEGER AAAAG0(15)
      DATA AAAAA0/225,244,0/
      DATA AAAAB0/233,238,0/
      DATA AAAAC0/243,229,227,239,238,228,243,0/
      DATA AAAAD0/237,233,238,245,244,229,243,0/
      DATA AAAAE0/232,239,245,242,243,0/
      DATA AAAAF0/193,236,225,242,237,160,243,229,244,160,230,239,242,16
     *0,170,178,172,172,176,233,186,170,178,172,172,176,233,186,170,178,
     *172,172,176,233,170,238,0/
      DATA AAAAG0/160,195,245,242,242,229,238,244,160,244,233,237,229,16
     *0,0/
      I=1
      IF((GETARG(I,ARG,128).NE.-1))GOTO 10000
        VALUE=0
        GOTO 10001
10000   IF((EQUAL(ARG,AAAAA0).NE.1))GOTO 10002
          I=I+(1)
          J=1
          IF((GETARG(I,ARG,128).EQ.-1))GOTO 10004
          IF((PARSTM(ARG,J,THEN).EQ.-3))GOTO 10004
          GOTO 10003
10004       CALL USAGE
10003     NOW=TIMEO0(NOW)
          VALUE=THEN-NOW
          IF((VALUE.GE.0))GOTO 10005
            VALUE=VALUE+(86400)
10005     GOTO 10006
10002     IF((EQUAL(ARG,AAAAB0).NE.1))GOTO 10007
            I=I+(1)
            IF((GETARG(I,ARG,128).NE.-1))GOTO 10008
              CALL USAGE
10008     CONTINUE
10007     J=1
          VALUE=INTL(CTOI(ARG,J))
          IF((J.NE.1))GOTO 10009
            CALL USAGE
10009     GOTO 10010
10011     GOTO 10012
10013       I=I+(1)
            J=1
          GOTO 10012
10012       GOTO 10014
10015       GOTO 10016
10017         VALUE=VALUE*(60)
            GOTO 10016
10018         VALUE=VALUE*(3600)
            GOTO 10016
10014       IF((EQUIS(ARG(J),AAAAC0).NE.0))GOTO 10015
            IF((EQUIS(ARG(J),AAAAD0).NE.0))GOTO 10017
            IF((EQUIS(ARG(J),AAAAE0).NE.0))GOTO 10018
              CALL USAGE
10016     GOTO 10019
10010     IF((ARG(J).NE.0))GOTO 10011
          IF((GETARG(I+1,ARG,128).NE.-1))GOTO 10013
10019   CONTINUE
10006 CONTINUE
10001 IF((GETARG(I+1,ARG,1).EQ.-1))GOTO 10020
        CALL USAGE
10020 CALL BREAK$(1)
      CURTI0=TIMEO0(VALUE)
      GOAL=CURTI0+VALUE
      IF((GOAL.LT.86400))GOTO 10021
        GOAL=GOAL-(86400)
10021 HRS=GOAL/3600
      MIN=MOD((GOAL/60),60)
      SEC=GOAL-HRS*3600-MIN*60
      CALL PRINT(-15,AAAAF0,HRS,MIN,SEC)
      CALL PRINT(-15,AAAAG0)
      CALL CLOCK(VALUE)
      CALL BREAK$(0)
      CALL SWT
      END
      SUBROUTINE USAGE
      CALL ERROR('Usage: alarm ([in] <value> [<units>] | at <time>).')
      END
      INTEGER * 4 FUNCTION TIMEO0(TIME)
      INTEGER * 4 TIME
      INTEGER TD(5)
      CALL TIMDAT(TD,5)
      TIMEO0=INTL(TD(4))*INTL(60)+INTL(TD(5))
      RETURN
      END
      SUBROUTINE CLOCK(SECON0)
      INTEGER * 4 SECON0
      LOGICAL FLAG
      LOGICAL TQUIT$
      INTEGER TIME(9),PREV
      INTEGER BACKUP(9)
      INTEGER CHECK,ALARM
      INTEGER * 4 GOAL,CURTI0,TIMEO0
      DATA BACKUP/8*136,0/
      PREV=160
      CHECK=1
      ALARM=0
      CURTI0=TIMEO0(TIME)
      GOAL=CURTI0+SECON0
      IF((GOAL.LE.86400))GOTO 10022
        GOAL=GOAL-(86400)
        CHECK=0
10022 CONTINUE
10023   CONTINUE
10024     CALL DATE(2,TIME)
          IF((TIME(8).EQ.PREV))GOTO 10025
            GOTO 10026
10025     CALL SLEEP$(INTL(100))
        GOTO 10024
10026   PREV=TIME(8)
        CALL PUTLIN(TIME,-15)
        IF((ALARM.NE.1))GOTO 10027
          CALL T1OU(135)
10027   IF((.NOT.TQUIT$(FLAG)))GOTO 10028
          GOTO 10029
10028   IF((ALARM.NE.0))GOTO 10030
          CURTI0=TIMEO0(TIME)
          IF((CHECK.NE.0))GOTO 10031
          IF((CURTI0.GE.GOAL))GOTO 10031
            CHECK=1
10031     IF((CHECK.NE.1))GOTO 10032
          IF((CURTI0.LT.GOAL))GOTO 10032
            ALARM=1
10032   CONTINUE
10030   CALL SLEEP$(INTL(900))
        CALL PUTLIN(BACKUP,-15)
      GOTO 10023
10029 CALL T1OU(138)
      RETURN
      END
      INTEGER FUNCTION EQUIS(S1,S2)
      INTEGER S1(1),S2(1)
      INTEGER I
      I=1
      GOTO 10035
10033 I=I+(1)
10035 IF((S1(I).EQ.0))GOTO 10034
        IF((S1(I).EQ.S2(I)))GOTO 10036
          EQUIS=0
          RETURN
10036 GOTO 10033
10034 EQUIS=1
      RETURN
      END
C ---- Long Name Map ----
C timeofday                      timeo0
C seconds                        secon0
C curtime                        curti0