summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeder Andersen2012-11-12 17:33:38 (EST)
committer Eugene Tarassov2012-11-14 19:55:54 (EST)
commit608f210f6c0d23a27761e96a21321b16cb6287e5 (patch)
treec133568f7d976b47ae47ba1fabe147400e73c552
parent97cf26b2a706e4967a2ab75a4f674bd50c7f6bda (diff)
downloadorg.eclipse.tcf.agent-608f210f6c0d23a27761e96a21321b16cb6287e5.zip
org.eclipse.tcf.agent-608f210f6c0d23a27761e96a21321b16cb6287e5.tar.gz
org.eclipse.tcf.agent-608f210f6c0d23a27761e96a21321b16cb6287e5.tar.bz2
pathmap: factor out tests for path separators
In an effort to simplify/clarify a number of conditionals, wrap tests for path separators in a function call.
-rw-r--r--agent/tcf/services/pathmap.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/agent/tcf/services/pathmap.c b/agent/tcf/services/pathmap.c
index cf1b863..345ce5b 100644
--- a/agent/tcf/services/pathmap.c
+++ b/agent/tcf/services/pathmap.c
@@ -26,6 +26,11 @@
#include <tcf/services/contextquery.h>
#include <tcf/services/pathmap.h>
+
+static int is_separator(const char c) {
+ return ((c == '/') || (c == '\\'));
+}
+
char * canonic_path_map_file_name(const char * fnm) {
char * buf;
size_t buf_pos = 0;
@@ -39,11 +44,11 @@ char * canonic_path_map_file_name(const char * fnm) {
if (ch == '/' && buf_pos >= 2 && buf[buf_pos - 1] == '/') continue;
if (ch == '/' && *fnm == 0 && buf_pos > 0 && buf[buf_pos - 1] != ':') break;
if (ch == '.' && (buf_pos == 0 || buf[buf_pos - 1] == '/')) {
- if (*fnm == '/' || *fnm == '\\') {
+ if (is_separator(*fnm)) {
fnm++;
continue;
}
- if (buf_pos > 0 && *fnm == '.' && (fnm[1] == '/' || fnm[1] == '\\')) {
+ if (buf_pos > 0 && *fnm == '.' && is_separator(fnm[1])) {
size_t j = buf_pos - 1;
if (j > 0 && buf[j - 1] != '/') {
buf[buf_pos] = 0;
@@ -351,16 +356,16 @@ static char * map_file_name(Context * ctx, PathMap * m, char * fnm, int mode) {
} else {
const size_t dst_len = strlen(r->dst);
const char last_dest_char = dst_len == 0 ? 0 : r->dst[dst_len - 1];
- if (fnm[k] != '/' && fnm[k] != '\\') {
- if (!(last_dest_char == '/' || last_dest_char == '\\')) {
+ if (!is_separator(fnm[k])) {
+ if (!is_separator(last_dest_char)) {
const char last_src_char = k == 0 ? 0 : r->src[k - 1];
- if (!(last_src_char == '/' || last_src_char == '\\'))
+ if (!is_separator(last_src_char))
/* prevent matching mid-filename */
continue;
}
/* re-add initial path separator */
--k;
- } else if (last_dest_char == '/' || last_dest_char == '\\')
+ } else if (is_separator(last_dest_char))
/* strip extra path separator */
++k;