File: msgid.c

package info (click to toggle)
diablo 1.16.test2-1
  • links: PTS
  • area: non-free
  • in suites: slink
  • size: 1,504 kB
  • ctags: 1,603
  • sloc: ansic: 17,654; perl: 2,054; sh: 260; csh: 118; makefile: 73
file content (52 lines) | stat: -rw-r--r-- 972 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

/*
 * LIB/MSGID.C
 *
 * (c)Copyright 1997, Matthew Dillon, All Rights Reserved.  Refer to
 *    the COPYRIGHT file in the base directory of this distribution 
 *    for specific rights granted.
 */

#include "defs.h"

Prototype char *MsgId(const char *s);

/*
 * MsgId() - the message id must begin with a '<', end with a '>', 
 *	     and not contain any embedded '<' or TAB.
 */

char *
MsgId(const char *s)
{
    int i;
    static char *LMsgId;

    if (LMsgId) {
	zfree(&SysMemPool, LMsgId, strlen(LMsgId) + 1);
	LMsgId = NULL;
    }

    if (s == NULL)
	return("<>");
    while (*s && (*s == ' ' || *s == '\t'))
	++s;
    if (*s != '<')
	return("<>");

    for (i = 1; s[i] && s[i] != '>'; ++i) {
	if (s[i] == '<' || s[i] == '\t' || s[i] == ' ')
	    return("<>");
    }

    if (s[i] != '>')
	return("<>");
    ++i;
    if (i >= MAXMSGIDLEN)
	return("<>");
    LMsgId = zalloc(&SysMemPool, i + 1);
    bcopy(s, LMsgId, i);
    LMsgId[i] = 0;
    return(LMsgId);
}