home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Elysian Archive
/
AmigaElysianArchive.iso
/
wp_dtp
/
xdme1821.lha
/
XDME
/
io.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-03-25
|
8KB
|
432 lines
/*
* CMD2.C
*
* (C)Copyright 1987 by Matthew Dillon, All Rights Reserved
*/
#include "defs.h"
Prototype void do_edit (void);
Prototype int do_bappendsave(void);
Prototype int do_bsave (void);
Prototype int do_barpsave (void);
Prototype int do_appendsave (void);
Prototype int do_save (void);
Prototype int do_saveas (void);
Prototype int do_aslsave (void);
Prototype int do_reqsave (void);
Prototype int saveit (const char *);
Prototype void do_cd (void);
typedef struct WBStartup WBS;
typedef struct DiskObject DISKOBJ;
#include "rexx.h"
void do_edit (void)
{
FILE * fi;
BPTR oldlock;
BPTR new_lock;
long lines;
UBYTE buf[MAXLINELEN];
UBYTE * ptr;
BOOL failed = 1;
BOOL newfile = (*av[0] == 'n');
ED * ep = Ep;
text_sync ();
if (newfile)
{ /* newfile or insfile */
if (ep->modified && getyn("XDME Warning", "Delete modified Image?", "Yes|No") == 0)
return;
ep = uninit_init (ep);
strncpy ((char *)ep->name, (char *)av[1], 63);
ep->name[63] = 0;
} else
{
ep->modified = 1;
}
lines = ep->lines;
oldlock = CurrentDir (ep->dirlock);
if (fi = fopen (av[1], "r"))
{
int len;
char oktitle = 1;
/* Get lock for file */
if (newfile)
{
if (new_lock = Lock (av[1], SHARED_LOCK))
{
BOOL success;
/* get full path */
success = NameFromLock (new_lock, tmp_buffer,
sizeof (tmp_buffer));
/* always unlock lock */
UnLock (new_lock);
if (success)
{
strncpy (ep->name, FilePart (tmp_buffer),
sizeof (ep->name)-1);
ep->name[sizeof(ep->name)-1] = 0;
*(PathPart(tmp_buffer)) = 0;
new_lock = Lock (tmp_buffer, SHARED_LOCK);
UnLock (ep->dirlock);
ep->dirlock = new_lock;
}
}
}
sprintf (buf, "Loading %s ...", ep->name);
title (buf);
while ((len = xefgets(fi, (char *)buf, MAXLINELEN-1)) >= 0)
{
failed = 0;
len ++;
if (makeroom(256) && (ptr = allocline(len)))
{
SETLINE(ep,ep->lines) = ptr;
ep->lines ++;
movmem(buf, ptr, len);
} else
{
set_window_params ();
nomemory ();
oktitle = 0;
break;
}
}
set_window_params ();
if (oktitle)
{
title ("Loading OK");
globalflags.MForceTitle = TRUE;
}
fclose (fi);
} else /* couldn't open file */
{
if (!newfile) /* insertfile ? */
{
warn ("File `%s' not found", av[1]);
cmderr = CMD_FAILED;
} else
{
/* copy argument */
strcpy (tmp_buffer, av[1]);
/* copy name of file */
strncpy (ep->name, FilePart (tmp_buffer), sizeof (ep->name)-1);
ep->name[sizeof(ep->name)-1] = 0;
/* clip name off */
*(PathPart (tmp_buffer)) = 0;
/* get new lock */
new_lock = Lock (tmp_buffer, SHARED_LOCK);
/* unlock old lock */
UnLock (ep->dirlock);
/* remember new lock */
ep->dirlock = new_lock;
}
}
CurrentDir (oldlock);
if (ep->lines != 1 && lines == 1 && *GETTEXT(ep,0) == 0)
{
ep->modified = 0;
ep->line = 0;
freeline (GETLINE(ep,0));
bmovl (ep->list+1, ep->list, --ep->lines);
} else
{
if (!failed && lines <= ep->lines - 1)
{
/* INSFILE: move text to correct position */
ActualBlock.ep = ep;
ActualBlock.start_line = lines;
ActualBlock.end_line = ep->lines - 1;
ActualBlock.type = BT_LINE;
do_bmove ();
}
}
set_window_params ();
window_title ();
text_load ();
text_redisplay ();
} /* do_edit */
static BOOL blockmode;
int do_appendsave (void)
{
return (saveit ("a"));
} /* do_appendsave */
int do_bappendsave (void)
{
int result = FALSE;
if (block_ok ())
{
blockmode = 1;
result = saveit ("a");
blockmode = 0;
} else
error ("bappendsave:\nNo block specified");
return (result);
} /* do_bappendsave */
int do_bsave (void)
{
int result = FALSE;
if (block_ok ())
{
blockmode = 1;
result = saveit ("w");
blockmode = 0;
} else
error ("bsave:\nNo block specified");
return (result);
} /* do_bsave() */
int do_barpsave (void)
{
int result = FALSE;
if (block_ok ())
{
blockmode = 1;
result = aslsave ();
blockmode = 0;
} else
error ("barpsave:\nNo block specified");
return (result);
} /* do_barpsave */
int do_save (void)
{
av[1] = Ep->name;
return (do_saveas ());
} /* do_save() */
int do_saveas (void)
{
return (saveit ("w"));
} /* do_saveas */
int do_aslsave (void)
{
return (aslsave ());
} /* do_aslsave */
int do_reqsave (void)
{
return (reqsave ());
} /* do_reqsave */
int saveit (const char * om) /* av: xxx filename */
{
BPTR oldlock;
FILE * fi;
long i;
short j,
k;
UBYTE * ptr,
* bp;
Line xs,
xe;
ED * ep;
if (!stricmp (av[1], "unnamed"))
{
return (do_aslsave ());
} else if (!stricmp (Ep->name, "unnamed")) /* get new name */
{
strncpy (Ep->name, FilePart (av[1]), sizeof (Ep->name)-1);
Ep->name[sizeof(Ep->name)-1] = 0;
}
if (blockmode) /* block is ok */
{
xs = ActualBlock.start_line;
xe = ActualBlock.end_line + 1;
ep = ActualBlock.ep;
} else
{
xs = 0;
xe = Ep->lines;
ep = Ep;
}
text_sync ();
oldlock = CurrentDir (Ep->dirlock);
if (Wbs && globalflags.Wdisable == 0)
{ /* Write out .info file */
DISKOBJ sdo, * d;
clrmem (&sdo, sizeof(sdo));
if ((d = GetDiskObject ((char *)av[1])) == NULL)
{
/* Get path to XDME with name of the editor appended */
if (getpathto (Wbs->sm_ArgList[0].wa_Lock,
Wbs->sm_ArgList[0].wa_Name, tmp_buffer))
{
sdo.do_Magic = WB_DISKMAGIC;
sdo.do_Version = WB_DISKVERSION;
makemygadget (&sdo.do_Gadget);
sdo.do_Type = WBPROJECT;
sdo.do_DefaultTool = (char *)tmp_buffer;
sdo.do_ToolTypes = NULL;
sdo.do_CurrentX = NO_ICON_POSITION;
sdo.do_CurrentY = NO_ICON_POSITION;
sdo.do_DrawerData = NULL;
sdo.do_ToolWindow = NULL;
sdo.do_StackSize = 8192;
PutDiskObject ((char *)av[1], &sdo);
}
} else
{
FreeDiskObject (d);
}
}
if (fi = fopen (av[1], om))
{
title ("Saving ...");
for (i = xs; i < xe; ++i)
{
ptr = GETTEXT(ep,i);
if (globalflags.Savetabs)
{
for (bp = tmp_buffer, j = 0; *ptr; ++ptr, ++bp, j = (j+1)&7)
{
*bp = *ptr;
if (j == 7 && *bp == ' ' && *(bp-1) == ' ')
{
k = j;
while (k-- >= 0 && *bp == ' ')
--bp;
*++bp = 9;
} else
{
if (globalflags.SimpleTabs) /* PATCH_NULL [25 Jan 1993] : line added */
break; /* PATCH_NULL [25 Jan 1993] : line added */
if (*bp < 32 || *bp == '\"' || *bp == '\'' || *bp == '`' || *bp == '(')
break;
}
}
strcpy ((char *)bp, (char *)ptr);
ptr = tmp_buffer;
}
fputs (ptr, fi);
fputc ('\n', fi);
}
if (fclose (fi))
{
error ("save:\nWrite failed !");
} else
{
title ("Saving OK");
globalflags.MForceTitle = TRUE;
/* Only remove modify if blockmode is OFF */
ep->modified = (ep->modified && blockmode);
}
} else
{
error ("save:\nUnable to open write file\n`%s'", av[1]);
}
blockmode = 0;
CurrentDir (oldlock);
window_title ();
return (!globalflags.Abortcommand);
} /* do_saveit() */
/*
* av[1] - Directory
*/
void do_cd (void)
{
BPTR oldlock;
BPTR lock;
oldlock = CurrentDir (Ep->dirlock);
if (lock = Lock (av[1], SHARED_LOCK))
{
UnLock (CurrentDir (oldlock));
Ep->dirlock = (long)lock;
} else
{
CurrentDir (oldlock);
error ("cd:\nUnable to cd to\n`%s'", av[1]);
}
} /* do_cd */