annotate Modules/cdmodule.c @ 2800:ab3dca97ffbe legacy-trunk

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