]> git.ipfire.org Git - thirdparty/sarg.git/blob - decomp.c
Reindent code with tabs instead of space
[thirdparty/sarg.git] / decomp.c
1 /*
2 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
3 * 1998, 2010
4 *
5 * SARG donations:
6 * please look at http://sarg.sourceforge.net/donations.php
7 * Support:
8 * http://sourceforge.net/projects/sarg/forums/forum/363374
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"
28 #include "include/defs.h"
29
30 FILE *decomp(const char *arq, bool *pipe)
31 {
32 char cmd[1024];
33 int arqlen;
34
35 if(access(arq, R_OK) != 0) {
36 debuga(_("File not found: %s\n"),arq);
37 exit(EXIT_FAILURE);
38 }
39
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 }
50
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 }
60
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 }
70
71 *pipe=false;
72 return(MY_FOPEN(arq,"r"));
73 }