robinson@elux1.cs.umass.edu (Richard Robinson) (05/07/91)
To attach a console file to a window you have open (you must be using
ConMan, I don't know which version), use this code fragment:
/*----------------------------------------------------------------------*/
FILE *fp;
struct Window *w;
char buffer[20];
w = OpenWindow(whatever);
sprintf(buffer,"CON:W%x",w);
fp = fopen(buffer,"w+");
/*----------------------------------------------------------------------*/
I don't know of any way to do this with standard AmigaDOS (well, maybe with
2.0, but I don't have 2.0, so).
A second question was how to turn a console window into RAW mode, like
more does, use this code
/*----------------------------------------------------------------------*/
/*
* code to switch a terminal to and from RAW / CON mode.
* use and abuse as desired
*
* -Dread
*/
#include <exec/types.h>
#include <exec/memory.h>
#include <libraries/dosextens.h>
#include <string.h>
#include <stdio.h>
#include <proto/exec.h>
#include <proto/dos.h>
static LONG send_packet(struct MsgPort *where,LONG what,LONG args[],
LONG num_args,LONG result[2])
{
struct MsgPort *reply_port;
struct StandardPacket *packet;
LONG index,*array;
result[0] = result[1] = 0;
reply_port = CreatePort(NULL,0);
if( !reply_port ) return 0;
packet = AllocMem(sizeof(struct StandardPacket),MEMF_PUBLIC|MEMF_CLEAR);
if( !packet )
{
DeletePort(reply_port);
return 0;
}
packet->sp_Msg.mn_Node.ln_Name = (char *)&(packet->sp_Pkt);
packet->sp_Pkt.dp_Link = &(packet->sp_Msg);
packet->sp_Pkt.dp_Port = reply_port;
packet->sp_Pkt.dp_Type = what;
array = &(packet->sp_Pkt.dp_Arg1);
for( index=0;index<num_args;index++ )
array[index] = args[index];
PutMsg(where,(struct Message *)packet);
WaitPort(reply_port);
GetMsg(reply_port);
result[0] = packet->sp_Pkt.dp_Result1;
result[1] = packet->sp_Pkt.dp_Res1;
/* I think that should be res2 - I will check, but since the following
code doesn't use it, who cares? */
FreeMem(packet,sizeof(struct StandardPacket));
DeletePort(reply_port);
return result[0];
}
/* ok, here is the function to call */
LONG set_screen_mode(BPTR fp,int flag)
{
LONG args[1];
LONG res[2];
struct FileHandle *fh;
fh = (struct FileHandle *)(fp<<2);
args[0] = flag;
return send_packet(fh->fh_Type,ACTION_SCREEN_MODE,args,1,res);
}
/* I HOPE this code is correct - I just retyped it in, and might of made
some typing errors. I also renamed the variables to be more clear.
If you have problems (I doubt it though), I will fix it */
/*
* ok, now to set the current console to RAW mode, do this
*/
set_screen_mode(Output(),-1);
/* to set it back to con mode - do this before you exit */
set_screen_mode(Output(),0);
Hope that helps
-Dread
--
robinson@elux1.cs.umass.edu