Re: exu 3, key.ex

new topic     » goto parent     » topic index » view thread      » older message » newer message

Chris Burch wrote:
> Will this help
> 
> #include <stdio.h>
> #include <stdlib.h>
> #include <sys/ioctl.h>
> #include <unistd.h>
> 
> struct winsize ws;
> 
> int main()
> {
> char *buffer, *env;
> int lines;
> int rows, cols;
> 
> buffer = getenv("LINES");
> if (buffer != NULL )
>     printf("LINES are %s\n", buffer);
> //lines = atoi("400");
> //printf("Lines number :%d\n", lines);
> 
> if (ioctl(1, TIOCGWINSZ, &ws) == -1) 
> 	{
> 	rows = 24;
> 	cols = 80;
> 	} 
> else 
> 	{
> 	if (!ioctl(STDIN_FILENO, TIOCGWINSZ, &ws)) 
> 		{
> 		 rows = ws.ws_row;
> 		 cols = ws.ws_col;
> 		 if (!rows) 
> 			 {
> 			  env = getenv("LINES");
> 			  if (env)
> 				rows = atoi(env);
> 			  if (!rows)
> 				rows = 24;
> 		     }
> 		if (!cols) 
> 			{
> 			 env = getenv("COLUMNS");
> 			 if (env)
> 				cols = atoi(env);
> 			 if (!cols)
> 				cols = 80;
> 		    }
> 		}
> 	}
> 
> if (!rows) 
> 	{
> 	env = getenv("LINES");
> 	if (env)
> 		rows = atoi(env);
> 	if (!rows)
> 		rows = 24;
> 	}
> 
> if (!cols) 
> 	{
> 	env = getenv("COLUMNS");
> 	if (env)
> 		cols = atoi(env);
> 	if (!cols)
> 		cols = 80;
> 	}
> 
> printf("%d %d\n", rows, cols);
> 
> printf("Program completed successfully\n");
> 
> }

Yes, it works! Thanks a lot. That code will be very useful.
It's actually the ioctl call that successfully picks up
the lines and columns. As I had found earlier, getenv() 
doesn't retrieve these variables. Though, if I say:
    export LINES
    export COLUMNS
before running the program, then getenv() does work. (Thanks Elliott).
But that's a bit inconvenient.

Sorry for the long delay in testing your code and replying.
I had a lot of distractions lately (such as watching Saw II smile).

Regards,
   Rob Craig
   Rapid Deployment Software
   http://www.RapidEuphoria.com

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu