home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Club Amiga de Montreal - CAM
/
CAM_CD_1.iso
/
files
/
389.lha
/
dme_v1.40
/
src
/
cmd3.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-07-03
|
4KB
|
276 lines
/*
* CMD3.C
*
* (C)Copyright 1988 by Matthew Dillon, All Rights Reserved
*
* SETFONT
* IGNORECASE
* SET
* SETENV
* UNSET
* UNSETENV
* CD
* SAVECONFIG
* FGPEN
* BGPEN
*/
#include "defs.h"
#include <libraries/dos.h>
#define nomemory() { memoryfail = 1; }
/*
* SETFONT font size
*/
void
do_setfont()
{
FONT *font = (FONT *)GetFont(av[1], (short)atoi(av[2]));
ED *ep = Ep;
if (font) {
if (ep->Font)
CloseFont(ep->Font);
ep->Font = font;
SetFont(ep->Win->RPort, font);
SetRast(ep->Win->RPort, 0);
RefreshWindowFrame(ep->Win);
set_window_params();
text_redisplay();
} else {
title("Unable to find font");
}
}
void
do_ignorecase()
{
ED *ep = Ep;
if (av[1][0]) {
switch(av[1][1] & 0x1F) {
case 'n'&0x1F:
ep->IgnoreCase = 1;
break;
case 'f'&0x1F:
ep->IgnoreCase = 0;
break;
case 'o'&0x1F:
ep->IgnoreCase = 1 - ep->IgnoreCase;
break;
}
if (ep->IgnoreCase)
title("Case InSensitive");
else
title("Case Sensitive");
}
}
/*
* av[1]
*/
void
do_cd()
{
BPTR oldlock;
BPTR lock;
oldlock = CurrentDir((BPTR)Ep->dirlock);
if (lock = Lock(av[1], SHARED_LOCK)) {
UnLock(CurrentDir(oldlock));
Ep->dirlock = (long)lock;
} else {
CurrentDir(oldlock);
Abortcommand = 1;
title("Unable to CD");
}
}
/*
* VARIABLE SUPPORT!
*/
#define VARS struct _VARS
VARS {
MNODE Node;
char *Name;
char *Str;
};
static MLIST SList = { (MNODE *)&SList.mlh_Tail, NULL, (MNODE *)&SList.mlh_Head };
void
do_set()
{
VARS *v;
void do_unset();
do_unset();
if (v = malloc(sizeof(VARS))) {
if (v->Name = malloc(strlen(av[1])+1)) {
if (v->Str = malloc(strlen(av[2])+1)) {
AddHead((LIST *)&SList, (NODE *)v);
strcpy(v->Name, av[1]);
strcpy(v->Str , av[2]);
return;
}
free(v->Name);
}
free(v);
}
nomemory();
}
void
do_setenv()
{
SetDEnv(av[1], av[2]);
}
void
do_unset()
{
VARS *v;
for (v = (VARS *)SList.mlh_Head; v->Node.mln_Succ; v = (VARS *)v->Node.mln_Succ) {
if (strcmp(v->Name, av[1]) == 0) {
Remove((NODE *)v);
free(v);
free(v->Name);
free(v->Str);
break;
}
}
}
void
do_unsetenv()
{
char *ptr = (char *)av[1];
char *tmp = malloc(4+strlen(ptr)+1);
if (tmp) {
strcpy(tmp, "ENV:");
strcat(tmp, ptr);
mountrequest(0);
DeleteFile(tmp);
mountrequest(1);
free(tmp);
}
}
/*
* Search (1) internal list, (2) enviroment, (3) macros. The variable
* is allocated with malloc(). NULL if not found. ENV: need not exist.
*/
char *
getvar(find)
char *find;
{
char *str = NULL;
{
VARS *v;
for (v = (VARS *)SList.mlh_Head; v->Node.mln_Succ; v = (VARS *)v->Node.mln_Succ) {
if (strcmp(v->Name, find) == 0) {
if (str = malloc(strlen(v->Str)+1)) {
strcpy(str, v->Str);
return(str);
}
}
}
}
mountrequest(0);
str = (char *)GetDEnv(find);
mountrequest(1);
if (str)
return(str);
if ((str = keyspectomacro(find)) || (str = menutomacro(find))) {
char *ptr = malloc(strlen(str)+1);
if (ptr) {
strcpy(ptr, str);
return(ptr);
}
}
return(NULL);
}
void
do_col()
{
int col = atoi(av[1]) - 1;
if (col > 254 || col < 0) {
Abortcommand = 1;
return;
}
while (Clen < col)
Current[Clen++] = ' ';
Ep->Column = col;
if (Ep->Column - Ep->Topcolumn >= Columns || Ep->Column < Ep->Topcolumn)
text_sync();
}
void
do_saveconfig()
{
ED *ep = Ep;
FILE *fi;
if (ep->iconmode == 0) {
WIN *win = ep->Win;
ep->Winx = win->LeftEdge;
ep->Winy = win->TopEdge;
ep->Winwidth = win->Width;
ep->Winheight = win->Height;
}
if (fi = fopen("s:dme.config", "w")) {
fwrite(&ep->BeginConfig, (char *)&ep->EndConfig - (char *)&ep->BeginConfig, 1, fi);
fclose(fi);
}
}
void
loadconfig(ep)
ED *ep;
{
FILE *fi;
if (fi = fopen("s:dme.config", "r")) {
fread(&ep->BeginConfig, (char *)&ep->EndConfig - (char *)&ep->BeginConfig, 1, fi);
fclose(fi);
}
}
void
do_fgpen()
{
ED *ep = Ep;
ep->FGPen = atoi(av[1]);
}
void
do_bgpen()
{
ED *ep = Ep;
ep->BGPen = atoi(av[1]);
}
void
do_hgpen()
{
ED *ep = Ep;
ep->HGPen = atoi(av[1]);
}