/* file sstok_lr_s.c */

#if !defined(COMPILE_ENVIRONMENT)
#include <gp/stdcenvf.h> /* std compile environment for functions */
#endif

 SUBSTRING sstok_lr_s(char *sx, char lbound, char rbound,boolean include_bounds)
 /**********************************************************************/
 /*                                                                    */
 /*   Finds the next token in the char string *sx and returns it as a  */
 /* SUBSTRING.  A token is a string of characters bounded on the left  */
 /* by lbound and the right by rbound.  Iff (!include_bounds), the     */
 /* boundary characters are not included in the token.                 */
 /*   If delimiters aren't found, returns a substring of length < 0    */
 /**********************************************************************/

 {char *proc = "sstok_lr_s";
  SUBSTRING ssy_data, *ssy = &ssy_data;
 /* code */
  db_enter_msg(proc,2); /* debug only */
if (db_level > 3) printf("%s sx=[%s],lbound=[%c],rbound=[%c]\n",pdb,sx,lbound,rbound);
/* move ssy->start to first delimiter character */
  ssy->start = sx;
  while ((*(ssy->start) != lbound)&&(*ssy->start != '\0')) ssy->start += 1;
  if (*ssy->start == '\0') ssy->end = ssy->start - 2;
  else
    {/* more ssy->end from 1 beyond there to next delimiter characters */
     ssy->end = ssy->start+1;
     while ((*(ssy->end) != rbound)&&(*ssy->end != '\0')) ssy->end += 1;
     if (*ssy->end == '\0') ssy->end = ssy->start - 2;
     else
       {if (!include_bounds)
	  {ssy->start += 1;
	   ssy->end -= 1;
    }  }  }
if (db_level > 3) printf("%s @return, len(ssy)=%d\n",pdb,substr_length(ssy));
  db_leave_msg(proc,2); /* debug only */
  return *ssy;
  } /* end of function "sstok_lr_s" */
