From dab687ed495aeadda5393257e07d2a197c4dc741 Mon Sep 17 00:00:00 2001 From: Greg Hudson Date: Mon, 31 Oct 1994 00:33:46 +0000 Subject: Case-insensitive hashing, and a support routine for quoting subscription database dumps. --- server/common.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) (limited to 'server/common.c') diff --git a/server/common.c b/server/common.c index 6ae0a13..87585b9 100644 --- a/server/common.c +++ b/server/common.c @@ -49,7 +49,7 @@ strsave (sp) return(ret); } -/* generic string hash function */ +/* The "& 0x5f" provides case-insensitivity for ASCII. */ unsigned long #ifdef __STDC__ @@ -66,30 +66,49 @@ hash (string) cp = *string++; if (!cp) break; - hval += cp; + hval += cp & 0x5f; cp = *string++; if (!cp) break; - hval += cp * (3 + (1 << 16)); + hval += (cp & 0x5f) * (3 + (1 << 16)); cp = *string++; if (!cp) break; - hval += cp * (1 + (1 << 8)); + hval += (cp & 0x5f) * (1 + (1 << 8)); cp = *string++; if (!cp) break; - hval += cp * (1 + (1 << 12)); + hval += (cp & 0x5f) * (1 + (1 << 12)); cp = *string++; if (!cp) break; - hval += cp * (1 + (1 << 4)); + hval += (cp & 0x5f) * (1 + (1 << 4)); hval += ((long) hval) >> 18; } hval &= 0x7fffffff; return hval; } + +/* Output a name, replacing newlines with \n and single quotes with \q. */ +void subscr_quote(p, fp) + char *p; + FILE *fp; +{ + for (; *p; p++) { + if (*p == '\'') { + putc('\\', fp); + putc('q', fp); + } else if (*p == '\n') { + putc('\\', fp); + putc('n', fp); + } else { + putc(*p, fp); + } + } +} + -- cgit v1.2.3