-
Notifications
You must be signed in to change notification settings - Fork 3
/
OutIni.c
186 lines (166 loc) · 4.97 KB
/
OutIni.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/*
* LSI-11 Linker
* úÁÐÉÓØ/ÞÔÅÎÉÅ ×ÙÈÏÄÎÏÇÏ ÆÁÊÌÁ
* íÅÔÏÄ ÒÁÂÏÔÙ: ÐÒÏÞÅÓÔØ-ÎÁÓÔÒÏÉÔØ-ÚÁÐÉÓÁÔØ.
*/
#include <SysStrings> /* MVS() */
#include <FileSystem>
#define LFNAME (sizeof(Fname))
#include <FileIO>
#define READL 2
#define WRITEL 3
#include <SysErrors>
#include "LinkerDefs"
static char outname[ LFNAME ];
static unsigned block; static int index; /* õËÁÚÁÔÅÌØ ××ÏÄÁ/×Ù×ÏÄÁ */
#define BUFLENG (SectorSize*4)
static union {
char fbuff[ BUFLENG ];
int buff_padder;
} ub;
static long totleng; /* äÌÉÎÁ ÆÁÊÌÁ, ÚÁÐÉÓÁÎÎÏÇÏ ÎÁ ÄÉÓË */
static int secsize; /* òÁÚÍÅÒ ÓÅËÔÏÒÁ */
static char flab;
/*
* ïÔËÒÙÔØ ×ÒÅÍÅÎÎÙÊ ÆÁÊÌ
*/
void OutIni( fname )
char *fname;
{
int rc;
FileItem ipar;
int i;
for( i = 0; i < LFNAME; i++ ){
outname[ i ] = (*fname != '\0') ? *fname++ : ' ';
}
MVS( outname, LFNAME, ipar.name.c ); ipar.type = '-';
ipar.access = ipar.protection = 0; ipar.p.pwd = 0;
if( (rc = DoUniqName( &ipar, WorkCatal )) < 0 ) Error(11);
flab = (char) rc;
secsize = GetSectorSize( flab );
block = 0; index = 0; totleng = 0l;
}
/*
* ðÒÏÞÅÓÔØ 2 ÂÁÊÔa; õËÁÚÁÔÅÌØ ×/× îå óíåýáåôóñ!
*/
unsigned OutWGet( Offset )
unsigned Offset;
{
unsigned AskBlock;
IOl_block iopar;
int rc;
long leng;
if( Offset & 1 ) Error(14);
if( (AskBlock = Offset/secsize) < block ||
AskBlock >= block+BUFLENG/secsize )
{
if( index != 0 ){
iopar.label = flab; iopar.dir = WRITEL;
iopar.bufadr = ub.fbuff;
leng = ((long)block)*secsize + (iopar.buflen = index);
if( leng >= totleng ){ /* äÌÉÎÁ ×ÏÚÒÏÓÌÁ ? */
totleng = leng;
}else{ /* ÷ ÂÕÆÅÒÅ ÂÏÌØÛÅ, ÞÅÍ index*/
iopar.buflen = BUFLENG; /* þÔÏÂÙ ÎÅ ÏÂÒÅÚÁÔØ ÐÏ index*/
}
iopar.sector = (long) block;
if( (rc = _io_( &iopar )) >> 8 == (~0) ){
if( rc != ErrDiskFull ) Error(12);
Error(13); /* äÉÓË ÐÅÒÅÐÏÌÎÅÎ */
}
}
iopar.dir = READL;
iopar.buflen = BUFLENG;
iopar.sector = (long) (block = AskBlock);
if( (rc = _io_( &iopar )) >> 8 == (~0) ){
if( rc != ErrFileAddr ) Error(14);
}
index = Offset % secsize;
}else{
index = Offset - block*secsize;
}
return (ub.fbuff[ index+1 ] << 8) + (ub.fbuff[ index ] & 0xFF);
}
/*
* úÁÐÉÓÁÔØ × ÆÁÊÌ; õËÁÚÁÔÅÌØ ×/× ÓÍÅÝÁÅÔÓÑ ÏÂÙÞÎÙÍ ÐÏÒÑÄËÏÍ
*/
void OutWrite( Buff, Len )
register char *Buff;
int Len;
{
IOl_block iopar;
int rc;
long leng;
for( ; --Len >= 0; ){
ub.fbuff[ index ] = *Buff++;
if( ++index >= BUFLENG ){
iopar.label = flab; iopar.dir = WRITEL;
iopar.bufadr = ub.fbuff;
iopar.buflen = BUFLENG;
iopar.sector = (long) block;
if( (rc = _io_( &iopar )) >> 8 == (~0) ){
if( rc != ErrDiskFull ) Error(12);
Error(13); /* äÉÓË ÐÅÒÅÐÏÌÎÅÎ */
}
block += BUFLENG/secsize;
index = 0;
}
}
if( (leng = block*secsize + index) >= totleng ) totleng = leng;
}
void OutClose()
{
static char out_proc[8] = {
0x02,0x1F,0xBE,0xA0,0x0C,0xD0,0x00,0x00
};
int rc;
{
static IOl_block iopar;
long leng;
if( index != 0 ){
iopar.label = flab; iopar.dir = WRITEL;
iopar.bufadr = ub.fbuff;
iopar.buflen = BUFLENG;
leng = ((long)block)*secsize + index;
if( leng >= totleng ){
totleng = leng;
iopar.buflen = index;
}
iopar.sector = (long) block;
if( (rc = _io_( &iopar )) >> 8 == (~0) ){
if( rc != ErrDiskFull ) Error(12);
Error(13); /* äÉÓË ÐÅÒÅÐÏÌÎÅÎ */
}
}
SetEOF( flab, (totleng + (secsize-1)) / secsize );
}
{
static FileItem fpar;
char *cp;
Statistics fib; /* âÕÆÅÒ ÉÎÆÏÒÍÁÃÉÉ Ï ÆÁÊÌÅ */
fpar.type = 'B';
MVS( outname, LFNAME, fpar.name.c );
DeleteName( &fpar, WorkCatal );/* óÔÉÒÁÅÍ, ÍÏÖÅÔ ÄÁÔØ EFILNU */
fpar.protection = 0;
fpar.access = 2;
{ register FileItem *ip;
fpar.p.pwd = ((ip=GetFileItem(OwnCatal)) == 0)? 0: ip->p.pwd;
}
Tget( &fib ); /* ðÏÌÕÞÁÅÍ ÒÁÚÍÅÒÙ ÐÒÏÇÒÁÍÍÙ */
cp = (char*) &fpar.info;
/* òÁÚÍÅÒ ËÏÄÁ */
*cp++ = (char) fib.Stlen; *cp++ = (char) (fib.Stlen >> 8);
/* òÁÚÍÅÒ ÄÁÎÎÙÈ */
*cp++ = (char) fib.Sdlen; *cp++ = (char) (fib.Sdlen >> 8);
/* òÁÚÍÅÒ ÂÕÆÅÒÏ× */
*cp++ = (char) fib.Sblen; *cp++ = (char) (fib.Sblen >> 8);
/* úÁÒÅÚÅÒ×ÉÒÏ×ÁÎÏ */
*cp++ = *cp++ = 0;
MVS( out_proc, 8, (char*) &fpar.processor );
/*ðÅÒÅÉÍÅÎÏ×Ù×ÁÅÍ*/
if( RenameFile( &fpar, flab, WorkCatal ) < 0 ){
Error(15);
}
CloseFile( flab );
}
}