/**** message which is shown after closing joe (CTRL+x; CTRL+k) *****/ void genexmsg(BW *bw, int saved, char *name) { const char *s; if (bw->b->name && bw->b->name[0]) { s = bw->b->name; } else { s = joe_gettext(_("(Unnamed)")); } if (name) { if (saved) { joe_snprintf_1(msgbuf, JOE_MSGBUFSIZE, joe_gettext(_("File %s saved")), name); } else { joe_snprintf_1(msgbuf, JOE_MSGBUFSIZE, joe_gettext(_("File %s not saved")), name); } } else if (bw->b->changed && bw->b->count == 1) { joe_snprintf_1(msgbuf, JOE_MSGBUFSIZE, joe_gettext(_("File %s not saved")), s); } else if (saved) { joe_snprintf_1(msgbuf, JOE_MSGBUFSIZE, joe_gettext(_("File %s saved")), s); } else { joe_snprintf_1(msgbuf, JOE_MSGBUFSIZE, joe_gettext(_("File %s not changed so no update needed")), s); } if (exmsg) vsrm(exmsg); exmsg = vsncpy(NULL,0,sz(msgbuf)); if (!noexmsg) msgnw(bw->parent, msgbuf); }
/**** message which is shown after closing joe (CTRL+x; CTRL+k) *****/ void genexmsg(BW *bw, int saved, char *name) { const char *s; if (bw->b->name && bw->b->name[0]) { s = bw->b->name; } else { s = joe_gettext(_("(Unnamed)")); } if (name) { if (saved) { joe_snprintf_1(msgbuf, JOE_MSGBUFSIZE, joe_gettext(_("File %s saved")), name); } else { joe_snprintf_1(msgbuf, JOE_MSGBUFSIZE, joe_gettext(_("File %s not saved")), name); } } else if (bw->b->changed && bw->b->count == 1) { joe_snprintf_1(msgbuf, JOE_MSGBUFSIZE, joe_gettext(_("File %s not saved")), s); } else if (saved) { joe_snprintf_1(msgbuf, JOE_MSGBUFSIZE, joe_gettext(_("File %s saved")), s); } else { joe_snprintf_1(msgbuf, JOE_MSGBUFSIZE, joe_gettext(_("File %s not changed so no update needed")), s); } if (exmsg) vsrm(exmsg); exmsg = vsncpy(NULL,0,sz(msgbuf)); if (!noexmsg) { /* duplicate backslashes in file names because msgnw interprets escape sequences */ char *t = duplicate_backslashes(sz(msgbuf)); zcpy(msgbuf, t); vsrm(t); msgnw(bw->parent, msgbuf); } }
static void show_messages_found_count(BW *bw, int n) { if (n) joe_snprintf_1(msgbuf, JOE_MSGBUFSIZE, joe_gettext(_("%d messages found")), n); else joe_snprintf_0(msgbuf, JOE_MSGBUFSIZE, joe_gettext(_("No messages found"))); msgnw(bw->parent, msgbuf); }
static int backup(BW *bw) { if (!bw->b->backup && !nobackups && !bw->o.nobackup && bw->b->name && bw->b->name[0]) { char tmp[1024]; char name[1024]; #ifdef __MSDOS__ int x; if (backpath) { char *t = vsncpy(NULL,0,sz(backpath)); t = canonical(t); joe_snprintf_2(name, SIZEOF(name), "%s/%s", t, namepart(tmp, SIZEOF(tmp), bw->b->name)); vsrm(t); } else { joe_snprintf_1(name, SIZEOF(name), "%s", bw->b->name); } for (x = zlen(name); name[--x] != '.';) { if (name[x] == '\\' || (name[x] == ':' && x == 1) || x == 0) { x = zlen(name); break; } } zlcpy(name + x, SIZEOF(name) - x, ".bak"); #else /* Create backup file name */ const char *simple_backup_suffix = getenv("SIMPLE_BACKUP_SUFFIX"); if (simple_backup_suffix == NULL) { simple_backup_suffix = "~"; } if (backpath) { char *t = vsncpy(NULL, 0, sz(backpath)); t = canonical(t); joe_snprintf_3(name, SIZEOF(name), "%s/%s%s", t, namepart(tmp, SIZEOF(tmp), dequote(bw->b->name)), simple_backup_suffix); vsrm(t); } else { joe_snprintf_2(name, SIZEOF(name), "%s%s", dequote(bw->b->name), simple_backup_suffix); } /* Attempt to delete backup file first */ unlink(name); #endif /* Copy original file to backup file */ if (cp(dequote(bw->b->name), name)) { return 1; } else { bw->b->backup = 1; return 0; } } else { return 0; } }
int try_lock(BW *bw,B *b) { /* First time we modify the file */ /* If we're a plain file, acquire lock */ if (!nolocks && plain_file(b)) { unsigned char bf1[256]; unsigned char bf[300]; int x; /* It's a plain file- try to lock it */ if (lock_it(b->name,bf1)) { for(x=0;bf1[x] && bf1[x]!=':';++x); bf1[x]=0; if(bf1[0]) joe_snprintf_1(bf,sizeof(bf),joe_gettext(LOCKMSG1),bf1); else joe_snprintf_0(bf, sizeof(bf), joe_gettext(LOCKMSG2)); if (mkqw(bw->parent, sz(bf), steal_lock, NULL, b, NULL)) { uquery(bw); if (!b->locked) return 0; } else return 0; } else { /* Remember to unlock it */ b->locked = 1; } } return 1; }
int steal_lock(BW *bw,int c,B *b,int *notify) { if (yncheck(steallock_key, c)) { unsigned char bf1[256]; unsigned char bf[300]; unlock_it(b->name); if (lock_it(b->name,bf1)) { int x; for(x=0;bf1[x] && bf1[x]!=':';++x); bf1[x]=0; if(bf1[0]) joe_snprintf_1(bf,sizeof(bf),joe_gettext(LOCKMSG1),bf1); else joe_snprintf_0(bf, sizeof(bf), joe_gettext(LOCKMSG2)); if (mkqw(bw->parent, sz(bf), steal_lock, NULL, b, notify)) { return 0; } else { if (notify) *notify = -1; return -1; } } else { b->locked=1; if (notify) *notify = 1; return 0; } } else if (yncheck(ignorelock_key, c)) { b->locked=1; b->ignored_lock=1; if (notify) *notify = 1; return 0; } else if (yncheck(canceledit_key, c)) { if (notify) *notify = 1; return 0; } else { if (mkqw(bw->parent, sz(joe_gettext(LOCKMSG2)), steal_lock, NULL, b, notify)) { return 0; } else return -1; } }
/* static */char *stagen(char *stalin, BW *bw, const char *s, char fill) { char buf[80]; int x; int field; W *w = bw->parent; time_t n=time(NULL); struct tm *cas; cas=localtime(&n); stalin = vstrunc(stalin, 0); while (*s) { if (*s == '%' && s[1]) { field = 0; ++s; while (*s >= '0' && *s <= '9' && s[1]) { field = field * 10 + *s - '0'; ++s; } switch (*s) { case 'v': /* Version of JOE */ { joe_snprintf_1(buf, SIZEOF(buf), "%s", VERSION); stalin = vsncpy(sv(stalin), sz(buf)); } break; case 'x': /* Context (but only if autoindent is enabled) */ { if ( bw->o.autoindent) { char *ts = get_context(bw); /* We need to translate between file's character set to locale */ my_iconv(stdbuf, SIZEOF(stdbuf), locale_map,ts,bw->o.charmap); stalin = vsncpy(sv(stalin), sz(stdbuf)); } } break; case 'y': { if (bw->o.syntax) { joe_snprintf_1(buf, SIZEOF(buf), "(%s)", bw->o.syntax->name); stalin = vsncpy(sv(stalin), sz(buf)); } } break; case 't': { time_t curtime = time(NULL); int l; char *d = ctime(&curtime); l = (d[11] - '0') * 10 + d[12] - '0'; if (l > 12) l -= 12; joe_snprintf_1(buf, SIZEOF(buf), "%2.2d", l); if (buf[0] == '0') buf[0] = fill; stalin = vsncpy(sv(stalin), buf, 2); stalin = vsncpy(sv(stalin), d + 13, 3); } break; case 'd': { if (s[1]) switch (*++s) { case 'd' : joe_snprintf_1(buf, SIZEOF(buf), "%02d",cas->tm_mday); break; case 'm' : joe_snprintf_1(buf, SIZEOF(buf), "%02d",cas->tm_mon + 1); break; case 'y' : joe_snprintf_1(buf, SIZEOF(buf), "%02d",cas->tm_year % 100); break; case 'Y' : joe_snprintf_1(buf, SIZEOF(buf), "%04d",cas->tm_year + 1900); break; case 'w' : joe_snprintf_1(buf, SIZEOF(buf), "%d",cas->tm_wday); break; case 'D' : joe_snprintf_1(buf, SIZEOF(buf), "%03d",cas->tm_yday); break; default : buf[0]='d'; buf[1]=*s; buf[2]=0; } else { buf[0]='d'; buf[1]=0; } stalin=vsncpy(sv(stalin),sz(buf)); } break; case 'E': { char *ch; int l; buf[0]=0; for(l=0;s[l+1] && s[l+1] != '%'; l++) buf[l]=s[l+1]; if (s[l+1]=='%' && buf[0]) { buf[l]=0; s+=l+1; ch=getenv(buf); if (ch) stalin=vsncpy(sv(stalin),sz(ch)); } } break; case 'Z': { const char *ch; int l; buf[0]=0; for(l=0;s[l+1] && s[l+1] != '%'; l++) buf[l]=s[l+1]; if (s[l+1]=='%' && buf[0]) { buf[l]=0; s+=l+1; ch=get_status(bw, buf); if (ch) stalin=vsncpy(sv(stalin),sz(ch)); } } break; case 'u': { time_t curtime = time(NULL); char *d = ctime(&curtime); stalin = vsncpy(sv(stalin), d + 11, 5); } break; case 'T': if (bw->o.overtype) stalin = vsadd(stalin, 'O'); else stalin = vsadd(stalin, 'I'); break; case 'W': if (bw->o.wordwrap) stalin = vsadd(stalin, 'W'); else stalin = vsadd(stalin, fill); break; case 'I': if (bw->o.autoindent) stalin = vsadd(stalin, 'A'); else stalin = vsadd(stalin, fill); break; case 'X': if (square) stalin = vsadd(stalin, 'X'); else stalin = vsadd(stalin, fill); break; case 'n': { if (bw->b->name) { char *tmp = simplify_prefix(bw->b->name); char *tmp1 = duplicate_backslashes(sv(tmp)); vsrm(tmp); stalin = vsncpy(sv(stalin), sv(tmp1)); vsrm(tmp1); } else { stalin = vsncpy(sv(stalin), sz(joe_gettext(_("Unnamed")))); } } break; case 'm': if (bw->b->changed) stalin = vsncpy(sv(stalin), sz(joe_gettext(_("(Modified)")))); break; case 'R': if (bw->b->rdonly) stalin = vsncpy(sv(stalin), sz(joe_gettext(_("(Read only)")))); break; case '*': if (bw->b->changed) stalin = vsadd(stalin, '*'); else stalin = vsadd(stalin, fill); break; case 'r': if (field) #ifdef HAVE_LONG_LONG joe_snprintf_1(buf, SIZEOF(buf), "%-4lld", (long long)(bw->cursor->line + 1)); #else joe_snprintf_1(buf, SIZEOF(buf), "%-4ld", (long)(bw->cursor->line + 1)); #endif else #ifdef HAVE_LONG_LONG joe_snprintf_1(buf, SIZEOF(buf), "%lld", (long long)(bw->cursor->line + 1)); #else joe_snprintf_1(buf, SIZEOF(buf), "%ld", (long)(bw->cursor->line + 1)); #endif for (x = 0; buf[x]; ++x) if (buf[x] == ' ') buf[x] = fill; stalin = vsncpy(sv(stalin), sz(buf)); break; case 'o': if (field) #ifdef HAVE_LONG_LONG joe_snprintf_1(buf, SIZEOF(buf), "%-4lld", (long long)bw->cursor->byte); #else joe_snprintf_1(buf, SIZEOF(buf), "%-4ld", (long)bw->cursor->byte); #endif else #ifdef HAVE_LONG_LONG joe_snprintf_1(buf, SIZEOF(buf), "%lld", (long long)bw->cursor->byte); #else joe_snprintf_1(buf, SIZEOF(buf), "%ld", (long)bw->cursor->byte); #endif for (x = 0; buf[x]; ++x) if (buf[x] == ' ') buf[x] = fill; stalin = vsncpy(sv(stalin), sz(buf)); break; case 'O': if (field) #ifdef HAVE_LONG_LONG joe_snprintf_1(buf, SIZEOF(buf), "%-4llX", (unsigned long long)bw->cursor->byte); #else joe_snprintf_1(buf, SIZEOF(buf), "%-4lX", (unsigned long)bw->cursor->byte); #endif else