home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Datafile PD-CD 5
/
DATAFILE_PDCD5.iso
/
utilities
/
m
/
motorola
/
!AsRef
/
Sources
/
c
/
ffwdansi
< prev
next >
Wrap
Text File
|
1993-07-18
|
3KB
|
121 lines
#include <stdio.h>
#include "mselect.h" /*external selection of microprocessor symbol table*/
#include "proto.h"
#include "as.h"
#include "extvars.h"
#include "structs.h"
/*
* file I/O version of forward ref handler
*/
/*
* fwdinit --- initialize forward ref file
*/
void
fwdinit(void)
{
if ((Forward = fopen(Fwd_name, "w+b")) == NULL)
fatal("Cannot open forward reference file - no Wimp$ScrapDir?");
return;
}
/*
* fwdreinit --- reinitialize forward ref file
*/
void
fwdreinit(void)
{
int stat;
extern int Ffn;
extern int F_ref;
F_ref = 0;
Ffn = 0;
rewind(Forward); /* rewind forward refs */
stat = fread(&Ffn, 1, sizeof(int), Forward);
if (ferror(Forward) != 0)
fatal("Unable to read forward ref file");
/*
* ad first forward ref into mem
*/
stat = fread(&F_ref, 1, sizeof(int), Forward); /* read first forward
* ref into mem */
if (ferror(Forward) != 0)
fatal("Unable to read forward ref file");
#ifdef DEBUG
printf("First fwd ref: %d,%d\n", Ffn, F_ref);
#endif
}
/*
* fwdmark --- mark current file/line as containing a forward ref
*/
void
fwdmark(void)
{
int stat;
extern int Cfn, Line_num;
stat = fwrite(&Cfn, sizeof(Cfn), sizeof(char), Forward);
/*
* if( stat < sizeof(int)) fatal("Unable to write to forward ref
* file");
*/
stat = fwrite(&Line_num, sizeof(Line_num), sizeof(char), Forward);
/*
* if( stat < sizeof(int)) fatal("Unable to write to forward ref
* file");
*/
}
/*
* fwdnext --- get next forward ref
*/
void
fwdnext(void)
{
int stat;
extern int F_ref, Ffn;
stat = fread(&Ffn, 1, sizeof(int), Forward);
if (ferror(Forward))
fatal("Unable to read forward ref file");
#ifdef DEBUG
printf("Ffn stat=%d ", stat);
#endif
stat = fread(&F_ref, 1, sizeof(int), Forward);
/*
* if( stat < sizeof(F_ref) ){ if( ferror(Forward) ) fatal("Unable to
* read forward ref file"); F_ref=0; Ffn=0; }
*/
if (stat < 2) {
if (ferror(Forward))
fatal("Unable to read forward ref file");
F_ref = 0;
Ffn = 0;
}
#ifdef DEBUG
printf("F_ref stat=%d ", stat);
printf("Next Fwd ref: %d,%d\n", Ffn, F_ref);
#endif
}
/*
* fwd_done --- closes & deletes forward reference file
*/
void
fwd_done(void)
{
fclose(Forward); /* Have to close first on MS-DOS or you leave
* lost clusters. */
#ifndef DEBUG
remove(Fwd_name);
#endif
}