home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d5xx / d562 / clisizer.lha / CLIsizer / cs.c < prev    next >
C/C++ Source or Header  |  1991-11-20  |  4KB  |  151 lines

  1.     /***************************************************************
  2.      *                    CLIsizer v1.0  03/89                     *
  3.      *                    by Torsten Jürgeleit                     *
  4.      *                   for Manx Aztec C v3.6a                    *
  5.      * with   : cc clisizer.c                                      *
  6.      *          ln clisizer.o detach.o -lc                         *
  7.      * Syntax : clisizer xoffset yoffset width height [batch file] *
  8.      *          endcli                                             *
  9.      *     or : clisizer [batch file]                              *
  10.      *          endcli                                             *
  11.      ***************************************************************/
  12.  
  13.     /* Includes */
  14.  
  15. #include <exec/exec.h>
  16. #include <libraries/dos.h>
  17. #include <graphics/gfxbase.h>
  18. #include <intuition/intuition.h>
  19. #define INTUITIONPRIVATE
  20. #include <intuition/intuitionbase.h>
  21. #include <functions.h>
  22.  
  23.     /* Defines */
  24.  
  25. #define MAX_RETRIES        100    /* num of retries for CloseWorkbench() -> needs EndCLI before */
  26. #define DOS_COMMAND_LEN        200
  27.  
  28.     /* Declarations for DETACH (segment list splitting) -> EndCLI possible */
  29.  
  30. LONG _stack        = 0x1000;
  31. LONG _priority     = 0;
  32. LONG _BackGroundIO = 0;
  33. BYTE *_procname    = "CLIsizer1.0";
  34.  
  35.     /* Globals */
  36.  
  37. struct GfxBase        *GfxBase;
  38. struct IntuitionBase    *IntuitionBase;
  39.  
  40. UBYTE dos_command[DOS_COMMAND_LEN];
  41.  
  42.     /* Dummy functions - not used from c.lib */
  43.  
  44. VOID _wb_parse() {}
  45.  
  46.     /* Main */
  47.  
  48.    VOID
  49. main(argc, argv)
  50.    USHORT argc;
  51.    UBYTE  *argv[];
  52. {
  53.    struct Preferences    *prefs;
  54.    struct FileHandle    *file_handle;
  55.    USHORT xoffset, yoffset, width, height, i;
  56.    UBYTE  *file_name = NULL;
  57.    ULONG  ilock;
  58.    BOOL   success = FALSE;
  59.  
  60.    if (GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 0L)) {
  61.       if (IntuitionBase = (struct IntuitionBase *)
  62.                      OpenLibrary("intuition.library", 0L)) {
  63.      if (prefs = (struct Preferences *)AllocMem((ULONG)
  64.             sizeof(struct Preferences), MEMF_PUBLIC | MEMF_CLEAR)) {
  65.         GetPrefs(prefs, (ULONG)sizeof(struct Preferences));
  66.         if (file_handle = Open("NIL:", MODE_NEWFILE)) {
  67.  
  68.            /* needs 0, 1, 4 or 5 command line arguments */
  69.  
  70.            if (argc > 2 && argc < 5 || argc > 6) {
  71.           DisplayBeep(NULL);
  72.            } else {
  73.           if (argc >= 5) {
  74.  
  75.              /* get new dimensions */
  76.  
  77.              xoffset = atoi(argv[1]);
  78.              yoffset = atoi(argv[2]);
  79.              width   = atoi(argv[3]);
  80.              height  = atoi(argv[4]);
  81.  
  82.              /* get script file name */
  83.  
  84.              if (argc == 6) {
  85.             file_name = argv[5];
  86.              }
  87.           } else {
  88.  
  89.              /* get default dimensions */
  90.  
  91.              xoffset   = 0;
  92.              yoffset   = 0;
  93.              width     = GfxBase->NormalDisplayColumns;
  94.              height    = GfxBase->NormalDisplayRows;
  95.  
  96.              /* get script file name */
  97.  
  98.              if (argc == 2) {
  99.             file_name = argv[1];
  100.              }
  101.           }
  102.           sprintf(&dos_command[0],
  103.                    "NewCLI <nil: >nil: con:0/0/%d/%d/NewCLI %s",
  104. /*
  105.                    "NewWSH <nil: >nil: con:0/0/%d/%d/NewWSH %s",
  106. */
  107.                           width, height, file_name);
  108.  
  109.           /* wait for EndCLI to satisfy CloseWorkBench() */
  110.  
  111.           for (i = 0; i < MAX_RETRIES && success == FALSE; i++) {
  112.              if ((success = CloseWorkBench()) == TRUE) {
  113.  
  114.             /* change Workbench and CLI dimensions */
  115.  
  116.             prefs->ViewXOffset      = xoffset;
  117.             prefs->ViewYOffset      = yoffset;
  118.             prefs->ColumnSizeChange = width -
  119.                           GfxBase->NormalDisplayColumns;
  120.             prefs->RowSizeChange    = height -
  121.                          GfxBase->NormalDisplayRows;
  122.             SetPrefs(prefs, (ULONG)sizeof(struct Preferences),
  123.                                      FALSE);
  124.             ilock = LockIBase(0L);
  125.             IntuitionBase->MaxDisplayWidth  = width;
  126.             IntuitionBase->MaxDisplayHeight = 2 * height;
  127.             IntuitionBase->MaxDisplayRow    = 2 * height - 1;
  128.             UnlockIBase(ilock);
  129.             OpenWorkBench();
  130.  
  131.             /* execute NewCLI command */
  132.  
  133.             Execute(&dos_command[0], file_handle, file_handle);
  134.              } else {
  135.             Delay(20L);
  136.              }
  137.           }
  138.           if (success == FALSE) {
  139.              DisplayBeep(NULL);
  140.           }
  141.            }
  142.            Close(file_handle);
  143.         }
  144.         FreeMem(prefs, (ULONG) sizeof(struct Preferences));
  145.      }
  146.      CloseLibrary(IntuitionBase);
  147.       }
  148.       CloseLibrary(GfxBase);
  149.    }
  150. }
  151.