home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 4
/
FreshFish_May-June1994.bin
/
bbs
/
may94
/
util
/
edit
/
jade.lha
/
Jade
/
src
/
amiga_commandline.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-04-19
|
5KB
|
188 lines
/* amiga_commandline.c -- prompt for AmigaDOS
Copyright (C) 1993, 1994 John Harper <jsh@ukc.ac.uk>
This file is part of Jade.
Jade is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
Jade is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Jade; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "jade.h"
#include "jade_protos.h"
#define INTUI_V36_NAMES_ONLY
#include <clib/intuition_protos.h>
#include <clib/keymap_protos.h>
#include <string.h>
_PR u_char *docmdline(VW *, u_char *, u_char *);
/*
* returns a string got from the command line
* it (the string) must be valstrfree()'ed after use.
* cursor should be off.
*/
u_char *
docmdline(VW *vw, u_char *prompt, u_char *original)
{
u_char *cmdline;
long cmdlen;
long promptlen = strlen(prompt);
if(!unsleep(vw))
return(FALSE);
cmdline = mystrdup(original ? original : (STRPTR)"");
if(cmdline)
{
POS oldcursor = vw->vw_CursorPos;
long oldstartcol = vw->vw_StartCol;
long prevx;
char keepgoing = 0;
cmdlen = strlen(cmdline) + 1;
vw->vw_CursorPos.pos_Col = promptlen + cmdlen - 1;
vw->vw_CursorPos.pos_Line = vw->vw_StartCol + vw->vw_MaxY - 1;
prevx = vw->vw_CursorPos.pos_Col;
if(vw->vw_CursorPos.pos_Col >= vw->vw_MaxX)
vw->vw_StartCol = vw->vw_CursorPos.pos_Col - vw->vw_MaxX + 1;
else
vw->vw_StartCol = 0;
redrawcmdline(vw, prompt, cmdline, promptlen, cmdlen - 1);
cmdlncursor(vw, CURS_ON);
while(!keepgoing)
{
struct IntuiMessage *imsg;
Wait(1 << vw->vw_Window->UserPort->mp_SigBit);
while((!keepgoing) && (imsg = GetWinIMsg(vw->vw_Window)))
{
struct IntuiMessage imsgcopy = *imsg;
ReplyMsg((struct Message *)imsg);
if(imsgcopy.Class == IDCMP_RAWKEY)
{
cmdlncursor(vw, CURS_OFF);
switch(imsgcopy.Code)
{
case 0x41: /* delete */
if(cmdlen > 1)
{
u_char *newline;
vw->vw_CursorPos.pos_Col--;
cmdlen--;
if(newline = mystrdupn(cmdline, cmdlen - 1))
{
mystrfree(cmdline);
cmdline = newline;
}
}
break;
case 0x44: /* return */
keepgoing = 1;
break;
case 0x45: /* escape */
keepgoing = -1;
break;
case 0x4c: /* up */
case 0x4d: /* down */
if(LastPrompted)
{
u_char *temp = cmdline;
cmdline = LastPrompted;
LastPrompted = temp;
cmdlen = strlen(cmdline) + 1;
vw->vw_CursorPos.pos_Col = cmdlen + promptlen - 1;
prevx = 20000;
}
break;
default:
if(!(imsgcopy.Code & IECODE_UP_PREFIX))
{
struct InputEvent ie;
u_char buff[256];
long len;
ie.ie_Class = IECLASS_RAWKEY;
ie.ie_SubClass = 0;
ie.ie_Code = imsgcopy.Code;
ie.ie_Qualifier = imsgcopy.Qualifier;
ie.ie_EventAddress = *((APTR *)imsgcopy.IAddress);
if((len = MapRawKey(&ie, buff, 255, NULL)) != -1)
{
u_char *newline;
buff[len] = 0;
if(newline = mystrdupn(cmdline, cmdlen + len))
{
strcat(newline, buff);
mystrfree(cmdline);
cmdline = newline;
cmdlen += len;
vw->vw_CursorPos.pos_Col += len;
}
}
}
break;
}
}
else if(imsgcopy.Class == IDCMP_NEWSIZE)
{
cmdlncursor(vw, CURS_OFF);
vw->vw_StartCol = oldstartcol;
updatedimensions(vw);
redrawall(vw);
prevx = 20000;
#if 0
redrawcmdline(vw, prompt, cmdline, promptlen, cmdlen - 1);
#endif
}
else
continue;
if(vw->vw_CursorPos.pos_Col >= vw->vw_MaxX)
{
vw->vw_StartCol = vw->vw_CursorPos.pos_Col - vw->vw_MaxX + 1;
redrawcmdline(vw, prompt, cmdline, promptlen, cmdlen - 1);
}
else
{
vw->vw_StartCol = 0;
if(prevx >= vw->vw_MaxX)
redrawcmdline(vw, prompt, cmdline, promptlen, cmdlen - 1);
else if(prevx < vw->vw_CursorPos.pos_Col)
redrawcmdlinefrom(vw, prompt, cmdline, promptlen, cmdlen - 1, prevx);
else
redrawcmdlinefrom(vw, prompt, cmdline, promptlen, cmdlen - 1, vw->vw_CursorPos.pos_Col);
}
prevx = vw->vw_CursorPos.pos_Col;
cmdlncursor(vw, CURS_ON);
}
}
if(keepgoing < 0)
{
mystrfree(cmdline);
cmdline = NULL;
}
else
{
mystrfree(LastPrompted);
LastPrompted = mystrdup(cmdline);
}
cmdlncursor(vw, CURS_OFF);
vw->vw_CursorPos = oldcursor;
vw->vw_StartCol = oldstartcol;
restorecmdline(vw);
return(cmdline);
}
return(FALSE);
}