GnuCOBOL  2.0
A free COBOL compiler
strings.c File Reference
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <stdarg.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#include "libcob.h"
#include "coblocal.h"
Include dependency graph for strings.c:

Go to the source code of this file.

Data Structures

struct  dlm_struct
 

Macros

#define COB_LIB_EXPIMP
 
#define INSPECT_ALL   0
 
#define INSPECT_LEADING   1
 
#define INSPECT_FIRST   2
 
#define INSPECT_TRAILING   3
 
#define DLM_DEFAULT_NUM   8U
 

Functions

static COB_INLINE int cob_min_int (const int x, const int y)
 
static void cob_str_memcpy (cob_field *dst, unsigned char *src, const int size)
 
static void alloc_figurative (const cob_field *f1, const cob_field *f2)
 
static void inspect_common (cob_field *f1, cob_field *f2, const int type)
 
void cob_inspect_init (cob_field *var, const cob_u32_t replacing)
 
void cob_inspect_start (void)
 
void cob_inspect_before (const cob_field *str)
 
void cob_inspect_after (const cob_field *str)
 
void cob_inspect_characters (cob_field *f1)
 
void cob_inspect_all (cob_field *f1, cob_field *f2)
 
void cob_inspect_leading (cob_field *f1, cob_field *f2)
 
void cob_inspect_first (cob_field *f1, cob_field *f2)
 
void cob_inspect_trailing (cob_field *f1, cob_field *f2)
 
void cob_inspect_converting (const cob_field *f1, const cob_field *f2)
 
void cob_inspect_finish (void)
 
void cob_string_init (cob_field *dst, cob_field *ptr)
 
void cob_string_delimited (cob_field *dlm)
 
void cob_string_append (cob_field *src)
 
void cob_string_finish (void)
 
void cob_unstring_init (cob_field *src, cob_field *ptr, const size_t num_dlm)
 
void cob_unstring_delimited (cob_field *dlm, const cob_u32_t all)
 
void cob_unstring_into (cob_field *dst, cob_field *dlm, cob_field *cnt)
 
void cob_unstring_tallying (cob_field *f)
 
void cob_unstring_finish (void)
 
void cob_exit_strings (void)
 
void cob_init_strings (void)
 

Variables

static const cob_field_attr const_alpha_attr
 
static const cob_field_attr const_strall_attr
 
static cob_fieldinspect_var
 
static unsigned char * inspect_data
 
static unsigned char * inspect_start
 
static unsigned char * inspect_end
 
static int * inspect_mark
 
static size_t inspect_mark_size
 
static size_t inspect_size
 
static cob_u32_t inspect_replacing
 
static int inspect_sign
 
static cob_field inspect_var_copy
 
static cob_fieldstring_dst
 
static cob_fieldstring_ptr
 
static cob_fieldstring_dlm
 
static cob_field string_dst_copy
 
static cob_field string_ptr_copy
 
static cob_field string_dlm_copy
 
static int string_offset
 
static struct dlm_structdlm_list
 
static cob_fieldunstring_src
 
static cob_fieldunstring_ptr
 
static size_t dlm_list_size
 
static cob_field unstring_src_copy
 
static cob_field unstring_ptr_copy
 
static int unstring_offset
 
static int unstring_count
 
static int unstring_ndlms
 
static unsigned char * figurative_ptr
 
static size_t figurative_size
 
static cob_field alpha_fld
 
static cob_field str_cob_low
 

Macro Definition Documentation

#define COB_LIB_EXPIMP

Definition at line 33 of file strings.c.

#define DLM_DEFAULT_NUM   8U

Definition at line 43 of file strings.c.

Referenced by cob_init_strings().

#define INSPECT_ALL   0

Definition at line 38 of file strings.c.

Referenced by cob_inspect_all().

#define INSPECT_FIRST   2

Definition at line 40 of file strings.c.

Referenced by cob_inspect_first(), and inspect_common().

#define INSPECT_LEADING   1

Definition at line 39 of file strings.c.

Referenced by cob_inspect_leading(), and inspect_common().

#define INSPECT_TRAILING   3

Definition at line 41 of file strings.c.

Referenced by cob_inspect_trailing(), and inspect_common().

Function Documentation

static void alloc_figurative ( const cob_field f1,
const cob_field f2 
)
static

Definition at line 115 of file strings.c.

References cob_free(), cob_malloc(), cob_field::data, figurative_ptr, figurative_size, and cob_field::size.

Referenced by cob_inspect_converting(), and inspect_common().

116 {
117 
118  unsigned char *s;
119  size_t size1;
120  size_t size2;
121  size_t n;
122 
123  size2 = f2->size;
124  if (size2 > figurative_size) {
125  if (figurative_ptr) {
127  }
128  figurative_ptr = cob_malloc (size2);
129  figurative_size = size2;
130  }
131  size1 = 0;
132  s = figurative_ptr;
133  for (n = 0; n < size2; ++n, ++s) {
134  *s = f1->data[size1];
135  size1++;
136  if (size1 >= f1->size) {
137  size1 = 0;
138  }
139  }
140  alpha_fld.size = size2;
142 }
void cob_free(void *mptr)
Definition: common.c:1284
unsigned char * data
Definition: common.h:952
static cob_field alpha_fld
Definition: strings.c:89
size_t size
Definition: common.h:951
void * cob_malloc(const size_t size)
Definition: common.c:1250
static unsigned char * figurative_ptr
Definition: strings.c:86
static size_t figurative_size
Definition: strings.c:87

Here is the call graph for this function:

Here is the caller graph for this function:

void cob_exit_strings ( void  )

Definition at line 634 of file strings.c.

References cob_free(), figurative_ptr, figurative_size, inspect_mark, and NULL.

Referenced by cob_terminate_routines().

635 {
636  if (inspect_mark) {
638  inspect_mark = NULL;
639  }
640  if (dlm_list) {
641  cob_free (dlm_list);
642  dlm_list = NULL;
643  }
644  if (figurative_ptr) {
647  }
648  figurative_size = 0;
649 }
void cob_free(void *mptr)
Definition: common.c:1284
static int * inspect_mark
Definition: strings.c:61
static struct dlm_struct * dlm_list
Definition: strings.c:76
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
static unsigned char * figurative_ptr
Definition: strings.c:86
static size_t figurative_size
Definition: strings.c:87

Here is the call graph for this function:

Here is the caller graph for this function:

void cob_init_strings ( void  )

Definition at line 652 of file strings.c.

References cob_field::attr, cob_malloc(), COB_NORMAL_BUFF, cob_u8_ptr, const_alpha_attr, const_strall_attr, cob_field::data, DLM_DEFAULT_NUM, dlm_list_size, figurative_ptr, figurative_size, inspect_mark, inspect_mark_size, NULL, and cob_field::size.

Referenced by cob_init().

653 {
655  dlm_list = cob_malloc (DLM_DEFAULT_NUM * sizeof(struct dlm_struct));
659  figurative_size = 0;
660  alpha_fld.size = 0;
661  alpha_fld.data = NULL;
663  str_cob_low.size = 1;
664  str_cob_low.data = (cob_u8_ptr)"\0";
666 }
static size_t inspect_mark_size
Definition: strings.c:62
#define DLM_DEFAULT_NUM
Definition: strings.c:43
static const cob_field_attr const_alpha_attr
Definition: strings.c:52
#define COB_NORMAL_BUFF
Definition: common.h:541
static cob_field str_cob_low
Definition: strings.c:90
unsigned char * data
Definition: common.h:952
static int * inspect_mark
Definition: strings.c:61
#define cob_u8_ptr
Definition: common.h:66
static struct dlm_struct * dlm_list
Definition: strings.c:76
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
static cob_field alpha_fld
Definition: strings.c:89
static size_t dlm_list_size
Definition: strings.c:79
static const cob_field_attr const_strall_attr
Definition: strings.c:54
size_t size
Definition: common.h:951
const cob_field_attr * attr
Definition: common.h:953
void * cob_malloc(const size_t size)
Definition: common.c:1250
static unsigned char * figurative_ptr
Definition: strings.c:86
static size_t figurative_size
Definition: strings.c:87

Here is the call graph for this function:

Here is the caller graph for this function:

void cob_inspect_after ( const cob_field str)

Definition at line 283 of file strings.c.

References cob_field::data, inspect_end, inspect_start, and cob_field::size.

Referenced by GCic_().

284 {
285  unsigned char *p;
286 
287  for (p = inspect_start; p < inspect_end - str->size + 1; ++p) {
288  if (memcmp (p, str->data, str->size) == 0) {
289  inspect_start = p + str->size;
290  return;
291  }
292  }
294 }
unsigned char * data
Definition: common.h:952
static unsigned char * inspect_end
Definition: strings.c:60
size_t size
Definition: common.h:951
static unsigned char * inspect_start
Definition: strings.c:59

Here is the caller graph for this function:

void cob_inspect_all ( cob_field f1,
cob_field f2 
)

Definition at line 329 of file strings.c.

References INSPECT_ALL, and inspect_common().

Referenced by cobxref_(), GCic_(), and LISTING_().

330 {
331  inspect_common (f1, f2, INSPECT_ALL);
332 }
static void inspect_common(cob_field *f1, cob_field *f2, const int type)
Definition: strings.c:145
#define INSPECT_ALL
Definition: strings.c:38

Here is the call graph for this function:

Here is the caller graph for this function:

void cob_inspect_before ( const cob_field str)

Definition at line 270 of file strings.c.

References cob_field::data, inspect_end, inspect_start, and cob_field::size.

Referenced by cobxref_().

271 {
272  unsigned char *p;
273 
274  for (p = inspect_start; p < inspect_end - str->size + 1; ++p) {
275  if (memcmp (p, str->data, str->size) == 0) {
276  inspect_end = p;
277  return;
278  }
279  }
280 }
unsigned char * data
Definition: common.h:952
static unsigned char * inspect_end
Definition: strings.c:60
size_t size
Definition: common.h:951
static unsigned char * inspect_start
Definition: strings.c:59

Here is the caller graph for this function:

void cob_inspect_characters ( cob_field f1)

Definition at line 297 of file strings.c.

References cob_add_int(), cob_field::data, inspect_data, inspect_end, inspect_mark, inspect_replacing, and inspect_start.

Referenced by cobxref_().

298 {
299  int *mark;
300  int i;
301  int n;
302  int len;
303 
305  len = (int)(inspect_end - inspect_start);
306  if (inspect_replacing) {
307  /* INSPECT REPLACING CHARACTERS f1 */
308  for (i = 0; i < len; ++i) {
309  if (mark[i] == -1) {
310  mark[i] = f1->data[0];
311  }
312  }
313  } else {
314  /* INSPECT TALLYING f1 CHARACTERS */
315  n = 0;
316  for (i = 0; i < len; ++i) {
317  if (mark[i] == -1) {
318  mark[i] = 1;
319  n++;
320  }
321  }
322  if (n > 0) {
323  cob_add_int (f1, n, 0);
324  }
325  }
326 }
static unsigned char * inspect_data
Definition: strings.c:58
int cob_add_int(cob_field *, const int, const int)
Definition: numeric.c:2195
unsigned char * data
Definition: common.h:952
static int * inspect_mark
Definition: strings.c:61
static unsigned char * inspect_end
Definition: strings.c:60
static cob_u32_t inspect_replacing
Definition: strings.c:64
static unsigned char * inspect_start
Definition: strings.c:59

Here is the call graph for this function:

Here is the caller graph for this function:

void cob_inspect_converting ( const cob_field f1,
const cob_field f2 
)

Definition at line 353 of file strings.c.

References alloc_figurative(), alpha_fld, COB_EC_RANGE_INSPECT_SIZE, COB_FIELD_TYPE, cob_set_exception(), COB_TYPE_ALPHANUMERIC_ALL, cob_field::data, inspect_end, inspect_mark, inspect_start, cob_field::size, str_cob_low, and unlikely.

Referenced by LISTING_().

354 {
355  size_t i;
356  size_t j;
357  size_t len;
358 
359  if (unlikely(!f1)) {
360  f1 = &str_cob_low;
361  }
362  if (unlikely(!f2)) {
363  f2 = &str_cob_low;
364  }
365  if (f1->size != f2->size) {
367  alloc_figurative (f2, f1);
368  f2 = &alpha_fld;
369  } else {
371  return;
372  }
373  }
374 
375  len = (size_t)(inspect_end - inspect_start);
376  for (j = 0; j < f1->size; ++j) {
377  for (i = 0; i < len; ++i) {
378  if (inspect_mark[i] == -1 &&
379  inspect_start[i] == f1->data[j]) {
380  inspect_start[i] = f2->data[j];
381  inspect_mark[i] = 1;
382  }
383  }
384  }
385 }
#define COB_FIELD_TYPE(f)
Definition: common.h:662
static cob_field str_cob_low
Definition: strings.c:90
unsigned char * data
Definition: common.h:952
static int * inspect_mark
Definition: strings.c:61
#define unlikely(x)
Definition: common.h:437
static cob_field alpha_fld
Definition: strings.c:89
void cob_set_exception(const int id)
Definition: common.c:1212
static void alloc_figurative(const cob_field *f1, const cob_field *f2)
Definition: strings.c:115
static unsigned char * inspect_end
Definition: strings.c:60
#define COB_TYPE_ALPHANUMERIC_ALL
Definition: common.h:622
size_t size
Definition: common.h:951
static unsigned char * inspect_start
Definition: strings.c:59

Here is the call graph for this function:

Here is the caller graph for this function:

void cob_inspect_finish ( void  )

Definition at line 388 of file strings.c.

References COB_PUT_SIGN, inspect_data, inspect_mark, inspect_replacing, inspect_sign, inspect_size, and unlikely.

Referenced by cobxref_(), GCic_(), and LISTING_().

389 {
390  size_t i;
391 
392  if (inspect_replacing) {
393  for (i = 0; i < inspect_size; ++i) {
394  if (inspect_mark[i] != -1) {
395  inspect_data[i] = inspect_mark[i];
396  }
397  }
398  }
399 
400  if (unlikely(inspect_var)) {
402  }
403 }
static unsigned char * inspect_data
Definition: strings.c:58
static cob_field * inspect_var
Definition: strings.c:57
static int * inspect_mark
Definition: strings.c:61
static size_t inspect_size
Definition: strings.c:63
#define unlikely(x)
Definition: common.h:437
#define COB_PUT_SIGN(f, s)
Definition: coblocal.h:160
static cob_u32_t inspect_replacing
Definition: strings.c:64
static int inspect_sign
Definition: strings.c:65

Here is the caller graph for this function:

void cob_inspect_first ( cob_field f1,
cob_field f2 
)

Definition at line 341 of file strings.c.

References inspect_common(), and INSPECT_FIRST.

342 {
343  inspect_common (f1, f2, INSPECT_FIRST);
344 }
static void inspect_common(cob_field *f1, cob_field *f2, const int type)
Definition: strings.c:145
#define INSPECT_FIRST
Definition: strings.c:40

Here is the call graph for this function:

void cob_inspect_init ( cob_field var,
const cob_u32_t  replacing 
)

Definition at line 231 of file strings.c.

References cob_fast_malloc(), COB_FIELD_DATA, COB_FIELD_IS_NUMDISP, COB_FIELD_SIZE, cob_free(), COB_GET_SIGN, cob_set_exception(), inspect_data, inspect_end, inspect_mark, inspect_mark_size, inspect_replacing, inspect_sign, inspect_size, inspect_start, inspect_var_copy, NULL, and unlikely.

232 {
233  size_t i;
234  size_t digcount;
235 
236  if (unlikely(COB_FIELD_IS_NUMDISP (var))) {
237  inspect_var_copy = *var;
239  inspect_sign = COB_GET_SIGN (var);
240  } else {
241  inspect_var = NULL;
242  }
245  inspect_replacing = replacing;
247  inspect_end = NULL;
248  digcount = inspect_size * sizeof (int);
249  if (digcount > inspect_mark_size) {
250  if (inspect_mark) {
252  }
253  inspect_mark = cob_fast_malloc (digcount);
254  inspect_mark_size = digcount;
255  }
256  for (i = 0; i < inspect_size; ++i) {
257  inspect_mark[i] = -1;
258  }
259  cob_set_exception (0);
260 }
static size_t inspect_mark_size
Definition: strings.c:62
void cob_free(void *mptr)
Definition: common.c:1284
#define COB_FIELD_IS_NUMDISP(f)
Definition: common.h:675
#define COB_FIELD_DATA(f)
Definition: common.h:668
static unsigned char * inspect_data
Definition: strings.c:58
static cob_field * inspect_var
Definition: strings.c:57
static int * inspect_mark
Definition: strings.c:61
static size_t inspect_size
Definition: strings.c:63
static cob_field inspect_var_copy
Definition: strings.c:66
#define COB_GET_SIGN(f)
Definition: coblocal.h:158
#define unlikely(x)
Definition: common.h:437
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
void cob_set_exception(const int id)
Definition: common.c:1212
static unsigned char * inspect_end
Definition: strings.c:60
static cob_u32_t inspect_replacing
Definition: strings.c:64
void * cob_fast_malloc(const size_t size)
Definition: common.c:1296
static unsigned char * inspect_start
Definition: strings.c:59
static int inspect_sign
Definition: strings.c:65
#define COB_FIELD_SIZE(f)
Definition: common.h:671

Here is the call graph for this function:

void cob_inspect_leading ( cob_field f1,
cob_field f2 
)

Definition at line 335 of file strings.c.

References inspect_common(), and INSPECT_LEADING.

336 {
338 }
static void inspect_common(cob_field *f1, cob_field *f2, const int type)
Definition: strings.c:145
#define INSPECT_LEADING
Definition: strings.c:39

Here is the call graph for this function:

void cob_inspect_start ( void  )

Definition at line 263 of file strings.c.

References inspect_data, inspect_end, inspect_size, and inspect_start.

Referenced by cobxref_(), GCic_(), and LISTING_().

264 {
267 }
static unsigned char * inspect_data
Definition: strings.c:58
static size_t inspect_size
Definition: strings.c:63
static unsigned char * inspect_end
Definition: strings.c:60
static unsigned char * inspect_start
Definition: strings.c:59

Here is the caller graph for this function:

void cob_inspect_trailing ( cob_field f1,
cob_field f2 
)

Definition at line 347 of file strings.c.

References inspect_common(), and INSPECT_TRAILING.

348 {
350 }
static void inspect_common(cob_field *f1, cob_field *f2, const int type)
Definition: strings.c:145
#define INSPECT_TRAILING
Definition: strings.c:41

Here is the call graph for this function:

static COB_INLINE int cob_min_int ( const int  x,
const int  y 
)
static

Definition at line 95 of file strings.c.

Referenced by cob_unstring_into().

96 {
97  if (x < y) {
98  return x;
99  }
100  return y;
101 }

Here is the caller graph for this function:

static void cob_str_memcpy ( cob_field dst,
unsigned char *  src,
const int  size 
)
static

Definition at line 104 of file strings.c.

References cob_field::attr, cob_move(), const_alpha_attr, cob_field::data, and cob_field::size.

Referenced by cob_unstring_into().

105 {
106  cob_field temp;
107 
108  temp.size = size;
109  temp.data = src;
110  temp.attr = &const_alpha_attr;
111  cob_move (&temp, dst);
112 }
void cob_move(cob_field *, cob_field *)
Definition: move.c:1170
static const cob_field_attr const_alpha_attr
Definition: strings.c:52
unsigned char * data
Definition: common.h:952
size_t size
Definition: common.h:951
const cob_field_attr * attr
Definition: common.h:953

