[comp.sys.amiga] Help needed with finding ConUnit structure

jarkko@tolsun.oulu.fi (Jarkko Oikarinen) (02/29/88)

[I am just forwarding this message...but I can forward any replys also...]

I have tried to do "more" program which would handle correctly resizes of
CLI window. The problem is where to find the size of currently used CLI
window. I know that the information is in ConUnit structure (at least)
but where can I find the pointer to that structure ? Surely there are other
ways than using ConUnit and I'm open also to these ideas but this ConUnit
scrambles my mind...
A simple example would be nice with a lots of comments.
You can send followups [hope I get any !] to this newsgroup or directly to
Jarkko Oikarinen

Thanks in advance !

Tero Manninen
University of Oulu
Dpt of Electrical Engineering

=================================================
Jarkko Oikarinen   UUCP:         ...!tut!oulu!jto
                   INTERNET:   jto@tolsun.oulu.fi
                   EARN/BITNET:   toljto at finou
=================================================

kenchiu@phoenix.Princeton.EDU (Kenneth Chiu) (03/05/88)

Someone wanted an example of using the ConUnit structure from Manx C.  Here's
some code that does it.  It seems to work properly, if anyone knows
otherwise, please let me know.  It is part of an ls program that adjusts to
different window widths and does "maximally compressed columnation."  If you
have no idea what that means, you probably don't care.  :-)

Success
winsize(x, y)
int *x, *y;
{
	struct InfoData *id;
	struct Process *process;
	struct ConUnit *conunit;

	if ((id = malloc(sizeof(struct InfoData))) == NULL)
		return FAIL;

	/* find myself */
	process = (struct Process *) FindTask(0L);

	/* make sure we have a console task */
	if (process->pr_ConsoleTask == NULL)
		return FAIL;

	/*
	send the packet, id is filled in by the console task, also note
	that AmigaDOS wants a BPTR.  In practice, you can leave out 2L, 3L,
	etc.  They are just dummy arguments that are not used.  I think if
	you want to be ultra proper, though, you should include them,
	because otherwise, in theory, you could have illegal memory reads,
	I think.
	*/

	if (!dos_packet(process->pr_ConsoleTask, ACTION_DISK_INFO,
		CP2BP(id)), 2L, 3L, 4L, 5L, 6L, 7L)
		return FAIL;

	/* here's the conunit, got to dig deep don't you */
	conunit = (struct ConUnit *)
		((struct IOStdReq *) id->id_InUse)->io_Unit;

	/* here are the window limits in no. of columns and no. of rows */
	*x = conunit->cu_XMax + 1;
	*y = conunit->cu_YMax + 1;

	free(id);

	return SUCCESS;
}

Ken Chiu