comp.lang.ada
 help / color / mirror / Atom feed
* Re: Readkey in VAX Ada 83
       [not found] <1995Jan27.172515.1@clstcs>
@ 1995-01-31 13:38 ` Theodore E. Dennison
  1995-01-31 21:03 ` Larry Kahn
  1995-02-02 13:28 ` Larry Kilgallen, LJK Software
  2 siblings, 0 replies; 4+ messages in thread
From: Theodore E. Dennison @ 1995-01-31 13:38 UTC (permalink / raw)


amlombardi@vms4.sci.csupomona.edu wrote:
>
> I posted earlier about getting a character from the keyboard buffer but left
> out a vital part... I'm using VAX Ada... I've had a few responses and one
> person mentioned the file STARLET.... does anyone know if the answer lies in
> here because the file is 2500 blocks long ... thanks.. e-mail me with response

Yes, the "person" is correct. I wouldn't look in there for an answer,
though; the VMS packages have NO comments explaining what the routines
do or how to use them. Look in your VMS programming manuals. Pay 
particular attention to SYS$, LIB$, and SMG$. When you find the 
routine you want, look in the Starlet, Lib, or Smg package for it.

T.E.D.



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Readkey in VAX Ada 83
       [not found] <1995Jan27.172515.1@clstcs>
  1995-01-31 13:38 ` Readkey in VAX Ada 83 Theodore E. Dennison
@ 1995-01-31 21:03 ` Larry Kahn
  1995-02-02 13:28 ` Larry Kilgallen, LJK Software
  2 siblings, 0 replies; 4+ messages in thread
From: Larry Kahn @ 1995-01-31 21:03 UTC (permalink / raw)


In article <1995Jan27.172515.1@clstcs>, amlombardi@vms4.sci.csupomona.edu says...
>
>I posted earlier about getting a character from the keyboard buffer but left
>out a vital part... I'm using VAX Ada... I've had a few responses and one
>person mentioned the file STARLET.... does anyone know if the answer lies in
>here because the file is 2500 blocks long ... thanks.. e-mail me with response


I've done this in c by calling the various vax system calls and you would do it the
same way in Ada... I don't have time to do this for you but will include the
c stuff... take a look specifically and the myread function that calls the vms 
system call qiow to read one character at a time... you would use the ada bindings
and do a similiar call.....

hope this helps....



#include "mtype.h"
#include <stdio.h>
#include <ctype.h>
#if ONVAX == 1
#include <ssdef>
#include <iodef>
#include <descrip>

static unsigned long int oneone = 1;
static unsigned long int zz = 0;
int chan = 0;
long int readit;
int readclr;
extern long int LIB$SPAWN(), SYS$QIOW(), SYS$ASSIGN(), LIB$GET_SYMBOL();
long int stat;
struct dsc$descriptor dvname, cmdstr, symstr, symstr2;
char rdbuf[4] = "   ";
#endif

int fline = 0;
int lline = 0;
int mline = 0;
int cline = 0;
int column = 0;
char pmnemarr[26][5];
char menuarr[26][80];
int menuflag = 0;
int menucolumn;
int composite = 0; /* flag to indicate if using a composite monitor 
                    default is no */
void home()
{
int i;
static char home[6] = {27,'[','1',';','1','f'};

for (i = 0; i<6; i++)
 putchar(home[i]);
}

void cls()
{
int i;
static char cls[4] = {27,'[','2','J'};

for (i = 0; i<4; i++)
 putchar(cls[i]);
}

void cback(num)
   int num;
{
int i,s;
static char back[4] = {27,'[','1','D'};

for (i = 1; i<=num; i++)
  for (s=0; s<4; s++)
    putchar(back[s]);
}

void cforward(num)
   int num;
{
int i,s;
static char forw[4] = {27,'[','1','C'};

for (i = 1; i<=num; i++)
  for (s=0; s<4; s++)
    putchar(forw[s]);
}

void cdown(num)
   int num;
{
int i,s;
static char down[4] = {27,'[','1','B'};

for (i = 1; i<=num; i++)
  for (s=0; s<4; s++)
    putchar(down[s]);
}

void cup(num)
   int num;
{
int i,s;
static char up[4] = {27,'[','1','A'};

for (i = 1; i<=num; i++)
  for (s=0; s<4; s++)
    putchar(up[s]);
}

void locate(row,column)
   int row,column;
{
 char crow[3];
 char ccol[3];
 int i;

 strcpy(crow,"  ");
 strcpy(ccol,"  ");
 sprintf(crow,"%d",row);
 sprintf(ccol,"%d",column);
 putchar(27);
 putchar('[');
 
for (i =0; i < strlen(crow); i++)
  putchar(crow[i]);

putchar(';');

for (i =0; i < strlen(ccol); i++)
  putchar(ccol[i]);

putchar('f');
 }

 void pr_loc(row,column,instring)
  int row,column;
  char *instring;

  {
    locate(row,column);
    printf(instring);
  }

