]> git.ipfire.org Git - thirdparty/sarg.git/blame - decomp.c
Convert or split all the input logs
[thirdparty/sarg.git] / decomp.c
CommitLineData
25697a35 1/*
94ff9470 2 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
1164c474 3 * 1998, 2010
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 30FILE *decomp(const char *arq, bool *pipe)
25697a35 31{
25697a35 32 char cmd[1024];
b008f87f 33 int arqlen;
25697a35
GS
34
35 if(access(arq, R_OK) != 0) {
10210234 36 debuga(_("File not found: %s\n"),arq);
06b39c87 37 exit(EXIT_FAILURE);
25697a35
GS
38 }
39
b008f87f
FM
40 arqlen=strlen(arq);
41 if(arqlen>3 && strcmp(arq+arqlen-3,".gz") == 0) {
d2855b39
FM
42 debuga(_("Decompressing log file \"%s\" with zcat\n"),arq);
43 if (snprintf(cmd,sizeof(cmd),"zcat \"%s\"",arq)>=sizeof(cmd)) {
10210234 44 debuga(_("decompression command too long for log file %s\n"),arq);
06b39c87 45 exit(EXIT_FAILURE);
b008f87f 46 }
d2855b39
FM
47 *pipe=true;
48 return(popen(cmd,"r"));
25697a35
GS
49 }
50
b008f87f 51 if(arqlen>4 && strcmp(arq+arqlen-4,".bz2") == 0) {
d2855b39
FM
52 debuga(_("Decompressing log file \"%s\" with bzcat\n"),arq);
53 if (snprintf(cmd,sizeof(cmd),"bzcat \"%s\"",arq)>=sizeof(cmd)) {
10210234 54 debuga(_("decompression command too long for log file %s\n"),arq);
06b39c87 55 exit(EXIT_FAILURE);
b008f87f 56 }
d2855b39
FM
57 *pipe=true;
58 return(popen(cmd,"r"));
25697a35
GS
59 }
60
b008f87f 61 if(arqlen>2 && strcmp(arq+arqlen-2,".Z") == 0) {
d2855b39
FM
62 debuga(_("Decompressing log file \"%s\" with zcat\n"),arq);
63 if (snprintf(cmd,sizeof(cmd),"zcat \"%s\"",arq)>=sizeof(cmd)) {
10210234 64 debuga(_("decompression command too long for log file %s\n"),arq);
06b39c87 65 exit(EXIT_FAILURE);
b008f87f 66 }
d2855b39
FM
67 *pipe=true;
68 return(popen(cmd,"r"));
456d78a5 69 }
25697a35 70
d2855b39
FM
71 *pipe=false;
72 return(MY_FOPEN(arq,"r"));
25697a35 73}