comp.lang.ada
 help / color / mirror / Atom feed
From: kahn@kahn.pdial.interpath.net (Larry Kahn)
Subject: Re: Readkey in VAX Ada 83
Date: 31 Jan 1995 21:03:10 GMT
Date: 1995-01-31T21:03:10+00:00	[thread overview]
Message-ID: <3gm8ie$gj2@redstone.interpath.net> (raw)
In-Reply-To: 1995Jan27.172515.1@clstcs

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.)




  parent reply	other threads:[~1995-01-31 21:03 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [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 [this message]
1995-02-02 13:28 ` Larry Kilgallen, LJK Software
1995-02-01 14:11 CONDIC
replies disabled

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