Here is the call graph for this function:

Here is the caller graph for this function:

void cob_string_append ( cob_field src)

Definition at line 440 of file strings.c.

References COB_EC_OVERFLOW_STRING, cob_get_exception_code(), cob_set_exception(), cob_field::data, cob_field::size, and string_offset.

Referenced by cobxref_(), GCic_(), and LISTING_().

441 {
442  size_t src_size;
443  int i;
444  int size;
445 
446  if (cob_get_exception_code ()) {
447  return;
448  }
449 
450  src_size = src->size;
451  if (!src_size) {
452  return;
453  }
454  if (string_dlm) {
455  size = (int)(src_size - string_dlm->size + 1);
456  for (i = 0; i < size; ++i) {
457  if (memcmp (src->data + i, string_dlm->data,
458  string_dlm->size) == 0) {
459  src_size = i;
460  break;
461  }
462  }
463  }
464 
465  if (src_size <= string_dst->size - string_offset) {
466  memcpy (string_dst->data + string_offset, src->data, src_size);
467  string_offset += (int) src_size;
468  } else {
469  size = (int)(string_dst->size - string_offset);
470  memcpy (string_dst->data + string_offset, src->data, (size_t)size);
471  string_offset += size;
473  }
474 }
unsigned char * data
Definition: common.h:952
static cob_field * string_dst
Definition: strings.c:68
int cob_get_exception_code(void)
Definition: common.c:1193
void cob_set_exception(const int id)
Definition: common.c:1212
size_t size
Definition: common.h:951
static int string_offset
Definition: strings.c:74
static cob_field * string_dlm
Definition: strings.c:70

Here is the call graph for this function:

Here is the caller graph for this function:

void cob_string_delimited ( cob_field dlm)

Definition at line 430 of file strings.c.

References NULL, and string_dlm_copy.

Referenced by cobxref_(), GCic_(), and LISTING_().

431 {
432  string_dlm = NULL;
433  if (dlm) {
434  string_dlm_copy = *dlm;
436  }
437 }
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
static cob_field string_dlm_copy
Definition: strings.c:73
static cob_field * string_dlm
Definition: strings.c:70

Here is the caller graph for this function:

void cob_string_finish ( void  )

Definition at line 477 of file strings.c.

References cob_set_int(), and string_offset.

Referenced by cobxref_(), GCic_(), and LISTING_().

478 {
479  if (string_ptr) {
481  }
482 }
static cob_field * string_ptr
Definition: strings.c:69
void cob_set_int(cob_field *, const int)
Definition: move.c:1612
static int string_offset
Definition: strings.c:74

Here is the call graph for this function:

Here is the caller graph for this function:

void cob_string_init ( cob_field dst,
cob_field ptr 
)

Definition at line 408 of file strings.c.

References COB_EC_OVERFLOW_STRING, cob_get_int(), cob_set_exception(), NULL, cob_field::size, string_dst_copy, string_offset, and string_ptr_copy.

Referenced by cobxref_(), GCic_(), and LISTING_().

409 {
410  string_dst_copy = *dst;
412  string_ptr = NULL;
413  if (ptr) {
414  string_ptr_copy = *ptr;
416  }
417  string_offset = 0;
418  cob_set_exception (0);
419 
420  if (string_ptr) {
422  if (string_offset < 0 ||
423  string_offset >= (int)string_dst->size) {
425  }
426  }
427 }
static cob_field * string_ptr
Definition: strings.c:69
int cob_get_int(cob_field *)
Definition: move.c:1626
static cob_field * string_dst
Definition: strings.c:68
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
static cob_field string_ptr_copy
Definition: strings.c:72
void cob_set_exception(const int id)
Definition: common.c:1212
static cob_field string_dst_copy
Definition: strings.c:71
size_t size
Definition: common.h:951
static int string_offset
Definition: strings.c:74

Here is the call graph for this function:

Here is the caller graph for this function:

void cob_unstring_delimited ( cob_field dlm,
const cob_u32_t  all 
)

Definition at line 516 of file strings.c.

References dlm_struct::uns_all, dlm_struct::uns_dlm, and unstring_ndlms.

517 {
520  unstring_ndlms++;
521 }
static struct dlm_struct * dlm_list
Definition: strings.c:76
cob_field uns_dlm
Definition: strings.c:46
static int unstring_ndlms
Definition: strings.c:84
cob_u32_t uns_all
Definition: strings.c:47
void cob_unstring_finish ( void  )

Definition at line 620 of file strings.c.

References COB_EC_OVERFLOW_UNSTRING, cob_set_exception(), cob_set_int(), cob_field::size, and unstring_offset.

Referenced by cobxref_(), GCic_(), get__reserved__lists_(), and LISTING_().

