home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Club Amiga de Montreal - CAM
/
CAM_CD_1.iso
/
files
/
635.lha
/
mini
/
mini.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-10-28
|
4KB
|
152 lines
/* The routines in this file are copyright © 1990 by Lorenzo Zago.
* Permission is granted for use and free distribution as long as the
* original author's name is included with the code.
* These routines may be modified for improvements and adaptations as
* long as:
* - credits for the original ideas and code are given to the original
* author;
* - the modified program is made freely available in the PD distribution;
* - a copy of the new source code and executables are sent to L. Zago.
*
* Compiled with Lattice C 4.0
* LC:lc -M -r -v -b mini.c
* Linked as
* Blink LIB:c.o+_main.o+mini.o+Sprintf.o TO mini SC SD ND LIB amiga.lib+lc.lib */
#include <libraries/dosextens.h>
#include <exec/memory.h>
#include <intuition/intuitionbase.h>
#include <intuition/intuition.h>
#include <workbench/startup.h>
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<=(b)?(a):(b))
#define ACTIVESCREEN IntuitionBase->ActiveScreen
#define ACTIVESCREENWIDTH IntuitionBase->ActiveScreen->Width
#define ACTIVESCREENHEIGHT IntuitionBase->ActiveScreen->Height
struct IntuitionBase *IntuitionBase;
struct Window *wind ;
char *lines[70],*strchr();
int oldlock;
struct FileHandle *fp,*fc,*Open(),*fo;
VOID OpenLibs(), MemCleanup(), MiniWindow(),
Finish();
void main(argc,argv)
int argc;
char **argv;
{ char *buf,*ib,*eb; UBYTE qc=0;
long i,lin=1,len=1,slen[70];
int ic=0,maxlin,maxcol,tc,ms,id=0;
short x,y,w,h;
struct WBStartup *argmsg; /* *WBenchMsg; */
struct WBArg *arg;
IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",0);
if (IntuitionBase == NULL) exit(FALSE);
fo=Output();
if (argc > 0)
{ if((argc != 2) || !strcmp(argv[1],"?"))
{ fprintf(fo,"Mini ©1990 L.Zago \n Usage: %s <filename>\n",argv[0]);
CloseLibrary( IntuitionBase); exit(20); }
ib=argv[1];
}
else
{ argmsg = (struct WBStartup *)argv;
arg= argmsg->sm_ArgList; arg++;
ib=arg->wa_Name; oldlock=CurrentDir (arg->wa_Lock); }
if ((fp=Open(ib,MODE_OLDFILE))==0)
{ fprintf (fo,"Problems opening file %s \n",ib);
CloseLibrary( IntuitionBase); exit(20); }
maxlin = (ACTIVESCREENHEIGHT-13)/8-1;
maxcol = (ACTIVESCREENWIDTH-20) /8;
tc=maxlin*maxcol; ms=tc+2;
buf = (char *)AllocMem (ms,MEMF_CLEAR);
tc = Read (fp,buf,tc); ib=buf;
while (ic<20)
{ if ((*ib==0) || ((*ib>127) && (*ib<160)))
{ ic=MessageWindow ("File contain binaries ...");
Finish(); }
ib++; ic++;
}
ib=buf; lines[1]=ib;
eb=buf+tc; *eb=0;
eb++; *eb=0;
while ((ib < eb) && (lin <= maxlin+1))
{ ib=strchr (ib,10); if (ib==0) break;
*ib = 0;
slen[lin]=strlen(lines[lin]);
len=max(len,slen[lin]);
ib++; if (*ib == 0) break;
lin=lin+1; lines[lin]=ib;
}
while (slen[lin]==0) lin--;
if (lin > maxlin)
{ ic=MessageWindow ("File has too many lines ...");
if (ic == 113) Finish(); else lin=maxlin; id=1; }
if (len > maxcol)
{ ic=MessageWindow ("File has too long lines ...");
if (ic == 113) Finish(); else len=maxcol; id=1; }
w=len*8+14; h=(lin+id)*8+13;
x=Seed()*(ACTIVESCREENWIDTH-w)/3000;
y=Seed()*(ACTIVESCREENHEIGHT-h)/3000;
MiniWindow (x,y,w,h);
for (i=1;i<lin;i++) fprintf (fc,"%s\n",lines[i]);
fprintf (fc,"%s",lines[lin]);
while (qc != 113)
{ i=WaitForChar (fc,1000000000L);
Read (fc,&qc,1);
}
if (buf) FreeMem (buf,ms);
Finish();
}
VOID Finish()
{ if (fp) Close (fp);
if (fc) Close (fc);
if (oldlock) CurrentDir (oldlock);
if (IntuitionBase) CloseLibrary( IntuitionBase);
exit(0);
}
Seed()
{ long c[3];
DateStamp(&c[0]);
return (c[2]);
}
MessageWindow(text)
char *text;
{ short x,y,w,h; int i; UBYTE ic;
x=160; y=100; w=392; h=29;
MiniWindow (x,y,w,h);
fprintf (fc,"%s\n",text);
i= WaitForChar (fc,1000000000L);
Read (fc,&ic,1);
return (ic);
}
VOID MiniWindow (x,y,w,h)
short x,y,h,w;
{ char con[100];
w=w+8;
if (wind == 0)
{ Sprintf (&con[0],"RAW:%ld/%ld/%ld/%ld/Mini ©1990 L.Zago",x,y,w,h);
fc = Open (con,1005L);
wind = IntuitionBase->ActiveWindow;
}
else { MoveWindow (wind,x-wind->LeftEdge,y-wind->TopEdge);
SizeWindow (wind,w-wind->Width,h-wind->Height);
Delay(20); }
}
VOID MemCleanup(){}