📄 vms.c
字号:
} if (outfab != 0) { outfab->fab$l_xab = first_xab; return 1; } else return 0;}/****************************** * Function extract_block * ******************************//* * Simple uncompression routne. The compression uses bit stream. * Compression scheme: * * if(byte!=0) * putbit(1),putyte(byte) * else * putbit(0) */static byte *extract_block(p, retlen, init, needlen) int *retlen;struct extra_block *p;byte *init;int needlen;{ byte *block; /* Pointer to block allocated */ byte *bitptr; /* Pointer into compressed data */ byte *outptr; /* Pointer into output block */ UWORD length; ULONG bitbuf = 0; int bitcnt = 0;#define _FILL if(bitcnt+8 <= 32) \ { bitbuf |= (*bitptr++) << bitcnt;\ bitcnt += 8; \ } if( p->flags & 1 ) length = p->length; /* Block is compressed */ else length = p->size - EXTBSL - RESL; /* Simple case, uncompressed */ if( needlen == 0 ) needlen = length; if(retlen) *retlen = needlen; if( (p->flags & 1) || (needlen > length) ) { if ((block = (byte*)malloc(needlen)) == NULL) return NULL; }/* else if( needlen > length ) { if ((block = (byte*)malloc(needlen)) == NULL) return NULL; }*/ else outptr = block = &p->body[0]; if(init && (length < needlen)) memcpy(block,init,needlen); if ((p->flags & 1) == 0) return block; /* Do nothing more if uncompressed */ outptr = block; bitptr = &p->body[0]; if(length > needlen) length = needlen; while (length--) { if (bitcnt <= 0) _FILL; if (bitbuf & 1) { bitbuf >>= 1; if ((bitcnt -= 1) < 8) _FILL; *outptr++ = (byte) bitbuf; bitcnt -= 8; bitbuf >>= 8; } else { *outptr++ = 0; bitcnt -= 1; bitbuf >>= 1; } } return block;}/***************************//* Function FlushOutput() *//***************************/int FlushOutput(){ /* return PK-type error code */ /* flush contents of output buffer */ if (tflag) { /* Do not output. Update CRC only */ UpdateCRC(outbuf, outcnt); outpos += outcnt; outcnt = 0; outptr = outbuf; return 0; } else return text_file ? _flush_records(0) : _flush_blocks(0);}static int _flush_blocks(final_flag) /* Asynchronous version */ int final_flag;/* 1 if this is the final flushout */{ int round; int rest; int off = 0; int out_count = outcnt; int status; while(out_count > 0) { if( curbuf -> bufcnt < BUFS512 ) { int ncpy; ncpy = out_count > (BUFS512-curbuf->bufcnt) ? BUFS512-curbuf->bufcnt : out_count; memcpy(curbuf->buf + curbuf->bufcnt, outbuf+off, ncpy); out_count -= ncpy; curbuf -> bufcnt += ncpy; off += ncpy; } if( curbuf -> bufcnt == BUFS512 ) { status = WriteBuffer(curbuf->buf,curbuf->bufcnt); if(status) return status; curbuf = curbuf -> next; curbuf -> bufcnt = 0; } } UpdateCRC(outbuf, outcnt); outpos += outcnt; outcnt = 0; outptr = outbuf; return (final_flag && (curbuf->bufcnt > 0)) ? WriteBuffer(curbuf->buf,curbuf->bufcnt) : 0; /* 0: no error */}#define RECORD_END(c) ((c) == CR || (c) == LF)static int _flush_records(final_flag) int final_flag;/* 1 if this is the final flushout */{ int rest; int end = 0, start = 0; int off = 0; if (outcnt == 0 && loccnt == 0) return 0; /* Nothing to do ... */ if (loccnt) { for (end = 0; end < outcnt && !RECORD_END(outbuf[end]);) ++end; if (end >= outcnt) { fprintf(stderr, "[ Warning: Record too long (%d) ]\n", outcnt + loccnt); if (WriteRecord(locbuf, loccnt)) return (50); memcpy(locbuf, outbuf, outcnt); locptr = &locbuf[loccnt = outcnt]; } else { memcpy(locptr, outbuf, end); if (WriteRecord(locbuf, loccnt + end)) return (50); loccnt = 0; locptr = &locbuf; } start = end + 1; } do { while (start < outcnt && outbuf[start] == CR) /* Skip CR's at the * beginning of rec. */ ++start; /* Find record end */ for (end = start; end < outcnt && !RECORD_END(outbuf[end]);) ++end; if (end < outcnt) { /* Record end found, write the record */ if (WriteRecord(outbuf + start, end - start)) return (50); /* Shift to the begining of the next record */ start = end + 1; } } while (start < outcnt && end < outcnt); rest = outcnt - start; if (rest > 0) if (final_flag) { /* This is a final flush. Put out all remaining in * the buffer */ if (loccnt && WriteRecord(locbuf, loccnt)) return (50); } else { memcpy(locptr, outbuf + start, rest); locptr += rest; loccnt += rest; } UpdateCRC(outbuf, outcnt); outpos += outcnt; outcnt = 0; outptr = outbuf; return (0); /* 0: no error */}/***************************//* Function WriteBuffer() *//***************************/static int WriteBuffer(buf, len)/* return 0 if successful, 1 if not */ unsigned char *buf;int len;{ int status; status = sys$wait(outrab);#ifdef DEBUG if(ERR(status)) { message("[ Write buffer: sys$wait faled ]\n",status); message("",outrab->rab$l_sts); message("",outrab->rab$l_sts); }#endif outrab->rab$w_rsz = len; outrab->rab$l_rbf = buf; if (ERR(status = sys$write(outrab))) { fprintf(stderr, "WriteBuffer: sys$write failed.\n", filename); fprintf(stderr, " status = %d\n", status); fprintf(stderr, " rab->sts = %d\n", outrab->rab$l_sts); fprintf(stderr, " stv = %d\n", outrab->rab$l_stv); return 50; } return (0);}/***************************//* Function WriteRecord() *//***************************/static int WriteRecord(rec, len)/* return 0 if successful, 1 if not */ unsigned char *rec;int len;{ int status; sys$wait(outrab);#ifdef DEBUG if(ERR(status)) { message("[ Write buffer: sys$wait faled ]\n",status); message("",outrab->rab$l_sts); message("",outrab->rab$l_sts); }#endif outrab->rab$w_rsz = len; outrab->rab$l_rbf = rec; if (ERR(status = sys$put(outrab))) { fprintf(stderr, "WriteRecord: sys$put failed.\n", filename); fprintf(stderr, " status = %d\n", status); fprintf(stderr, " rab->sts = %d\n", outrab->rab$l_sts); fprintf(stderr, " stv = %d\n", outrab->rab$l_stv); return 50; } return (0);}/********************************//* Function CloseOutputFile() *//********************************/int CloseOutputFile(){ int status; if (text_file) _flush_records(1); else _flush_blocks(1); if ((outfab->fab$l_xab = xabrdt) != 0L) /* Link XABPRO and XABRDT */ xabrdt->xab$l_nxt = (secinf ? xabpro : 0L); else outfab->fab$l_xab = (secinf ? xabpro : 0L); sys$wait(outrab); status = sys$close(outfab);#ifdef DEBUG if (ERR(status)) { message("\r[ Warning: can not set owner/protection/time attributes ]\n", status); message("", outfab->fab$l_stv); }#endif}#ifdef DEBUGdump_rms_block(p) unsigned char *p;{ unsigned char bid, len; int err; char *type; char buf[132]; int i; err = 0; bid = p[0]; len = p[1]; switch (bid) { case FAB$C_BID: type = "FAB"; break; case XAB$C_ALL: type = "xabALL"; break; case XAB$C_KEY: type = "xabKEY"; break; case XAB$C_DAT: type = "xabDAT"; break; case XAB$C_RDT: type = "xabRDT"; break; case XAB$C_FHC: type = "xabFHC"; break; case XAB$C_PRO: type = "xabPRO"; break; default: type = "Unknown"; err = 1; break; } printf("Block @%08X of type %s (%d).", p, type, bid); if (err) { printf("\n"); return; } printf(" Size = %d\n", len); printf(" Offset - Hex - Dec\n"); for (i = 0; i < len; i += 8) { int j; printf("%3d - ", i); for (j = 0; j < 8; j++) if (i + j < len) printf("%02X ", p[i + j]); else printf(" "); printf(" - "); for (j = 0; j < 8; j++) if (i + j < len) printf("%03d ", p[i + j]); else printf(" "); printf("\n"); }}#endif /* DEBUG */message(string, status) int status;char *string;{ char msgbuf[256]; $DESCRIPTOR(msgd, msgbuf); int msglen = 0; if (ERR(lib$sys_getmsg(&status, &msglen, &msgd, 0, 0))) fprintf(stderr, "%s[ VMS status = %d ]\n", string, status); else { msgbuf[msglen] = 0; fprintf(stderr, "%s[ %s ]\n", string, msgbuf); }}#endif /* !VMS */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -