home *** CD-ROM | disk | FTP | other *** search
/ Dream 49 / Amiga_Dream_49.iso / amiga / workbench / commodoties / processicon.lha / Source / ProcessIcon.c
C/C++ Source or Header  |  1998-02-06  |  7KB  |  248 lines

  1. #define NAME     "ProcessIcon"
  2. #define REVISION "8"
  3. #define SDI_ENDCODE
  4.  
  5. /* Programmheader
  6.  
  7.     Name:        ProcessIcon
  8.     Author:        SDI
  9.     Distribution:    PD
  10.     Description:    processes .info files
  11.     Compileropts:    -
  12.     Linkeropts:    -l amiga
  13.  
  14.  1.0   01.93.97 : first version
  15.  1.1   03.03.97 : options KILLSTACKSIZE, KILLDEFTOOL, VIEW
  16.  1.2   05.03.97 : added SIT and CIT options
  17.  1.3   29.03.97 : not existing TO produces icon
  18.  1.4   13.06.97 : lots of changes, renamed from CopyIconImage
  19.  1.5   14.06.97 : added more data to VIEW option
  20.  1.6   01.07.97 : fixed problem with DrawerData
  21.  1.7   09.11.97 : added UNSNAP function
  22.  1.8   05.02.98 : IMGSRC became REFICON, added COPYIMAGE instead of autocopy
  23. */
  24.  
  25. #include <proto/dos.h>
  26. #include <proto/icon.h>
  27. #include <proto/exec.h>
  28. #define SDI_TO_ANSI
  29. #include "SDI_ASM_STD_protos.h"
  30. #include "SDI_defines.h"
  31.  
  32. #define PARAM (STRPTR)  "ICON/A,REFICON,VIEW/S,OPT=OPTIMIZE/S,"        \
  33.             "US=UNSNAP/S,"                    \
  34.             "SDT=SETDEFTOOL,SIT=SETICONTYPE,"        \
  35.             "SBP=SETBITPLANES/N,SXP=SETXPOS/N,"        \
  36.             "SYP=SETYPOS/N,"                \
  37.             "KDT=KILLDEFTOOL/S,KTT=KILLTOOLTYPES/S,"    \
  38.             "KSS=KILLSTACKSIZE/S,KDD=KILLDRAWERDATA/S,"    \
  39.             "CDT=COPYDEFTOOL/S,CIT=COPYICONTYPE/S,"        \
  40.             "CTT=COPYTOOLTYPES/S,CDD=COPYDRAWERDATA/S,"    \
  41.             "CII=COPYICONIMAGE/S"
  42.  
  43. struct RDArgs*        rda        = 0;
  44. struct Library *    IconBase    = 0;
  45. ULONG            DosVersion    = 37;
  46. struct DiskObject *    dobj        = 0;
  47. struct DiskObject *    dobjsrc        = 0;
  48. struct DiskObject *    dobjdrw        = 0;
  49.  
  50. STRPTR IconTypeRecog[] = 
  51. {0, "Disk", "Drawer", "Tool", "Project", "Garbage", "Device", "Kick", "AppIcon"};
  52.  
  53. static void testgroup(STRPTR a, ULONG b, ULONG c)
  54. {
  55.   if((a && (b || c)) || (b && c))
  56.   {
  57.     SetIoErr(ERROR_TOO_MANY_ARGS);
  58.     End(RETURN_FAIL);
  59.   }
  60. }
  61.  
  62. static void kill(ULONG a, APTR b)
  63. {
  64.   if(a && *((ULONG *)b))
  65.     *((ULONG *)b) = 0;
  66. }
  67.  
  68. static void set(STRPTR a, APTR b)
  69. {
  70.   if(a)
  71.     *((STRPTR *)b) = a;
  72. }
  73.  
  74. void main(void)
  75. {
  76.   STRPTR empty = 0;
  77.   struct Args {
  78.     STRPTR    icon;
  79.     STRPTR    reficon;
  80.     ULONG    view;
  81.     ULONG    optimize;
  82.     ULONG     unsnap;
  83.     STRPTR    setdeftool;
  84.     STRPTR    seticontype;
  85.     ULONG *    setbitplanes;
  86.     ULONG *    setxpos;
  87.     ULONG *    setypos;
  88.     ULONG    killdeftool;
  89.     ULONG    killtooltypes;
  90.     ULONG    killstacksize;
  91.     ULONG    killdrawerdata;
  92.     ULONG    copydeftool;
  93.     ULONG    copyicontype;
  94.     ULONG    copytooltypes;
  95.     ULONG    copydrawerdata;
  96.     ULONG    copyiconimage;
  97.   } args = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  98.  
  99.   ULONG parerror = 0;
  100.   ULONG s;
  101.  
  102.   if(!(rda = ReadArgs(PARAM, (LONG *) &args, 0)))
  103.     End(RETURN_FAIL);
  104.  
  105.   testgroup(args.setdeftool,    args.killdeftool,    args.copydeftool);
  106.   testgroup(0,            args.killtooltypes,    args.copytooltypes);
  107.   testgroup(args.seticontype,    0,            args.copyicontype);
  108.   testgroup(0,            args.killdrawerdata,    args.copydrawerdata);
  109.  
  110.   if((args.unsnap && (args.setxpos || args.setypos)) || (!args.reficon &&
  111.   (args.copydeftool || args.copytooltypes || args.copyicontype ||
  112.   args.copydrawerdata || args.copyiconimage)))
  113.   {
  114.     SetIoErr(ERROR_TOO_MANY_ARGS);
  115.     End(RETURN_FAIL);
  116.   }
  117.  
  118.   s = strlen(args.icon);
  119.   if(!strncmp(args.icon+s-5, ".info",5))
  120.     args.icon[s-5] = 0;
  121.  
  122.   if(
  123.   !(IconBase = OpenLibrary("icon.library", 37)) ||
  124.   !(dobj = GetDiskObjectNew(args.icon)) ||
  125.   !(dobjdrw = GetDefDiskObject(WBDRAWER)))
  126.     End(RETURN_FAIL);
  127.  
  128.   if(args.view)
  129.   {
  130.     STRPTR *a;
  131.  
  132.     Printf("Name: %s\n SS: %ld\n IT: %s\n BP: %ld,%ld\n SZ: x=%3ld, y=%3ld, w=%3ld, h=%3ld\n DT: (%s) %s\n TT: (%s)\n", args.icon,
  133.       dobj->do_StackSize, IconTypeRecog[dobj->do_Type],
  134.       ((struct Image *)dobj->do_Gadget.GadgetRender)->Depth,
  135.       (dobj->do_Gadget.SelectRender ?
  136.       ((struct Image *)dobj->do_Gadget.SelectRender)->Depth : 0),
  137.       dobj->do_CurrentX, dobj->do_CurrentY, dobj->do_Gadget.Width,
  138.       dobj->do_Gadget.Height,
  139.       (dobj->do_DefaultTool ? "YES" : "NO"), dobj->do_DefaultTool, 
  140.       (dobj->do_ToolTypes ? "YES" : "NO"));
  141.     if((a = (STRPTR *) dobj->do_ToolTypes))
  142.       while(*a)
  143.         Printf("  %s\n", *(a++));
  144.     End(RETURN_OK);
  145.   }
  146.  
  147.   if(args.reficon)
  148.   {
  149.     s = strlen(args.reficon);
  150.     if(!strncmp(args.reficon+s-5, ".info",5))
  151.       args.reficon[s-5] = 0;
  152.     if((dobjsrc = GetDiskObjectNew(args.reficon)))
  153.     {
  154.       if(args.copyiconimage)
  155.       {
  156.         if(dobj->do_CurrentX != NO_ICON_POSITION && dobj->do_CurrentY !=
  157.         NO_ICON_POSITION)
  158.         {
  159.           dobj->do_CurrentX +=
  160.             (dobj->do_Gadget.Width>>1) - (dobjsrc->do_Gadget.Width>>1);
  161.           dobj->do_CurrentY +=
  162.             dobj->do_Gadget.Height - dobjsrc->do_Gadget.Height;
  163.           /* 'down middle position' of gadget should be same after image copy */
  164.         }
  165.         dobj->do_Gadget = dobjsrc->do_Gadget;    /* copy gadget structures */
  166.       }
  167.       if(args.copydeftool)    dobj->do_DefaultTool = dobjsrc->do_DefaultTool;
  168.       if(args.copytooltypes)    dobj->do_ToolTypes = dobjsrc->do_ToolTypes;
  169.       if(args.copyicontype)    dobj->do_Type = dobjsrc->do_Type;
  170.       if(args.copydrawerdata)    dobj->do_DrawerData = dobjsrc->do_DrawerData;
  171.     }
  172.     else
  173.       End(RETURN_FAIL);
  174.   }
  175.  
  176.   if(args.seticontype)
  177.   {
  178.     UBYTE i = 0;
  179.  
  180.     while(++i <= WBAPPICON && stricmp(IconTypeRecog[i], args.seticontype))
  181.       ;
  182.     if(i <= WBAPPICON)
  183.       dobj->do_Type = i;
  184.  
  185.     if(dobj->do_Type == WBDISK || dobj->do_Type == WBGARBAGE ||
  186.        dobj->do_Type == WBDRAWER)
  187.       dobj->do_DrawerData = dobjdrw->do_DrawerData;
  188.   }
  189.  
  190.   if(args.setbitplanes)
  191.   {
  192.     ((struct Image *) dobj->do_Gadget.GadgetRender)->Depth =
  193.     *args.setbitplanes;
  194.     if(dobj->do_Gadget.SelectRender)
  195.       ((struct Image *) dobj->do_Gadget.SelectRender)->Depth =
  196.       *args.setbitplanes;
  197.   }
  198.  
  199.   if(args.setxpos)        dobj->do_CurrentX = *args.setxpos;
  200.   if(args.setypos)        dobj->do_CurrentY = *args.setypos;
  201.   set(args.setdeftool, &dobj->do_DefaultTool);
  202.  
  203.   if(args.killdrawerdata)
  204.   {
  205.     dobj->do_DrawerData = dobjdrw->do_DrawerData;
  206.     if(dobj->do_Type != WBDISK && dobj->do_Type != WBGARBAGE &&
  207.     dobj->do_Type != WBDRAWER)
  208.       dobj->do_DrawerData = 0;
  209.   }
  210.     
  211.   if(args.unsnap)        dobj->do_CurrentX = dobj->do_CurrentY = NO_ICON_POSITION;
  212.  
  213.   if(dobj->do_Type == WBPROJECT || dobj->do_Type == WBTOOL)
  214.   {
  215.     if(!dobj->do_ToolTypes)
  216.       dobj->do_ToolTypes = (char **) ∅
  217.     kill(args.killtooltypes, dobj->do_ToolTypes);
  218.   }
  219.   else
  220.     kill(args.killtooltypes, &dobj->do_ToolTypes);
  221.  
  222.   kill(args.killstacksize, &dobj->do_StackSize);
  223.   kill(args.killdeftool, &dobj->do_DefaultTool);
  224.  
  225.   if(args.optimize)
  226.   {
  227.     if(dobj->do_Type != WBDISK && dobj->do_Type != WBPROJECT)
  228.       dobj->do_DefaultTool = 0;
  229.     if(dobj->do_Type != WBPROJECT && dobj->do_Type != WBTOOL)
  230.       dobj->do_ToolTypes = 0;
  231.     if(dobj->do_Type != WBDISK && dobj->do_Type != WBGARBAGE &&
  232.     dobj->do_Type != WBDRAWER)
  233.       dobj->do_DrawerData = 0;
  234.   }
  235.  
  236.   End(PutDiskObject(args.icon, dobj) ? RETURN_OK : RETURN_FAIL);
  237. }
  238.  
  239. void end(void)
  240. {
  241.   if(dobj)        FreeDiskObject(dobj);
  242.   if(dobjdrw)        FreeDiskObject(dobjdrw);
  243.   if(dobjsrc)        FreeDiskObject(dobjsrc);
  244.   if(IconBase)        CloseLibrary(IconBase);
  245.   if(rda)        FreeArgs(rda);
  246. }
  247.  
  248.