예제 #1
0
int LocalInteractive( sys_handle fh )
/*******************************/
{
    ULONG  type;
    ULONG  flags;

    //NYI: really should convert fh to sys_handle, but I know that it's
    // a one-to-one mapping
    if( DosQueryHType( fh, &type, &flags ) ) {
        return( 0 );
    }
    if( type == 1 ) {   /* device type */
        return( 1 );
    }
    return( 0 );
}
예제 #2
0
int main(VOID) {

   APIRET   rc                     = NO_ERROR;   /* Return code */

   CHAR     message[256]           = "";         /* Message buffer */

   HFILE    PipeHandle             = NULLHANDLE; /* Pipe handle */

   PIPEINFO PipeBuffer[4]          = {{0}};

   struct   _AVAILDATA  BytesAvail = {0};

   UCHAR    Buffer[200]            = {0};

   ULONG    bytes                  = 0;

   ULONG    Action                 = 0;

   ULONG    PipeState              = 0;

   ULONG    HandType               = 0;

   ULONG    FlagWord               = 0;

   ULONG    BytesRead              = 0;



   rc = DosOpen("\\PIPE\\EXAMPLE", &PipeHandle, &Action, 0, 0, FILE_OPEN,

                OPEN_ACCESS_READWRITE | OPEN_SHARE_DENYREADWRITE |

                OPEN_FLAGS_FAIL_ON_ERROR, NULL);

   if (rc != NO_ERROR) {

      printf("DosOpen error: error code = %u\n", rc);

      return 1;

   }  else printf("Connected to pipe.\n");

   rc = DosQueryHType(PipeHandle, &HandType, &FlagWord);

   if (rc != NO_ERROR) {

      printf("DosQueryHType error: error code = %u\n", rc);

      return 1;

   }  else printf("Handle type value is %u\n", HandType);



   rc = DosPeekNPipe(PipeHandle, Buffer, sizeof(Buffer),

                     &BytesRead, &BytesAvail, &PipeState);

   if (rc != NO_ERROR) {

      printf("DosPeekNPipe error: error code = %u\n", rc);

      return 1;

   }  else printf("Pipe status value is %u\n\n", PipeState);



   printf("Enter message to send to PIPEHOST: ");



   fflush(NULL);   /* Flush above printf out to display */

   gets(message);



   rc = DosWrite(PipeHandle, message, strlen(message), &bytes);

   if (rc != NO_ERROR) {

      printf("DosWrite error: error code = %u\n", rc);

      return 1;

   }



   rc = DosRead(PipeHandle, message, sizeof(message), &bytes);

   if (rc != NO_ERROR) {

      printf("DosRead error: error code = %u\n", rc);

      return 1;

   }



   printf("\nMessage received from PIPEHOST: %s\n\n", message);



   rc = DosClose(PipeHandle);

   /* Should check if (rc != NO_ERROR) here... */



   printf("...Disconnected\n");

   return NO_ERROR;

}
예제 #3
0
int main(int argc, char **argv)
{
    ULONG ulType = 0;
    ULONG ulAttr = 0;
    APIRET rc;
    int i;
    int iMode = MODE_NONE;

    rc = DosQueryHType(0, &ulType, &ulAttr);    //STDIN

    if(!rc)
    {
        ulType &= 0xFF;

        if(ulType == 0 || ulType == 2)  //file or pipe
            iMode |= MODE_IN;
    }

    rc = DosQueryHType(1, &ulType, &ulAttr);    //STDOUT

    if(!rc)
    {
        ulType &= 0xFF;

        if(ulType == 0 || ulType == 2)  //file or pipe
            iMode |= MODE_OUT;
    }

    for(i = 1; i < argc; i++)
    {
        if(argv[i][0] == '-' || argv[i][0] == '/')
        {
            switch(argv[i][1])
            {
                case 'I':
                case 'i':
                    if(argv[i][2] == '-')
                        iMode &= ~MODE_IN;
                    else
                        iMode |= MODE_IN;
                    break;

                case 'o':
                case 'O':
                    if(argv[i][2] == '-')
                        iMode &= ~MODE_OUT;
                    else
                        iMode |= MODE_OUT;
                    break;

                case 'h':
                case 'H':
                case '?':
                    usage();
                    return 0;
            }
        }
    }

    if(!iMode)
    {
        usage();
        return 0;
    }

    rc = init_pm();

    if(rc)
        return -1;

    if(iMode & MODE_IN)
    {
        char *str = ReadPipe(0);

        if(str)
            set_clip(str);

        delete str;
    }

    if(iMode & MODE_OUT)
    {
        char *str = get_clip();

        if(str)
        {
            ULONG  ulWrote = 0;
            rc = DosWrite(1, str, strlen(str), &ulWrote);
        }
    }

    done_pm();

    return rc;
}
예제 #4
0
bool LocalInteractive( sys_handle fh )
/************************************/
{
    APIRET type;
    APIRET flags;

    //NYI: really should convert fh to sys_handle, but I know that it's
    // a one-to-one mapping
#ifdef _M_I86
    if( DosQHandType( fh, &type, &flags ) ) {
#else
    if( DosQueryHType( fh, &type, &flags ) ) {
#endif
        return( false );
    }
    if( type == 1 ) {   /* device type */
        return( true );
    }
    return( false );
}

void LocalGetBuff( char *buff, unsigned size )
/********************************************/
{
    struct _STRINGINBUF length;

    if( size > UCHAR_MAX ) {
        size = UCHAR_MAX;
    }
    length.cb = size;
    length.cchIn = 0;
    if( KbdStringIn( buff, &length, 0, 0 ) ) {
        buff[0] = '\r';
        buff[1] = NULLCHAR;
        return;
    }
    buff[length.cchIn] = NULLCHAR;
}

error_handle LocalRename( const char *from, const char *to )
/**********************************************************/
{
#ifdef _M_I86
    return( StashErrCode( DosMove( from, to, 0 ), OP_LOCAL ) );
#else
    return( StashErrCode( DosMove( from, to ), OP_LOCAL ) );
#endif
}

error_handle LocalMkDir( const char *name )
/*****************************************/
{
#ifdef _M_I86
    return( StashErrCode( DosMkDir( name, 0 ), OP_LOCAL ) );
#else
    return( StashErrCode( DosCreateDir( name, NULL ), OP_LOCAL ) );
#endif
}

error_handle LocalRmDir( const char *name )
/*****************************************/
{
#ifdef _M_I86
    return( StashErrCode( DosRmDir( name, 0 ), OP_LOCAL ) );
#else
    return( StashErrCode( DosDeleteDir( name ), OP_LOCAL ) );
#endif
}

error_handle LocalSetDrv( int drv )
/*********************************/
{
#ifdef _M_I86
    return( StashErrCode( DosSelectDisk( drv + 1 ), OP_LOCAL ) );
#else
    return( StashErrCode( DosSetDefaultDisk( drv + 1 ), OP_LOCAL ) );
#endif
}

int LocalGetDrv( void )
/*********************/
{
    APIRET    drive;
    ULONG     map;

#ifdef _M_I86
    if( DosQCurDisk( &drive, &map ) ) {
#else
    if( DosQueryCurrentDisk( &drive, &map ) ) {
#endif
        return( -1 );
    }
    return( drive - 1 );
}

error_handle LocalSetCWD( const char *name )
/******************************************/
{
#ifdef _M_I86
    return( StashErrCode( DosChDir( name, 0 ), OP_LOCAL ) );
#else
    return( StashErrCode( DosSetCurrentDir( name ), OP_LOCAL ) );
#endif
}

long LocalGetFileAttr( const char *name )
/***************************************/
{
#ifdef _M_I86
    USHORT attr;

    if( DosQFileMode( name, &attr, 0 ) ) {
        return( -1L );
    }
    return( attr );
#else
    FILESTATUS3 fileinfo;

    if( DosQueryPathInfo( name, FIL_STANDARD, &fileinfo, sizeof( fileinfo ) ) ) {
        return( -1L );
    }
    return( fileinfo.attrFile );
#endif
}