home *** CD-ROM | disk | FTP | other *** search
/ Amiga Elysian Archive / AmigaElysianArchive.iso / screen / shdwmstr.lha / source / savers / guard.c < prev    next >
C/C++ Source or Header  |  1991-12-09  |  4KB  |  148 lines

  1. /*
  2.  * A template for use in building new saver utilities.
  3.  *
  4.  * Copyright 1991, Mike Meyer
  5.  * All Rights Reserved
  6.  *
  7.  * See the file "ShadowMaster:Distribution" for information on distribution.
  8.  *
  9.  * ===build instructions
  10.  * % lc guard ; output= guard.o input= guard.c utilitymain.h
  11.  * % blink guard.o LIB lib:lcr.lib SC SD ; output= guard input=guard.o
  12.  * % copy guard //savers
  13.  * ===endbuild
  14.  *
  15.  * Note: the lib:lcr.lib may not be needed. Try linking without it and see...
  16.  *
  17.  * Basically, the only thing to do is change doutility to run your code, and
  18.  * have it return the name of a blanker to run, or a NULL pointer if it shouldn't
  19.  * run any blanker at all.
  20.  *
  21.  * If you compile this with -dLOOPS, then your code is called multiple times,
  22.  * with a TRUE argument the first time and FALSE thereafter. If your argument
  23.  * is FALSE, your utility routine is expected to wait for the CTRL C, and then
  24.  * return either another name, or a NULL to indicate that we want to stop now.
  25.  * This code will kill the running saver module, and start the one you asked
  26.  * it to start.
  27.  */
  28.  
  29. #include <exec/types.h>
  30. #include <dos/dos.h>
  31. #include <dos/dostags.h>
  32. #include <dos/rdargs.h>
  33. #include <proto/dos.h>
  34. #include <proto/exec.h>
  35.  
  36. char *doutility(int) ;
  37. static void __saveds procend(void) ;
  38.  
  39. struct ExecBase        *SysBase = NULL ;
  40. struct DosLibrary    *DOSBase = NULL ;
  41.  
  42. /* Don't change anything above this point... */
  43.  
  44. /*
  45.  * We use ReadArgs for parsing the arguments. Just define template correctly,
  46.  * and set up the opts array with appropriate names for your code. If you don't
  47.  * want the arguments looked at, comment out the define of template. Change opts
  48.  * to set any defaults you feel need setting.
  49.  */
  50. #define TEMPLATE    "FROM"
  51. static long opts[1] = { 0 };
  52.  
  53. /*
  54.  * Private variables used by the utility.
  55.  */
  56. #define MAXSTRING 200
  57. static char command[MAXSTRING], *args = NULL ;
  58. static int size, corners ;
  59. #define TOP_LEFT    1
  60. #define TOP_RIGHT    2
  61. #define BOTTOM_LEFT    4
  62. #define BOTTOM_RIGHT    8
  63.  
  64. /*
  65.  * The proctags table is here for you to change - to a degree. We expect the
  66.  * Seglist to be first, and CommandName to be second. Your code can rely on
  67.  * (if you want to) Arguments to be third.
  68.  */
  69. struct TagItem proctags[] = {
  70.     {NP_Seglist, 0},
  71.     {NP_CommandName, 0},
  72.     {NP_Arguments, &" "},    /* The space guards against a bug in 2.0 */
  73.     {NP_FreeSeglist, 1},
  74.     {NP_StackSize, 8000},
  75.     {NP_Cli, 1},
  76.     {NP_CopyVars, 0},
  77.     {NP_ExitCode, &procend},
  78.     {TAG_DONE, 0}
  79.     } ;
  80.  
  81. #include "utilitymain.h"
  82. /*
  83.  * You should replace from here down with your own doutility function.
  84.  * Just return the name of the blanker you want run, and we'll do the
  85.  * rest. Note that it's valid to return a pointer to a static data area.
  86.  */
  87. #include <intuition/intuitionbase.h>
  88.  
  89. struct IntuitionBase    *IntuitionBase = NULL ;
  90.  
  91. int LoadFile(char *) ;
  92.  
  93. char *
  94. doutility(int x) {
  95.     int skip_corner ;
  96.  
  97.     if ((IntuitionBase = (struct IntuitionBase *)
  98.         OpenLibrary("intuition.library", 37)) == NULL)
  99.         return NULL ;
  100.  
  101.     if (!LoadFile(*opts ? (char *) *opts : "env:shadowmaster/guard.prefs"))
  102.         return NULL ;
  103.     if (IntuitionBase->FirstScreen->MouseY <= size)
  104.         skip_corner = TOP_LEFT | TOP_RIGHT ;
  105.     else if (IntuitionBase->FirstScreen->Height - IntuitionBase->FirstScreen->MouseY <= size)
  106.         skip_corner = BOTTOM_LEFT | BOTTOM_RIGHT ;
  107.     else skip_corner = 0 ;
  108.  
  109.     if (IntuitionBase->FirstScreen->MouseX <= size)
  110.         skip_corner &= TOP_LEFT | BOTTOM_LEFT ;
  111.     else if (IntuitionBase->FirstScreen->Width - IntuitionBase->FirstScreen->MouseX <= size)
  112.         skip_corner &= TOP_RIGHT | BOTTOM_RIGHT ;
  113.     else skip_corner = 0 ;
  114.  
  115.     CloseLibrary((struct Library *) IntuitionBase) ;
  116.  
  117.     if (args)
  118.         proctags[2].ti_Data = (long) args ;
  119.     if ((skip_corner & corners) == 0) return (char *) command ;
  120.     Wait(SIGBREAKF_CTRL_C) ;
  121.     return NULL ;
  122.     }
  123.  
  124. #include <string.h>
  125. #include <stdlib.h>
  126.  
  127. int
  128. LoadFile(char *file) {
  129.     BPTR fh ;
  130.     char *cp ;
  131.  
  132.     if (!(fh = Open(file, MODE_OLDFILE))) return FALSE ;
  133.     FGets(fh, command, MAXSTRING) ;
  134.     corners = atoi(command) ;
  135.     if (!corners) corners = TOP_LEFT ;
  136.     FGets(fh, command, MAXSTRING) ;
  137.     size = atoi(command) ;
  138.     FGets(fh, command, MAXSTRING) ;
  139.     if (cp = strchr(command, '\n')) *cp = '\0' ;
  140.     if (cp = strchr(command, ' ')) {
  141.         *cp = '\0' ;
  142.         args = cp ;
  143.         }
  144.     Close(fh) ;
  145.  
  146.     return TRUE ;
  147.     }
  148.