/loggerouter/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/loggerouter/trunk

« back to all changes in this revision

Viewing changes to src/tools.vala

  • Committer: Gustav Hartvigsson
  • Date: 2025-06-04 14:25:01 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20250604142501-uhe0ukoxuwcku2bt
Fixed crash caused from missing config file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
  }
32
32
 
33
33
  public static string str_escape_enviorment_variables (string str ) {
34
 
    return str;
 
34
    StringBuilder builder = new StringBuilder ();
 
35
    var enviorment = GLib.Environ.@get ();
 
36
 
 
37
    if (str_starts_with (str, "/")) {
 
38
      builder.append_c ('/');
 
39
    }
 
40
 
 
41
    var tokens = str.split ("/");
 
42
    builder.append (tokens[0]);
 
43
 
 
44
    for (size_t i = 1; i <= tokens.length; i++) {
 
45
      var t = tokens[i];
 
46
 
 
47
      if (str_starts_with (str, "$")) {
 
48
        builder.append (GLib.Environ.get_variable (enviorment, t));
 
49
      } else {
 
50
        builder.append (t);
 
51
      }
 
52
    }
 
53
 
 
54
    if (str_ends_with (str, "/")) {
 
55
      builder.append_c ('/');
 
56
    }
 
57
 
 
58
    return builder.str;
35
59
  }
36
60
 
37
61
 
100
124
    return true;
101
125
  }
102
126
 
 
127
  bool str_ends_with (string stack, string needle) {
 
128
    if (stack.length < needle.length) {
 
129
      return false;
 
130
    }
 
131
    long stack_len = stack.length;
 
132
    for (long i = needle.length; i > 0; i--) {
 
133
      if (stack[i] != needle[stack_len]) {
 
134
        return false;
 
135
      }
 
136
      stack_len--;
 
137
    }
 
138
    return true;
 
139
  }
 
140
 
103
141
 
104
142
  string resolve_path (string path) {
105
143
    string base_dir;