| 1 | /* crumf2ux - convert PC master file to UNIX/Linux format |
|---|
| 2 | crunchmf/AOT, 10/04/2001 |
|---|
| 3 | */ |
|---|
| 4 | #include <stdio.h> |
|---|
| 5 | #include <string.h> |
|---|
| 6 | #include "cisis.h" |
|---|
| 7 | #include "cirun.h" |
|---|
| 8 | |
|---|
| 9 | #define pc_SIZEOF_M0STRU 32 |
|---|
| 10 | #define pc_LEADER 18 |
|---|
| 11 | #define pc_MSNVSPLT 14 /* gdb .mst never split - 'til base */ |
|---|
| 12 | |
|---|
| 13 | #define ux_SIZEOF_M0STRU 32 |
|---|
| 14 | #define ux_LEADER 20 |
|---|
| 15 | #define ux_MSNVSPLT 16 /* gdb .mst never split - 'til base */ |
|---|
| 16 | |
|---|
| 17 | #define NOSW_20 0 |
|---|
| 18 | #define NOSW_21 1 |
|---|
| 19 | #define NOSW_40 0 |
|---|
| 20 | #define NOSW_41 1 |
|---|
| 21 | #define NOSW_42 2 |
|---|
| 22 | #define NOSW_43 3 |
|---|
| 23 | |
|---|
| 24 | #define SWAP_20 1 |
|---|
| 25 | #define SWAP_21 0 |
|---|
| 26 | #define SWAP_40 3 |
|---|
| 27 | #define SWAP_41 2 |
|---|
| 28 | #define SWAP_42 1 |
|---|
| 29 | #define SWAP_43 0 |
|---|
| 30 | |
|---|
| 31 | int target_SIZEOF_M0STRU; |
|---|
| 32 | int target_LEADER; |
|---|
| 33 | int target_MSNVSPLT; |
|---|
| 34 | |
|---|
| 35 | char *movtmp; |
|---|
| 36 | int alignment; |
|---|
| 37 | int mv20,mv21,mv40,mv41,mv42,mv43; |
|---|
| 38 | int xalign; |
|---|
| 39 | |
|---|
| 40 | #define mov2(moved,movp,source) \ |
|---|
| 41 | movtmp = (char *)&(source); \ |
|---|
| 42 | if (alignment >= 2) if ((xalign=moved%2) != 0) while (xalign--) { *movp++ = '\0'; moved++; } \ |
|---|
| 43 | *movp++ = movtmp[mv20]; \ |
|---|
| 44 | *movp++ = movtmp[mv21]; \ |
|---|
| 45 | moved+=2; |
|---|
| 46 | #define mov4(moved,movp,source) \ |
|---|
| 47 | if (alignment >= 4) if ((xalign=moved%4) != 0) while (xalign--) { *movp++ = '\0'; moved++; } \ |
|---|
| 48 | movtmp = (char *)&(source); \ |
|---|
| 49 | *movp++ = movtmp[mv40]; \ |
|---|
| 50 | *movp++ = movtmp[mv41]; \ |
|---|
| 51 | *movp++ = movtmp[mv42]; \ |
|---|
| 52 | *movp++ = movtmp[mv43]; \ |
|---|
| 53 | moved+=4; |
|---|
| 54 | #define movx(sourcep,len) \ |
|---|
| 55 | memcpy(movp,sourcep,(size_t)len); \ |
|---|
| 56 | movp+=len; \ |
|---|
| 57 | moved+=len; |
|---|
| 58 | /* |
|---|
| 59 | #define mov2(moved,movp,source) \ |
|---|
| 60 | movtmp = (char *)&(source); \ |
|---|
| 61 | swab(movtmp,movp,2); movp+=2; \ |
|---|
| 62 | moved+=2; |
|---|
| 63 | */ |
|---|
| 64 | |
|---|
| 65 | #if ANSI |
|---|
| 66 | void putuxmst(LONGX mfn, UWORD reclen); |
|---|
| 67 | void putuxxrf(LONGX mfn, LONGX comb, int comp); |
|---|
| 68 | void enduxmst(UWORD reclen); |
|---|
| 69 | #else |
|---|
| 70 | void putuxmst(); |
|---|
| 71 | void putuxxrf(); |
|---|
| 72 | void enduxmst(); |
|---|
| 73 | #endif |
|---|
| 74 | |
|---|
| 75 | int xrf_fd; |
|---|
| 76 | char *xrf_buffer; |
|---|
| 77 | LONGX xrf_lastmfn; |
|---|
| 78 | int mst_fd; |
|---|
| 79 | char *mst_buffer,*mst_record; |
|---|
| 80 | LONGX mst_nxtmfb; |
|---|
| 81 | int mst_nxtmfp; |
|---|
| 82 | UWORD mst_left,mst_type; |
|---|
| 83 | |
|---|
| 84 | void main(argc,argv) |
|---|
| 85 | int argc; |
|---|
| 86 | char *argv[]; |
|---|
| 87 | { |
|---|
| 88 | RECSTRU *recp; /* mandatory for defines REC RDB MF0 MFR DIR, FIELDP */ |
|---|
| 89 | char *dbnp,*uxdbnp; |
|---|
| 90 | LONGX irec,mfn; |
|---|
| 91 | UWORD mfrl,base,datalen; |
|---|
| 92 | DIRSTRU *dirp; |
|---|
| 93 | int xdir; |
|---|
| 94 | char *p,line[BUFSIZ]; |
|---|
| 95 | LONGX count1,count2; |
|---|
| 96 | int argnext=1; |
|---|
| 97 | int parmtrace=0; |
|---|
| 98 | LONGX parmfrom,parmto,parmtell,parmloop,parmcount; |
|---|
| 99 | /* int zero=0; */ |
|---|
| 100 | char *movp; |
|---|
| 101 | UWORD moved; |
|---|
| 102 | |
|---|
| 103 | /* |
|---|
| 104 | #if PC || VAX || UNISYSCPU || INTELCPU |
|---|
| 105 | #define SWAPPED 1 |
|---|
| 106 | #endif |
|---|
| 107 | */ |
|---|
| 108 | #define TARGET_pc 0 |
|---|
| 109 | #define TARGET_linux 1 |
|---|
| 110 | #define TARGET_hp-ux 2 |
|---|
| 111 | #define TARGET_sun 3 |
|---|
| 112 | #define TARGET_alpha 4 |
|---|
| 113 | #define TARGET_vax 5 |
|---|
| 114 | #define TARGET_unisys 6 |
|---|
| 115 | #define TARGET_mpe 7 |
|---|
| 116 | #define TARGET_cdc 8 |
|---|
| 117 | /* 0 1 2 3 4 5 6 7 8 */ |
|---|
| 118 | char *target_id[] = {"pc","linux","hpux","sun","alpha","vax","unisys","mpe","cdc",NULL}; |
|---|
| 119 | int target_align[] = { 1, 4, 4, 4, 4, 1, 4, 4, 4, 0 }; |
|---|
| 120 | int target_swapped[]= { 1, 1, 0, 0, 1, 1, 1, 0, 0, 0 }; |
|---|
| 121 | int i; |
|---|
| 122 | |
|---|
| 123 | #if PC |
|---|
| 124 | int xtarget=TARGET_linux; |
|---|
| 125 | #else |
|---|
| 126 | int xtarget=TARGET_pc; |
|---|
| 127 | #endif |
|---|
| 128 | |
|---|
| 129 | int xorigin=TARGET_alpha; |
|---|
| 130 | #if PC |
|---|
| 131 | xorigin=TARGET_pc; |
|---|
| 132 | #endif |
|---|
| 133 | #if UNIX |
|---|
| 134 | #if INTELCPU |
|---|
| 135 | xorigin=TARGET_linux; |
|---|
| 136 | #endif |
|---|
| 137 | #endif |
|---|
| 138 | #if BRME |
|---|
| 139 | xorigin=TARGET_hp-ux; |
|---|
| 140 | #endif |
|---|
| 141 | #if SUN |
|---|
| 142 | xorigin=TARGET_sun; |
|---|
| 143 | #endif |
|---|
| 144 | #if VAX |
|---|
| 145 | xorigin=TARGET_vax; |
|---|
| 146 | #endif |
|---|
| 147 | #if UNISYSCPU |
|---|
| 148 | xorigin=TARGET_unisys; |
|---|
| 149 | #endif |
|---|
| 150 | #if MPE |
|---|
| 151 | xorigin=TARGET_mpe; |
|---|
| 152 | #endif |
|---|
| 153 | #if CDCS4320 |
|---|
| 154 | xorigin=TARGET_cds; |
|---|
| 155 | #endif |
|---|
| 156 | /* |
|---|
| 157 | #define PC 0 |
|---|
| 158 | #define VAX 0 |
|---|
| 159 | #define MPE 0 |
|---|
| 160 | #define UNIX 0 |
|---|
| 161 | #define SUN 0 |
|---|
| 162 | #define UNISYSCPU 0 |
|---|
| 163 | #define INTELCPU 0 |
|---|
| 164 | #define BRME 0 |
|---|
| 165 | #define CDCS4320 0 |
|---|
| 166 | */ |
|---|
| 167 | |
|---|
| 168 | if (argc == 2 && strcmp(argv[1],"what") == 0) { |
|---|
| 169 | printf("%s",cicopyr("?Utility CRUMF2UX")); |
|---|
| 170 | printf("\n"); |
|---|
| 171 | exit(0); |
|---|
| 172 | } |
|---|
| 173 | if (argc < 3) { |
|---|
| 174 | printf("%s",cicopyr("Utility CRUMF2UX")); |
|---|
| 175 | printf("\n"); |
|---|
| 176 | printf("crumf2ux <dbn> <target_dbn> [<option> [...]] \n"); |
|---|
| 177 | printf(" \n"); |
|---|
| 178 | printf("options: \n"); |
|---|
| 179 | printf("\n"); |
|---|
| 180 | printf(" {from|to|loop|count|tell}=<n> \n"); |
|---|
| 181 | printf("\n"); |
|---|
| 182 | printf(" target=<platform> \n"); |
|---|
| 183 | printf("\n"); |
|---|
| 184 | printf("platforms: \n"); |
|---|
| 185 | printf("\n"); |
|---|
| 186 | printf(" %s (default for %s) \n",target_id[xtarget],target_id[xorigin]); |
|---|
| 187 | for (i=0; target_id[i]; i++) |
|---|
| 188 | if (i != xtarget && i != xorigin) printf(" %s \n",target_id[i]); |
|---|
| 189 | /* |
|---|
| 190 | printf(" target={%s",target_id[xtarget]); |
|---|
| 191 | for (i=0; target_id[i]; i++) |
|---|
| 192 | if (i != xtarget && i != xorigin) printf("|%s",target_id[i]); |
|---|
| 193 | printf("} \n"); |
|---|
| 194 | printf(" \n"); |
|---|
| 195 | printf("default: %s \n",target_id[xtarget]); |
|---|
| 196 | */ |
|---|
| 197 | printf(" \n"); |
|---|
| 198 | exit(1); |
|---|
| 199 | } |
|---|
| 200 | |
|---|
| 201 | /* get positional parms */ |
|---|
| 202 | dbnp=argv[argnext++]; |
|---|
| 203 | uxdbnp=argv[argnext++]; |
|---|
| 204 | |
|---|
| 205 | /* get optional parms */ |
|---|
| 206 | parmfrom=1L; parmto=9999999L; parmtell=0L; parmloop=1L; |
|---|
| 207 | |
|---|
| 208 | if (strcmp(dbnp,"null")) parmcount=LONGX_MAX; else parmcount=0L; |
|---|
| 209 | |
|---|
| 210 | for (; argnext < argc; ) { |
|---|
| 211 | p=argv[argnext++]; |
|---|
| 212 | if (strncmp(p,"from?",5) == 0 || strncmp(p,"from=",5) == 0) { |
|---|
| 213 | if (sscanf(p+5,"%"_LD_,&parmfrom) != 1) fatal(p); |
|---|
| 214 | continue; |
|---|
| 215 | } |
|---|
| 216 | if (strncmp(p,"to?",3) == 0 || strncmp(p,"to=",3) == 0) { |
|---|
| 217 | if (sscanf(p+3,"%"_LD_,&parmto) != 1) fatal(p); |
|---|
| 218 | continue; |
|---|
| 219 | } |
|---|
| 220 | if (strncmp(p,"count?",6) == 0 || strncmp(p,"count=",6) == 0) { |
|---|
| 221 | if (sscanf(p+6,"%"_LD_,&parmcount) != 1) |
|---|
| 222 | fatal(p); |
|---|
| 223 | continue; |
|---|
| 224 | } |
|---|
| 225 | if (strncmp(p,"loop?",5) == 0 || strncmp(p,"loop=",5) == 0) { |
|---|
| 226 | if (sscanf(p+5,"%"_LD_,&parmloop) != 1) |
|---|
| 227 | fatal(p); |
|---|
| 228 | continue; |
|---|
| 229 | } |
|---|
| 230 | if (strncmp(p,"tell?",5) == 0 || strncmp(p,"tell=",5) == 0) { |
|---|
| 231 | if (sscanf(p+5,"%"_LD_,&parmtell) != 1) fatal(p); |
|---|
| 232 | continue; |
|---|
| 233 | } |
|---|
| 234 | if (strcmp(p,"trace?all") == 0|| strcmp(p,"trace=all") == 0) { |
|---|
| 235 | parmtrace=dbxtrace=rectrace=1; |
|---|
| 236 | continue; |
|---|
| 237 | } |
|---|
| 238 | if (strcmp(p,"trace") == 0) { |
|---|
| 239 | parmtrace=1; |
|---|
| 240 | continue; |
|---|
| 241 | } |
|---|
| 242 | if (strncmp(p,"target?",7) == 0 || strncmp(p,"target=",7) == 0) { |
|---|
| 243 | int found=0; |
|---|
| 244 | for (xtarget=0; target_id[xtarget]; xtarget++) { |
|---|
| 245 | if (strcmp(p+7,target_id[xtarget])) continue; |
|---|
| 246 | found=1; break; |
|---|
| 247 | } |
|---|
| 248 | if (!found) fatal(p); |
|---|
| 249 | continue; |
|---|
| 250 | } |
|---|
| 251 | fatal(p); |
|---|
| 252 | } |
|---|
| 253 | |
|---|
| 254 | /* setup processing */ |
|---|
| 255 | alignment=target_align[xtarget]; |
|---|
| 256 | |
|---|
| 257 | if (xtarget == TARGET_pc) { |
|---|
| 258 | target_SIZEOF_M0STRU=pc_SIZEOF_M0STRU; |
|---|
| 259 | target_LEADER=pc_LEADER; |
|---|
| 260 | target_MSNVSPLT=pc_MSNVSPLT; |
|---|
| 261 | } else { |
|---|
| 262 | target_SIZEOF_M0STRU=ux_SIZEOF_M0STRU; |
|---|
| 263 | target_LEADER=ux_LEADER; |
|---|
| 264 | target_MSNVSPLT=ux_MSNVSPLT; |
|---|
| 265 | } |
|---|
| 266 | |
|---|
| 267 | mv20=NOSW_20; |
|---|
| 268 | mv21=NOSW_21; |
|---|
| 269 | mv40=NOSW_40; |
|---|
| 270 | mv41=NOSW_41; |
|---|
| 271 | mv42=NOSW_42; |
|---|
| 272 | mv43=NOSW_43; |
|---|
| 273 | if (target_swapped[xtarget] != target_swapped[xorigin]) { |
|---|
| 274 | mv20=SWAP_20; |
|---|
| 275 | mv21=SWAP_21; |
|---|
| 276 | mv40=SWAP_40; |
|---|
| 277 | mv41=SWAP_41; |
|---|
| 278 | mv42=SWAP_42; |
|---|
| 279 | mv43=SWAP_43; |
|---|
| 280 | } |
|---|
| 281 | |
|---|
| 282 | /* get control record */ |
|---|
| 283 | RECORD(irec=nrecs,dbnp,0L); |
|---|
| 284 | if (parmtrace) prtcontrol(recp,dbnp); |
|---|
| 285 | |
|---|
| 286 | /* create .xrf and allocate putuxxrf() output buffer */ |
|---|
| 287 | strcpy(line,uxdbnp); |
|---|
| 288 | strcat(line,xx1extp); |
|---|
| 289 | p=dbxopenc(uxdbnp,line,&xrf_fd,NULL,NULL,1,0); /*..force create= */ |
|---|
| 290 | if (xrf_fd <= 0) fatal(line); |
|---|
| 291 | if (parmtrace) printf("+++ %s=%d\n",p,xrf_fd); |
|---|
| 292 | xrf_buffer=(char *)ALLOC((ALLOPARM)XRBSIZ); |
|---|
| 293 | if (xrf_buffer == (char *)ALLONULL) fatal("ALLOC/xrf_buffer"); |
|---|
| 294 | |
|---|
| 295 | /* create .mst and allocate putuxmst() output buffer */ |
|---|
| 296 | strcpy(line,uxdbnp); |
|---|
| 297 | strcat(line,mx1extp); |
|---|
| 298 | p=dbxopenc(uxdbnp,line,&mst_fd,NULL,NULL,1,0); /*..force create= */ |
|---|
| 299 | if (mst_fd <= 0) fatal(line); |
|---|
| 300 | if (parmtrace) printf("+++ %s=%d\n",p,mst_fd); |
|---|
| 301 | mst_buffer=(char *)ALLOC((ALLOPARM)MSBSIZ); |
|---|
| 302 | if (mst_buffer == (char *)ALLONULL) fatal("ALLOC/mst_buffer"); |
|---|
| 303 | |
|---|
| 304 | /* initialize putuxxrf() */ |
|---|
| 305 | xrf_lastmfn=MF0nxtmfn-1; |
|---|
| 306 | if (parmto < xrf_lastmfn) xrf_lastmfn=parmto; |
|---|
| 307 | /* initialize putuxmst() */ |
|---|
| 308 | mst_nxtmfb=1L; |
|---|
| 309 | mst_nxtmfp=1; |
|---|
| 310 | mst_left=MSBSIZ; |
|---|
| 311 | mst_type=MF0mftype; |
|---|
| 312 | |
|---|
| 313 | /* allocate processing buffer */ |
|---|
| 314 | mst_record=(char *)ALLOC((ALLOPARM)MAXMFRL); |
|---|
| 315 | if (mst_record == (char *)ALLONULL) fatal("ALLOC/mst_record"); |
|---|
| 316 | |
|---|
| 317 | /* initialize control record */ |
|---|
| 318 | movp=mst_record; |
|---|
| 319 | moved=target_SIZEOF_M0STRU+target_SIZEOF_M0STRU; /* gdb */ |
|---|
| 320 | memset(movp,0x00,moved); |
|---|
| 321 | putuxmst(0L,moved); |
|---|
| 322 | for (mfn=1L; mfn < parmfrom; mfn++) { |
|---|
| 323 | putuxxrf(mfn,(-1L),0); /* PDEL pointer */ |
|---|
| 324 | } |
|---|
| 325 | |
|---|
| 326 | /* convert mf records */ |
|---|
| 327 | for (count1=count2=0L, mfn=parmfrom; mfn <= parmto; mfn+=parmloop) { |
|---|
| 328 | RECORD(irec,dbnp,mfn); |
|---|
| 329 | if (RECrc == RCEOF) break; |
|---|
| 330 | if (count1 >= parmcount) break; |
|---|
| 331 | count1++; |
|---|
| 332 | if (RECrc != RCNORMAL) { |
|---|
| 333 | putuxxrf(mfn,(-1L),0); /* PDEL pointer */ |
|---|
| 334 | continue; |
|---|
| 335 | } |
|---|
| 336 | count2++; |
|---|
| 337 | base=target_LEADER+MFRnvf*sizeof(DIRSTRU); |
|---|
| 338 | datalen=0; |
|---|
| 339 | for (dirp=MFRdir, xdir=MFRnvf; xdir--; dirp++) datalen+=dirp->len; |
|---|
| 340 | mfrl=base+datalen; |
|---|
| 341 | if (mfrl & 0x01) mfrl++; /* gdb always an even number */ |
|---|
| 342 | MFRmfbwb=0L; |
|---|
| 343 | MFRmfbwp=0; |
|---|
| 344 | movp=mst_record; moved=0; |
|---|
| 345 | mov4(moved,movp,MFRmfn); |
|---|
| 346 | mov2(moved,movp,mfrl); |
|---|
| 347 | /* mov2(moved,movp,zero); /* align - in putuxmst.. */ |
|---|
| 348 | mov4(moved,movp,MFRmfbwb); |
|---|
| 349 | mov2(moved,movp,MFRmfbwp); |
|---|
| 350 | mov2(moved,movp,base); |
|---|
| 351 | mov2(moved,movp,MFRnvf); |
|---|
| 352 | mov2(moved,movp,MFRstatus); |
|---|
| 353 | for (dirp=MFRdir, xdir=0; xdir < MFRnvf; xdir++, dirp++) { |
|---|
| 354 | mov2(moved,movp,dirp->tag); |
|---|
| 355 | mov2(moved,movp,dirp->pos); |
|---|
| 356 | mov2(moved,movp,dirp->len); |
|---|
| 357 | } |
|---|
| 358 | movx(MFX+MFRbase,datalen); |
|---|
| 359 | if (moved & 0x01) { |
|---|
| 360 | *movp=' '; moved++; /* gdb always an even number */ |
|---|
| 361 | } |
|---|
| 362 | putuxmst(mfn,moved); |
|---|
| 363 | |
|---|
| 364 | if (parmtell) |
|---|
| 365 | if (count1 % parmtell == 0) |
|---|
| 366 | fprintf(stderr,"+++ %"_LD_"/%"_LD_" \n",count1,count2); |
|---|
| 367 | } |
|---|
| 368 | |
|---|
| 369 | /* update control record */ |
|---|
| 370 | RECORD(irec,dbnp,0L); |
|---|
| 371 | MF0nxtmfn=xrf_lastmfn+1; |
|---|
| 372 | MF0nxtmfb=mst_nxtmfb; |
|---|
| 373 | MF0nxtmfp=mst_nxtmfp; |
|---|
| 374 | MF0reccnt=MF0mfcxx1=MF0mfcxx2=MF0mfcxx3=0; |
|---|
| 375 | movp=mst_record; moved=0; |
|---|
| 376 | mov4(moved,movp,MF0ctlmfn); |
|---|
| 377 | mov4(moved,movp,MF0nxtmfn); |
|---|
| 378 | mov4(moved,movp,MF0nxtmfb); |
|---|
| 379 | mov2(moved,movp,MF0nxtmfp); /* bug */ |
|---|
| 380 | mov2(moved,movp,MF0mftype); |
|---|
| 381 | mov4(moved,movp,MF0reccnt); |
|---|
| 382 | mov4(moved,movp,MF0mfcxx1); |
|---|
| 383 | mov4(moved,movp,MF0mfcxx2); |
|---|
| 384 | mov4(moved,movp,MF0mfcxx3); |
|---|
| 385 | enduxmst(moved); |
|---|
| 386 | if (parmtell) |
|---|
| 387 | if (count1 % parmtell == 0) ; else |
|---|
| 388 | fprintf(stderr,"+++ %"_LD_"/%"_LD_" \n",count1,count2); |
|---|
| 389 | |
|---|
| 390 | exit(0); |
|---|
| 391 | } |
|---|
| 392 | |
|---|
| 393 | void putuxmst(mfn,reclen) |
|---|
| 394 | LONGX mfn; |
|---|
| 395 | UWORD reclen; |
|---|
| 396 | { |
|---|
| 397 | char *p; |
|---|
| 398 | int n; |
|---|
| 399 | #if MSTTRACE |
|---|
| 400 | int loop; |
|---|
| 401 | for (p=mst_record, loop=0; loop<reclen; p++) { |
|---|
| 402 | printf("%02x ",*p); |
|---|
| 403 | if (++loop%16 == 0) printf("\n"); |
|---|
| 404 | } |
|---|
| 405 | printf("\n"); |
|---|
| 406 | #endif |
|---|
| 407 | if (mst_type == MSMFTMSG) { |
|---|
| 408 | n = reclen % MSBSIZ; |
|---|
| 409 | if (n) { |
|---|
| 410 | n=MSBSIZ-n; |
|---|
| 411 | memset(mst_record+reclen,0x00,n); reclen+=n; |
|---|
| 412 | } |
|---|
| 413 | } |
|---|
| 414 | if (mst_left < target_MSNVSPLT) { |
|---|
| 415 | memset(&mst_buffer[MSBSIZ-mst_left],0x00,mst_left); |
|---|
| 416 | if (CIWRITE(mst_fd,mst_buffer,MSBSIZ) < MSBSIZ) fatal("putuxmst/write"); |
|---|
| 417 | mst_nxtmfb++; mst_nxtmfp=1; |
|---|
| 418 | mst_left=MSBSIZ; |
|---|
| 419 | } |
|---|
| 420 | putuxxrf(mfn,mst_nxtmfb,mst_nxtmfp-1); |
|---|
| 421 | for (p=mst_record; reclen; ) { |
|---|
| 422 | if (reclen <= mst_left) { |
|---|
| 423 | memcpy(&mst_buffer[MSBSIZ-mst_left],p,(size_t)reclen); |
|---|
| 424 | mst_left-=reclen; |
|---|
| 425 | mst_nxtmfp+=reclen; |
|---|
| 426 | break; |
|---|
| 427 | } |
|---|
| 428 | memcpy(&mst_buffer[MSBSIZ-mst_left],p,mst_left); |
|---|
| 429 | if (CIWRITE(mst_fd,mst_buffer,MSBSIZ) < MSBSIZ) fatal("putuxmst/write"); |
|---|
| 430 | reclen-=mst_left; |
|---|
| 431 | p+=mst_left; |
|---|
| 432 | mst_left=MSBSIZ; |
|---|
| 433 | mst_nxtmfb++; mst_nxtmfp=1; |
|---|
| 434 | } |
|---|
| 435 | } |
|---|
| 436 | void enduxmst(reclen) |
|---|
| 437 | UWORD reclen; |
|---|
| 438 | { |
|---|
| 439 | #if MSTTRACE |
|---|
| 440 | char *p; |
|---|
| 441 | int loop; |
|---|
| 442 | for (p=mst_record, loop=0; loop<reclen; p++) { |
|---|
| 443 | printf("%02x ",*p); |
|---|
| 444 | if (++loop%16 == 0) printf("\n"); |
|---|
| 445 | } |
|---|
| 446 | printf("\n"); |
|---|
| 447 | #endif |
|---|
| 448 | if (mst_left < MSBSIZ) { |
|---|
| 449 | memset(&mst_buffer[MSBSIZ-mst_left],0x00,mst_left); |
|---|
| 450 | if (CIWRITE(mst_fd,mst_buffer,MSBSIZ) < MSBSIZ) fatal("enduxmst/write"); |
|---|
| 451 | } |
|---|
| 452 | putuxxrf(-1L,0L,0); |
|---|
| 453 | if (reclen) { |
|---|
| 454 | if (LSEEK64(mst_fd,SEEK_SET,0L) != 0L) fatal("enduxmst/seek"); |
|---|
| 455 | if (CIWRITE(mst_fd,mst_record,reclen) < reclen) fatal("enduxmst/write"); |
|---|
| 456 | } |
|---|
| 457 | } |
|---|
| 458 | void putuxxrf(mfn,comb,comp) |
|---|
| 459 | LONGX mfn; |
|---|
| 460 | LONGX comb; |
|---|
| 461 | int comp; |
|---|
| 462 | { |
|---|
| 463 | static XRSTRU *xrxp; |
|---|
| 464 | static LONGX xrf_block,xrf_lastblock; |
|---|
| 465 | static int xrf_lastidx; |
|---|
| 466 | static int xrf_towrit=0L; |
|---|
| 467 | XRPTR pointer,xrftiv; |
|---|
| 468 | int thisidx,n; |
|---|
| 469 | XRPOS thispos; |
|---|
| 470 | char x[4]; |
|---|
| 471 | char *movp; |
|---|
| 472 | UWORD moved; |
|---|
| 473 | |
|---|
| 474 | if (mfn < 0L) if (xrf_towrit) { |
|---|
| 475 | for (moved=0, movp=xrf_buffer, n=XRBSIZ; n; n-=4) {memcpy(x,movp,4); mov4(moved,movp,x[0]);} |
|---|
| 476 | if (CIWRITE(xrf_fd,xrf_buffer,XRBSIZ) != XRBSIZ) fatal("putuxxrf/write"); |
|---|
| 477 | if (xrxp->xrxrpos < 0) return; |
|---|
| 478 | |
|---|
| 479 | xrxp->xrxrpos = -xrf_lastblock; |
|---|
| 480 | xrftiv = (0)*XRXDIVIDE + (0); /* EOF pointer */ |
|---|
| 481 | for (n=0; n < XRMAXTIV; ) xrxp->xrmfptr[n++]=xrftiv; |
|---|
| 482 | for (moved=0, movp=xrf_buffer, n=XRBSIZ; n; n-=4) {memcpy(x,movp,4); mov4(moved,movp,x[0]);} |
|---|
| 483 | if (CIWRITE(xrf_fd,xrf_buffer,XRBSIZ) != XRBSIZ) fatal("putuxxrf/write"); |
|---|
| 484 | return; |
|---|
| 485 | } |
|---|
| 486 | if (mfn == 0) { |
|---|
| 487 | if (mfn + XRBSIZ % 4) fatal("putuxxrf/XRBSIZ"); |
|---|
| 488 | xrxp=(XRSTRU *)xrf_buffer; |
|---|
| 489 | xrf_block=0L; |
|---|
| 490 | xrf_lastblock=(xrf_lastmfn+XRMAXTV1)/XRMAXTIV; |
|---|
| 491 | if (xrf_lastmfn%XRMAXTIV == 0) xrf_lastblock++; /* 127 */ |
|---|
| 492 | xrf_lastidx=0; |
|---|
| 493 | |
|---|
| 494 | xrxp->xrxrpos = ++xrf_block; |
|---|
| 495 | if (xrf_block == xrf_lastblock) xrxp->xrxrpos = -xrf_block; |
|---|
| 496 | xrftiv = (0)*XRXDIVIDE + (0); /* EOF pointer */ |
|---|
| 497 | for (n=0; n < XRMAXTIV; ) xrxp->xrmfptr[n++]=xrftiv; |
|---|
| 498 | xrf_towrit=1; |
|---|
| 499 | return; |
|---|
| 500 | } |
|---|
| 501 | thispos=(mfn+XRMAXTV1)/XRMAXTIV; |
|---|
| 502 | thisidx=(mfn-1)%XRMAXTIV; |
|---|
| 503 | pointer = comb * XRXDIVIDE + comp; |
|---|
| 504 | if (thispos < xrf_block) fatal("putuxxrf/thispos"); |
|---|
| 505 | if (thispos == xrf_block) { |
|---|
| 506 | xrftiv=(-1)*XRXDIVIDE + (0); /* PDEL pointer */ |
|---|
| 507 | for (n=xrf_lastidx+1; n<thisidx; n++) xrxp->xrmfptr[n] = xrftiv; |
|---|
| 508 | xrxp->xrmfptr[xrf_lastidx=thisidx] = pointer; |
|---|
| 509 | xrf_towrit=1; |
|---|
| 510 | return; |
|---|
| 511 | } |
|---|
| 512 | |
|---|
| 513 | /* thispos > xrf_block */ |
|---|
| 514 | for (moved=0, movp=xrf_buffer, n=XRBSIZ; n; n-=4) {memcpy(x,movp,4); mov4(moved,movp,x[0]);} |
|---|
| 515 | if (CIWRITE(xrf_fd,xrf_buffer,XRBSIZ) != XRBSIZ) fatal("putuxxrf/write"); |
|---|
| 516 | xrftiv=(-1)*XRXDIVIDE + (0); /* PDEL pointer */ |
|---|
| 517 | for (n=0; n < XRMAXTIV; ) xrxp->xrmfptr[n++]=xrftiv; |
|---|
| 518 | while (++xrf_block < thispos) { |
|---|
| 519 | xrxp->xrxrpos = xrf_block; |
|---|
| 520 | if (xrf_block == xrf_lastblock) fatal("putuxxrf/lastblock"); |
|---|
| 521 | for (moved=0, movp=xrf_buffer, n=XRBSIZ; n; n-=4) {memcpy(x,movp,4); mov4(moved,movp,x[0]);} |
|---|
| 522 | if (CIWRITE(xrf_fd,xrf_buffer,XRBSIZ) != XRBSIZ) fatal("putuxxrf/write"); |
|---|
| 523 | } |
|---|
| 524 | xrxp->xrxrpos = xrf_block; |
|---|
| 525 | if (xrf_block == xrf_lastblock) xrxp->xrxrpos = -xrf_block; |
|---|
| 526 | xrxp->xrmfptr[xrf_lastidx=thisidx] = pointer; |
|---|
| 527 | xrftiv= (0)*XRXDIVIDE + (0); /* EOF pointer */ |
|---|
| 528 | for (n=thisidx+1; n<XRMAXTIV; n++) xrxp->xrmfptr[n] = xrftiv; |
|---|
| 529 | xrf_towrit=1; |
|---|
| 530 | return; |
|---|
| 531 | } |
|---|