/[debian]/cdck/trunk/src/cdck_main.cpp
ViewVC logotype

Contents of /cdck/trunk/src/cdck_main.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 454 - (show annotations)
Fri Dec 8 05:47:10 2006 UTC (14 years, 9 months ago) by tmancill
File size: 2955 byte(s)
diffs for bug #402079
1 /*
2 * $RCSfile: cdck_main.cpp,v $
3 * $Author: swaj $
4 * $Revision: 1.5 $
5 */
6
7 #ifdef HAVE_CONFIG_H
8 #include "config.h"
9 #endif
10
11 #include <stdio.h>
12 #include <unistd.h>
13 #include <stdlib.h>
14 #include <string.h>
15
16 #include "defines.h"
17 #include "debugging.h"
18 #include "cdck_main.h"
19 #include "lib_main.h"
20
21
22 int main (int argc, char *argv[])
23 {
24 signed char ch;
25 char *program_name = (strchr(argv[0], '/') == NULL) ? argv[0] : (strrchr(argv[0], '/') + 1);
26
27 bool verbose = false;
28 bool only_info = false;
29 bool do_plot = false;
30 char devname[FILE_MAX];
31 char plotname[FILE_MAX];
32
33 memset (devname, 0x0, FILE_MAX);
34 memset (plotname, 0x0, FILE_MAX);
35
36 while ((ch = getopt(argc, argv, "?hivd:po:V"))!=-1) {
37 switch (ch) {
38 case 'h':
39 case '?':
40 print_help (program_name);
41 exit(0);
42 case 'V':
43 print_ver();
44 exit (0);
45 case 'v':
46 verbose = true;
47 break;
48 case 'i':
49 only_info = true;
50 break;
51 case 'p':
52 do_plot = true;
53 break;
54 case 'd':
55 strncpy (devname, optarg, FILE_MAX-1);
56 break;
57
58 case 'o':
59 strncpy (plotname, optarg, FILE_MAX-1);
60 break;
61
62 default:
63 break;
64 }
65
66 }
67
68 if (only_info)
69 verbose=true;
70
71 /* some debug info
72 printf ("verbose = %d\n", verbose);
73 printf ("only_info = %d\n", only_info);
74 printf ("do_plot = %d\n", do_plot );
75 printf ("devname = '%s'\n", devname);
76 printf ("plotname = '%s'\n", plotname);
77 */
78
79 Ccdrom *cdrom=0;
80
81 if (!strlen (devname))
82 cdrom = new Ccdrom ();
83 else
84 cdrom = new Ccdrom (devname);
85
86
87 unless (cdrom) {
88 fprintf (stderr, "Out of nemory\n");
89 exit (1);
90 }
91
92 cdrom->EnableInfo (verbose);
93
94 int rv = cdrom->ReadTOC();
95
96 if (rv) {
97 fprintf (stderr, "Unable to read TOC because %s\n", cdrom->Error() );
98 delete cdrom;
99 exit (1);
100 }
101
102 if (only_info)
103 exit (0);
104
105 rv = cdrom->ReadCD();
106 if (rv) {
107 fprintf (stderr, "Unable to read disc because %s\n", cdrom->Error() );
108 delete cdrom;
109 exit (1);
110 }
111
112 cdrom->AnalyzeResults();
113
114 if (do_plot) {
115 if (! strlen (plotname) )
116 rv = cdrom->OpenPlotFile();
117 else
118 rv = cdrom->OpenPlotFile (plotname);
119
120 if (rv) {
121 fprintf (stderr, "Unable to open plot data file\n");
122 delete cdrom;
123 exit (1);
124 }
125
126 cdrom->WritePlotData();
127 cdrom->ClosePlotFile();
128 }
129
130 delete cdrom;
131 exit (0);
132 }
133
134 static
135 void print_help (char *program_name)
136 {
137 printf ("Usage: %s [-d /dev/devname] [-i] [-v] [-p] [-o plot-file.dat]\n", program_name);
138 printf (" -d CD/DVD device name, default is /dev/cdrom\n");
139 printf (" -i Print CD/DVD information and quit, perform no timings\n");
140 printf (" -p Save data for gnuplot(1) program\n");
141 printf (" -o specify plot file, ./cdck-plot.dat is default\n");
142 printf (" -V Print version\n");
143 printf (" -v Verbose operations\n");
144 }
145
146 static
147 void print_ver (void)
148 {
149 printf ("Simple CD/DVD check program, ver %s. ", VERSION);
150 printf ("Written by Alexey Semenoff (c) 2005-2006.\n");
151 }
152
153
154
155 /*
156 * __END__
157 */

  ViewVC Help
Powered by ViewVC 1.1.26