char *SV_GetSaveInfo(const char *dir) { char name[MAX_QPATH], date[MAX_QPATH]; size_t len; uint64_t timestamp; int autosave, year; time_t t; struct tm *tm; len = Q_snprintf(name, MAX_QPATH, "save/%s/server.ssv", dir); if (len >= MAX_QPATH) return NULL; if (read_binary_file(name)) return NULL; if (MSG_ReadLong() != SAVE_MAGIC1) return NULL; if (MSG_ReadLong() != SAVE_VERSION) return NULL; // read the comment field timestamp = (uint64_t)MSG_ReadLong(); timestamp |= (uint64_t)MSG_ReadLong() << 32; autosave = MSG_ReadByte(); MSG_ReadString(name, sizeof(name)); if (autosave) return Z_CopyString(va("ENTERING %s", name)); // get current year t = time(NULL); tm = localtime(&t); year = tm ? tm->tm_year : -1; // format savegame date t = (time_t)timestamp; if ((tm = localtime(&t)) != NULL) { if (tm->tm_year == year) strftime(date, sizeof(date), "%b %d %H:%M", tm); else strftime(date, sizeof(date), "%b %d %Y", tm); } else { strcpy(date, "???"); } return Z_CopyString(va("%s %s", date, name)); }
/* ==================== Prompt_Action User just pressed enter ==================== */ char *Prompt_Action(commandPrompt_t *prompt) { char *s = prompt->inputLine.text; int i, j; Prompt_ClearState(prompt); if (s[0] == 0 || ((s[0] == '/' || s[0] == '\\') && s[1] == 0)) { IF_Clear(&prompt->inputLine); return NULL; // empty line } // save current line in history i = prompt->inputLineNum & HISTORY_MASK; j = (prompt->inputLineNum - 1) & HISTORY_MASK; if (!prompt->history[j] || strcmp(prompt->history[j], s)) { if (prompt->history[i]) { Z_Free(prompt->history[i]); } prompt->history[i] = Z_CopyString(s); prompt->inputLineNum++; } else { i = j; } // stop history search prompt->historyLineNum = prompt->inputLineNum; IF_Clear(&prompt->inputLine); return prompt->history[i]; }
}END_TEST START_TEST(check_Z_CopyString) { char *test = Z_CopyString("test"); ck_assert(Z_Size() == strlen(test) + 1); Z_Free(test); ck_assert(Z_Size() == 0); }END_TEST
/* =================== Key_SetBinding =================== */ void Key_SetBinding(int keynum, const char *binding) { if (keynum < 0 || keynum > 255) return; // free old binding if (keybindings[keynum]) { Z_Free(keybindings[keynum]); } // allocate memory for new binding keybindings[keynum] = Z_CopyString(binding); }
void Prompt_CompleteHistory(commandPrompt_t *prompt, qboolean forward) { char *s, *m = NULL; int i, j; if (!prompt->search) { s = prompt->inputLine.text; if (*s == '/' || *s == '\\') { s++; } if (!*s) { return; } prompt->search = Z_CopyString(s); } if (forward) { for (i = prompt->historyLineNum + 1; i < prompt->inputLineNum; i++) { s = prompt->history[i & HISTORY_MASK]; if (s && strstr(s, prompt->search)) { if (strcmp(s, prompt->inputLine.text)) { m = s; break; } } } } else { j = prompt->inputLineNum - HISTORY_SIZE; if (j < 0) { j = 0; } for (i = prompt->historyLineNum - 1; i >= j; i--) { s = prompt->history[i & HISTORY_MASK]; if (s && strstr(s, prompt->search)) { if (strcmp(s, prompt->inputLine.text)) { m = s; break; } } } } if (!m) { return; } prompt->historyLineNum = i; IF_Replace(&prompt->inputLine, prompt->history[i & HISTORY_MASK]); }
qboolean Prompt_AddMatch( genctx_t *ctx, const char *s ) { int r; if( ctx->count >= ctx->size ) { return qfalse; } if( ctx->ignorecase ) { r = Q_strncasecmp( ctx->partial, s, ctx->length ); } else { r = strncmp( ctx->partial, s, ctx->length ); } if( !r ) { ctx->matches[ctx->count++] = Z_CopyString( s ); } return qtrue; }
/* ================ VID_GetClipboardData ================ */ char *VID_GetClipboardData( void ) { HANDLE clipdata; char *data = NULL; char *cliptext; if( OpenClipboard( NULL ) == FALSE ) { Com_DPrintf( "Couldn't open clipboard.\n" ); return data; } if( ( clipdata = GetClipboardData( CF_TEXT ) ) != NULL ) { if( ( cliptext = GlobalLock( clipdata ) ) != NULL ) { data = Z_CopyString( cliptext ); GlobalUnlock( clipdata ); } } CloseClipboard(); return data; }
qboolean Prompt_AddMatch(genctx_t *ctx, const char *s) { int r; if (ctx->count >= ctx->size) return qfalse; if (ctx->ignorecase) r = Q_strncasecmp(ctx->partial, s, ctx->length); else r = strncmp(ctx->partial, s, ctx->length); if (r) return qtrue; if (ctx->ignoredups && find_dup(ctx, s)) return qtrue; ctx->matches[ctx->count++] = Z_CopyString(s); return qtrue; }
/* ==================== Prompt_HistoryUp ==================== */ void Prompt_HistoryUp(commandPrompt_t *prompt) { int i; Prompt_ClearState(prompt); if (prompt->historyLineNum == prompt->inputLineNum) { // save current line in history i = prompt->inputLineNum & HISTORY_MASK; if (prompt->history[i]) { Z_Free(prompt->history[i]); } prompt->history[i] = Z_CopyString(prompt->inputLine.text); } if (prompt->inputLineNum - prompt->historyLineNum < HISTORY_SIZE && prompt->historyLineNum > 0) { prompt->historyLineNum--; } i = prompt->historyLineNum & HISTORY_MASK; IF_Replace(&prompt->inputLine, prompt->history[i]); }
/* ================= VID_GetClipboardData ================= */ char *VID_GetClipboardData(void) { #if USE_X11 SDL_SysWMinfo info; Display *dpy; Window win, sowner; Atom type, property; unsigned long len, bytes_left; unsigned char *data; int format, result; char *ret; SDL_VERSION(&info.version); if (!SDL_GetWMInfo(&info)) { return NULL; } if (info.subsystem != SDL_SYSWM_X11) { return NULL; } dpy = info.info.x11.display; win = info.info.x11.window; if (!dpy) { return NULL; } sowner = XGetSelectionOwner(dpy, XA_PRIMARY); if (sowner == None) { return NULL; } property = XInternAtom(dpy, "GETCLIPBOARDDATA_PROP", False); XConvertSelection(dpy, XA_PRIMARY, XA_STRING, property, win, CurrentTime); XSync(dpy, False); result = XGetWindowProperty(dpy, win, property, 0, 0, False, AnyPropertyType, &type, &format, &len, &bytes_left, &data); if (result != Success) { return NULL; } ret = NULL; if (bytes_left) { result = XGetWindowProperty(dpy, win, property, 0, bytes_left, True, AnyPropertyType, &type, &format, &len, &bytes_left, &data); if (result == Success) { ret = Z_CopyString((char *)data); } } XFree(data); return ret; #else return NULL; #endif }