} Buf;
void buf_init(Buf* buf);
+void buf_setpath(Buf* buf, char* path);
void buf_load(Buf* buf, char* path);
void buf_reload(Buf* buf);
-int buf_save(Buf* buf);
+int buf_save(Buf* buf, char* path);
size_t buf_end(Buf* buf);
int buf_getrat(Buf* buf, size_t off);
assert(buf->bufstart);
}
+void buf_setpath(Buf* buf, char* path) {
+ if (path) {
+ free(buf->path);
+ buf->path = strdup(path);
+ }
+}
+
void buf_load(Buf* buf, char* path) {
if (!path) return;
/* process the file path and address */
buf_load(buf, path);
}
-int buf_save(Buf* buf) {
+int buf_save(Buf* buf, char* path) {
+ buf_setpath(buf, path);
if (0 == buf_end(buf)) return buf->status;
char* wptr;
long fd, nwrite = 0, towrite = 0;
buf_init(&TestBuf);
buf_load(&TestBuf, "testdocs/lorem.txt");
TestBuf.status = MODIFIED;
- buf_save(&TestBuf);
+ buf_save(&TestBuf, NULL);
CHECK(TestBuf.status != MODIFIED);
}
buf_init(&TestBuf);
buf_load(&TestBuf, "testdocs/waf");
TestBuf.status = MODIFIED;
- buf_save(&TestBuf);
+ buf_save(&TestBuf, NULL);
CHECK(TestBuf.status != MODIFIED);
}
buf_init(&TestBuf);
buf_load(&TestBuf, "testdocs/lf.txt");
TestBuf.status = MODIFIED;
- buf_save(&TestBuf);
+ buf_save(&TestBuf, NULL);
CHECK(TestBuf.status != MODIFIED);
}
buf_init(&TestBuf);
buf_load(&TestBuf, "testdocs/crlf.txt");
TestBuf.status = MODIFIED;
- buf_save(&TestBuf);
+ buf_save(&TestBuf, NULL);
CHECK(TestBuf.status != MODIFIED);
}
}
static void put(char* arg) {
- View* view = win_view(EDIT);
- if (!arg) arg = view->buffer.path;
- if (!arg) return;
- char* path = realpath(arg, NULL);
- if (!path) path = strdup(arg);
- free(view->buffer.path);
- view->buffer.path = path;
- if (buf_save(&(view->buffer)) == NORMAL) {
- char* path = realpath(view->buffer.path, NULL);
- if (path) {
- free(view->buffer.path);
- view->buffer.path = path;
- }
+ Buf* buf = win_buf(EDIT);
+ if (buf_save(buf, arg) == NORMAL) {
+ /* convert saved path to absolute path */
+ char* path = realpath(buf->path, NULL);
+ buf_setpath(buf, path);
+ free(path);
}
- win_title(view->buffer.path);
- win_prop_set("TIDE_FILE", "file", view->buffer.path);
+ win_title(buf->path);
+ win_prop_set("TIDE_FILE", "file", buf->path);
}
static void get(char* arg) {
/* if we still have args left we're going to open it in this instance */
if (*argv) {
char* path = realpath(*argv, NULL);
- if (!path) path = strdup(*argv); // if file doesnt exist, use the original name
+ if (!path) path = *argv; /* if file doesnt exist, use the original name */
view_init(win_view(EDIT), path);
win_title(path);
win_prop_set("TIDE_FILE", "file", path);