home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga MA Magazine 1998 #6
/
amigamamagazinepolishissue1998.iso
/
coders
/
snooplibs
/
fd2sl
/
fd2sl.c
< prev
next >
Wrap
C/C++ Source or Header
|
1986-05-23
|
5KB
|
169 lines
#include <exec/types.h>
#include <exec/memory.h>
#include <dos/dos.h>
#include <clib/exec_protos.h>
#include <clib/dos_protos.h>
#include <string.h>
#include <stdio.h>
#include <dos/stdio.h>
#include <stdlib.h>
#include <libraries/dos.h>
//-------------------------------------------------------------------------\\
//--- fd2sl -> convert library ".fd" files to SnoopLibs's ".sl" files. ---\\
//--- Compile: (SAS 5.x) lc -v -cfuist -L fd2sl.c ---\\
//--- ---\\
//--- The format of the ".sl" files is in ascii so the output-format ---\\
//--- strings can be edited; this will make a better output possible. ---\\
//--- ---\\
//--- (c) ASWare 1993 by Ekke Verheul. ---\\
//--- ASWare, Postbus 2521, 3000 CM, Rotterdam, the Netherlands. ---\\
//-------------------------------------------------------------------------\\
LONG line = 0;
WORD offset = 0;
BOOL public = 1, remarks = 1;
UBYTE name[64], args[128], format[256];
int Convert( UBYTE *buf );
void PrintFunction( UBYTE *buf );
//-----------------------------------------------------------------
void main(int argc, char **argv)
{
FILE *input;
UBYTE buf[256];
if (argc > 1 && argv[1][0] != '?')
{
if (input = fopen(argv[1],"r"))
{
if (argc > 2 && argv[2][0] == 'R') remarks = 0;
while (fgets(buf,256,input))
{
if (Convert(buf)) break;
line++;
}
fclose(input);
}
}
else
{ printf ("\nFORMAT: fd2sl [>output.sl] <name.fd> [R]\n\n");
}
}
//-----------------------------------------------------------------
int Convert( UBYTE *buf )
{
switch (line)
{
case 0: //--- the first line must be a `* "#?.library"'
{ UBYTE *ptr;
if (!strncmp(buf,"* \"",3))
{
for (ptr=&buf[3]; *ptr && *ptr != '.'; ptr++);
if (*ptr)
{ *ptr++ = '\0';
if (!strncmp(ptr,"library\"",8))
{
printf("* SnoopLib: %s.library\n",&buf[3]);
return(0);
}
}
}
printf("Not a library.fd file...\n");
return(-1);
}
case 1:
{ if (!strncmp(buf,"##base ",7)) return(0);
return(1);
}
default:
{
switch (buf[0])
{
case '*':
{ if (remarks) printf(buf);
return(0); //--- skip remarks
}
case '#':
{ int offs;
if (sscanf(buf,"##bias %d",&offs)) //--- set offset
{ offset = offs;
return(0);
}
else if (!strncmp(buf,"##public",8))
{ public = 1;
return(0);
}
else if (!strncmp(buf,"##private",9))
{ public = 0;
return(0);
}
else if (!strncmp(buf,"##end",5))
{ return(-1);
}
printf(" Unknown command: %s\n",buf);
return(-1);
}
default:
{
if (public)
{ PrintFunction(buf);
}
offset += 6;
return(0);
}
}
}
}
}
//-----------------------------------------------------------------
void PrintFunction( UBYTE *buf )
{
UBYTE *ptr1,*ptr2,*p;
WORD i;
name[0] = 0;
args[0] = 0;
format[0] = 0;
//--- TextLength(rp,string,count)(a1,a0,d0)
//--- ==> FFCA TextLength «%s(rp: 0x%06lx, string: 0x%06lx, count: %ld)» «a1,a0,d0»
for (ptr1=buf,i=0; *ptr1 && *ptr1 != '(' && i < 63; name[i++] = *ptr1++); //--- copy name
name[i] = 0; ptr1++;
strcpy(format,"«%s (");
if (*ptr1!=')') //--- any arguments ?
{
strcpy(args,"«");
for (ptr2 = ptr1; *ptr2 && *ptr2 != '('; ptr2++); //--- find registers
ptr2++;
for (p=ptr2; *p; p++) if (*p==',' || *p=='/' || *p==')') *p=0;
for (p=ptr1; p<ptr2; p++) //--- count args
{ if (*p==',' || *p==')')
{ *p=0;
strcat(format,ptr1);
while (*ptr1) ptr1++; ptr1++;
if (*ptr2 == 'd') strcat(format,": %ld, ");
else strcat(format,": 0x%06lx, ");
strcat(args,ptr2);
strcat(args,",");
while (*ptr2) ptr2++; ptr2++;
}
}
format[strlen(format)-2]='\0';
args[strlen(args)-1]='»';
}
else strcat(format," void ");
strcat(format,")»");
printf( "%04X %s %s %s\n",(-offset)&0xFFFF,name,format,args);
}