2 This file is part of GNUnet.
3 Copyright (C) 2006, 2009, 2015, 2016 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
16 * @file transport-testing-filenames.c
17 * @brief convenience string manipulation functions for tests
18 * @author Matthias Wachs
19 * @author Christian Grothoff
21 #include "transport-testing.h"
25 * Removes all directory separators from absolute filename
27 * @param file the absolute file name, e.g. as found in argv[0]
28 * @return extracted file name, has to be freed by caller
31 extract_filename (const char *file)
33 char *pch = GNUNET_strdup (file);
35 char *filename = NULL;
39 if ((strlen (pch) >= 3) && pch[1] == ':')
41 if (NULL != strstr (pch, "\\"))
43 pch = strtok (pch, "\\");
46 pch = strtok (NULL, "\\");
53 pch = filename; /* If we miss the next condition, filename = pch will
57 if (NULL != strstr (pch, "/"))
59 pch = strtok (pch, "/");
62 pch = strtok (NULL, "/");
72 res = GNUNET_strdup (filename);
79 * Extracts the test filename from an absolute file name and removes
82 * @param file absolute file name
86 GNUNET_TRANSPORT_TESTING_get_test_name (const char *file)
88 char *backup = extract_filename (file);
89 char *filename = backup;
97 filename = strstr (filename, "test");
100 GNUNET_free (backup);
105 if (NULL != (dotexe = strstr (filename, ".exe")))
107 ret = GNUNET_strdup (filename);
108 GNUNET_free (backup);
114 * Extracts the filename from an absolute file name and removes the extension
116 * @param file absolute file name
120 GNUNET_TRANSPORT_TESTING_get_test_source_name (const char *file)
122 char *src = extract_filename (file);
125 split = strstr (src, ".");
133 * Extracts the plugin name from an absolute file name and the test name
135 * @param file absolute file name
136 * @param test test name
140 GNUNET_TRANSPORT_TESTING_get_test_plugin_name (const char *file,
145 char *e = extract_filename (file);
146 char *t = extract_filename (test);
152 filename = strstr (e, "tes");
153 if (NULL == filename)
156 if (NULL != (dotexe = strstr (filename, ".exe")))
160 filename = strstr (filename, t);
161 if (NULL == filename)
164 filename += strlen (t);
165 if ('\0' != *filename)
167 ret = GNUNET_strdup (filename);
179 * This function takes the filename (e.g. argv[0), removes a "lt-"-prefix and
180 * if existing ".exe"-prefix and adds the peer-number
182 * @param file filename of the test, e.g. argv[0]
183 * @param count peer number
187 GNUNET_TRANSPORT_TESTING_get_config_name (const char *file,
190 char *filename = extract_filename (file);
191 char *backup = filename;
195 if (NULL == filename)
198 filename = strstr (filename, "test");
199 if (NULL == filename)
202 if (NULL != (dotexe = strstr (filename, ".exe")))
204 GNUNET_asprintf (&ret,
208 GNUNET_free (backup);
211 GNUNET_free (backup);
216 /* end of transport-testing-filenames.c */