home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / IPC-2.ZIP / IPC-2.C next >
C/C++ Source or Header  |  1991-12-02  |  3KB  |  99 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. //                                                                          //
  12. ////////////////////////////////////////////////////////////////////////////*/
  13.  
  14.  
  15. #define INCL_DOS
  16. #include <os2.h>
  17.  
  18.  
  19. #include <io.h>
  20. #include <fcntl.h>
  21. #include <stdio.h>
  22.  
  23. /*  #include <sys/stat.h>  */
  24.  
  25. #include <share.h>
  26. /*  #include <mem.h>  */
  27. #include <stdlib.h>
  28. #include <string.h>
  29.  
  30. struct Ipc {
  31.  
  32.   int avail;
  33.   char username[36];
  34.   char status[80];
  35.   unsigned msgs_waiting;
  36.   unsigned long next_msgofs;
  37.   unsigned long new_msgofs;
  38.  
  39. };
  40.  
  41. void Write( struct Ipc *ipc, int node ) {
  42.   
  43.   int fp;
  44.   char filename[13] = "IPC00.BBS";
  45.   
  46.   filename[3] = node>>4;
  47.   if( filename[3] > 9 )
  48.     filename[3] += 'A' - 10;
  49.   else
  50.     filename[3] += '0';
  51.   filename[4] = (node&15);
  52.   if( filename[4] > 9 )
  53.     filename[4] += 'A' - 10;
  54.   else
  55.     filename[4] += '0';
  56.   if( (fp = creat( filename, O_WRONLY | O_BINARY | O_CREAT )) == -1 ) {
  57.     puts( "Error: Unable to open file for output.\n\r" );
  58.     return;
  59.   }
  60.   
  61.   write( fp, ipc, sizeof( struct Ipc ) );
  62.   
  63.   close( fp );
  64.   
  65.  
  66. void Ipc( struct Ipc *ipc, int node, char *name, char *stat, int av ) {
  67.  
  68.   memset( ipc, 0, sizeof( struct Ipc ) );
  69.   strncpy( ipc->username, name, 35 );
  70.   strncpy( ipc->status, stat, 79 );
  71.   ipc->avail = av;
  72.   Write( ipc, node );
  73.  
  74. }
  75.  
  76. void main( int argc, char *argv[] ) {
  77.     
  78.   struct Ipc ipc;
  79.   char *user, *status;
  80.   int node;
  81.  
  82.   puts( "\nMaximus IPC creator -- by Peter G. Zion\nCopyright 1991.  All rights reserved.\n" );
  83.     
  84.     if( argc != 4 ) {
  85.     puts( "Usage:\n\tIPC <node number> <user to list> <status>\n\nExample:\n\tIPC 1 \"Mailer\" \"Waiting for call\"");
  86.         return;
  87.     }
  88.     
  89.   node = atoi( argv[1] );
  90.   user = argv[2];
  91.   status = argv[3];
  92.     
  93.   Ipc( &ipc, node, user, status, 0 );
  94.  
  95.   puts( "Done!" );
  96.  
  97. }
  98.