home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 3 / goldfish_volume_3.bin / files / util / misc / ascsend / non-mui / irec-source / irec.c < prev    next >
C/C++ Source or Header  |  1995-06-19  |  6KB  |  206 lines

  1. #include "irec.h"
  2.  
  3. /* ------------------------------------------------------------------- */
  4. /*      for cback.o startup */
  5. /* ------------------------------------------------------------------- */
  6.  
  7. long                      __stack        = 4096;
  8. char                      *__procname    = IREC_VERSION;
  9. long                      __priority      = 0L;
  10. long                      __BackGroundIO = 0;
  11. extern BPTR               _Backstdout;
  12.  
  13. struct EasyStruct InfoReq =
  14.        {
  15.         0L,0L,(UBYTE *)"InputEvent Recorder",
  16.               (UBYTE *)IREC_VERSION "\n\nFreeware By Lunqual%%MAB@wsb.freinet.de\n",
  17.               (UBYTE *)"Beenden|Weiter",
  18.        };
  19.  
  20. UBYTE  *version = IREC_VERSION; 
  21. struct NewBroker  newbroker;
  22. CxObj            *broker;  
  23. char            **tooltypes;
  24. struct List       action_list;
  25. UBYTE  rec_start[STRMAXLEN];
  26. UBYTE  rec_stop [STRMAXLEN];
  27. UBYTE  rec_file [STRMAXLEN];
  28. LONG   recording;
  29. ULONG  min_delay;
  30. BYTE   h_priority;
  31. ULONG  i_mb,i_dl;
  32. ULONG  max_on;
  33. ULONG  rec_max;
  34. ULONG  cycle1;
  35.  
  36. long              __OSlibversion = 37;
  37.  
  38. void __stdargs main(int argc,char **argv)
  39. {
  40.  int   end = FALSE;
  41.  NewList(&action_list);
  42.  {
  43.   if(OpenBroker(argc,argv))
  44.   {
  45.    if(init_recorder())
  46.    {
  47.     if(cycle1 && rec_max && max_on)
  48.     {
  49.      Delay(cycle1);
  50.      rec_start_f(rec_max + 1);
  51.      Wait(1L << SigBit);
  52.      rec_stop_f(rec_file);
  53.     }
  54.     else
  55.     {
  56.      while(!end)
  57.      {
  58.       ULONG sgs;
  59.       sgs = Wait((1L << newbroker.nb_Port->mp_SigBit)|(1L << SigBit));
  60.       if(sgs & 1L << SigBit)
  61.       {
  62.        rec_stop_f(rec_file);
  63.       }
  64.       if(HandleBroker() == RETURN_QUIT) end = TRUE;
  65.      }
  66.     }
  67.     exit_recorder();
  68.    }
  69.    CloseBroker();
  70.   }
  71.  }
  72.  exit(0);
  73. }
  74.  
  75. int OpenBroker(int argc,char **argv)
  76. {
  77.  int     ret = FALSE;
  78.  if(newbroker.nb_Port = CreateMsgPort())
  79.  {
  80.   tooltypes = ArgArrayInit(argc,argv);
  81.   newbroker.nb_Version = NB_VERSION;
  82.   newbroker.nb_Name    = "IREC";
  83.   newbroker.nb_Title   = "InputEvent Recorder";
  84.   newbroker.nb_Descr   = "Writes InputEvents to a Textfile";
  85.   newbroker.nb_Unique  = NBU_UNIQUE | NBU_NOTIFY;
  86.   newbroker.nb_Pri     = (BYTE)ArgInt(tooltypes,"CX_PRIORITY",0);
  87.   min_delay            = (ULONG)ArgInt(tooltypes,"MIN_DELAY",25);
  88.   h_priority           = (BYTE)ArgInt(tooltypes,"HANDLER_PRIORITY",60);
  89.   rec_max              = (ULONG)ArgInt(tooltypes,"REC_MAXCHAR",0);
  90.   cycle1               = (ULONG)ArgInt(tooltypes,"WAIT",0);
  91.  
  92.   strncpy(rec_file,ArgString(tooltypes,"RECFILE","ram:irec_file.0"),STRMAXLEN);
  93.   if(!stricmp(ArgString(tooltypes,"INCLUDE_MB","NO"),"YES"))
  94.    i_mb = TRUE;
  95.   else
  96.    i_mb = FALSE;
  97.   if(!stricmp(ArgString(tooltypes,"INCLUDE_DELAY","NO"),"YES"))
  98.    i_dl = TRUE;
  99.   else
  100.    i_dl = FALSE;
  101.  if(!stricmp(ArgString(tooltypes,"REC_MAX_ON","NO"),"YES"))
  102.    max_on = TRUE;
  103.   else
  104.    max_on = FALSE;
  105.  
  106.   if(broker = CxBroker(&newbroker,NULL))
  107.   {
  108.    struct a_node *node;
  109.    if(node  = MakeActionNode(ArgString(tooltypes,"RECSTARTKEY","f4"),NULL,
  110.                                REC_START)) AddTail(&action_list,(struct Node *)node);
  111.    if(node  = MakeActionNode(ArgString(tooltypes,"RECSTOPKEY","shift f4"),NULL,
  112.                                REC_STOP)) AddTail(&action_list,(struct Node *)node);
  113.    ret = TRUE;
  114.   }
  115.  }
  116.  if(ret)ActivateCxObj(broker,1L);
  117.  return ret;
  118. }
  119.  
  120. void CloseBroker()
  121. {
  122.  struct a_node *n;
  123.  struct Message *msg;
  124.  if(broker)
  125.  {
  126.    if(newbroker.nb_Port)
  127.   {
  128.    while(msg = GetMsg(newbroker.nb_Port))ReplyMsg(msg);
  129.    DeletePort(newbroker.nb_Port);
  130.   }
  131.   while(n = (struct a_node *)RemHead(&action_list))RemActionNode(n);
  132.   DeleteCxObjAll(broker);
  133.   if(tooltypes)ArgArrayDone();
  134.  }
  135. }
  136.  
  137. struct a_node *MakeActionNode(UBYTE *key,UBYTE *file,LONG ID)
  138. {
  139.  struct a_node *node;
  140.  if(node = (struct a_node *)AllocVec(sizeof(struct a_node),MEMF_PUBLIC | MEMF_CLEAR))
  141.  {
  142.   strncpy(node->an_action.hotkey,key,STRMAXLEN);
  143.   strncpy(node->an_action.file,file,STRMAXLEN);
  144.   node->an_action.id = ID;
  145.   if(node->an_action.key = CxFilter(node->an_action.hotkey))
  146.   {
  147.    AttachCxObj(broker,node->an_action.key);
  148.    if(node->an_action.sender = CxSender(newbroker.nb_Port,ID))
  149.    {
  150.     AttachCxObj(node->an_action.key,node->an_action.sender);
  151.     if(node->an_action.translate = (CxTranslate(NULL)))
  152.     {
  153.      AttachCxObj(node->an_action.key,node->an_action.translate);
  154.     }
  155.    }
  156.   }
  157.  }
  158.  return node;   
  159. }
  160.  
  161. void  RemActionNode(struct a_node *node)
  162. {
  163.  DeleteCxObjAll(node->an_action.key);
  164.  FreeVec(node); 
  165. }
  166.  
  167. int HandleBroker()
  168. {
  169.  LONG id,type;
  170.  int rc = RETURN_IS_OK;
  171.  CxMsg *msg;
  172.  if(msg = (CxMsg *)GetMsg(newbroker.nb_Port))
  173.  {
  174.   id    = CxMsgID(msg);
  175.   type  = CxMsgType(msg);
  176.   ReplyMsg((struct Message *)msg);
  177.   switch(type)
  178.   {
  179.    case CXM_IEVENT   : switch(id)
  180.                        {
  181.                         case REC_START : rec_start_f((rec_max && max_on) ? rec_max + 1 : 0);
  182.                                          break;
  183.                         case REC_STOP  : rec_stop_f(rec_file);
  184.                                          break;
  185.                        }
  186.                        break;
  187.    case CXM_COMMAND  :
  188.         switch(id)
  189.         {
  190.          case CXCMD_DISABLE   : ActivateCxObj(broker,0L);
  191.                                 break;
  192.          case CXCMD_ENABLE    : ActivateCxObj(broker,1L);
  193.                                 break;
  194.          case CXCMD_KILL      : if(EasyRequest(NULL,&InfoReq,NULL) == 1)rc = RETURN_QUIT;
  195.                                 break;
  196.          case CXCMD_UNIQUE    : rc = RETURN_QUIT;
  197.                                 break; 
  198.          default     : break;
  199.         }
  200.         break;     
  201.    default           : break;
  202.   }
  203.  }
  204.  return rc;
  205. }
  206.