void docolor(color)
 char color[];
 {
   int clen,i;

   clen = strlen(color);
   putchar(27);
   putchar('[');
   for (i =0; i < clen; i++)
    putchar(color[i]);
     putchar('m');

}

void upline()
   {

#if ONVAX == 0
         docolor(WHITEA);
         docolor(CYANF);
#else 
         docolor(VNORMAL);
#endif

         /* write out normal */
         if (cline != mline)
           pr_loc(cline,menucolumn,menuarr[cline]);
         else {
                pr_loc(mline,14,"     ");
                pr_loc(mline,3,menuarr[cline]);
              }

     if (cline == fline)   /* already on first line so go to menu line */
         cline = mline;

     else if (cline == mline) /* already on menu line so go to last line */
             cline = lline;
         
     else /* subtract a line */
             --cline;
#if ONVAX == 0        
    if (composite == 0)
      {
        docolor(WHITEB);
        docolor(REDF);
      }
    else  /* composite == 1 */
      	docolor(REVERSE);
      /* this makes the reverse menu selections visible on a composite
         monitor */
#else 
         docolor(VREVERSE);
#endif
         if (cline != mline)
           pr_loc(cline,menucolumn,menuarr[cline]);
         else {
                pr_loc(mline,14,"     ");
                pr_loc(mline,3,menuarr[cline]);
              }
   }

void downline()
   {

#if ONVAX == 0
         docolor(WHITEA);
         docolor(CYANF);
#else 
         docolor(VNORMAL);
#endif

         /* write out normal */
         if (cline != mline)
           pr_loc(cline,menucolumn,menuarr[cline]);
         else {
                pr_loc(mline,14,"     ");
                pr_loc(mline,3,menuarr[cline]);
              }
                
     if (cline == lline)   /* on last line so go to menu line */
         cline = mline;

     else if (cline == mline) /* already on menu line so go to first line */
             cline = fline;

         
     else /* add a line */
         ++cline;

#if ONVAX == 0    
    if (composite == 0)
      {
        docolor(WHITEB);
        docolor(REDF);
      }
    else  /* composite == 1 */
      	docolor(REVERSE);
      /* this makes the reverse menu selections visible on a composite
         monitor */

#else 
         docolor(VREVERSE);
#endif
             /* write out the line in reverse */
         if (cline != mline)
           pr_loc(cline,menucolumn,menuarr[cline]);
         else {
                pr_loc(mline,14,"     ");
                pr_loc(mline,3,menuarr[cline]);
              }
   }


/* only compile this if on the vax */

#if ONVAX == 1

void myread(buf,len,pflag)
char buf[];
int len;
int pflag;
{
  

  int tkey;
  int counter = 0;
  int retfnd = 0;
  char bline[78];
  int i;
  
 for (i=0; i<78; i++)
    bline[i]= ' ';

 bline[77] = '\0';

  /* set up desc */

readit = IO$_READLBLK + IO$M_NOECHO+ IO$M_NOFILTR;
while (retfnd == 0)
{
  
  stat = SYS$QIOW(zz,chan,readit,zz,zz,zz,&rdbuf,oneone,zz,zz,zz,zz);

 if (stat != SS$_NORMAL)
   {
    pr_loc(22,1,bline);
    locate(22,25);
    printf("Error: read failure, error code = %d",stat);
    exit(1);
   }

      tkey = rdbuf[0];

       /* if 0 try next char for movement */

       if (tkey == 27)
        {
           rdbuf[0] = ' ';           

       stat = SYS$QIOW(zz,chan,readit,zz,zz,zz,&rdbuf,oneone,zz,zz,zz,zz);
     
            if (stat != SS$_NORMAL)
              {
                pr_loc(22,1,bline);
                locate(22,25);
                printf("Error: read failure, error code = %d",stat);
                exit(1);
               }

              tkey = rdbuf[0];
              if (tkey == 91)    /* could be cursor movement */
                {
                  rdbuf[0] = ' ';           

                  stat = SYS$QIOW(zz,chan,readit,zz,zz,zz,
                                  &rdbuf,oneone,zz,zz,zz,zz);
     
                 if (stat != SS$_NORMAL)
                   {
                    pr_loc(22,1,bline);
                    locate(22,25);
                    printf("Error: read failure, error code = %d",stat);
                    exit(1);
                   }

                 tkey = rdbuf[0];
                 if ((tkey == 65) && (menuflag == 1)) /* up */               
                   {
                     upline();
                     counter = 0;  /* reset buffer */
                   }   
                 if ((tkey == 66) && (menuflag == 1))    /* down */
                   {
                     downline();
                     counter = 0;  /* reset buffer */
                   }       
             } /* end of 91 */
         } /* end of 27 */

       else if ((tkey == 32) && (menuflag == 1))  /* want menu movement */
              {
                downline();
                counter = 0;   /* reset buffer */
              }
       else 
        {
         tkey = toupper(tkey);
       
         if (counter < len )
           {
                        /* is ok */             
              if (((isalnum(tkey) > 0) || (tkey == 45) ||
                 (tkey == 46)) && ((menuflag == 0) || (cline == mline)))
               {
                  buf[counter] = tkey;
                  ++counter;
                  if (pflag > 0)
                    putchar(tkey);
                  else putchar(' ');
               }

            } /* only accept legal characters if less than length */
            /* however accept backspace or return when at length */
          
            if (tkey == 13)  /* check for return */
               {
                retfnd = 1; 

                /* if return and not on menuline the put in pnemonic */
                if ((cline != mline) && (menuflag == 1))
                  {
                    strcpy(buf,pmnemarr[cline]);
                    counter = strlen(pmnemarr[cline]);
                  }
                }
          
                  /* check for backspace */

            if ((tkey == 127)  && ((menuflag == 0) || (cline == mline)))   
              { if (counter >= 1)
                  { --counter;
                    buf[counter] = ' ';
                    cback(1);
                    putchar(' ');
                    cback(1);
                  }
              }
          }
     }
  buf[counter] = '\0';
}

