static int docmd(BW *bw, unsigned char *s, void *object, int *notify) { MACRO *mac; int ret = -1; mac = mparse(NULL, s, &ret,0); if (ret < 0) { msgnw(bw->parent,joe_gettext(_("No such command"))); } else { ret = exmacro(mac, 1); rmmacro(mac); } #ifdef junk CMD *cmd = findcmd(s); vsrm(s); /* allocated in pw.c::rtnpw() */ if (!cmd) msgnw(bw->parent,joe_gettext(_("No such command"))); else { mac = mkmacro(-1, 0, 0, cmd); ret = exmacro(mac, 1); rmmacro(mac); } #endif if (notify) *notify = 1; return ret; }
int output_security_context(const char *from_file) { #ifdef WITH_SELINUX security_context_t scontext; if (selinux_enabled == -1) selinux_enabled = (is_selinux_enabled() > 0); if (!selinux_enabled) return 0; if (getfilecon(from_file, &scontext) < 0) { /* * If the filesystem doesn't support extended * attributes, the original had no special security * context and the target cannot have one either. */ if (errno == EOPNOTSUPP) return 0; error(0, errno,joe_gettext(_("Could not get security context for %s")), from_file); return 1; } error(0, 0, joe_gettext(_("%s Security Context %s")), from_file, scontext); freecon(scontext); #endif return 0; }
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); }
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 cstart(BW *bw, unsigned char *name, unsigned char **s, void *obj, int *notify, int build, int out_only) { #ifdef __MSDOS__ if (notify) { *notify = 1; } varm(s); msgnw(bw->parent, joe_gettext(_("Sorry, no sub-processes in DOS (yet)"))); return -1; #else MPX *m; if (notify) { *notify = 1; } if (bw->b->pid) { msgnw(bw->parent, joe_gettext(_("Program already running in this window"))); varm(s); return -1; } /* p_goto_eof(bw->cursor); */ if (!(m = mpxmk(&bw->b->out, name, s, cdata, bw->b, build ? cdone_parse : cdone, bw->b, out_only))) { varm(s); msgnw(bw->parent, joe_gettext(_("No ptys available"))); return -1; } else { bw->b->pid = m->pid; } return 0; #endif }
int cstart(BW *bw, unsigned char *name, unsigned char **s, void *obj, int *notify, int build, int out_only, unsigned char *first_command, int vt) { #ifdef __MSDOS__ if (notify) { *notify = 1; } varm(s); msgnw(bw->parent, joe_gettext(_("Sorry, no sub-processes in DOS (yet)"))); return -1; #else MPX *m; int shell_w = -1, shell_h = -1; if (notify) { *notify = 1; } if (bw->b->pid) { if (!vt) { /* Don't complain if shell already running.. makes F-key switching nicer */ /* Keep old behavior for dumb terminal */ msgnw(bw->parent, joe_gettext(_("Program already running in this window"))); } varm(s); return -1; } if (vt) { BW *master = vtmaster(bw->parent->t, bw->b); /* In case of multiple BWs on one B, pick one to be the master */ if (!master) master = bw; /* Should never happen */ shell_w = master->w; shell_h = master->h; bw->b->vt = mkvt(bw->b, master->top, master->h, master->w); bw->b->o.ansi = 1; bw->b->o.syntax = load_syntax(USTR "ansi"); /* Turn on shell mode for each window */ ansiall(bw->b); } /* p_goto_eof(bw->cursor); */ if (!(m = mpxmk(&bw->b->out, name, s, cdata, bw->b, build ? cdone_parse : cdone, bw->b, out_only, shell_w, shell_h))) { varm(s); msgnw(bw->parent, joe_gettext(_("No ptys available"))); return -1; } else { bw->b->pid = m->pid; if (first_command) if (-1 == write(bw->b->out, first_command, zlen(first_command))) msgnw(bw->parent, joe_gettext(_("Write failed when writing first command to shell"))); } return 0; #endif }
/* For ^X ^C */ static void genexmsgmulti(BW *bw, int saved, int skipped) { if (saved) if (skipped) joe_snprintf_0(msgbuf, SIZEOF(msgbuf), joe_gettext(_("Some files have not been saved."))); else joe_snprintf_0(msgbuf, SIZEOF(msgbuf), joe_gettext(_("All modified files have been saved."))); else joe_snprintf_0(msgbuf, SIZEOF(msgbuf), joe_gettext(_("No modified files, so no updates needed."))); msgnw(bw->parent, msgbuf); exmsg = vsncpy(NULL,0,sz(msgbuf)); }
int copy_security_context(const char *from_file, const char *to_file) { int status = 0; #ifdef WITH_SELINUX security_context_t from_context; security_context_t to_context; if (selinux_enabled == -1) selinux_enabled = (is_selinux_enabled() > 0); if (!selinux_enabled) return 0; if (getfilecon(from_file, &from_context) < 0) { /* * If the filesystem doesn't support extended * attributes, the original had no special security * context and the target cannot have one either. */ if (errno == EOPNOTSUPP) return 0; error(0, errno, joe_gettext(_("Could not get security context for %s")), from_file); return 1; } if (getfilecon(to_file, &to_context) < 0) { MSG_PUTS(_(joe_gettext(_("\nCould not get security context for ")))); msg_outtrans(to_file); msg_putchar('\n'); freecon(from_context); return 1; } if (zcmp(from_context, to_context) != 0) { if (setfilecon(to_file, from_context) < 0) { error(0, errno, joe_gettext(_("Could not set security context for %s")), to_file); status = 1; } } freecon(to_context); freecon(from_context); #endif return status; }
int modify_logic(BW *bw,B *b) { if (last_time > b->check_time + CHECK_INTERVAL) { b->check_time = last_time; if (!nomodcheck && !b->gave_notice && check_mod(b)) { file_changed(bw,0,b,NULL); return 0; } } if (b != bw->b) { if (!b->didfirst) { /* This happens when we try to block move from a window which is not on the screen */ if (bw->o.mfirst) { msgnw(bw->parent,joe_gettext(_("Modify other window first for macro"))); return 0; } b->didfirst = 1; if (bw->o.mfirst) exmacro(bw->o.mfirst,1); } if (b->rdonly) { msgnw(bw->parent,joe_gettext(_("Other buffer is read only"))); if (joe_beep) ttputc(7); return 0; } else if (!b->changed && !b->locked) { if (!try_lock(bw,b)) return 0; } } else { if (!b->didfirst) { b->didfirst = 1; if (bw->o.mfirst) exmacro(bw->o.mfirst,1); } if (b->rdonly) { msgnw(bw->parent,joe_gettext(_("Read only"))); if (joe_beep) ttputc(7); return 0; } else if (!b->changed && !b->locked) { if (!try_lock(bw,b)) return 0; } } return 1; }
static RETSIGTYPE fperr(int unused) { if (!merr) { merr = joe_gettext(_("Float point exception")); } REINSTALL_SIGHANDLER(SIGFPE, fperr); }
int utag(BW *bw) { BW *pbw; pbw = wmkpw(bw->parent, joe_gettext(_("Tag search: ")), &taghist, dotag, NULL, NULL, tag_cmplt, NULL, NULL, locale_map, 0); if (pbw && joe_isalnum_(bw->b->o.charmap,brch(bw->cursor))) { P *p = pdup(bw->cursor, "utag"); P *q = pdup(p, "utag"); int c; while (joe_isalnum_(bw->b->o.charmap,(c = prgetc(p)))) /* do nothing */; if (c != NO_MORE_DATA) { pgetc(p); } pset(q, p); while (joe_isalnum_(bw->b->o.charmap,(c = pgetc(q)))) /* do nothing */; if (c != NO_MORE_DATA) { prgetc(q); } binsb(pbw->cursor, bcpy(p, q)); pset(pbw->cursor, pbw->b->eof); pbw->cursor->xcol = piscol(pbw->cursor); prm(p); prm(q); } if (pbw) { return 0; } else { return -1; } }
static int dobknd(BW *bw, int vt) { unsigned char **a; unsigned char *s; unsigned char *sh; unsigned char start_sh[] = ". " JOERC "shell.sh\n"; unsigned char start_csh[] = "source " JOERC "shell.csh\n"; if (!modify_logic(bw,bw->b)) return -1; sh=(unsigned char *)getenv("SHELL"); if (file_exists(sh) && zcmp(sh,USTR "/bin/sh")) goto ok; if (file_exists(sh=USTR "/bin/bash")) goto ok; if (file_exists(sh=USTR "/usr/bin/bash")) goto ok; if (file_exists(sh=USTR "/bin/sh")) goto ok; msgnw(bw->parent, joe_gettext(_("\"SHELL\" environment variable not defined or exported"))); return -1; ok: a = vamk(3); s = vsncpy(NULL, 0, sz(sh)); a = vaadd(a, s); s = vsncpy(NULL, 0, sc("-i")); a = vaadd(a, s); return cstart(bw, sh, a, NULL, NULL, 0, 0, (vt ? (zstr(sh, USTR "csh") ? start_csh : start_sh) : NULL), vt); }
int ttshell(unsigned char *cmd) { int x, omode = ttymode; int stat= -1; unsigned char *s = (unsigned char *)getenv("SHELL"); if (!s) { s = "/bin/sh"; /* return; */ } ttclsn(); if ((x = fork()) != 0) { if (x != -1) wait(&stat); if (omode) ttopnn(); return stat; } else { signrm(); if (cmd) execl((char *)s, (char *)s, "-c", cmd, NULL); else { fprintf(stderr, (char *)joe_gettext(_("You are at the command shell. Type 'exit' to return\n"))); execl((char *)s, (char *)s, NULL); } _exit(0); return 0; } }
int unotmod(BW *bw) { bw_unlock(bw); bw->b->changed = 0; msgnw(bw->parent, joe_gettext(_("Modified flag cleared"))); return 0; }
/* Open terminal */ void ttopnn(void) { int x; struct termios newterm; if (!open_terminal_handles()) { fprintf(stderr, (char *)joe_gettext(_("Couldn\'t open /dev/tty\n"))); exit(1); } joe_set_signal(SIGWINCH, winchd); if (ttymode) return; ttymode = 1; fflush(termout); tcgetattr(fileno(termin), &oldterm); newterm = oldterm; newterm.c_lflag = 0; if (noxon) newterm.c_iflag &= ~(ICRNL | IGNCR | INLCR | IXON | IXOFF); else newterm.c_iflag &= ~(ICRNL | IGNCR | INLCR); newterm.c_oflag = 0; newterm.c_cc[VMIN] = 1; newterm.c_cc[VTIME] = 0; tcsetattr(fileno(termin), TCSADRAIN, &newterm); }
int ubknd(BW *bw) { unsigned char **a; unsigned char *s; unsigned char *sh; if (!modify_logic(bw,bw->b)) return -1; sh=(unsigned char *)getenv("SHELL"); if (file_exists(sh) && zcmp(sh,USTR "/bin/sh")) goto ok; if (file_exists(sh=USTR "/bin/bash")) goto ok; if (file_exists(sh=USTR "/usr/bin/bash")) goto ok; if (file_exists(sh=USTR "/bin/sh")) goto ok; msgnw(bw->parent, joe_gettext(_("\"SHELL\" environment variable not defined or exported"))); return -1; ok: a = vamk(3); s = vsncpy(NULL, 0, sz(sh)); a = vaadd(a, s); s = vsncpy(NULL, 0, sc("-i")); a = vaadd(a, s); return cstart(bw, sh, a, NULL, NULL, 0, 0); }
int uvtbknd(BW *bw) { if (kmap_empty(kmap_getcontext(USTR "vtshell"))) { msgnw(bw->parent, joe_gettext(_(":vtshell keymap is missing"))); return -1; } return dobknd(bw, 1); }
int file_changed(BW *bw,int c,B *b,int *notify) { if (mkqw(bw->parent, sz(joe_gettext(_("Notice: File on disk changed! (hit ^C to continue) "))), file_changed, NULL, b, notify)) { b->gave_notice = 1; return 0; } else return -1; }
int urun(BW *bw) { if (wmkpw(bw->parent, joe_gettext(_("Program to run: ")), &runhist, dorun, USTR "Run", NULL, NULL, NULL, NULL, locale_map, 1)) { return 0; } else { return -1; } }
int uexecmd(BW *bw) { if (wmkpw(bw->parent, joe_gettext(USTR _("Command: ")), &cmdhist, docmd, USTR "cmd", NULL, cmdcmplt, NULL, NULL, locale_map, 0)) { return 0; } else { return -1; } }
int ubknd(BW *bw) { if (kmap_empty(shell_kbd->topmap)) { msgnw(bw->parent, joe_gettext(_(":shell keymap is missing"))); return -1; } return dobknd(bw, 0); }
int usys(W *w, int k) { BW *bw; WIND_BW(bw, w); if (wmkpw(w, joe_gettext(_("System (^C to abort): ")), NULL, dosys, NULL, NULL, NULL, NULL, NULL, bw->b->o.charmap, 1)) return 0; else 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; } }
int ubuild(BW *bw) { if (buildhist) { if ((bw=wmkpw(bw->parent, joe_gettext(_("Build command: ")), &buildhist, dobuild, USTR "Run", NULL, NULL, NULL, NULL, locale_map, 1))) { uuparw(bw); u_goto_eol(bw); bw->cursor->xcol = piscol(bw->cursor); return 0; } else { return -1; } } else { if (wmkpw(bw->parent, joe_gettext(_("Enter build command (for example, 'make'): ")), &buildhist, dobuild, USTR "Run", NULL, NULL, NULL, NULL, locale_map, 1)) { return 0; } else { return -1; } } }
int ucurrent_msg(BW *bw) { if (errptr != &errors) { msgnw(bw->parent, errptr->msg); return 0; } else { msgnw(bw->parent, joe_gettext(_("No messages"))); return -1; } }
void parse_color_def(struct high_color **color_list, unsigned char *p, unsigned char *name, int line) { unsigned char bf[256]; if (!parse_tows(&p, bf)) { struct high_color *color, *gcolor; /* Find color */ color = find_color(*color_list, bf, name); /* If it doesn't exist, create it */ if (!color) { color = joe_malloc(sizeof(struct high_color)); color->name = zdup(bf); color->color = 0; color->next = *color_list; *color_list = color; } else { i_printf_2((char *)joe_gettext(_("%s %d: Class already defined\n")), name, line); } /* Find it in global list */ if (color_list != &global_colors && (gcolor = find_color(global_colors, bf, name))) { color->color = gcolor->color; } else { /* Parse color definition */ while (parse_ws(&p, '#'), !parse_ident(&p, bf, sizeof(bf))) { color->color |= meta_color(bf); } } } else { i_printf_2((char *)joe_gettext(_("%s %d: Missing class name\n")), name, line); } }
static int doisrch(BW *bw, int dir) { /* Create a struct isrch */ struct isrch *isrch = (struct isrch *) joe_malloc(SIZEOF(struct isrch)); izque(IREC, link, &isrch->irecs); isrch->pattern = vsncpy(NULL, 0, NULL, 0); isrch->dir = dir; isrch->quote = 0; isrch->prompt = vsncpy(NULL, 0, sz(joe_gettext(_("I-find: ")))); isrch->ofst = sLen(isrch->prompt); return itype(bw->parent, -1, isrch, NULL); }
int ukillpid(BW *bw) { if (bw->b->pid) { if (mkqw(bw->parent, sz(joe_gettext(_("Kill program (y,n,^C)?"))), pidabort, NULL, NULL, NULL)) { return 0; } else { return -1; } } else { return 0; } }
int ugrep(BW *bw) { /* Set parser to grep */ bw->b->parseone = parseone_grep; if (grephist) { if ((bw=wmkpw(bw->parent, joe_gettext(_("Grep command: ")), &grephist, dobuild, USTR "Run", NULL, NULL, NULL, NULL, locale_map, 1))) { uuparw(bw); u_goto_eol(bw); bw->cursor->xcol = piscol(bw->cursor); return 0; } else { return -1; } } else { if (wmkpw(bw->parent, joe_gettext(_("Enter grep command (for example, 'grep -n foo *.c'): ")), &grephist, dobuild, USTR "Run", NULL, NULL, NULL, NULL, locale_map, 1)) { return 0; } else { return -1; } } }
/**** 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); }