00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include <stdio.h>
00035 #include "general.h"
00036 #include "strings.h"
00037 char RRo_is_Z[100];
00038
00043 FILE *rr_oopen(char *path)
00044 {
00045 static char rname[]="rr_oopen";
00046 FILE *fp;
00047 char pipe[256], is_Z;
00048 int lpath;
00049
00050 if (strcmp(path,"-")==0) return(stdout);
00051
00052 lpath = strlen(path);
00053 if (strcmp(&path[lpath-2],".Z")==0) {
00054 if (lpath > sizeof(pipe) - strlen("compress >! ") - 4)
00055 quit(-1,"%s: pathname '%s' is too long\n",rname,path);
00056 sprintf(pipe,"compress > %s",path);
00057 fp = popen(pipe,"w");
00058 if (!fp) quit(-1,"%s: problems opening the pipe '%s' for output.\n", rname,pipe);
00059 is_Z = 1;
00060 }
00061 else {
00062 if (strcmp(&path[lpath-3],".gz")==0) {
00063 if (lpath > sizeof(pipe) - strlen("gzip >! ") -4)
00064 quit(-1,"%s: pathname '%s' is too long\n",rname,path);
00065 sprintf(pipe,"gzip > %s",path);
00066 fp = popen(pipe,"w");
00067 if (!fp) quit(-1,"%s: problems opening the pipe '%s' for output.\n", rname,pipe);
00068 is_Z = 1;
00069 }
00070 else {
00071 fp = rr_fopen(path,"w");
00072 is_Z = 0;
00073 }
00074 }
00075
00076 if (fileno(fp) > sizeof(RRo_is_Z)-1) quit(-1,"%s: fileno = %d is too large\n",rname,fileno(fp));
00077 RRo_is_Z[fileno(fp)] = is_Z;
00078
00079 return(fp);
00080 }
00081
00082 void *rr_oclose(FILE *fp)
00083 {
00084 if (fp==stdout) return(0);
00085 fflush(fp);
00086 if (RRo_is_Z[fileno(fp)])
00087 pclose(fp);
00088 else
00089 fclose(fp);
00090
00091 return(0);
00092
00093 }