int system(comm)

 char *comm;
{
/* set up for call */
    
cmdstr.dsc$w_length = strlen(comm);
cmdstr.dsc$a_pointer = comm;
cmdstr.dsc$b_class = DSC$K_CLASS_S;
cmdstr.dsc$b_dtype = DSC$K_DTYPE_T;

stat = LIB$SPAWN(&cmdstr,zz,zz,zz,zz,zz,zz,zz,zz,zz,zz,zz);
}

#else

void myread(buf,len,pflag)
char buf[];
int len;
int pflag;
{
  
  int tkey;
  int counter = 0;
  int retfnd = 0;
  
while (retfnd == 0)

     { 
       tkey = getch();

       /* if 0 get next char */

       if (tkey == 0)
          {
            tkey = getch();
            if ((tkey == 72) && (menuflag == 1))   /* up */
              {        
                upline();
                counter = 0;   /* reset buffer */
               }   
            if ((tkey == 80) && (menuflag == 1))    /* down */
              {            
                downline();
                counter = 0; /* reset buffer */
              }
          }    /* end of = 0 */
            
       else if ((tkey == 32) && (menuflag == 1))  /* want menu movement */
              {
                downline();
                counter = 0;  /* reset buffer */
              }

       else 
        {
         tkey = toupper(tkey);
       
         if (counter < len )
           {
                        /* is ok */             
              if (((isalnum(tkey) > 0) || (tkey == 45) ||
                 (tkey == 46)) && ((menuflag == 0) || (cline == mline)))
                 
               {
                  buf[counter] = tkey;
                  ++counter;
                  if (pflag > 0)
                    putch(tkey);
                  else putch(' ');
               }

            } /* only accept legal characters if less than length */
            /* however accept backspace or return when at length */
          
            if (tkey == 13)  /* check for return */
               {
                retfnd = 1; 

                /* if return and not on menuline then put in pnemonic */
                if ((cline != mline) && (menuflag == 1))
                  {
                    strcpy(buf,pmnemarr[cline]);
                    counter = strlen(pmnemarr[cline]);
                  }
                }

                /* check for backspace */

            if ((tkey == 8)  && ((menuflag == 0) || (cline == mline)))   
              { if (counter >= 1)
                  { --counter;
                    buf[counter] = ' ';
                    cback(1);
                    putch(' ');
                    cback(1);
                  }
              }
          }
     }
  buf[counter] = '\0';
}
#endif


void pause2()
{
   char bline[78];
   int i;
   for (i=0; i<78; i++)
      bline[i]= ' ';
    bline[77] = '\0';
    pr_loc(24,1,bline);  
   
#if ONVAX == 0
   docolor(CYANF);
#else 
   docolor(VNORMAL);
#endif

   pr_loc(24,25,"PRESS <RETURN> TO CONTINUE");
   myread(bline,0);
}


-- 
Laurence G. Kahn
Senior Software Engineer
Dynamics Research Corp.
(Finger .site@kahn.pdial.interpath.net for PGP public key.)




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Readkey in VAX Ada 83
@ 1995-02-01 14:11 CONDIC
  0 siblings, 0 replies; 4+ messages in thread
From: CONDIC @ 1995-02-01 14:11 UTC (permalink / raw)


