1*11a8fa6cSceastha /* 2*11a8fa6cSceastha * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 3*11a8fa6cSceastha * Use is subject to license terms. 4*11a8fa6cSceastha */ 5*11a8fa6cSceastha 67c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 77c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 87c478bd9Sstevel@tonic-gate 97c478bd9Sstevel@tonic-gate /* 107c478bd9Sstevel@tonic-gate * Copyright (c) 1980 Regents of the University of California. 117c478bd9Sstevel@tonic-gate * All rights reserved. The Berkeley software License Agreement 127c478bd9Sstevel@tonic-gate * specifies the terms and conditions for redistribution. 137c478bd9Sstevel@tonic-gate */ 147c478bd9Sstevel@tonic-gate 157c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 167c478bd9Sstevel@tonic-gate 177c478bd9Sstevel@tonic-gate 187c478bd9Sstevel@tonic-gate #include <stdio.h> 197c478bd9Sstevel@tonic-gate #include <locale.h> 207c478bd9Sstevel@tonic-gate 21*11a8fa6cSceastha int 22*11a8fa6cSceastha hash(char *s) 237c478bd9Sstevel@tonic-gate { 247c478bd9Sstevel@tonic-gate int c, n; 257c478bd9Sstevel@tonic-gate for (n = 0; c = *s; s++) 267c478bd9Sstevel@tonic-gate n += (c*n+ c << (n%4)); 277c478bd9Sstevel@tonic-gate return (n > 0 ? n : -n); 287c478bd9Sstevel@tonic-gate } 297c478bd9Sstevel@tonic-gate 30*11a8fa6cSceastha void 31*11a8fa6cSceastha err(char *s, int a) 327c478bd9Sstevel@tonic-gate { 337c478bd9Sstevel@tonic-gate fprintf(stderr, gettext("Error: ")); 347c478bd9Sstevel@tonic-gate fprintf(stderr, s, a); 357c478bd9Sstevel@tonic-gate putc('\n', stderr); 367c478bd9Sstevel@tonic-gate exit(1); 377c478bd9Sstevel@tonic-gate } 387c478bd9Sstevel@tonic-gate 39*11a8fa6cSceastha int 40*11a8fa6cSceastha prefix(char *t, char *s) 417c478bd9Sstevel@tonic-gate { 427c478bd9Sstevel@tonic-gate int c; 437c478bd9Sstevel@tonic-gate 447c478bd9Sstevel@tonic-gate while ((c = *t++) == *s++) 45*11a8fa6cSceastha if (c == 0) 46*11a8fa6cSceastha return (1); 477c478bd9Sstevel@tonic-gate return (c == 0 ? 1 : 0); 487c478bd9Sstevel@tonic-gate } 497c478bd9Sstevel@tonic-gate 507c478bd9Sstevel@tonic-gate char * 51*11a8fa6cSceastha mindex(char *s, char c) 527c478bd9Sstevel@tonic-gate { 53*11a8fa6cSceastha char *p; 547c478bd9Sstevel@tonic-gate for (p = s; *p; p++) 557c478bd9Sstevel@tonic-gate if (*p == c) 567c478bd9Sstevel@tonic-gate return (p); 577c478bd9Sstevel@tonic-gate return (0); 587c478bd9Sstevel@tonic-gate } 597c478bd9Sstevel@tonic-gate 60*11a8fa6cSceastha void * 61*11a8fa6cSceastha zalloc(size_t m, size_t n) 627c478bd9Sstevel@tonic-gate { 637c478bd9Sstevel@tonic-gate char *calloc(); 64*11a8fa6cSceastha void *t; 657c478bd9Sstevel@tonic-gate #if D1 667c478bd9Sstevel@tonic-gate fprintf(stderr, "calling calloc for %d*%d bytes\n", m, n); 677c478bd9Sstevel@tonic-gate #endif 68*11a8fa6cSceastha t = calloc(m, n); 697c478bd9Sstevel@tonic-gate #if D1 707c478bd9Sstevel@tonic-gate fprintf(stderr, "calloc returned %o\n", t); 717c478bd9Sstevel@tonic-gate #endif 727c478bd9Sstevel@tonic-gate return (t); 737c478bd9Sstevel@tonic-gate } 74