home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / DevCon / Milan_1991 / Devcon91.1 / Libraries / IFFParse / apps / ScreenSave / ScreenSave.c next >
Encoding:
C/C++ Source or Header  |  1992-09-01  |  6.7 KB  |  252 lines

  1. /* ScreenSave
  2.  * Saves front screen as an ILBM
  3.  * Requires linkage with several iffparse modiules - See Makefile
  4.  */ 
  5.  
  6. #include "iffp/ilbmapp.h"
  7.  
  8. #include <intuition/intuitionbase.h>
  9. #include <workbench/workbench.h>
  10.  
  11. #include <clib/icon_protos.h>
  12.  
  13. #ifdef LATTICE
  14. int CXBRK(void) { return(0); }  /* Disable Lattice CTRL/C handling */
  15. int chkabort(void) { return(0); }  /* really */
  16. #endif
  17.  
  18. char *vers = "\0$VER: screensave 37.5";
  19. char *Copyright = 
  20.   "screensave v37.5 - supports new modes - Freely Redistributable";
  21. char *usage =
  22.  "Usage: screensave filename (filename -c[unit] for clipboard)\n" 
  23.  "Options: QUIET, NODELAY, NOICON, SEQUENCE (sequence adds a number to name)\n"
  24.  "Saves front screen after 10-sec delay (unless NODELAY).\n";
  25.  
  26. int mygets(char *s);
  27. void bye(UBYTE *s,int e);
  28. void cleanup(void);
  29.  
  30. struct Library    *IntuitionBase = NULL;
  31. struct Library    *GfxBase = NULL;
  32. struct Library    *IconBase = NULL;
  33. struct Library    *IFFParseBase = NULL;
  34.  
  35. struct ILBMInfo ilbm = {0};
  36.  
  37. BOOL fromWB, Quiet, NoDelay, NoIcon, Sequence;
  38.  
  39.  
  40.  
  41. #define INBUFSZ 128
  42. char nbuf[INBUFSZ];
  43.  
  44. /* Data for project icon for saved ILBM
  45.  *
  46.  */
  47. UWORD ILBMI1Data[] =
  48. {
  49. /* Plane 0 */
  50.     0x0000,0x0000,0x0000,0x0001,0x0000,0x0000,0x0000,0x0003,
  51.     0x0FFF,0xFFFF,0xFFFF,0xFFF3,0x0FFF,0x0000,0x0000,0xFFF3,
  52.     0x0FFC,0x0000,0x0000,0x3FF3,0x0FE0,0x0E80,0xF800,0x07F3,
  53.     0x0F80,0x1C01,0x8C00,0x01F3,0x0F00,0x0001,0x8C00,0x00F3,
  54.     0x0600,0x0000,0x0600,0x0063,0x0600,0x0003,0xBC00,0x0063,
  55.     0x0600,0x0001,0xFC00,0x0063,0x0600,0x0000,0xFC00,0x0063,
  56.     0x0600,0x1FC1,0xFE40,0x0063,0x0600,0x1DC1,0xFE20,0x0063,
  57.     0x0600,0x1CE3,0xFF12,0x0063,0x0F00,0x1CE0,0x004F,0xC0F3,
  58.     0x0F80,0x1CE0,0x002F,0x01F3,0x0FE0,0x0E78,0x423D,0x07F3,
  59.     0x0FFC,0x0000,0x0000,0x3FF3,0x0FFF,0x0000,0x0000,0xFFF3,
  60.     0x0FFF,0xFFFF,0xFFFF,0xFFF3,0x0000,0x0000,0x0000,0x0003,
  61.     0x7FFF,0xFFFF,0xFFFF,0xFFFF,
  62. /* Plane 1 */
  63.     0xFFFF,0xFFFF,0xFFFF,0xFFFE,0xD555,0x5555,0x5555,0x5554,
  64.     0xD000,0x0000,0x0000,0x0004,0xD3FC,0xFFFF,0xFFFF,0x3FC4,
  65.     0xD3C0,0x0000,0x0000,0x03C4,0xD300,0x0100,0xF800,0x00C4,
  66.     0xD300,0x0381,0xFC00,0x00C4,0xD080,0x0701,0xFC00,0x0104,
  67.     0xD180,0xF883,0xFE00,0x0194,0xD181,0xDF80,0x4700,0x0194,
  68.     0xD181,0xDF82,0x0180,0x0194,0xD180,0x6F82,0x00C0,0x0194,
  69.     0xD180,0x0002,0x0020,0x0194,0xD180,0x0000,0x0000,0x0194,
  70.     0xD180,0x0000,0x0002,0x0194,0xD080,0x0000,0xCC46,0xC104,
  71.     0xD300,0x0000,0xCC2F,0x00C4,0xD300,0x0E78,0x883D,0x00C4,
  72.     0xD3C0,0x0000,0x0000,0x03C4,0xD3FC,0xFFFF,0xFFFF,0x3FC4,
  73.     0xD000,0x0000,0x0000,0x0004,0xD555,0x5555,0x5555,0x5554,
  74.     0x8000,0x0000,0x0000,0x0000,
  75. };
  76.  
  77. struct Image ILBMI1 =
  78. {
  79.     0, 0,            /* Upper left corner */
  80.     64, 23, 2,            /* Width, Height, Depth */
  81.     ILBMI1Data,            /* Image data */
  82.     0x0003, 0x0000,        /* PlanePick, PlaneOnOff */
  83.     NULL            /* Next image */
  84. };
  85.  
  86. UBYTE *ILBMTools[] =
  87. {
  88.     "FILETYPE=ILBM",
  89.     NULL
  90. };
  91.  
  92. struct DiskObject ILBMobject =
  93. {
  94.     WB_DISKMAGIC,        /* Magic Number */
  95.     WB_DISKVERSION,        /* Version */
  96.     {                /* Embedded Gadget Structure */
  97.     NULL,            /* Next Gadget Pointer */
  98.     0, 0, 64, 24,        /* Left,Top,Width,Height */
  99.     GADGIMAGE | GADGBACKFILL,    /* Flags */
  100.     RELVERIFY | GADGIMMEDIATE,        /* Activation Flags */
  101.     BOOLGADGET,        /* Gadget Type */
  102.     (APTR)&ILBMI1,    /* Render Image */
  103.     NULL,            /* Select Image */
  104.     NULL,            /* Gadget Text */
  105.     NULL,            /* Mutual Exclude */
  106.     NULL,            /* Special Info */
  107.     0,            /* Gadget ID */
  108.     NULL,            /* User Data */
  109.     },
  110.     WBPROJECT,            /* Icon Type */
  111.     "Display",            /* Default Tool */
  112.     ILBMTools,            /* Tool Type Array */
  113.     NO_ICON_POSITION,        /* Current X */
  114.     NO_ICON_POSITION,        /* Current Y */
  115.     NULL,            /* Drawer Structure */
  116.     NULL,            /* Tool Window */
  117.     0                /* Stack Size */
  118. };
  119.  
  120.  
  121.  
  122. void main(int argc, char **argv)
  123.    {
  124.    struct Screen   *frontScreen;
  125.    LONG        error = 0L, seqlock;
  126.    char         *filename;
  127.    int l, k;
  128.  
  129.    fromWB = (argc==0) ? TRUE : FALSE;
  130.  
  131.  
  132.    if(!(IntuitionBase = OpenLibrary("intuition.library", 0)))
  133.       bye("Can't open intuition library.\n",RETURN_WARN);
  134.       
  135.    if(!(GfxBase = OpenLibrary("graphics.library",0)))
  136.       bye("Can't open graphics library.\n",RETURN_WARN);
  137.  
  138.    if(!(IFFParseBase = OpenLibrary("iffparse.library",0)))
  139.       bye("Can't open iffparse library.\n",RETURN_WARN);
  140.  
  141.    if(!(IconBase = OpenLibrary("icon.library",0)))
  142.       bye("Can't open icon library.\n",RETURN_WARN);
  143.  
  144.    if(!(ilbm.ParseInfo.iff = AllocIFF()))
  145.       bye(IFFerr(IFFERR_NOMEM),RETURN_WARN);
  146.  
  147.    if(argc>1)                 /* Passed filename via command line  */
  148.       {
  149.       if(argv[1][0]=='?') 
  150.         {
  151.         printf("%s\n%s\n",Copyright,usage);
  152.         bye("\n",RETURN_OK);
  153.         }
  154.       else filename = argv[1];
  155.  
  156.       NoDelay = NoIcon = Quiet = Sequence = FALSE;
  157.       for(k=2; k < (argc); k++)
  158.     {
  159.     if(!(stricmp(argv[k],"NODELAY")))    NoDelay  = TRUE;
  160.     else if(!(stricmp(argv[k],"NOICON")))    NoIcon   = TRUE;
  161.     else if(!(stricmp(argv[k],"QUIET")))    Quiet    = TRUE;
  162.     else if(!(stricmp(argv[k],"SEQUENCE")))    Sequence = TRUE;
  163.     }
  164.       if(Sequence)
  165.     {
  166.     for(k=1; k<9999; k++)
  167.         {
  168.         sprintf(nbuf,"%s%04ld",filename,k);
  169.         if(seqlock = Lock(nbuf,ACCESS_READ))    UnLock(seqlock);
  170.         else break;
  171.         }
  172.     filename = nbuf;
  173.     }
  174.       }
  175.    else
  176.       {
  177.       printf("%s\n%s\n",Copyright,usage);
  178.       printf("Enter filename for save: ");
  179.       l = mygets(&nbuf[0]);
  180.  
  181.       if(l==0)                /* No filename - Exit */
  182.          {
  183.          bye("\nScreen not saved, filename required\n",RETURN_FAIL);
  184.          }
  185.       else
  186.          {
  187.          filename = &nbuf[0];
  188.          }
  189.       }
  190.      
  191.    if(!NoDelay)    Delay(500);
  192.  
  193.    Forbid();
  194.    frontScreen  = ((struct IntuitionBase *)IntuitionBase)->FirstScreen;
  195.    Permit();
  196.  
  197.    if(error = screensave(&ilbm, frontScreen,
  198.                 NULL, NULL,
  199.                 filename))
  200.     {
  201.     printf("%s\n",IFFerr(error));
  202.     }
  203.    else
  204.     {
  205.           if(!Quiet) printf("Screen saved as %s... ",filename);
  206.     if((!NoIcon)&&(filename[0]!='-')&&(filename[1]!='c')) /* not clipboard */
  207.         {
  208.               if(!(PutDiskObject(filename,&ILBMobject)))
  209.                 {
  210.                 bye("Error saving icon\n",RETURN_WARN);
  211.                 }
  212.            if(!Quiet) printf("Icon saved\n");
  213.         }
  214.     else if(!Quiet) printf("\n");
  215.           bye("",RETURN_OK);
  216.           }
  217.     }
  218.  
  219.  
  220. void bye(UBYTE *s,int e)
  221.    {
  222.    if(s&&(*s)) printf("%s\n",s);
  223.    if ((fromWB)&&(*s))    /* Wait so user can read messages */
  224.       {
  225.       printf("\nPRESS RETURN TO EXIT\n");
  226.       mygets(&nbuf[0]);
  227.       }
  228.    cleanup();
  229.    exit(e);
  230.    }
  231.  
  232. void cleanup()
  233.    {
  234.    if(ilbm.ParseInfo.iff)    FreeIFF(ilbm.ParseInfo.iff);
  235.  
  236.    if(GfxBase)        CloseLibrary(GfxBase);
  237.    if(IntuitionBase)    CloseLibrary(IntuitionBase);
  238.    if(IconBase)        CloseLibrary(IconBase);
  239.    if(IFFParseBase)    CloseLibrary(IFFParseBase);
  240.    }
  241.  
  242.  
  243. int mygets(char *s)
  244.    {
  245.    int l = 0, max = INBUFSZ - 1;
  246.  
  247.    while (((*s = getchar()) !='\n' )&&(l < max)) s++, l++;
  248.    *s = NULL;
  249.    return(l);
  250.    }
  251.  
  252.