File: xIrcNickListEntry.cpp

package info (click to toggle)
xirc 2.0-3
  • links: PTS
  • area: contrib
  • in suites: hamm, slink
  • size: 2,624 kB
  • ctags: 2,093
  • sloc: cpp: 21,094; makefile: 1,033
file content (199 lines) | stat: -rw-r--r-- 5,315 bytes parent folder | download
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/***************************************************************************
**    xIrcNickListEntry.cpp  $Revision: 1.5 $ - $Name: V2-0 $ 
**    Class for handling Nick names
**
** Copyright (C) 1995, 1996  Joseph Croft <jcroft@unicomp.net>  
** 
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 1, or (at your option)
** any later version.
** 
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
** 
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**
 ***************************************************************************/
#include <stdio.h>
#include <ctype.h>
#include "xIrcNickListEntry.h"

static int dbg = 0;

xIrcNickListEntry::xIrcNickListEntry(const char *pName, xIrcNickListEntry *entry)
{
   nick = "";
   addr = "";
   if (pName)
      setNick(pName);
   pNext = pPrev = NULL;
   if (entry)
      link(entry);
}

xIrcNickListEntry::xIrcNickListEntry(xIrcNickListEntry *pNick, xIrcNickListEntry *entry = NULL)
{
   nick = "";
   addr = "";
   if (pNick)
   {
      setNick(pNick->getNick());
      setAddr(pNick->getAddr());
   }
   pNext = pPrev = NULL;
   if (entry)
      link(entry);
}

xIrcNickListEntry::xIrcNickListEntry()
{
   nick = "";
   addr = "";
   pNext = pPrev = NULL;
}

xIrcNickListEntry::~xIrcNickListEntry()
{
   if (dbg > 2) fprintf(stdout, "xIrcNickListEntry::xIrcNickListEntry():Enter\n");
   if (dbg > 2) fflush(stdout);
   unlink();
   if (dbg > 2) fprintf(stdout, "xIrcNickListEntry::xIrcNickListEntry():Exit\n");
   if (dbg > 2) fflush(stdout);
}

bool xIrcNickListEntry::is(const char *pName, bool byNick)
{
   QString tmpName, tmpNick, tmpAddr;
   const char *cp, *cp1, *cp2;

   if (dbg > 2) fprintf(stdout, "xIrcNickListEntry::is():Enter\n");
   if (dbg > 2) fflush(stdout);
   for (tmpName = "", cp = pName; *cp && !isspace(*cp); cp++)
      tmpName += toupper(*cp);

   if (dbg > 2) fprintf(stdout, "xIrcNickListEntry::is():Checking if test name or address\n");
   if (dbg > 2) fflush(stdout);
   if (byNick)
   {
      if (dbg > 2) fprintf(stdout, "xIrcNickListEntry::is():Test by name\n");
      if (dbg > 2) fflush(stdout);
      for (tmpNick = "", cp = nick; *cp; cp++)
         tmpNick += toupper(*cp);
   }
   else
   {
      if (dbg > 2) fprintf(stdout, "xIrcNickListEntry::is():Test by addr\n");
      if (dbg > 2) fflush(stdout);
      for (tmpNick = "", cp = addr; *cp; cp++)
         tmpNick += toupper(*cp);
   }

   if (dbg > 2) fprintf(stdout, "xIrcNickListEntry::is():Testing |%s| against |%s|\n",
                              (const char *)tmpName, (const char *)tmpNick);
   if (dbg > 2) fflush(stdout);
   cp1 = (const char *)tmpNick;
   cp2 = (const char *)tmpName;
   if (dbg > 2) fprintf(stdout, "xIrcNickListEntry::is():cp1 = |%s|\n", cp1);
   if (dbg > 2) fflush(stdout);
   if (dbg > 2) fprintf(stdout, "xIrcNickListEntry::is():cp2 = |%s|\n", cp2);
   if (dbg > 2) fflush(stdout);
   if (dbg > 2) fprintf(stdout, "xIrcNickListEntry::is():Testing op name??\n");
   if (dbg > 2) fflush(stdout);
   if (byNick && *cp1 == '@' && *cp2 != '@')
   {
      if (dbg > 2) fprintf(stdout, "xIrcNickListEntry::is():Testing for old op name\n");
      if (dbg > 2) fflush(stdout);
      if (strcmp(cp2, ++cp1) == 0)
         return(TRUE);
      else
         return(FALSE);
   }
   else if (byNick && *cp2 == '@' && *cp1 != '@')
   {
      if (dbg > 2) fprintf(stdout, "xIrcNickListEntry::is():Testing for new op name\n");
      if (dbg > 2) fflush(stdout);
      if (strcmp(++cp2, cp1) == 0)
         return(TRUE);
      else
         return(FALSE);
   }
   else
   {
      if (dbg > 2) fprintf(stdout, "xIrcNickListEntry::is():Testing for reg name\n");
      if (dbg > 2) fflush(stdout);
      if (strcmp(cp2, cp1) == 0)
         return(TRUE);
      else
         return(FALSE);
   }
}

const char *xIrcNickListEntry::getNick(bool fullName)
{
   const char *cp;

   cp = nick;
   if (fullName || *cp != '@')
      return(cp);
   else
      return(++cp);
}
  
void xIrcNickListEntry::setNick(const char *pNick)
{
   const char *cp;

   nick = "";
   for (cp = pNick; *cp && !isspace(*cp); cp++)
      nick += *cp;
}

void xIrcNickListEntry::setAddr(const char *pAddr)
{
   const char *cp;

   addr = "";
   for (cp = pAddr; *cp && !isspace(*cp); cp++)
      nick += *cp;
}

xIrcNickListEntry *xIrcNickListEntry::next(xIrcNickListEntry  *pEntry)
{
   xIrcNickListEntry *rv;

   rv = pNext;
   pNext = pEntry;
   return(rv);
}

xIrcNickListEntry *xIrcNickListEntry::prev(xIrcNickListEntry  *pEntry)
{
   xIrcNickListEntry *rv;

   rv = pPrev;
   pPrev = pEntry;
   return(rv);
}

void xIrcNickListEntry::link(xIrcNickListEntry *pEntry)
{
   pNext = pEntry->next(this);
   if (pNext)
      pNext->prev(this);
   pPrev = pEntry;
}

void xIrcNickListEntry::unlink()
{
   if (pNext)
      pNext->prev(pPrev);
   if (pPrev)
      pPrev->next(pNext);
   pPrev = pNext = NULL;
}