-
Notifications
You must be signed in to change notification settings - Fork 1
/
PULSE.C
104 lines (98 loc) · 2.24 KB
/
PULSE.C
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include <dos.h>
int onhook=290;
int dialtone=320;
int makepulse=14;
int breakpulse=22;
int pulsepause=130;
void pickup(void)
{
int p;
p=inportb(0x3fc);
if (p&1)
{
p&=0xfe;
outportb(0x3fc,p);
delay(onhook);
}
outportb(0x3fc,p|1);
delay(dialtone);
}
void pulse(int n)
{
int p;
p=inportb(0x3fc);
if ((p&1)==0) pickup();
p&=0xfe;
while (n--)
{
outportb(0x3fc,p);
delay(breakpulse);
outportb(0x3fc,p|1);
delay(makepulse);
}
delay(pulsepause);
}
void usage(void)
{
printf("Usage: PULSE -[owmbp] number\n");
printf(" -onnn : specify onhooktime default : %d ms\n", onhook);
printf(" -wnnn : specify dialtone wait default : %d ms\n", dialtone);
printf(" -mnnn : specify make pulse default : %d ms\n", makepulse);
printf(" -bnnn : specify break pulse default : %d ms\n", breakpulse);
printf(" -pnnn : specify pulse pause default : %d ms\n", pulsepause);
printf(" number : 1-9, 0, a-m : pulses 1-23 pulses\n");
printf(" ! : pickup phone\n");
}
void main(int argc, char **argv)
{
char *p;
while (argc>1)
{
if (argv[1][0]=='-')
switch(argv[1][1])
{
case 'o': onhook=atoi(argv[1]+2); break;
case 'w': dialtone=atoi(argv[1]+2); break;
case 'm': makepulse=atoi(argv[1]+2); break;
case 'b': breakpulse=atoi(argv[1]+2); break;
case 'p': pulsepause=atoi(argv[1]+2); break;
default: usage(); return;
}
else
{
p=argv[1];
while (*p)
{
switch(*p)
{
case '0': pulse(10); break;
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9': pulse(*p-'0'); break;
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
case 'g':
case 'h':
case 'i':
case 'j':
case 'k':
case 'l':
case 'm': pulse(*p-'a'+11); break;
case '!': pickup(); break;
}
p++;
}
}
argc--; argv++;
}
}