/* * rtfrmshell - back from shell, fix modes and return */ RETSIGTYPE rtfrmshell(int sig) { signal(SIGCONT, SIG_DFL); ttopen(); ttresize(); pclear(0, term.t_nrow); pico_refresh(0, 1); }
int composer_file_drop(int x, int y, char *filename) { int attached = 0; EML eml; if((ComposerTopLine > 2 && x <= ComposerTopLine) || !LikelyASCII(filename)){ AppendAttachment(filename, NULL, NULL); attached++; } else{ setimark(FALSE, 1); ifile(filename); swapimark(FALSE, 1); } if(ComposerEditing){ /* update display */ PaintBody(0); } else{ pico_refresh(0, 1); update(); } eml.s = filename; if(attached) emlwrite(_("Attached dropped file \"%s\""), &eml); else emlwrite(_("Inserted dropped file \"%s\""), &eml); if(ComposerEditing){ /* restore cursor */ HeaderPaintCursor(); } else{ curwp->w_flag |= WFHARD; update(); } return(1); }
/* * bktoshell - suspend and wait to be woken up */ int bktoshell(int f, int n) { UCS z = CTRL | 'Z'; if(!(gmode&MDSSPD)){ unknown_command(z); return(FALSE); } if(Pmaster){ if(!Pmaster->suspend){ unknown_command(z); return(FALSE); } if((*Pmaster->suspend)() == NO_OP_COMMAND){ int rv; if(km_popped){ term.t_mrow = 2; curwp->w_ntrows -= 2; } clearcursor(); mlerase(); rv = (*Pmaster->showmsg)('x'); ttresize(); picosigs(); if(rv) /* Did showmsg corrupt the display? */ pico_refresh(0, 1); /* Yes, repaint */ mpresf = 1; if(km_popped){ term.t_mrow = 0; curwp->w_ntrows += 2; } } else{ ttresize(); pclear(0, term.t_nrow); pico_refresh(0, 1); } return(TRUE); } if(gmode&MDSPWN){ char *shell; int dummy; vttidy(); movecursor(0, 0); (*term.t_eeop)(); printf("\n\n\nUse \"exit\" to return to Pi%s\n", (gmode & MDBRONLY) ? "lot" : "co"); system((shell = (char *)getenv("SHELL")) ? shell : "/bin/csh"); rtfrmshell(dummy); /* fixup tty */ } else { movecursor(term.t_nrow-1, 0); peeol(); movecursor(term.t_nrow, 0); peeol(); movecursor(term.t_nrow, 0); printf("\n\n\nUse \"fg\" to return to Pi%s\n", (gmode & MDBRONLY) ? "lot" : "co"); ttclose(); movecursor(term.t_nrow, 0); peeol(); (*term.t_flush)(); signal(SIGCONT, rtfrmshell); /* prepare to restart */ signal(SIGTSTP, SIG_DFL); /* prepare to stop */ kill(0, SIGTSTP); } return(TRUE); }
/* Replace a pattern with the pattern the user types in one or more times. */ int replace_pat(UCS *defpat, int *wrapt) { register int status; UCS lpat[NPAT], origpat[NPAT]; /* case sensitive pattern */ EXTRAKEYS menu_pat[2]; int repl_all = FALSE; UCS *b; char utf8tmp[NPMT]; UCS prompt[NPMT]; UCS *promptp; forscan(wrapt, defpat, NULL, 0, PTBEG); /* go to word to be replaced */ lpat[0] = '\0'; /* additional 'replace all' menu option */ menu_pat[0].name = "^X"; menu_pat[0].key = (CTRL|'X'); menu_pat[0].label = N_("Repl All"); KS_OSDATASET(&menu_pat[0], KS_NONE); menu_pat[1].name = NULL; while(1) { update(); (*term.t_rev)(1); get_pat_cases(origpat, defpat); pputs(origpat, 1); /* highlight word */ (*term.t_rev)(0); snprintf(utf8tmp, NPMT, "Replace%s \"", repl_all ? " every" : ""); b = utf8_to_ucs4_cpystr(utf8tmp); if(b){ ucs4_strncpy(prompt, b, NPMT); prompt[NPMT-1] = '\0'; fs_give((void **) &b); } promptp = &prompt[ucs4_strlen(prompt)]; expandp(defpat, promptp, NPMT-(promptp-prompt)); prompt[NPMT-1] = '\0'; promptp += ucs4_strlen(promptp); b = utf8_to_ucs4_cpystr("\" with"); if(b){ ucs4_strncpy(promptp, b, NPMT-(promptp-prompt)); promptp += ucs4_strlen(promptp); prompt[NPMT-1] = '\0'; fs_give((void **) &b); } if(rpat[0] != '\0'){ if((promptp-prompt) < NPMT-2){ *promptp++ = ' '; *promptp++ = '['; *promptp = '\0'; } expandp(rpat, promptp, NPMT-(promptp-prompt)); prompt[NPMT-1] = '\0'; promptp += ucs4_strlen(promptp); if((promptp-prompt) < NPMT-1){ *promptp++ = ']'; *promptp = '\0'; } } if((promptp-prompt) < NPMT-3){ *promptp++ = ' '; *promptp++ = ':'; *promptp++ = ' '; *promptp = '\0'; } prompt[NPMT-1] = '\0'; status = mlreplyd(prompt, lpat, NPAT, QDEFLT, menu_pat); curwp->w_flag |= WFMOVE; switch(status){ case TRUE : case FALSE : if(lpat[0]){ ucs4_strncpy(rpat, lpat, NPAT); /* remember default */ rpat[NPAT-1] = '\0'; } else{ ucs4_strncpy(lpat, rpat, NPAT); /* use default */ lpat[NPAT-1] = '\0'; } if (repl_all){ status = replace_all(defpat, lpat); } else{ chword(defpat, lpat); /* replace word */ update(); status = TRUE; } if(status == TRUE) emlwrite("", NULL); return(status); case HELPCH: /* help requested */ if(Pmaster){ VARS_TO_SAVE *saved_state; saved_state = save_pico_state(); (*Pmaster->helper)(Pmaster->search_help, _("Help for Searching"), 1); if(saved_state){ restore_pico_state(saved_state); free_pico_state(saved_state); } } else pico_help(SearchHelpText, _("Help for Searching"), 1); case (CTRL|'L'): /* redraw requested */ pico_refresh(FALSE, 1); update(); break; case (CTRL|'X'): /* toggle replace all option */ if (repl_all){ repl_all = FALSE; /* TRANSLATORS: abbreviation for Replace All occurences */ menu_pat[0].label = N_("Repl All"); } else{ repl_all = TRUE; /* TRANSLATORS: Replace just one occurence */ menu_pat[0].label = N_("Repl One"); } break; default: if(status == ABORT){ emlwrite(_("Replacement Cancelled"), NULL); pico_refresh(FALSE, 1); } else{ mlerase(); chword(defpat, origpat); } update(); return(FALSE); } } }
int forwsearch(int f, int n) { int status; int wrapt = FALSE, wrapt2 = FALSE; int repl_mode = FALSE; UCS defpat[NPAT]; int search = FALSE; EML eml; /* resolve the repeat count */ if (n == 0) n = 1; if (n < 1) /* search backwards */ FWS_RETURN(0); defpat[0] = '\0'; /* ask the user for the text of a pattern */ while(1){ if (gmode & MDREPLACE) status = srpat("Search", defpat, NPAT, repl_mode); else status = readpattern("Search", TRUE); switch(status){ case TRUE: /* user typed something */ search = TRUE; break; case HELPCH: /* help requested */ if(Pmaster){ VARS_TO_SAVE *saved_state; saved_state = save_pico_state(); (*Pmaster->helper)(Pmaster->search_help, _("Help for Searching"), 1); if(saved_state){ restore_pico_state(saved_state); free_pico_state(saved_state); } } else pico_help(SearchHelpText, _("Help for Searching"), 1); case (CTRL|'L'): /* redraw requested */ pico_refresh(FALSE, 1); update(); break; case (CTRL|'V'): gotoeob(0, 1); mlerase(); FWS_RETURN(TRUE); case (CTRL|'Y'): gotobob(0, 1); mlerase(); FWS_RETURN(TRUE); case (CTRL|'T') : switch(status = readnumpat(_("Search to Line Number : "))){ case -1 : emlwrite(_("Search to Line Number Cancelled"), NULL); FWS_RETURN(FALSE); case 0 : emlwrite(_("Line number must be greater than zero"), NULL); FWS_RETURN(FALSE); case -2 : emlwrite(_("Line number must contain only digits"), NULL); FWS_RETURN(FALSE); case -3 : continue; default : gotoline(0, status); mlerase(); FWS_RETURN(TRUE); } break; case (CTRL|'W'): { LINE *linep = curwp->w_dotp; int offset = curwp->w_doto; gotobop(0, 1); gotobol(0, 1); /* * if we're asked to backup and we're already * */ if((lastflag & CFSRCH) && linep == curwp->w_dotp && offset == curwp->w_doto && !(offset == 0 && lback(linep) == curbp->b_linep)){ backchar(0, 1); gotobop(0, 1); gotobol(0, 1); } } mlerase(); FWS_RETURN(TRUE); case (CTRL|'O'): if(curwp->w_dotp != curbp->b_linep){ gotoeop(0, 1); forwchar(0, 1); } mlerase(); FWS_RETURN(TRUE); case (CTRL|'U'): fillbuf(0, 1); mlerase(); FWS_RETURN(TRUE); case (CTRL|'R'): /* toggle replacement option */ repl_mode = !repl_mode; break; default: if(status == ABORT) emlwrite(_("Search Cancelled"), NULL); else mlerase(); FWS_RETURN(FALSE); } /* replace option is disabled */ if (!(gmode & MDREPLACE)){ ucs4_strncpy(defpat, pat, NPAT); defpat[NPAT-1] = '\0'; break; } else if (search){ /* search now */ ucs4_strncpy(pat, defpat, NPAT); /* remember this search for the future */ pat[NPAT-1] = '\0'; break; } } /* * This code is kind of dumb. What I want is successive C-W 's to * move dot to successive occurences of the pattern. So, if dot is * already sitting at the beginning of the pattern, then we'll move * forward a char before beginning the search. We'll let the * automatic wrapping handle putting the dot back in the right * place... */ status = 0; /* using "status" as int temporarily! */ while(1){ if(defpat[status] == '\0'){ forwchar(0, 1); break; /* find next occurence! */ } if(status + curwp->w_doto >= llength(curwp->w_dotp) || !eq(defpat[status],lgetc(curwp->w_dotp, curwp->w_doto + status).c)) break; /* do nothing! */ status++; } /* search for the pattern */ while (n-- > 0) { if((status = forscan(&wrapt,defpat,NULL,0,PTBEG)) == FALSE) break; } /* and complain if not there */ if (status == FALSE){ char *utf8; UCS x[1]; x[0] = '\0'; utf8 = ucs4_to_utf8_cpystr(defpat ? defpat : x); /* TRANSLATORS: reporting the result of a failed search */ eml.s = utf8; emlwrite(_("\"%s\" not found"), &eml); if(utf8) fs_give((void **) &utf8); } else if((gmode & MDREPLACE) && repl_mode == TRUE){ status = replace_pat(defpat, &wrapt2); /* replace pattern */ if (wrapt == TRUE || wrapt2 == TRUE){ eml.s = (status == ABORT) ? "cancelled but wrapped" : "Wrapped"; emlwrite("Replacement %s", &eml); } } else if(wrapt == TRUE){ emlwrite("Search Wrapped", NULL); } else if(status == TRUE){ emlwrite("", NULL); } FWS_RETURN(status); }