home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / languages / fpl-v115.lha / FPL / debug / dbsend.c next >
Encoding:
C/C++ Source or Header  |  1994-08-04  |  5.4 KB  |  170 lines

  1. /************************************************************************
  2.  *                FREXX PROGRAMMING LANGUAGE DEBUGGER                *
  3.  ************************************************************************
  4.  
  5.  FPL debugger instruction sender program
  6.  
  7.  ************************************************************************/
  8.  
  9. /************************************************************************
  10.  *                                                                      *
  11.  * fpl.library - A shared library interpreting script langauge.         *
  12.  * Copyright (C) 1992-1994 FrexxWare                                    *
  13.  * Author: Daniel Stenberg                                              *
  14.  *                                                                      *
  15.  * This program is free software; you may redistribute for non          *
  16.  * commercial purposes only. Commercial programs must have a written    *
  17.  * permission from the author to use FPL. FPL is *NOT* public domain!   *
  18.  * Any provided source code is only for reference and for assurance     *
  19.  * that users should be able to compile FPL on any operating system     *
  20.  * he/she wants to use it in!                                           *
  21.  *                                                                      *
  22.  * You may not change, resource, patch files or in any way reverse      *
  23.  * engineer anything in the FPL package.                                *
  24.  *                                                                      *
  25.  * This program is distributed in the hope that it will be useful,      *
  26.  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
  27.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                 *
  28.  *                                                                      *
  29.  * Daniel Stenberg                                                      *
  30.  * Ankdammsgatan 36, 4tr                                                *
  31.  * S-171 43 Solna                                                       *
  32.  * Sweden                                                               *
  33.  *                                                                      *
  34.  * FidoNet 2:201/328    email:dast@sth.frontec.se                       *
  35.  *                                                                      *
  36.  ************************************************************************/
  37.  
  38. #include <dos/dos.h>
  39. #include <exec/execbase.h>
  40. #include <exec/memory.h>
  41. #include <exec/types.h>
  42. #include <exec/ports.h>
  43. #include <proto/dos.h>
  44. #include <proto/exec.h>
  45. #include <stdio.h>
  46. #include <stdlib.h>
  47. #include <string.h>
  48.  
  49. #include "/src/script.h"
  50. #include "debugmail.h"
  51.  
  52. extern struct ExecBase *SysBase;
  53. struct GfxBase *GfxBase=NULL;
  54. struct IntuitionBase *IntuitionBase=NULL;
  55.  
  56. #define TEMPLATE "Send/k,H=Hide/k,S=Show/k,Q=Quit/s,??=Help/s"
  57. struct args {
  58.   char *message;
  59.   char *ignore;
  60.   char *allow;
  61.   int *Quit;
  62.   ULONG as_help;
  63. };
  64.  
  65. struct args argarray;
  66. struct RDArgs *rdargs=NULL;
  67. struct MsgPort *TimerMP=NULL;
  68. struct timerequest *TimerIO=NULL;
  69.  
  70. #define HELPTEXT "\
  71. Usage: FPLdb <COMMAND> [ARGUMENT]\n\n\
  72. Available commands are:\n\
  73. send <string>\n\
  74. hide <function>\n\
  75. show <function>\n\
  76. quit\n\
  77. help\n"
  78.  
  79. void PrintError(DebugRet);
  80. DebugRet SendToDb(long, long, void *);
  81.  
  82. int main()
  83. {
  84.   DebugRet ret;
  85.   if (SysBase->SoftVer>36) {
  86.     if ((rdargs=ReadArgs(TEMPLATE,(LONG *)&argarray,NULL))) {
  87.       if (argarray.as_help) {
  88.         printf(HELPTEXT);
  89.       }
  90.       if (argarray.Quit) {
  91.         ret = SendToDb(MAIL_EXITALL, 0, NULL);
  92.         PrintError(ret);
  93.       }
  94.       if (argarray.message) {
  95.         ret = SendToDb(MAIL_STRING,
  96.                        500,
  97.                        argarray.message);
  98.         if(ret==FPLDB_OK)
  99.           printf("Message sent!\n");
  100.         else
  101.           PrintError(ret);
  102.       }
  103.       if(argarray.ignore || argarray.allow) {
  104.         ret = SendToDb(argarray.ignore?MAIL_HIDE:MAIL_SHOW,
  105.                        500,
  106.                        argarray.ignore?argarray.ignore:argarray.allow);
  107.         if(ret == FPLDB_OK)
  108.           printf("All mails of the type '%s' is now %s!\n",
  109.                  argarray.ignore?argarray.ignore:argarray.allow,
  110.                  argarray.ignore?"ignored":"allowed");
  111.         else
  112.           PrintError(ret);
  113.       }
  114.  
  115.       FreeArgs(rdargs);
  116.  
  117.     } else
  118.       printf("Bad input!\n");
  119.   } else
  120.     printf("Kickstart must be over 36!\n");
  121.   return 0;
  122. }
  123.  
  124. void PrintError(DebugRet error)
  125. {
  126.   char *ErrorStrings[]={
  127.     "OK",
  128.     "Can't ignore that",
  129.     "Unrecognized parameter",
  130.     "Failed to get a system resource",
  131.     "FPLdb isn't running"
  132.   };
  133.   printf("%s!\n", error>=NO_OF_RETCODES?"System error":ErrorStrings[error]);
  134. }
  135.  
  136. DebugRet SendToDb(long subject, long prio, void *data)
  137. {
  138.   DebugRet ret = FPLDB_OK;
  139.   struct Messy mess;
  140.   struct MsgPort *port;
  141.   Forbid();
  142.   port=FindPort(MSGPORT_NAME);
  143.   if (port) {
  144.     struct MsgPort *answerport;
  145.     answerport=CreateMsgPort();
  146.     if (answerport) {
  147.       mess.mess.mn_Length=sizeof(struct Messy);
  148.       mess.mess.mn_ReplyPort=answerport;
  149.       mess.flag = subject;
  150.       mess.data = data;
  151.       mess.prio = prio;
  152.       mess.ret = FPLDB_OK; /* init result code to OK! */
  153.       PutMsg(port, (struct Message *)&mess);
  154.       Permit();
  155.       WaitPort(answerport);
  156.       GetMsg(answerport);
  157.       DeleteMsgPort(answerport);
  158.       ret = mess.ret;
  159.     } else {
  160.       Permit();
  161.       ret = FPLDB_RESOURCE;
  162.     }
  163.   } else {
  164.     Permit();
  165.     ret = FPLDB_NOTALIVE;
  166.   }
  167.   return ret;
  168. }
  169.  
  170.