/* Collection of code snippets by Arne Vajhøj */
/* (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) */
#include <stdio.h>
#include <string.h>
#include <descrip.h>
#include <iodef.h>

long sys$assign();
long sys$qiow();
long sys$dassgn();

main()
{
   short chan,iosb[4];
   float f;
   char primda[]="\x1B[c";
   char secda[]="\x1B[>c";
   char buf[80];
   $DESCRIPTOR(ttdesc,"TT:");
   sys$assign(&ttdesc,&chan,0,0);
   sys$qiow(0,chan,IO$_WRITEVBLK,0,0,0,primda,strlen(primda),0,0,0,0);
   sys$qiow(0,chan,IO$_READVBLK|IO$M_NOECHO|IO$M_TIMED,iosb,0,0,
              &buf,sizeof(buf),2,0,0,0);
   sys$qiow(0,chan,IO$_READVBLK|IO$M_NOECHO|IO$M_TIMED,iosb,0,0,
              &buf,sizeof(buf),2,0,0,0);
   buf[iosb[1]]='\0';
   if(strstr(buf,"62;")) printf("VT200 series\n");
   if(strstr(buf,"63;")) printf("VT300 series\n");
   if(strstr(buf,"64;")) printf("VT400 series\n");
   if(strstr(buf,";1")) printf("132 columns\n");
   if(strstr(buf,";2")) printf("printer port\n");
   if(strstr(buf,";3")) printf("ReGIS graphics\n");
   if(strstr(buf,";4")) printf("Sixel graphics\n");
   if(strstr(buf,";6")) printf("selective erase\n");
   if(strstr(buf,";7")) printf("soft character set\n");
   if(strstr(buf,";8")) printf("user-defined keys\n");
   if(strstr(buf,";9")) printf("NRC sets\n");
   if(strstr(buf,";13")) printf("local editing mode\n");
   if(strstr(buf,";15")) printf("technical character set\n");
   if(strstr(buf,";16")) printf("locator device port\n");
   if(strstr(buf,";18")) printf("windows\n");
   if(strstr(buf,";19")) printf("dual session\n");
   if(strstr(buf,";21")) printf("horizontal scrolling\n");
   sys$qiow(0,chan,IO$_WRITEVBLK,0,0,0,secda,strlen(secda),0,0,0,0);
   sys$qiow(0,chan,IO$_READVBLK|IO$M_NOECHO|IO$M_TIMED,iosb,0,0,
              &buf,sizeof(buf),2,0,0,0);
   sys$qiow(0,chan,IO$_READVBLK|IO$M_NOECHO|IO$M_TIMED,iosb,0,0,
              &buf,sizeof(buf),2,0,0,0);
   buf[iosb[1]]='\0';
   if(strstr(buf,">1;")) printf("VT220\n");
   if(strstr(buf,">2;")) printf("VT240/VT241\n");
   if(strstr(buf,">18;")) printf("VT330\n");
   if(strstr(buf,">19;")) printf("VT340\n");
   if(strstr(buf,">24;")) printf("VT320\n");
   if(strstr(buf,">41;")) printf("VT420\n");
   sys$dassgn(chan);
}
