File: ding.c

package info (click to toggle)
zoem 06-234-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 2,560 kB
  • ctags: 1,915
  • sloc: ansic: 16,472; sh: 793; makefile: 227
file content (101 lines) | stat: -rw-r--r-- 2,100 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*   (C) Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005 Stijn van Dongen
 *   (C) Copyright 2006 Stijn van Dongen
 *
 * This file is part of tingea.  You can redistribute and/or modify tingea
 * under the terms of the GNU General Public License; either version 2 of the
 * License or (at your option) any later version.  You should have received a
 * copy of the GPL along with tingea, in the file COPYING.
*/

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

#include "ding.h"
#include "types.h"
#include "alloc.h"


const char* trGetToken
(  const char *p
,  const char *z
,  int  *tokval
)  ;

char* mcxStrDup
(  const char* str
)
   {  dim len = strlen(str)
   ;  char* rts = mcxAlloc(len+1, RETURN_ON_FAIL)
   ;  if (rts)
      memcpy(rts, str, len+1)
   ;  return rts
;  }


dim mcxStrCountChar
(  const char*    p
,  char           c
,  ofs            len
)
   {  const char* z = p
   ;  dim      ct =  0

   ;  z += (len >= 0) ? len : strlen(p)

   ;  while (p<z)       /* ho hum will pass embedded nil bytes */
      if (*p++ == c)
      ct++

   ;  return ct
;  }


char* mcxStrChrIs
(  const char*    p
,  int          (*fbool)(int c)
,  ofs            len
)
   {  if (len)
      while (*p && !fbool((unsigned char) *p) && --len && ++p)
      ;
      return (char*) ((len && *p) ?  p : NULL)
;  }


char* mcxStrChrAint
(  const char*    p
,  int          (*fbool)(int c)
,  ofs            len
)
   {  if (len)
      while (*p && fbool((unsigned char) *p) && --len && ++p)
      ;
      return (char *) ((len && *p) ?  p : NULL)
;  }


char* mcxStrRChrIs
(  const char*    p
,  int          (*fbool)(int c)
,  ofs            offset
)
   {  const char* z =  offset >= 0 ? p+offset : p + strlen(p)
   ;  while (--z >= p && !fbool((unsigned char) *z))
      ;
      return (char*) (z >= p ? z : NULL)
;  }


char* mcxStrRChrAint
(  const char*    p
,  int          (*fbool)(int c)
,  ofs            offset
)
   {  const char* z  =  offset >= 0 ? p+offset : p + strlen(p)
   ;  while (--z >= p && fbool((unsigned char) *z))
      ;
      return (char*) (z >= p ? z : NULL)
;  }