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