home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Misc / JOE_SOUR.LHA / Sources.lha / s!x / olm / olm.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-09  |  4.1 KB  |  192 lines

  1. /************************************************/
  2.                                              /***/
  3. #define REVISION "1.1"                         /***/
  4. #define REVDATE  "13.02.96"                     /***/
  5. #define PROGNAME "OLM"     /***/
  6. #define NAME     "Olm"                 /***/
  7. #define AUTHOR   "Joe Cool"                     /***/
  8.                                              /***/
  9. /************************************************/
  10.  
  11. #include <exec/types.h>
  12. #include <exec/ports.h>
  13. #include <exec/memory.h>
  14. #include <dos/dos.h>
  15. #include <clib/exec_protos.h>
  16. #include <clib/dos_protos.h>
  17. #include <clib/alib_protos.h>
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <string.h>
  21. #include <ctype.h>
  22. #include "aedoor.h"
  23. #include "semis.h"
  24. #include <proto/FileID.h>
  25. static const char VersionTag[] = "\0$VER: "PROGNAME" "REVISION" ("REVDATE")";
  26. #define ws WriteStr
  27.  
  28. void Start(int node);
  29. char *Nodes_get(void);
  30. char *Mainline(void);
  31. char *handleget(void);
  32.  
  33. void main(int argc, char *argv[])
  34. {
  35.     int    Node=0;
  36. if(argc<2)
  37. {
  38.     printf("Sorry, %s must be called from S!X or /X\n",argv[0]);
  39.     exit(0);
  40. }
  41.  
  42. Node=atoi(argv[1]);
  43. Register(Node);
  44.  
  45. XIM_Msg->Command=140;                    
  46. CheckMessage();
  47. SetTaskPri(FindTask(0),atol(XIM_Msg->String));
  48.  
  49. Start(Node);
  50. ShutDown();
  51.  
  52. }
  53.  
  54.  
  55.  
  56.  
  57. void Start(Node)
  58. {
  59.     char    buffer[255],
  60.             mainline[255],
  61.             handle[50],
  62.             arg[4][10],
  63.             *pointer=NULL;
  64.     long    counter=0;
  65.     BOOL    node[10],
  66.             nodeexist=FALSE;
  67.     struct SinglePort *Single=NULL;
  68.     struct MultiPort *MPort;
  69.     BPTR    fileptr=NULL,
  70.             fileptr2=NULL;
  71.  
  72.  
  73.     ws("",1);
  74.     ws("Olm V1.1 ©1996 Joe Cool",0);
  75.     
  76.     SendStrDataCmd(ENVSTAT,"28",0);
  77.     SendStrDataCmd(DT_NAME,"",1);
  78.     strcpy(handle,XIM_Msg->String);
  79.     
  80.     strcpy(buffer,Nodes_get());    
  81.     for (counter=0;counter<10;counter++)
  82.         if (buffer[counter]=='X') node[counter]=TRUE; else node[counter]=FALSE; 
  83.  
  84.     strcpy(buffer,Mainline());
  85.     strcpy(mainline,buffer);
  86.     arg[0][0]=0;
  87.     arg[1][0]=0;
  88.     arg[2][0]=0;
  89.     arg[3][0]=0;
  90.     sscanf(buffer,"%s %10s %10s",arg[0],arg[1],arg[2]);
  91.     strcpy(arg[3],arg[1]);
  92.     
  93.     if (arg[1][0] && isdigit(arg[1][0])) 
  94.         if (atoi(arg[1])<10 && atoi(arg[1])>-1)
  95.             if (node[atoi(arg[1])])
  96.                 nodeexist=TRUE;
  97.     if (!nodeexist) 
  98.     {
  99.         arg[2][0]=0;
  100.         strcpy(arg[1],Prompt(1,"...Node :"));
  101.         if (atoi(arg[1])<10 && atoi(arg[1])>-1 && isdigit(arg[1][0]))
  102.             if (node[atoi(arg[1])])
  103.                 nodeexist=TRUE;
  104.     }
  105.     if (!nodeexist) ShutDown(); 
  106.     if (atoi(arg[1])==Node)
  107.     {
  108.         ws("...Wanna send a olm to yourself?",1);
  109.         ShutDown();
  110.     }
  111.     GetDT(531,"\0");
  112.     MPort=(struct MultiPort *)XIM_Msg->Semi;
  113.     {
  114.         ObtainSemaphore((struct SignalSemaphore *)MPort);
  115.         Single=(struct SinglePort *)MPort->MyNode[atoi(arg[1])].s;
  116.         ReleaseSemaphore((struct SignalSemaphore *)MPort);
  117.     }
  118.  
  119.  
  120.     if (Single->Status==22)
  121.     {
  122.         ws("...Nobody online!",1);
  123.         ShutDown();
  124.     }
  125.     counter=0;
  126.     if (arg[2][0])
  127.     {    
  128.         pointer=strstr(mainline,arg[0]);
  129.         pointer=strstr(pointer,arg[3]);
  130.         pointer++;
  131.         for (;isspace(pointer[0]);pointer++);
  132.         sprintf(buffer,"bbs:node%d/OLM.Message.txt",atoi(arg[1]));
  133.         fileptr = Open( buffer, MODE_READWRITE );
  134.         Seek( fileptr, 0, OFFSET_END );
  135.         sprintf(buffer,"Got OLM from: %s  Node: %d\n",handle,Node);
  136.         FPuts(fileptr, buffer);
  137.         FPuts(fileptr, "\n");
  138.         FPuts(fileptr, pointer );
  139.         FPuts(fileptr, "\n");
  140.         FPuts(fileptr, "\n");
  141.  
  142.         Close(fileptr);
  143.         ws ("...sent successful!",1);
  144.         
  145.  
  146.     }
  147.     else
  148.     {
  149.         ws("",1);
  150.         sprintf(buffer,"t:olmfrom%d",Node);
  151.         DeleteFile( buffer );
  152.         SendStrDataCmd(JH_EF,buffer,0);
  153.         if (XIM_Msg->Data==-1) ShutDown();
  154.         fileptr2 = Open( buffer, MODE_OLDFILE );
  155.         if (!fileptr2) ShutDown();
  156.  
  157.         sprintf(buffer,"bbs:node%d/OLM.Message.txt",atoi(arg[1]));
  158.         fileptr = Open( buffer, MODE_READWRITE );
  159.         Seek( fileptr, 0, OFFSET_END );
  160.         FPuts(fileptr,"\n");
  161.         sprintf(buffer,"Got OLM from: %s  Node: %d\n",handle,Node);
  162.         FPuts(fileptr, buffer);
  163.         FPuts(fileptr, "\n");
  164.         while(FGets(fileptr2, buffer, 200))
  165.         {
  166.             FPuts(fileptr,buffer);
  167.         }
  168.         FPuts(fileptr, "\n");
  169.         Close(fileptr2);
  170.         Close(fileptr);
  171.         sprintf(buffer,"t:olmfrom%d",Node);
  172.         DeleteFile( buffer );
  173.         ws ("",1);
  174.         ws ("",1);
  175.         ws ("OLM sent successful",1);
  176.                     
  177.     }
  178.         
  179. ShutDown();        
  180.  
  181. }
  182. char *Nodes_get(void)
  183. {
  184.     SendStrDataCmd(ACTIVE_NODES,"",0);
  185.     return(XIM_Msg->String);
  186. }
  187. char *Mainline(void)
  188. {
  189.     SendStrDataCmd(BB_MAINLINE,"",0);
  190.     return(XIM_Msg->String);
  191. }
  192.