You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
118 lines
3.3 KiB
118 lines
3.3 KiB
program ModemCtl; |
|
|
|
{$MODE OBJFPC} |
|
|
|
uses SysUtils, StrUtils, Sockets; |
|
|
|
type |
|
//Connection state |
|
Connection = record |
|
Originate: boolean; |
|
Answer: boolean; |
|
Dial: boolean; |
|
Addr: longword; |
|
Port: word; |
|
Hang: boolean; |
|
end; |
|
|
|
var |
|
ConnVar: Connection; //State of the modem |
|
ConnFile: file of Connection; //File storing the state of the modem |
|
Addr: in_addr; //Temporary variable |
|
|
|
begin |
|
|
|
//Check the arguments |
|
if ParamStr (1) = '-a' then begin |
|
if ParamCount <> 2 then begin |
|
writeln ('Usage: modemctl -o/[-a address:port]/[-d address:port]/-h'); |
|
halt (1); |
|
end; |
|
end |
|
else if ParamStr (1) = '-d' then begin |
|
if ParamCount <> 2 then begin |
|
writeln ('Usage: modemctl -o/[-a address:port]/[-d address:port]/-h'); |
|
halt (1); |
|
end; |
|
end |
|
else begin |
|
if ParamCount > 1 then begin |
|
writeln ('Usage: modemctl -o/[-a address:port]/[-d address:port]/-h'); |
|
halt (1); |
|
end; |
|
end; |
|
|
|
//Assign the state file |
|
assign (ConnFile, ExpandFileName ('~/.thingamajig/connection')); |
|
|
|
//Set the connection |
|
if ParamStr (1) = '-o' then begin |
|
ConnVar.Originate := true; |
|
ConnVar.Answer := false; |
|
ConnVar.Dial := false; |
|
ConnVar.Addr := 0; |
|
ConnVar.Port := 0; |
|
ConnVar.Hang := false; |
|
end |
|
else if ParamStr (1) = '-a' then begin |
|
ConnVar.Originate := false; |
|
ConnVar.Answer := true; |
|
ConnVar.Dial := false; |
|
try |
|
Addr := StrToHostAddr (ExtractDelimited (1, ParamStr (2), [':'])); |
|
ConnVar.Addr := Addr.s_addr; |
|
except |
|
writeln ('Usage: modemctl -o/[-a address:port]/[-d address:port]/-h'); |
|
halt (1); |
|
end; |
|
try |
|
ConnVar.Port := StrToInt (ExtractDelimited (2, ParamStr (2), [':'])); |
|
except |
|
writeln ('Usage: modemctl -o/[-a address:port]/[-d address:port]/-h'); |
|
halt (1); |
|
end; |
|
ConnVar.Hang := false; |
|
ConnVar.Hang := false; |
|
end |
|
else if ParamStr (1) = '-d' then begin |
|
ConnVar.Originate := false; |
|
ConnVar.Answer := false; |
|
ConnVar.Dial := true; |
|
try |
|
Addr := StrToHostAddr (ExtractDelimited (1, ParamStr (2), [':'])); |
|
ConnVar.Addr := Addr.s_addr; |
|
except |
|
writeln ('Usage: modemctl -o/[-a address:port]/[-d address:port]/-h'); |
|
halt (1); |
|
end; |
|
try |
|
ConnVar.Port := StrToInt (ExtractDelimited (2, ParamStr (2), [':'])); |
|
except |
|
writeln ('Usage: modemctl -o/[-a address:port]/[-d address:port]/-h'); |
|
halt (1); |
|
end; |
|
ConnVar.Hang := false; |
|
end |
|
else if ParamStr (1) = '-h' then begin |
|
ConnVar.Originate := false; |
|
ConnVar.Answer := false; |
|
ConnVar.Dial := false; |
|
ConnVar.Addr := 0; |
|
ConnVar.Port := 0; |
|
ConnVar.Hang := true; |
|
end |
|
else begin |
|
writeln ('Usage: modemctl -o/[-a address:port]/[-d address:port]/-h'); |
|
halt (1); |
|
end; |
|
|
|
//Write the state |
|
try |
|
rewrite (ConnFile); |
|
write (ConnFile, ConnVar); |
|
close (ConnFile); |
|
except |
|
writeln ('Error: could not set the connection'); |
|
end; |
|
|
|
end.
|
|
|