Indentation fix, cleanup.
[AROS.git] / workbench / tools / IconInject / main.c
blobec2ca6f125fe3717617063035202bfbd6344aad2
2 #define DEBUG 0
3 #include <aros/debug.h>
5 #include <proto/exec.h>
6 #include <proto/dos.h>
7 #include <proto/icon.h>
8 #include <workbench/icon.h>
9 #include <stdio.h>
10 #include <string.h>
12 static const char version[] __attribute__((used)) = "\0$VER: IconInject 0.1 (06.03.09) © The AROS Dev Team" ;
14 static
15 const UBYTE iitemplate[] =
16 "SOURCE,"
17 "TARGET,"
18 "IMAGE/S,"
19 "VERBOSE/S";
21 struct ArgList
23 STRPTR sourceIcon;
24 STRPTR targetIcon;
25 IPTR replaceimages;
26 IPTR verbose;
27 } arglist;
29 int main(int argc, char **argv)
31 struct RDArgs *iireadargs;
32 struct ArgList *IIArgList = &arglist;
34 char *IISourceIcon = NULL;
35 char *IITargetIcon = NULL;
37 iireadargs = ReadArgs(iitemplate, (IPTR *)IIArgList, NULL);
38 if (iireadargs)
40 if ((IIArgList->sourceIcon) && (IIArgList->targetIcon))
42 D(bug("[IconInject] Source @ %p, Dest @ %p\n", IIArgList->sourceIcon, IIArgList->targetIcon));
43 D(bug("[IconInject] '%s' -> '%s'\n", IIArgList->sourceIcon, IIArgList->targetIcon));
44 if ((strlen(IIArgList->sourceIcon) > 5) && (strncmp(IIArgList->sourceIcon + strlen(IIArgList->sourceIcon) - 5, ".info",5)))
46 if ((IISourceIcon = AllocVec(strlen(IIArgList->sourceIcon) - 4, MEMF_CLEAR)) != NULL)
47 CopyMem(IIArgList->sourceIcon, IISourceIcon, strlen(IIArgList->sourceIcon) - 5);
49 else
51 /* "TODO: Check if the name is a device and append disk.." */
52 if ((IISourceIcon = AllocVec(strlen(IIArgList->sourceIcon) + 1, MEMF_CLEAR)) != NULL)
53 CopyMem(IIArgList->sourceIcon, IISourceIcon, strlen(IIArgList->sourceIcon) - 5);
56 if ((strlen(IIArgList->targetIcon) > 5) && (strncmp(IIArgList->targetIcon + strlen(IIArgList->targetIcon) - 5, ".info",5)))
58 if ((IITargetIcon = AllocVec(strlen(IIArgList->targetIcon) - 4, MEMF_CLEAR)) != NULL)
59 CopyMem(IIArgList->targetIcon, IITargetIcon, strlen(IIArgList->targetIcon) - 5);
61 else
63 /* "TODO: Check if the name is a device and append disk.." */
64 if ((IITargetIcon = AllocVec(strlen(IIArgList->targetIcon) + 1, MEMF_CLEAR)) != NULL)
65 CopyMem(IIArgList->targetIcon, IITargetIcon, strlen(IIArgList->targetIcon) - 5);
68 if (IISourceIcon && IITargetIcon)
70 struct DiskObject *sourceIconDOB = NULL;
71 struct DiskObject *targetIconDOB = NULL;
72 IPTR tmpGadRender = 0;
73 IPTR tmpSelRender = 0;
75 D(bug("[IconInject] '%s' -> '%s'\n", IISourceIcon, IITargetIcon));
77 sourceIconDOB = GetIconTags
79 IISourceIcon,
80 ICONGETA_FailIfUnavailable, FALSE,
81 TAG_DONE
84 targetIconDOB = GetIconTags
86 IITargetIcon,
87 ICONGETA_FailIfUnavailable, FALSE,
88 TAG_DONE
91 if (sourceIconDOB && targetIconDOB)
93 if (IIArgList->replaceimages)
95 if (IIArgList->verbose)
96 printf("Replacing ICON IMAGERY in %s.info from %s.info\n", IITargetIcon, IISourceIcon);
98 tmpGadRender = (IPTR)targetIconDOB->do_Gadget.GadgetRender;
99 tmpSelRender = (IPTR)targetIconDOB->do_Gadget.SelectRender;
101 targetIconDOB->do_Gadget.GadgetRender = sourceIconDOB->do_Gadget.GadgetRender;
102 targetIconDOB->do_Gadget.SelectRender = sourceIconDOB->do_Gadget.SelectRender;
105 // Update the icon ..
106 PutIconTagList(IITargetIcon, targetIconDOB, NULL);
108 if (IIArgList->replaceimages)
110 targetIconDOB->do_Gadget.GadgetRender = (APTR)tmpGadRender;
111 targetIconDOB->do_Gadget.SelectRender = (APTR)tmpSelRender;
115 // Couldnt obtain one of the Icons ..
118 else
120 //Failed to allocate Icon name buffer(s) ..
123 else
125 //Missing arguments.. display a gui?
126 printf("no args ..\n");
129 if (IISourceIcon) FreeVec(IISourceIcon);
130 if (IITargetIcon) FreeVec(IITargetIcon);
131 return RETURN_OK;