home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Frozen Fish 2: PC
/
frozenfish_august_1995.bin
/
bbs
/
d01xx
/
d0113.lha
/
Dme
/
src
/
subs.c
< prev
next >
Wrap
C/C++ Source or Header
|
1987-11-21
|
4KB
|
220 lines
/*
* SUBS.C
*
* (C)Copyright 1987 by Matthew Dillon, All Rights Reserved
*
* Subroutines.
*/
#include "defs.h"
/*
* Create DME's text icon.
*/
makemygadget(gad)
register struct Gadget *gad;
{
static unsigned long ga[] = {
0xFFFFFFFF, /* 32 pixels across */
0x80FDCBFD,
0xFFFDDFFD,
0x80000001,
0x80DFDDDF,
0x80000001,
0xBC0EF00B,
0x80000001,
0xBFC00CDD,
0x80000001,
0xA00DF00F,
0x80000001,
0x80000001,
0x80000001,
0x80FDCBFD,
0xFFFDDFFD,
0x80000001,
0x80DFDDDF,
0x80000001,
0xBC0EF00B,
0x80000001,
0xBFC00CDD,
0x80000001,
0xA00DF00F,
0x80000001,
0xFFFFFFFF
};
static struct Image image = {
0, 0, 20, sizeof(ga)/4/2, 2, (unsigned short *)ga, 3, 0, NULL
};
bzero(gad, sizeof(struct Gadget));
gad->Width = 20;
gad->Height = sizeof(ga)/4/2 + 1;
gad->Flags = GADGIMAGE|GADGHCOMP;
gad->GadgetType = BOOLGADGET;
gad->Activation = RELVERIFY|GADGIMMEDIATE;
gad->GadgetRender = (APTR)ℑ
}
/*
* return index of first non space. Returns 0 if no spaces found.
*/
firstns(str)
register char *str;
{
register short i;
for (i = 0; str[i] && str[i] == ' '; ++i);
if (str[i] == 0)
i = 0;
return(i);
}
/*
* Return index of last non-space, 0 if no spaces.
*/
lastns(str)
register char *str;
{
register short i;
for (i = strlen(str) - 1; i > 0 && str[i] == ' '; --i);
if (i < 0)
i = 0;
return(i);
}
/*
* Return length of word under cursor
*/
wordlen(str)
register char *str;
{
register short i;
for (i = 0; *str && *str != ' '; ++i, ++str);
return(i);
}
/*
* Find the path from some root device to a specific filename (src), and
* stick the result in (dest). If unable to backtrace along directories,
* simply copy (src) into (dest)
*
* Returns (1) if able to backtrace, (0) if not.
*/
getpath(src, dest)
char *src, *dest;
{
register long flock, pflock;
register short len, total;
register FIB *fib = (FIB *)malloc(sizeof(FIB));
char c;
dest[0] = 0;
total = 1;
flock = Lock(src, ACCESS_READ);
if (flock == NULL) { /* missing file? */
for (len = strlen(src); len >= 0; --len) {
if (src[len] == '/') {
--len;
break;
}
if (src[len] == ':')
break;
}
if (c = src[len + 1]) {
strcpy(dest, src+len+2);
total = strlen(dest)+1;
}
src[len + 1] = 0;
flock = Lock(src, ACCESS_READ);
src[len + 1] = c;
}
if (flock) {
do {
pflock = ParentDir(flock);
if (Examine(flock, fib) == 0)
fib->fib_FileName[0] = 0;
if (fib->fib_FileName[0] == 0)
strcpy(fib->fib_FileName, "ram");
len = strlen(fib->fib_FileName);
bmov(dest, dest + len + 1, total);
dest[len] = (pflock) ? '/' : ':';
bmov(fib->fib_FileName, dest, len);
total += len + 1;
UnLock(flock);
flock = pflock;
} while(pflock);
len = strlen(dest) - 1;
if (dest[len] == '/')
dest[len] = 0;
return(1);
}
strcpy(dest, src);
return(0);
}
/*
* Allocation routines and other shortcuts
*/
ubyte *
allocb(bytes)
{
return(AllocMem(bytes, MEMF_CLEAR|MEMF_PUBLIC));
}
ubyte *
allocl(lwords)
{
return(AllocMem(lwords<<2, MEMF_CLEAR|MEMF_PUBLIC));
}
bmovl(s,d,n)
char *s,*d;
{
bmov(s,d,n<<2);
}
/*
* Remove tabs in a buffer
*/
detab(ibuf, obuf, maxlen)
register char *ibuf, *obuf;
{
register short i, j;
maxlen -= 2;
for (i = j = 0; ibuf[i] && j < maxlen; ++i) {
if (ibuf[i] == 9) {
do {
obuf[j++] = ' ';
} while ((j & 7) && j < maxlen);
} else {
obuf[j++] = ibuf[i];
}
}
while (j && obuf[j-1] == ' ')
--j;
obuf[j] = 0;
return(j);
}
xefgets(xfi, buf, max)
char *buf;
long xfi;
{
char ebuf[256];
if (xfgets(xfi, ebuf, max) >= 0)
return(detab(ebuf, buf, max));
return(-1);
}