home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / NDK / NDK_3.5 / Examples / Icon / StripIcons.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-30  |  4.0 KB  |  203 lines

  1. /*
  2.  * $Id$
  3.  *
  4.  * :ts=4
  5.  *
  6.  * COPYRIGHT:
  7.  *
  8.  *   Unless otherwise noted, all files are Copyright (c) 1999 Amiga, Inc.
  9.  *   All rights reserved.
  10.  *
  11.  * DISCLAIMER:
  12.  *
  13.  *   This software is provided "as is". No representations or warranties
  14.  *   are made with respect to the accuracy, reliability, performance,
  15.  *   currentness, or operation of this software, and all use is at your
  16.  *   own risk. Neither Amiga nor the authors assume any responsibility
  17.  *   or liability whatsoever with respect to your use of this software.
  18.  *
  19.  */
  20.  
  21. #include <dos/dosextens.h>
  22. #include <dos/dosasl.h>
  23. #include <dos/rdargs.h>
  24.  
  25. #include <exec/memory.h>
  26.  
  27. #include <workbench/workbench.h>
  28.  
  29. #include <clib/exec_protos.h>
  30. #include <clib/utility_protos.h>
  31. #include <clib/dos_protos.h>
  32.  
  33. #include <pragmas/exec_sysbase_pragmas.h>
  34. #include <pragmas/utility_pragmas.h>
  35. #include <pragmas/dos_pragmas.h>
  36.  
  37. #include <string.h>
  38.  
  39. /****************************************************************************/
  40.  
  41. extern struct Library * SysBase;
  42. extern struct Library * DOSBase;
  43. extern struct Library * UtilityBase;
  44. extern struct Library * IconBase;
  45.  
  46. /****************************************************************************/
  47.  
  48. #include <workbench/icon.h>
  49. #include <clib/icon_protos.h>
  50. #include <pragmas/icon_pragmas.h>
  51.  
  52. /****************************************************************************/
  53.  
  54. #define OK (0)
  55. #define SAME (0)
  56.  
  57. /****************************************************************************/
  58.  
  59. #define MAX_PATH_LEN 1024
  60.  
  61. /****************************************************************************/
  62.  
  63. #define FIB_IS_DRAWER(fib)    ((fib)->fib_DirEntryType > 0)
  64. #define FIB_IS_FILE(fib)    ((fib)->fib_DirEntryType < 0)
  65.  
  66. /****************************************************************************/
  67.  
  68. int
  69. main(int argc,char **argv)
  70. {
  71.     struct RDArgs * rda = NULL;
  72.     struct AnchorPath * ap;
  73.     int result = RETURN_FAIL;
  74.     STRPTR * names = NULL;
  75.     BOOL matched = FALSE;
  76.     LONG error = OK;
  77.     STRPTR str;
  78.  
  79.     if(IconBase->lib_Version < 44)
  80.     {
  81.         Printf("Could not open icon.library V44\n");
  82.         goto out;
  83.     }
  84.  
  85.     rda = ReadArgs("FILES/A/M",(LONG *)&names,NULL);
  86.     if(rda == NULL)
  87.     {
  88.         error = IoErr();
  89.         goto out;
  90.     }
  91.  
  92.     ap = AllocVec(sizeof(*ap) + MAX_PATH_LEN,MEMF_ANY);
  93.     if(ap == NULL)
  94.     {
  95.         error = ERROR_NO_FREE_STORE;
  96.         goto out;
  97.     }
  98.  
  99.     while((error == OK) && (str = (*names++)) != NULL)
  100.     {
  101.         memset(ap,0,sizeof(*ap));
  102.  
  103.         ap->ap_BreakBits = SIGBREAKF_CTRL_C;    
  104.         ap->ap_Strlen = MAX_PATH_LEN;
  105.  
  106.         matched = TRUE;
  107.  
  108.         error = MatchFirst(str,ap);
  109.         if(error == OK)
  110.         {
  111.             if(FIB_IS_DRAWER(&ap->ap_Info))
  112.             {
  113.                 ap->ap_Flags |= APF_DODIR;
  114.  
  115.                 error = MatchNext(ap);
  116.                 ap->ap_Flags &= ~APF_DIDDIR;
  117.             }
  118.  
  119.             while(error == OK)
  120.             {
  121.                 STRPTR name;
  122.                 int len;
  123.  
  124.                 name = ap->ap_Buf;
  125.                 len = strlen(name);
  126.  
  127.                 if(len < strlen(".info") || Stricmp(&name[len - strlen(".info")],".info") != SAME)
  128.                 {
  129.                     struct DiskObject * icon;
  130.                     LONG why;
  131.  
  132.                     Printf("Getting icon for \"%s\"... ",name);
  133.                     Flush(Output());
  134.  
  135.                     icon = GetIconTags(name,
  136.                         ICONA_ErrorCode,&why,
  137.                     TAG_DONE);
  138.  
  139.                     if(icon != NULL)
  140.                     {
  141.                         Printf("writing it back... ");
  142.                         Flush(Output());
  143.  
  144.                         if(PutIconTags(name,icon,
  145.                             ICONPUTA_DropNewIconToolTypes,TRUE,
  146.                             ICONPUTA_DropChunkyIconImage,TRUE,
  147.                             ICONPUTA_NotifyWorkbench,TRUE,
  148.                             ICONA_ErrorCode,&why,
  149.                         TAG_DONE))
  150.                         {
  151.                             Printf("ok.\n");
  152.                         }
  153.  
  154.                         FreeDiskObject(icon);
  155.                     }
  156.  
  157.                     if(why != OK)
  158.                     {
  159.                         UBYTE errorString[100];
  160.                         int len;
  161.  
  162.                         Fault(why,NULL,errorString,sizeof(errorString));
  163.  
  164.                         len = strlen(errorString);
  165.                         while(len > 0 && errorString[len-1] == '\n')
  166.                             errorString[--len] = '\0';
  167.  
  168.                         Printf("failed (%s).\n",errorString);
  169.                     }
  170.                 }
  171.  
  172.                 error = MatchNext(ap);
  173.             }
  174.         }
  175.  
  176.         if(error == ERROR_NO_MORE_ENTRIES)
  177.             error = OK;
  178.  
  179.         MatchEnd(ap);
  180.         matched = FALSE;
  181.     }
  182.  
  183.     if(error == OK)
  184.         result = RETURN_OK;
  185.     else if (error == ERROR_BREAK)
  186.         result = RETURN_WARN;
  187.     else
  188.         result = RETURN_ERROR;
  189.  
  190.  out:
  191.  
  192.     if(matched)
  193.         MatchEnd(ap);
  194.  
  195.     FreeVec(ap);
  196.     FreeArgs(rda);
  197.  
  198.     if(error != OK)
  199.         PrintFault(error,FilePart(argv[0]));
  200.  
  201.     return(result);
  202. }
  203.