home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
devpl016.zip
/
PIPESAV.C
< prev
next >
Wrap
Text File
|
1994-02-07
|
4KB
|
152 lines
/******************************************************************
NMPipe make & read Function
ö─ùp╩▀▓╠▀ô╟é▌ì₧é▌âïü[â`âô
DosReadé╔éµéΘâtâ@âCâï string(CR/LF) Read
*******************************************************************/
#define INCL_DOS
#define INCL_DOSPROCESS
#define INCL_DOSNMPIPES
#include <os2.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "pipe.h"
#define MAXLEN 100
#define MAXLINE 3000
extern char huge linebf[MAXLINE][MAXLEN+1];
#define LENGTH_STRING 33 /*âXâgâèâôâOé╠Æ╖é│ */
extern CHAR szFilename[LENGTH_STRING]; // âåü[âUü[é¬ôⁿù═é╡é╜ filename
extern HWND hwndFrame; /*âtâîü[âÇüEâEâBâôâhâEüEânâôâhâï */
extern disp_flag; // Timer é┼ò\Īé╖éΘé⌐é╠âtâëâO
extern USHORT st_len; // âèü[âhâoâbâtâ@é╠î╗ì▌é╠Æ╖é│.
// ********** PIPE Define section *****************
#define NAMEDPIPE "\\PIPE\\DWP" // ╕╫▓▒▌─é╞ùÿùpé╖éΘ╩▀▓╠▀û╝
#define PIPESIZE 512 // ╩▀▓╠▀é¬ôfé½Åoé╖├▐░└╗▓╜▐
/* Pipe mode set */
USHORT pipeopenmode = PIPE_ACCESS_DUPLEX;
USHORT pipemode = (PIPE_WAIT | PIPE_READMODE_BYTE | PIPE_TYPE_BYTE | 1);
USHORT server_thread(void)
{
// HFILE hf;
USHORT cbBytesRead, usError ;
USHORT llp,count;
BYTE abBuf[512];
HPIPE pipehandle;
USHORT retval;
USHORT ii; // loop counter éµéñdummy
llp=-1; // read buffer count reset
st_len=0; // read buffer count (save)
count=0; // readbuff string position
if(retval = DosMakeNmPipe( // û╝æOòt╩▀▓╠▀é╠ì∞ɼ
NAMEDPIPE, // ╩▀▓╠▀û╝é≡ì∞ɼé╖éΘ
&pipehandle, // ╩▀▓╠▀é╠╩▌─▐┘
pipeopenmode, // PIPE OPEN MODE
pipemode, // Pipe mode
PIPESIZE, // output buffers
PIPESIZE, // input buffers
1000L // Time out defult (mS)
))
WinMessageBox( HWND_DESKTOP,hwndFrame,(PSZ)"Create",(PSZ)"ERROR",0,MB_OK | MB_ICONEXCLAMATION);
for(;;) {
if(retval = DosConnectNmPipe( // ╕╫▓▒▌─é¬pipeé≡opené╖éΘé▄é┼æ╥é┬
pipehandle))
WinMessageBox( HWND_DESKTOP,hwndFrame,(PSZ)"Connect",(PSZ)"ERROR",0,MB_OK | MB_ICONEXCLAMATION);
for(;;) {
if(llp == -1 ) {
if (!usError) {
DosRead( pipehandle, /* ╠º▓┘ ╩▌─▐┘ */
abBuf, /* ╩▐»╠º ▒─▐┌╜ */
sizeof(abBuf), /* read ╗▓╜▐ */
&cbBytesRead /* read┌└ ╩▐▓─ ▒─▐┌╜ */
); }
else {
WinMessageBox( HWND_DESKTOP,hwndFrame,(PSZ)"âpâCâvé⌐éτé╠âfü[â^é╠ô╟é▌ì₧é▌Æåé╔âGâëü[é¬ö¡É╢é╡é▄é╡é╜.",(PSZ)"ERROR",0,MB_OK | MB_ICONEXCLAMATION);
}
if(cbBytesRead == 0 || st_len >= MAXLINE ) break;
}
/* É«î`âïü[â`âô */
for(;;) {
llp ++;
if(abBuf[llp] == 0x0d || count >= (MAXLEN-1)) {
linebf[st_len][count]=0;
count=0;
disp_flag=1; // ò\Īì╧é▌âtâëâOé╠âZâbâg
st_len++;
if(st_len == MAXLINE) st_len--;
}
if(llp == cbBytesRead ) { llp=-1; break; }
if (abBuf[llp] >= ' ') { // ' ' ê╚ë║é═û│Äïé╖éΘ
linebf[st_len][count]=abBuf[llp];
count ++ ; }
}
}
if (retval = DosDisConnectNmPipe( // ╕╫▓▒▌─é╠pipeé≡closeé╖éΘ
pipehandle))
WinMessageBox( HWND_DESKTOP,hwndFrame,(PSZ)"DisConnect",(PSZ)"ERROR",0,MB_OK | MB_ICONEXCLAMATION);
for(ii=0;ii != MAXLEN ;ii++) // *** ïµÉ╪éΦïLìå
linebf[st_len][ii]='-';
disp_flag=1; // ò\Īì╧é▌âtâëâOé╠âZâbâg
st_len++;
if(st_len == MAXLINE) st_len--;
WinPostMsg (hwndFrame,
WM_SEM1,
NULL,
NULL);
}
DosClose(pipehandle);
return(st_len);
}