x11gfx.hidd: support 32 bit modes
[AROS.git] / compiler / stdc / stpsym.c
blob99876816de191d1795b3d9d78f22cc675f1f3fef
1 /*
2 Copyright © 2002-2012, The AROS Development Team. All rights reserved.
3 $Id$
5 SAS/C function stpsym().
6 */
8 #include <ctype.h>
10 /*****************************************************************************
12 NAME */
13 #include <string.h>
15 char * stpsym (
17 /* SYNOPSIS */
18 char * str_ptr,
19 char * dest_ptr,
20 int dest_size)
22 /* FUNCTION
23 Searches for a symbol in a string.
25 INPUTS
26 str_ptr - points to the string to scan
28 dest_ptr - points to the string where stpsym stores the symbol
30 dest_size - specifies the size in bytes of *dest_ptr
32 RESULT
33 Pointer to the next character in the string after the symbol.
34 If stpsym could not find a symbol, it returns str_ptr.
36 NOTES
37 A symbol consists of an alphabetic character followed by zero
38 or more alphanumeric characters. stpsym() does not skip leading
39 space characters.
41 Note that if you want to retrieve a symbol of length n, you need
42 to ensure that *dest_ptr can accommodate at least n+1 elements,
43 and that dest_size == n+1. This extra element is needed for the
44 terminating null character.
46 EXAMPLE
47 #include <string.h>
48 #include <stdio.h>
50 int main(void)
52 char *text;
53 char symbol[10];
54 char *r;
56 text = "alpha1 2";
57 r = stpsym(text,symbol,10);
58 printf("%s",symbol); // prints "alpha1"
61 BUGS
63 SEE ALSO
65 INTERNALS
67 ******************************************************************************/
69 int count = 0;
70 char *str = str_ptr;
72 if(str == NULL)
73 return NULL;
75 if(isalpha(*str))
77 dest_ptr[count++] = *str++;
78 while(isalnum(*str) && count<(dest_size-1))
80 dest_ptr[count++] = *str++;
82 dest_ptr[count] = 0;
85 return str;
86 } /* stpsym */