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

  1. /*
  2.  *  WOPENON     A companion utility to wIconify that allows you to
  3.  *              specify where windows that are destined for the
  4.  *              Workbench screen should be openned.
  5.  *
  6.  *  Copyright 1990 by Davide P. Cervone, all rights reserved.
  7.  *  You may use this code, provided this copyright notice is kept intact.
  8.  */
  9.  
  10.  
  11. #include <exec/types.h>
  12. #include "wIcon.h"
  13.  
  14. #define USAGE\
  15.    "wOpenOn [ACTIVE_SCREEN | CURRENT_WB | REAL_WB] [[NO]RESIZE]"
  16.  
  17. static char *program = "wOpenOn";
  18. static char *version = "v1.2";
  19. static char *copyright =
  20.    "Copyright (C) 1990 by Davide P. Cervone, all rights reserved.";
  21.  
  22.  
  23. #define ACTIVESCRN      1
  24. #define CURRENTWB       2
  25. #define REALWB          3
  26. #define NOCHANGE        99
  27.  
  28. static int ScreenType = NOCHANGE;
  29. static int Resize     = NOCHANGE;
  30.  
  31.  
  32. #define ARGMATCH(s)     (stricmp(*argv,s) == 0)
  33.  
  34.  
  35. /*
  36.  *  Print()
  37.  *
  38.  *  Find the standard AmigaDOS output file and write the output string
  39.  *  to the output file.  This is intended as a substitute for printf()
  40.  *  when no formatting is required, and when you want a small executable.
  41.  */
  42.  
  43. static void Print(s)
  44. char *s;
  45. {
  46.    ULONG OutFile;
  47.    extern ULONG Output();
  48.    
  49.    OutFile = Output();
  50.    if (OutFile && s) Write(OutFile,s,strlen(s));
  51. }
  52.  
  53.  
  54. /*
  55.  *  ParseArguments()
  56.  *
  57.  *  While there are more arguments to view,
  58.  *    Move to the next one
  59.  *    If it matches something we're looking for, then set the proper variable.
  60.  *    Otherwise, report an error.
  61.  *  Return TRUE if all parameters were OK and at least one was given,
  62.  *    and return FALSE otherwise.
  63.  */
  64.  
  65. static int ParseArguments(argc,argv)
  66. int argc;
  67. char **argv;
  68. {
  69.    int status = TRUE;
  70.    
  71.    while (--argc)
  72.    {
  73.       argv++;
  74.       if (ARGMATCH("ACTIVE_SCREEN")) ScreenType = ACTIVESCRN; else
  75.       if (ARGMATCH("CURRENT_WB"))    ScreenType = CURRENTWB; else
  76.       if (ARGMATCH("REAL_WB"))       ScreenType = REALWB; else
  77.       if (ARGMATCH("RESIZE"))        Resize     = TRUE; else
  78.       if (ARGMATCH("NORESIZE"))      Resize     = FALSE;
  79.       else
  80.       {
  81.          Print("Unrecognized flag '");
  82.          Print(*argv);
  83.          Print("'\n");
  84.          status = FALSE;
  85.       }
  86.    }
  87.    if (ScreenType == NOCHANGE && Resize == NOCHANGE) status = FALSE;
  88.    return(status);
  89. }
  90.  
  91.  
  92. /*
  93.  *  Error()
  94.  *
  95.  *  Print the character string, and up to two optional strings, then
  96.  *  go to a new output line, close Intuition, and exit with an error.
  97.  */
  98.  
  99. static void Error(s,x1)
  100. char *s,*x1;
  101. {
  102.    Print(s);
  103.    if (x1) Print(x1);
  104.    Print("\n");
  105.    _exit(10L);
  106. }
  107.  
  108.  
  109. /*
  110.  *  main()
  111.  *
  112.  *  If all the arguments are OK,
  113.  *    If wIconify is running, set the OpenOn menus appropriately,
  114.  *    Otherwise give an error.
  115.  *  Otherwise show the Usage message.
  116.  */
  117.  
  118. void main(argc,argv)
  119. int argc;
  120. char **argv;
  121. {
  122.    if (ParseArguments(argc,argv))
  123.    {
  124.       if (wIconifyActive()) wSetOpenOn(ScreenType,Resize);
  125.         else Error("wIconify not running or incompatible version",NULL);
  126.    } else Error("Usage:  ",USAGE);
  127. }
  128.