home *** CD-ROM | disk | FTP | other *** search
/ AMIGA PD 1 / AMIGA-PD-1.iso / Programme_zum_Heft / Programmieren / Kurztests / ACE / include / WBarg.h < prev   
C/C++ Source or Header  |  1994-10-23  |  4KB  |  189 lines

  1. {   Retrieve WorkBench argument info' 
  2.  
  3.     Workbench arguments are contained in the 
  4.     WBStartup structure's ArgList after 
  5.     a program has been launched from the 
  6.     Workbench or an icon with a default tool 
  7.     has been double-clicked.
  8.  
  9.     The order in which the arguments appear in 
  10.     the list is the same as the order in which
  11.     the icons (corresponding to the arguments)
  12.     were single-clicked.
  13.     
  14.   - WBargcount returns the number of arguments 
  15.     to a Workbench launched program. The name 
  16.     of the program is included in this count.
  17.  
  18.   - WBarg$(N) returns the Nth Workbench argument
  19.     as a string. The zeroth argument is the 
  20.     program's name. Only the name of the argument
  21.     is returned, not it's full path. To obtain
  22.     the latter, use WBargPath$(N).
  23.  
  24.   - WBargLock&(N) returns the file lock of the
  25.     Nth Workbench argument. It is primarily
  26.     for use by WBargPath$(N).
  27.  
  28.   - WBargPath$(N) returns the full path of the 
  29.     Nth Workbench argument as a string.
  30.  
  31.   Author: David J Benn
  32.     Date: 25th December 1992
  33. }
  34.  
  35. #include <stddef.h>
  36.  
  37. external WBenchMsg&    '..Task's WBStartup message (from startup.lib)
  38.  
  39. '..the structures
  40. struct WBArg
  41.   longint wa_Lock
  42.   longint wa_Name
  43. end struct
  44.  
  45. struct WBStartup
  46.   string  sm_Message size 20
  47.   longint sm_Process
  48.   longint sm_Segment
  49.   longint sm_NumArgs
  50.   longint sm_ToolWindow
  51.   longint sm_ArgList
  52. end struct
  53.  
  54. struct FileInfoBlock
  55.   longint fib_DiskKey
  56.   longint fib_DirEntryType
  57.   string  fib_FileName size 108
  58.   longint fib_Protection
  59.   longint fib_EntryType
  60.   longint fib_Size
  61.   longint fib_NumBlocks
  62.   string  fib_Date size 12
  63.   string  fib_Comment size 80
  64.   string  fib_Reserved size 36
  65. end struct
  66.  
  67.  
  68. '..the functions
  69. SUB WBargcount
  70. declare struct WBStartup *WBinfo
  71. declare struct WBArg *argptr
  72.  
  73.   { return # of WB args }
  74.  
  75.   WBinfo = WBenchMsg
  76.  
  77.   if WBinfo <> NULL then
  78.     WBargcount = WBinfo->sm_NumArgs
  79.   else
  80.     WBargcount = 0
  81.   end if
  82. END SUB
  83.  
  84. SUB WBarg$(N)
  85. declare struct WBStartup *WBinfo
  86. declare struct WBArg *argptr
  87. longint argptr,max_param,count
  88.  
  89.   { return the Nth WB arg }
  90.  
  91.   WBinfo = WBenchMsg
  92.  
  93.   if WBinfo <> NULL then
  94.     max_param = WBinfo->sm_NumArgs
  95.   else
  96.     max_param = 0
  97.   end if
  98.  
  99.   if max_param > 0 and N <= max_param then
  100.     argptr = WBinfo->sm_ArgList
  101.  
  102.     count=0
  103.     while count < N     
  104.       argptr = argptr+sizeof(WBArg)
  105.       ++count
  106.     wend
  107.  
  108.     WBarg$ = cstr(argptr->wa_Name)
  109.   else
  110.     '..Nth argument is non-existent 
  111.     WBarg$ = ""    
  112.   end if
  113. END SUB
  114.  
  115. SUB WBargLock&(N)
  116. declare struct WBStartup *WBinfo
  117. declare struct WBArg *argptr
  118. longint argptr,max_param,count
  119.  
  120.   { return the Nth WB arg lock }
  121.  
  122.   WBinfo = WBenchMsg
  123.  
  124.   if WBinfo <> NULL then
  125.     max_param = WBinfo->sm_NumArgs
  126.   else
  127.     max_param = 0
  128.   end if
  129.  
  130.   if max_param > 0 and N <= max_param then
  131.     argptr = WBinfo->sm_ArgList
  132.  
  133.     count=0
  134.     while count < N     
  135.       argptr = argptr+sizeof(WBArg)
  136.       ++count
  137.     wend
  138.  
  139.     WBargLock& = argptr->wa_Lock
  140.   else
  141.     '..Nth lock is non-existent
  142.     WBargLock& = NULL    
  143.   end if
  144. END SUB
  145.  
  146. SUB get_abs_path(lock&,abspathaddr&)
  147. string abspath address abspathaddr&
  148. longint parentlock
  149.  
  150. declare struct FileInfoBlock info
  151. declare function ParentDir& library dos
  152. declare function Examine library dos
  153.  
  154.   { recursively get absolute path }
  155.  
  156.   if lock& <> NULL then
  157.     parentlock = ParentDir(lock&) 
  158.     get_abs_path(parentlock,abspathaddr&)
  159.   end if    
  160.  
  161.   if lock& <> NULL then
  162.     Examine(lock&,info)
  163.     abspath = abspath + info->fib_FileName
  164.     if parentlock <> NULL then 
  165.       '..directory
  166.       abspath = abspath + "/" 
  167.     else 
  168.       '..volume
  169.       abspath = abspath + ":" 
  170.     end if   
  171.   end if
  172. END SUB
  173.  
  174. SUB WBargPath$(N)
  175. longint arglock
  176. string  abspath
  177.  
  178.   { return full path of Nth WB arg }
  179.  
  180.   arglock = WBargLock&(N)
  181.  
  182.   if arglock <> NULL then
  183.     get_abs_path(arglock,@abspath)
  184.     WBargPath$ = abspath
  185.   else
  186.     WBargPath$ = ""
  187.   end if
  188. END SUB
  189.