Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit df48d14

Browse files
committed
Define the constants needed for working with these functions directly
in this module; no more need for TERMIOS.py.
1 parent 0f4e93d commit df48d14

1 file changed

Lines changed: 158 additions & 0 deletions

File tree

Modules/termios.c

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,15 +293,173 @@ static PyMethodDef termios_methods[] =
293293
{NULL, NULL}
294294
};
295295

296+
297+
static struct constant {
298+
char *name;
299+
long value;
300+
} termios_constants[] = {
301+
/* cfgetospeed(), cfsetospeed() constants */
302+
{"B0", B0},
303+
{"B50", B50},
304+
{"B75", B75},
305+
{"B110", B110},
306+
{"B134", B134},
307+
{"B150", B150},
308+
{"B200", B200},
309+
{"B300", B300},
310+
{"B600", B600},
311+
{"B1200", B1200},
312+
{"B1800", B1800},
313+
{"B2400", B2400},
314+
{"B4800", B4800},
315+
{"B9600", B9600},
316+
{"B19200", B19200},
317+
{"B38400", B38400},
318+
{"B57600", B57600},
319+
{"B115200", B115200},
320+
{"B230400", B230400},
321+
{"CBAUDEX", CBAUDEX},
322+
323+
/* tcsetattr() constants */
324+
{"TCSANOW", TCSANOW},
325+
{"TCSADRAIN", TCSADRAIN},
326+
{"TCSAFLUSH", TCSAFLUSH},
327+
328+
/* tcflush() constants */
329+
{"TCIFLUSH", TCIFLUSH},
330+
{"TCOFLUSH", TCOFLUSH},
331+
{"TCIOFLUSH", TCIOFLUSH},
332+
333+
/* tcflow() constants */
334+
{"TCOOFF", TCOOFF},
335+
{"TCOON", TCOON},
336+
{"TCIOFF", TCIOFF},
337+
{"TCION", TCION},
338+
339+
/* struct termios.c_iflag constants */
340+
{"IGNBRK", IGNBRK},
341+
{"BRKINT", BRKINT},
342+
{"IGNPAR", IGNPAR},
343+
{"PARMRK", PARMRK},
344+
{"INPCK", INPCK},
345+
{"ISTRIP", ISTRIP},
346+
{"INLCR", INLCR},
347+
{"IGNCR", IGNCR},
348+
{"ICRNL", ICRNL},
349+
{"IUCLC", IUCLC},
350+
{"IXON", IXON},
351+
{"IXANY", IXANY},
352+
{"IXOFF", IXOFF},
353+
{"IMAXBEL", IMAXBEL},
354+
355+
/* struct termios.c_oflag constants */
356+
{"OPOST", OPOST},
357+
{"OLCUC", OLCUC},
358+
{"ONLCR", ONLCR},
359+
{"OCRNL", OCRNL},
360+
{"ONOCR", ONOCR},
361+
{"ONLRET", ONLRET},
362+
{"OFILL", OFILL},
363+
{"OFDEL", OFDEL},
364+
{"NLDLY", NLDLY},
365+
{"CRDLY", CRDLY},
366+
{"TABDLY", TABDLY},
367+
{"BSDLY", BSDLY},
368+
{"VTDLY", VTDLY},
369+
{"FFDLY", FFDLY},
370+
371+
/* struct termios.c_oflag-related values (delay mask) */
372+
{"NL0", NL0},
373+
{"NL1", NL1},
374+
{"CR0", CR0},
375+
{"CR1", CR1},
376+
{"CR2", CR2},
377+
{"CR3", CR3},
378+
{"TAB0", TAB0},
379+
{"TAB1", TAB1},
380+
{"TAB2", TAB2},
381+
{"TAB3", TAB3},
382+
{"XTABS", XTABS},
383+
{"BS0", BS0},
384+
{"BS1", BS1},
385+
{"VT0", VT0},
386+
{"VT1", VT1},
387+
{"FF0", FF0},
388+
{"FF1", FF1},
389+
390+
/* struct termios.c_cflag constants */
391+
{"CSIZE", CSIZE},
392+
{"CSTOPB", CSTOPB},
393+
{"CREAD", CREAD},
394+
{"PARENB", PARENB},
395+
{"PARODD", PARODD},
396+
{"HUPCL", HUPCL},
397+
{"CLOCAL", CLOCAL},
398+
{"CIBAUD", CIBAUD},
399+
{"CRTSCTS", CRTSCTS},
400+
401+
/* struct termios.c_cflag-related values (character size) */
402+
{"CS5", CS5},
403+
{"CS6", CS6},
404+
{"CS7", CS7},
405+
{"CS8", CS8},
406+
407+
/* struct termios.c_lflag constants */
408+
{"ISIG", ISIG},
409+
{"ICANON", ICANON},
410+
{"XCASE", XCASE},
411+
{"ECHO", ECHO},
412+
{"ECHOE", ECHOE},
413+
{"ECHOK", ECHOK},
414+
{"ECHONL", ECHONL},
415+
{"ECHOCTL", ECHOCTL},
416+
{"ECHOPRT", ECHOPRT},
417+
{"ECHOKE", ECHOKE},
418+
{"FLUSHO", FLUSHO},
419+
{"NOFLSH", NOFLSH},
420+
{"TOSTOP", TOSTOP},
421+
{"PENDIN", PENDIN},
422+
{"IEXTEN", IEXTEN},
423+
424+
/* indexes into the control chars array returned by tcgetattr() */
425+
{"VINTR", VINTR},
426+
{"VQUIT", VQUIT},
427+
{"VERASE", VERASE},
428+
{"VKILL", VKILL},
429+
{"VEOF", VEOF},
430+
{"VTIME", VTIME},
431+
{"VMIN", VMIN},
432+
{"VSWTC", VSWTC},
433+
{"VSTART", VSTART},
434+
{"VSTOP", VSTOP},
435+
{"VSUSP", VSUSP},
436+
{"VEOL", VEOL},
437+
{"VREPRINT", VREPRINT},
438+
{"VDISCARD", VDISCARD},
439+
{"VWERASE", VWERASE},
440+
{"VLNEXT", VLNEXT},
441+
{"VEOL2", VEOL2},
442+
443+
/* sentinel */
444+
{NULL, 0}
445+
};
446+
447+
296448
DL_EXPORT(void)
297449
PyInit_termios(void)
298450
{
299451
PyObject *m, *d;
452+
struct constant *constant = termios_constants;
300453

301454
m = Py_InitModule4("termios", termios_methods, termios__doc__,
302455
(PyObject *)NULL, PYTHON_API_VERSION);
303456

304457
d = PyModule_GetDict(m);
305458
TermiosError = PyErr_NewException("termios.error", NULL, NULL);
306459
PyDict_SetItemString(d, "error", TermiosError);
460+
461+
while (constant->name != NULL) {
462+
PyModule_AddIntConstant(m, constant->name, constant->value);
463+
++constant;
464+
}
307465
}

0 commit comments

Comments
 (0)