621 {
622  if (unstring_offset < (int)unstring_src->size) {
624  }
625 
626  if (unstring_ptr) {
628  }
629 }
static int unstring_offset
Definition: strings.c:82
static cob_field * unstring_ptr
Definition: strings.c:78
void cob_set_exception(const int id)
Definition: common.c:1212
void cob_set_int(cob_field *, const int)
Definition: move.c:1612
size_t size
Definition: common.h:951
static cob_field * unstring_src
Definition: strings.c:77

Here is the call graph for this function:

Here is the caller graph for this function:

void cob_unstring_init ( cob_field src,
cob_field ptr,
const size_t  num_dlm 
)

Definition at line 487 of file strings.c.

References COB_EC_OVERFLOW_UNSTRING, cob_free(), cob_get_int(), cob_malloc(), cob_set_exception(), dlm_list_size, NULL, cob_field::size, unstring_count, unstring_ndlms, unstring_offset, unstring_ptr_copy, and unstring_src_copy.

Referenced by cobxref_(), GCic_(), get__reserved__lists_(), and LISTING_().

488 {
489  unstring_src_copy = *src;
491  unstring_ptr = NULL;
492  if (ptr) {
493  unstring_ptr_copy = *ptr;
495  }
496 
497  unstring_offset = 0;
498  unstring_count = 0;
499  unstring_ndlms = 0;
500  cob_set_exception (0);
501  if (num_dlm > dlm_list_size) {
502  cob_free (dlm_list);
503  dlm_list = cob_malloc (num_dlm * sizeof(struct dlm_struct));
504  dlm_list_size = num_dlm;
505  }
506 
507  if (unstring_ptr) {
509  if (unstring_offset < 0 || unstring_offset >= (int)unstring_src->size) {
511  }
512  }
513 }
void cob_free(void *mptr)
Definition: common.c:1284
static int unstring_offset
Definition: strings.c:82
static int unstring_count
Definition: strings.c:83
int cob_get_int(cob_field *)
Definition: move.c:1626
static struct dlm_struct * dlm_list
Definition: strings.c:76
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
static cob_field * unstring_ptr
Definition: strings.c:78
void cob_set_exception(const int id)
Definition: common.c:1212
static size_t dlm_list_size
Definition: strings.c:79
static int unstring_ndlms
Definition: strings.c:84
size_t size
Definition: common.h:951
void * cob_malloc(const size_t size)
Definition: common.c:1250
static cob_field unstring_ptr_copy
Definition: strings.c:81
static cob_field unstring_src_copy
Definition: strings.c:80
static cob_field * unstring_src
Definition: strings.c:77

Here is the call graph for this function:

Here is the caller graph for this function:

void cob_unstring_into ( cob_field dst,
cob_field dlm,
cob_field cnt 
)

Definition at line 524 of file strings.c.

References COB_FIELD_IS_NUMERIC, COB_FIELD_SIZE, cob_get_exception_code(), cob_min_int(), cob_set_int(), cob_str_memcpy(), cob_field::data, NULL, cob_field::size, dlm_struct::uns_all, dlm_struct::uns_dlm, unstring_count, unstring_ndlms, and unstring_offset.

Referenced by cobxref_(), GCic_(), get__reserved__lists_(), and LISTING_().

