/*static char *SCCSID = "@(#)cmrrchr.c	6.1 90/11/16";*/
/* static char *SCCSID = "@(#)cmrrchr.c	6.2 90/01/24"; */

/*********************************************************************/
/*	 IBM/Microsoft Confidential				     */
/*								     */
/*	 Copyright (c) IBM Corporation 1987, 1989		     */
/*	 Copyright (c) Microsoft Corporation 1987, 1989		     */
/*								     */
/*	 All Rights Reserved					     */
/*********************************************************************/

/********* START OF SPECIFICATION ********** IBM CONFIDENTIAL ********/
/*								     */
/* SUBROUTINE NAME:  COM_STRRCHR				     */
/*								     */
/* DESCRIPTIVE NAME:  SEARCH FOR LAST OCCURENCE OF CHARACTER WITHIN  */
/*		      A STRING					     */
/*								     */
/* FUNCTION: Search string from front to back checking the match     */
/*	     of character to current string index char value	     */
/*								     */
/* NOTES:    Char passed must be non-DBCS else NULL returned	     */
/*								     */
/* ENTRY POINT:	 com_strrchr					     */
/*   LINKAGE  :							     */
/*								     */
/* INPUT:    string1  --- source string pointer (unsigned char ptr)  */
/*	     c	      --- char	 to be located	(unsigned char ptr)  */
/*								     */
/* EXIT:   integer						     */
/*	 value	       meaning					     */
/*	 pointer       a pointer to the last  occurence of the	     */
/*		       non-DBCS character.			     */
/*	 NULL pointer  given non-DBCS char is not found		     */
/*								     */
/* EXIT-NORMAL: string pointer					     */
/*								     */
/* EXIT-ERROR:	NULL pointer given char is DBCS lead byte type	     */
/*								     */
/* EFFECTS:							     */
/*								     */
/* INTERNAL REFERENCES:						     */
/*   ROUTINES: check_dbcs					     */
/*								     */
/* EXTERNAL REFERENCES:						     */
/*   ROUTINES: com_settbl,strlen				     */
/*								     */
/* RELEASE:							     */
/*								     */
/*   VERSION	  DATE	     AUTHOR	 REASON			     */
/*								     */
/*     1.00    06/13/1986    USHI      initial version		     */
/*     1.10    06/18/1987    JMH       correct version		     */
/*     1.11    07/15/1987    JMH       I2 review changes	     */
/*     1.20    03/18/1988  Cora Yang				     */
/*				    a. Allow it searches for NULL    */
/*				       character also.		     */
/*				    b. use pointers instead of	     */
/*				       array, etc. to make it faster */
/*				    c. take care of the problem of   */
/*				       the Leading byte and trailing */
/*				       byte could fall into the	     */
/*				       same Lead byte range.	     */
/*								     */
/*     1.21    03/28/1988    Cora Yang	   call check_dbcs instead   */
/*					   of com_chkdbcs to improve */
/*					   performance		     */
/******************* END OF SPECIFICATIONS ***************************/
#include "cmdbcs.h"
#include "comsub.h"
#include <string.h>
#include <stdio.h>

unsigned char
*com_strrchr(string,c)
register unsigned char *string;		    /* string to be searched	    */
unsigned char c;			    /* char to search with thru str */
{
unsigned char c0;
unsigned char  *finger = NULL;
int i =0;

 com_settbl();				       /* initialize DBCS table	   */

 /* handle null seperatly to make main loop easier to code */
   if (c == '\0')			     /* @@	     */
       return(string + strlen(string));	     /* @@	     */

      if ( check_dbcs(c) != DBCS)   {	      /* @@ if test char != DBCS */
	    while ( c0 = *string) {		      /* @@	   */
		 if (c0 == c)			      /* @@	   */
			 finger = string;	      /* @@	   */
		 string++;			      /* @@	   */
		 if (  check_dbcs(c0) == DBCS )	      /* @@	   */
		       string++;		      /* @@	   */
	    }
	      return(finger);			      /* @@	   */
      } else
	      return(NULL);		     /*	 return NULL since DBCS	 @@  */


}
