aboutsummaryrefslogtreecommitdiff
path: root/src/EOS_Utils.c
blob: 815a665b37d97766132f78c64f006d3931c13cb1 (plain)
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
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>

#include "cctk.h"
#include "cctk_Parameters.h"
#include "cctk_Arguments.h"

#include "util_String.h"
#include "util_ErrorCodes.h"
#include "util_Table.h"

 /*@@
   @routine    EOS_StrSep
   @date       Wed Mar  2 14:57:50 2005
   @author     Ian Hawke
   @desc 
   A wrapper to Util_StrSep that returns the last token if there 
   are no more delimiters. Note that the documentation is incorrect;
   delim_set (here delim) cannot be a set but must be a single 
   character.
   @enddesc 
   @calls     
   @calledby   
   @history 
 
   @endhistory 

@@*/


const char * EOS_StrSep(const char ** string_ptr, const char * delim);

const char * EOS_StrSep(const char ** string_ptr, const char * delim)
{
  
  const char * token;
  const char ** string;
  
  string = string_ptr;
  
  if (string == NULL)
  {
    return NULL;
  }
  
  token = Util_StrSep(string_ptr, delim);
  
  if ( (token == NULL) && (strlen(*string) > 0) && 
       (!(CCTK_Equals(*string, "\n"))) )
  {
    string_ptr = string;
    token = Util_StrSep(string_ptr, "\n");
    if ( (token == NULL) && (strlen(*string) > 0) )
    {
      string_ptr = '\0';
      token = *string;
    } 
  }

#ifdef EOS_GTR_DEBUG
  printf("EOS_StrSep: token '%s' and string_ptr '%s' (%s)\n",
         token, *string_ptr, *string);
#endif

  return token;
}