home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: InfoMgt / InfoMgt.zip / MAILMIND.ZOO / NETSEND.C < prev    next >
Text File  |  1992-03-11  |  4KB  |  201 lines

  1. /* netsend.c - send a message
  2.  * Thomas A. Marciniak, M.D. = ytm@nihccpc1.bitnet
  3.  * Division of Cancer Prevention & Control, NCI
  4.  */
  5.  
  6. /* Revision history:
  7.  * 1.01  ytm  02/07/91  prompt for username & msg
  8.  * 1.00  ytm  01/31/91  first release
  9.  */
  10.  
  11. /* Program notes:
  12.  * Current versions are specific for TurboC.
  13.  */
  14.  
  15. #include <local.h>                      /* standard definitions */
  16. #include "netbios.h"
  17.  
  18. /* defines */
  19. #define HELP 1
  20. #define USER_NUM 4                      /* should be username */
  21.  
  22. /* status structure */
  23. #define STATUS_ABORT   100
  24. #define STATUS_UNKNOWN 0xff
  25. #define STATUS_STRUCT struct status
  26. STATUS_STRUCT
  27.   {
  28.   word   wCode;
  29.   string sText;
  30.   };
  31. STATUS_STRUCT aStatus[] =
  32.   {
  33.   {0, "OK"},
  34.   {9, "no local name"},
  35.   {STATUS_ABORT, "aborted"},
  36.   {STATUS_UNKNOWN, "?"}
  37.   };
  38.  
  39. /* globals */
  40. NCB     Ncb;
  41.  
  42. /* function prototypes */
  43. short main(short argc, string argv[]);
  44. string GetsEsc(string sLine);
  45. word NetSend(string sName, string sMsg, short iNbNum);
  46.  
  47. /* main */
  48. short main(short argc, string argv[])
  49. {
  50. boolean bGetInput;
  51. char   caMsg[MAXLINE];
  52. char   caName[NETBIOS_NAME_LEN];
  53. short  i;
  54. word   wStatus = 0;
  55. printf("Netsend v1.01");
  56. if (argc < 2)
  57.   {
  58.   bGetInput = TRUE;
  59.   while (bGetInput)
  60.     {
  61.     printf("\nSend to: ");
  62.     switch (*GetsEsc(caName))
  63.       {
  64.       case ESC:
  65.         wStatus = STATUS_ABORT;
  66.         bGetInput = FALSE;
  67.         break;
  68.       case '\0':
  69.       case '?':
  70.       case HELP:
  71.         printf("\nEnter the user initials of the person ");
  72.         printf("to whom you wish to send a message.");
  73.         printf("\nPress <Esc> to abort");
  74.         break;
  75.       default:
  76.         bGetInput = FALSE;
  77.         break;
  78.       }
  79.     }
  80.   }
  81. else
  82.   {
  83.   strcpy(caName, argv[1]);
  84.   printf("\nSend to: %s", caName);
  85.   }
  86. if (!wStatus && argc < 3)
  87.   {
  88.   bGetInput = TRUE;
  89.   while (bGetInput)
  90.     {
  91.     printf("\nMessage: ");
  92.     switch (*GetsEsc(caMsg))
  93.       {
  94.       case ESC:
  95.         wStatus = STATUS_ABORT;
  96.         bGetInput = FALSE;
  97.         break;
  98.       case '\0':
  99.       case '?':
  100.       case HELP:
  101.         printf("\nEnter the message you wish to send to %s.", caName);
  102.         printf("\nPress <Esc> to abort");
  103.         break;
  104.       default:
  105.         bGetInput = FALSE;
  106.         break;
  107.       }
  108.     }
  109.   }
  110. else
  111.   {
  112.   strcpy(caMsg, argv[2]);
  113.   printf("\nMessage: %s", caMsg);
  114.   }
  115. if (!wStatus)
  116.   wStatus = NetSend(caName, caMsg, (argc > 3) ? atoi(argv[3]) : USER_NUM);
  117. for (i = 0; *(aStatus[i].sText) != '?'; i++)
  118.   if (aStatus[i].wCode == wStatus) break;
  119. printf("\nNetsend status: %s (%d)\n", aStatus[i].sText, Ncb.NCB_CMD_CPLT);
  120. return(i);
  121. } /* main */
  122.  
  123. /* get a string from the console allowing escape */
  124. string GetsEsc(string sLine)
  125. {
  126. boolean   bGetInput = TRUE;
  127. short     iCol, iRow;
  128. short     c;
  129. string    s = sLine;
  130. union REGS Reg;
  131. while (bGetInput)
  132.   {
  133.   GETKEY(c);
  134.   switch (c)
  135.     {
  136.     case BS:
  137.       if (s > sLine)
  138.         {
  139.         Reg.h.ah = 3;
  140.         Reg.h.bh = 0;
  141.         int86(0x10, &Reg, &Reg);
  142.         iCol = --Reg.h.dl;
  143.         iRow = Reg.h.dh;
  144.         Reg.h.ah = 2;
  145.         int86(0x10, &Reg, &Reg);
  146.         putch(' ');
  147.         Reg.h.ah = 2;
  148.         Reg.h.dl = iCol;
  149.         Reg.h.dh = iRow;
  150.         int86(0x10, &Reg, &Reg);
  151.         s--;
  152.         }
  153.       break;
  154.     case CR:
  155.       bGetInput = FALSE;
  156.       break;
  157.     case ESC:
  158.       bGetInput = FALSE;
  159.       s = sLine;
  160.       *s++ = ESC;
  161.       break;
  162.     case F1:
  163.       bGetInput = FALSE;
  164.       s = sLine;
  165.       *s++ = HELP;
  166.       break;
  167.     default:
  168.       if (c >= SPACE && c < DEL)
  169.         {
  170.         putch(c);
  171.         *s++ = c;
  172.         }
  173.       else putch(BELL);
  174.       break;
  175.     }
  176.   }
  177. *s = '\0';
  178. return(sLine);
  179. } /* GetsEsc */
  180.  
  181. /* send a Msg to Name from iNbNum */
  182. word NetSend(string sName, string sMsg, short iNbNum)
  183. {
  184. string s;
  185. memset(&Ncb, 0, sizeof(NCB));
  186. Ncb.NCB_COMMAND = SEND_DATAGRAM_WAIT;
  187. Ncb.NCB_NUM = iNbNum;
  188. strncpy(Ncb.NCB_CALLNAME, sName, NETBIOS_NAME_LEN);
  189. for (s = Ncb.NCB_CALLNAME; s < Ncb.NCB_NAME - 1; s++)
  190.   *s = ((*s) ? toupper(*s) : ' ');
  191. Ncb.NCB_BUFFER = (void far *) sMsg;
  192. Ncb.NCB_LENGTH = strlen(sMsg);
  193. Ncb.NCB_CMD_CPLT = STATUS_UNKNOWN;
  194. _ES = FP_SEG(&Ncb);
  195. _BX = FP_OFF(&Ncb);
  196. _AX = 0x0100;
  197. geninterrupt(0x5c);
  198. return(Ncb.NCB_CMD_CPLT);
  199. } /* NetSend */ 
  200.  
  201.