HP3000-L Archives

August 2002, Week 2

HP3000-L@RAVEN.UTC.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Peter Smithson <[log in to unmask]>
Reply To:
Peter Smithson <[log in to unmask]>
Date:
Fri, 9 Aug 2002 08:31:44 -0500
Content-Type:
text/plain
Parts/Attachments:
text/plain (141 lines)
 On Fri, 09 Aug 2002 10:27:18 GMT, [log in to unmask]
(Peter Smithson) wrote:

>On Thu, 8 Aug 2002 14:46:24 -0500 (Central Daylight Time), Keven
>Miller <[log in to unmask]> wrote:
>
>>I had forgotten how to use fdevicecontrol, 192.
>>You need to specify param2 to a valid value of
>>1 read, 2 write, 3 both.
>>(See intrinsic manual, FDEVICECONTROL, code=192, parm2;
>> which follows all parm1 definitions)
>>
>
>Thanks - that works great.  Not sure why the following code doesn't
>work but life is too short sometimes! -

The saga continues -

It works if you use CCXL at the CI prompt.  I normally work at the ksh
prompt and use c89.  Compiled with c89 the behaviour is quite
different.  When you hit the 2nd EOR character, all the previous input
is discarded and getchar returns -1 (EOF).

Somebody suggested using an intrinsic rather than getchar previously.
Trouble is, READX or READ return even if there is no data there.

About an hour later  - think I've cracked it.  The following code will
get the terminal type, demonstrating that characters are not lost (the
problem with most solutions) and you can type either <CR> or 'x' as
the end of record character (EOR).  Had to avoid using getchar() to
get it to work with c89.

$ cat Z.c
#include <stdio.h>

#pragma intrinsic READX
#pragma intrinsic FDEVICECONTROL

#define BUF_LEN 1000

/* set the 2nd EOR to 'x' - will change this to 30
   for block read code */

void DoIoctls()
{
   short filenum = fileno(stdin);
   short buffer = 'x'*256;
   short bufferlen=1;
   short controlcode = 192;
   short param1 = 40;
   short param2 = 2;    /* write */
   unsigned short errorcode = 1;

   filenum = _mpe_fileno ( filenum );

   FDEVICECONTROL(filenum, &buffer, bufferlen, controlcode,
                                param1, param2, &errorcode);
}

static int mygetchar()
{
        static char buf[BUF_LEN];
        static int len = 0;
        static int pos = 0;


        if (len == 0)
        {
                len = READX (buf,-BUF_LEN);
                printf("len =  %d\n",len);
                pos = 0;
        /* should check len here */
        }
        len--;
        return buf[pos++];
}

main(int argc, char *argv[])
{
        int i;
        int c = 'A';
        char x;

        DoIoctls();
        printf("\033*s^");  /* Ask for terminal type */
        fflush(stdout);
        while (c>31)
        {
                c=mygetchar();
                if (c>31)
                        printf ("%c\n", c);
                else
                        printf ("%d\n", c);
        }
}

$ ./Z
errorcode = 0
70092
len =  5
7
0
0
9
2
abc
len =  3
a
b
c<CR>
defxlen =  4
d
e
f
x
<ctrl-A here>
len =  1
1

============

Looks like I'm losing the <CR> character - I guess I could make
'mygetchar' add it back in if there's  a problem.

I found 100's more posts in google groups once I had a few intrinsics
under my belt related to this problem.  Non of the solutions did quite
what I wanted so I've posted this for anyone else in my situation.

Thanks for all the help.

Peter

PS. Your 'x' key won't work after running that code!

--
http://www.wadmag.org.uk
http://uk.geocities.com/ukwebring - UK Motorcycle site webring

* To join/leave the list, search archives, change list settings, *
* etc., please visit http://raven.utc.edu/archives/hp3000-l.html *

ATOM RSS1 RSS2