| 1 | /* |
| 2 | * Descent 3 |
| 3 | * Copyright (C) 2024 Parallax Software |
| 4 | * |
| 5 | * This program is free software: you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation, either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | |
| 18 | --- HISTORICAL COMMENTS FOLLOW --- |
| 19 | |
| 20 | * $Logfile: /DescentIII/Main/Editor/DallasUtilities.cpp $ |
| 21 | * $Revision: 1.1.1.1 $ |
| 22 | * $Date: 2003-08-26 03:57:37 $ |
| 23 | * $Author: kevinb $ |
| 24 | * |
| 25 | * Code for DALLAS related utility functions |
| 26 | * |
| 27 | * $Log: not supported by cvs2svn $ |
| 28 | * |
| 29 | * 6 6/09/99 7:06p Jeff |
| 30 | * stub functions added. #ifdef NEWEDITORs added, files changed, to get |
| 31 | * Dallas integrated into new editor |
| 32 | * |
| 33 | * 5 2/19/99 5:35p Nate |
| 34 | * Added new types and events |
| 35 | * |
| 36 | * 4 12/16/98 8:45p Nate |
| 37 | * Added loading of Actions |
| 38 | * |
| 39 | * 3 12/15/98 7:48p Nate |
| 40 | * Fixed minor buffering problem |
| 41 | * |
| 42 | * 2 12/14/98 12:45p Nate |
| 43 | * Initial Version |
| 44 | * |
| 45 | * $NoKeywords: $ |
| 46 | */ |
| 47 | |
| 48 | #include "stdafx.h" |
| 49 | |
| 50 | #include <string.h> |
| 51 | #include <ctype.h> |
| 52 | |
| 53 | #include "pserror.h" |
| 54 | #include "cfile.h" |
| 55 | #include "mem.h" |
| 56 | #include "mono.h" |
| 57 | #include "psglob.h" |
| 58 | #include "manage.h" |
| 59 | #include "gamefile.h" |
| 60 | |
| 61 | #include "DallasUtilities.h" |
| 62 | |
| 63 | // Removes any whitespace padding from the end of a string |
| 64 | void RemoveTrailingWhitespace(char *s) { |
| 65 | int last_char_pos; |
| 66 | |
| 67 | last_char_pos = strlen(s) - 1; |
| 68 | while (last_char_pos >= 0 && isspace(s[last_char_pos])) { |
| 69 | s[last_char_pos] = '\0'; |
| 70 | last_char_pos--; |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | // Returns a pointer to the first non-whitespace char in given string |
| 75 | char *SkipInitialWhitespace(char *s) { |
| 76 | while ((*s) != '\0' && isspace(*s)) |
| 77 | s++; |
| 78 | |
| 79 | return (s); |
| 80 | } |
| 81 | |
| 82 | class tFindInManage { |
| 83 | public: |
| 84 | tFindInManage() { searching = false; } |
| 85 | |
| 86 | bool searching; |
| 87 | bool in_Gamefiles; |
| 88 | int curr_index; |
| 89 | char glob_string[PAGENAME_LEN]; |
| 90 | }; |
| 91 | tFindInManage FindInManageData; |
| 92 | |
| 93 | bool FindManageFirst(char *buffer, char *wildcard) { |
| 94 | #ifndef NEWEDITOR |
| 95 | if (FindInManageData.searching) |
| 96 | FindManageClose(); |
| 97 | |
| 98 | FindInManageData.searching = true; |
| 99 | strcpy(FindInManageData.glob_string, wildcard); |
| 100 | FindInManageData.curr_index = 0; |
| 101 | FindInManageData.in_Gamefiles = true; |
| 102 | |
| 103 | return FindManageNext(buffer); |
| 104 | #else |
| 105 | return false; |
| 106 | #endif |
| 107 | } |
| 108 | |
| 109 | bool FindManageNext(char *buffer) { |
| 110 | #ifndef NEWEDITOR |
| 111 | if (!FindInManageData.searching) |
| 112 | return false; |
| 113 | |
| 114 | if (FindInManageData.in_Gamefiles) { |
| 115 | |
| 116 | for (; FindInManageData.curr_index < MAX_GAMEFILES; FindInManageData.curr_index++) { |
| 117 | if (Gamefiles[FindInManageData.curr_index].used && |
| 118 | PSGlobMatch(FindInManageData.glob_string, Gamefiles[FindInManageData.curr_index].name, false, false)) { |
| 119 | // match |
| 120 | strcpy(buffer, Gamefiles[FindInManageData.curr_index].name); |
| 121 | FindInManageData.curr_index++; |
| 122 | return true; |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | FindInManageData.curr_index = 0; |
| 127 | FindInManageData.in_Gamefiles = false; |
| 128 | } |
| 129 | |
| 130 | for (; FindInManageData.curr_index < MAX_TRACKLOCKS; FindInManageData.curr_index++) { |
| 131 | if (GlobalTrackLocks[FindInManageData.curr_index].used && |
| 132 | GlobalTrackLocks[FindInManageData.curr_index].pagetype == PAGETYPE_GAMEFILE && |
| 133 | PSGlobMatch(FindInManageData.glob_string, GlobalTrackLocks[FindInManageData.curr_index].name, false, false)) { |
| 134 | // match |
| 135 | strcpy(buffer, GlobalTrackLocks[FindInManageData.curr_index].name); |
| 136 | FindInManageData.curr_index++; |
| 137 | return true; |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | return false; |
| 142 | #else |
| 143 | return false; |
| 144 | #endif |
| 145 | } |
| 146 | |
| 147 | void FindManageClose(void) { |
| 148 | #ifndef NEWEDITOR |
| 149 | FindInManageData.searching = false; |
| 150 | #endif |
| 151 | } |
| 152 | |
| 153 | bool GamefileExists(char *name) { |
| 154 | bool found; |
| 155 | char buffer[PAGENAME_LEN + 1]; |
| 156 | |
| 157 | found = FindManageFirst(buffer, name); |
| 158 | FindManageClose(); |
| 159 | |
| 160 | return (found); |
| 161 | } |