1 /*
2 * This file is part of Checkmate, a program to check MP3 files for errors
3 *
4 * Copyright (C) 2006 Sjoerd Langkemper
5 *
6 * Checkmate is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 *****************************************************************************
21 *
22 * total.c - keeps total stats
23 *
24 */
25
26 #include "mpck.h"
27 #include "total.h"
28 #include "options.h"
29
30 #ifdef HAVE_STDLIB_H
31 #include <stdlib.h>
32 #endif
33
34 #ifdef HAVE_STRING_H
35 #include <string.h>
36 #endif
37
38 #ifdef HAVE_STRINGS_H
39 #include <strings.h>
40 #endif
41
42 total_info *
total_create()43 total_create()
44 {
45 total_info * total;
46
47 total = (total_info *) malloc(sizeof(total_info));
48 if (total == NULL) return NULL;
49 memset(total, 0, sizeof(total_info));
50 return total;
51 }
52
total_destroy(total)53 void total_destroy(total)
54 total_info * total;
55 {
56 free(total);
57 }
58
59 /*
60 * puts stats from file (bitrate, file count) into the total stats
61 */
62 int
total_update(total,file)63 total_update(total, file)
64 total_info * total;
65 const file_info * file;
66 {
67 /* don't do stats for files which aren't MP3s */
68 if (!file->ismp3file) return TRUE;
69
70 total->filecount++;
71
72 if (!file->errors) total->goodcount++;
73 total->time += file->time;
74 total->totalbitrate += file->bitrate;
75 if ((!total->minbitrate)||(file->bitrate < total->minbitrate)) {
76 total->minbitrate=file->bitrate;
77 }
78 if (file->bitrate > total->maxbitrate) {
79 total->maxbitrate=file->bitrate;
80 }
81 return TRUE;
82 }
83
84 void
total_print(total)85 total_print(total)
86 const total_info * total;
87 {
88 if (total->filecount<2) return;
89 if (options_get_quiet()) return;
90 printf("TOTAL:\n");
91 printf(" %-30s%d\n", "number of files", total->filecount);
92 printf(" %-26s%d\n", GOODFILE, total->goodcount);
93 printf(" %-26s%d\n", BADFILE, total->filecount-total->goodcount);
94 printf(" %-30s%d:%02d:%02d\n", "time",
95 total->time/3600, (total->time/60)%60, total->time%60);
96 printf(" %-30s\n", "bitrate");
97 printf(" %-26s%d\n", "minimum", total->minbitrate);
98 printf(" %-26s%d\n", "average", total->totalbitrate/total->filecount);
99 printf(" %-26s%d\n", "maximum", total->maxbitrate);
100 printf("\n");
101 }
102
103 int
total_allgood(total)104 total_allgood(total)
105 const total_info * total;
106 {
107 return total->goodcount == total->filecount;
108 }
109
110 void
total_clear(total)111 total_clear(total)
112 total_info * total;
113 {
114 memset(total, 0, sizeof(total_info));
115 }
116