peter@sugar.UUCP (Peter da Silva) (11/15/87)
This is just a quicky program that you can use to convert an icon file from one type to another, or to clear the X and Y co-ordinates of the icon so it can be left to drift around (most useful for disk icons). I've been looking for this for some time. The only example I'd seen was a Basic program (ick). So I just sat down and wrote it. Usage: icon [RESET] [type] file... Do not include the .info in the file name. ---- #include <stdio.h> #include <ctype.h> #include <intuition/intuition.h> #include <workbench/workbench.h> int newtype = NULL; int modify = 0; int reset = 0; int nocare = 0; struct Library *IconBase; main(ac, av) int ac; char **av; { if(match(av[1], "?")) { printf("ICON RESET/S,DISK/S,DRAWER/S,TOOL/S,PROJECT/S,GARBAGE/S,FILE...\n"); exit(0); } if(!(IconBase = OpenLibrary("icon.library", 1))) { printf("Couldn't open icon.library.\n"); exit(20); } while(*++av) { if(match(*av, "DISK")) { modify = 1; newtype = WBDISK; } else if(match(*av, "DRAWER")) { modify = 1; newtype = WBDRAWER; } else if(match(*av, "TOOL")) { modify = 1; newtype = WBTOOL; } else if(match(*av, "PROJECT")) { modify = 1; newtype = WBPROJECT; } else if(match(*av, "GARBAGE")) { modify = 1; newtype = WBGARBAGE; } else if(match(*av, "KICK")) { printf("Cannot modify kickstart icons.\n"); CloseLibrary(IconBase); exit(10); } else if(match(*av, "FORCE")) { nocare = 1; } else if(match(*av, "RESET")) { modify = 1; reset = 1; } else if(match(*av, "FILE")) { ++av; if(!*av) { printf("No file name specified.\n"); CloseLibrary(IconBase); exit(10); } munge(*av); } else munge(*av); } CloseLibrary(IconBase); } static char *typenames[] = { "UNKNOWN", "DISK", "DRAWER", "TOOL", "PROJECT", "GARBAGE", "DEVICE", "KICK", "UNKNOWN" }; munge(file) char *file; { struct DiskObject *GetDiskObject(), *dobj; int errno, newclass, oldclass; fflush(stdout); dobj = GetDiskObject(file); fflush(stdout); if(!dobj) { errno = IoErr(); if(errno) printf("Can't open %s.info -- error %d.\n", file, errno); else printf("Not an icon: %s.info.\n", file); return; } if(modify) { if(reset) dobj->do_CurrentX = dobj->do_CurrentY = NO_ICON_POSITION; if(newtype) { switch(newtype) { case WBDISK: case WBDEVICE: case WBDRAWER: case WBGARBAGE: newclass = WBDRAWER; break; case WBTOOL: case WBPROJECT: newclass = WBTOOL; break; default: newclass = 0; break; } switch(dobj->do_Type) { case WBDISK: case WBDEVICE: case WBDRAWER: case WBGARBAGE: oldclass = WBDRAWER; break; case WBTOOL: case WBPROJECT: oldclass = WBTOOL; break; default: oldclass = 0; break; } if(oldclass != newclass) { printf("I'm not supposed to convert %s to %s.\n", typenames[newtype], typenames[dobj->do_Type]); if(!nocare) { FreeDiskObject(dobj); return 0; } } dobj->do_Type = newtype; } PutDiskObject(file, dobj); } printf("%s -- %s", file, typenames[dobj->do_Type]); if(dobj->do_CurrentX == NO_ICON_POSITION || dobj->do_CurrentY == NO_ICON_POSITION) printf(", free to move.\n"); else printf(" at %d, %d.\n", dobj->do_CurrentX, dobj->do_CurrentY); FreeDiskObject(dobj); } match(s1, s2) char *s1, *s2; { char c1, c2; while(*s1 && *s2) { c1 = *s1; c2 = *s2; if(isupper(c1)) c1 = tolower(c1); if(isupper(c2)) c2 = tolower(c2); if(c1!=c2) break; s1++; s2++; } return !*s1 && !*s2; } -- -- Peter da Silva `-_-' ...!hoptoad!academ!uhnix1!sugar!peter -- Disclaimer: These U aren't mere opinions... these are *values*.