home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / devpl016.zip / PIPESAV.C < prev    next >
Text File  |  1994-02-07  |  4KB  |  152 lines

  1. /******************************************************************
  2.         NMPipe make &  read Function     
  3.         ö─ùp╩▀▓╠▀ô╟é▌ì₧é▌âïü[â`âô
  4.         DosReadé╔éµéΘâtâ@âCâï string(CR/LF) Read    
  5. *******************************************************************/
  6.  
  7.  
  8. #define INCL_DOS
  9. #define INCL_DOSPROCESS
  10. #define INCL_DOSNMPIPES
  11. #include <os2.h>
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <string.h>
  15. #include "pipe.h"
  16.  
  17.  
  18.  
  19. #define    MAXLEN    100
  20. #define    MAXLINE    3000
  21. extern char huge linebf[MAXLINE][MAXLEN+1];
  22. #define LENGTH_STRING  33               /*âXâgâèâôâOé╠Æ╖é│                  */
  23. extern CHAR  szFilename[LENGTH_STRING];   // âåü[âUü[é¬ôⁿù═é╡é╜ filename
  24. extern HWND  hwndFrame;                /*âtâîü[âÇüEâEâBâôâhâEüEânâôâhâï    */
  25. extern disp_flag;            // Timer é┼ò\Īé╖éΘé⌐é╠âtâëâO
  26. extern USHORT  st_len;            // âèü[âhâoâbâtâ@é╠î╗ì▌é╠Æ╖é│.
  27.  
  28.  
  29. // ********** PIPE Define section *****************
  30. #define    NAMEDPIPE    "\\PIPE\\DWP"        // ╕╫▓▒▌─é╞ùÿùpé╖éΘ╩▀▓╠▀û╝
  31. #define    PIPESIZE    512            // ╩▀▓╠▀é¬ôfé½Åoé╖├▐░└╗▓╜▐
  32.  
  33. /*   Pipe mode set         */
  34. USHORT pipeopenmode = PIPE_ACCESS_DUPLEX;
  35. USHORT pipemode = (PIPE_WAIT | PIPE_READMODE_BYTE | PIPE_TYPE_BYTE |    1);
  36.  
  37.  
  38.  
  39. USHORT    server_thread(void)
  40. {
  41. //    HFILE     hf;
  42.     USHORT    cbBytesRead, usError ;
  43.     USHORT    llp,count;
  44.     BYTE     abBuf[512];
  45.  
  46.     HPIPE pipehandle;
  47.     USHORT retval;
  48.     USHORT ii;    // loop counter éµéñdummy
  49.  
  50.  
  51.  
  52.     llp=-1;        // read buffer count reset
  53.     st_len=0;    // read buffer count (save)
  54.     count=0;    // readbuff string position
  55.  
  56.  
  57.     if(retval = DosMakeNmPipe(        // û╝æOòt╩▀▓╠▀é╠ì∞ɼ
  58.             NAMEDPIPE,        // ╩▀▓╠▀û╝é≡ì∞ɼé╖éΘ
  59.             &pipehandle,        // ╩▀▓╠▀é╠╩▌─▐┘
  60.             pipeopenmode,        // PIPE OPEN MODE
  61.             pipemode,        // Pipe mode
  62.             PIPESIZE,        // output buffers
  63.             PIPESIZE,        // input buffers
  64.             1000L            // Time out defult (mS)
  65.             ))
  66.  
  67.           WinMessageBox( HWND_DESKTOP,hwndFrame,(PSZ)"Create",(PSZ)"ERROR",0,MB_OK | MB_ICONEXCLAMATION);
  68.  
  69.  
  70.  
  71. for(;;) {
  72.  
  73.     if(retval = DosConnectNmPipe(        // ╕╫▓▒▌─é¬pipeé≡opené╖éΘé▄é┼æ╥é┬
  74.             pipehandle))
  75.           WinMessageBox( HWND_DESKTOP,hwndFrame,(PSZ)"Connect",(PSZ)"ERROR",0,MB_OK | MB_ICONEXCLAMATION);
  76.  
  77.  
  78.  
  79.  
  80.     for(;;) {
  81.  
  82.     if(llp == -1 ) {
  83.        if (!usError) {
  84.         DosRead(    pipehandle,        /* ╠º▓┘ ╩▌─▐┘     */
  85.                 abBuf,            /* ╩▐»╠º ▒─▐┌╜    */
  86.                 sizeof(abBuf),        /* read ╗▓╜▐     */
  87.                 &cbBytesRead        /* read┌└ ╩▐▓─ ▒─▐┌╜ */
  88.             );    }
  89.        else {
  90.           WinMessageBox( HWND_DESKTOP,hwndFrame,(PSZ)"âpâCâvé⌐éτé╠âfü[â^é╠ô╟é▌ì₧é▌Æåé╔âGâëü[é¬ö¡É╢é╡é▄é╡é╜.",(PSZ)"ERROR",0,MB_OK | MB_ICONEXCLAMATION);   
  91.             }
  92.     if(cbBytesRead == 0 || st_len >= MAXLINE ) break;
  93.         }
  94.  
  95.  
  96.  
  97.  
  98.     /*  É«î`âïü[â`âô    */
  99.  
  100.     for(;;) {
  101.         llp ++;
  102.  
  103.         if(abBuf[llp] == 0x0d || count >= (MAXLEN-1))     {
  104.                 linebf[st_len][count]=0;
  105.                 count=0;
  106.                 disp_flag=1;    // ò\Īì╧é▌âtâëâOé╠âZâbâg
  107.                 st_len++;
  108.                 if(st_len == MAXLINE) st_len--;
  109.                  }
  110.  
  111.         if(llp == cbBytesRead ) { llp=-1; break; }
  112.  
  113.  
  114.         if (abBuf[llp] >= ' ') {    // ' ' ê╚ë║é═û│Äïé╖éΘ
  115.             linebf[st_len][count]=abBuf[llp];
  116.             count ++ ; }
  117.          }
  118.    }
  119.  
  120.  
  121.     if (retval = DosDisConnectNmPipe(     // ╕╫▓▒▌─é╠pipeé≡closeé╖éΘ
  122.             pipehandle))
  123.           WinMessageBox( HWND_DESKTOP,hwndFrame,(PSZ)"DisConnect",(PSZ)"ERROR",0,MB_OK | MB_ICONEXCLAMATION);
  124.  
  125.     for(ii=0;ii != MAXLEN ;ii++)        // *** ïµÉ╪éΦïLìå
  126.         linebf[st_len][ii]='-';
  127.  
  128.  
  129.         disp_flag=1;    // ò\Īì╧é▌âtâëâOé╠âZâbâg
  130.         st_len++;
  131.         if(st_len == MAXLINE) st_len--;
  132.  
  133.  
  134.  
  135.  
  136.  
  137.                WinPostMsg (hwndFrame,
  138.                 WM_SEM1,
  139.                 NULL,
  140.                 NULL);
  141.  
  142.  
  143.     }
  144.  
  145.     DosClose(pipehandle);
  146.  
  147.  
  148.  
  149.     return(st_len);
  150. }
  151.  
  152.