OpenCores
URL https://opencores.org/ocsvn/System09/System09/trunk

Subversion Repositories System09

[/] [System09/] [trunk/] [Tools/] [as09/] [ffwd.c] - Blame information for rev 95

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 83 davidgb
/*
2
 *      file I/O version of forward ref handler
3
 */
4
 
5
#define FILEMODE 0644 /* file creat mode */
6
#define UPDATE  2 /* file open mode */
7
#define ABS  0 /* absolute seek */
8
 
9
int Forward =0;  /* temp file's file descriptor */
10
char Fwd_name[] = { "Fwd_refs" } ;
11
 
12
/*
13
 *      fwdinit --- initialize forward ref file
14
 */
15
fwdinit()
16
{
17
 Forward = open(Fwd_name,O_CREAT | O_TRUNC | O_WRONLY, FILEMODE); //creat(Fwd_name,FILEMODE);
18
 if(Forward <0)
19
  fatal("Can't create temp file");
20
 close(Forward); /* close and reopen for reads and writes */
21
 Forward = open(Fwd_name,UPDATE);
22
 if(Forward <0)
23
  fatal("Forward ref file has gone.");
24
}
25
 
26
/*
27
 *      fwdreinit --- reinitialize forward ref file
28
 */
29
fwdreinit()
30
{
31
 F_ref   = 0;
32
 Ffn     = 0;
33
 lseek(Forward,0L,ABS);   /* rewind forward refs */
34
 read(Forward,&Ffn,sizeof(Ffn));
35
 read(Forward,&F_ref,sizeof(F_ref)); /* read first forward ref into mem */
36
#ifdef DEBUG
37
 printf("First fwd ref: %d,%d\n",Ffn,F_ref);
38
#endif
39
}
40
 
41
/*
42
 *      fwdmark --- mark current file/line as containing a forward ref
43
 */
44
fwdmark()
45
{
46
 write(Forward,&Cfn,sizeof(Cfn));
47
 write(Forward,&Line_num,sizeof(Line_num));
48
}
49
 
50
/*
51
 *      fwdnext --- get next forward ref
52
 */
53
fwdnext()
54
{
55
 int stat;
56
 
57
 stat = read(Forward,&Ffn,sizeof(Ffn));
58
#ifdef DEBUG
59
 printf("Ffn stat=%d ",stat);
60
#endif
61
 stat = read(Forward,&F_ref,sizeof(F_ref));
62
#ifdef DEBUG
63
 printf("F_ref stat=%d  ",stat);
64
#endif
65
 if( stat < 2 ){
66
  F_ref=0;Ffn=0;
67
  }
68
#ifdef DEBUG
69
 printf("Next Fwd ref: %d,%d\n",Ffn,F_ref);
70
#endif
71
}
72
 
73
/*
74
 *  fwd_done --- closes & deletes forward reference file
75
 */
76
fwd_done()
77
{
78
        int stat;
79
 
80
        stat = close(Forward); /* Have to close first on MS-DOS or you leave lost clusters. */
81
#ifndef DEBUG
82
        if( stat == 0 )        /* If close was successful, delete file */
83
                unlink(Fwd_name);
84
#endif
85
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.