void DefaultPath (char *path, const char *basepath, size_t len) { char temp[128]; if (path[0] == '/' || path[0] == '\\') return; // absolute path location if (path[0] != '\0' && path[1] == ':') return; // absolute path location, like c:\dir qerr_strlcpy(__thisfunc__, __LINE__, temp, path, sizeof(temp)); qerr_strlcpy(__thisfunc__, __LINE__, path, basepath, len); qerr_strlcat(__thisfunc__, __LINE__, path, temp, len); }
void Q_getwd (char *out, size_t size, qboolean trailing_dirsep) { size_t sz; if (getcwd(out, size) == NULL) COM_Error ("Couldn't determine current directory"); if (!trailing_dirsep) return; sz = strlen(out); if (!sz || out[sz - 1] == '/') return; qerr_strlcat(__thisfunc__, __LINE__, out, "/", size); }
void Q_getwd (char *out, size_t size, qboolean trailing_dirsep) { size_t sz; sz = GetCurrentDirectory(size, out); if (sz == 0 || sz > size) COM_Error ("Couldn't determine current directory"); if (!trailing_dirsep) return; sz = strlen(out); if (!sz || out[sz - 1] == '\\' || out[sz - 1] == '/') return; qerr_strlcat(__thisfunc__, __LINE__, out, "\\", size); }
char *ExpandArg (const char *path) { static char full[1024]; if (path[0] != '/' && path[0] != '\\' && path[1] != ':') { Q_getwd (full, sizeof(full)); qerr_strlcat(__thisfunc__, __LINE__, full, path, sizeof(full)); } else { qerr_strlcpy(__thisfunc__, __LINE__, full, path, sizeof(full)); } return full; }
void Q_getwd (char *out, size_t size, qboolean trailing_dirsep) { #if 0 qerr_strlcpy(__thisfunc__, __LINE__, out, "PROGDIR:", size); #else size_t sz; if (NameFromLock(((struct Process *) FindTask(NULL))->pr_CurrentDir, (STRPTR) out, size) == 0) COM_Error ("Couldn't determine current directory"); if (!trailing_dirsep) return; sz = strlen(out); if (!sz || out[sz - 1] == ':' || out[sz - 1] == '/') return; qerr_strlcat(__thisfunc__, __LINE__, out, "/", size); #endif }
void SetQdirFromPath (const char *path) { char temp[1024]; const char *c, *mark; if (!(path[0] == '/' || path[0] == '\\' || path[1] == ':')) { // path is partial Q_getwd (temp, sizeof(temp)); qerr_strlcat(__thisfunc__, __LINE__, temp, path, sizeof(temp)); path = temp; } c = path; while (*c) ++c; while (c > path && *c != '/' && *c != '\\') --c; if (c == path) goto end; mark = c + 1; --c; // search for the basedir (as defined in BUILDDIR) in path while (c != path) { if (!q_strncasecmp (c, BUILDDIR, sizeof(BUILDDIR) - 1)) { strncpy (qdir, path, c + sizeof(BUILDDIR) - path); printf ("qdir: %s\n", qdir); // now search for a gamedir in path c += sizeof(BUILDDIR); while (c < mark) { if (*c == '/' || *c == '\\') { strncpy (gamedir, path, c + 1 - path); printf ("gamedir: %s\n", gamedir); return; } c++; } Error ("No gamedir in %s", path); } --c; } end: Error ("%s: no '%s' in %s", __thisfunc__, BUILDDIR, path); }
/* ================== COM_DefaultExtension ================== */ void COM_DefaultExtension (char *path, const char *extension, size_t len) { char *src; // // if path doesn't have a .EXT, append extension // (extension should include the .) // if (!*path) return; src = path + strlen(path) - 1; while (*src != '/' && src != path) { if (*src == '.') return; // it has an extension src--; } qerr_strlcat(__thisfunc__, __LINE__, path, extension, len); }
void Q_getwd (char *out, size_t size, qboolean trailing_dirsep) { ULONG l, drv; if (size < 8) COM_Error ("Too small buffer for getcwd"); l = size - 3; if (DosQueryCurrentDir(0, (PBYTE) out + 3, &l) != NO_ERROR) COM_Error ("Couldn't determine current directory"); DosQueryCurrentDisk(&drv, &l); out[0] = drv + 'A' - 1; out[1] = ':'; out[2] = '\\'; if (!trailing_dirsep) return; l = strlen(out); if (out[l - 1] == '\\' || out[l - 1] == '/') return; qerr_strlcat(__thisfunc__, __LINE__, out, "\\", size); }