home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d5xx / d500 / wiconify.lha / wIconify / wUtilities.lzh / wIconScreen / wIconScreen.c < prev    next >
C/C++ Source or Header  |  1991-04-19  |  5KB  |  163 lines

  1. /*
  2.  *  WICONSCREEN     A utility that works with WICONIFY to open a new
  3.  *                  wIconify screen of the desired resolution and depth.
  4.  *
  5.  *  Copyright 1990 by Davide P. Cervone, all rights reserved.
  6.  *  You may use this code, provided this copyright notice is kept intact.
  7.  */
  8.  
  9.  
  10. #define INTUITION_PREFERENCES_H             /* don't need 'em */
  11. #include <intuition/intuition.h>
  12. #include "wIcon.h"
  13.  
  14. #define USAGE\
  15.    "wIconScreen [depth] [LORES] [HIRES] [INTERLACE] [HAM]\n           \
  16.                 [[NO]ACTIVATE] [[NO]BEHIND]"
  17.  
  18. static char *program = "wIconScreen";
  19. static char *version = "v1.3";
  20. static char *copyright =
  21.    "Copyright (C) 1990 by Davide P. Cervone, all rights reserved.";
  22.  
  23. #define INTUITION_REV   0L
  24. extern struct IntuitionBase *IntuitionBase;
  25. extern struct IntuitionBase *OpenLibrary();
  26. extern struct Screen *wNewScreen();
  27.  
  28. static UWORD Depth = 2;         /* The number of bitplanes for the screen */
  29. static UWORD Modes = HIRES;     /* The desired resolution and type */
  30. static UWORD Activate;          /* Activate the wIconify window? */
  31. static UWORD Behind;            /* Open the screen behind the others? */
  32.  
  33. #define ARGMATCH(s)     (stricmp(*argv,s) == 0)
  34.  
  35.  
  36. /*
  37.  *  Print()
  38.  *
  39.  *  Find the standard AmigaDOS output file and write the output string
  40.  *  to the output file.  This is intended as a substitute for printf()
  41.  *  when no formatting is required, and when you want a small executable.
  42.  */
  43.  
  44. static void Print(s)
  45. char *s;
  46. {
  47.    ULONG OutFile;
  48.    extern ULONG Output();
  49.    
  50.    OutFile = Output();
  51.    if (OutFile && s) Write(OutFile,s,strlen(s));
  52. }
  53.  
  54.  
  55. /*
  56.  *  ParseArguments()
  57.  *
  58.  *  While there are more arguments to view,
  59.  *    Check if it equals something we are looking for, and if so,
  60.  *      set or unset the proper flag.
  61.  *    If it equals a number, then this is the depth, so check if the
  62.  *      given depth is legal.
  63.  *    If no match is found, the parameter is unknown, so warn the user.
  64.  *  Return TRUE if all arguments matched, FALSE otherwise.
  65.  */
  66.  
  67. static int ParseArguments(argc,argv)
  68. int argc;
  69. char **argv;
  70. {
  71.    int status = TRUE;
  72.    ULONG depth;
  73.    
  74.    while (--argc)
  75.    {
  76.       argv++;
  77.       if (ARGMATCH("HIRES"))      Modes |= HIRES; else
  78.       if (ARGMATCH("LORES"))      Modes &= ~HIRES; else
  79.       if (ARGMATCH("INTERLACE"))  Modes |= LACE; else
  80.       if (ARGMATCH("HAM"))        Modes |= HAM; else
  81.       if (ARGMATCH("ACTIVATE"))   Activate = TRUE; else
  82.       if (ARGMATCH("NOACTIVATE")) Activate = FALSE; else
  83.       if (ARGMATCH("BEHIND"))     Behind = TRUE; else
  84.       if (ARGMATCH("NOBEHIND"))   Behind = FALSE; else
  85.       if (sscanf(*argv,"%lu",&depth) == 1)
  86.       {
  87.          if (depth < 1) depth = 1;
  88.          else if (depth > 5) depth = 5;
  89.          Depth = depth;
  90.       } else {
  91.          Print("Unrecognized flag '");
  92.          Print(*argv);
  93.          Print("'\n");
  94.          status = FALSE;
  95.       }
  96.    }
  97.    return(status);
  98. }
  99.  
  100.  
  101. /*
  102.  *  Error()
  103.  *
  104.  *  Print the character string, and an optional second string, then
  105.  *  go to a new output line, and exit with an error.
  106.  */
  107.  
  108. static void Error(s,x1)
  109. char *s,*x1;
  110. {
  111.    Print(s);
  112.    if (x1) Print(x1);
  113.    Print("\n");
  114.    if (IntuitionBase) CloseLibrary(IntuitionBase);
  115.    _exit(10L);
  116. }
  117.  
  118.  
  119. /*
  120.  *  main()
  121.  *
  122.  *  First parse the argument list.
  123.  *  If all are OK, then
  124.  *    If wIconify is running,
  125.  *      Open the Intuition library.
  126.  *      If succcessful,
  127.  *        Ask wIconify to open a new screen.
  128.  *        If one is openned,
  129.  *          If we are supposed to activate it, do so.
  130.  *          If it should be behind, send it there.
  131.  *        Otherwise, say that one can't be openned.
  132.  *        Close Intuition.
  133.  *      Otherwise say that Intuition can't be openned.
  134.  *    Otherwise say that wIconify is not running.
  135.  *  Otherwise, give the Usage message.
  136.  */
  137.  
  138. void main(argc,argv)
  139. int argc;
  140. char **argv;
  141. {
  142.    struct Screen *theScreen;
  143.  
  144.    if (ParseArguments(argc,argv))
  145.    {
  146.       if (wIconifyActive())
  147.       {
  148.          IntuitionBase = OpenLibrary("intuition.library",INTUITION_REV);
  149.          if (IntuitionBase)
  150.          {
  151.             theScreen = wNewScreen(Depth,Modes);
  152.             if (theScreen)
  153.             {
  154.                if (Activate && theScreen->FirstWindow)
  155.                    ActivateWindow(theScreen->FirstWindow);
  156.                if (Behind) ScreenToBack(theScreen);
  157.             } else Error("Can't open new Iconify screen",NULL);
  158.             CloseLibrary(IntuitionBase);
  159.          } else Error("Can't Open Intuition Library!",NULL);
  160.       } else Error("wIconify not running or incompatible version",NULL);
  161.    } else Error("Usage:  ",USAGE);
  162. }
  163.