From: Marin David Condic, 407.796.8997, M/S 731-93
Subject: Re: Readkey in VAX Ada 83
Original_To:  PROFS%"SMTP@PWAGPDB"
Original_cc:  CONDIC



>
>I posted earlier about getting a character from the keyboard buffer but left
>out a vital part... I'm using VAX Ada... I've had a few responses and one
>person mentioned the file STARLET.... does anyone know if the answer lies in
>here because the file is 2500 blocks long ... thanks.. e-mail me with response
>
I believe that the relavent STARLET call looks like this:

    STARLET.QIOW(
         STATUS => STATUS,
         EFN    => INPUT_EFN,
         CHAN   => INPUT_CHANNEL,
         FUNC   => STARLET.IO_READVBLK,
         P1     => SYSTEM.TO_UNSIGNED_LONGWORD(KEY'address),
         P2     => 2);

However, this is not the only answer for reading characters
from the keyboard as they occur.

STARLET is just one of the packages VAX Ada provides to give you
the connections you want to system services. If you know how to
get keystrokes through any variety of system calls, somewhere in
the ACS Ada library you will find an interface to the system
call.

You will also want to investigate the SMG$ routines and I believe
that there is a call known as SMG$READ_KEYSTROKE. (Try ACS
EXTRACT SOURCE/SPECIFICATION_ONLY SMG to see the package spec for
all the SMG calls.)

Of course, the truly studly way of getting keystrokes is through
the use of Asynchronous System Traps - you have to set up a
mailbox and tie an AST to a task entry and all sorts of other
delecate operations which will take you right down into the
bowels of VMS. (Details left as an exercise for the student. It's
not pretty!) This will allow you to react to keystrokes as
independent events - but beware: it can be slow and is subject to
application lockup due to buffer overflows.

And then we could always ask the question: "When will compiler
writers give me a TEXT_IO.GET_CHARACTER routine which behaves the
way I want it to when connected to a keyboard?" But that might
take all the glamour our of application programming ;-)

Pax,
Marin

Marin David Condic, Senior Computer Engineer    ATT:        407.796.8997
M/S 731-93                                      Technet:    796.8997
Pratt & Whitney, GESP                           Internet:   CONDICMA@PWFL.COM
P.O. Box 109600                                 Internet:   MDCONDIC@AOL.COM
West Palm Beach, FL 33410-9600
===============================================================================
    "I have traveled the length and breadth of this country and talked
    with the best people, and I can assure you that data processing is
    a fad that won't last out the year."

        --  The editor in charge of business books for Prentice
            Hall, 1957.
===============================================================================



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Readkey in VAX Ada 83
       [not found] <1995Jan27.172515.1@clstcs>
  1995-01-31 13:38 ` Readkey in VAX Ada 83 Theodore E. Dennison
  1995-01-31 21:03 ` Larry Kahn
@ 1995-02-02 13:28 ` Larry Kilgallen, LJK Software
  2 siblings, 0 replies; 4+ messages in thread
From: Larry Kilgallen, LJK Software @ 1995-02-02 13:28 UTC (permalink / raw)


In article <1995Jan27.172515.1@clstcs>, amlombardi@vms4.sci.csupomona.edu writes:

> I posted earlier about getting a character from the keyboard buffer but left
> out a vital part... I'm using VAX Ada... I've had a few responses and one
> person mentioned the file STARLET.... does anyone know if the answer lies in
> here because the file is 2500 blocks long ... thanks.. e-mail me with response

Package STARLET describes the common programmer interfaces to the VMS
operating system, and is available both on VAX and the newer Alpha VMS
systems (when VAX Ada or DEC Ada are available).

I do not recall your previous post, but if you are trying to read
characters from the keyboard before a carriage return has been entered,
the procedure you want is STARLET.QIO or STARLET.QIOW.  It is not practical
to explain the use of QIO online.  You should consult the VMS manual
called the I/O User's Guide, looking at the chapter about Terminal IO.

Perhaps you hoped for a routine which would be portable across operating
systems, but I tend to think it would be impossible to specify one which
was sufficiently general to cover all operating systems.  Your particular
need is to avoid waiting for the end of line, but someone else might want
to prefill the input buffer with particular text (available on VMS) or
specify the color in which characters will be echoed (not available on VMS,
but surely available on some other operating system).  Specifying the
unification of all operating system features would be a daunting task for
the designers of Ada, and one which would be outdated immediately by the
provision of new features in some operating system.

Larry Kilgallen
using Ada without being mandated



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~1995-02-02 13:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <1995Jan27.172515.1@clstcs>
1995-01-31 13:38 ` Readkey in VAX Ada 83 Theodore E. Dennison
1995-01-31 21:03 ` Larry Kahn
1995-02-02 13:28 ` Larry Kilgallen, LJK Software
1995-02-01 14:11 CONDIC

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox