aboutsummaryrefslogtreecommitdiffstats
path: root/spo256/getspo.c
blob: de3eeeb4d7a5ef6722fa1e35bd1ef9d232fb4580 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
 * Parse .conf file interface spec for spo communications.
 * $Id: getspo.c 1.2 Mon, 24 Mar 1997 12:25:37 -0500 dyfet $
 * Copyright (c) 1997 by Tycho Softworks.
 * For conditions of distribution and reuse see product license.
 */

#include <other/string.h>
#include <other/config.h>
#include <std/files.h>
#include <proc/process.h>
#include <dev/tty.h>

char	*mask = NULL;

int	getspo(CONFIG *cfg)
{
	int	spo = -1;
	char	*p;
	stty_t	stty;

	if(!seek_config(cfg, "interface"))
		fatal(EX_CONFIG, "spo256: [interface]: missing from speak.conf\n");

	while(NULL != read_config(cfg))
	{
		if(NULL != (p = get_config(cfg, "bind")))
		{
			mask = strdup(p);
			continue;
		}

		if(NULL != (p = get_config(cfg, "device")))
		{
			spo = open(p, O_RDWR);
			if(spo < 0)
				fatal(EX_UNAVAILABLE, "spo256: %s: cannot access\n", p); 
			stty = getstty(spo);
			interactive(stty, FALSE);
			continue;
		}

		if(NULL != (p = get_config(cfg, "flowctrl")))
		{
			if(atol(p) == 0)
				setflowctrl(stty, FC_NONE); 
			else if(atol(p) == 1)
				setflowctrl(stty, FC_HARD);
			else if(atol(p) == 2)
				setflowctrl(stty, FC_SOFT);
			else if(atol(p) == 3)
				setflowctrl(stty, FC_FULL);
			else
				setflowctrl(stty, FC_NONE);
		}
	
		if(NULL != (p = get_config(cfg, "speed")))
		{
			if(spo < 0)
				fatal(EX_CONFIG, "spo256: set speed for unspecified device\n");
			setspeed(stty, atol(p));
			continue;
		}

		if(NULL != (p = get_config(cfg, "parity")))
		{
			if(spo < 0)
				fatal(EX_CONFIG, "spo256: set format for unspecified device\n"); 
			if(!stricmp(p, "even"))
				setformat(stty, "7e1");
			if(!stricmp(p, "odd"))
				setformat(stty, "7o1");
			if(!stricmp(p, "none"))
				setformat(stty, "8n1");
			continue;
		}
	}
	putstty(spo, stty, TRUE);
	return spo;
}