home *** CD-ROM | disk | FTP | other *** search
/ Aminet 10 / aminetcdnumber101996.iso / Aminet / util / batch / BindNames36_19.lha / Icon.c < prev    next >
C/C++ Source or Header  |  1995-11-05  |  4KB  |  183 lines

  1. /* File : Icon.c
  2.  *
  3.  * $Project:         Bindnames
  4.  *
  5.  * $Module Id:         
  6.  * $Original Author:   Daryl Hegyi and Robert Hardy
  7.  * $Date Started:      Mon Aug  8 1994
  8.  *
  9.  * $Revision: 1.5 $
  10.  *
  11.  * $State: Exp $
  12.  *
  13.  * $Locker:  $
  14.  *
  15.  * $Log: Icon.c-v $
  16.  * Revision 1.5  1995/11/06  02:39:25  Bob
  17.  * OOPs.  Closed IconBase before FreeDiskObject().
  18.  *
  19.  * Revision 1.4  1995/11/05  06:03:54  Bob
  20.  * Cleanup and optimize;
  21.  *
  22.  * Revision 1.3  1995/11/05  05:36:25  Bob
  23.  * Debugging,  code was expecting a project icon.
  24.  * Fixed to handle both.
  25.  *
  26.  * Revision 1.2  1995/11/05  04:54:27  Bob
  27.  * Opps! Was not freeing DiskObject.
  28.  *
  29.  * Revision 1.1  1995/08/08  02:28:02  Bob
  30.  * Initial revision
  31.  * 
  32.  *
  33.  *
  34.  */
  35.  
  36.  
  37. #include <exec/types.h>
  38. #include <stdio.h>
  39. #include <ctype.h>
  40. #include <stdlib.h>
  41. #include <string.h>
  42. #include <libraries/dos.h>
  43. #include <libraries/dosextens.h>
  44. #include <workbench/workbench.h>
  45. #include <workbench/startup.h>
  46. #include <proto/all.h>
  47.  
  48. #include "BindNames.h"
  49.  
  50. #define dbg(FLAGS, args)                 \
  51. {                                                \
  52.     if ( ((FLAGS) & DBG_Flags) == FLAGS )    \
  53.     {                                            \
  54.         printf("\r%s: %d <%s> ", __FILE__, __LINE__,__FUNC__); \
  55.         printf args;                            \
  56.     }                                            \
  57. }                                             /**/
  58.  
  59. #define LDT_Gen_Icon     1
  60. private long DBG_Flags = 0;
  61.  
  62. static struct FileLock  *Old_Lock = NIL,
  63.                         *Program_Lock = NIL,
  64.                         *Datafile_Lock = NIL;
  65. static short IconBase_Loaded = 0;
  66.  
  67. struct DiskObject *Disk_Obj = NIL;
  68.  
  69. static short get_arg_list(ARG_LIST *arg_list, char *objname, short num_to_init)
  70. {
  71.     char **ToolTypes;
  72.     char *tool;
  73.     ARG_LIST *argptr;
  74.     short count = 0;
  75.     short argnum = 0;
  76.  
  77.     dbg(LDT_Gen_Icon, ("Obj name is: '%s'\r\n", objname));
  78.  
  79.     if ( (argptr = arg_list) )
  80.     {
  81.         if ( (Disk_Obj = GetDiskObject(objname)) )
  82.         {
  83.             ToolTypes= Disk_Obj->do_ToolTypes;
  84.  
  85.             while ( (argptr->arg_type) != NIL )
  86.             {
  87.                 dbg(LDT_Gen_Icon, ("arg #%d [%s]", argnum+1, argptr->arg_type));
  88.  
  89.                 ++argnum;    /* count it */
  90.  
  91.                 if (  ( tool = FindToolType( ToolTypes, argptr->arg_type ) )  )
  92.                 {
  93.                     argptr->arg_value = tool;
  94.                     ++count;
  95.                 }
  96.                 else if ( argnum <= num_to_init )
  97.                 {
  98.                     argptr-> arg_value = objname;
  99.                     ++count;
  100.                 }
  101.  
  102.                 ++argptr;    /* point to next one */
  103.             }
  104.         }
  105.     }
  106.  
  107.     return count;
  108. }
  109.  
  110. short Icon_Launch( int argc, char **argv,
  111.                     ARG_LIST *program_args, short num_to_init )
  112. {
  113.     struct WBArg *wbarg;
  114.     struct WBStartup *wb = (struct WBStartup *) argv;
  115.     short result = FALSE;
  116.  
  117.             /* started from workbench */
  118.     if (argc == 0 && wb )
  119.     {
  120.         if ( (IconBase = OpenLibrary("icon.library", 0L)) )
  121.         {
  122.             /* should point to program (tooltype) name */
  123.                wbarg = wb->sm_ArgList;
  124.  
  125.             if ( wbarg )
  126.             {
  127.                 Program_Lock = (struct FileLock *) wbarg->wa_Lock;
  128.  
  129.                 if (wb->sm_NumArgs > 1 && (++wbarg)->wa_Name)
  130.                 {
  131.                     /* change to the file's directory */
  132.                     Datafile_Lock = (struct FileLock *)wbarg->wa_Lock;
  133.  
  134.                     if (Datafile_Lock)
  135.                         Old_Lock = (struct FileLock *)CurrentDir(
  136.                             (BPTR)Datafile_Lock);
  137.                     else
  138.                         Old_Lock = (struct FileLock *)CurrentDir(
  139.                                 (BPTR)Program_Lock);
  140.  
  141.                 }
  142.                 else
  143.                     Old_Lock = (struct FileLock *)CurrentDir(
  144.                             (BPTR)Program_Lock);
  145.  
  146.                 dbg(LDT_Gen_Icon, ("Icon Name is '%s'\r\n", wbarg->wa_Name));
  147.  
  148.                 /* set desired argument values to point to the icon name */
  149.                 if (program_args)
  150.                 {
  151.                     get_arg_list(program_args, wbarg->wa_Name, num_to_init);
  152.                 }
  153.  
  154.                 result = TRUE;
  155.             }
  156.         }
  157.     }
  158.  
  159.     return result;
  160. }
  161.  
  162. void Icon_Finish(void)
  163. {
  164.  
  165.     if (Old_Lock)
  166.         Old_Lock = (struct FileLock *)CurrentDir((BPTR)Old_Lock);
  167.  
  168.     if (Disk_Obj)
  169.     {
  170.         FreeDiskObject(Disk_Obj);
  171.         Disk_Obj = NIL;
  172.     }
  173.  
  174.     if (IconBase)
  175.     {
  176.         CloseLibrary(IconBase);
  177.         IconBase = NIL;
  178.     }
  179.  
  180.     Program_Lock = Datafile_Lock = NIL;
  181. }
  182.  
  183.