diff options
author | Jeremias Stotter <jeremias@stotter.eu> | 2023-10-15 15:53:46 +0200 |
---|---|---|
committer | Jeremias Stotter <jeremias@stotter.eu> | 2023-10-15 15:53:46 +0200 |
commit | bd3685fbcf2c07af1f72e56b8976e59796d41395 (patch) | |
tree | 414b9ff7c4dffa7d4498e2953a85cbc686743b56 | |
parent | d77caf955f15e1f28c26b6657c1727ac138bf0ed (diff) | |
download | network-simulator-bd3685fbcf2c07af1f72e56b8976e59796d41395.tar.gz network-simulator-bd3685fbcf2c07af1f72e56b8976e59796d41395.tar.bz2 network-simulator-bd3685fbcf2c07af1f72e56b8976e59796d41395.zip |
Fix devices getting the same name after copying
-rw-r--r-- | gui.c | 10 |
1 files changed, 10 insertions, 0 deletions
@@ -1157,7 +1157,17 @@ void copy_selection_clipboard(struct device_selection* selection) { continue; // Create the new device char* dev_name = malloc_or_abort(strlen(dev->name) + strlen(COPY_SUFFIX) + 1); + // Check if device with this name already exists sprintf(dev_name, "%s"COPY_SUFFIX, dev->name); + if(dev_from_name(start_device, dev_name)) { + char* dev_name_new = malloc_or_abort(strlen(dev_name) + 4); + strcpy(dev_name_new, dev_name); + for(int i = 1; dev_from_name(start_device, dev_name_new) && i < 100; i++) { + sprintf(dev_name_new, "%s %d", dev_name, i); + } + free(dev_name); + dev_name = dev_name_new; + } struct device* new_dev = new_device(&clipboard, dev_name, selected_device_template, false); // Load the state // Ask the old device to save its state and pass it to the new device |