2 * coded by Ketmar // Invisible Vector <ketmar@ketmar.no-ip.org>
3 * Understanding is not required. Only obedience.
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 module addrbook
is aliced
;
26 // ////////////////////////////////////////////////////////////////////////// //
27 public final class AddressBookEntry
{
29 string realname
; // can be empty
34 public __gshared AddressBookEntry
[] abook
;
37 // ////////////////////////////////////////////////////////////////////////// //
38 public AddressBookEntry
abookFindByNickFirst (const(char)[] nick
) {
40 if (nick
.length
== 0) return null;
42 foreach (AddressBookEntry ae
; abook
) {
43 if (ae
.nick
.strEquCI(nick
)) return ae
;
46 foreach (AddressBookEntry ae
; abook
) {
47 if (ae
.nick
.startsWithCI(nick
)) return ae
;
54 public AddressBookEntry
abookFindByNick (const(char)[] nick
) {
56 if (nick
.length
== 0) return null;
58 foreach (AddressBookEntry ae
; abook
) {
59 if (ae
.nick
.strEquCI(nick
)) return ae
;
62 AddressBookEntry partial
;
63 foreach (AddressBookEntry ae
; abook
) {
64 if (ae
.nick
.startsWithCI(nick
)) {
65 if (partial
!is null) return null;
73 // ////////////////////////////////////////////////////////////////////////// //
74 public AddressBookEntry
abookFindByMailFirst (const(char)[] mail
) {
76 if (mail
.length
== 0) return null;
78 foreach (AddressBookEntry ae
; abook
) {
79 if (ae
.mail
.strEquCI(mail
)) return ae
;
82 foreach (AddressBookEntry ae
; abook
) {
83 if (ae
.mail
.startsWithCI(mail
)) return ae
;
90 public AddressBookEntry
abookFindByMail (const(char)[] mail
) {
92 if (mail
.length
== 0) return null;
94 foreach (AddressBookEntry ae
; abook
) {
95 if (ae
.mail
.strEquCI(mail
)) return ae
;
98 AddressBookEntry partial
;
99 foreach (AddressBookEntry ae
; abook
) {
100 if (ae
.mail
.startsWithCI(mail
)) {
101 if (partial
!is null) return null;
109 // ////////////////////////////////////////////////////////////////////////// //
110 shared static this () {
111 //addressbook_add nick noip name "Ketmar Dark" email "ketmar@ketmar.no-ip.org"
112 conRegFunc
!((ConString nick
, ConString
[] args
) {
114 if (nick
.length
== 0) { conwriteln("addressbook_add: empty nick"); return; }
115 auto origargs
= args
;
116 auto ae
= new AddressBookEntry();
118 while (args
.length
) {
119 if (args
.length
< 2) { conwriteln("addressbook_add: invalid args: ", origargs
); return; }
126 if (ae
.mail
.length
!= 0) {
127 conwriteln("addressbook_add: duplicate mail option: '", arg
, "'");
128 conwriteln("addressbook_add: invalid args: ", origargs
);
136 if (ae
.realname
.length
!= 0) {
137 conwriteln("addressbook_add: duplicate name option: '", arg
, "'");
138 conwriteln("addressbook_add: invalid args: ", origargs
);
141 ae
.realname
= arg
.idup
;
144 conwriteln("addressbook_add: unknown options: '", opt
, "'");
145 conwriteln("addressbook_add: invalid args: ", origargs
);
149 if (ae
.mail
.length
== 0) { conwriteln("addressbook_add: invalid args (no mail): ", origargs
); return; }
150 foreach (ref AddressBookEntry oae
; abook
) {
151 if (oae
.nick
.strEquCI(nick
)) { oae
= ae
; return; }
154 })("addressbook_add", "add address book entry");