annotate Modules/cdmodule.c @ 4566:6403c94de50d legacy-trunk

Added safeguard against failure in __del__.
author Guido van Rossum <guido@python.org>
date Wed, 27 Nov 1996 19:39:58 +0000
parents 65d2d8e67da3
children d36250aefb82
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 /**********************************************************
2061
172ba04a5191 Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
172ba04a5191 Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
3 The Netherlands.
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
4
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
5 All Rights Reserved
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
6
4503
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2603
diff changeset
7 Permission to use, copy, modify, and distribute this software and its
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2603
diff changeset
8 documentation for any purpose and without fee is hereby granted,
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 provided that the above copyright notice appear in all copies and that
4503
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2603
diff changeset
10 both that copyright notice and this permission notice appear in
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 supporting documentation, and that the names of Stichting Mathematisch
4503
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2603
diff changeset
12 Centrum or CWI or Corporation for National Research Initiatives or
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2603
diff changeset
13 CNRI not be used in advertising or publicity pertaining to
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2603
diff changeset
14 distribution of the software without specific, written prior
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2603
diff changeset
15 permission.
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
16
4503
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2603
diff changeset
17 While CWI is the initial source for this software, a modified version
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2603
diff changeset
18 is made available by the Corporation for National Research Initiatives
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2603
diff changeset
19 (CNRI) at the Internet address ftp://ftp.python.org.
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2603
diff changeset
20
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2603
diff changeset
21 STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2603
diff changeset
22 REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2603
diff changeset
23 MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2603
diff changeset
24 CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2603
diff changeset
25 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2603
diff changeset
26 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2603
diff changeset
27 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2603
diff changeset
28 PERFORMANCE OF THIS SOFTWARE.
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
29
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
30 ******************************************************************/
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
31
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
32 /* CD module -- interface to Mark Callow's and Roger Chickering's */
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
33 /* CD Audio Library (CD). */
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
34
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
35 #include <sys/types.h>
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
36 #include <cdaudio.h>
2603
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
37 /* #include <sigfpe.h> */
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
38 #include "allobjects.h"
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
39 #include "import.h"
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
40 #include "modsupport.h"
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
41 #include "ceval.h"
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
42
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
43 #define NCALLBACKS 8
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
44
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
45 typedef struct {
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
46 OB_HEAD
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
47 CDPLAYER *ob_cdplayer;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
48 } cdplayerobject;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
49
1063
aaa3bccb143a Defined exception cd.error which is used for errors other than
Sjoerd Mullender <sjoerd@acm.org>
parents: 926
diff changeset
50 static object *CdError; /* exception cd.error */
aaa3bccb143a Defined exception cd.error which is used for errors other than
Sjoerd Mullender <sjoerd@acm.org>
parents: 926
diff changeset
51
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
52 static object *
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
53 CD_allowremoval(self, args)
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
54 cdplayerobject *self;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
55 object *args;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
56 {
2603
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
57 if (!newgetargs(args, ""))
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
58 return NULL;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
59
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
60 CDallowremoval(self->ob_cdplayer);
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
61
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
62 INCREF(None);
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
63 return None;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
64 }
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
65
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
66 static object *
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
67 CD_preventremoval(self, args)
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
68 cdplayerobject *self;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
69 object *args;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
70 {
2603
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
71 if (!newgetargs(args, ""))
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
72 return NULL;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
73
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
74 CDpreventremoval(self->ob_cdplayer);
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
75
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
76 INCREF(None);
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
77 return None;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
78 }
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
79
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
80 static object *
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
81 CD_bestreadsize(self, args)
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
82 cdplayerobject *self;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
83 object *args;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
84 {
2603
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
85 if (!newgetargs(args, ""))
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
86 return NULL;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
87
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
88 return newintobject((long) CDbestreadsize(self->ob_cdplayer));
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
89 }
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
90
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
91 static object *
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
92 CD_close(self, args)
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
93 cdplayerobject *self;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
94 object *args;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
95 {
2603
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
96 if (!newgetargs(args, ""))
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
97 return NULL;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
98
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
99 if (!CDclose(self->ob_cdplayer)) {
1063
aaa3bccb143a Defined exception cd.error which is used for errors other than
Sjoerd Mullender <sjoerd@acm.org>
parents: 926
diff changeset
100 err_errno(CdError); /* XXX - ??? */
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
101 return NULL;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
102 }
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
103 self->ob_cdplayer = NULL;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
104
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
105 INCREF(None);
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
106 return None;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
107 }
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
108
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
109 static object *
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
110 CD_eject(self, args)
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
111 cdplayerobject *self;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
112 object *args;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
113 {
849
fe6a5f2640a2 Wanneer er geen disk in de speler zit falen sommige routines. De
Guido van Rossum <guido@python.org>
parents: 848
diff changeset
114 CDSTATUS status;
fe6a5f2640a2 Wanneer er geen disk in de speler zit falen sommige routines. De
Guido van Rossum <guido@python.org>
parents: 848
diff changeset
115
2603
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
116 if (!newgetargs(args, ""))
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
117 return NULL;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
118
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
119 if (!CDeject(self->ob_cdplayer)) {
849
fe6a5f2640a2 Wanneer er geen disk in de speler zit falen sommige routines. De
Guido van Rossum <guido@python.org>
parents: 848
diff changeset
120 if (CDgetstatus(self->ob_cdplayer, &status) &&
fe6a5f2640a2 Wanneer er geen disk in de speler zit falen sommige routines. De
Guido van Rossum <guido@python.org>
parents: 848
diff changeset
121 status.state == CD_NODISC)
1063
aaa3bccb143a Defined exception cd.error which is used for errors other than
Sjoerd Mullender <sjoerd@acm.org>
parents: 926
diff changeset
122 err_setstr(CdError, "no disc in player");
849
fe6a5f2640a2 Wanneer er geen disk in de speler zit falen sommige routines. De
Guido van Rossum <guido@python.org>
parents: 848
diff changeset
123 else
1063
aaa3bccb143a Defined exception cd.error which is used for errors other than
Sjoerd Mullender <sjoerd@acm.org>
parents: 926
diff changeset
124 err_setstr(CdError, "eject failed");
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
125 return NULL;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
126 }
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
127
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
128 INCREF(None);
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
129 return None;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
130 }
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
131
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
132 static object *
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
133 CD_getstatus(self, args)
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
134 cdplayerobject *self;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
135 object *args;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
136 {
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
137 CDSTATUS status;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
138
2603
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
139 if (!newgetargs(args, ""))
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
140 return NULL;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
141
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
142 if (!CDgetstatus(self->ob_cdplayer, &status)) {
1063
aaa3bccb143a Defined exception cd.error which is used for errors other than
Sjoerd Mullender <sjoerd@acm.org>
parents: 926
diff changeset
143 err_errno(CdError); /* XXX - ??? */
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
144 return NULL;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
145 }
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
146
2603
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
147 return mkvalue("(ii(iii)(iii)(iii)iiii)", status.state,
830
ea5072de7427 Return more structured data in some cases
Guido van Rossum <guido@python.org>
parents: 820
diff changeset
148 status.track, status.min, status.sec, status.frame,
ea5072de7427 Return more structured data in some cases
Guido van Rossum <guido@python.org>
parents: 820
diff changeset
149 status.abs_min, status.abs_sec, status.abs_frame,
ea5072de7427 Return more structured data in some cases
Guido van Rossum <guido@python.org>
parents: 820
diff changeset
150 status.total_min, status.total_sec, status.total_frame,
ea5072de7427 Return more structured data in some cases
Guido van Rossum <guido@python.org>
parents: 820
diff changeset
151 status.first, status.last, status.scsi_audio,
2603
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
152 status.cur_block);
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
153 }
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
154
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
155 static object *
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
156 CD_gettrackinfo(self, args)
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
157 cdplayerobject *self;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
158 object *args;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
159 {
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
160 int track;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
161 CDTRACKINFO info;
849
fe6a5f2640a2 Wanneer er geen disk in de speler zit falen sommige routines. De
Guido van Rossum <guido@python.org>
parents: 848
diff changeset
162 CDSTATUS status;
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
163
2603
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
164 if (!newgetargs(args, "i", &track))
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
165 return NULL;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
166
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
167 if (!CDgettrackinfo(self->ob_cdplayer, track, &info)) {
849
fe6a5f2640a2 Wanneer er geen disk in de speler zit falen sommige routines. De
Guido van Rossum <guido@python.org>
parents: 848
diff changeset
168 if (CDgetstatus(self->ob_cdplayer, &status) &&
fe6a5f2640a2 Wanneer er geen disk in de speler zit falen sommige routines. De
Guido van Rossum <guido@python.org>
parents: 848
diff changeset
169 status.state == CD_NODISC)
1063
aaa3bccb143a Defined exception cd.error which is used for errors other than
Sjoerd Mullender <sjoerd@acm.org>
parents: 926
diff changeset
170 err_setstr(CdError, "no disc in player");
849
fe6a5f2640a2 Wanneer er geen disk in de speler zit falen sommige routines. De
Guido van Rossum <guido@python.org>
parents: 848
diff changeset
171 else
1063
aaa3bccb143a Defined exception cd.error which is used for errors other than
Sjoerd Mullender <sjoerd@acm.org>
parents: 926
diff changeset
172 err_setstr(CdError, "gettrackinfo failed");
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
173 return NULL;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
174 }
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
175
830
ea5072de7427 Return more structured data in some cases
Guido van Rossum <guido@python.org>
parents: 820
diff changeset
176 return mkvalue("((iii)(iii))",
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
177 info.start_min, info.start_sec, info.start_frame,
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
178 info.total_min, info.total_sec, info.total_frame);
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
179 }
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
180
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
181 static object *
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
182 CD_msftoblock(self, args)
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
183 cdplayerobject *self;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
184 object *args;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
185 {
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
186 int min, sec, frame;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
187
2603
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
188 if (!newgetargs(args, "iii", &min, &sec, &frame))
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
189 return NULL;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
190
2603
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
191 return newintobject((long) CDmsftoblock(self->ob_cdplayer,
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
192 min, sec, frame));
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
193 }
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
194
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
195 static object *
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
196 CD_play(self, args)
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
197 cdplayerobject *self;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
198 object *args;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
199 {
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
200 int start, play;
849
fe6a5f2640a2 Wanneer er geen disk in de speler zit falen sommige routines. De
Guido van Rossum <guido@python.org>
parents: 848
diff changeset
201 CDSTATUS status;
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
202
2603
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
203 if (!newgetargs(args, "ii", &start, &play))
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
204 return NULL;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
205
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
206 if (!CDplay(self->ob_cdplayer, start, play)) {
849
fe6a5f2640a2 Wanneer er geen disk in de speler zit falen sommige routines. De
Guido van Rossum <guido@python.org>
parents: 848
diff changeset
207 if (CDgetstatus(self->ob_cdplayer, &status) &&
fe6a5f2640a2 Wanneer er geen disk in de speler zit falen sommige routines. De
Guido van Rossum <guido@python.org>
parents: 848
diff changeset
208 status.state == CD_NODISC)
1063
aaa3bccb143a Defined exception cd.error which is used for errors other than
Sjoerd Mullender <sjoerd@acm.org>
parents: 926
diff changeset
209 err_setstr(CdError, "no disc in player");
849
fe6a5f2640a2 Wanneer er geen disk in de speler zit falen sommige routines. De
Guido van Rossum <guido@python.org>
parents: 848
diff changeset
210 else
1063
aaa3bccb143a Defined exception cd.error which is used for errors other than
Sjoerd Mullender <sjoerd@acm.org>
parents: 926
diff changeset
211 err_setstr(CdError, "play failed");
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
212 return NULL;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
213 }
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
214
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
215 INCREF(None);
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
216 return None;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
217 }
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
218
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
219 static object *
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
220 CD_playabs(self, args)
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
221 cdplayerobject *self;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
222 object *args;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
223 {
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
224 int min, sec, frame, play;
849
fe6a5f2640a2 Wanneer er geen disk in de speler zit falen sommige routines. De
Guido van Rossum <guido@python.org>
parents: 848
diff changeset
225 CDSTATUS status;
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
226
2603
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
227 if (!newgetargs(args, "iiii", &min, &sec, &frame, &play))
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
228 return NULL;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
229
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
230 if (!CDplayabs(self->ob_cdplayer, min, sec, frame, play)) {
849
fe6a5f2640a2 Wanneer er geen disk in de speler zit falen sommige routines. De
Guido van Rossum <guido@python.org>
parents: 848
diff changeset
231 if (CDgetstatus(self->ob_cdplayer, &status) &&
fe6a5f2640a2 Wanneer er geen disk in de speler zit falen sommige routines. De
Guido van Rossum <guido@python.org>
parents: 848
diff changeset
232 status.state == CD_NODISC)
1063
aaa3bccb143a Defined exception cd.error which is used for errors other than
Sjoerd Mullender <sjoerd@acm.org>
parents: 926
diff changeset
233 err_setstr(CdError, "no disc in player");
849
fe6a5f2640a2 Wanneer er geen disk in de speler zit falen sommige routines. De
Guido van Rossum <guido@python.org>
parents: 848
diff changeset
234 else
1063
aaa3bccb143a Defined exception cd.error which is used for errors other than
Sjoerd Mullender <sjoerd@acm.org>
parents: 926
diff changeset
235 err_setstr(CdError, "playabs failed");
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
236 return NULL;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
237 }
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
238
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
239 INCREF(None);
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
240 return None;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
241 }
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
242
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
243 static object *
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
244 CD_playtrack(self, args)
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
245 cdplayerobject *self;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
246 object *args;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
247 {
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
248 int start, play;
849
fe6a5f2640a2 Wanneer er geen disk in de speler zit falen sommige routines. De
Guido van Rossum <guido@python.org>
parents: 848
diff changeset
249 CDSTATUS status;
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
250
2603
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
251 if (!newgetargs(args, "ii", &start, &play))
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
252 return NULL;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
253
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
254 if (!CDplaytrack(self->ob_cdplayer, start, play)) {
849
fe6a5f2640a2 Wanneer er geen disk in de speler zit falen sommige routines. De
Guido van Rossum <guido@python.org>
parents: 848
diff changeset
255 if (CDgetstatus(self->ob_cdplayer, &status) &&
fe6a5f2640a2 Wanneer er geen disk in de speler zit falen sommige routines. De
Guido van Rossum <guido@python.org>
parents: 848
diff changeset
256 status.state == CD_NODISC)
1063
aaa3bccb143a Defined exception cd.error which is used for errors other than
Sjoerd Mullender <sjoerd@acm.org>
parents: 926
diff changeset
257 err_setstr(CdError, "no disc in player");
849
fe6a5f2640a2 Wanneer er geen disk in de speler zit falen sommige routines. De
Guido van Rossum <guido@python.org>
parents: 848
diff changeset
258 else
1063
aaa3bccb143a Defined exception cd.error which is used for errors other than
Sjoerd Mullender <sjoerd@acm.org>
parents: 926
diff changeset
259 err_setstr(CdError, "playtrack failed");
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
260 return NULL;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
261 }
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
262
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
263 INCREF(None);
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
264 return None;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
265 }
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
266
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
267 static object *
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
268 CD_playtrackabs(self, args)
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
269 cdplayerobject *self;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
270 object *args;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
271 {
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
272 int track, min, sec, frame, play;
849
fe6a5f2640a2 Wanneer er geen disk in de speler zit falen sommige routines. De
Guido van Rossum <guido@python.org>
parents: 848
diff changeset
273 CDSTATUS status;
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
274
2603
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
275 if (!newgetargs(args, "iiiii", &track, &min, &sec, &frame, &play))
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
276 return NULL;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
277
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
278 if (!CDplaytrackabs(self->ob_cdplayer, track, min, sec, frame, play)) {
849
fe6a5f2640a2 Wanneer er geen disk in de speler zit falen sommige routines. De
Guido van Rossum <guido@python.org>
parents: 848
diff changeset
279 if (CDgetstatus(self->ob_cdplayer, &status) &&
fe6a5f2640a2 Wanneer er geen disk in de speler zit falen sommige routines. De
Guido van Rossum <guido@python.org>
parents: 848
diff changeset
280 status.state == CD_NODISC)
1063
aaa3bccb143a Defined exception cd.error which is used for errors other than
Sjoerd Mullender <sjoerd@acm.org>
parents: 926
diff changeset
281 err_setstr(CdError, "no disc in player");
849
fe6a5f2640a2 Wanneer er geen disk in de speler zit falen sommige routines. De
Guido van Rossum <guido@python.org>
parents: 848
diff changeset
282 else
1063
aaa3bccb143a Defined exception cd.error which is used for errors other than
Sjoerd Mullender <sjoerd@acm.org>
parents: 926
diff changeset
283 err_setstr(CdError, "playtrackabs failed");
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
284 return NULL;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
285 }
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
286
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
287 INCREF(None);
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
288 return None;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
289 }
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
290
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
291 static object *
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
292 CD_readda(self, args)
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
293 cdplayerobject *self;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
294 object *args;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
295 {
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
296 int numframes, n;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
297 object *result;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
298
2603
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
299 if (!newgetargs(args, "i", &numframes))
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
300 return NULL;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
301
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
302 result = newsizedstringobject(NULL, numframes * sizeof(CDFRAME));
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
303 if (result == NULL)
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
304 return NULL;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
305
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
306 n = CDreadda(self->ob_cdplayer, (CDFRAME *) getstringvalue(result), numframes);
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
307 if (n == -1) {
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
308 DECREF(result);
1063
aaa3bccb143a Defined exception cd.error which is used for errors other than
Sjoerd Mullender <sjoerd@acm.org>
parents: 926
diff changeset
309 err_errno(CdError);
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
310 return NULL;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
311 }
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
312 if (n < numframes)
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
313 if (resizestring(&result, n * sizeof(CDFRAME)))
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
314 return NULL;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
315
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
316 return result;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
317 }
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
318
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
319 static object *
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
320 CD_seek(self, args)
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
321 cdplayerobject *self;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
322 object *args;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
323 {
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
324 int min, sec, frame;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
325 long block;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
326
2603
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
327 if (!newgetargs(args, "iii", &min, &sec, &frame))
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
328 return NULL;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
329
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
330 block = CDseek(self->ob_cdplayer, min, sec, frame);
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
331 if (block == -1) {
1063
aaa3bccb143a Defined exception cd.error which is used for errors other than
Sjoerd Mullender <sjoerd@acm.org>
parents: 926
diff changeset
332 err_errno(CdError);
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
333 return NULL;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
334 }
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
335
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
336 return newintobject(block);
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
337 }
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
338
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
339 static object *
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
340 CD_seektrack(self, args)
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
341 cdplayerobject *self;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
342 object *args;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
343 {
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
344 int track;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
345 long block;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
346
2603
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
347 if (!newgetargs(args, "i", &track))
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
348 return NULL;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
349
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
350 block = CDseektrack(self->ob_cdplayer, track);
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
351 if (block == -1) {
1063
aaa3bccb143a Defined exception cd.error which is used for errors other than
Sjoerd Mullender <sjoerd@acm.org>
parents: 926
diff changeset
352 err_errno(CdError);
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
353 return NULL;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
354 }
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
355
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
356 return newintobject(block);
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
357 }
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
358
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
359 static object *
2603
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
360 CD_seekblock(self, args)
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
361 cdplayerobject *self;
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
362 object *args;
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
363 {
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
364 unsigned long block;
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
365
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
366 if (!newgetargs(args, "l", &block))
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
367 return NULL;
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
368
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
369 block = CDseekblock(self->ob_cdplayer, block);
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
370 if (block == (unsigned long) -1) {
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
371 err_errno(CdError);
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
372 return NULL;
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
373 }
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
374
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
375 return newintobject(block);
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
376 }
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
377
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
378 static object *
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
379 CD_stop(self, args)
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
380 cdplayerobject *self;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
381 object *args;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
382 {
849
fe6a5f2640a2 Wanneer er geen disk in de speler zit falen sommige routines. De
Guido van Rossum <guido@python.org>
parents: 848
diff changeset
383 CDSTATUS status;
fe6a5f2640a2 Wanneer er geen disk in de speler zit falen sommige routines. De
Guido van Rossum <guido@python.org>
parents: 848
diff changeset
384
2603
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
385 if (!newgetargs(args, ""))
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
386 return NULL;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
387
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
388 if (!CDstop(self->ob_cdplayer)) {
849
fe6a5f2640a2 Wanneer er geen disk in de speler zit falen sommige routines. De
Guido van Rossum <guido@python.org>
parents: 848
diff changeset
389 if (CDgetstatus(self->ob_cdplayer, &status) &&
fe6a5f2640a2 Wanneer er geen disk in de speler zit falen sommige routines. De
Guido van Rossum <guido@python.org>
parents: 848
diff changeset
390 status.state == CD_NODISC)
1063
aaa3bccb143a Defined exception cd.error which is used for errors other than
Sjoerd Mullender <sjoerd@acm.org>
parents: 926
diff changeset
391 err_setstr(CdError, "no disc in player");
849
fe6a5f2640a2 Wanneer er geen disk in de speler zit falen sommige routines. De
Guido van Rossum <guido@python.org>
parents: 848
diff changeset
392 else
1063
aaa3bccb143a Defined exception cd.error which is used for errors other than
Sjoerd Mullender <sjoerd@acm.org>
parents: 926
diff changeset
393 err_setstr(CdError, "stop failed");
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
394 return NULL;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
395 }
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
396
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
397 INCREF(None);
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
398 return None;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
399 }
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
400
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
401 static object *
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
402 CD_togglepause(self, args)
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
403 cdplayerobject *self;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
404 object *args;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
405 {
849
fe6a5f2640a2 Wanneer er geen disk in de speler zit falen sommige routines. De
Guido van Rossum <guido@python.org>
parents: 848
diff changeset
406 CDSTATUS status;
fe6a5f2640a2 Wanneer er geen disk in de speler zit falen sommige routines. De
Guido van Rossum <guido@python.org>
parents: 848
diff changeset
407
2603
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
408 if (!newgetargs(args, ""))
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
409 return NULL;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
410
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
411 if (!CDtogglepause(self->ob_cdplayer)) {
849
fe6a5f2640a2 Wanneer er geen disk in de speler zit falen sommige routines. De
Guido van Rossum <guido@python.org>
parents: 848
diff changeset
412 if (CDgetstatus(self->ob_cdplayer, &status) &&
fe6a5f2640a2 Wanneer er geen disk in de speler zit falen sommige routines. De
Guido van Rossum <guido@python.org>
parents: 848
diff changeset
413 status.state == CD_NODISC)
1063
aaa3bccb143a Defined exception cd.error which is used for errors other than
Sjoerd Mullender <sjoerd@acm.org>
parents: 926
diff changeset
414 err_setstr(CdError, "no disc in player");
849
fe6a5f2640a2 Wanneer er geen disk in de speler zit falen sommige routines. De
Guido van Rossum <guido@python.org>
parents: 848
diff changeset
415 else
1063
aaa3bccb143a Defined exception cd.error which is used for errors other than
Sjoerd Mullender <sjoerd@acm.org>
parents: 926
diff changeset
416 err_setstr(CdError, "togglepause failed");
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
417 return NULL;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
418 }
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
419
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
420 INCREF(None);
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
421 return None;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
422 }
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
423
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
424 static struct methodlist cdplayer_methods[] = {
2603
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
425 {"allowremoval", (method)CD_allowremoval, 1},
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
426 {"bestreadsize", (method)CD_bestreadsize, 1},
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
427 {"close", (method)CD_close, 1},
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
428 {"eject", (method)CD_eject, 1},
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
429 {"getstatus", (method)CD_getstatus, 1},
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
430 {"gettrackinfo", (method)CD_gettrackinfo, 1},
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
431 {"msftoblock", (method)CD_msftoblock, 1},
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
432 {"play", (method)CD_play, 1},
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
433 {"playabs", (method)CD_playabs, 1},
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
434 {"playtrack", (method)CD_playtrack, 1},
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
435 {"playtrackabs", (method)CD_playtrackabs, 1},
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
436 {"preventremoval", (method)CD_preventremoval, 1},
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
437 {"readda", (method)CD_readda, 1},
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
438 {"seek", (method)CD_seek, 1},
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
439 {"seekblock", (method)CD_seekblock, 1},
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
440 {"seektrack", (method)CD_seektrack, 1},
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
441 {"stop", (method)CD_stop, 1},
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
442 {"togglepause", (method)CD_togglepause, 1},
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
443 {NULL, NULL} /* sentinel */
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
444 };
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
445
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
446 static void
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
447 cdplayer_dealloc(self)
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
448 cdplayerobject *self;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
449 {
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
450 if (self->ob_cdplayer != NULL)
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
451 CDclose(self->ob_cdplayer);
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
452 DEL(self);
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
453 }
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
454
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
455 static object *
2603
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
456 cdplayer_getattr(self, name)
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
457 cdplayerobject *self;
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
458 char *name;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
459 {
2603
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
460 if (self->ob_cdplayer == NULL) {
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
461 err_setstr(RuntimeError, "no player active");
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
462 return NULL;
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
463 }
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
464 return findmethod(cdplayer_methods, (object *)self, name);
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
465 }
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
466
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
467 typeobject CdPlayertype = {
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
468 OB_HEAD_INIT(&Typetype)
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
469 0, /*ob_size*/
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
470 "cdplayer", /*tp_name*/
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
471 sizeof(cdplayerobject), /*tp_size*/
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
472 0, /*tp_itemsize*/
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
473 /* methods */
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1313
diff changeset
474 (destructor)cdplayer_dealloc, /*tp_dealloc*/
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
475 0, /*tp_print*/
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1313
diff changeset
476 (getattrfunc)cdplayer_getattr, /*tp_getattr*/
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
477 0, /*tp_setattr*/
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
478 0, /*tp_compare*/
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
479 0, /*tp_repr*/
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
480 };
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
481
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
482 static object *
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
483 newcdplayerobject(cdp)
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
484 CDPLAYER *cdp;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
485 {
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
486 cdplayerobject *p;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
487
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
488 p = NEWOBJ(cdplayerobject, &CdPlayertype);
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
489 if (p == NULL)
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
490 return NULL;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
491 p->ob_cdplayer = cdp;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
492 return (object *) p;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
493 }
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
494
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
495 static object *
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
496 CD_open(self, args)
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
497 object *self, *args;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
498 {
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
499 char *dev, *direction;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
500 CDPLAYER *cdp;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
501
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
502 /*
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
503 * Variable number of args.
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
504 * First defaults to "None", second defaults to "r".
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
505 */
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
506 dev = NULL;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
507 direction = "r";
2603
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
508 if (!newgetargs(args, "|zs", &dev, &direction))
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
509 return NULL;
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
510
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
511 cdp = CDopen(dev, direction);
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
512 if (cdp == NULL) {
1063
aaa3bccb143a Defined exception cd.error which is used for errors other than
Sjoerd Mullender <sjoerd@acm.org>
parents: 926
diff changeset
513 err_errno(CdError);
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
514 return NULL;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
515 }
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
516
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
517 return newcdplayerobject(cdp);
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
518 }
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
519
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
520 typedef struct {
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
521 OB_HEAD
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
522 CDPARSER *ob_cdparser;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
523 struct {
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
524 object *ob_cdcallback;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
525 object *ob_cdcallbackarg;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
526 } ob_cdcallbacks[NCALLBACKS];
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
527 } cdparserobject;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
528
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
529 static void
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
530 CD_callback(arg, type, data)
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
531 void *arg;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
532 CDDATATYPES type;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
533 void *data;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
534 {
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
535 object *result, *args, *v;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
536 char *p;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
537 int i;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
538 cdparserobject *self;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
539
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
540 self = (cdparserobject *) arg;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
541 args = newtupleobject(3);
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
542 if (args == NULL)
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
543 return;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
544 INCREF(self->ob_cdcallbacks[type].ob_cdcallbackarg);
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
545 settupleitem(args, 0, self->ob_cdcallbacks[type].ob_cdcallbackarg);
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
546 settupleitem(args, 1, newintobject((long) type));
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
547 switch (type) {
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
548 case cd_audio:
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
549 v = newsizedstringobject(data, CDDA_DATASIZE);
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
550 break;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
551 case cd_pnum:
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
552 case cd_index:
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
553 v = newintobject(((CDPROGNUM *) data)->value);
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
554 break;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
555 case cd_ptime:
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
556 case cd_atime:
830
ea5072de7427 Return more structured data in some cases
Guido van Rossum <guido@python.org>
parents: 820
diff changeset
557 #define ptr ((struct cdtimecode *) data)
2603
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
558 v = mkvalue("(iii)",
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
559 ptr->mhi * 10 + ptr->mlo,
830
ea5072de7427 Return more structured data in some cases
Guido van Rossum <guido@python.org>
parents: 820
diff changeset
560 ptr->shi * 10 + ptr->slo,
ea5072de7427 Return more structured data in some cases
Guido van Rossum <guido@python.org>
parents: 820
diff changeset
561 ptr->fhi * 10 + ptr->flo);
ea5072de7427 Return more structured data in some cases
Guido van Rossum <guido@python.org>
parents: 820
diff changeset
562 #undef ptr
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
563 break;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
564 case cd_catalog:
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
565 v = newsizedstringobject(NULL, 13);
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
566 p = getstringvalue(v);
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
567 for (i = 0; i < 13; i++)
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
568 *p++ = ((char *) data)[i] + '0';
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
569 break;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
570 case cd_ident:
2603
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
571 #define ptr ((struct cdident *) data)
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
572 v = newsizedstringobject(NULL, 12);
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
573 p = getstringvalue(v);
2603
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
574 CDsbtoa(p, ptr->country, 2);
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
575 p += 2;
2603
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
576 CDsbtoa(p, ptr->owner, 3);
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
577 p += 3;
2603
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
578 *p++ = ptr->year[0] + '0';
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
579 *p++ = ptr->year[1] + '0';
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
580 *p++ = ptr->serial[0] + '0';
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
581 *p++ = ptr->serial[1] + '0';
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
582 *p++ = ptr->serial[2] + '0';
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
583 *p++ = ptr->serial[3] + '0';
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
584 *p++ = ptr->serial[4] + '0';
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
585 #undef ptr
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
586 break;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
587 case cd_control:
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
588 v = newintobject((long) *((unchar *) data));
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
589 break;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
590 }
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
591 settupleitem(args, 2, v);
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
592 if (err_occurred()) {
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
593 DECREF(args);
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
594 return;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
595 }
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
596
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
597 result = call_object(self->ob_cdcallbacks[type].ob_cdcallback, args);
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
598 DECREF(args);
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
599 XDECREF(result);
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
600 }
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
601
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
602 static object *
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
603 CD_deleteparser(self, args)
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
604 cdparserobject *self;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
605 object *args;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
606 {
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
607 int i;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
608
2603
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
609 if (!newgetargs(args, ""))
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
610 return NULL;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
611
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
612 CDdeleteparser(self->ob_cdparser);
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
613 self->ob_cdparser = NULL;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
614
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
615 /* no sense in keeping the callbacks, so remove them */
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
616 for (i = 0; i < NCALLBACKS; i++) {
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
617 XDECREF(self->ob_cdcallbacks[i].ob_cdcallback);
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
618 self->ob_cdcallbacks[i].ob_cdcallback = NULL;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
619 XDECREF(self->ob_cdcallbacks[i].ob_cdcallbackarg);
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
620 self->ob_cdcallbacks[i].ob_cdcallbackarg = NULL;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
621 }
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
622
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
623 INCREF(None);
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
624 return None;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
625 }
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
626
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
627 static object *
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
628 CD_parseframe(self, args)
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
629 cdparserobject *self;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
630 object *args;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
631 {
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
632 char *cdfp;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
633 int length;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
634 CDFRAME *p;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
635
2603
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
636 if (!newgetargs(args, "s#", &cdfp, &length))
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
637 return NULL;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
638
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
639 if (length % sizeof(CDFRAME) != 0) {
1063
aaa3bccb143a Defined exception cd.error which is used for errors other than
Sjoerd Mullender <sjoerd@acm.org>
parents: 926
diff changeset
640 err_setstr(TypeError, "bad length");
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
641 return NULL;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
642 }
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
643
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
644 p = (CDFRAME *) cdfp;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
645 while (length > 0) {
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
646 CDparseframe(self->ob_cdparser, p);
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
647 length -= sizeof(CDFRAME);
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
648 p++;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
649 if (err_occurred())
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
650 return NULL;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
651 }
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
652
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
653 INCREF(None);
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
654 return None;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
655 }
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
656
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
657 static object *
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
658 CD_removecallback(self, args)
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
659 cdparserobject *self;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
660 object *args;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
661 {
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
662 int type;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
663
2603
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
664 if (!newgetargs(args, "i", &type))
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
665 return NULL;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
666
921
8078834996ec cdmodule.c: 2 minor changes by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 849
diff changeset
667 if (type < 0 || type >= NCALLBACKS) {
1063
aaa3bccb143a Defined exception cd.error which is used for errors other than
Sjoerd Mullender <sjoerd@acm.org>
parents: 926
diff changeset
668 err_setstr(TypeError, "bad type");
921
8078834996ec cdmodule.c: 2 minor changes by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 849
diff changeset
669 return NULL;
8078834996ec cdmodule.c: 2 minor changes by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 849
diff changeset
670 }
8078834996ec cdmodule.c: 2 minor changes by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 849
diff changeset
671
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
672 CDremovecallback(self->ob_cdparser, (CDDATATYPES) type);
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
673
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
674 XDECREF(self->ob_cdcallbacks[type].ob_cdcallback);
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
675 self->ob_cdcallbacks[type].ob_cdcallback = NULL;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
676
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
677 XDECREF(self->ob_cdcallbacks[type].ob_cdcallbackarg);
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
678 self->ob_cdcallbacks[type].ob_cdcallbackarg = NULL;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
679
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
680 INCREF(None);
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
681 return None;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
682 }
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
683
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
684 static object *
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
685 CD_resetparser(self, args)
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
686 cdparserobject *self;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
687 object *args;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
688 {
2603
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
689 if (!newgetargs(args, ""))
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
690 return NULL;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
691
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
692 CDresetparser(self->ob_cdparser);
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
693
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
694 INCREF(None);
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
695 return None;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
696 }
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
697
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
698 static object *
921
8078834996ec cdmodule.c: 2 minor changes by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 849
diff changeset
699 CD_addcallback(self, args)
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
700 cdparserobject *self;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
701 object *args;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
702 {
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
703 int type;
1313
6ee380349c84 * Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
704 object *func, *funcarg;
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
705
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
706 /* XXX - more work here */
2603
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
707 if (!newgetargs(args, "iOO", &type, &func, &funcarg))
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
708 return NULL;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
709
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
710 if (type < 0 || type >= NCALLBACKS) {
1063
aaa3bccb143a Defined exception cd.error which is used for errors other than
Sjoerd Mullender <sjoerd@acm.org>
parents: 926
diff changeset
711 err_setstr(TypeError, "argument out of range");
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
712 return NULL;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
713 }
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
714
1071
2291da05f178 Changed an ifdef from IRIX_405 to CDsetcallback.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1063
diff changeset
715 #ifdef CDsetcallback
921
8078834996ec cdmodule.c: 2 minor changes by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 849
diff changeset
716 CDaddcallback(self->ob_cdparser, (CDDATATYPES) type, CD_callback, (void *) self);
8078834996ec cdmodule.c: 2 minor changes by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 849
diff changeset
717 #else
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
718 CDsetcallback(self->ob_cdparser, (CDDATATYPES) type, CD_callback, (void *) self);
921
8078834996ec cdmodule.c: 2 minor changes by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 849
diff changeset
719 #endif
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
720 XDECREF(self->ob_cdcallbacks[type].ob_cdcallback);
1313
6ee380349c84 * Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
721 INCREF(func);
6ee380349c84 * Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
722 self->ob_cdcallbacks[type].ob_cdcallback = func;
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
723 XDECREF(self->ob_cdcallbacks[type].ob_cdcallbackarg);
1313
6ee380349c84 * Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
724 INCREF(funcarg);
6ee380349c84 * Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
725 self->ob_cdcallbacks[type].ob_cdcallbackarg = funcarg;
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
726
2603
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
727 /*
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
728 if (type == cd_audio) {
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
729 sigfpe_[_UNDERFL].repls = _ZERO;
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
730 handle_sigfpes(_ON, _EN_UNDERFL, NULL, _ABORT_ON_ERROR, NULL);
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
731 }
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
732 */
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
733
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
734 INCREF(None);
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
735 return None;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
736 }
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
737
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
738 static struct methodlist cdparser_methods[] = {
2603
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
739 {"addcallback", (method)CD_addcallback, 1},
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
740 {"deleteparser", (method)CD_deleteparser, 1},
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
741 {"parseframe", (method)CD_parseframe, 1},
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
742 {"removecallback", (method)CD_removecallback, 1},
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
743 {"resetparser", (method)CD_resetparser, 1},
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
744 {"setcallback", (method)CD_addcallback, 1}, /* backward compatibility */
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
745 {NULL, NULL} /* sentinel */
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
746 };
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
747
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
748 static void
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
749 cdparser_dealloc(self)
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
750 cdparserobject *self;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
751 {
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
752 int i;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
753
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
754 for (i = 0; i < NCALLBACKS; i++) {
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
755 XDECREF(self->ob_cdcallbacks[i].ob_cdcallback);
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
756 self->ob_cdcallbacks[i].ob_cdcallback = NULL;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
757 XDECREF(self->ob_cdcallbacks[i].ob_cdcallbackarg);
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
758 self->ob_cdcallbacks[i].ob_cdcallbackarg = NULL;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
759 }
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
760 CDdeleteparser(self->ob_cdparser);
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
761 DEL(self);
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
762 }
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
763
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
764 static object *
2603
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
765 cdparser_getattr(self, name)
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
766 cdparserobject *self;
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
767 char *name;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
768 {
2603
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
769 if (self->ob_cdparser == NULL) {
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
770 err_setstr(RuntimeError, "no parser active");
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
771 return NULL;
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
772 }
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
773
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
774 return findmethod(cdparser_methods, (object *)self, name);
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
775 }
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
776
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
777 typeobject CdParsertype = {
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
778 OB_HEAD_INIT(&Typetype)
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
779 0, /*ob_size*/
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
780 "cdparser", /*tp_name*/
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
781 sizeof(cdparserobject), /*tp_size*/
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
782 0, /*tp_itemsize*/
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
783 /* methods */
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1313
diff changeset
784 (destructor)cdparser_dealloc, /*tp_dealloc*/
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
785 0, /*tp_print*/
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1313
diff changeset
786 (getattrfunc)cdparser_getattr, /*tp_getattr*/
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
787 0, /*tp_setattr*/
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
788 0, /*tp_compare*/
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
789 0, /*tp_repr*/
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
790 };
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
791
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
792 static object *
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
793 newcdparserobject(cdp)
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
794 CDPARSER *cdp;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
795 {
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
796 cdparserobject *p;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
797 int i;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
798
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
799 p = NEWOBJ(cdparserobject, &CdParsertype);
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
800 if (p == NULL)
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
801 return NULL;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
802 p->ob_cdparser = cdp;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
803 for (i = 0; i < NCALLBACKS; i++) {
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
804 p->ob_cdcallbacks[i].ob_cdcallback = NULL;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
805 p->ob_cdcallbacks[i].ob_cdcallbackarg = NULL;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
806 }
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
807 return (object *) p;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
808 }
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
809
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
810 static object *
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
811 CD_createparser(self, args)
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
812 object *self, *args;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
813 {
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
814 CDPARSER *cdp;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
815
2603
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
816 if (!newgetargs(args, ""))
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
817 return NULL;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
818 cdp = CDcreateparser();
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
819 if (cdp == NULL) {
1063
aaa3bccb143a Defined exception cd.error which is used for errors other than
Sjoerd Mullender <sjoerd@acm.org>
parents: 926
diff changeset
820 err_setstr(CdError, "createparser failed");
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
821 return NULL;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
822 }
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
823
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
824 return newcdparserobject(cdp);
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
825 }
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
826
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
827 static object *
2603
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
828 CD_msftoframe(self, args)
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
829 object *self, *args;
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
830 {
2603
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
831 int min, sec, frame;
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
832
2603
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
833 if (!newgetargs(args, "iii", &min, &sec, &frame))
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
834 return NULL;
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
835
2603
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
836 return newintobject((long) CDmsftoframe(min, sec, frame));
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
837 }
2603
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
838
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
839 static struct methodlist CD_methods[] = {
2603
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
840 {"open", (method)CD_open, 1},
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
841 {"createparser", (method)CD_createparser, 1},
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
842 {"msftoframe", (method)CD_msftoframe, 1},
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
843 {NULL, NULL} /* Sentinel */
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
844 };
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
845
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
846 void
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
847 initcd()
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
848 {
1063
aaa3bccb143a Defined exception cd.error which is used for errors other than
Sjoerd Mullender <sjoerd@acm.org>
parents: 926
diff changeset
849 object *m, *d;
aaa3bccb143a Defined exception cd.error which is used for errors other than
Sjoerd Mullender <sjoerd@acm.org>
parents: 926
diff changeset
850
aaa3bccb143a Defined exception cd.error which is used for errors other than
Sjoerd Mullender <sjoerd@acm.org>
parents: 926
diff changeset
851 m = initmodule("cd", CD_methods);
aaa3bccb143a Defined exception cd.error which is used for errors other than
Sjoerd Mullender <sjoerd@acm.org>
parents: 926
diff changeset
852 d = getmoduledict(m);
aaa3bccb143a Defined exception cd.error which is used for errors other than
Sjoerd Mullender <sjoerd@acm.org>
parents: 926
diff changeset
853
aaa3bccb143a Defined exception cd.error which is used for errors other than
Sjoerd Mullender <sjoerd@acm.org>
parents: 926
diff changeset
854 CdError = newstringobject("cd.error");
2603
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
855 dictinsert(d, "error", CdError);
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
856
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
857 /* Identifiers for the different types of callbacks from the parser */
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
858 dictinsert(d, "audio", newintobject((long) cd_audio));
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
859 dictinsert(d, "pnum", newintobject((long) cd_pnum));
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
860 dictinsert(d, "index", newintobject((long) cd_index));
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
861 dictinsert(d, "ptime", newintobject((long) cd_ptime));
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
862 dictinsert(d, "atime", newintobject((long) cd_atime));
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
863 dictinsert(d, "catalog", newintobject((long) cd_catalog));
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
864 dictinsert(d, "ident", newintobject((long) cd_ident));
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
865 dictinsert(d, "control", newintobject((long) cd_control));
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
866
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
867 /* Block size information for digital audio data */
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
868 dictinsert(d, "DATASIZE", newintobject((long) CDDA_DATASIZE));
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
869 dictinsert(d, "BLOCKSIZE", newintobject((long) CDDA_BLOCKSIZE));
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
870
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
871 /* Possible states for the cd player */
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
872 dictinsert(d, "ERROR", newintobject((long) CD_ERROR));
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
873 dictinsert(d, "NODISC", newintobject((long) CD_NODISC));
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
874 dictinsert(d, "READY", newintobject((long) CD_READY));
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
875 dictinsert(d, "PLAYING", newintobject((long) CD_PLAYING));
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
876 dictinsert(d, "PAUSED", newintobject((long) CD_PAUSED));
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
877 dictinsert(d, "STILL", newintobject((long) CD_STILL));
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
878 #ifdef CD_CDROM /* only newer versions of the library */
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
879 dictinsert(d, "CDROM", newintobject((long) CD_CDROM));
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
880 #endif
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
881
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
882 if (err_occurred())
4084ecf276cf Use newgetargs instead of getargs.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2061
diff changeset
883 fatal("can't initialize module cd");
820
09c69a1ec7b0 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
884 }