From: terry@spcvxb.spc.edu (Terry Kennedy, Operations Mgr.)
Newsgroups: comp.os.vms
Subject: Re: Bookreader
Date: 26 Sep 92 05:04:18 GMT
Organization: St. Peter's College, US

In article <1992Sep25.132217.5421@gserv1.dl.ac.uk>, ufe@dlva.dl.ac.uk writes:
> Given that, how do I determine which bookreader files I need for
> a given product ?

  The following half-baked program (written while I was sleeping one night)
takes an edited copy of DMASTER.DECW$BOOKSHELF and recursively copies all
of the selected product manuals and bookshelves to an output disk/directory.

  You'll need to customize the device and directory names used, but it should
give you an idea. You could also modify it to return the disk files for books,
given the product name(s).

	Terry Kennedy		Operations Manager, Academic Computing
	terry@spcvxa.bitnet	St. Peter's College, Jersey City, NJ USA
	terry@spcvxa.spc.edu	+1 201 915 9381

/*
 * BOOK_CUSTOMIZE.C - Build a custom library volume from the OLD CD's
 *
 * V1.0-00 - 17-May-1992 - tmk - Original version
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

FILE *master_shelf;
FILE *output_dcl;

char line[512], work[512], output[512];
char *type, *name, *text;
int level = 0;

main()
{
    if ((master_shelf = fopen("spc.decw$bookshelf", "r")) == NULL) {
	perror("Couldn't open input bookshelf");
	exit(1);
    }

    if ((output_dcl = fopen("book_customize.com", "w")) == NULL) {
	perror("Couldn't open output command file");
	exit(1);
    }

    fprintf(output_dcl, "$   set noon\n");
    fprintf(output_dcl, "$  ! Generated command file\n");
    fprintf(output_dcl, "$  ! To eliminate redundant copy operations, you may\n");
    fprintf(output_dcl, "$  ! use the SORT/NODUPLICATES command on this file.\n");

    while (fgets(line, sizeof(line), master_shelf) != NULL) {
	line[strlen(line) - 1] = '\0';
	type = strtok(line, "\\");
	name = strtok(NULL, "\\");
	text = strtok(NULL, "\\");

	if (strcmp("SHELF",type) != 0) {
	    printf("Can't deal with loose books at top level\n");
	    exit(1);
	}

	process_shelf(name, text);
    }

    fprintf(output_dcl, "$ ! All done\n");

    if (level != 0) {
	printf("Synchronization error\n");
    }

    fclose(master_shelf);
    fclose(output_dcl);
    exit(1);
}

process_shelf(name, text)
char *name, *text;
{
    FILE *shelf;
    char shelf_name[80];
    char *ltype, *lname, *ltext;

    level++;

    printf("Processing shelf (%d): %s\n", level, text);

    fprintf(output_dcl, "$ ! Shelf: %s\n", text);

    strcpy(output, "$ copy spcvxx$dkb400:[decw$book]");
    strcat(output, name);
    strcat(output, ".decw$bookshelf spcvxz$dua0:[cust$book]");
    fprintf(output_dcl, "%s\n", output);

#ifdef	test
    strcpy(shelf_name, "[]");
#else
    strcpy(shelf_name, "spcvxx$dkb400:[decw$book]");
#endif	/* test */
    strcat(shelf_name, name);
    strcat(shelf_name, ".decw$bookshelf");

    if ((shelf = fopen(shelf_name, "r")) == NULL) {
	perror("Couldn't open included bookshelf");
	exit(1);
    }

    while (fgets(work, sizeof(work), shelf) != NULL) {
	work[strlen(work) - 1] = '\0';
	ltype = strtok(work, "\\");
	lname = strtok(NULL, "\\");
	ltext = strtok(NULL, "\\");

	if (strcmp("SHELF",ltype) == 0) {
	    process_shelf(lname, ltext);
	} else {
	    printf("            book (%d): %s\n", level, ltext);
	    strcpy(output, "$ copy spcvxx$dkb400:[decw$book]");
	    strcat(output, lname);
	    strcat(output, ".decw$book spcvxz$dua0:[cust$book]");
	    fprintf(output_dcl, "%s\n", output);
	}
    }
    fclose(shelf);
    level--;
}
Newsgroups: comp.os.vms