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
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 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 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
21 * @file transport-testing-filenames.c
22 * @brief convenience string manipulation functions for tests
23 * @author Matthias Wachs
24 * @author Christian Grothoff
26 #include "transport-testing.h"
30 * Removes all directory separators from absolute filename
32 * @param file the absolute file name, e.g. as found in argv[0]
33 * @return extracted file name, has to be freed by caller
36 extract_filename (const char *file)
38 char *pch = GNUNET_strdup (file);
40 char *filename = NULL;
44 if ((strlen (pch) >= 3) && pch[1] == ':')
46 if (NULL != strstr (pch, "\\"))
48 pch = strtok (pch, "\\");
51 pch = strtok (NULL, "\\");
58 pch = filename; /* If we miss the next condition, filename = pch will
62 if (NULL != strstr (pch, "/"))
64 pch = strtok (pch, "/");
67 pch = strtok (NULL, "/");
77 res = GNUNET_strdup (filename);
84 * Extracts the test filename from an absolute file name and removes
87 * @param file absolute file name
91 GNUNET_TRANSPORT_TESTING_get_test_name (const char *file)
93 char *backup = extract_filename (file);
94 char *filename = backup;
102 filename = strstr (filename, "test");
103 if (NULL == filename)
105 GNUNET_free (backup);
110 if (NULL != (dotexe = strstr (filename, ".exe")))
112 ret = GNUNET_strdup (filename);
113 GNUNET_free (backup);
119 * Extracts the filename from an absolute file name and removes the extension
121 * @param file absolute file name
125 GNUNET_TRANSPORT_TESTING_get_test_source_name (const char *file)
127 char *src = extract_filename (file);
130 split = strstr (src, ".");
138 * Extracts the plugin name from an absolute file name and the test name
140 * @param file absolute file name
141 * @param test test name
145 GNUNET_TRANSPORT_TESTING_get_test_plugin_name (const char *file,
150 char *e = extract_filename (file);
151 char *t = extract_filename (test);
157 filename = strstr (e, "tes");
158 if (NULL == filename)
161 if (NULL != (dotexe = strstr (filename, ".exe")))
165 filename = strstr (filename, t);
166 if (NULL == filename)
169 filename += strlen (t);
170 if ('\0' != *filename)
172 ret = GNUNET_strdup (filename);
184 * This function takes the filename (e.g. argv[0), removes a "lt-"-prefix and
185 * if existing ".exe"-prefix and adds the peer-number
187 * @param file filename of the test, e.g. argv[0]
188 * @param count peer number
192 GNUNET_TRANSPORT_TESTING_get_config_name (const char *file,
195 char *filename = extract_filename (file);
196 char *backup = filename;
200 if (NULL == filename)
203 filename = strstr (filename, "test");
204 if (NULL == filename)
207 if (NULL != (dotexe = strstr (filename, ".exe")))
209 GNUNET_asprintf (&ret,
213 GNUNET_free (backup);
216 GNUNET_free (backup);
221 /* end of transport-testing-filenames.c */