********>BZIP2 Support Update for Carnal in Amber 7 Author: Ross Walker Date: 3/13/03 Programs: Carnal Description: Most versions of Linux now include support for the bzip2 method of file compression. This typically offers between 10 and 20% higher compression ratios than gzip. This patch adds support for bzipped mdcrd files using the bunzip2 program. Bzip2 files should have the file extension .bz2 Usage: Apply the following patch to amber7/src/carnal/util.c: ------------------------------------------------------------------------------ *** util.c Fri Nov 23 00:00:00 2001 --- util.c Thu Mar 13 13:35:37 2003 @@ -41,6 +41,7 @@ #define COMPRESS 1 #define GZIP 2 +#define BZIP2 3 char tok[TOKLEN]; char line[TOKLEN]; @@ -206,9 +207,15 @@ compressed = GZIP; goto OPEN; } - + strcpy(&cbuf[length], ".bz2"); + if (stat(cbuf, &sbuf) != -1) { + printf("\tusing %s\n", cbuf); + strcat(name, ".bz2"); + compressed = BZIP2; + goto OPEN; + } printf("%s: does not exist %s\n", - name, "(nor do .Z or .gz)"); + name, "(nor do .Z or .gz or .bz2)"); return(NULL); case COMPRESS: @@ -234,6 +241,18 @@ name[length-2] = '\0'; compressed = 0; goto OPEN; + + case BZIP2: + cbuf[length-4] = '\0'; + if (stat(cbuf, &sbuf) == -1) { + printf("%s, %s: does not exist\n", + name, cbuf); + return(NULL); + } + printf("\tusing %s\n", cbuf); + name[length-2] = '\0'; + compressed = 0; + goto OPEN; } } default: @@ -273,6 +292,16 @@ } break; } + case BZIP2: { + char pcmd[MAXPATHLEN+20]; + + sprintf(pcmd, "bunzip2 -c %s", cbuf); + if ((fp = popen(pcmd, "r")) == NULL) { + perror(pcmd); + exit(1); + } + break; + } default: printf("programming error in genopen\n"); exit(1); @@ -420,6 +449,18 @@ } break; } + case BZIP2: { + char pcmd[120]; + + sprintf(pcmd, "bunzip2 -c %s", name); + if (pclose(*file) == -1) + perror(name); + if ((*file = popen(pcmd, "r")) == NULL) { + perror(pcmd); + exit(1); + } + break; + } default: fprintf(stderr, "programmer error - compression type\n"); exit(1); @@ -463,6 +504,13 @@ return(0); if (!strcmp(&name[i-3], ".gz")) return(GZIP); + if (i < 5) + return(0); + if (!strcmp(&name[i-4], ".bz2")) + { + return(BZIP2); + + } return(0); }