]>
Commit | Line | Data |
---|---|---|
25697a35 | 1 | /* |
94ff9470 | 2 | * SARG Squid Analysis Report Generator http://sarg.sourceforge.net |
61d965f3 | 3 | * 1998, 2012 |
25697a35 GS |
4 | * |
5 | * SARG donations: | |
6 | * please look at http://sarg.sourceforge.net/donations.php | |
1164c474 FM |
7 | * Support: |
8 | * http://sourceforge.net/projects/sarg/forums/forum/363374 | |
25697a35 GS |
9 | * --------------------------------------------------------------------- |
10 | * | |
11 | * This program is free software; you can redistribute it and/or modify | |
12 | * it under the terms of the GNU General Public License as published by | |
13 | * the Free Software Foundation; either version 2 of the License, or | |
14 | * (at your option) any later version. | |
15 | * | |
16 | * This program is distributed in the hope that it will be useful, | |
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 | * GNU General Public License for more details. | |
20 | * | |
21 | * You should have received a copy of the GNU General Public License | |
22 | * along with this program; if not, write to the Free Software | |
23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. | |
24 | * | |
25 | */ | |
26 | ||
27 | #include "include/conf.h" | |
5f3cfd1d | 28 | #include "include/defs.h" |
25697a35 | 29 | |
d2855b39 | 30 | FILE *decomp(const char *arq, bool *pipe) |
25697a35 | 31 | { |
9bd92830 FM |
32 | char cmd[1024]; |
33 | int arqlen; | |
25697a35 | 34 | |
9bd92830 FM |
35 | if(access(arq, R_OK) != 0) { |
36 | debuga(_("File not found: %s\n"),arq); | |
37 | exit(EXIT_FAILURE); | |
38 | } | |
25697a35 | 39 | |
9bd92830 FM |
40 | arqlen=strlen(arq); |
41 | if(arqlen>3 && strcmp(arq+arqlen-3,".gz") == 0) { | |
42 | debuga(_("Decompressing log file \"%s\" with zcat\n"),arq); | |
43 | if (snprintf(cmd,sizeof(cmd),"zcat \"%s\"",arq)>=sizeof(cmd)) { | |
44 | debuga(_("decompression command too long for log file %s\n"),arq); | |
45 | exit(EXIT_FAILURE); | |
46 | } | |
47 | *pipe=true; | |
48 | return(popen(cmd,"r")); | |
49 | } | |
25697a35 | 50 | |
9bd92830 FM |
51 | if(arqlen>4 && strcmp(arq+arqlen-4,".bz2") == 0) { |
52 | debuga(_("Decompressing log file \"%s\" with bzcat\n"),arq); | |
53 | if (snprintf(cmd,sizeof(cmd),"bzcat \"%s\"",arq)>=sizeof(cmd)) { | |
54 | debuga(_("decompression command too long for log file %s\n"),arq); | |
55 | exit(EXIT_FAILURE); | |
56 | } | |
57 | *pipe=true; | |
58 | return(popen(cmd,"r")); | |
59 | } | |
25697a35 | 60 | |
9bd92830 FM |
61 | if(arqlen>2 && strcmp(arq+arqlen-2,".Z") == 0) { |
62 | debuga(_("Decompressing log file \"%s\" with zcat\n"),arq); | |
63 | if (snprintf(cmd,sizeof(cmd),"zcat \"%s\"",arq)>=sizeof(cmd)) { | |
64 | debuga(_("decompression command too long for log file %s\n"),arq); | |
65 | exit(EXIT_FAILURE); | |
66 | } | |
67 | *pipe=true; | |
68 | return(popen(cmd,"r")); | |
69 | } | |
25697a35 | 70 | |
9bd92830 FM |
71 | *pipe=false; |
72 | return(MY_FOPEN(arq,"r")); | |
25697a35 | 73 | } |