home *** CD-ROM | disk | FTP | other *** search
/ BCI NET / BCI NET Dec 94.iso / archives / utilities / misc / iconmonger.lha / source.lha / DoArgs.c next >
Encoding:
C/C++ Source or Header  |  1994-01-10  |  7.4 KB  |  318 lines

  1. #include <exec/types.h>
  2.  
  3. #include <dos/dos.h>
  4. #include <dos/rdargs.h>
  5. #include <dos/dosextens.h>
  6.  
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include <ctype.h>
  11.  
  12. #include <proto/dos.h>
  13. #include <proto/wb.h>
  14. #include <proto/icon.h>
  15. #include <proto/exec.h>
  16. #include <clib/alib_protos.h>
  17.  
  18.  
  19. #include "monger.h"
  20. #include "IconMonger_rev.h"
  21.  
  22. char version[] = VERSTAG;
  23.  
  24. extern struct DosLibrary *DOSBase;
  25.  
  26. parms_t parms;
  27.  
  28. LONG *result = (LONG *)&parms;
  29.  
  30.  
  31. struct RDArgs *rdargs;
  32.  
  33. struct IntuitionBase *IntuitionBase = NULL;
  34. struct GfxBase         *GfxBase        = NULL;
  35. struct Library         *IconBase        = NULL;
  36.  
  37.  
  38. void close_stuff( void )
  39.   {
  40.     if (IntuitionBase) CloseLibrary( (struct Library *)IntuitionBase );
  41.     if (GfxBase      ) CloseLibrary( (struct Library *)GfxBase       );
  42.     if (IconBase     ) CloseLibrary( (struct Library *)IconBase      );
  43.     IntuitionBase = NULL;
  44.     GfxBase      = NULL;
  45.     IconBase      = NULL;
  46.   }
  47.  
  48. BOOL open_stuff( void )
  49.   {
  50.     IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library",33L);
  51.     if(IntuitionBase == NULL) return FALSE;
  52.  
  53.     GfxBase = (struct GfxBase *) OpenLibrary("graphics.library", 33L);
  54.     if(GfxBase == NULL)
  55.     { close_stuff();
  56.       return FALSE;
  57.     }
  58.  
  59.     IconBase = (struct Library *)OpenLibrary("icon.library",33L);
  60.     if (IconBase==NULL) {
  61.     close_stuff();
  62.     return FALSE;
  63.     }
  64.  
  65.     return TRUE;
  66.   }
  67.  
  68. void usage( char *pgmname )
  69.   {
  70.     printf("PROGRAM: " VSTRING );
  71.     printf("by Todd M. Lewis\t\te-mail: Todd_Lewis@unc.edu\n"
  72.        "   2601 Piedmont Drive\n"
  73.        "   Sanford NC 27330-9437  (USA)\n");
  74.     printf("Purpose: makes changes to icons.\n");
  75.     printf("Select icons to change with these parameters:\n");
  76.     printf("  FROM, FILE, ALL, DISKS, TOOLS, DRAWERS, PROJECTS,\n");
  77.     printf("  GARBAGE, OLDIMAGE, OLDTOOL, and OLDSTACK.\n");
  78.     printf("Specify changes to be made with these parameters:\n");
  79.     printf("  UNSNAPSHOT, RECOLOR, NEWIMAGE, NEWTOOL,\n");
  80.     printf("  NEWSTACK, and NEWICON.\n");
  81.     printf("Control messages with QUIET and VERBOSE, and\n");
  82.     printf("use TEST to see what a command would do.\n\n");
  83.   }
  84.  
  85. char *do_TypeStr( UBYTE Type )
  86.   {
  87.     switch( Type )
  88.       {
  89.     case WBDISK   : return "DISK";
  90.     case WBDRAWER : return "DRAWER";
  91.     case WBTOOL   : return "TOOL";
  92.     case WBPROJECT: return "PROJECT";
  93.     case WBGARBAGE: return "GARBAGE";
  94.     case WBDEVICE : return "DEVICE";
  95.     case WBKICK   : return "KICK";
  96.     case WBAPPICON: return "APPICON";
  97.     default       : return "<UNKNOWN>";
  98.       }
  99.   }
  100.  
  101. BOOL study_verbose( void )
  102.   { short count;
  103.     int ch;
  104.  
  105.     if ( ! parms.verbose ) return TRUE;
  106.  
  107.     printf("Find all icons in the %s directory", *(char *)parms.from ? parms.from:"current");
  108.     if ( parms.all )
  109.        printf(" tree");
  110.     if ( parms.file_pat )
  111.        printf("\nwith file names which match the pattern \"%s\"", parms.file_pat );
  112.     count = 0;
  113.     if ( parms.new_icon )
  114.     {
  115.       printf("\nof type %s", do_TypeStr( newicon->do_Type ) );
  116.     }
  117.       else
  118.     {
  119.       if ( parms.disks  )
  120.         {
  121.           count++;
  122.           if (count > 1 ) printf(", DISK");
  123.         else          printf("\nof type DISK");
  124.         }
  125.       if ( parms.drawers  )
  126.         {
  127.           count++;
  128.           if (count > 1 ) printf(", DRAWER");
  129.         else          printf("\nof type DRAWER");
  130.         }
  131.       if ( parms.projects )
  132.         {
  133.           count++;
  134.           if ( count >1 ) printf(", PROJECT");
  135.         else          printf("\nof type PROJECT");
  136.         }
  137.       if ( parms.tools    )
  138.         {
  139.           count++;
  140.           if ( count >1 ) printf(", TOOL");
  141.         else          printf("\nof type TOOL");
  142.         }
  143.       if ( parms.garbage  )
  144.         {
  145.           count++;
  146.           if (count > 1 ) printf(", GARBAGE");
  147.         else          printf("\nof type GARBAGE");
  148.         }
  149.     }
  150.     if ( parms.old_image )
  151.     printf("\nthat look like the icon \"%s\"", parms.old_image );
  152.  
  153.     if ( parms.old_tool_pat )
  154.     printf("\nwith a default tool that matches the pattern \"%s\"",parms.old_tool_pat );
  155.  
  156.     if ( parms.old_stack )
  157.     printf("\nwith a stack setting %s", parms.old_stack );
  158.  
  159.     printf(".\n");
  160.  
  161.     printf("\nFor each of those icons, ");
  162.     if ( parms.new_icon )
  163.       printf("\n * replace the entire icon with a copy of the icon \"%s\",", parms.new_icon );
  164.     if ( parms.unsnapshot )
  165.       printf("\n * unsnapshot it,");
  166.     if ( parms.recolor )
  167.       printf("\n * recolor it (swapping pens 1 and 2),");
  168.     if ( parms.new_image )
  169.       printf("\n * replace its image with the one from the icon \"%s\",", parms.new_image );
  170.     if ( parms.new_tool )
  171.       printf("\n * set its default tool to \"%s\",", parms.new_tool );
  172.     if ( parms.new_stack )
  173.       printf("\n * change its stack setting to %d,", *(ULONG *)parms.new_stack );
  174.     if ( parms.quiet )
  175.       printf("\nChanged icons will not be listed.");
  176.     if ( parms.verbose )
  177.       printf("\nExplanations of how each examined icon meets selection criteria will be listed.\n");
  178.     printf("\n");
  179.  
  180.     if ( parms.test )
  181.       printf("Running in test mode--changes will not be written to disk.\n");
  182.     printf("Continue (y/n)? ");
  183.  
  184.     while ( 1 )
  185.        {
  186.      if ( stop_check() )
  187.        {
  188.          printf("***Break\n");
  189.          return FALSE;
  190.        }
  191.      ch = getch();
  192.      switch( ch )
  193.        {
  194.          case 'y' :
  195.          case 'Y' : printf("Yes\n") ; return TRUE;
  196.          case 'n' :
  197.          case 'N' : printf("No\n");  return FALSE;
  198.        }
  199.        }
  200.   }
  201.  
  202. BOOL study_old_stack( void )
  203.   { char *ch;
  204.     char op[3];
  205.     int  i;
  206.     LONG val = 0;
  207.  
  208.     if ( parms.old_stack==0 ) return TRUE;
  209.  
  210.     ch = (char *)parms.old_stack;
  211.  
  212.     for ( i=0; (i<2) && (*ch) && (isalpha(*ch)); ch++,i++ )
  213.       op[i] = toupper( *ch );
  214.     op[i] = '\0';
  215.  
  216.     for (i=0; *ch; ch++,i++ )
  217.       {
  218.     if ( i > 9 )
  219.         {
  220.           printf("Error: OLDSTACK is too weird.\n");
  221.           goto bad_old_stack_exit;
  222.         }
  223.     if ( ! isdigit(*ch) )
  224.         {
  225.           goto bad_old_stack_exit;
  226.         }
  227.     val = val * 10 + ( *ch - '0' );
  228.       }
  229.  
  230.     /**/ if ( strcmp(op,"LT")==0 )
  231.        {
  232.          parms.old_stack_op  =   1;
  233.          parms.old_stack_val = val;
  234.        }
  235.     else if ( strcmp(op,"LE")==0 )
  236.        {
  237.          parms.old_stack_op  =   1;
  238.          parms.old_stack_val = val+1;
  239.        }
  240.     else if ( strcmp(op,"EQ")==0 || op[0]=='\0' )
  241.        {
  242.          parms.old_stack_op  =   0;
  243.          parms.old_stack_val = val;
  244.        }
  245.     else if ( strcmp(op,"GE")==0 )
  246.        {
  247.          parms.old_stack_op  =  -1;
  248.          parms.old_stack_val = val-1;
  249.        }
  250.     else if ( strcmp(op,"GT")==0 )
  251.        {
  252.          parms.old_stack_op  =  -1;
  253.          parms.old_stack_val = val;
  254.        }
  255.     else   {
  256.          bad_old_stack_exit:
  257.            printf("Error: invalid OLDSTACK specification.\n");
  258.            printf("  use: OLDSTACK [=] [ LT | LE | EQ | GE | GT ]###\n");
  259.            return FALSE;
  260.        }
  261.     return TRUE;
  262.   }
  263.  
  264. int main( int argc, char * argv[] )
  265.   {
  266.     int retcode = 10;
  267.  
  268.     if (DOSBase->dl_lib.lib_Version < 37)
  269.     {
  270.       printf("Sorry, requires dos.library version 37 or above.\n");
  271.       return 1;
  272.     }
  273.  
  274.     if ( argc == 0 )
  275.     {
  276.       printf("Must be run from a CLI.\n");
  277.       return 1;
  278.     }
  279.  
  280.     if ( !open_stuff() )
  281.     return retcode;
  282.  
  283.     if ( argc > 1 && argv[1][0] == '?' )
  284.     usage( argv[0] );
  285.  
  286.     if ( rdargs=(struct RDArgs*)AllocDosObject( DOS_RDARGS,NULL ) )
  287.     {
  288.       if ( ReadArgs( TEMPLATE, result, rdargs ) )
  289.           {
  290.         if ( !parms.from )
  291.             {
  292.               parms.from = "";
  293.             }
  294.         if ( scan_setup() )
  295.           {
  296.             if ( study_old_stack() && study_verbose() )
  297.                {
  298.               retcode = scan_directory( parms.from );
  299.               if ( control_c_hit )
  300.                 printf("***Break\n");
  301.                }
  302.             scan_cleanup();
  303.            }
  304.         FreeArgs( rdargs );
  305.           }
  306.         else
  307.           {
  308.         printf("Bad arguments.\n");
  309.           }
  310.       FreeDosObject( DOS_RDARGS, rdargs );
  311.       rdargs = NULL;
  312.     }
  313.     close_stuff();
  314.     return retcode;
  315.   }
  316.  
  317.  
  318.