[comp.mail.elm] Priority etc.

andrew@stl.stc.co.uk (Andrew Macpherson) (01/30/91)

The comparisons of various header fields in elm are made with the macro
first_word(a,b) which expands to (strncmp(a,b,strlen(b))==0)

In various places different common capitalisations are tested to set (e.g.)
the Urgency flag.

I suggest this definition be changed to strincmp allowing many expressions
to be simplified, and a better chance of Non-Urgent messages being handled
correctly :-).

A side effect is that istrcmp/strnicmp should be moved to opt_utils.c,
and the second copy of istrcmp deleted from newalias.

Proposed patch:
*** hdrs/defs.oh	Tue Jan 29 16:22:59 1991
--- hdrs/defs.h	Tue Jan 29 15:22:06 1991
***************
*** 192,198 ****
  			     s[xyz--] = '\0';                                 \
  			}
  			  
! #define first_word(s,w) (strncmp(s,w, strlen(w)) == 0)
  #define ClearLine(n)	MoveCursor(n,0); CleartoEOLN()
  #define whitespace(c)	(c == ' ' || c == '\t')
  #define ok_rc_char(c)	(isalnum(c) || c == '-' || c == '_')
--- 192,198 ----
  			     s[xyz--] = '\0';                                 \
  			}
  			  
! #define first_word(s,w) (strincmp(s,w, strlen(w)) == 0)
  #define ClearLine(n)	MoveCursor(n,0); CleartoEOLN()
  #define whitespace(c)	(c == ' ' || c == '\t')
  #define ok_rc_char(c)	(isalnum(c) || c == '-' || c == '_')
*** src/aliaslib.oc	Mon Dec 10 16:42:22 1990
--- src/aliaslib.c	Tue Jan 29 15:56:59 1991
***************
*** 301,341 ****
  }
  
  int
- istrcmp(s1,s2)
- register char *s1, *s2;
- {
- 	/* case insensitive comparison */
- 	register int d;
- 	for (;;) {
- 	  d = ( isupper(*s1) ? tolower(*s1) : *s1 )
- 		  - ( isupper(*s2) ? tolower(*s2) : *s2 ) ;
- 	  if ( d != 0 || *s1 == '\0' || *s2 == '\0' )
- 	    return d;
- 	  ++s1;
- 	  ++s2;
- 	}
- 	/*NOTREACHED*/
- }
- 
- int
- strincmp(s1,s2,n)
- register char *s1, *s2;
- register int n;
- {
- 	/* case insensitive comparison */
- 	register int d;
- 	while (--n >= 0) {
- 	  d = ( isupper(*s1) ? tolower(*s1) : *s1 )
- 		  - ( isupper(*s2) ? tolower(*s2) : *s2 ) ;
- 	  if ( d != 0 || *s1 == '\0' || *s2 == '\0' )
- 	    return d;
- 	  ++s1;
- 	  ++s2;
- 	}
- 	return(0);
- }
- 
- int
  hash_it(string, table_size)
  register char *string;
  int   table_size;
--- 301,306 ----
*** src/opt_utils.oc	Mon Dec 10 16:37:58 1990
--- src/opt_utils.c	Tue Jan 29 16:07:32 1991
***************
*** 449,451 ****
--- 449,487 ----
  	return(0);
  }
  #endif
