Exemple #1
0
/*
|| Standard main
*/
int
main( int argc, char *argv[] )
{
    HETB *hetb;
    FETB *fetb;
    char *i_filename;
    int   i_faketape = FALSE;
    SInt32  rc;
    SInt32  fileno;
    SInt32  i;
    U32  uminsz;
    U32  umaxsz;
    U32  ubytes;
    U32  cminsz;
    U32  cmaxsz;
    U32  cbytes;
    U32  totblocks;
    U64  totubytes;
    U64  totcbytes;
    U32  opts = 0;
    SInt32  lResidue    = max_bytes_dsply;  /* amount of space left to print */
    char *pgm;

    INITIALIZE_UTILITY( UTILITY_NAME, "Hercules AWS, HET and FakeTape tape map program", &pgm );

#define O_ALL               0xC0
#define O_FILES             0X80
#define O_LABELS            0X40
#define O_DATASETS          0X20
#define O_TAPEMAP_OUTPUT    0x10
#define O_TAPEMAP_INVOKED   0x08
#define O_SLANAL_OUT        0x04

    if (! (opts & O_TAPEMAP_INVOKED) )
    {

        opts = O_ALL;

        while( TRUE )
        {
            rc = getopt( argc, argv, "ab:dfhlst" );
            if( rc == -1 )
                break;

            switch( rc )
            {
                case 'a':
                    opts = O_ALL;
                    break;
                case 'b':
                    max_bytes_dsply = atoi( optarg );
                    if ( max_bytes_dsply < 256 ) max_bytes_dsply = 256;
                    else
                    {
                        int i;
                        i = max_bytes_dsply % 4;
                        max_bytes_dsply += (4-i);
                    }
                    opts = O_SLANAL_OUT;
                    break;
                case 'd':
                    opts = O_DATASETS;
                    break;
                case 'f':
                    opts = O_FILES;
                    break;
                case 'h':
                    Print_Usage( pgm );
                    return 1;
                case 'l':
                    opts = O_LABELS;
                    break;
                case 's':
                    opts = O_SLANAL_OUT;
                    break;
                case 't':
                    opts = O_TAPEMAP_OUTPUT;
                    break;
                default:
                    Print_Usage( pgm );
                    return 1;
            }
        }

    }  // end if (! (opts & O_TAPEMAP_INVOKED) )

    argc -= optind;
    if( argc != 1 )
    {
        Print_Usage( pgm );
        exit( 1 );
    }

    if( opts & O_ALL )
    {
        printf( "%s", sep );
        printf( "%-20.20s: %s\n", "Filename", argv[ optind ] );
    }

    i_filename = argv[ optind ];

    if ( ( rc = (int)strlen( i_filename ) ) > 4 && ( rc = strcasecmp( &i_filename[rc-4], ".fkt" ) ) == 0 )
    {
        i_faketape = TRUE;
    }

    if ( i_faketape )
        rc = fet_open( &fetb, i_filename, FETOPEN_READONLY );
    else
        rc = het_open( &hetb, i_filename, HETOPEN_READONLY );
    if( rc < 0 )
    {
        if ( i_faketape )
        {
            printf( "fet_open() returned %d\n", (int)rc );
            fet_close( &fetb );
        }
        else
        {
            printf( "het_open() returned %d\n", (int)rc );
            het_close( &hetb );
        }
        exit( 1 );
    }

    BLANK_OUT ( gStdLblBuffer, sizeof ( gStdLblBuffer ) );

    fileno = 0;
    gBlkCount = 0;

    uminsz = 0;
    umaxsz = 0;
    ubytes = 0;
    cminsz = 0;
    cmaxsz = 0;
    cbytes = 0;

    totblocks = 0;
    totubytes = 0;
    totcbytes = 0;

    while( TRUE )
    {
#ifdef EXTERNALGUI
        if( extgui )
        {
            off_t curpos;
            /* Report progress every nnnK */
            if ( i_faketape )
                curpos = ftell( fetb->fh );
            else
                curpos = ftell( hetb->fh );
            if( ( curpos & PROGRESS_MASK ) != ( prevpos & PROGRESS_MASK ) )
            {
                prevpos = curpos;
                EXTGUIMSG( "IPOS=%"PRId64"\n", (U64)curpos );
            }
        }
#endif /*EXTERNALGUI*/

        if ( i_faketape)
        {
            rc = fet_read( fetb, gBuffer );
        }
        else
            rc = het_read( hetb, gBuffer );
        if( rc == HETE_EOT )                    // FETE and HETE enums are the same
        {
            if( opts & O_TAPEMAP_OUTPUT )
            {
                printf ("End of tape.\n");
            }
            break;
        }

        if( rc == HETE_TAPEMARK )
        {
            fileno += 1;

            lResidue = max_bytes_dsply;

            if( opts & O_TAPEMAP_OUTPUT )
            {
                printf ("File %d: Blocks=%d, block size min=%d, max=%d\n",
                        (int)fileno, (int)gBlkCount, (int)uminsz, (int)umaxsz      );
            }

            if( opts & O_FILES )
            {
                printf ( "%s", sep );
                printf ( "%-20.20s: %d\n", "File #", (int)fileno );
                printf ( "%-20.20s: %d\n", "Blocks", (int)gBlkCount );
                printf ( "%-20.20s: %d\n", "Min Blocksize", (int)uminsz );
                printf ( "%-20.20s: %d\n", "Max Blocksize", (int)umaxsz );
                if ( !i_faketape )
                {
                    printf ( "%-20.20s: %d\n", "Uncompressed bytes", (int)ubytes );
                    printf ( "%-20.20s: %d\n", "Min Blocksize-Comp", (int)cminsz );
                    printf ( "%-20.20s: %d\n", "Max Blocksize-Comp", (int)cmaxsz );
                    printf ( "%-20.20s: %d\n", "Compressed bytes", (int)cbytes );
                }
            }

            totblocks += gBlkCount;
            totubytes += ubytes;
            totcbytes += cbytes;

            gPrevBlkCnt = gBlkCount;
            gBlkCount = 0;

            uminsz = 0;
            umaxsz = 0;
            ubytes = 0;
            cminsz = 0;
            cmaxsz = 0;
            cbytes = 0;

            continue;
        }

        if( rc < 0 )
        {
            if ( i_faketape )
                printf ( "fet_read() returned %d\n", (int)rc );
            else
                printf ( "het_read() returned %d\n", (int)rc );
            break;
        }

        gBlkCount += 1;
        if ( !i_faketape )
        {
            ubytes += hetb->ublksize;
            cbytes += hetb->cblksize;

            if( uminsz == 0 || hetb->ublksize < uminsz ) uminsz = hetb->ublksize;
            if( hetb->ublksize > umaxsz ) umaxsz = hetb->ublksize;
            if( cminsz == 0 || hetb->cblksize < cminsz ) cminsz = hetb->cblksize;
            if( hetb->cblksize > cmaxsz ) cmaxsz = hetb->cblksize;
        }

        if ( rc >= 80 )
        {
            for (i=0; i < 80; i++)
            {
                gStdLblBuffer[i] = ebcdic_to_ascii[gBuffer[i]];
            }
            gStdLblBuffer[i] = '\0';
        }

        if( opts & O_LABELS )
        {
            Print_Label( rc );
        }

        if( opts & O_TAPEMAP_OUTPUT )
        {
            Print_Label_Tapemap( rc );
        }

        if( opts & O_DATASETS )
        {
            Print_Dataset( rc, fileno );
        }

        if( opts & O_SLANAL_OUT )
        {
            gLength = rc;

            if ( gLength == 80 )
            {
                if ( 0
                    || memcmp ( gStdLblBuffer, "HDR", 3 ) == 0
                    || memcmp ( gStdLblBuffer, "EOF", 3 ) == 0
                    || memcmp ( gStdLblBuffer, "VOL", 3 ) == 0
                    || memcmp ( gStdLblBuffer, "EOV", 3 ) == 0
                    || memcmp ( gStdLblBuffer, "UHL", 3 ) == 0
                    || memcmp ( gStdLblBuffer, "UTL", 3 ) == 0 )
                {
                    if ( !Print_Standard_Labels (  ) )
                    {
                        if ( gBlkCount <= 10 && ( gBlkCount == 1 || ( gBlkCount > 1 && lResidue > bytes_per_line ) ) )
                        {
                            gLenPrtd = ( gBlkCount == 1 ? ( gLength <= max_bytes_dsply ? gLength : max_bytes_dsply ) :
                                        ( gLength <= lResidue ? gLength : lResidue ) );
                            lResidue -= Print_Block_Data ( gLenPrtd );
                        }
                    }
                }
                else
                {
                    if ( gBlkCount <= 10 && ( gBlkCount == 1 || ( gBlkCount > 1 && lResidue > bytes_per_line ) ) )
                    {
                        gLenPrtd = ( gBlkCount == 1 ? ( gLength <= max_bytes_dsply ? gLength : max_bytes_dsply ) :
                                    ( gLength <= lResidue ? gLength : lResidue ) );
                        lResidue -= Print_Block_Data ( gLenPrtd );
                    }
                }
            }
            else
            {
                if ( ( gBlkCount <= 10 ) && ( ( gBlkCount == 1 ) || ( ( gBlkCount > 1 ) && ( lResidue > bytes_per_line ) ) ) )
                {
                    gLenPrtd = ( gBlkCount == 1 ? ( gLength <= max_bytes_dsply ? gLength : max_bytes_dsply ) :
                                ( gLength <= lResidue ? gLength : lResidue ) );
                    lResidue -= Print_Block_Data ( gLenPrtd );
                }
            }
        }
    }

    if( opts & O_FILES )
    {
        printf ( "%s", sep );
        printf ( "%-20.20s:\n", "Summary" );
        printf ( "%-20.20s: %d\n", "Files", (int)fileno );
        printf ( "%-20.20s: %d\n", "Blocks", (int)totblocks );
        if ( !i_faketape )
        {
            printf ( "%-20.20s: %llu\n", "Uncompressed bytes", (unsigned long long)totubytes );
            printf ( "%-20.20s: %llu\n", "Compressed bytes", (unsigned long long)totcbytes );
            printf ( "%-20.20s: %llu\n", "Reduction", (unsigned long long)(totubytes - totcbytes) );
        }
    }

    if ( i_faketape )
        fet_close( &fetb );
    else
        het_close( &hetb );

    return 0;
}
Exemple #2
0
/*
|| Open HET tapes and set options
*/
static int
opentapes( void )
{
    int rc;

    if ( ( rc = (int)strlen( o_sname ) ) > 4 && 
        ( rc = strcasecmp( &o_sname[rc-4], ".fkt" ) ) == 0 )
    {
        i_faketape = TRUE;
    }

    if ( i_faketape )
        rc = fet_open( &s_fetb, o_sname, FETOPEN_READONLY );
    else
        rc = het_open( &s_hetb, o_sname, HETOPEN_READONLY );
    if( rc < 0 )
    {
        if ( o_verbose )
            WRMSG( HHC02720, "E", o_sname, rc, het_error( rc ) );
        goto exit;
    }

    if ( ( rc = (int)strlen( o_dname ) ) > 4 && 
        ( rc = strcasecmp( &o_dname[rc-4], ".fkt" ) ) == 0 )
    {
        o_faketape = TRUE;
    }
    
    if ( o_faketape )
        rc = fet_open( &d_fetb, o_dname, FETOPEN_CREATE );
    else
        rc = het_open( &d_hetb, o_dname, HETOPEN_CREATE );
    if( rc < 0 )
    {
        if ( o_verbose )
            WRMSG( HHC02720, "E", o_dname, rc, het_error( rc ) );
        goto exit;
    }

    if ( !i_faketape )
    {
        if ( o_verbose )
            WRMSG( HHC02755, "I", "decompress", yesno( o_decompress ) );

        rc = het_cntl( s_hetb, HETCNTL_SET | HETCNTL_DECOMPRESS, o_decompress );
        if( rc < 0 )
        {
            if ( o_verbose )
                WRMSG( HHC00075, "E", "het_cntl()", het_error( rc ) );
            goto exit;
        }
    }

    if ( !o_faketape )
    {
        if ( o_verbose )
            WRMSG( HHC02755, "I", "compress", yesno( o_compress ) );

        rc = het_cntl( d_hetb, HETCNTL_SET | HETCNTL_COMPRESS, o_compress );
        if( rc < 0 )
        {
            if ( o_verbose )
                WRMSG( HHC00075, "E", "het_cntl()", het_error( rc ) );
            goto exit;
        }

        if ( o_verbose )
        {
            char msgbuf[16];
            MSGBUF( msgbuf, "%d", o_method );
            WRMSG( HHC02755, "I", "method", msgbuf );
        }

        rc = het_cntl( d_hetb, HETCNTL_SET | HETCNTL_METHOD, o_method );
        if( rc < 0 )
        {
            if ( o_verbose )
                WRMSG( HHC00075, "E", "het_cntl()", het_error( rc ) );
            goto exit;
        }

        if ( o_verbose )
        {
            char msgbuf[16];
            MSGBUF( msgbuf, "%d", o_level );
            WRMSG( HHC02755, "I", "level", msgbuf );
        }

        rc = het_cntl( d_hetb, HETCNTL_SET | HETCNTL_LEVEL, o_level );
        if( rc < 0 )
        {
            if ( o_verbose )
                WRMSG( HHC00075, "E", "het_cntl()", het_error( rc ) );
            goto exit;
        }

        if ( o_verbose )
        {
            char msgbuf[16];
            MSGBUF( msgbuf, "%d", o_chunksize );
            WRMSG( HHC02755, "I", "chunksize", msgbuf );
        }

        rc = het_cntl( d_hetb, HETCNTL_SET | HETCNTL_CHUNKSIZE, o_chunksize );
        if( rc < 0 )
        {
            if ( o_verbose )
                WRMSG( HHC00075, "E", "het_cntl()", het_error( rc ) );
            goto exit;
        }
    }

    if( o_verbose )
    {
        char msgbuf[128];

        MSGBUF( msgbuf, "Source             : %s", o_sname );
        WRMSG( HHC02757, "I", msgbuf );
        MSGBUF( msgbuf, "Destination        : %s", o_dname );
        WRMSG( HHC02757, "I", msgbuf );
        if ( !i_faketape )
        {
            MSGBUF( msgbuf, "Decompress source  : %s", yesno( het_cntl( s_hetb, HETCNTL_DECOMPRESS, 0 ) ) );
            WRMSG( HHC02757, "I", msgbuf );
        }
        if ( !o_faketape )
        {
            MSGBUF( msgbuf, "Compress dest      : %s", yesno( het_cntl( d_hetb, HETCNTL_COMPRESS, 0 ) ) );
            WRMSG( HHC02757, "I", msgbuf );
            MSGBUF( msgbuf, "Compression method : %d", het_cntl( d_hetb, HETCNTL_METHOD, 0 ) );
            WRMSG( HHC02757, "I", msgbuf );
            MSGBUF( msgbuf, "Compression level  : %d", het_cntl( d_hetb, HETCNTL_LEVEL, 0 ) );
            WRMSG( HHC02757, "I", msgbuf );
        }
    }

exit:

    return( rc );
}
Exemple #3
0
/*
|| Standard main
*/
int
main( int argc, char *argv[] )
{
    char           *pgmname;                /* prog name in host format  */
    char           *pgm;                    /* less any extension (.ext) */
    char            msgbuf[512];            /* message build work area   */
    FILE           *outf;
    int             rc;
    int             i;
    char            pathname[MAX_PATH];
    char           *strtok_str = NULL;

    /* Set program name */
    if ( argc > 0 )
    {
        if ( strlen(argv[0]) == 0 )
        {
            pgmname = strdup( UTILITY_NAME );
        }
        else
        {
            char path[MAX_PATH];
#if defined( _MSVC_ )
            GetModuleFileName( NULL, path, MAX_PATH );
#else
            strncpy( path, argv[0], sizeof( path ) );
#endif
            pgmname = strdup(basename(path));
#if !defined( _MSVC_ )
            strncpy( path, argv[0], sizeof(path) );
#endif
        }
    }
    else
    {
        pgmname = strdup( UTILITY_NAME );
    }

    pgm = strtok_r( strdup(pgmname), ".", &strtok_str);
    INITIALIZE_UTILITY( pgmname );

    /* Display the program identification message */
    MSGBUF( msgbuf, MSG_C( HHC02499, "I", pgm, "Extract Files from AWS, HET or FAKETAPE" ) );
    display_version (stderr, msgbuf+10, FALSE);

    /*
    || Process option switches
    */
    while( TRUE )
    {
        rc = getopt( argc, argv, "abhnsu" );
        if( rc == -1 )
        {
            break;
        }

        switch( rc )
        {
            case 'a':
                opts.flags |= O_ASCII;
                set_codepage(NULL);
            break;

            case 'h':
                usage( pgm );
                exit( 1 );
            break;

            case 'n':
                opts.flags |= O_NL;
            break;

            case 's':
                opts.flags |= O_STRIP;
            break;

            case 'u':
                opts.flags |= O_UNBLOCK;
            break;

            default:
                usage( pgm );
                exit( 1 );
            break;
        }
    }

    /*
    || Calc number of non-switch arguments
    */
    argc -= optind;

    /*
    || We must have at least the first 3 parms
    */
    if(argc < 3)
    {
        if ( argc > 1 )
            WRMSG( HHC02446, "E" );
        usage( pgm );
        exit( 1 );
    }

    hostpath( pathname, argv[ optind ], sizeof(pathname) );
    opts.ifile = strdup( pathname );
    if ( ( rc = (int)strlen( opts.ifile ) ) > 4 
      && ( rc = strcasecmp( &opts.ifile[rc-4], ".fkt" ) ) == 0 )
    {
        opts.faketape = TRUE;
    }


    hostpath( pathname, argv[ optind + 1 ], sizeof(pathname) );
    opts.ofile = strdup( pathname );

    opts.fileno = atoi( argv[ optind + 2 ] );

    if( opts.fileno == 0 || opts.fileno > 9999 )
    {
        char msgbuf[20];
        MSGBUF( msgbuf, "%d", opts.fileno );
        WRMSG( HHC02205, "E", msgbuf, "; file number must be within the range of 1 to 9999" );
        exit( 1 );
    }

    /*
    || If NL tape, then we require the DCB attributes
    */
    if( opts.flags & O_NL )
    {
        if( argc != 6 )
        {
            WRMSG( HHC02750, "E" );
            exit( 1 );
        }
    }

    /*
    || If specified, get the DCB attributes
    */
    if( argc > 3 )
    {
        /*
        || Must have only three
        */
        if( argc != 6 )
        {
            usage( pgm );
            exit( 1 );
        }

        /*
        || Lookup the specified RECFM in our table
        */
        opts.recfm = 0;
        for( i = 0 ; i < (int)VALFMCNT ; i++ )
        {
            if( strcasecmp( argv[ optind + 3 ], valfm[ i ].recfm ) == 0 )
            {
                opts.recfm = valfm[ i ].fmt;
                break;
            }
        }

        /*
        || If we didn't find a match, show the user what the valid ones are
        */
        if( opts.recfm == 0)
        {
            char msgbuf[512] = "";
            char msgbuf2[64] = "";
            char msgbuf3[16] = "";
            char msgbuf4[128] = "";

            /*
            || Dump out the valid RECFMs
            */
            MSGBUF( msgbuf, MSG( HHC02751, "I" ) );
            for( i = 0 ; i < (int)VALFMCNT ; i++ )
            {
                MSGBUF( msgbuf3, "  %-4.4s", valfm[ i ].recfm );

                if( ( ( i + 1 ) % 3 ) == 0 )
                {
                    strcat( msgbuf2, msgbuf3 );
                    MSGBUF( msgbuf4, MSG( HHC02752, "I", msgbuf2 ) );
                    strcat( msgbuf, msgbuf4 );
                    msgbuf2[0] = 0;
                }
                else
                {
                    strcat( msgbuf2, msgbuf3 );
                }
            }
            printf( "%s", msgbuf );
            exit( 1 );
        }

        /*
        || Get the record length
        */
        opts.lrecl = atoi( argv[ optind + 4 ] );

        /*
        || Get and validate the blksize
        */
        opts.blksize = atoi( argv[ optind + 5 ] );
        if( opts.blksize == 0 )
        {
            WRMSG( HHC02205, "E", "0", "; block size can't be zero" );
            exit( 1 );
        }
    }

    /*
    || Open the tape file
    */
    if ( opts.faketape )
        rc = fet_open( &opts.fetb, opts.ifile, FETOPEN_READONLY );
    else
        rc = het_open( &opts.hetb, opts.ifile, HETOPEN_READONLY );
    if( rc >= 0 )
    {
        /*
        || Get memory for the tape buffer
        */
        blkptr = malloc( HETMAX_BLOCKSIZE );
        if( blkptr != NULL )
        {
            /*
            || Open the output file
            */
            outf = fopen( opts.ofile, "wb" );
            if( outf != NULL )
            {
                /*
                || Go extract the file from the tape
                */
                rc = getfile( outf );

                /*
                || Close the output file
                */
                fclose( outf );
            }
            
            /*
            || Free the buffer memory
            */
            free( blkptr );
        }
    }
    else
    {
        if ( opts.faketape )
            WRMSG( HHC00075, "E", "fet_open()", fet_error( rc ) );
        else
            WRMSG( HHC00075, "E", "het_open()", het_error( rc ) );
    }

    /*
    || Close the tape file
    */
    if ( opts.faketape )
        fet_close( &opts.fetb );
    else
        het_close( &opts.hetb );

    return 0;
}
Exemple #4
0
/*
|| Standard main() function
*/
int
main( int argc, char *argv[] )
{
    char           *pgmname;                /* prog name in host format  */
    char           *pgm;                    /* less any extension (.ext) */
    char            msgbuf[512];            /* message build work area   */
    int             rc;
    SLLABEL         lab;
    HETB           *hetb;                   /* used for aws and het tapes*/
    FETB           *fetb;                   /* used for faketapes        */
    int             o_iehinitt;
    int             o_nl;
    int             o_compress;
    int             o_faketape;
    char           *o_filename;
    char           *o_owner;
    char           *o_volser;
    char           *strtok_str = NULL;


    /* Set program name */
    if ( argc > 0 )
    {
        if ( strlen(argv[0]) == 0 )
        {
            pgmname = strdup( UTILITY_NAME );
        }
        else
        {
            char path[MAX_PATH];
#if defined( _MSVC_ )
            GetModuleFileName( NULL, path, MAX_PATH );
#else
            strncpy( path, argv[0], sizeof( path ) );
#endif
            pgmname = strdup(basename(path));
#if !defined( _MSVC_ )
            strncpy( path, argv[0], sizeof(path) );
#endif
        }
    }
    else
    {
        pgmname = strdup( UTILITY_NAME );
    }

    pgm = strtok_r( strdup(pgmname), ".", &strtok_str);
    INITIALIZE_UTILITY( pgmname );

    /* Display the program identification message */
    MSGBUF( msgbuf, MSG_C( HHC02499, "I", pgm, "HET IEHINITT " ) );
    display_version (stderr, msgbuf+10, FALSE);

    hetb = NULL;
    fetb = NULL;
    o_filename = NULL;
    o_faketape = FALSE;
    o_iehinitt = TRUE;
    o_nl = FALSE;
    o_compress = TRUE;
    o_owner = NULL;
    o_volser = NULL;

    while( TRUE )
    {
        rc = getopt( argc, argv, "dhin" );
        if( rc == -1 )
        {
            break;
        }

        switch( rc )
        {
            case 'd':
                o_compress = FALSE;
            break;

            case 'h':
                usage( pgm );
                goto exit;
            break;

            case 'i':
                o_iehinitt = TRUE;
                o_nl = FALSE;
            break;

            case 'n':
                o_iehinitt = FALSE;
                o_nl = TRUE;
            break;

            default:
                usage( pgm );
                goto exit;
            break;
        }
    }

    argc -= optind;

    if( argc < 1 )
    {
        usage( pgm );
        goto exit;
    }

    o_filename = argv[ optind ];

    if ( ( rc = (int)strlen( o_filename ) ) > 4 && ( rc = strcasecmp( &o_filename[rc-4], ".fkt" ) ) == 0 )
    {
        o_faketape = TRUE;
    }

    if( o_iehinitt )
    {
        if( argc == 2 )
        {
            o_volser = argv[ optind + 1 ];
        }
        else if( argc == 3 )
        {
            o_volser = argv[ optind + 1 ];
            o_owner = argv[ optind + 2 ];
        }
        else
        {
            usage( pgm );
            goto exit;
        }
    }

    if( o_nl )
    {
        if( argc != 1 )
        {
            usage( pgm );
            goto exit;
        }
    }

    if( o_volser )
        het_string_to_upper( o_volser );

    if( o_owner )
        het_string_to_upper( o_owner );

    if ( o_faketape )  
    {
        rc = fet_open( &fetb, o_filename, FETOPEN_CREATE );
        if ( rc < 0 )
        {
            WRMSG( HHC00075, "E", "fet_open()", fet_error( rc ) );
            goto exit;
        }

    }
    else
    {
        rc = het_open( &hetb, o_filename, HETOPEN_CREATE );
        if( rc < 0 )
        {
            WRMSG( HHC00075, "E", "het_open()", het_error( rc ) );
            goto exit;
        }
   
        rc = het_cntl( hetb, HETCNTL_SET | HETCNTL_COMPRESS, o_compress );
        if( rc < 0 )
        {
            WRMSG( HHC00075, "E", "het_cntl()", het_error( rc ) );
            goto exit;
        }
    }

    if( o_iehinitt )
    {
        rc = sl_vol1( &lab, o_volser, o_owner );
        if( rc < 0 )
        {
            WRMSG( HHC00075, "E", "sl_vol1()", sl_error( rc ) );
            goto exit;
        }

        if ( o_faketape )
            rc = fet_write( fetb, &lab, (U16)sizeof( lab ) );
        else
            rc = het_write( hetb, &lab, sizeof( lab ) );
        if( rc < 0 )
        {
            if ( o_faketape )
                WRMSG( HHC00075, "E", "fet_write() for VOL1", fet_error( rc ) );
            else
                WRMSG( HHC00075, "E", "het_write() for VOL1", het_error( rc ) );
            goto exit;
        }

        rc = sl_hdr1( &lab, SL_INITDSN, NULL, 0, 0, NULL, 0 );
        if( rc < 0 )
        {
            WRMSG( HHC00075, "E", "sl_hdr1()", sl_error( rc ) );
            goto exit;
        }
        
        if ( o_faketape )  
            rc = fet_write( fetb, &lab, (U16)sizeof(lab) );
        else
            rc = het_write( hetb, &lab, sizeof( lab ) );
        if( rc < 0 )
        {
            if ( o_faketape )
                WRMSG( HHC00075, "E", "fet_write() for HDR1", fet_error( rc ) );
            else
                WRMSG( HHC00075, "E", "het_write() for HDR1", het_error( rc ) );
            goto exit;
        }

    }
    else if( o_nl )
    {
        if ( o_faketape )  
            rc = fet_tapemark( fetb );
        else
            rc = het_tapemark( hetb );
        if( rc < 0 )
        {
            if ( o_faketape )
                WRMSG( HHC00075, "E", "fet_tapemark()", fet_error( rc ) );
            else
                WRMSG( HHC00075, "E", "het_tapemark()", het_error( rc ) );
            goto exit;
        }
    }

    if ( o_faketape )  
        rc = fet_tapemark( fetb );
    else
        rc = het_tapemark( hetb );
    if( rc < 0 )
    {
        if ( o_faketape )
            WRMSG( HHC00075, "E", "fet_tapemark()", fet_error( rc ) );
        else
            WRMSG( HHC00075, "E", "het_tapemark()", het_error( rc ) );
        goto exit;
    }

exit:
    if ( o_faketape)
        fet_close( &fetb );
    else
        het_close( &hetb );

    return( rc < 0 );
}
Exemple #5
0
/*
|| Standard main
*/
int
main( int argc, char *argv[] )
{
    char           *pgm;                    /* less any extension (.ext) */
    FILE           *outf;
    int             rc;
    int             i;
    char            pathname[MAX_PATH];

    INITIALIZE_UTILITY( UTILITY_NAME, "Extract Files from AWS, HET or FAKETAPE", &pgm );

    /*
    || Process option switches
    */
    while( TRUE )
    {
        rc = getopt( argc, argv, "abhnsu" );
        if( rc == -1 )
        {
            break;
        }

        switch( rc )
        {
            case 'a':
                opts.flags |= O_ASCII;
                set_codepage(NULL);
            break;

            case 'h':
                usage( pgm );
                exit( 1 );
            UNREACHABLE_CODE();

            case 'n':
                opts.flags |= O_NL;
            break;

            case 's':
                opts.flags |= O_STRIP;
            break;

            case 'u':
                opts.flags |= O_UNBLOCK;
            break;

            default:
                usage( pgm );
                exit( 1 );
            UNREACHABLE_CODE();
        }
    }

    /*
    || Calc number of non-switch arguments
    */
    argc -= optind;

    /*
    || We must have at least the first 3 parms
    */
    if(argc < 3)
    {
        if ( argc > 1 )
            // "Invalid number of arguments"
            FWRMSG( stderr, HHC02446, "E" );
        usage( pgm );
        exit( 1 );
    }

    hostpath( pathname, argv[ optind ], sizeof(pathname) );
    opts.ifile = strdup( pathname );
    if ( ( rc = (int)strlen( opts.ifile ) ) > 4
      && ( rc = strcasecmp( &opts.ifile[rc-4], ".fkt" ) ) == 0 )
    {
        opts.faketape = TRUE;
    }


    hostpath( pathname, argv[ optind + 1 ], sizeof(pathname) );
    opts.ofile = strdup( pathname );

    opts.fileno = atoi( argv[ optind + 2 ] );

    if( opts.fileno == 0 || opts.fileno > 9999 )
    {
        char msgbuf[20];
        MSGBUF( msgbuf, "%d", opts.fileno );
        // "Invalid argument %s%s"
        FWRMSG( stderr, HHC02205, "S", msgbuf, "; file number must be within the range of 1 to 9999" );
        exit( 1 );
    }

    /*
    || If NL tape, then we require the DCB attributes
    */
    if( opts.flags & O_NL )
    {
        if( argc != 6 )
        {
            // "DCB attributes required for NL tape"
            FWRMSG( stderr, HHC02750, "S" );
            exit( 1 );
        }
    }

    /*
    || If specified, get the DCB attributes
    */
    if( argc > 3 )
    {
        /*
        || Must have only three
        */
        if( argc != 6 )
        {
            usage( pgm );
            exit( 1 );
        }

        /*
        || Lookup the specified RECFM in our table
        */
        opts.recfm = 0;
        for( i = 0 ; i < (int)VALFMCNT ; i++ )
        {
            if( strcasecmp( argv[ optind + 3 ], valfm[ i ].recfm ) == 0 )
            {
                opts.recfm = valfm[ i ].fmt;
                break;
            }
        }

        /*
        || If we didn't find a match, show the user what the valid ones are
        */
        if( opts.recfm == 0)
        {
            char msgbuf[512] = "";
            char msgbuf2[64] = "";
            char msgbuf3[16] = "";
            char msgbuf4[128] = "";

            /*
            || Dump out the valid RECFMs
            */
            // "Valid record formats are:"
            MSGBUF( msgbuf, MSG( HHC02751, "I" ) );
            for( i = 0 ; i < (int)VALFMCNT ; i++ )
            {
                MSGBUF( msgbuf3, "  %-4.4s", valfm[ i ].recfm );

                if( ( ( i + 1 ) % 3 ) == 0 )
                {
                    strlcat( msgbuf2, msgbuf3, sizeof(msgbuf2) );
                    // "%s"
                    MSGBUF( msgbuf4, MSG( HHC02752, "I", msgbuf2 ) );
                    strlcat( msgbuf, msgbuf4, sizeof(msgbuf) );
                    msgbuf2[0] = 0;
                }
                else
                {
                    strlcat( msgbuf2, msgbuf3, sizeof(msgbuf2) );
                }
            }
            printf( "%s", msgbuf );
            exit( 1 );
        }

        /*
        || Get the record length
        */
        opts.lrecl = atoi( argv[ optind + 4 ] );

        /*
        || Get and validate the blksize
        */
        opts.blksize = atoi( argv[ optind + 5 ] );
        if( opts.blksize == 0 )
        {
            // "Invalid argument %s%s"
            FWRMSG( stderr, HHC02205, "S", "0", "; block size can't be zero" );
            exit( 1 );
        }
    }

    /*
    || Open the tape file
    */
    if ( opts.faketape )
        rc = fet_open( &opts.fetb, opts.ifile, FETOPEN_READONLY );
    else
        rc = het_open( &opts.hetb, opts.ifile, HETOPEN_READONLY );
    if( rc >= 0 )
    {
        /*
        || Get memory for the tape buffer
        */
        blkptr = malloc( HETMAX_BLOCKSIZE );
        if( blkptr != NULL )
        {
            /*
            || Open the output file
            */
            outf = fopen( opts.ofile, "wb" );
            if( outf != NULL )
            {
                /*
                || Go extract the file from the tape
                */
                rc = getfile( outf );

                /*
                || Close the output file
                */
                fclose( outf );
            }

            /*
            || Free the buffer memory
            */
            free( blkptr );
        }
    }
    else
    {
        // "Error in function %s: %s"
        if ( opts.faketape )
            FWRMSG( stderr, HHC00075, "E", "fet_open()", fet_error( rc ) );
        else
            FWRMSG( stderr, HHC00075, "E", "het_open()", het_error( rc ) );
    }

    /*
    || Close the tape file
    */
    if ( opts.faketape )
        fet_close( &opts.fetb );
    else
        het_close( &opts.hetb );

    return 0;
}