home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 440.lha / LibraryKiller / LibraryKiller.asm < prev    next >
Assembly Source File  |  1990-11-13  |  8KB  |  337 lines

  1.  
  2. ; ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
  3. ; ­­                                                                   ­­
  4. ; ­­                       LibraryKiller V1.0                          ­­
  5. ; ­­                                                                   ­­
  6. ; ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
  7. ; ­­                                                                   ­­
  8. ; ­­                Author :  Roger Fischlin                           ­­
  9. ; ­­                          Steigerwaldweg 6                         ­­
  10. ; ­­                          6450 Hanau 7                             ­­
  11. ; ­­                          West Germany                             ­­
  12. ; ­­                                                                   ­­
  13. ; ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
  14. ; ­­                                                                   ­­
  15. ; ­­             This program may be freely distributed .              ­­ 
  16. ; ­­                                                                   ­­
  17. ; ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
  18. ; ­­                                                                   ­­
  19. ; ­­                   Assembler : DevPac V2                           ­­
  20. ; ­­                                                                   ­­
  21. ; ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
  22.  
  23.  
  24.     incdir       "ram:include/"
  25.  
  26.             include     exec/memory.i
  27.     include    exec/exec_lib.i
  28.     include    exec/execbase.i
  29.     include    exec/libraries.i
  30.     include    exec/lists.i
  31.     include    exec/nodes.i
  32.     include    libraries/dos_lib.i
  33.     include    libraries/dos.i
  34.  
  35.  
  36.  
  37. CALL_DOS    macro
  38.     move.l    -SP_DosBase(a5),a6
  39.     jsr    _LVO\1(a6)
  40.     endm
  41. CALL_INT    macro
  42.     move.l    -SP_IntBase(a5),a6
  43.     jsr    _LVO\1(a6)
  44.     endm
  45. CALL_GFX    macro
  46.     move.l    -SP_GfxBase(a5),a6
  47.     jsr    _LVO\1(a6)
  48.     endm
  49.  
  50.     rsreset
  51. SP_A0    rs.l    1
  52. SP_D0    rs.l    1
  53. SP_DosBase    rs.l    1
  54. SP_Text    rs.b    82
  55.  
  56. SP_SIZEOF    rs.w    0
  57.  
  58.  
  59.  
  60.  
  61. OpenThem    link    a5,#-SP_SIZEOF
  62.     
  63.     clr.b    -1(a0,d0)        ; terminate string with 0
  64.  
  65.     move.l    a0,-SP_A0(a5)        ; save d0/a0
  66.     move.l    d0,-SP_D0(a5)
  67.  
  68.     lea    dosname(pc),a1        ; open library
  69.     CALLEXEC     OldOpenLibrary
  70.     move.l    d0,-SP_DosBase(a5)
  71.  
  72.     move.l    -SP_A0(a5),a0        ; no command line
  73.     tst.b    (a0)
  74.     beq    LIST
  75.     cmp.b    #"?",(a0)        ; command line "?"
  76.     beq    Info
  77.  
  78.     jsr    REMOVE
  79.  
  80. CloseLib    move.l    -SP_DosBase(a5),a1    ; close library
  81.     CALLEXEC     CloseLibrary
  82.  
  83.     moveq.l    #0,d0
  84.     unlk    a5
  85.     rts
  86.  
  87.  
  88. Info    CALL_DOS    Output        ; write info text
  89.     move.l    d0,d1
  90.     lea.l    .Text(pc),a0
  91.     move.l    a0,d2
  92.     move.l    #.TextEnd-.Text,d3
  93.     CALL_DOS    Write
  94.     bra    CloseLib
  95.  
  96. .Text    dc.b    $a,$9b,"1;33;40m"
  97.     dc.b    "                LibraryKiller V1.0 (5-April-1990)"
  98.     dc.b    $9b,"0;32;40m",$a
  99.     dc.b    "Author : Roger Fischlin, Steigerwaldweg 6, 6450 Hanau 7, West Germany",$a
  100.     dc.b    $9b,"0;31;40m",$a
  101.     dc.b    "LibraryKiller  removes libraries  which are  not used  any more. This",$a
  102.     dc.b    "program  may  freely distributed.",$a,$a
  103.     dc.b    "Usage: LibraryKiller                 » list all libraries",$a
  104.     dc.b    "       LibraryKiller <library name>  » remove library ( '*' allowed )",$a
  105.     dc.b    "       LibraryKiller *               » remove all libraries",$a,$a
  106. .TextEnd
  107.     even
  108.     
  109. dosname    DOSNAME
  110.  
  111.  
  112.  
  113. ******************************************************************
  114. *             search libraries and remove them                   *
  115. ******************************************************************
  116.  
  117.  
  118. REMOVE    move.l    4.w,a2        ; exec structure
  119.     lea.l    LibList(a2),a2        ; 1st library node
  120.     CALLEXEC    Forbid        ; another task could add a new library or remove one ....
  121.  
  122. .Label2    move.l    (a2),d0        ; first node
  123.     beq    .NotFound        ; empty list ?
  124. .Label4    move.l    d0,a2
  125.     move.l    (a2),d0        ; pointer to 0
  126.     beq    .NotFound
  127.     
  128.     move.l    LN_NAME(a2),a1        ; compare names
  129.     move.l    -SP_A0(a5),a0
  130. .Label1    cmp.b    #"*",(a0)        ; "*" ?
  131.     beq    .Found
  132.     cmpm.b    (a0)+,(a1)+
  133.     bne.s    .Label2
  134.     tst.b    -1(a1)        ; end of string (0) ?
  135.     bne    .Label1
  136.  
  137.  
  138.  
  139. .Found    CALL_DOS    Output
  140.     move.l    d0,d1
  141.     move.l    LN_NAME(a2),a0        ; write libary name
  142.     move.l    a0,d2
  143.     moveq.l    #-1,d3
  144. .Label3    addq.l    #1,d3
  145.     tst.b    (a0)+
  146.     bne.s    .Label3
  147.     CALL_DOS    Write
  148.  
  149.     cmp.l    d0,d3        ; error ?
  150.     bne    .NotFound
  151.     
  152.     move.l    (a2),d5        ; save pointer
  153.     
  154.     lea.l    .InUseText(pc),a0
  155.     move.l    a0,d2
  156.     tst.w    LIB_OPENCNT(a2)    ; nobody uses this library 
  157.     bne    .NoError        ; library still in use ...
  158.     
  159.     move.l    a2,a1
  160.     CALLEXEC    RemLibrary        ; remove library (that's all !!!)
  161.     
  162.     lea.l    .RemoveText(pc),a0
  163.     move.l    a0,d2
  164.     tst.l    d0
  165.     bne.s    .NoError
  166.     lea.l    .RemoveError(pc),a0
  167.     move.l    a0,d2
  168.     
  169. .NoError    CALL_DOS    Output        ; write result
  170.     move.l    d0,d1
  171.     move.l    #20,d3
  172.     CALL_DOS    Write
  173.     cmp.l    d0,d3        ; error ?
  174.     bne.s    .NotFound
  175.     
  176.     move.l    d5,d0        ; next node
  177.     beq.s    .NotFound        ; last ?
  178.     bra    .Label4    
  179.  
  180. .NotFound    CALLEXEC    Permit
  181.     rts
  182.  
  183.  
  184. .RemoveText    dc.b    "  : removed.       ",$a
  185. .InUseText    dc.b    "  : still in use ! ",$a
  186. .RemoveError    dc.b    "  : remove failed !",$a
  187.  
  188.  
  189.  
  190. ******************************************************************
  191. *                      list  all  libraries                      *
  192. ******************************************************************
  193.  
  194. LIST    CALL_DOS    Output        ; write first line
  195.     move.l    d0,d1
  196.     lea    .Header(pc),a0
  197.     move.l    a0,d2
  198.     move.l    #.HeaderEnd-.Header,d3
  199.     CALL_DOS    Write
  200.  
  201.  
  202.  
  203.     move.l    4.w,a2        ; exec structure
  204.     lea.l    LibList(a2),a2        ; 1st library node
  205.  
  206. .Label2    move.l    (a2),d0        ; first node
  207.     beq    .NoMore        ; empty list ?
  208.     move.l    d0,a2
  209.     move.l    (a2),d0        ; pointer to 0
  210.     beq    .NoMore
  211.     
  212.  
  213.     lea    -SP_Text-80(a5),a1    ; clear 
  214.     move.w    #77,d0
  215. .Label1    move.b    #" ",(a1)+
  216.     dbra    d0,.Label1
  217.     move.b    #$a,(a1)+
  218.     
  219.     move.l    LN_NAME(a2),a1        ; copy name
  220.     lea    -SP_Text-80(a5),a0
  221.     move.w    #19,d0
  222. .Label3    move.b    (a1)+,(a0)+
  223.     dbeq    d0,.Label3
  224.  
  225.     moveq.l    #0,d0
  226.     move.b    LN_TYPE(a2),d0        ; write Type
  227.     lea    -SP_Text-80+62-32+1(a5),a0
  228.     bsr    .Write4    
  229.  
  230.     lea    -SP_Text-80+70-32+1(a5),a0
  231.     moveq.l    #0,d0
  232.     move.b    LN_PRI(a2),d0        ; write Pri
  233.     bpl.s    .Positive        ; positive ?
  234.     neg.b    d0
  235.     move.b    #"-",(a0)        ; write "-"
  236. .Positive    bsr    .Write4    
  237.  
  238.     move.w    LIB_OPENCNT(a2),d0    ; write OpenCount
  239.     lea    -SP_Text-80+78-32+1(a5),a0
  240.     bsr    .Write4    
  241.  
  242.     move.w    LIB_VERSION(a2),d0    ; write version
  243.     lea    -SP_Text-80+86-32+1(a5),a0
  244.     bsr    .Write4    
  245.  
  246.     move.w    LIB_REVISION(a2),d0    ; write revision
  247.     lea    -SP_Text-80+93-32+1(a5),a0
  248.     bsr    .Write4    
  249.  
  250.     move.w    LIB_NEGSIZE(a2),d0    ; write size
  251.     lea    -SP_Text-80+99-32+1(a5),a0
  252.     bsr    .Write4        
  253.     move.w    LIB_POSSIZE(a2),d0
  254.     lea    -SP_Text-80+105-32+1(a5),a0
  255.     bsr    .Write4    
  256.  
  257.     move.l    a2,d0        ; write library base
  258.     lea    -SP_Text-80+52-32+1(a5),a0
  259.     move.b    #"$",(a0)+    
  260.     moveq.l    #7,d2        ; 8 nibble
  261.     moveq.l    #0,d1
  262. .Label6    rol.l    #4,d0        ; get next nibble and
  263.     move.b    d0,d1        ; move to lowest nibble
  264.     and.b    #$f,d1
  265.     cmp.b    #10,d1
  266.     blt.s    .Label7
  267.     add.b    #"A"-"0"-10,d1        ; offset for letters
  268. .Label7    add.b    #"0",d1        ; convert to ASCII
  269.     move.b    d1,(a0)+
  270.     dbra    d2,.Label6
  271.  
  272.     CALL_DOS    Output        ; write line
  273.     move.l    d0,d1
  274.     lea    -SP_Text-80(a5),a0
  275.     move.l    a0,d2
  276.     move.l    #78,d3
  277.     CALL_DOS    Write
  278.     cmp.l    d3,d0        ; error ?
  279.     bne.s    .Error
  280.  
  281.     bra    .Label2        ; next entry
  282.  
  283.  
  284.  
  285.  
  286. .NoMore    CALL_DOS    Output        ; write LF
  287.     move.l    d0,d1
  288.     lea    .Return(pc),a0
  289.     move.l    a0,d2
  290.     moveq.l    #2,d3
  291.     CALL_DOS    Write
  292.  
  293. .Error    bra    CloseLib
  294.  
  295.  
  296.  
  297.  
  298. .Write4    and.l    #$ffff,d0
  299.     move.w    #"0",d1        ; Word -> ASCII
  300.     cmp.w    #999,d0
  301.     bls.s    .Label_W1
  302.     divu    #1000,d0
  303.     add.b    d1,d0
  304.     move.b    d0,(a0)
  305.     clr.w    d0
  306.     swap    d0
  307. .Label_W1    cmp.w    #99,d0
  308.     bls.s    .Label_W2
  309.     divu    #100,d0
  310.     add.b    d1,d0
  311.     move.b    d0,1(a0)
  312.     clr.w    d0
  313.     swap    d0
  314. .Label_W2    cmp.w    #9,d0
  315.     bls.s    .Label_W3
  316.     divu    #10,d0
  317.     add.b    d1,d0
  318.     move.b    d0,2(a0)
  319.     clr.w    d0
  320.     swap    d0
  321. .Label_W3    add.b    d1,d0
  322.     move.b    d0,3(a0)
  323.     rts
  324.  
  325.     
  326.  
  327. .Header    dc.b    $a,$9b,"0;33;40m"
  328.     dc.b    "                                 Libraries",$a,$a
  329.     dc.b    $9b,"4;32;40m"
  330.     dc.b    "Name                 Address   Type   Pri.  OpenCnt  Vers.   Rev.  Neg.  Pos."
  331.     dc.b    $9b,"0;31;40m",$a
  332. .HeaderEnd
  333.     even
  334. .Return    dc.b    $a,$a
  335.  
  336.  
  337.