+ 
+ int
+ istrcmp(s1,s2)
+ register char *s1, *s2;
+ {
+ 	/* case insensitive comparison */
+ 	register int d;
+ 	for (;;) {
+ 	  d = ( isupper(*s1) ? tolower(*s1) : *s1 )
+ 		  - ( isupper(*s2) ? tolower(*s2) : *s2 ) ;
+ 	  if ( d != 0 || *s1 == '\0' || *s2 == '\0' )
+ 	    return d;
+ 	  ++s1;
+ 	  ++s2;
+ 	}
+ 	/*NOTREACHED*/
+ }
+ 
+ int
+ strincmp(s1,s2,n)
+ register char *s1, *s2;
+ register int n;
+ {
+ 	/* case insensitive comparison */
+ 	register int d;
+ 	while (--n >= 0) {
+ 	  d = ( isupper(*s1) ? tolower(*s1) : *s1 )
+ 		  - ( isupper(*s2) ? tolower(*s2) : *s2 ) ;
+ 	  if ( d != 0 || *s1 == '\0' || *s2 == '\0' )
+ 	    return d;
+ 	  ++s1;
+ 	  ++s2;
+ 	}
+ 	return(0);
+ }
+ 
*** utils/newalias.oc	Sat Jan 26 10:12:29 1991
--- utils/newalias.c	Tue Jan 29 16:14:43 1991
***************
*** 441,463 ****
  }
  
  int
- istrcmp(s1,s2)
- register char *s1, *s2;
- {
- 	/* case insensitive comparison */
- 	register int d;
- 	for (;;) {
- 	  d = ( isupper(*s1) ? tolower(*s1) : *s1 )
- 		  - ( isupper(*s2) ? tolower(*s2) : *s2 ) ;
- 	  if ( d != 0 || *s1 == '\0' || *s2 == '\0' )
- 	    return d;
- 	  ++s1;
- 	  ++s2;
- 	}
- 	/*NOTREACHED*/
- }
- 
- int
  hash_it(string, table_size)
  register char *string;
  int   table_size;
--- 441,446 ----

-- 
Andrew.Macpherson@stl.stc.co.uk  --  PSI%234237100122::Andrew.Macpherson
"There is nothing quite so worthwhile as simply messing about in boats"

pwo@ztivax.UUCP (Peter W Osel) (01/31/91)

In article <3987@stl.stc.co.uk> "Andrew Macpherson" <andrew@stl.stc.co.uk> writes:
>The comparisons of various header fields in elm are made with the macro
>first_word(a,b) which expands to (strncmp(a,b,strlen(b))==0)
>
>In various places different common capitalisations are tested to set (e.g.)
>the Urgency flag.
>
>I suggest this definition be changed to strincmp allowing many expressions
>to be simplified, and a better chance of Non-Urgent messages being handled
>correctly :-).
>
>A side effect is that istrcmp/strnicmp should be moved to opt_utils.c,
>and the second copy of istrcmp deleted from newalias.
>
>Proposed patch:
	[... patch deleted ...]

	Why not use the library functions strcasecmp(3) and strncasecmp(3).
As far as I understand, these functions will migrate into the standard C
libraries of all machines (at least I got them on my SUN :-).  Aren't there
public domain implementations too?  I think these functions would be faster than
istrcmp and strnicmp ...

	Ping,
		pwo
--
Peter W. Osel			UUCP:		uunet|mcvax!unido!ztivax!pwo
Siemens AG, HL SC 3				pwo@ztivax.UUCP
D-8000 Munich 80		Internet:	pwo%sunrise@ztivax.siemens.com
Balanstrasse 73			DECNET:		hippie::pwo || sscvx1::osel
				Phone:		+49 89 4144 3825
				Fax:		+49 89 4144 4009

andrew@stl.stc.co.uk (Andrew Macpherson) (02/01/91)

In the referenced article pwo%sunrise@ztivax.siemens.com (Peter W Osel) writes:
| 	Why not use the library functions strcasecmp(3) and strncasecmp(3).
| As far as I understand, these functions will migrate into the standard C
| libraries of all machines (at least I got them on my SUN :-).  Aren't there
| public domain implementations too?  I think these functions would be faster than
| istrcmp and strnicmp ...
| --
| Peter W. Osel			Internet:	pwo%sunrise@ztivax.siemens.com

While I agree in principle, both of these functions are in libresolv rather
than libc on SunOS, BSD4.3, SysVr4, and these string functions are provided
as part of the package.

-- 
Andrew.Macpherson@stl.stc.co.uk  --  PSI%234237100122::Andrew.Macpherson
"There is nothing quite so worthwhile as simply messing about in boats"