comparison test/testcdrom.c @ 1668:4da1ee79c9af SDL-1.3

more tweaking indent options
author Sam Lantinga <slouken@libsdl.org>
date Mon, 29 May 2006 04:04:35 +0000
parents 782fd950bd46
children
comparison
equal deleted inserted replaced
1667:1fddae038bc8 1668:4da1ee79c9af
8 8
9 #include "SDL.h" 9 #include "SDL.h"
10 10
11 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ 11 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
12 static void 12 static void
13 quit (int rc) 13 quit(int rc)
14 { 14 {
15 SDL_Quit (); 15 SDL_Quit();
16 exit (rc); 16 exit(rc);
17 } 17 }
18 18
19 static void 19 static void
20 PrintStatus (int driveindex, SDL_CD * cdrom) 20 PrintStatus(int driveindex, SDL_CD * cdrom)
21 { 21 {
22 CDstatus status; 22 CDstatus status;
23 char *status_str; 23 char *status_str;
24 24
25 status = SDL_CDStatus (cdrom); 25 status = SDL_CDStatus(cdrom);
26 switch (status) { 26 switch (status) {
27 case CD_TRAYEMPTY: 27 case CD_TRAYEMPTY:
28 status_str = "tray empty"; 28 status_str = "tray empty";
29 break; 29 break;
30 case CD_STOPPED: 30 case CD_STOPPED:
38 break; 38 break;
39 case CD_ERROR: 39 case CD_ERROR:
40 status_str = "error state"; 40 status_str = "error state";
41 break; 41 break;
42 } 42 }
43 printf ("Drive %d status: %s\n", driveindex, status_str); 43 printf("Drive %d status: %s\n", driveindex, status_str);
44 if (status >= CD_PLAYING) { 44 if (status >= CD_PLAYING) {
45 int m, s, f; 45 int m, s, f;
46 FRAMES_TO_MSF (cdrom->cur_frame, &m, &s, &f); 46 FRAMES_TO_MSF(cdrom->cur_frame, &m, &s, &f);
47 printf ("Currently playing track %d, %d:%2.2d\n", 47 printf("Currently playing track %d, %d:%2.2d\n",
48 cdrom->track[cdrom->cur_track].id, m, s); 48 cdrom->track[cdrom->cur_track].id, m, s);
49 } 49 }
50 } 50 }
51 51
52 static void 52 static void
53 ListTracks (SDL_CD * cdrom) 53 ListTracks(SDL_CD * cdrom)
54 { 54 {
55 int i; 55 int i;
56 int m, s, f; 56 int m, s, f;
57 char *trtype; 57 char *trtype;
58 58
59 SDL_CDStatus (cdrom); 59 SDL_CDStatus(cdrom);
60 printf ("Drive tracks: %d\n", cdrom->numtracks); 60 printf("Drive tracks: %d\n", cdrom->numtracks);
61 for (i = 0; i < cdrom->numtracks; ++i) { 61 for (i = 0; i < cdrom->numtracks; ++i) {
62 FRAMES_TO_MSF (cdrom->track[i].length, &m, &s, &f); 62 FRAMES_TO_MSF(cdrom->track[i].length, &m, &s, &f);
63 if (f > 0) 63 if (f > 0)
64 ++s; 64 ++s;
65 switch (cdrom->track[i].type) { 65 switch (cdrom->track[i].type) {
66 case SDL_AUDIO_TRACK: 66 case SDL_AUDIO_TRACK:
67 trtype = "audio"; 67 trtype = "audio";
71 break; 71 break;
72 default: 72 default:
73 trtype = "unknown"; 73 trtype = "unknown";
74 break; 74 break;
75 } 75 }
76 printf ("\tTrack (index %d) %d: %d:%2.2d / %d [%s track]\n", i, 76 printf("\tTrack (index %d) %d: %d:%2.2d / %d [%s track]\n", i,
77 cdrom->track[i].id, m, s, cdrom->track[i].length, trtype); 77 cdrom->track[i].id, m, s, cdrom->track[i].length, trtype);
78 } 78 }
79 } 79 }
80 80
81 static void 81 static void
82 PrintUsage (char *argv0) 82 PrintUsage(char *argv0)
83 { 83 {
84 fprintf (stderr, "Usage: %s [drive#] [command] [command] ...\n", argv0); 84 fprintf(stderr, "Usage: %s [drive#] [command] [command] ...\n", argv0);
85 fprintf (stderr, "Where 'command' is one of:\n"); 85 fprintf(stderr, "Where 'command' is one of:\n");
86 fprintf (stderr, " -status\n"); 86 fprintf(stderr, " -status\n");
87 fprintf (stderr, " -list\n"); 87 fprintf(stderr, " -list\n");
88 fprintf (stderr, 88 fprintf(stderr,
89 " -play [first_track] [first_frame] [num_tracks] [num_frames]\n"); 89 " -play [first_track] [first_frame] [num_tracks] [num_frames]\n");
90 fprintf (stderr, " -pause\n"); 90 fprintf(stderr, " -pause\n");
91 fprintf (stderr, " -resume\n"); 91 fprintf(stderr, " -resume\n");
92 fprintf (stderr, " -stop\n"); 92 fprintf(stderr, " -stop\n");
93 fprintf (stderr, " -eject\n"); 93 fprintf(stderr, " -eject\n");
94 fprintf (stderr, " -sleep <milliseconds>\n"); 94 fprintf(stderr, " -sleep <milliseconds>\n");
95 } 95 }
96 96
97 int 97 int
98 main (int argc, char *argv[]) 98 main(int argc, char *argv[])
99 { 99 {
100 int drive; 100 int drive;
101 int i; 101 int i;
102 SDL_CD *cdrom; 102 SDL_CD *cdrom;
103 103
104 /* Initialize SDL first */ 104 /* Initialize SDL first */
105 if (SDL_Init (SDL_INIT_CDROM) < 0) { 105 if (SDL_Init(SDL_INIT_CDROM) < 0) {
106 fprintf (stderr, "Couldn't initialize SDL: %s\n", SDL_GetError ()); 106 fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
107 return (1); 107 return (1);
108 } 108 }
109 109
110 /* Find out how many CD-ROM drives are connected to the system */ 110 /* Find out how many CD-ROM drives are connected to the system */
111 if (SDL_CDNumDrives () == 0) { 111 if (SDL_CDNumDrives() == 0) {
112 printf ("No CD-ROM devices detected\n"); 112 printf("No CD-ROM devices detected\n");
113 quit (0); 113 quit(0);
114 } 114 }
115 printf ("Drives available: %d\n", SDL_CDNumDrives ()); 115 printf("Drives available: %d\n", SDL_CDNumDrives());
116 for (i = 0; i < SDL_CDNumDrives (); ++i) { 116 for (i = 0; i < SDL_CDNumDrives(); ++i) {
117 printf ("Drive %d: \"%s\"\n", i, SDL_CDName (i)); 117 printf("Drive %d: \"%s\"\n", i, SDL_CDName(i));
118 } 118 }
119 119
120 /* Open the CD-ROM */ 120 /* Open the CD-ROM */
121 drive = 0; 121 drive = 0;
122 i = 1; 122 i = 1;
123 if (argv[i] && isdigit (argv[i][0])) { 123 if (argv[i] && isdigit(argv[i][0])) {
124 drive = atoi (argv[i++]); 124 drive = atoi(argv[i++]);
125 } 125 }
126 cdrom = SDL_CDOpen (drive); 126 cdrom = SDL_CDOpen(drive);
127 if (cdrom == NULL) { 127 if (cdrom == NULL) {
128 fprintf (stderr, "Couldn't open drive %d: %s\n", drive, 128 fprintf(stderr, "Couldn't open drive %d: %s\n", drive,
129 SDL_GetError ()); 129 SDL_GetError());
130 quit (2); 130 quit(2);
131 } 131 }
132 #ifdef TEST_NULLCD 132 #ifdef TEST_NULLCD
133 cdrom = NULL; 133 cdrom = NULL;
134 #endif 134 #endif
135 135
136 /* Find out which function to perform */ 136 /* Find out which function to perform */
137 for (; argv[i]; ++i) { 137 for (; argv[i]; ++i) {
138 if (strcmp (argv[i], "-status") == 0) { 138 if (strcmp(argv[i], "-status") == 0) {
139 /* PrintStatus(drive, cdrom); */ 139 /* PrintStatus(drive, cdrom); */
140 } else if (strcmp (argv[i], "-list") == 0) { 140 } else if (strcmp(argv[i], "-list") == 0) {
141 ListTracks (cdrom); 141 ListTracks(cdrom);
142 } else if (strcmp (argv[i], "-play") == 0) { 142 } else if (strcmp(argv[i], "-play") == 0) {
143 int strack, sframe; 143 int strack, sframe;
144 int ntrack, nframe; 144 int ntrack, nframe;
145 145
146 strack = 0; 146 strack = 0;
147 if (argv[i + 1] && isdigit (argv[i + 1][0])) { 147 if (argv[i + 1] && isdigit(argv[i + 1][0])) {
148 strack = atoi (argv[++i]); 148 strack = atoi(argv[++i]);
149 } 149 }
150 sframe = 0; 150 sframe = 0;
151 if (argv[i + 1] && isdigit (argv[i + 1][0])) { 151 if (argv[i + 1] && isdigit(argv[i + 1][0])) {
152 sframe = atoi (argv[++i]); 152 sframe = atoi(argv[++i]);
153 } 153 }
154 ntrack = 0; 154 ntrack = 0;
155 if (argv[i + 1] && isdigit (argv[i + 1][0])) { 155 if (argv[i + 1] && isdigit(argv[i + 1][0])) {
156 ntrack = atoi (argv[++i]); 156 ntrack = atoi(argv[++i]);
157 } 157 }
158 nframe = 0; 158 nframe = 0;
159 if (argv[i + 1] && isdigit (argv[i + 1][0])) { 159 if (argv[i + 1] && isdigit(argv[i + 1][0])) {
160 nframe = atoi (argv[++i]); 160 nframe = atoi(argv[++i]);
161 } 161 }
162 if (CD_INDRIVE (SDL_CDStatus (cdrom))) { 162 if (CD_INDRIVE(SDL_CDStatus(cdrom))) {
163 if (SDL_CDPlayTracks (cdrom, strack, sframe, 163 if (SDL_CDPlayTracks(cdrom, strack, sframe,
164 ntrack, nframe) < 0) { 164 ntrack, nframe) < 0) {
165 fprintf (stderr, 165 fprintf(stderr,
166 "Couldn't play tracks %d/%d for %d/%d: %s\n", 166 "Couldn't play tracks %d/%d for %d/%d: %s\n",
167 strack, sframe, ntrack, nframe, SDL_GetError ()); 167 strack, sframe, ntrack, nframe, SDL_GetError());
168 } 168 }
169 } else { 169 } else {
170 fprintf (stderr, "No CD in drive!\n"); 170 fprintf(stderr, "No CD in drive!\n");
171 } 171 }
172 } else if (strcmp (argv[i], "-pause") == 0) { 172 } else if (strcmp(argv[i], "-pause") == 0) {
173 if (SDL_CDPause (cdrom) < 0) { 173 if (SDL_CDPause(cdrom) < 0) {
174 fprintf (stderr, "Couldn't pause CD: %s\n", SDL_GetError ()); 174 fprintf(stderr, "Couldn't pause CD: %s\n", SDL_GetError());
175 } 175 }
176 } else if (strcmp (argv[i], "-resume") == 0) { 176 } else if (strcmp(argv[i], "-resume") == 0) {
177 if (SDL_CDResume (cdrom) < 0) { 177 if (SDL_CDResume(cdrom) < 0) {
178 fprintf (stderr, "Couldn't resume CD: %s\n", SDL_GetError ()); 178 fprintf(stderr, "Couldn't resume CD: %s\n", SDL_GetError());
179 } 179 }
180 } else if (strcmp (argv[i], "-stop") == 0) { 180 } else if (strcmp(argv[i], "-stop") == 0) {
181 if (SDL_CDStop (cdrom) < 0) { 181 if (SDL_CDStop(cdrom) < 0) {
182 fprintf (stderr, "Couldn't eject CD: %s\n", SDL_GetError ()); 182 fprintf(stderr, "Couldn't eject CD: %s\n", SDL_GetError());
183 } 183 }
184 } else if (strcmp (argv[i], "-eject") == 0) { 184 } else if (strcmp(argv[i], "-eject") == 0) {
185 if (SDL_CDEject (cdrom) < 0) { 185 if (SDL_CDEject(cdrom) < 0) {
186 fprintf (stderr, "Couldn't eject CD: %s\n", SDL_GetError ()); 186 fprintf(stderr, "Couldn't eject CD: %s\n", SDL_GetError());
187 } 187 }
188 } else if ((strcmp (argv[i], "-sleep") == 0) && 188 } else if ((strcmp(argv[i], "-sleep") == 0) &&
189 (argv[i + 1] && isdigit (argv[i + 1][0]))) { 189 (argv[i + 1] && isdigit(argv[i + 1][0]))) {
190 SDL_Delay (atoi (argv[++i])); 190 SDL_Delay(atoi(argv[++i]));
191 printf ("Delayed %d milliseconds\n", atoi (argv[i])); 191 printf("Delayed %d milliseconds\n", atoi(argv[i]));
192 } else { 192 } else {
193 PrintUsage (argv[0]); 193 PrintUsage(argv[0]);
194 SDL_CDClose (cdrom); 194 SDL_CDClose(cdrom);
195 quit (1); 195 quit(1);
196 } 196 }
197 } 197 }
198 PrintStatus (drive, cdrom); 198 PrintStatus(drive, cdrom);
199 SDL_CDClose (cdrom); 199 SDL_CDClose(cdrom);
200 SDL_Quit (); 200 SDL_Quit();
201 201
202 return (0); 202 return (0);
203 } 203 }