525 {
526  unsigned char *p;
527  unsigned char *dp;
528  unsigned char *s;
529  unsigned char *dlm_data;
530  unsigned char *start;
531  size_t dlm_size = 0;
532  int i;
533  int srsize;
534  int dlsize;
535  int match_size = 0;
536  int brkpt = 0;
537 
538  if (cob_get_exception_code ()) {
539  return;
540  }
541 
542  if (unstring_offset >= (int)unstring_src->size) {
543  return;
544  }
545 
546  start = unstring_src->data + unstring_offset;
547  dlm_data = NULL;
548  if (unstring_ndlms == 0) {
549  match_size = cob_min_int ((int)COB_FIELD_SIZE (dst),
551  cob_str_memcpy (dst, start, match_size);
552  unstring_offset += match_size;
553  } else {
554  srsize = (int) unstring_src->size;
555  s = unstring_src->data + srsize;
556  for (p = start; p < s; ++p) {
557  for (i = 0; i < unstring_ndlms; ++i) {
558  dlsize = (int) dlm_list[i].uns_dlm.size;
559  dp = dlm_list[i].uns_dlm.data;
560  if (p + dlsize > s) {
561  continue;
562  }
563  if (!memcmp (p, dp, (size_t)dlsize)) { /* delimiter equal */
564  match_size = (int)(p - start); /* count in */
565  cob_str_memcpy (dst, start, match_size); /* into */
566  unstring_offset += match_size + dlsize; /* with pointer */
567  dlm_data = dp;
568  dlm_size = dlsize;
569  if (dlm_list[i].uns_all) { /* delimited by all */
570  for (p += dlsize ; p < s; p += dlsize) {
571  if (p + dlsize > s) {
572  break;
573  }
574  if (memcmp (p, dp, (size_t)dlsize)) {
575  break;
576  }
577  unstring_offset += dlsize;
578  }
579  }
580  brkpt = 1;
581  break;
582  }
583  }
584  if (brkpt) {
585  break;
586  }
587  }
588  if (!brkpt) {
589  /* No match */
590  match_size = (int)(unstring_src->size - unstring_offset);
591  cob_str_memcpy (dst, start, match_size);
593  dlm_data = NULL;
594  }
595  }
596  unstring_count++;
597 
598  if (dlm) {
599  if (dlm_data) {
600  cob_str_memcpy (dlm, dlm_data, (int) dlm_size);
601  } else if (COB_FIELD_IS_NUMERIC (dlm)) {
602  cob_set_int (dlm, 0);
603  } else {
604  memset (dlm->data, ' ', dlm->size);
605  }
606  }
607 
608  if (cnt) {
609  cob_set_int (cnt, match_size);
610  }
611 }
static int unstring_offset
Definition: strings.c:82
static void cob_str_memcpy(cob_field *dst, unsigned char *src, const int size)
Definition: strings.c:104
#define COB_FIELD_IS_NUMERIC(f)
Definition: common.h:674
static int unstring_count
Definition: strings.c:83
unsigned char * data
Definition: common.h:952
static COB_INLINE int cob_min_int(const int x, const int y)
Definition: strings.c:95
static struct dlm_struct * dlm_list
Definition: strings.c:76
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
int cob_get_exception_code(void)
Definition: common.c:1193
void cob_set_int(cob_field *, const int)
Definition: move.c:1612
cob_field uns_dlm
Definition: strings.c:46
static int unstring_ndlms
Definition: strings.c:84
size_t size
Definition: common.h:951
static cob_field * unstring_src
Definition: strings.c:77
#define COB_FIELD_SIZE(f)
Definition: common.h:671

Here is the call graph for this function:

Here is the caller graph for this function:

void cob_unstring_tallying ( cob_field f)

Definition at line 614 of file strings.c.

References cob_add_int(), and unstring_count.

615 {
616  cob_add_int (f, unstring_count, 0);
617 }
int cob_add_int(cob_field *, const int, const int)
Definition: numeric.c:2195
static int unstring_count
Definition: strings.c:83

Here is the call graph for this function:

static void inspect_common ( cob_field f1,
cob_field f2,
const int  type 
)
static

Definition at line 145 of file strings.c.

References alloc_figurative(), alpha_fld, cob_add_int(), COB_EC_RANGE_INSPECT_SIZE, COB_FIELD_TYPE, cob_set_exception(), COB_TYPE_ALPHANUMERIC_ALL, cob_field::data, inspect_data, inspect_end, INSPECT_FIRST, INSPECT_LEADING, inspect_mark, inspect_replacing, inspect_start, INSPECT_TRAILING, cob_field::size, str_cob_low, and unlikely.

Referenced by cob_inspect_all(), cob_inspect_first(), cob_inspect_leading(), and cob_inspect_trailing().

146 {
147  int *mark;
148  size_t n = 0;
149  size_t j;
150  int i;
151  int len;
152 
153  if (unlikely(!f1)) {
154  f1 = &str_cob_low;
155  }
156  if (unlikely(!f2)) {
157  f2 = &str_cob_low;
158  }
159 
160  if (inspect_replacing && f1->size != f2->size) {
162  alloc_figurative (f1, f2);
163  f1 = &alpha_fld;
164  } else {
166  return;
167  }
168  }
169 
171  len = (int)(inspect_end - inspect_start);
172  if (type == INSPECT_TRAILING) {
173  for (i = len - (int)f2->size; i >= 0; --i) {
174  /* Find matching substring */
175  if (memcmp (inspect_start + i, f2->data, f2->size) == 0) {
176  /* Check if it is already marked */
177  for (j = 0; j < f2->size; ++j) {
178  if (mark[i + j] != -1) {
179  break;
180  }
181  }
182  /* If not, mark and count it */
183  if (j == f2->size) {
184  for (j = 0; j < f2->size; ++j) {
185  mark[i + j] = inspect_replacing ? f1->data[j] : 1;
186  }
187  i -= f2->size - 1;
188  n++;
189  }
190  } else {
191  break;
192  }
193  }
194  } else {
195  for (i = 0; i < (int)(len - f2->size + 1); ++i) {
196  /* Find matching substring */
197  if (memcmp (inspect_start + i, f2->data, f2->size) == 0) {
198  /* Check if it is already marked */
199  for (j = 0; j < f2->size; ++j) {
200  if (mark[i + j] != -1) {
201  break;
202  }
203  }
204  /* If not, mark and count it */
205  if (j == f2->size) {
206  for (j = 0; j < f2->size; ++j) {
207  mark[i + j] = inspect_replacing ? f1->data[j] : 1;
208  }
209  i += f2->size - 1;
210  n++;
211  if (type == INSPECT_FIRST) {
212  break;
213  }
214  }
215  } else if (type == INSPECT_LEADING) {
216  break;
217  }
218  }
219  }
220 
221  if (n > 0 && !inspect_replacing) {
222  cob_add_int (f1, (int) n, 0);
223  }
224 }
static unsigned char * inspect_data
Definition: strings.c:58
int cob_add_int(cob_field *, const int, const int)
Definition: numeric.c:2195
#define COB_FIELD_TYPE(f)
Definition: common.h:662
static cob_field str_cob_low
Definition: strings.c:90
#define INSPECT_FIRST
Definition: strings.c:40
#define INSPECT_TRAILING
Definition: strings.c:41
unsigned char * data
Definition: common.h:952
static int * inspect_mark
Definition: strings.c:61
#define unlikely(x)
Definition: common.h:437
static cob_field alpha_fld
Definition: strings.c:89
void cob_set_exception(const int id)
Definition: common.c:1212
static void alloc_figurative(const cob_field *f1, const cob_field *f2)
Definition: strings.c:115
static unsigned char * inspect_end
Definition: strings.c:60
#define COB_TYPE_ALPHANUMERIC_ALL
Definition: common.h:622
static cob_u32_t inspect_replacing
Definition: strings.c:64
#define INSPECT_LEADING
Definition: strings.c:39
size_t size
Definition: common.h:951
static unsigned char * inspect_start
Definition: strings.c:59

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

