home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 2 / goldfish_vol2_cd1.bin / files / dev / src / amilock / source / login.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-08-03  |  5.8 KB  |  235 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5. #include <exec/ports.h>
  6. #include <exec/memory.h>
  7. #include <exec/types.h>
  8. #include <exec/interrupts.h>
  9. #include <devices/input.h>
  10. #include <intuition/intuition.h>
  11. #include <proto/all.h>
  12. #include <clib/exec_protos.h>
  13. #include <clib/alib_protos.h>
  14. #include <clib/intuition_protos.h>
  15.  
  16.  
  17. #include "headers/global.h"
  18. #include "headers/deamon.h"
  19. #include "headers/talkto_proto.h"
  20. #include "headers/login.h"
  21. #include "headers/error_proto.h"
  22.  
  23. #define MAXPOS    100
  24. #define MAXDISP    22
  25. #define BS    '\b'
  26. #define CR    0xa
  27. #define NL    0xd
  28.  
  29. static const char __Version[]=LOGINVERST;
  30.  
  31. extern void     ButtonSwap(void);
  32. void        INITKillButtons(void);
  33. void        KillButtons(void);
  34. void        FINALRestoreButtons(void);
  35. void        RestoreButtons(void);
  36.  
  37. struct IOStdReq        *inputReqBlk;
  38. struct MsgPort        *inputPort;
  39. struct Interrupt    *inputHandler;
  40. UBYTE            device;
  41.  
  42. void KillButtons() 
  43. {
  44.     inputHandler->is_Code = ButtonSwap;
  45.     inputHandler->is_Data=NULL;
  46.     inputHandler->is_Node.ln_Pri=100;
  47.     inputHandler->is_Node.ln_Name=LOGINVER;
  48.     inputReqBlk->io_Data=(APTR)inputHandler;
  49.     inputReqBlk->io_Command=IND_ADDHANDLER;
  50.     DoIO((struct IORequest *)inputReqBlk);
  51.     
  52. }
  53.  
  54. void INITKillButtons() 
  55. {
  56.     if (inputPort = CreatePort(NULL,NULL)) {
  57.         if (inputHandler=AllocMem(sizeof(struct Interrupt),MEMF_PUBLIC+MEMF_CLEAR)){
  58.             if (inputReqBlk=(struct IOStdReq *)CreateExtIO(inputPort,sizeof(struct IOStdReq))) {
  59.                 if (!(device = OpenDevice("input.device",NULL,(struct IORequest *)inputReqBlk,NULL))) {
  60.                     inputHandler->is_Code = ButtonSwap;
  61.                     inputHandler->is_Data=NULL;
  62.                     inputHandler->is_Node.ln_Pri=100;
  63.                     inputHandler->is_Node.ln_Name=LOGINVER;
  64.                     inputReqBlk->io_Data=(APTR)inputHandler;
  65.                     inputReqBlk->io_Command=IND_ADDHANDLER;
  66.                     DoIO((struct IORequest *)inputReqBlk);
  67.                 }
  68.                 else {
  69.                     Error("Could not open input.device");
  70.                     DeleteExtIO((struct IORequest *)inputReqBlk);
  71.                     exit(10);
  72.                 }
  73.             }
  74.             else {
  75.                 Error("Could not create IORequest");
  76.                 FreeMem(inputHandler,sizeof(struct Interrupt));
  77.                 exit(10);
  78.             }
  79.         }
  80.         else {
  81.             Error("could not allocate interrupt struct Memory");
  82.             DeletePort(inputPort);    
  83.             exit(10);
  84.         }
  85.         
  86.     }
  87.     else {
  88.         Error("could not create message port");
  89.         exit (10);
  90.     }
  91. }
  92.  
  93. void RestoreButtons()
  94. {
  95.     inputReqBlk->io_Data=(APTR)inputHandler;
  96.     inputReqBlk->io_Command=IND_REMHANDLER;
  97.     DoIO((struct IORequest *)inputReqBlk);
  98. }
  99.  
  100. void FINALRestoreButtons()
  101. {
  102.     inputReqBlk->io_Data=(APTR)inputHandler;
  103.     inputReqBlk->io_Command=IND_REMHANDLER;
  104.     DoIO((struct IORequest *)inputReqBlk);
  105.     DeleteExtIO((struct IORequest*)inputReqBlk);
  106.     FreeMem(inputHandler,sizeof(struct Interrupt));
  107.     DeletePort(inputPort);
  108. }
  109.  
  110. #if (DEBUG)
  111.     void main()
  112. #else 
  113.     void __main(argv) 
  114.     char    *argv;
  115. #endif
  116. {
  117.     char            Pass[MAXPOS+1];
  118.     char            DispPass[MAXDISP+1]="                      ";
  119.     char            PPos=0,PPDisp=0;
  120.     unsigned long        Status=-1;
  121.     struct IntuitionBase     *IntuiBase;
  122.     struct Window        *window=NULL;
  123.     void*            address;
  124.     ULONG            class;
  125.     USHORT            key1,key2;
  126.     struct IntuiMessage *    my_message;
  127.     BOOL            accept = FALSE;
  128.     BOOL            PassWord=FALSE;
  129.  
  130.     if (!(IntuiBase = (struct IntuitionBase *)OpenLibrary("intuition.library",NULL))) {
  131.         Error("Cannot Open Intuition.library");
  132.         exit(10);
  133.     }
  134.     
  135.     if (!(window = OpenWindow(&NewWindowStructure1))) {
  136.         Error("cannot Open the Window");
  137.         exit(15);
  138.     }
  139.  
  140.     INITKillButtons();
  141.  
  142.     Gadget2.GadgetText->IText = DispPass;
  143.  
  144.     do {
  145.         SetWindowTitles(window,NULL,LOGINVER);
  146.         PrintIText(window->RPort,&IntuiTextList1,0,0);
  147.  
  148.         ActivateGadget(&Gadget1,window,NULL);
  149.         Gadget1.Flags |= SELECTED;
  150.         RefreshGadgets(&Gadget1,window,NULL);
  151.  
  152.         while (!accept) {
  153.             Wait(1<<window->UserPort->mp_SigBit);
  154.                 while (my_message = (struct IntuiMessage *) GetMsg(window->UserPort )) {
  155.                       class = my_message->Class;      /* Save the IDCMP flag. */
  156.                       address = my_message->IAddress; /* Save the address. */
  157.       
  158.                 key1 = my_message->Code;
  159.                 my_message->Code = 0;
  160.                 key2 = my_message->Qualifier;
  161.                 my_message->Qualifier = 0;
  162.                       ReplyMsg((struct Message*) my_message );
  163.                 
  164.                 if (class==IDCMP_GADGETUP) {
  165.                     if (address == &Gadget2) {
  166.                         PassWord = !PassWord;
  167.                         Gadget1.Flags &= ~SELECTED;
  168.                         RefreshGadgets(&Gadget1,window,NULL);
  169.                     }
  170.                     else if (address == &Gadget1) {
  171.                         PassWord = TRUE;
  172.                         Gadget2.Flags |= SELECTED;
  173.                         Gadget1.Flags &= ~SELECTED;
  174.                         RefreshGadgets(&Gadget1,window,NULL);
  175.                     }
  176.                 }
  177.                 else if (class == IDCMP_GADGETDOWN) {
  178.                     if (address == &Gadget1) {
  179.                         Gadget1.Flags |= SELECTED;
  180.                         Gadget2.Flags &= ~SELECTED;
  181.                         RefreshGadgets(&Gadget1,window,NULL);
  182.                         PassWord = FALSE;
  183.                     }
  184.                 }
  185.                 else if (class == IDCMP_RAWKEY || class == IDCMP_VANILLAKEY) {
  186.                     if (class == IDCMP_RAWKEY) {
  187.                         break;
  188.                     }
  189.                     if (PassWord) {
  190.                         if ((key1 == CR)||(key1 == NL)) {
  191.                             accept = TRUE;
  192.                         }
  193.                         if (isprint(key1)) {
  194.                             if (PPos < MAXPOS) {
  195.                                 Pass[PPos++] = key1;
  196.                                 Pass[PPos] = NULL;
  197.                                 if (PPDisp < MAXDISP) {
  198.                                     DispPass[PPDisp++] = '*';
  199.                                     DispPass[PPDisp] = NULL;
  200.                                 }
  201.                             }
  202.                             else DisplayBeep(NULL);
  203.                         }
  204.                         if (key1 == BS) {
  205.                             if (PPos > 0) {
  206.                                 Pass[--PPos] = NULL;
  207.                                 if (PPDisp > PPos) {
  208.                                     DispPass[--PPDisp] = NULL;
  209.                                 }
  210.                             }
  211.                             else DisplayBeep(NULL);
  212.                         }
  213.                         RefreshGadgets(&Gadget1,window,NULL);
  214.                     }
  215.                 }
  216.                 else if ((class == IDCMP_MOUSEBUTTONS)||(class == IDCMP_INACTIVEWINDOW)) {
  217.                     ActivateGadget(&Gadget1,window,NULL);
  218.                     Gadget1.Flags |= SELECTED;
  219.                     RefreshGadgets(&Gadget1,window,NULL);
  220.                     WindowToFront(window);
  221.                     ActivateWindow(window);
  222.                 }
  223.             }
  224.         }
  225.         RestoreButtons();
  226.         Status = TalkTo(Gadget1SIBuff,Pass,NULL ,LOGIN);
  227.         KillButtons();
  228.         accept = FALSE;
  229.         if (!(Status == OK)) DisplayBeep(NULL);
  230.     } while (!(Status == OK));
  231.     FINALRestoreButtons();
  232.     CloseWindow(window);
  233.     CloseLibrary((struct Library *) IntuiBase);
  234. }
  235.