home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD2.bin / bbs / dev / tbsource.lha / TBSource / Logger / UpTime.S.BAcKuP < prev    next >
Text File  |  1993-12-21  |  7KB  |  373 lines

  1. *************************************************
  2. *                        *
  3. *         (C)opyright 1992        *
  4. *                        *
  5. *        by  Tomi Blinnikka        *
  6. *                        *
  7. *    Don´t try to understand the code    *
  8. *                        *
  9. * Version 0.01    05/07/1992            *
  10. *                        *
  11. * BUGS:    UpDays should've been long not word    *
  12. *                        *
  13. * Version 1.00    10/08/1992            *
  14. *                        *
  15. * BUGS:    Gave things like '0 day'        *
  16. *                        *
  17. * Version 1.01    13/08/1992            *
  18. *                        *
  19. * Version 1.02    22/08/1992            *
  20. *                        *
  21. *************************************************
  22.  
  23.     INCLUDE    "JMPLibs.i"
  24.     INCLUDE    "exec/types.i"
  25.     INCLUDE    "libraries/dos.i"
  26.     INCLUDE    "libraries/dosextens.i"
  27.  
  28.     INCLUDE    "XREF:2.0.xref"
  29.     INCLUDE    "XREF:exec.xref"
  30.     INCLUDE    "XREF:dos.xref"
  31.  
  32.         section    UpTime,CODE
  33.  
  34.         move.l    a0,a4
  35.         clr.b    -1(a0,d0.l)
  36.         openlib    Dos,ShutDown_Out
  37.  
  38.         bsr    GetSysTime
  39.         bsr    CheckUpTime
  40.  
  41.         cmp.b    #'?',(a4)
  42.         beq    CmdLineHelp
  43.         cmp.w    #'-?',(a4)
  44.         beq    CmdLineHelp
  45.         cmp.w    #'-h',(a4)
  46.         beq    CmdLineHelp
  47.         cmp.w    #'-i',(a4)
  48.         bne    Skip1
  49.         move.b    #1,Action
  50.         add.l    #2,a4
  51. Skip1:        cmp.w    #'-o',(a4)
  52.         bne    Skip2
  53.         move.b    #2,Action
  54.         add.l    #2,a4
  55.  
  56. Skip2:        tst.b    Action
  57.         beq    Information
  58.  
  59. Skip2.1:    cmp.b    #' ',(a4)
  60.         bne    Skip3
  61.         add.l    #1,a4
  62.         bra    Skip2.1
  63. Skip3:        cmp.b    #'c',(a4)
  64.         bne    Skip4
  65.         move.b    #'c',CurrentTTY
  66.         add.l    #1,a4            ;skip 'c'
  67.         bra    Skip5
  68. Skip4:        cmp.b    #'0',(a4)
  69.         bcs    CmdLineHelp
  70.         cmp.b    #'9',(a4)
  71.         bhi    CmdLineHelp
  72.         move.b    (a4),CurrentTTY
  73.         add.l    #1,a4
  74. Skip5:        lea.l    TTYUser,a0
  75.         move.l    a0,a1
  76.         add.l    #20,a1
  77.         cmp.b    #' ',(a4)
  78.         bne    Skip6
  79.         add.l    #1,a4
  80.         bra    Skip5
  81. Skip6:        cmp.b    #'A',(a4)
  82.         bcs    Skip7
  83.         cmp.b    #'z',(a4)
  84.         bhi    Skip7
  85.         move.b    (a4)+,(a0)+
  86.         cmp.l    a0,a1
  87.         bne    Skip6
  88.  
  89. Skip7:        clr.b    (a0)+
  90.         tst.b    TTYUser
  91.         bne    Skip8
  92.         move.l    #'root',TTYUser
  93.         move.b    #$00,TTYUser+4
  94.  
  95. Skip8:        cmp.b    #1,Action
  96.         beq    Login
  97.         cmp.b    #2,Action
  98.         beq    Logout
  99.         bra    ShutDown
  100.  
  101. ;Get system time
  102. ;Uptime equals (System time - NUT_timeval)
  103. ;Try to read ENV:NUT_login + ENV:NUT_TTYX
  104. ;Loop 0 - 9
  105. ;try reading ENV:UT_loadavg
  106.  
  107. Information:    bsr    GetUpTime
  108.         bsr    DoTTYTest
  109.         bsr    GetLoadAvg
  110.  
  111.         cmp.w    #1,Users
  112.         bne    CheckUsrNum1
  113.         lea.l    SingleString1,a0
  114.         move.l    a0,UsersString
  115. CheckUsrNum1:    bsr    Format
  116.         lea.l    UpTimeText1,a0
  117.         bsr    Printer
  118.  
  119.         lea.l    LoadAvgBuf,a0
  120.         bsr    Printer
  121.  
  122.         lea.l    EndText1,a0
  123.         bsr    Printer
  124.         bra    ShutDown
  125.  
  126. Login:        sub.l    a1,a1
  127.         lib    Exec,FindTask
  128.         move.l    d0,a0
  129.         move.l    $8c(a0),TTYTaskNum
  130.         cmp.b    #'c',CurrentTTY
  131.         bne    Login1
  132.         lea.l    UpTimeConsole,a0
  133.         bra    Login2
  134. Login1:        move.b    CurrentTTY,TTY
  135.         lea.l    UpTimeTTY,a0
  136. Login2:        move.l    a0,d1
  137.         move.l    #MODE_NEWFILE,d2
  138.         lib    Dos,Open
  139.         tst.l    d0
  140.         beq    ShutDown
  141.         move.l    d0,d4
  142.         move.l    d0,d1
  143.         lea.l    DateTime1,a0
  144.         move.l    a0,d2
  145.         move.l    #4*4+20,d3    ;info + username
  146.         lib    Dos,Write
  147.         move.l    d4,d1
  148.         lib    Dos,Close
  149.         bra    ShutDown
  150.  
  151. Logout:        cmp.b    #'c',CurrentTTY
  152.         bne    Logout1
  153.         lea.l    UpTimeConsole,a0
  154.         bra    Logout2
  155. Logout1:    move.b    CurrentTTY,TTY
  156.         lea.l    UpTimeTTY,a0
  157. Logout2:    move.l    a0,d1
  158.         lib    Dos,DeleteFile
  159.         bra    ShutDown
  160.  
  161. CheckUpTime:    lea.l    UpTimeName,a3
  162.         move.l    a3,d1
  163.         move.l    #MODE_OLDFILE,d2
  164.         lib    Dos,Open
  165.         tst.l    d0
  166.         beq    CheckUpTime2
  167.         move.l    d0,d4
  168.         move.l    d0,d1
  169.         lea.l    UpTimeBuf,a0
  170.         move.l    a0,d2
  171.         move.l    #3*4,d3
  172.         lib    Dos,Read
  173.         move.l    d4,d1
  174.         lib    Dos,Close
  175.         rts
  176. CheckUpTime2:    move.l    a3,d1
  177.         move.l    #MODE_NEWFILE,d2
  178.         lib    Dos,Open
  179.         tst.l    d0
  180.         beq    CheckUpTime3
  181.         move.l    d0,d4
  182.         move.l    d0,d1
  183.         lea.l    DateTime1,a0
  184.         move.l    a0,d2
  185.         move.l    #3*4,d3
  186.         lib    Dos,Write
  187.         move.l    d4,d1
  188.         lib    Dos,Close
  189.         move.l    DateTime1,UpTimeBuf
  190.         move.l    DateTime1+4,UpTimeBuf+4
  191.         move.l    DateTime1+4,UpTimeBuf+4
  192. CheckUpTime3:    rts
  193.  
  194. GetSysTime:    lea.l    DateTime1,a0
  195.         move.l    a0,d1
  196.         lib    Dos,DateStamp
  197.  
  198.         move.l    DateTime1+4,d0
  199.         divu.w    #60,d0
  200.         move.w    d0,Hours
  201.         swap    d0
  202.         move.w    d0,Minutes
  203.         rts
  204.  
  205. ;GetSystime has already got the current time for us
  206.  
  207. GetUpTime:    move.l    UpTimeBuf,d0
  208.         move.l    DateTime1,d1
  209.         sub.l    d0,d1
  210.         move.l    d1,UpDays
  211.         move.l    UpTimeBuf+4,d0
  212.         move.l    DateTime1+4,d1
  213.         sub.l    d0,d1
  214.         bmi    GetUpTime3
  215. GetUpTime1:    divu.w    #60,d1
  216.         move.w    d1,UpHours
  217.         swap    d1
  218.         move.w    d1,UpMinutes
  219. GetUpTime2:    rts
  220. GetUpTime3:    move.l    UpTimeBuf+4,d0
  221.         move.l    DateTime1+4,d1
  222.         add.l    #1440,d1
  223.         sub.l    d0,d1
  224.         sub.l    #1,UpDays
  225.         cmp.l    #1,UpDays
  226.         bne    GetUpTime1
  227.         lea.l    SingleString1,a0
  228.         move.l    a0,DaysString
  229.         bra    GetUpTime1
  230.  
  231. DoTTYTest:    lea.l    UpTimeConsole,a0
  232.         move.l    a0,d1
  233.         move.l    #MODE_OLDFILE,d2
  234.         lib    Dos,Open
  235.         tst.l    d0
  236.         beq    DoTTYTest1
  237.         move.l    d0,d1
  238.         add.w    #1,Users
  239.         lib    Dos,Close
  240. DoTTYTest1:    move.b    #'0',TTY
  241.  
  242. DoTTYTest2:    lea.l    UpTimeTTY,a0
  243.         move.l    a0,d1
  244.         move.l    #MODE_OLDFILE,d2
  245.         lib    Dos,Open
  246.         tst.l    d0
  247.         beq    DoTTYTest3
  248.         move.l    d0,d1
  249.         add.w    #1,Users
  250.         lib    Dos,Close
  251. DoTTYTest3:    cmp.b    #'9',TTY
  252.         beq    DoTTYTest4
  253.         add.b    #1,TTY
  254.         bra    DoTTYTest2
  255. DoTTYTest4:    rts
  256.  
  257. GetLoadAvg:    lea.l    LoadAvgName,a0
  258.         move.l    a0,d1
  259.         move.l    #MODE_OLDFILE,d2
  260.         lib    Dos,Open
  261.         tst.l    d0
  262.         bne    GetLoadAvg2
  263. GetLoadAvg1:    move.l    #'N/A,',LoadAvgBuf
  264.         move.l    #'  N/',LoadAvgBuf+4
  265.         move.l    #'A,  ',LoadAvgBuf+8
  266.         move.l    #'N/A ',LoadAvgBuf+12
  267.         move.b    #$00,LoadAvgBuf+16
  268.         rts
  269. GetLoadAvg2:    move.l    d0,d4
  270.         move.l    d0,d1
  271.         lea.l    LoadAvgBuf,a0
  272.         move.l    a0,d2
  273.         move.l    #19,d3
  274.         lib    Dos,Read
  275.  
  276.         cmp.l    #19,d0
  277.         beq    GetLoadAvg3
  278.         bsr    GetLoadAvg1
  279. GetLoadAvg3:    move.l    d4,d1
  280.         lib    Dos,Close
  281.         rts
  282.  
  283. Format:        lea.l    fstrl1,a0        ;HEX->ASCII
  284.         lea.l    Hours,a1        ;Start of information
  285.         lea.l    PutChProc,a2
  286.         lea.l    UpTimeText1,a3        ;Destination
  287.         lib    Exec,RawDoFmt
  288.         rts
  289.  
  290. ShutDown:    closlib    Dos
  291. ShutDown_Out:    move.l    #RETURN_OK,d0
  292.         rts
  293.  
  294. CmdLineHelp:    lea.l    UsageText1,a0
  295.         bsr    Printer    
  296.         bra    ShutDown
  297.  
  298. Printer:    printa    a0
  299.         rts
  300.  
  301. PutChProc:    tst.b    d0
  302.         beq    PutChProc_OUT
  303.         move.b    d0,(a3)+
  304. PutChProc_OUT:    rts
  305.  
  306. ;Structures & reservations
  307.  
  308. CurrentTTY:    dc.b    0
  309. Action:        dc.b    0        ;0=show, 1=login, 2=logout
  310.  
  311. Hours:        dc.w    0
  312. Minutes:    dc.w    0
  313. UpDays:        dc.l    0
  314. DaysString:    dc.l    PluralString1
  315. UpHours:    dc.w    0
  316. UpMinutes:    dc.w    0
  317. Users:        dc.w    0
  318. UsersString:    dc.l    PluralString1
  319. PluralString1:    dc.b    's,',0
  320. SingleString1:    dc.b    ', ',0
  321.  
  322. ;Filenames
  323.  
  324. LoadAvgName:    dc.b    "ENV:UT_loadavg",0
  325. UpTimeName:    dc.b    "ENV:NUT_timeval",0
  326. UpTimeConsole:    dc.b    "ENV:NUT_console",0
  327. UpTimeTTY:    dc.b    "ENV:NUT_ttyp"
  328. TTY:        dc.b    0,0
  329.  
  330. ;Error strings etc...
  331.  
  332.  
  333. ;Information & other strings
  334.  
  335.         dc.b    "$VER: "
  336. AuthorText1:    dc.b    "Uptime 1.02 (22.8.92) by Tomi Blinnikka",13,10,13,10
  337. ;        dc.b    13,10,"!!! BETA TESTER VERSION !!!",13,10,13,10,13,10
  338.         dc.b    0
  339.  
  340. UsageText1:    dc.b    "USAGE: Uptime [-i] [-o] [Number] [User]",13,10,13,10
  341.         dc.b    "       Where: [-i] for login",13,10
  342.         dc.b    "              [-o] for logout",13,10
  343.         dc.b    "              [Number] is the tty number 0-9",13,10
  344.         dc.b    "              [User] is the username",13,10,13,10
  345.         dc.b    "Tells how long the system has been up and its CPU usage.",13,10
  346.         dc.b    "It also records the login time and username for a TTY.",13,10
  347.         dc.b    "See docs for more information.",13,10,0
  348. fstrl1:        dc.b    "  %02.2d:%02d up %ld day%s %02.2d:%02.2d, %2.2d user%s load average: ",0
  349. UpTimeText1:    dcb.b    100,0
  350. EndText1:    dc.b    13,10,0
  351.         ds.l    0
  352.  
  353. ;Structures
  354.  
  355. DateTime1:    dc.l    0        ;days past 1978
  356.         dc.l    0        ;mins past 00:00
  357.         dc.l    0        ;ticks past min
  358. TTYTaskNum:    dc.l    0        ;pr_TaskNum
  359. TTYUser:    dc.b    'root'        ;user on this tty
  360.         dcb.b    20-4,0
  361. TTYReal:    dcb.b    20,0        ;users' real name
  362.  
  363. ;library stuff
  364.  
  365.         libnames
  366.  
  367. ;Buffers
  368.  
  369. UpTimeBuf:    dcb.b    3*4,0        ;read NUT_timeval here
  370. LoadAvgBuf:    dcb.b    20,0        ;read UT_loadavg here
  371.         END
  372.  
  373.