History

plan9: load/save and display the filename

Sigrid Haflínudóttir committed 6 years ago

Commit c98d73f1 parent 46544df1 file · +26 −9Browse files

Unified · Split

plan9.c+26−9
@@ -31,6 +31,7 @@ static int charw, charh; · 30 unmodified lines
3131 static Field field;
3232 static Mbuf_reusable mbuf;
3333 static Oevent_list events;
34+static char filename[256];
3435
3536 static char *menu3i[] = {
3637 "load",
@@ -242,6 +243,10 @@ redraw(void) · 205 unmodified lines
242243 runesprint(linebuf, "%d", bpm);
243244 runestring(screen, p, display->white, ZP, font, linebuf);
244245
246+ /* filename */
247+ p.y += font->height;
248+ string(screen, p, display->white, ZP, font, filename);
249+
245250 /* cursor bg */
246251 p = top;
247252 p.x += curx*stringwidth(font, " ");
@@ -266,6 +271,18 @@ fieldload(char *path) · 18 unmodified lines
266271 return 0;
267272 }
268273
274+static int
275+fieldsave(char *path)
276+{
277+ FILE *f;
278+
279+ if ((f = fopen(path, "w")) == nil)
280+ return -1;
281+ field_fput(&field, f);
282+ fclose(f);
283+ return 0;
284+}
285+
269286 static void
270287 fieldset(Rune key)
271288 {
@@ -295,7 +312,7 @@ threadmain(int argc, char **argv) · 23 unmodified lines
295312 Rune key;
296313 Mouse m;
297314 char tmp[256];
298− int oldw, oldh, w, h;
315+ int oldw, oldh, w, h, n;
299316 Alt a[] = {
300317 { nil, &m, CHANRCV },
301318 { nil, nil, CHANRCV },
@@ -351,18 +368,18 @@ threadmain(int argc, char **argv) · 49 unmodified lines
351368 case 2:
352369 break;
353370 case 4:
354− switch (menuhit(3, mctl, &menu3, nil)) {
355− case 0:
356− tmp[0] = 0;
357− if (enter("load file:", tmp, sizeof(tmp), mctl, kctl, nil) > 0) {
358− if (fieldload(tmp) == 0) {
371+ n = menuhit(3, mctl, &menu3, nil);
372+ if (n == 0 || n == 1) {
373+ strncpy(tmp, filename, sizeof(tmp));
374+ if (enter("file path:", tmp, sizeof(tmp), mctl, kctl, nil) > 0) {
375+ if (n == 0 && fieldload(tmp) == 0) {
359376 w = field.width;
360377 h = field.height;
361− } else {
362− /* FIXME display the error */
378+ strncpy(filename, tmp, sizeof(filename));
379+ } else if (n == 1 && fieldsave(tmp) == 0) {
380+ strncpy(filename, tmp, sizeof(filename));
363381 }
364382 }
365− break;
366383 }
367384 break;
368385 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t