/*

  small program to lock a public screen until ctrl-c is pressed

  written by Dominic Clifton - hydrasmail@usa.net - http://come.to/dominicc

*/

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#include <exec/exec.h>
#include <clib/exec_protos.h>

#include <dos/dos.h>

#include <intuition/intuition.h>
#include <clib/intuition_protos.h>

void main(int argc,char **argv)
{
  struct Library *IntuitionBase;
  struct Screen *myscreen;
  int retval=0;
  BOOL QuietMode = FALSE;

  if (argc >= 2)
  {
    if (argc == 3)
    {
      if (stricmp(argv[2],"QUIET")==0) QuietMode=TRUE;
    }

    if (IntuitionBase = OpenLibrary("intuition.library",34))
    {
      if (!(myscreen = LockPubScreen(argv[1])))
      {
        if (!QuietMode) printf("could not lock public screen by the name of \"%s\"",argv[1]);
        retval=5;
      }
      else
      {
        if (!QuietMode) printf("locked public screen \"%s\", press Ctrl+C to unlock it..",argv[1]);
        flushall();
        Wait(SIGBREAKF_CTRL_C);
        if (!QuietMode) puts("unlocked!");
        UnlockPubScreen(NULL,myscreen);
      }
      CloseLibrary((struct Library *)IntuitionBase);
    }
  }
  else
  {
    puts("LockPubScreen: SCREENNAME,QUIET/K\n"
         "This program will lock a publicscreen if it's open\n"
         "It can be used with a program called \"opener\" to open\n"
         "and close public screens too!\n"
         "Written by Dominic Clifton, hydrasmail@usa.net, http://come.to/dominicc");
    retval = 20;
  }
  exit(retval);
}
