home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / MAXIPC2.ZIP / IPC-2.C next >
C/C++ Source or Header  |  1992-08-11  |  3KB  |  103 lines

  1.  
  2. /*////////////////////////////////////////////////////////////////////////////
  3. //                                                                          //
  4. //  Maximus IPC Creator                                                     //
  5. //  Copyright 1991 by Peter G. Zion.  All rights reserved.                  //
  6. //  Source code may be freely distributed as long as copyright message is   //
  7. //  not removed from this file or the compiled executable.                  //
  8. //                                                                          //
  9. //  Please send OS/2 source updates to 1:157/535.                           //
  10. //                                                                          //
  11. //  minor change to creat() by Bill Bond 1:325/118, 8/11/92 on this date    //
  12. //  1:157/535 was not in the nodelist.                                      //
  13. //                                                                          //
  14. //                                                                          //
  15. ////////////////////////////////////////////////////////////////////////////*/
  16.  
  17.  
  18. #define INCL_DOS
  19. //#include <os2.h>
  20.  
  21.  
  22. #include <io.h>
  23. #include <fcntl.h>
  24. #include <stdio.h>
  25. #include <sys\types.h>
  26. #include <sys/stat.h>
  27.  
  28. #include <share.h>
  29. /*  #include <mem.h>  */
  30. #include <stdlib.h>
  31. #include <string.h>
  32.  
  33. struct Ipc {
  34.  
  35.   int avail;
  36.   char username[36];
  37.   char status[80];
  38.   unsigned msgs_waiting;
  39.   unsigned long next_msgofs;
  40.   unsigned long new_msgofs;
  41.  
  42. };
  43.  
  44. void Write( struct Ipc *ipc, int node ) {
  45.   
  46.   int fp;
  47.   char filename[13] = "IPC00.BBS";
  48.   
  49.   filename[3] = node>>4;
  50.   if( filename[3] > 9 )
  51.     filename[3] += 'A' - 10;
  52.   else
  53.     filename[3] += '0';
  54.   filename[4] = (node&15);
  55.   if( filename[4] > 9 )
  56.     filename[4] += 'A' - 10;
  57.   else
  58.     filename[4] += '0';
  59.   if( (fp = creat( filename, S_IREAD | S_IWRITE)) == -1 ) {
  60.     puts( "Error: Unable to open file for output.\n\r" );
  61.     setmode( fp, O_BINARY );
  62.     return;
  63.   }
  64.   
  65.   write( fp, ipc, sizeof( struct Ipc ) );
  66.   
  67.   close( fp );
  68.   
  69.  
  70. void Ipc( struct Ipc *ipc, int node, char *name, char *stat, int av ) {
  71.  
  72.   memset( ipc, 0, sizeof( struct Ipc ) );
  73.   strncpy( ipc->username, name, 35 );
  74.   strncpy( ipc->status, stat, 79 );
  75.   ipc->avail = av;
  76.   Write( ipc, node );
  77.  
  78. }
  79.  
  80. void main( int argc, char *argv[] ) {
  81.     
  82.   struct Ipc ipc;
  83.   char *user, *status;
  84.   int node;
  85.  
  86.   puts( "\nMaximus IPC creator -- by Peter G. Zion\nCopyright 1991.  All rights reserved.\n" );
  87.     
  88.     if( argc != 4 ) {
  89.     puts( "Usage:\n\tIPC <node number> <user to list> <status>\n\nExample:\n\tIPC 1 \"Mailer\" \"Waiting for call\"");
  90.         return;
  91.     }
  92.     
  93.   node = atoi( argv[1] );
  94.   user = argv[2];
  95.   status = argv[3];
  96.     
  97.   Ipc( &ipc, node, user, status, 0 );
  98.  
  99.   puts( "Done!" );
  100.  
  101. }
  102.