📄 vms.c
字号:
{ got_eol = rawbuf[eol_off]; end = size; complete = 0; } else { memcpy(locptr, rawbuf, eol_off); recsize = loccnt + eol_off; locptr += eol_off; loccnt += eol_off; end = eol_off + eol_len; complete = 1; } } } if ( complete ) { if (WriteRecord(__G__ locbuf, recsize)) return PK_DISK; loccnt = 0; locptr = locbuf; } } /* end if ( loccnt ) */ for (start = end; start < size && end < size; ) { unsigned eol_off, eol_len; got_eol = 0;#ifdef undef if (uO.cflag) /* skip CR's at the beginning of record */ while (start < size && rawbuf[start] == CR) ++start;#endif if ( start >= size ) continue; /* Find record end */ end = start+(eol_off = find_eol(rawbuf+start, size-start, &eol_len)); if ( end >= size ) continue; if ( eol_len > 0 ) { if ( WriteRecord(__G__ rawbuf+start, end-start) ) return PK_DISK; start = end + eol_len; } else { got_eol = rawbuf[end]; end = size; continue; } } rest = size - start; if (rest > 0) { if ( rest > BUFSMAXREC ) { unsigned recsize; char buf[80]; /* CANNOT use slide for Info() */ recsize = rest - (got_eol ? 1 : 0 ); Info(buf, 1, (buf, "[ Warning: Record too long (%u) ]\n", recsize)); got_eol = 0; return WriteRecord(__G__ rawbuf+start, recsize); } else { memcpy(locptr, rawbuf + start, rest); locptr += rest; loccnt += rest; } } return PK_COOL;}static int WriteBuffer(__G__ buf, len) __GDEF uch *buf; unsigned len;{ int status; if (uO.cflag) { (void)(*G.message)((zvoid *)&G, buf, len, 0); } else { status = sys$wait(outrab); if (ERR(status)) { vms_msg(__G__ "[ WriteBuffer: sys$wait failed ]\n", status); vms_msg(__G__ "", outrab->rab$l_stv); } /* If odd byte count, then this must be the final record. Clear the extra byte past EOF to help keep the file clean. */ if (len & 1) buf[len] = '\0'; outrab->rab$w_rsz = len; outrab->rab$l_rbf = (char *) buf; if (ERR(status = sys$write(outrab))) { vms_msg(__G__ "[ WriteBuffer: sys$write failed ]\n", status); vms_msg(__G__ "", outrab->rab$l_stv); return PK_DISK; } } return PK_COOL;}static int WriteRecord(__G__ rec, len) __GDEF uch *rec; unsigned len;{ int status; if (uO.cflag) { (void)(*G.message)((zvoid *)&G, rec, len, 0); (void)(*G.message)((zvoid *)&G, (uch *) ("\n"), 1, 0); } else { if (ERR(status = sys$wait(outrab))) { vms_msg(__G__ "[ WriteRecord: sys$wait failed ]\n", status); vms_msg(__G__ "", outrab->rab$l_stv); } outrab->rab$w_rsz = len; outrab->rab$l_rbf = (char *) rec; if (ERR(status = sys$put(outrab))) { vms_msg(__G__ "[ WriteRecord: sys$put failed ]\n", status); vms_msg(__G__ "", outrab->rab$l_stv); return PK_DISK; } } return PK_COOL;}void close_outfile(__G) __GDEF{ int status; status = (*_flush_routine)(__G__ NULL, 0, 1); if (status) return /* PK_DISK */; if (uO.cflag) return /* PK_COOL */; /* Don't close stdout */ /* return */ (*_close_routine)(__G);}static int _close_rms(__GPRO){ int status; struct XABPRO pro; /* Link XABRDT, XABDAT and optionally XABPRO */ if (xabrdt != NULL) { xabrdt->xab$l_nxt = NULL; outfab->fab$l_xab = (void *) xabrdt; } else { rdt.xab$l_nxt = NULL; outfab->fab$l_xab = (void *) &rdt; } if (xabdat != NULL) { xabdat->xab$l_nxt = outfab->fab$l_xab; outfab->fab$l_xab = (void *)xabdat; } if (xabpro != NULL) { if ( !uO.X_flag ) xabpro->xab$l_uic = 0; /* Use default (user's) uic */ xabpro->xab$l_nxt = outfab->fab$l_xab; outfab->fab$l_xab = (void *) xabpro; } else { pro = cc$rms_xabpro; pro.xab$w_pro = G.pInfo->file_attr; pro.xab$l_nxt = outfab->fab$l_xab; outfab->fab$l_xab = (void *) &pro; } status = sys$wait(outrab); if (ERR(status)) { vms_msg(__G__ "[ _close_rms: sys$wait failed ]\n", status); vms_msg(__G__ "", outrab->rab$l_stv); } status = sys$close(outfab);#ifdef DEBUG if (ERR(status)) { vms_msg(__G__ "\r[ Warning: cannot set owner/protection/time attributes ]\n", status); vms_msg(__G__ "", outfab->fab$l_stv); }#endif free_up(); return PK_COOL;}static int _close_qio(__GPRO){ int status; pka_fib.FIB$L_ACCTL = FIB$M_WRITE | FIB$M_NOTRUNC ; pka_fib.FIB$W_EXCTL = 0; pka_fib.FIB$W_FID[0] = pka_fib.FIB$W_FID[1] = pka_fib.FIB$W_FID[2] = pka_fib.FIB$W_DID[0] = pka_fib.FIB$W_DID[1] = pka_fib.FIB$W_DID[2] = 0;#ifdef ASYNCH_QIO if (pka_io_pending) { status = sys$synch(0, &pka_io_sb); if (!ERR(status)) status = pka_io_sb.status; if (ERR(status)) { vms_msg(__G__ "[ _close_qio: sys$synch found I/O failure ]\n", status); } pka_io_pending = FALSE; }#endif /* ASYNCH_QIO */ status = sys$qiow(0, pka_devchn, IO$_DEACCESS, &pka_acp_sb, 0, 0, &pka_fibdsc, 0, 0, 0, &pka_atr, 0); sys$dassgn(pka_devchn); if ( !ERR(status) ) status = pka_acp_sb.status; if ( ERR(status) ) { vms_msg(__G__ "[ Deaccess QIO failed ]\n", status); return PK_DISK; } return PK_COOL;}#ifdef TIMESTAMP/* Nonzero if `y' is a leap year, else zero. */#define leap(y) (((y) % 4 == 0 && (y) % 100 != 0) || (y) % 400 == 0)/* Number of leap years from 1970 to `y' (not including `y' itself). */#define nleap(y) (((y) - 1969) / 4 - ((y) - 1901) / 100 + ((y) - 1601) / 400)/* Accumulated number of days from 01-Jan up to start of current month. */static ZCONST short ydays[] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365};/***********************//* Function mkgmtime() *//***********************/static time_t mkgmtime(tm) struct tm *tm;{ time_t m_time; int yr, mo, dy, hh, mm, ss; unsigned days; yr = tm->tm_year - 70; mo = tm->tm_mon; dy = tm->tm_mday - 1; hh = tm->tm_hour; mm = tm->tm_min; ss = tm->tm_sec; /* calculate days from BASE to this year and add expired days this year */ dy = (unsigned)dy + ((unsigned)yr * 365) + (unsigned)nleap(yr+1970) + (unsigned)ydays[mo] + ((mo > 1) && leap(yr+1970)); /* convert date & time to seconds relative to 00:00:00, 01/01/1970 */ return (time_t)((unsigned long)(unsigned)dy * 86400L + (unsigned long)hh * 3600L + (unsigned long)(mm * 60 + ss));} /* end function mkgmtime() *//*******************************//* Function dos_to_unix_time() */ /* only used for timestamping of archives *//*******************************/time_t dos_to_unix_time(dosdatetime) ulg dosdatetime;{ struct tm *ltm; /* Local time. */ time_t loctime; /* The time_t value of local time. */ time_t then; /* The time to return. */ long tzoffset_adj; /* timezone-adjustment `remainder' */ int bailout_cnt; /* counter of tries for tz correction */ then = time(NULL); ltm = localtime(&then); /* dissect date */ ltm->tm_year = ((int)(dosdatetime >> 25) & 0x7f) + 80; ltm->tm_mon = ((int)(dosdatetime >> 21) & 0x0f) - 1; ltm->tm_mday = ((int)(dosdatetime >> 16) & 0x1f); /* dissect time */ ltm->tm_hour = (int)(dosdatetime >> 11) & 0x1f; ltm->tm_min = (int)(dosdatetime >> 5) & 0x3f; ltm->tm_sec = (int)(dosdatetime << 1) & 0x3e; loctime = mkgmtime(ltm); /* Correct for the timezone and any daylight savings time. The correction is verified and repeated when not correct, to take into account the rare case that a change to or from daylight savings time occurs between when it is the time in `tm' locally and when it is that time in Greenwich. After the second correction, the "timezone & daylight" offset should be correct in all cases. To be sure, we allow a third try, but then the loop is stopped. */ bailout_cnt = 3; then = loctime; do { ltm = localtime(&then); tzoffset_adj = (ltm != NULL) ? (loctime - mkgmtime(ltm)) : 0L; if (tzoffset_adj == 0L) break; then += tzoffset_adj; } while (--bailout_cnt > 0); if ( (dosdatetime >= DOSTIME_2038_01_18) && (then < (time_t)0x70000000L) ) then = U_TIME_T_MAX; /* saturate in case of (unsigned) overflow */ if (then < (time_t)0L) /* a converted DOS time cannot be negative */ then = S_TIME_T_MAX; /* -> saturate at max signed time_t value */ return then;} /* end function dos_to_unix_time() *//*******************************//* Function uxtime2vmstime() *//*******************************/static void uxtime2vmstime( /* convert time_t value into 64 bit VMS bintime */ time_t utimeval, long int binval[2] ){ time_t m_time = utimeval; struct tm *t = localtime(&m_time); if (t == (struct tm *)NULL) { /* time conversion error; use current time instead, hoping that localtime() does not reject it as well! */ m_time = time(NULL); t = localtime(&m_time); } sprintf(timbuf, "%02d-%3s-%04d %02d:%02d:%02d.00", t->tm_mday, month[t->tm_mon], t->tm_year + 1900, t->tm_hour, t->tm_min, t->tm_sec); sys$bintim(&date_str, binval);} /* end function uxtime2vmstime() *//***************************//* Function stamp_file() */ /* adapted from VMSmunch...it just won't die! *//***************************/int stamp_file(fname, modtime) ZCONST char *fname; time_t modtime;{ int status; int i; static long int Cdate[2], Rdate[2], Edate[2], Bdate[2]; static short int revisions;#if defined(__DECC) || defined(__DECCXX)#pragma __member_alignment __save#pragma __nomember_alignment#endif /* __DECC || __DECCXX */ static union { unsigned short int value; struct { unsigned system : 4; unsigned owner : 4; unsigned group : 4; unsigned world : 4; } bits; } prot;#if defined(__DECC) || defined(__DECCXX)#pragma __member_alignment __restore#endif /* __DECC || __DECCXX */ static unsigned long uic; static struct fjndef jnl; static struct atrdef Atr[] = { {sizeof(pka_rattr), ATR$C_RECATTR, GVTC &pka_rattr}, {sizeof(pka_uchar), ATR$C_UCHAR, GVTC &pka_uchar}, {sizeof(Cdate), ATR$C_CREDATE, GVTC &Cdate[0]}, {sizeof(Rdate), ATR$C_REVDATE, GVTC &Rdate[0]}, {sizeof(Edate), ATR$C_EXPDATE, GVTC &Edate[0]}, {sizeof(Bdate), ATR$C_BAKDATE, GVTC &Bdate[0]}, {sizeof(revisions), ATR$C_ASCDATES, GVTC &revisions}, {sizeof(prot), ATR$C_FPRO, GVTC &prot}, {sizeof(uic), ATR$C_UIC, GVTC &uic},
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -