home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d1xx / d137 / sit.lha / Sit / sit.c < prev    next >
C/C++ Source or Header  |  1988-03-20  |  5KB  |  192 lines

  1. /************************************************************
  2.   sit.c  By: Stephen Vermeulen
  3.  
  4.   Copyright (C) 1987 By Stephen Vermeulen
  5.  
  6.   Use this tool to set the type of an icon.
  7.  
  8.   It has the following syntax:
  9.  
  10.       sit file [type] [drawer]
  11.  
  12.   when this is typed, sit will load the file called "file.info"
  13.   and change it to the given type and then resave it under
  14.   the old name to the disk.  The allowable types are:
  15.  
  16.        1 = DISK
  17.        2 = DRAWER
  18.        3 = TOOL
  19.        4 = PROJECT
  20.        5 = GARBAGE
  21.        6 = DEVICE   Say what?????????????????????!!!!!!!!!!!!!!
  22.        7 = KICK
  23. ************************************************************/
  24.  
  25. #include <intuition/intuition.h>
  26. #include <workbench/workbench.h>
  27. #include <stdio.h>
  28. #include <functions.h>
  29.  
  30. #define NO_ICONS       4
  31.  
  32. extern ULONG IconBase;
  33.  
  34. /************************************************************
  35.   The following routine just opens the libraries
  36. ************************************************************/
  37.  
  38. short OpenLibs()
  39. {
  40.   short flags; /* any libraries that do not open get recorded here */
  41.  
  42.   flags = 0;
  43.   IconBase = (ULONG) OpenLibrary("icon.library", 0L);
  44.   if (!IconBase) flags |= NO_ICONS;
  45.   return(flags);
  46. }
  47.  
  48. void CloseLibs(flags)
  49. short flags;
  50. {
  51.   if (!(flags & NO_ICONS))     CloseLibrary(IconBase);
  52. }
  53.  
  54. void main(argc, argv)
  55. short argc;
  56. char *argv[];
  57. {
  58.   short lib_flags, icon_type;
  59.   struct DiskObject *dobj, *drawer_obj;
  60.   struct DrawerData *dd_temp;
  61.  
  62.   if (argc >= 3)
  63.   {
  64.     lib_flags  = OpenLibs();
  65.     if (!lib_flags)
  66.     {
  67.       if (dobj = GetDiskObject(argv[1]))
  68.       {
  69.         sscanf(argv[2], "%d", &icon_type);
  70.         if (icon_type < 1) icon_type = 1;
  71.         if (icon_type > 7) icon_type = 7;
  72.         if ((icon_type == 1) || (icon_type == 2) || (icon_type == 5))
  73.         {
  74.           /*** the user wants to make this icon into a drawer
  75.                or disk or trashcan, so check to see if the
  76.                original is one of these
  77.            ***/
  78.  
  79.            if ((dobj->do_Type == 1) || (dobj->do_Type == 2) || (dobj->do_Type == 5))
  80.            {
  81.              /** ok to proceed **/
  82.              dobj->do_Type = icon_type;
  83.              PutDiskObject(argv[1], dobj);
  84.            }
  85.            else
  86.            {
  87.              /*** we have to read in some extra data from a
  88.                   sample Drawer, disk or trashcan icon to upgrade
  89.                   this icon.
  90.               ***/
  91.  
  92.              if (argc == 4)
  93.              {
  94.                /** correct number of parameters **/
  95.  
  96.                if (drawer_obj = GetDiskObject(argv[3]))
  97.                {
  98.                  if ((drawer_obj->do_Type == 1) ||
  99.                      (drawer_obj->do_Type == 2) ||
  100.                      (drawer_obj->do_Type == 5))
  101.                  {
  102.                    /** if it is the correct type of icon **/
  103.  
  104.                    dd_temp = dobj->do_DrawerData;
  105.                    dobj->do_DrawerData = drawer_obj->do_DrawerData;
  106.                    dobj->do_Type = icon_type;
  107.                    PutDiskObject(argv[1], dobj);
  108.                    dobj->do_DrawerData = dd_temp;
  109.                  }
  110.                  else
  111.                    printf("%s should be a DRAWER, DISK, or TRASHCAN icon!\n", argv[3]);
  112.  
  113.                  FreeDiskObject(drawer_obj);
  114.                }
  115.              }
  116.              else
  117.                printf("You need to supply a drawer icon as a template too\n");
  118.            }
  119.         }
  120.         else
  121.         {
  122.           /*** If the original was a drawer type thing we want to
  123.                dump that structure.
  124.            ***/
  125.  
  126.            dd_temp = dobj->do_DrawerData;
  127.            dobj->do_DrawerData = NULL;
  128.            dobj->do_Type = icon_type;
  129.            PutDiskObject(argv[1], dobj);
  130.            dobj->do_DrawerData = dd_temp;
  131.         }
  132.         FreeDiskObject(dobj);
  133.       }
  134.     }
  135.     CloseLibs(lib_flags);
  136.   }
  137.   else if (argc == 2)
  138.   {
  139.     lib_flags  = OpenLibs();
  140.     if (!lib_flags)
  141.     {
  142.       if (dobj = GetDiskObject(argv[1]))
  143.       {
  144.         printf("Type %d ", dobj->do_Type);
  145.         switch(dobj->do_Type)
  146.         {
  147.           case 1:
  148.             printf("WBDISK\n");
  149.             break;
  150.           case 2:
  151.             printf("WBDRAWER\n");
  152.             break;
  153.           case 3:
  154.             printf("WBTOOL\n");
  155.             break;
  156.           case 4:
  157.             printf("WBPROJECT\n");
  158.             break;
  159.           case 5:
  160.             printf("WBGARBAGE\n");
  161.             break;
  162.           case 6:
  163.             printf("WBDEVICE\n");
  164.             break;
  165.           case 7:
  166.             printf("WBKICK\n");
  167.             break;
  168.           deafult:
  169.             printf("UNKNOWN TYPE\n");
  170.         }
  171.         FreeDiskObject(dobj);
  172.       }
  173.     }
  174.     CloseLibs(lib_flags);
  175.   }
  176.   else
  177.   {
  178.     printf("Syntax is: sit icon [newtype] [drawer|disk|trashcan]\n");
  179.     printf("newtype:  1 = disk     2 = drawer   3 = tool\n");
  180.     printf("          4 = project  5 = garbage  6 = device  7 = kick\n");
  181.     printf("This is version 1.10\n");
  182.     printf("Written and Copyright (C) 1987 by: Stephen Vermeulen\n");
  183.     printf("                                   3635 Utah Dr. N.W.,\n");
  184.     printf("                                   Calgary, Alberta,\n");
  185.     printf("                                   CANADA, T2N 4A6\n");
  186.     printf("\n                                   (403) 282-7990\n");
  187.     printf("\nSupport more Vware, send a donation or a bug report...\n");
  188.     printf("This program may be freely distributed so long as no\n");
  189.     printf("charge is made for such distribution.\n");
  190.   }
  191. }
  192.