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 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595
|
/*
* ckvcvt - assorted outboard processing for C-Kermit/VMS labeled files
*/
/* Revision History:
* T1.0-00 - 08-Apr-91 - tmk - Initial coding, sync w/ 5A(167) and ckvfio.c
* 2.0-066.
* T1.0-01 - 14-Apr-91 - tmk - Fix errors in help output, show actual system
* message on RMS error.
* T1.0-02 - 15-Apr-91 - tmk - Redefine fab$b_journal as fab$b_rfm+1.
* T1.0-03 - 15-Apr-91 - tmk - ACL support, sync w/ 5A(169) and ckvfio.c 2.0-
* 069.
* T1.0-04 - 16-Apr-91 - tmk - Fix _another_ journaling bug (whimper), handle
* missing semicolon in filespec gracefully.
* T1.0-05 - 04-Sep-92 - tmk - Implement ckvfio.c 087 fix.
* T1.0-06 - 08-Apr-93 - tmk - Implement ckvfio.c 097 fix.
* T1.0-07 - 24-Feb-95 - mpjz- Fix for DEC C on VAX.
* T1.0-08 - 06-Sep-95 - fdc - Get rid of nonportable memmove().
*/
#ifdef WINTCP
#include stdio
#include stdlib
#include ctype
#include string
#include rms
#include ssdef
#else
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <rms.h>
#include <ssdef.h>
#endif /* WINTCP */
#define VERSION "T1.0-06"
#ifndef OLD_VMS
#include <starlet.h>
#endif /* OLD_VMS */
#define R_MODE "rb"
#define IO_ERROR 0
#define IO_SUCCESS 1
/*
* Definitions for output file
*/
static struct FAB fab_ofile;
static struct RAB rab_ofile;
static struct XABDAT xabdat_ofile;
static struct XABFHC xabfhc_ofile;
static struct XABPRO xabpro_ofile;
static struct XABALL xaball_ofile;
static struct XABRDT xabrdt_ofile;
static short ofile_ffb;
static int ofile_rec;
/*
* Common RMS items
*/
static unsigned long int rms_sts;
/*
* Global varables
*/
int keepacl = 0; /* Preserve ACL data? */
int backup = 0; /* Preserve file backup date? */
int debug = 0; /* Debug output? */
int notrim = 0; /* Don't trim names? */
int inquire = 0; /* Testing if labeled? */
int owner = 0; /* Preserve file ownership? */
int strip = 0; /* Just stripping? */
FILE *infd = NULL; /* Input file descriptor */
char *infn = NULL; /* Input file name */
char *outfn = NULL; /* Special output file name */
char buffer[512]; /* Work buffer */
char label[99]; /* Label name */
int lblen = 0; /* Length of label */
char vmsname[255]; /* Stored name */
char vmsfile[70]; /* Stored file info */
char vmsacl[512]; /* Stored ACL data */
int acllen = 0; /* Size of same */
char *filptr = vmsfile; /* Attribute pointer */
int gotname = 0; /* Found name? */
int gotfile = 0; /* Found file info? */
int gotacl = 0; /* Found ACL info? */
int bail = 0; /* If we should bail out */
char revdat[8]; /* Revision date */
unsigned short revnum; /* Revision number */
unsigned short jnlflg; /* Journaling flags */
/*
* Function prototypes
*/
extern int main(int, char **);
void do_help();
void barf(char *);
void strip_file();
#if !defined(__DECC) && !defined(VAX)
#define XABP char
#else
#define XABP void
#endif
/* memmove() replacement */
void
mymove(to, from, len) char * to; char * from; int len; {
char tmp[16384];
strncpy((char *)tmp,from,len);
strncpy(to,(char *)tmp,len);
}
/*
* Ok, let's do it
*/
int main(argc, argv)
int argc;
char *argv[];
{
register char *ap;
int i, j; /* How original */
if (argc < 2) /* User say anything? */
do_help(); /* If not... */
if (*argv[1] != '-') {
infn = argv[1];
if ((infd = fopen(argv[1], R_MODE)) == NULL) {
perror(argv[1]);
exit(IO_ERROR);
}
argc--;
argv++;
}
else
bail++;
while (argc > 1) {
ap = argv[1];
if (*ap != '-') {
fprintf(stderr, "Unknown option '%s',", ap);
fprintf(stderr, " do CKVCVT -? for help.\n");
}
else for (ap++; *ap; ap++) {
switch (tolower(*ap)) {
case 'a': /* Preserve ACL's */
keepacl++;
break;
case 'b': /* Preserve backup date */
backup++;
break;
case 'd': /* Debug mode? */
debug++;
break;
case 'f': /* Name output file */
if (isgraph(ap[1]) != 0)
outfn = &ap[1];
else if (argc > 2) {
outfn = argv[2];
argc--;
argv++;
}
else {
break;
}
goto next_arg;
case 'i': /* Inquire if labeled */
inquire++;
strip++;
break;
case 'o': /* Preserve file ownership */
owner++;
break;
case 's': /* Just strip it */
strip++;
break;
case 't': /* Don't trim filenames */
notrim++;
break;
case '?': /* Emit help text */
case 'h':
do_help();
break;
default:
fprintf(stderr, "?Unknown option '%c',", *ap);
fprintf(stderr, " do CKVCVT -? for help\n");
}
}
next_arg:
argc--;
argv++;
}
if (bail != 0)
exit(IO_ERROR);
fread(buffer, 20, 1, infd);
if (strncmp(buffer, "KERMIT LABELED FILE:", 20) != 0)
barf("not a Kermit labeled file");
fread(buffer, 2, 1, infd);
buffer[2] = '\0';
lblen = atoi(buffer);
if (lblen != 2)
barf("");
fread(buffer, lblen, 1, infd);
if (strip != 0) /* Stripping headers? */
strip_file();
if (strncmp(buffer, "D7", 2) != 0)
barf("not from a VAX/VMS system");
fread(buffer, 6, 1, infd);
if (strncmp(buffer, "04VERS", 6) != 0)
barf("");
fread(buffer, 8, 1, infd);
buffer[8] = '\0';
lblen = atoi(buffer);
fread(buffer, lblen, 1, infd);
buffer[lblen] = '\0';
if (debug)
fprintf(stderr, "File created under VAX/VMS %s\n", buffer);
fread(buffer, 7, 1, infd);
if (strncmp(buffer, "05KVERS", 7) != 0)
barf("");
fread(buffer, 8, 1, infd);
buffer[8] = '\0';
lblen = atoi(buffer);
fread(buffer, lblen, 1, infd);
buffer[lblen] = '\0';
if (debug)
fprintf(stderr, "File created with C-Kermit/VMS %s\n", buffer);
next_label:
fread(buffer, 2, 1, infd);
buffer[2] = '\0';
lblen = atoi(buffer);
if (lblen == 0)
barf("lost sync");
fread(buffer, lblen, 1, infd);
buffer[lblen] = '\0';
if (strcmp(buffer, "VMSNAME") == 0) {
fread(buffer, 8, 1, infd);
buffer[8] = '\0';
lblen = atoi(buffer);
fread(vmsname, lblen, 1, infd);
vmsname[lblen] = '\0';
gotname++;
if (debug)
fprintf(stderr, "Loaded file name block as %s\n", vmsname);
i = (int)strstr(vmsname, "::");
if (i != (int)NULL) {
char temp[255];
i += 2;
mymove(vmsname, (char *)i, (int)strlen(vmsname));
}
if (!notrim) {
char temp[255];
i = (int)strrchr(vmsname, ':');
j = (int)strrchr(vmsname, ']');
if (j == (int)NULL)
j = (int)strrchr(vmsname, '>');
if (j > i)
i = j;
i++;
mymove(vmsname, (char *)i, (int) strlen(vmsname));
}
if (strchr(vmsname, ';') != NULL) {
for (j = strlen(vmsname); vmsname[j] != ';'; j--)
;
vmsname[j] = '\0';
}
if (debug)
fprintf(stderr, "Resultant filespec: %s\n", vmsname);
goto next_label;
}
else if (strcmp(buffer, "VMSFILE") == 0) {
fread(buffer, 8, 1, infd);
buffer[8] = '\0';
lblen = atoi(buffer);
fread(vmsfile, lblen, 1, infd);
vmsfile[lblen] = '\0';
gotfile++;
if (debug)
fprintf(stderr, "Loaded file attribute block\n");
goto next_label;
}
else if (strcmp(buffer, "VMSACL") == 0) {
fread(buffer, 8, 1, infd);
buffer[8] = '\0';
acllen = atoi(buffer);
fread(vmsacl, acllen, 1, infd);
vmsacl[acllen] = '\0';
gotacl++;
if (debug)
fprintf(stderr, "Loaded file ACL block\n");
goto next_label;
}
else if (strcmp(buffer, "DATA") == 0) {
fread(buffer, 8, 1, infd);
buffer[8] = '\0';
lblen = atoi(buffer);
if (lblen != 0)
barf("");
if (debug)
fprintf(stderr, "Positioned at start of file data\n");
goto all_set;
}
else {
fprintf(stderr, "%s: unrecognized label '%s'\n", infn, buffer);
fread(buffer, 8, 1, infd);
buffer[8] = '\0';
lblen = atoi(buffer);
if (lblen > 512)
barf("unrecognized label too long to skip");
fread(vmsfile, lblen, 1, infd);
goto next_label;
}
all_set:
if (gotfile != 1 || gotname != 1)
barf("missing required labels");
/*
* Prep the characteristics
*/
fab_ofile = cc$rms_fab;
fab_ofile.fab$b_fac = FAB$M_BIO | FAB$M_PUT;
fab_ofile.fab$l_fop = FAB$M_MXV;
if (outfn == NULL) {
fab_ofile.fab$l_fna = vmsname;
fab_ofile.fab$b_fns = strlen(vmsname);
}
else {
fab_ofile.fab$l_fna = outfn;
fab_ofile.fab$b_fns = strlen(outfn);
}
fab_ofile.fab$l_xab = (XABP *)&xabdat_ofile;
rab_ofile = cc$rms_rab;
rab_ofile.rab$l_fab = &fab_ofile;
xabdat_ofile = cc$rms_xabdat;
xabdat_ofile.xab$l_nxt = (XABP *)&xabrdt_ofile;
xabrdt_ofile = cc$rms_xabrdt;
xabrdt_ofile.xab$l_nxt = (XABP *)&xabfhc_ofile;
xabfhc_ofile = cc$rms_xabfhc;
xabfhc_ofile.xab$l_nxt = (XABP *)&xabpro_ofile;
xabpro_ofile = cc$rms_xabpro;
xabpro_ofile.xab$l_nxt = (XABP *)&xaball_ofile;
xaball_ofile = cc$rms_xaball;
/*
* Load 'em up
*/
mymove(&xabpro_ofile.xab$w_pro, filptr, 2);
filptr += 2;
if (owner != 0)
mymove(&xabpro_ofile.xab$l_uic, filptr, 4);
filptr += 4;
mymove(&fab_ofile.fab$b_rfm, filptr, 1);
filptr += 1;
mymove(&fab_ofile.fab$b_org, filptr, 1);
filptr += 1;
mymove(&fab_ofile.fab$b_rat, filptr, 1);
filptr += 5; /* 4 bytes reserved for char */
mymove(&fab_ofile.fab$b_fsz, filptr, 1);
filptr += 1;
mymove(&xabfhc_ofile.xab$w_lrl, filptr, 2);
filptr += 2;
mymove(&fab_ofile.fab$w_mrs, filptr, 2);
filptr += 2;
mymove(&xabfhc_ofile.xab$l_ebk, filptr, 4);
filptr += 4;
/* preserve this as RMS won't remember it for us */
mymove(&ofile_ffb, filptr, 2);
filptr += 2;
mymove(&xaball_ofile.xab$l_alq, filptr, 4);
filptr += 4;
mymove(&xaball_ofile.xab$w_deq, filptr, 2);
filptr += 2;
#ifdef COMMENT /* was: defined(VAX) && defined(__DECC) */
/*
This is really annoying. The people from DEC changed xaball, but only on
VAX not AXP! - mpjz
*/
mymove(&xaball_ofile.xaballdef$$_fill_7, filptr, 1);
#else
mymove(&xaball_ofile.xab$b_bkz, filptr, 1);
#endif /* COMMENT */
filptr += 1;
mymove(&fab_ofile.fab$w_gbc, filptr, 2);
filptr += 2;
mymove(&xabfhc_ofile.xab$w_verlimit, filptr, 2);
filptr += 2;
mymove(&jnlflg, filptr, 1);
if (jnlflg !=0)
printf("Original file was marked for RMS Journaling, this copy is not.\n");
filptr += 1;
mymove(&xabdat_ofile.xab$q_cdt, filptr, 8);
filptr += 8;
mymove(&revdat, filptr, 8);
filptr += 8;
mymove(&revnum, filptr, 2);
filptr += 2;
mymove(&xabdat_ofile.xab$q_edt, filptr, 8);
filptr += 8;
if (backup != 0)
mymove(&xabdat_ofile.xab$q_bdt, filptr, 8);
filptr += 8;
/*
* ACL's?
*/
if(keepacl != 0 && gotacl != 0) {
xabpro_ofile.xab$l_aclbuf = (XABP *)&vmsacl;
xabpro_ofile.xab$w_aclsiz = acllen;
}
/*
* Give it a quick whirl around the dance floor
*/
printf("Creating %s...\n", fab_ofile.fab$l_fna);
rms_sts = sys$create(&fab_ofile);
if (!(rms_sts & 1))
exit(rms_sts);
if(keepacl != 0 && gotacl != 0) {
if (!(xabpro_ofile.xab$l_aclsts & 1))
exit(xabpro_ofile.xab$l_aclsts);
}
rms_sts = sys$connect(&rab_ofile);
if (!(rms_sts & 1))
exit(rms_sts);
ofile_rec = 1;
fread(buffer, 512, 1, infd);
while (!feof(infd)) {
rab_ofile.rab$l_rbf = buffer;
rab_ofile.rab$w_rsz = 512;
if (ofile_rec == xabfhc_ofile.xab$l_ebk) {
xabfhc_ofile.xab$w_ffb = ofile_ffb;
if (ofile_ffb)
rab_ofile.rab$w_rsz -= (512 - ofile_ffb);
if (debug) {
fprintf(stderr, "FFB (first free byte) = %d\n", ofile_ffb);
fprintf(stderr, "Last record size = %d\n", rab_ofile.rab$w_rsz);
}
}
rms_sts = sys$write(&rab_ofile);
if (!(rms_sts & 1))
exit(rms_sts);
fread(buffer, 512, 1, infd);
ofile_rec++;
}
/*
* Update the revision information
*/
mymove(&xabrdt_ofile.xab$q_rdt, revdat, 8);
mymove(&xabrdt_ofile.xab$w_rvn, &revnum, 2);
rms_sts = sys$close(&fab_ofile);
if (!(rms_sts & 1))
exit(rms_sts);
printf("...done.\n");
exit(IO_SUCCESS);
}
void do_help()
{
printf("This is CKVCVT %s\n\n", VERSION);
printf("Usage: CKVCVT infile options\n\n");
printf("Options:\n");
printf(" -a Preserve file ACL data (may require privs)\n");
printf(" -b Preserve file backup date\n");
printf(" -d Print debugging information\n");
printf(" -f fn Name output file fn instead of default\n");
printf(" -i Inquire if a file is labeled\n");
printf(" -o Preserve file ownership (requires privs)\n");
printf(" -s Strip one level of label information\n");
printf(" -t Don't trim paths from output file name\n");
printf(" -? Display this message\n\n");
exit(IO_SUCCESS);
}
void barf(text)
char *text;
{
if (text == "")
fprintf(stderr, "%s: corrupted Kermit labeled file\n", infn);
else
fprintf(stderr, "%s: %s\n", infn, text);
exit(IO_ERROR);
}
void strip_file()
{
next_label:
fread(buffer, 2, 1, infd); /* Get label length */
buffer[2] = '\0';
lblen = atoi(buffer);
if (lblen == 0) /* Better not be zero! */
barf("lost sync");
fread(label, lblen, 1, infd); /* Get the label name */
label[lblen] = '\0';
fread(buffer, 8, 1, infd); /* Get the contents length */
buffer[8] = '\0';
lblen = atoi(buffer);
if (strcmp(label, "DATA") == 0) { /* If done... */
if (lblen != 0)
barf("");
if (debug)
fprintf(stderr, "Positioned at start of file data\n");
goto all_set;
}
fread(buffer, lblen, 1, infd); /* Else skip contents */
goto next_label; /* And loop */
/*
* We've skipped the first header, now do whatever task is needed
*/
all_set:
if (inquire != 0) {
printf("%s is a properly formatted Kermit labeled file\n", infn);
exit(IO_SUCCESS);
}
fab_ofile = cc$rms_fab;
fab_ofile.fab$b_fac = FAB$M_BIO | FAB$M_PUT;
fab_ofile.fab$l_fop = FAB$M_MXV;
fab_ofile.fab$l_fna = infn;
fab_ofile.fab$b_fns = strlen(infn);
fab_ofile.fab$b_rfm = FAB$C_FIX;
fab_ofile.fab$w_mrs = 512;
rab_ofile = cc$rms_rab;
rab_ofile.rab$l_fab = &fab_ofile;
printf("Stripping %s...\n", fab_ofile.fab$l_fna);
rms_sts = sys$create(&fab_ofile);
if (!(rms_sts & 1))
exit(rms_sts);
rms_sts = sys$connect(&rab_ofile);
if (!(rms_sts & 1))
exit(rms_sts);
fread(buffer, 512, 1, infd);
while (!feof(infd)) {
rab_ofile.rab$l_rbf = buffer;
rab_ofile.rab$w_rsz = 512;
rms_sts = sys$write(&rab_ofile);
if (!(rms_sts & 1))
exit(rms_sts);
fread(buffer, 512, 1, infd);
}
rms_sts = sys$close(&fab_ofile);
if (!(rms_sts & 1))
exit(rms_sts);
printf("...done.\n");
exit(IO_SUCCESS);
}
|