Rename file to saveFile

Separate churn from actual change in upcoming diff,
no functional change.
weechat-hashes
Klemens Nanni 2021-06-11 12:30:57 +00:00 committed by C. McEnroe
parent 4aa3da5786
commit 8e591c96f8
1 changed files with 40 additions and 40 deletions

80
ui.c
View File

@ -1129,40 +1129,40 @@ static int writeString(FILE *file, const char *str) {
} }
int uiSave(const char *name) { int uiSave(const char *name) {
FILE *file = dataOpen(name, "w"); FILE *saveFile = dataOpen(name, "w");
if (!file) return -1; if (!saveFile) return -1;
int error = 0 int error = 0
|| writeTime(file, Signatures[7]) || writeTime(saveFile, Signatures[7])
|| writeTime(file, self.pos); || writeTime(saveFile, self.pos);
if (error) return error; if (error) return error;
for (uint num = 0; num < windows.len; ++num) { for (uint num = 0; num < windows.len; ++num) {
const struct Window *window = windows.ptrs[num]; const struct Window *window = windows.ptrs[num];
error = 0 error = 0
|| writeString(file, idNames[window->id]) || writeString(saveFile, idNames[window->id])
|| writeTime(file, window->mute) || writeTime(saveFile, window->mute)
|| writeTime(file, window->time) || writeTime(saveFile, window->time)
|| writeTime(file, window->thresh) || writeTime(saveFile, window->thresh)
|| writeTime(file, window->heat) || writeTime(saveFile, window->heat)
|| writeTime(file, window->unreadSoft) || writeTime(saveFile, window->unreadSoft)
|| writeTime(file, window->unreadWarm); || writeTime(saveFile, window->unreadWarm);
if (error) return error; if (error) return error;
for (size_t i = 0; i < BufferCap; ++i) { for (size_t i = 0; i < BufferCap; ++i) {
const struct Line *line = bufferSoft(window->buffer, i); const struct Line *line = bufferSoft(window->buffer, i);
if (!line) continue; if (!line) continue;
error = 0 error = 0
|| writeTime(file, line->time) || writeTime(saveFile, line->time)
|| writeTime(file, line->heat) || writeTime(saveFile, line->heat)
|| writeString(file, line->str); || writeString(saveFile, line->str);
if (error) return error; if (error) return error;
} }
error = writeTime(file, 0); error = writeTime(saveFile, 0);
if (error) return error; if (error) return error;
} }
return 0 return 0
|| writeString(file, "") || writeString(saveFile, "")
|| urlSave(file) || urlSave(saveFile)
|| fclose(file); || fclose(saveFile);
} }
static time_t readTime(FILE *file) { static time_t readTime(FILE *file) {
@ -1179,51 +1179,51 @@ static ssize_t readString(FILE *file, char **buf, size_t *cap) {
} }
void uiLoad(const char *name) { void uiLoad(const char *name) {
FILE *file = dataOpen(name, "r"); FILE *saveFile = dataOpen(name, "r");
if (!file) { if (!saveFile) {
if (errno != ENOENT) exit(EX_NOINPUT); if (errno != ENOENT) exit(EX_NOINPUT);
file = dataOpen(name, "w"); saveFile = dataOpen(name, "w");
if (!file) exit(EX_CANTCREAT); if (!saveFile) exit(EX_CANTCREAT);
fclose(file); fclose(saveFile);
return; return;
} }
time_t signature; time_t signature;
fread(&signature, sizeof(signature), 1, file); fread(&signature, sizeof(signature), 1, saveFile);
if (ferror(file)) err(EX_IOERR, "fread"); if (ferror(saveFile)) err(EX_IOERR, "fread");
if (feof(file)) { if (feof(saveFile)) {
fclose(file); fclose(saveFile);
return; return;
} }
size_t version = signatureVersion(signature); size_t version = signatureVersion(signature);
if (version > 1) { if (version > 1) {
self.pos = readTime(file); self.pos = readTime(saveFile);
} }
char *buf = NULL; char *buf = NULL;
size_t cap = 0; size_t cap = 0;
while (0 < readString(file, &buf, &cap) && buf[0]) { while (0 < readString(saveFile, &buf, &cap) && buf[0]) {
struct Window *window = windows.ptrs[windowFor(idFor(buf))]; struct Window *window = windows.ptrs[windowFor(idFor(buf))];
if (version > 3) window->mute = readTime(file); if (version > 3) window->mute = readTime(saveFile);
if (version > 6) window->time = readTime(file); if (version > 6) window->time = readTime(saveFile);
if (version > 5) window->thresh = readTime(file); if (version > 5) window->thresh = readTime(saveFile);
if (version > 0) { if (version > 0) {
window->heat = readTime(file); window->heat = readTime(saveFile);
window->unreadSoft = readTime(file); window->unreadSoft = readTime(saveFile);
window->unreadWarm = readTime(file); window->unreadWarm = readTime(saveFile);
} }
for (;;) { for (;;) {
time_t time = readTime(file); time_t time = readTime(saveFile);
if (!time) break; if (!time) break;
enum Heat heat = (version > 2 ? readTime(file) : Cold); enum Heat heat = (version > 2 ? readTime(saveFile) : Cold);
readString(file, &buf, &cap); readString(saveFile, &buf, &cap);
bufferPush(window->buffer, COLS, window->thresh, heat, time, buf); bufferPush(window->buffer, COLS, window->thresh, heat, time, buf);
} }
windowReflow(window); windowReflow(window);
} }
urlLoad(file, version); urlLoad(saveFile, version);
free(buf); free(buf);
fclose(file); fclose(saveFile);
} }