home *** CD-ROM | disk | FTP | other *** search
- #include <exec/types.h>
-
- #include <dos/dos.h>
- #include <dos/rdargs.h>
- #include <dos/dosextens.h>
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <ctype.h>
-
- #include <proto/dos.h>
- #include <proto/wb.h>
- #include <proto/icon.h>
- #include <proto/exec.h>
- #include <clib/alib_protos.h>
-
-
- #include "monger.h"
- #include "IconMonger_rev.h"
-
- char version[] = VERSTAG;
-
- extern struct DosLibrary *DOSBase;
-
- parms_t parms;
-
- LONG *result = (LONG *)&parms;
-
-
- struct RDArgs *rdargs;
-
- struct IntuitionBase *IntuitionBase = NULL;
- struct GfxBase *GfxBase = NULL;
- struct Library *IconBase = NULL;
-
-
- void close_stuff( void )
- {
- if (IntuitionBase) CloseLibrary( (struct Library *)IntuitionBase );
- if (GfxBase ) CloseLibrary( (struct Library *)GfxBase );
- if (IconBase ) CloseLibrary( (struct Library *)IconBase );
- IntuitionBase = NULL;
- GfxBase = NULL;
- IconBase = NULL;
- }
-
- BOOL open_stuff( void )
- {
- IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library",33L);
- if(IntuitionBase == NULL) return FALSE;
-
- GfxBase = (struct GfxBase *) OpenLibrary("graphics.library", 33L);
- if(GfxBase == NULL)
- { close_stuff();
- return FALSE;
- }
-
- IconBase = (struct Library *)OpenLibrary("icon.library",33L);
- if (IconBase==NULL) {
- close_stuff();
- return FALSE;
- }
-
- return TRUE;
- }
-
- void usage( char *pgmname )
- {
- printf("PROGRAM: " VSTRING );
- printf("by Todd M. Lewis\t\te-mail: Todd_Lewis@unc.edu\n"
- " 2601 Piedmont Drive\n"
- " Sanford NC 27330-9437 (USA)\n");
- printf("Purpose: makes changes to icons.\n");
- printf("Select icons to change with these parameters:\n");
- printf(" FROM, FILE, ALL, DISKS, TOOLS, DRAWERS, PROJECTS,\n");
- printf(" GARBAGE, OLDIMAGE, OLDTOOL, and OLDSTACK.\n");
- printf("Specify changes to be made with these parameters:\n");
- printf(" UNSNAPSHOT, RECOLOR, NEWIMAGE, NEWTOOL,\n");
- printf(" NEWSTACK, and NEWICON.\n");
- printf("Control messages with QUIET and VERBOSE, and\n");
- printf("use TEST to see what a command would do.\n\n");
- }
-
- char *do_TypeStr( UBYTE Type )
- {
- switch( Type )
- {
- case WBDISK : return "DISK";
- case WBDRAWER : return "DRAWER";
- case WBTOOL : return "TOOL";
- case WBPROJECT: return "PROJECT";
- case WBGARBAGE: return "GARBAGE";
- case WBDEVICE : return "DEVICE";
- case WBKICK : return "KICK";
- case WBAPPICON: return "APPICON";
- default : return "<UNKNOWN>";
- }
- }
-
- BOOL study_verbose( void )
- { short count;
- int ch;
-
- if ( ! parms.verbose ) return TRUE;
-
- printf("Find all icons in the %s directory", *(char *)parms.from ? parms.from:"current");
- if ( parms.all )
- printf(" tree");
- if ( parms.file_pat )
- printf("\nwith file names which match the pattern \"%s\"", parms.file_pat );
- count = 0;
- if ( parms.new_icon )
- {
- printf("\nof type %s", do_TypeStr( newicon->do_Type ) );
- }
- else
- {
- if ( parms.disks )
- {
- count++;
- if (count > 1 ) printf(", DISK");
- else printf("\nof type DISK");
- }
- if ( parms.drawers )
- {
- count++;
- if (count > 1 ) printf(", DRAWER");
- else printf("\nof type DRAWER");
- }
- if ( parms.projects )
- {
- count++;
- if ( count >1 ) printf(", PROJECT");
- else printf("\nof type PROJECT");
- }
- if ( parms.tools )
- {
- count++;
- if ( count >1 ) printf(", TOOL");
- else printf("\nof type TOOL");
- }
- if ( parms.garbage )
- {
- count++;
- if (count > 1 ) printf(", GARBAGE");
- else printf("\nof type GARBAGE");
- }
- }
- if ( parms.old_image )
- printf("\nthat look like the icon \"%s\"", parms.old_image );
-
- if ( parms.old_tool_pat )
- printf("\nwith a default tool that matches the pattern \"%s\"",parms.old_tool_pat );
-
- if ( parms.old_stack )
- printf("\nwith a stack setting %s", parms.old_stack );
-
- printf(".\n");
-
- printf("\nFor each of those icons, ");
- if ( parms.new_icon )
- printf("\n * replace the entire icon with a copy of the icon \"%s\",", parms.new_icon );
- if ( parms.unsnapshot )
- printf("\n * unsnapshot it,");
- if ( parms.recolor )
- printf("\n * recolor it (swapping pens 1 and 2),");
- if ( parms.new_image )
- printf("\n * replace its image with the one from the icon \"%s\",", parms.new_image );
- if ( parms.new_tool )
- printf("\n * set its default tool to \"%s\",", parms.new_tool );
- if ( parms.new_stack )
- printf("\n * change its stack setting to %d,", *(ULONG *)parms.new_stack );
- if ( parms.quiet )
- printf("\nChanged icons will not be listed.");
- if ( parms.verbose )
- printf("\nExplanations of how each examined icon meets selection criteria will be listed.\n");
- printf("\n");
-
- if ( parms.test )
- printf("Running in test mode--changes will not be written to disk.\n");
- printf("Continue (y/n)? ");
-
- while ( 1 )
- {
- if ( stop_check() )
- {
- printf("***Break\n");
- return FALSE;
- }
- ch = getch();
- switch( ch )
- {
- case 'y' :
- case 'Y' : printf("Yes\n") ; return TRUE;
- case 'n' :
- case 'N' : printf("No\n"); return FALSE;
- }
- }
- }
-
- BOOL study_old_stack( void )
- { char *ch;
- char op[3];
- int i;
- LONG val = 0;
-
- if ( parms.old_stack==0 ) return TRUE;
-
- ch = (char *)parms.old_stack;
-
- for ( i=0; (i<2) && (*ch) && (isalpha(*ch)); ch++,i++ )
- op[i] = toupper( *ch );
- op[i] = '\0';
-
- for (i=0; *ch; ch++,i++ )
- {
- if ( i > 9 )
- {
- printf("Error: OLDSTACK is too weird.\n");
- goto bad_old_stack_exit;
- }
- if ( ! isdigit(*ch) )
- {
- goto bad_old_stack_exit;
- }
- val = val * 10 + ( *ch - '0' );
- }
-
- /**/ if ( strcmp(op,"LT")==0 )
- {
- parms.old_stack_op = 1;
- parms.old_stack_val = val;
- }
- else if ( strcmp(op,"LE")==0 )
- {
- parms.old_stack_op = 1;
- parms.old_stack_val = val+1;
- }
- else if ( strcmp(op,"EQ")==0 || op[0]=='\0' )
- {
- parms.old_stack_op = 0;
- parms.old_stack_val = val;
- }
- else if ( strcmp(op,"GE")==0 )
- {
- parms.old_stack_op = -1;
- parms.old_stack_val = val-1;
- }
- else if ( strcmp(op,"GT")==0 )
- {
- parms.old_stack_op = -1;
- parms.old_stack_val = val;
- }
- else {
- bad_old_stack_exit:
- printf("Error: invalid OLDSTACK specification.\n");
- printf(" use: OLDSTACK [=] [ LT | LE | EQ | GE | GT ]###\n");
- return FALSE;
- }
- return TRUE;
- }
-
- int main( int argc, char * argv[] )
- {
- int retcode = 10;
-
- if (DOSBase->dl_lib.lib_Version < 37)
- {
- printf("Sorry, requires dos.library version 37 or above.\n");
- return 1;
- }
-
- if ( argc == 0 )
- {
- printf("Must be run from a CLI.\n");
- return 1;
- }
-
- if ( !open_stuff() )
- return retcode;
-
- if ( argc > 1 && argv[1][0] == '?' )
- usage( argv[0] );
-
- if ( rdargs=(struct RDArgs*)AllocDosObject( DOS_RDARGS,NULL ) )
- {
- if ( ReadArgs( TEMPLATE, result, rdargs ) )
- {
- if ( !parms.from )
- {
- parms.from = "";
- }
- if ( scan_setup() )
- {
- if ( study_old_stack() && study_verbose() )
- {
- retcode = scan_directory( parms.from );
- if ( control_c_hit )
- printf("***Break\n");
- }
- scan_cleanup();
- }
- FreeArgs( rdargs );
- }
- else
- {
- printf("Bad arguments.\n");
- }
- FreeDosObject( DOS_RDARGS, rdargs );
- rdargs = NULL;
- }
- close_stuff();
- return retcode;
- }
-
-
-