cob_field alpha_fld
static

Definition at line 89 of file strings.c.

Referenced by cob_inspect_converting(), and inspect_common().

const cob_field_attr const_alpha_attr
static
Initial value:
=
{COB_TYPE_ALPHANUMERIC, 0, 0, 0, ((void*)0) }
#define COB_TYPE_ALPHANUMERIC
Definition: common.h:621

Definition at line 52 of file strings.c.

Referenced by cob_init_strings(), and cob_str_memcpy().

const cob_field_attr const_strall_attr
static
Initial value:
=
{COB_TYPE_ALPHANUMERIC_ALL, 0, 0, 0, ((void*)0) }
#define COB_TYPE_ALPHANUMERIC_ALL
Definition: common.h:622

Definition at line 54 of file strings.c.

Referenced by cob_init_strings().

struct dlm_struct* dlm_list
static

Definition at line 76 of file strings.c.

size_t dlm_list_size
static

Definition at line 79 of file strings.c.

Referenced by cob_init_strings(), and cob_unstring_init().

unsigned char* figurative_ptr
static

Definition at line 86 of file strings.c.

Referenced by alloc_figurative(), cob_exit_strings(), and cob_init_strings().

size_t figurative_size
static

Definition at line 87 of file strings.c.

Referenced by alloc_figurative(), cob_exit_strings(), and cob_init_strings().

unsigned char* inspect_data
static
size_t inspect_mark_size
static

Definition at line 62 of file strings.c.

Referenced by cob_init_strings(), and cob_inspect_init().

cob_u32_t inspect_replacing
static
int inspect_sign
static

Definition at line 65 of file strings.c.

Referenced by cob_inspect_finish(), and cob_inspect_init().

size_t inspect_size
static

Definition at line 63 of file strings.c.

Referenced by cob_inspect_finish(), cob_inspect_init(), and cob_inspect_start().

cob_field* inspect_var
static

Definition at line 57 of file strings.c.

cob_field inspect_var_copy
static

Definition at line 66 of file strings.c.

Referenced by cob_inspect_init().

cob_field str_cob_low
static

Definition at line 90 of file strings.c.

Referenced by cob_inspect_converting(), and inspect_common().

cob_field* string_dlm
static

Definition at line 70 of file strings.c.

cob_field string_dlm_copy
static

Definition at line 73 of file strings.c.

Referenced by cob_string_delimited().

cob_field* string_dst
static

Definition at line 68 of file strings.c.

cob_field string_dst_copy
static

Definition at line 71 of file strings.c.

Referenced by cob_string_init().

int string_offset
static

Definition at line 74 of file strings.c.

Referenced by cob_string_append(), cob_string_finish(), and cob_string_init().

cob_field* string_ptr
static

Definition at line 69 of file strings.c.

cob_field string_ptr_copy
static

Definition at line 72 of file strings.c.

Referenced by cob_string_init().

int unstring_count
static

Definition at line 83 of file strings.c.

Referenced by cob_unstring_init(), cob_unstring_into(), and cob_unstring_tallying().

int unstring_ndlms
static

Definition at line 84 of file strings.c.

Referenced by cob_unstring_delimited(), cob_unstring_init(), and cob_unstring_into().

int unstring_offset
static

Definition at line 82 of file strings.c.

Referenced by cob_unstring_finish(), cob_unstring_init(), and cob_unstring_into().

cob_field* unstring_ptr
static

Definition at line 78 of file strings.c.

cob_field unstring_ptr_copy
static

Definition at line 81 of file strings.c.

Referenced by cob_unstring_init().

cob_field* unstring_src
static

Definition at line 77 of file strings.c.

cob_field unstring_src_copy
static

Definition at line 80 of file strings.c.

Referenced by cob_unstring_init().