Chapter Contents

Previous

Next
memscntb

memscntb



Build a Translate Table for Use by memscan

Portability: SAS/C extension


SYNOPSIS
DESCRIPTION
RETURN VALUE
CAUTION
IMPLEMENTATION
EXAMPLE
RELATED FUNCTIONS
SEE ALSO


SYNOPSIS

#include <lcstring.h>

char *memscntb(char *area, const char *chars,
               int val, size_t len);


DESCRIPTION

memscntb builds a translate table that is used with the memscan function to scan a block of memory for the first occurrence of one of a set of characters. A translate table is an array containing 1 byte for each of the 256 EBCDIC characters. memscan scans its argument area for a character whose value in the translate table is not 0.

area is either the address of a 256-byte array or NULL . If area is NULL , memscntb builds the translate table in a static area whose address is returned. If area is not NULL , the table is built in the specified array.

chars is an array of characters that are to be translated to the same value. The len argument specifies the number of characters in the chars array. The table byte corresponding to each character in the first len bytes of the chars array has the value specified by val , while all other characters have the value of !val (that is, 1 if val is 0, and 0 otherwise). For example, if chars is "ab", len is 2, and val is 0, then bytes 129 and 130 (the EBCDIC decimal values for a and b) in the translate table have the value 0, and all other bytes have the value 1.

The null character is treated like any other character and must be present in the chars array if the corresponding table entry (the first byte) is to contain the value of val .

When building a translate table with memscntb , you must consider how you will use memscan . If you are going to search for the first occurrence of a character in chars , val should be nonzero. If you want to search for the first character not in chars , val should be 0.


RETURN VALUE

memscntb returns a pointer to the translate table. If area is NULL , this table cannot be modified by the program.


CAUTION

If memscntb is called with a NULL area value, the table addressed by the return value is a static area. This area may be modified by the next call to any of these functions: memchr , memscntb , strchr , strcspn , strpbrk , strscntb , and strspn .


IMPLEMENTATION

memscntb is implemented as a built-in function. Inline code is generated if str is a string literal and val is an integer constant.


EXAMPLE

This example scans an area of memory for digits, and verifies that a sequence of a digit followed by a letter does not occur using memscntb :

#include <lcstring.h>
#include <stdio.h>
#include <ctype.h>

#define LEN 100

main()
{
   char area[LEN];
   char *digitp, *start;
   size_t len_left = LEN - 1;
   char *digtable;

      /* Build a translate table with nonzero entries for digits. */
   digtable = memscntb(NULL, "0123456789", 1, 10);

   for (start = area; ; start = digitp + 1) {

         /* Find next digit.                                      */
      digitp = memscan(start, digtable, len_left);
      if (!digitp) break;
      if (isalpha(*(digitp + 1))) {
         printf("Invalid sequence: %.2s\n", digitp);
         break;
      }
   }
}


RELATED FUNCTIONS

memscan , strscntb


SEE ALSO


Chapter Contents

Previous

Next

Top of Page

Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.