File indexing completed on 2025-08-03 08:20:53
0001
0002
0003 #include "buffer.h"
0004 #include <cstdio>
0005 #include <iostream>
0006 #include <iomanip>
0007 #include <cstdlib>
0008 #include <csignal>
0009
0010 #include <unistd.h>
0011 #include <sys/types.h>
0012 #include <sys/stat.h>
0013 #include <fcntl.h>
0014
0015
0016
0017 void exitmsg()
0018 {
0019 std::cout << "** usage: prdflist infile outfile1 outfile2 ..." << std::endl;
0020 exit(0);
0021 }
0022
0023
0024
0025
0026
0027
0028 int check_buffermarker ( const unsigned int bm)
0029 {
0030
0031 if ( bm == BUFFERMARKER ||
0032 bm == GZBUFFERMARKER ||
0033 bm == LZO1XBUFFERMARKER ||
0034 bm == LZO1CBUFFERMARKER ||
0035 bm == LZO2ABUFFERMARKER ||
0036 bm == BZ2BUFFERMARKER )
0037 {
0038 return 1;
0039 }
0040
0041 else if ( buffer::u4swap(bm) == BUFFERMARKER ||
0042 buffer::u4swap(bm) == GZBUFFERMARKER ||
0043 buffer::u4swap(bm) == LZO1XBUFFERMARKER ||
0044 buffer::u4swap(bm) == LZO1CBUFFERMARKER ||
0045 buffer::u4swap(bm) == LZO2ABUFFERMARKER ||
0046 buffer::u4swap(bm) == BZ2BUFFERMARKER )
0047 {
0048 return -1;
0049 }
0050
0051
0052 return 0;
0053 }
0054
0055
0056 int main(int argc, char *argv[])
0057 {
0058
0059 unsigned int buffer[8*8192];
0060
0061 int i;
0062 int fd;
0063
0064 int nr_outfiles = argc-2;
0065 int *fdout = new int[nr_outfiles];
0066
0067
0068 fd = open(argv[1], O_RDONLY | O_LARGEFILE);
0069
0070 for ( i=0; i< nr_outfiles; i++)
0071 {
0072
0073
0074 fdout[i] = open(argv[2+i], O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE ,
0075 S_IRWXU | S_IROTH | S_IRGRP);
0076 if ( fdout[i] < 0)
0077 {
0078 std::cout << " could not open " << argv[2+i] << std::endl;
0079 exit(1);
0080 }
0081
0082 }
0083
0084
0085 int length;
0086 int ip;
0087
0088 int total_read = 0;
0089
0090 int xc;
0091
0092 int current_fdnr = 0;
0093
0094 xc = read ( fd, (char *)buffer, 8192);
0095
0096 while ( xc == 8192 )
0097 {
0098
0099 ip = 8192;
0100
0101 int markerstatus;
0102 if ( (markerstatus = check_buffermarker(buffer[1]) ) )
0103 {
0104
0105
0106
0107 if ( markerstatus == -1)
0108 {
0109 length = buffer::i4swap(buffer[0]);
0110 }
0111 else
0112 {
0113 length = buffer[0];
0114 }
0115
0116
0117 int nwritten = write (fdout[current_fdnr], buffer, 8192);
0118 if ( nwritten < 8192)
0119 {
0120 std::cout << " could not write output " << total_read << std::endl;
0121 exit(1);
0122 }
0123
0124 while ( ip < length)
0125 {
0126 xc = read ( fd, (char *)buffer, 8192);
0127 if ( xc < 8192 )
0128 {
0129 std::cout << "end or error in read loop at rec " << total_read << std::endl;
0130 exit(1);
0131 }
0132 total_read++;
0133 ip+= 8192;
0134 nwritten = write (fdout[current_fdnr], buffer, 8192);
0135 }
0136
0137 }
0138
0139 if ( ++current_fdnr >= nr_outfiles) current_fdnr = 0;
0140
0141
0142 xc = read ( fd, (char *)buffer, 8192);
0143
0144 }
0145 for ( i=0; i< nr_outfiles; i++)
0146 {
0147 close (fdout[i]);
0148 }
0149 return 0;
0150
0151 }
0152