home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD2.bin / bbs / dev / tbsource.lha / TBSource / Logger / W.S < prev   
Text File  |  1993-12-21  |  10KB  |  505 lines

  1. *************************************************
  2. *                        *
  3. *        (C)opyright 1992-93        *
  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. * BUGS:    Version text was incorrect, length of    *
  20. *    TTY_X and console reads/writes were    *
  21. *    one byte too short. Pointers to lists    *
  22. *    were incorrect.                *
  23. *                        *
  24. * Version 1.02    22/08/1992            *
  25. *                        *
  26. * BUGS:    Didn't clear whole ActionBuf.        *
  27. *                        *
  28. * Version 1.03    14/02/1993            *
  29. *                        *
  30. * BUGS:    Didn't add NULL after command.        *
  31. *                        *
  32. * Version 1.04    28/02/1993            *
  33. *                        *
  34. * Version 1.05    04/04/1993            *
  35. *                        *
  36. * Fixed bug with command length (InfoOutText1)    *
  37. * at last...                    *
  38. *                        *
  39. *************************************************
  40.  
  41.     INCLUDE    "JMPLibs.i"
  42.     INCLUDE    "exec/types.i"
  43.     INCLUDE    "libraries/dos.i"
  44.     INCLUDE    "libraries/dosextens.i"
  45.  
  46.     INCLUDE    "XREF:2.0.xref"
  47.     INCLUDE    "XREF:exec.xref"
  48.     INCLUDE    "XREF:dos.xref"
  49.  
  50.         section    W,CODE
  51.  
  52.         move.l    a0,a4
  53.         clr.b    -1(a0,d0.l)
  54.         openlib    Dos,ShutDown_Out
  55.  
  56.         cmp.b    #'?',(a4)
  57.         beq    CmdLineHelp
  58.         cmp.w    #'-?',(a4)
  59.         beq    CmdLineHelp
  60.         cmp.w    #'-h',(a4)
  61.         beq    CmdLineHelp
  62.         cmp.b    #'h',(a4)
  63.         beq    CmdLineHelp
  64. Skip1:
  65.  
  66. ;Get system time
  67. ;Uptime equals (System time - NUT_timeval)
  68. ;Try to read ENV:NUT_console + ENV:NUT_TTYX
  69. ;Loop 0 - 9
  70. ;try reading ENV:UT_loadavg
  71.  
  72. Information:    bsr    GetSysTime
  73.         bsr    GetUpTime
  74.         bsr    DoTTYTest
  75.         bsr    GetLoadAvg
  76.  
  77.         cmp.w    #1,Users
  78.         bne    CheckUsrNum1
  79.         lea.l    SingleString1,a0
  80.         move.l    a0,UsersString
  81. CheckUsrNum1:    bsr    Format
  82.         lea.l    UpTimeText1,a0
  83.         bsr    Printer
  84.  
  85.         lea.l    LoadAvgBuf,a0
  86.         bsr    Printer
  87.  
  88.         lea.l    EndText1,a0
  89.         bsr    Printer
  90.  
  91.         lea.l    InfoText1,a0
  92.         bsr    Printer
  93.  
  94.         bsr    Do2TTYTest
  95.  
  96.         bra    ShutDown
  97.  
  98. CheckUpTime:    lea.l    UpTimeName,a3
  99.         move.l    a3,d1
  100.         move.l    #MODE_OLDFILE,d2
  101.         lib    Dos,Open
  102.         tst.l    d0
  103.         beq    CheckUpTime2
  104.         move.l    d0,d4
  105.         move.l    d0,d1
  106.         lea.l    UpTimeBuf,a0
  107.         move.l    a0,d2
  108.         move.l    #3*4,d3
  109.         lib    Dos,Read
  110.         move.l    d4,d1
  111.         lib    Dos,Close
  112.         rts
  113. CheckUpTime2:    move.l    a3,d1
  114.         move.l    #MODE_NEWFILE,d2
  115.         lib    Dos,Open
  116.         tst.l    d0
  117.         beq    CheckUpTime3
  118.         move.l    d0,d4
  119.         move.l    d0,d1
  120.         lea.l    DateTime1,a0
  121.         move.l    a0,d2
  122.         move.l    #3*4,d3
  123.         lib    Dos,Write
  124.         move.l    d4,d1
  125.         lib    Dos,Close
  126.         move.l    DateTime1,UpTimeBuf
  127.         move.l    DateTime1+4,UpTimeBuf+4
  128.         move.l    DateTime1+4,UpTimeBuf+4
  129. CheckUpTime3:    rts
  130.  
  131. GetSysTime:    lea.l    DateTime1,a0
  132.         move.l    a0,d1
  133.         lib    Dos,DateStamp
  134.  
  135.         move.l    DateTime1+4,d0
  136.         divu.w    #60,d0
  137.         move.w    d0,Hours
  138.         swap    d0
  139.         move.w    d0,Minutes
  140.         rts
  141.  
  142. GetUpTime:    lea.l    UpTimeName,a3
  143.         move.l    a3,d1
  144.         move.l    #MODE_OLDFILE,d2
  145.         lib    Dos,Open
  146.         tst.l    d0
  147.         beq    GetUpTime2
  148.         move.l    d0,d4
  149.         move.l    d0,d1
  150.         lea.l    UpTimeBuf,a0
  151.         move.l    a0,d2
  152.         move.l    #3*4,d3
  153.         lib    Dos,Read
  154.         move.l    d4,d1
  155.         lib    Dos,Close
  156.         move.l    UpTimeBuf,d0
  157.         move.l    DateTime1,d1
  158.         sub.l    d0,d1
  159.         move.l    d1,UpDays
  160.         move.l    UpTimeBuf+4,d0
  161.         move.l    DateTime1+4,d1
  162.         sub.l    d0,d1
  163.         bmi    GetUpTime3
  164. GetUpTime1:    divu.w    #60,d1
  165.         move.w    d1,UpHours
  166.         swap    d1
  167.         move.w    d1,UpMinutes
  168. GetUpTime2:    rts
  169. GetUpTime3:    move.l    UpTimeBuf+4,d0
  170.         move.l    DateTime1+4,d1
  171.         add.l    #1440,d1
  172.         sub.l    d0,d1
  173.         sub.l    #1,UpDays
  174.         cmp.l    #1,UpDays
  175.         bne    GetUpTime1
  176.         lea.l    SingleString1,a0
  177.         move.l    a0,DaysString
  178.         bra    GetUpTime1
  179.  
  180. DoTTYTest:    lea.l    UpTimeConsole,a0
  181.         move.l    a0,d1
  182.         move.l    #MODE_OLDFILE,d2
  183.         lib    Dos,Open
  184.         tst.l    d0
  185.         beq    DoTTYTest1
  186.         move.l    d0,d1
  187.         add.w    #1,Users
  188.         lib    Dos,Close
  189.  
  190. DoTTYTest1:    move.b    #'0',TTY
  191.  
  192. DoTTYTest2:    lea.l    UpTimeTTY,a0
  193.         move.l    a0,d1
  194.         move.l    #MODE_OLDFILE,d2
  195.         lib    Dos,Open
  196.         tst.l    d0
  197.         beq    DoTTYTest3
  198.         move.l    d0,d1
  199.         add.w    #1,Users
  200.         lib    Dos,Close
  201. DoTTYTest3:    cmp.b    #'9',TTY
  202.         beq    DoTTYTest4
  203.         add.b    #1,TTY
  204.         bra    DoTTYTest2
  205. DoTTYTest4:    rts
  206.  
  207. GetLoadAvg:    lea.l    LoadAvgName,a0
  208.         move.l    a0,d1
  209.         move.l    #MODE_OLDFILE,d2
  210.         lib    Dos,Open
  211.         tst.l    d0
  212.         bne    GetLoadAvg2
  213. GetLoadAvg1:    move.l    #'N/A,',LoadAvgBuf
  214.         move.l    #'  N/',LoadAvgBuf+4
  215.         move.l    #'A,  ',LoadAvgBuf+8
  216.         move.l    #'N/A ',LoadAvgBuf+12
  217.         move.b    #$00,LoadAvgBuf+16
  218.         rts
  219. GetLoadAvg2:    move.l    d0,d4
  220.         move.l    d0,d1
  221.         lea.l    LoadAvgBuf,a0
  222.         move.l    a0,d2
  223.         move.l    #19,d3
  224.         lib    Dos,Read
  225.  
  226.         cmp.l    #19,d0
  227.         beq    GetLoadAvg3
  228.         bsr    GetLoadAvg1
  229. GetLoadAvg3:    move.l    d4,d1
  230.         lib    Dos,Close
  231.         rts
  232.  
  233. Do2TTYTest:    lea.l    UpTimeConsole,a0
  234.         move.l    a0,d1
  235.         move.l    #MODE_OLDFILE,d2
  236.         lib    Dos,Open
  237.         tst.l    d0
  238.         beq    Do2TTYTest1
  239.         move.l    d0,d5
  240.  
  241.         move.l    d0,d1
  242.         lea.l    DateTime1,a0
  243.         move.l    a0,d2
  244.         move.l    #4*4+20,d3    ;was 3*4 !!!
  245.         lib    Dos,Read
  246.  
  247.         move.l    d5,d1
  248.         lib    Dos,Close
  249.  
  250.         bsr    D2TTY
  251.  
  252.         lea.l    ConsoleText1,a0
  253.         bsr    P2TTY
  254.  
  255. Do2TTYTest1:    move.b    #'0',TTY
  256. Do2TTYTest2:    lea.l    UpTimeTTY,a0
  257.         move.l    a0,d1
  258.         move.l    #MODE_OLDFILE,d2
  259.         lib    Dos,Open
  260.         tst.l    d0
  261.         beq    Do2TTYTest3
  262.         move.l    d0,d5
  263.         move.l    d0,d1
  264.         lea.l    DateTime1,a0
  265.         move.l    a0,d2
  266.         move.l    #4*4+20,d3    ;was 3*4 !!!
  267.         lib    Dos,Read
  268.  
  269.         move.l    d5,d1
  270.         lib    Dos,Close
  271.  
  272.         bsr    D2TTY
  273.  
  274.         lea.l    UpTimeTTY1,a0
  275.         bsr    P2TTY
  276.  
  277. Do2TTYTest3:    cmp.b    #'9',TTY
  278.         beq    Do2TTYTest4
  279.         add.b    #1,TTY
  280.         bra    Do2TTYTest2
  281. Do2TTYTest4:    rts
  282.  
  283. ;This puts everything in the right place and prints this TTY's info
  284. ;
  285. ;INPUTS
  286. ;
  287. ;a0 = String of tty or console
  288.  
  289. P2TTY:        move.l    a0,TTYText1
  290.         move.l    DateTime1+4,d0
  291.         divu.w    #60,d0
  292.         move.w    d0,HoursText1
  293.         swap    d0
  294.         move.w    d0,MinutesText1
  295.  
  296.         bsr    Format2
  297.         lea.l    InfoOutText1,a0
  298.         bsr    Printer
  299.         lea.l    EndText1,a0
  300.         bsr    Printer
  301.  
  302.         lea.l    ActionBuf,a0        ;this should clear 38 chars
  303.         move.l    #9,d0            ;but does (4 bytes * 10)
  304. P2TTY1:        clr.l    (a0)+
  305.         dbf    d0,P2TTY1
  306.  
  307.         lea.l    InfoOutText1,a0        ;this should clear 200 bytes
  308.         move.l    #49,d0            ;but does (4 bytes * 50)
  309. P2TTY2:        clr.l    (a0)+
  310.         dbf    d0,P2TTY2
  311.         rts
  312.  
  313. ;This goes through the lists and if it finds a cli process with same CLINum,
  314. ;it will copy the command name into ActionBuf.
  315.  
  316. D2TTY:        lib    Exec,Disable
  317.         move.l    $4,a6        ;not really needed!
  318.         lea.l    $1a4(a6),a2
  319.         move.l    LH_HEAD(a2),a2
  320.  
  321. D2TTY1:        bsr    LT_LOOP
  322.         cmp.l    #$00,a2
  323.         beq    D2TTY3
  324.  
  325. D2TTY2:        move.l    CLINumBuf,d0
  326.         cmp.l    TTYTaskNum,d0
  327.         beq    Do2Console
  328.         bsr    LT_LOOPer
  329.         cmp.l    #$00,a2
  330.         bne    D2TTY2
  331.  
  332. D2TTY3:        move.l    $4,a6            ;not needed ?
  333.         lea.l    $196(a6),a2
  334.         move.l    LH_HEAD(a2),a2
  335.         bsr    LT_LOOP
  336.         cmp.l    #$00,a2
  337.         beq    D2TTY5
  338.  
  339. D2TTY4:        move.l    CLINumBuf,d0
  340.         cmp.l    TTYTaskNum,d0
  341.         beq    Do2Console
  342.         bsr    LT_LOOPer
  343.         cmp.l    #$00,a2
  344.         bne    D2TTY4
  345.  
  346. D2TTY5:        sub.l    a1,a1
  347.         lib    Exec,FindTask
  348.         move.l    d0,a2
  349.         move.l    $8c(a2),d0
  350.         cmp.l    TTYTaskNum,d0
  351.         bne    Do2Console4
  352.  
  353. Do2Console:    bsr    LT_GetName
  354.         lea.l    ActionBuf,a3
  355.         clr.l    d0
  356.         move.b    (a0)+,d0
  357.         bne    Do2Console1
  358.         lea.l    NoCmdText1,a0
  359.         bra    Do2Console2
  360. Do2Console1:    sub.w    #1,d0
  361.         cmp.w    #38,d0            ;Do only 38 characters?
  362.         bls    Do2Console3
  363. Do2Console2:    move.l    #38,d0
  364. Do2Console3:    move.b    (a0)+,(a3)+
  365.         tst.b    (a0)
  366.         beq    DoConsole3.1
  367.         dbeq    d0,Do2Console3
  368. DoConsole3.1:    clr.b    (a3)+            ;was missing
  369. Do2Console4:    lib    Exec,Enable
  370.         rts
  371.  
  372. LT_LOOPer:    move.l    LN_SUCC(a2),a2
  373.  
  374. LT_LOOP:    tst.l    LN_SUCC(a2)
  375.         beq    LT_END
  376.  
  377.         move.b    LN_TYPE(a2),d0
  378.         cmp.b    #NT_PROCESS,d0
  379.         bne    LT_LOOPer            ;Not even a process
  380.  
  381.         move.l    $8c(a2),CLINumBuf
  382.         beq    LT_LOOPer            ;Not a CLI process
  383.         rts
  384.  
  385. LT_END:        move.l    #$00,a2
  386.         rts
  387.  
  388. ;Give it the cliprocess pointer in a2 (?)
  389.  
  390. LT_GetName:    move.l    $ac(a2),a0            ;change BPTR-APTR
  391.         add.l    a0,a0
  392.         add.l    a0,a0
  393.  
  394.         move.l    $10(a0),a0
  395.         add.l    a0,a0
  396.         add.l    a0,a0
  397.         rts
  398.  
  399.  
  400. Format:        lea.l    fstrl1,a0        ;HEX->ASCII
  401.         lea.l    Hours,a1        ;Start of information
  402.         lea.l    PutChProc,a2
  403.         lea.l    UpTimeText1,a3        ;Destination
  404.         lib    Exec,RawDoFmt
  405.         rts
  406.  
  407. Format2:    lea.l    fstrl2,a0        ;HEX->ASCII
  408.         lea.l    UserText1,a1        ;Start of information
  409.         lea.l    PutChProc,a2
  410.         lea.l    InfoOutText1,a3        ;Destination
  411.         lib    Exec,RawDoFmt
  412.         rts
  413.  
  414. ShutDown:    closlib    Dos
  415. ShutDown_Out:    move.l    #RETURN_OK,d0
  416.         rts
  417.  
  418. CmdLineHelp:    lea.l    UsageText1,a0
  419.         bsr    Printer    
  420.         bra    ShutDown
  421.  
  422. Printer:    printa    a0
  423.         rts
  424.  
  425. PutChProc:    tst.b    d0
  426.         beq    PutChProc_OUT
  427.         move.b    d0,(a3)+
  428. PutChProc_OUT:    rts
  429.  
  430. ;Structures & reservations
  431.  
  432. Hours:        dc.w    0
  433. Minutes:    dc.w    0
  434. UpDays:        dc.l    0
  435. DaysString:    dc.l    PluralString1
  436. UpHours:    dc.w    0
  437. UpMinutes:    dc.w    0
  438. Users:        dc.w    0
  439. UsersString:    dc.l    PluralString1
  440. PluralString1:    dc.b    's,',0
  441. SingleString1:    dc.b    ', ',0
  442.  
  443. UserText1:    dc.l    TTYUser
  444. TTYText1:    dc.l    UpTimeTTY1
  445. HoursText1:    dc.w    0
  446. MinutesText1:    dc.w    0
  447. ActionText1:    dc.l    ActionBuf
  448.  
  449. ;Filenames
  450.  
  451. LoadAvgName:    dc.b    "ENV:UT_lo