terminal functions (cursor position)

Hi there,

I have recently suffered the lack of the function changing cursor position to the specified coordinates (QNX 4.25)

Finally I’ve found term_cur() function which uses one of the global terminal strucutres (don’t remember the name now). Anyway it does not work as I was expecting… Maybe it’s because I use standard printf function to print the text… these two functionalities are the only one I need: moving cursor somewhere and printing the string.

Do you folks know how to solve this problem? Maybe other functions?

IIRC, term_cur was supplied in a supplemental library with QNX4 to provide compatibility with the old QNX2 term style functions. You are correct, if you expect it to work you need to use term_printf to print and you generally can’t mix and match functions. term_printf takes row and column arguments as a starting position. IIRC, you need to do a term_load to initialize the library before using any of them.

Sample code

#include <sys/types.h>
#include <sys/qnxterm.h>
#include <sys/vc.h>
#include <sys/psinfo.h>
#include <sys/kernel.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <time.h>
#include <signal.h>

#define MAX_NET 4



void sigAlrm (int s_num) {
s_num = s_num;

static timer_t idt;
static int pr_idt;
static struct itimerspec timer;

short diaginfo (nid_t node,short net, short *buf) {

short c,p;
pid_t pid;

if (pr_idt==0) {
 	if ((idt=timer_create (CLOCK_REALTIME,NULL))==-1)
		return (8);

// qnx_pflags (~0L,_PPF_SIGCATCH,NULL,NULL);
signal( SIGALRM, sigAlrm );
timer.it_value.tv_sec = 0L;
timer.it_value.tv_nsec = 0L;
timer.it_interval.tv_sec = 0L;
timer.it_interval.tv_nsec = 0L;
timer.it_value.tv_sec = 1L;
timer_settime (idt,0,&timer,NULL);
pid=qnx_vc_name_attach (node,100,“qnx/net”);
timer.it_value.tv_sec = 0L;
timer_settime (idt,0,&timer,NULL);
if (pid==-1)
return (1);

buf[0] = 0x438;

timer.it_value.tv_sec = 1L;
timer_settime (idt,0,&timer,NULL);
p = Send (pid,(void far *)buf,(void far *)buf,2,8+12*MAX_NET);
timer.it_value.tv_sec = 0L;
timer_settime (idt,0,&timer,NULL);
qnx_vc_detach (pid);
if (p)
	return (2);

if (buf[0])
	return (3);

for (c=0; c<buf[2]; c++)

	if (buf[4+c*6]==net) {

		pid = buf[4+c*6+4];

		timer.it_value.tv_sec = 1L;
		timer_settime (idt,0,&timer,NULL);
		pid=qnx_vc_attach (node,pid,512,0);
		timer.it_value.tv_sec = 0L;
		timer_settime (idt,0,&timer,NULL);
		if (pid==-1)
			return (4);

		buf[0] = 0x477;

		timer.it_value.tv_sec = 1L;
		timer_settime (idt,0,&timer,NULL);
		p = Send (pid,(void far *)buf,(void far *)buf,2,32);
		timer.it_value.tv_sec = 0L;
		timer_settime (idt,0,&timer,NULL);
		qnx_vc_detach (pid);
		if (p)
			return (5);

		if (buf[0])
			return (6);

		return (0);

return (7);


int main (int argc, char *argv[]) {

short i,j,k,km,max_node,buf[75],i1;

if (argc<2) {

	printf ("Use diaginfo <max_nodes>\n");
	return (1);

max_node = atoi (argv[1]);

if (max_node<1 || max_node>31)
	max_node = 31;

if (term_load ()) {

	printf ("_иÐ

thanks guys, of course I do use term_load() function but never used #define N_ATTR with the term_printf function. Anyway I will try to check it. the other reason may be that I am referring to the wrong library as a compilation parameter (without one library i couldn’t compile it at all, although i included <sys/qnxterm.h> )

second issue: i suppose gets() also won’t work properly, is there any other terminal function to read the string (with spaces) from the console?

and at last: do you know how to run qnx 4.25 from windows platform? E.g using virtual machine? And I am not thinking of QNX Neutrino… just old 4.25

Actually if you run your console in ANSI-mode you can use ANSI-Style to move the cursor.
It was something like:

In Shell do (for ANSIable Shell):

export TERM=ansi
stty protocol=1 term=$TERM

For xy coordinates use:

void gotoxy (int x, int y) {
	char c[7];
	c[0] = 0x9b;
	c[1] = 0x30+y/10;
	c[2] = 0x30+y%10;
	c[3] = 0x3b;
	c[4] = 0x30+x/10;
	c[5] = 0x30+x%10;
	c[6] = 0x48;

qnx.com/developers/docs/qnx_ … vansi.html


cc -l termlib

thx a lot. the library was: termlib3r
and it was okay, but I did have to switch between terminal functions and others standard input/output. So I used term_load and term_restore functions to enable/disable terminal couple times in the code.

Anyway big thanks, application works really well… and fast :slight_smile: