Amiga!
Home
Support
Get the SDK
(Answer) (Category) Amiga Inc. Faq-O-Matic : (Category) Amiga SDK FAQ :
How to I call an arbitrary tool? (name decided at run-time)
Those of you who use the VP assembler know that 'qcall' is one of your best
friends.  However, being limited to constant tool names defined at compile-time
doesn't always fulfill exactly what you want.  Sometimes, you want to be able
to determine at run-time what tool to call.  Thus, this macro was born.


; Usage:  tcall  name
; Usage:  tcall  name, (args:args)
; Usage:  tcall  name, (args:args), success
; Example:  tcall  toolname.p, (p0, p1, i0 : i4), tool_was_found
; NOTE:  the name follows the same rules as qcall's first argument:
;          1) full path
;          2) no leading slash
;          3) no trailing processor type (ie, '.00')
;        it will fail if any of these are not followed,
;        or if the tool is otherwise not found.
._qmacro tcall
        .check  %N >= 1
        defbegin
        defp    tcall_head, tcall_code
        
        qcall   sys/kn/tool/open, (%1, NULL.p : tcall_head, tcall_code)
        if      tcall_head == NULL
                .if     %N > 2
                        cpy     0, %3
                .endif
        else
        .if     %N == 1
                gos     tcall_code, (-:-)
        .elseif %N == 2
                gos     tcall_code, %2
        .elseif %N == 3
                gos     tcall_code, %2
                cpy     -1, %3
        .endif
                qcall   sys/kn/tool/deref, (tcall_head:-)
        endif
        defend
.endm



Here's an example of how to use it:

         ...
        if      i0 == 0
                cpy.p   strcmp.p, p0
        else
                cpy.p   strcmpi.p, p0
        endif
        tcall   p0, (str1, str2 : i0), i1
        if      i1 == 0
                tracef  "Tool '%s' not found!\n", p0
        else
                printf  "Result of %s ('%s', '%s') == %d\n", p0, str1, str2, i0
        endif
         ...
        data
strcmp:
        dc.b    'lib/strcmp',0
strcmpi:
        dc.b    'lib/strcmpi',0
         ...


Make sure you pay attention to those notes in the macro's comments.  (:
This macro can also be found at my site at:
  http://www.weblink.org/AmigaNG/


Jesse
[Append to This Answer]
thought
Previous: (Answer) Amiga Text Editors
Next: (Answer) Amiga SDK Setup doesn't take my Developer Id
This document is: http://www.amiga.com/cgi-bin/fom.cgi?file=129
[Search] [Appearance]
This is a Faq-O-Matic 2.710.
This FAQ administered by ray@amiga.com


© 1996-2000 Amiga, Inc.