File: ratAddrList.c

package info (click to toggle)
tkrat 1%3A2.2cvs20100105-true-dfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 10,328 kB
  • ctags: 9,259
  • sloc: ansic: 96,057; tcl: 25,667; makefile: 1,638; sh: 282
file content (88 lines) | stat: -rw-r--r-- 2,603 bytes parent folder | download | duplicates (4)
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
/*
 * ratAddrlist.c --
 *
 *	This file contains the native support for searching in the address list
 *
 * TkRat software and its included text is Copyright 1996-2005 by
 * Martin Forssn
 *
 * The full text of the legal notice is contained in the file called
 * COPYRIGHT, included with this distribution.
 */

#include "rat.h"


/*
 *----------------------------------------------------------------------
 *
 * GetMatchingAddrsImplCmd --
 *
 *      This routine creates an address command by an address given
 *	as argument
 *
 * Results:
 *	A list of address entity names is appended to the result
 *
 * Side effects:
 *	New address entities are created,
 *
 *
 *----------------------------------------------------------------------
 */

int
RatGetMatchingAddrsImplCmd(ClientData clientData, Tcl_Interp *interp, int objc,
                           Tcl_Obj *CONST objv[])
{
    int i, listc, max, matchlen, found=0;
    Tcl_Obj **listv, *ret, *o;
    char *match, *name, *email, buf[1024];
    ADDRESS adr;

    if (4 != objc
        || TCL_OK != Tcl_ListObjGetElements(interp, objv[1], &listc, &listv)
        || TCL_OK != Tcl_GetIntFromObj(interp, objv[3], &max)) {
	Tcl_AppendResult(interp, "Usage: ", Tcl_GetString(objv[0]),
                         " addrlist match max", (char*)NULL);
	return TCL_ERROR;
    }
    match = Tcl_GetStringFromObj(objv[2], &matchlen);

    ret = Tcl_NewObj();
    for (i=0; i<listc && found<max; i+=2) {
        email = Tcl_GetString(listv[i]);
        name = Tcl_GetString(listv[i+1]);
        if (0 == strncasecmp(match, email, matchlen)
            || 0 == strncasecmp(match, name, matchlen)) {
            if (strlen(name)) {
                strlcpy(buf, email, sizeof(buf));
                adr.personal = name;
                adr.adl = NULL;
                adr.mailbox = buf;
                adr.host = strchr(buf, '@');
                if (adr.host) {
                    *adr.host++ = '\0';
                } else {
                    adr.host = NODOMAIN;
                }
                adr.error = NULL;
                adr.next = NULL;
                o = Tcl_NewStringObj(RatAddressFull(interp, &adr, NULL), -1);
            } else {
                o = listv[i];
            }
            if (!strcmp(Tcl_GetString(o), match)) {
                /* Free it if refcount equals zero */
                Tcl_IncrRefCount(o);
                Tcl_DecrRefCount(o);
                continue;
            }
            Tcl_ListObjAppendElement(interp, ret, o);
            found++;
        }
    }

    Tcl_SetObjResult(interp, ret);
    return TCL_OK;
}