/* Copyright (C) 1997-2001 Id Software, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // // shared.c // #include "shared.h" /* ============================================================================== PARSING ============================================================================== */ /* ============ Com_Parse Parse a token out of a string ============ */ static char com_token[MAX_TOKEN_CHARS]; char *Com_Parse (char **dataPtr) { int c; int len; char *data; data = *dataPtr; len = 0; com_token[0] = 0; if (!data) { *dataPtr = NULL; return ""; } // Skip whitespace skipwhite: while ((c = *data) <= ' ') { if (c == 0) { *dataPtr = NULL; return ""; } data++; } // Skip // comments if (c == '/' && data[1] == '/') { while (*data && *data != '\n') data++; goto skipwhite; } // Handle quoted strings specially if (c == '\"') { data++; for ( ; ; ) { c = *data++; if (c == '\"' || !c) { com_token[len] = 0; *dataPtr = data; return com_token; } if (len < MAX_TOKEN_CHARS) { com_token[len] = c; len++; } } } // Parse a regular word do { if (len < MAX_TOKEN_CHARS) { com_token[len] = c; len++; } data++; c = *data; } while (c > 32); if (len >= MAX_TOKEN_CHARS) len = 0; com_token[len] = 0; *dataPtr = data; return com_token; } /* ============ Com_DefaultExtension If there is no extnsion in 'path', suffix 'extension'. ============ */ void Com_DefaultExtension (char *path, char *extension, size_t size) { char *src; if (!path[0]) return; // If path doesn't have an .ext, append extension (extension should include the .) src = path + strlen (path) - 1; while (*src != '/' && src != path) { if (*src == '.') return; // It has an extension src--; } Q_strcatz (path, extension, size); } /* ============ Com_FileBase ============ */ void Com_FileBase (char *in, char *out) { char *s, *s2; s = in + strlen(in) - 1; while (s != in && *s != '.') s--; for (s2=s ; s2 != in && *s2 != '/' ; s2--) ; if (s-s2 < 2) { out[0] = 0; } else { s--; strncpy (out, s2+1, s-s2); out[s-s2] = 0; } } /* ============ Com_FileExtension ============ */ void Com_FileExtension (char *path, char *out, size_t size) { uint32 i; while (*path && *path != '.') path++; if (!*path) return; path++; for (i=0 ; i