--- joe-3.1/ublock.c 2004-05-24 22:51:49.000000000 +0200 +++ joe/ublock.c 2004-12-21 14:38:36.881527968 +0100 @@ -563,31 +563,31 @@ umarkk(bw); pfwrd(markk, size); } updall(); return 0; } } else { msgnw(bw->parent, US "No block"); return -1; } } /* Write highlighted block to a file */ /* This is called by ublksave in ufile.c */ -int dowrite(BW *bw, unsigned char *s, void *object, int *notify) +/*int dowrite(BW *bw, unsigned char *s, void *object, int *notify) { if (notify) *notify = 1; if (markv(1)) { if (square) { int fl; int ret = 0; B *tmp = pextrect(markb, markk->line - markb->line + 1, markk->xcol); if ((fl = bsave(tmp->bof, s, tmp->eof->byte, 0)) != 0) { msgnw(bw->parent, msgs[-fl]); ret = -1; } @@ -602,31 +602,31 @@ if ((fl = bsave(markb, s, markk->byte - markb->byte, 0)) != 0) { msgnw(bw->parent, msgs[-fl]); ret = -1; } if (lightoff) unmark(bw); vsrm(s); return ret; } } else { vsrm(s); msgnw(bw->parent, US "No block"); return -1; } -} +}*/ /* Set highlighted block on a program block */ void setindent(BW *bw) { P *p, *q; long indent; if (pisblank(bw->cursor)) return; p = pdup(bw->cursor); q = pdup(p); indent = pisindent(p); --- joe-3.1/ufile.c 2004-05-28 18:40:48.000000000 +0200 +++ joe/ufile.c 2004-12-21 15:19:21.216932504 +0100 @@ -115,44 +115,30 @@ void genexmsgmulti(BW *bw, int saved, int skipped) { if (saved) if (skipped) joe_snprintf_0((char *)msgbuf, JOE_MSGBUFSIZE, "Some files have not been saved."); else joe_snprintf_0((char *)msgbuf, JOE_MSGBUFSIZE, "All modified files have been saved."); else joe_snprintf_0((char *)msgbuf, JOE_MSGBUFSIZE, "No modified files, so no updates needed."); msgnw(bw->parent, msgbuf); exmsg = vsncpy(NULL,0,sz(msgbuf)); } -/* Write highlighted block to a file */ - -int ublksave(BW *bw) -{ - if (markb && markk && markb->b == markk->b && (markk->byte - markb->byte) > 0 && (!square || piscol(markk) > piscol(markb))) { - if (wmkpw(bw->parent, US "Name of file to write (^C to abort): ", &filehist, dowrite, US "Names", NULL, cmplt, NULL, NULL, locale_map)) { - return 0; - } else { - return -1; - } - } else { - return usave(bw); - } -} /* Shell escape */ int ushell(BW *bw) { nescape(bw->parent->t->t); ttsusp(); nreturn(bw->parent->t->t); return 0; } /* Copy a file */ static int cp(unsigned char *from, unsigned char *to) { @@ -266,40 +252,43 @@ } else { return 0; } } /* Write file */ /* Continuation structure */ struct savereq { int (*callback) (); unsigned char *name; B *first; int not_saved; /* Set if a modified file was not saved */ int rename; /* Set if we're renaming the file during save */ + int block_save; // Flag, if we want to save a block# + char *message; // String for messages to be shown to the user }; -struct savereq *mksavereq(int (*callback)(), unsigned char *name, B *first,int rename) +struct savereq *mksavereq(int (*callback)(), unsigned char *name, B *first,int rename, int block_save) { struct savereq *req = (struct savereq *) joe_malloc(sizeof(struct savereq)); req->callback = callback; req->name = name; req->first = first; req->not_saved = 0; req->rename = rename; + req->block_save = block_save; return req; } static void rmsavereq(struct savereq *req) { vsrm(req->name); joe_free(req); } static int saver(BW *bw, int c, struct savereq *req, int *notify) { int fl; if (c == 'n' || c == 'N') { msgnw(bw->parent, US "Couldn't make backup file... file not saved"); if (req->callback) { @@ -370,130 +359,176 @@ rec->changed = 1; } genexmsg(bw, 1, req->name); if (req->callback) { return req->callback(bw, req, 0, notify); } else { rmsavereq(req); return 0; } } } static int dosave(BW *bw, struct savereq *req, int *notify) { - if (backup(bw)) { - return saver(bw, 0, req, notify); - } else { - return saver(bw, 'y', req, notify); - } -} - -static int dosave2(BW *bw, int c, struct savereq *req, int *notify) -{ - if (c == 'y' || c == 'Y') { - return dosave(bw, req, notify); - } else if (c == 'n' || c == 'N') { - if (notify) { + if (req->block_save) + { + if (notify) *notify = 1; + if (markv(1)) { + if (square) { + int fl; + int ret = 0; + B *tmp = pextrect(markb, + markk->line - markb->line + 1, + markk->xcol); + + if ((fl = bsave(tmp->bof, req->name, tmp->eof->byte, 0)) != 0) { + msgnw(bw->parent, msgs[-fl]); + ret = -1; + } + brm(tmp); + if (lightoff) + unmark(bw); + vsrm(req->name); + return ret; + } else { + int fl; + int ret = 0; + + if ((fl = bsave(markb, req->name, markk->byte - markb->byte, 0)) != 0) { + msgnw(bw->parent, msgs[-fl]); + ret = -1; + } + if (lightoff) + unmark(bw); + vsrm(req->name); + return ret; + } + } else { + vsrm(req->name); + msgnw(bw->parent, US "No block"); + return -1; + } + } + else + { + if (backup(bw)) { + return saver(bw, 0, req, notify); + } else { + return saver(bw, 'y', req, notify); } - genexmsg(bw, 0, req->name); - rmsavereq(req); - return -1; - } else if (mkqw(bw->parent, sc("File exists. Overwrite (y,n,^C)? "), dosave2, NULL, req, notify)) { - return 0; - } else { - /* Should be in abort function */ - rmsavereq(req); - return -1; } } -static int dosave2a(BW *bw, int c, struct savereq *req, int *notify) +static int dosave2(BW *bw, int c, struct savereq *req, int *notify) { if (c == 'y' || c == 'Y') { return dosave(bw, req, notify); } else if (c == 'n' || c == 'N') { if (notify) { *notify = 1; } genexmsg(bw, 0, req->name); rmsavereq(req); return -1; - } else if (mkqw(bw->parent, sc("File on disk is newer. Overwrite (y,n,^C)? "), dosave2a, NULL, req, notify)) { + } else if (mkqw(bw->parent, sz(req->message), dosave2, NULL, req, notify)) { return 0; } else { + /* Should be in abort function */ rmsavereq(req); return -1; } } /* Checks if file exists. */ static int dosave1(BW *bw, unsigned char *s, struct savereq *req, int *notify) { int f; if (req->name) vsrm(req->name); req->name = s; if (s[0] != '!' && !(s[0] == '>' && s[1] == '>')) { /* It's a normal file: not a pipe or append */ if (!bw->b->name || strcmp(s, bw->b->name)) { /* Newly named file or name is different than buffer */ f = open((char *)s, O_RDONLY); if (f != -1) { close(f); + //char *msg = "File exists. Overwrite (y,n,^C)? "; + //req->message = msg; + req->message = "File exists. Overwrite (y,n,^C)? "; return dosave2(bw, 0, req, notify); } } else { /* We're saving a newer version of the same file */ struct stat sbuf; if (!stat((char *)s,&sbuf)) { if (sbuf.st_mtime>bw->b->mod_time) { - return dosave2a(bw, 0, req, notify); + //char *msg = "File on disk is newer. Overwrite (y,n,^C)? "; + //req->message = msg; + req->message = "File on disk is newer. Overwrite (y,n,^C)? "; + return dosave2(bw, 0, req, notify); } } } } return dosave(bw, req, notify); } /* User command: ^K D */ int usave(BW *bw) { BW *pbw; - pbw = wmkpw(bw->parent, US "Name of file to save (^C to abort): ", &filehist, dosave1, US "Names", NULL, cmplt, mksavereq(NULL,NULL,NULL,0), NULL, locale_map); + pbw = wmkpw(bw->parent, US "Name of file to save (^C to abort): ", &filehist, dosave1, US "Names", NULL, cmplt, mksavereq(NULL,NULL,NULL,0, 0), NULL, locale_map); if (pbw && bw->b->name) { binss(pbw->cursor, bw->b->name); pset(pbw->cursor, pbw->b->eof); pbw->cursor->xcol = piscol(pbw->cursor); } if (pbw) { return 0; } else { return -1; } } +/* Write highlighted block to a file */ + +int ublksave(BW *bw) +{ + if (markb && markk && markb->b == markk->b && (markk->byte - markb->byte) > 0 && (!square || piscol(markk) > piscol(markb))) { + if (wmkpw(bw->parent, US "Name of file to write (^C to abort): ", &filehist, dosave1, US "Names", NULL, cmplt, mksavereq(NULL, NULL, NULL, 0, 1), NULL, locale_map)) { + return 0; + } else { + return -1; + } + } else { + return usave(bw); + } +} + + /* Load file to edit */ int doedit1(BW *bw,int c,unsigned char *s,int *notify) { int ret = 0; int er; void *object; W *w; B *b; if (c=='y' || c=='Y') { /* Reload from file */ if (notify) { *notify = 1; } @@ -817,33 +852,33 @@ } else { bw->b->changed = 0; saverr(bw->b->name); return uabort1(bw, -1); } } int uexsve(BW *bw) { if (!bw->b->changed || bw->b->scratch) { /* It didn't change or it's just a scratch buffer: don't save */ uabort(bw, -1); return 0; } else if (bw->b->name && !exask) { /* It changed, it's not a scratch buffer and it's named */ - return dosave1(bw, vsncpy(NULL, 0, sz(bw->b->name)), mksavereq(exdone,NULL,NULL,0), NULL); + return dosave1(bw, vsncpy(NULL, 0, sz(bw->b->name)), mksavereq(exdone,NULL,NULL,0,0), NULL); } else { - BW *pbw = wmkpw(bw->parent, US "Name of file to save (^C to abort): ", &filehist, dosave1, US "Names", NULL, cmplt, mksavereq(exdone,NULL,NULL,1), NULL, locale_map); + BW *pbw = wmkpw(bw->parent, US "Name of file to save (^C to abort): ", &filehist, dosave1, US "Names", NULL, cmplt, mksavereq(exdone,NULL,NULL,1,0), NULL, locale_map); if (pbw && bw->b->name) { binss(pbw->cursor, bw->b->name); pset(pbw->cursor, pbw->b->eof); pbw->cursor->xcol = piscol(pbw->cursor); } if (pbw) { return 0; } else { return -1; } } } /* If buffer is modified, prompt for saving: if user types 'n', uabort(), otherwise just return. */ @@ -1045,31 +1080,31 @@ *notify = 1; rmsavereq(req); return -1; } else return doquerysave(bw,'N',req,notify); } int uquerysave(BW *bw) { W *w = bw->parent; B *first = bw->b; /* Find a modified buffer */ do { if (bw->b->changed && !bw->b->scratch) - return doquerysave(bw,0,mksavereq(query_next,NULL,first,0),NULL); + return doquerysave(bw,0,mksavereq(query_next,NULL,first,0,0),NULL); else if (unbuf(bw)) return -1; bw = w->object; } while(bw->b!=first); genexmsgmulti(bw,0,0); return 0; } int ukilljoe(BW *bw) { leave = 1; return 0; }