int setquotelevelinregion(int quotelevel, REGION *addedregion) { int i, standards_based = 0; int quote_chars = 0, backuptoprevline = 0; int starts_midline = 0, ends_midline = 0, offset_into_start; long c, sz; UCS qstr_def1[] = { '>', ' ', 0}, qstr_def2[] = { '>', 0}; LINE *lp, *line_before_start; REGION region; if(curbp->b_mode&MDVIEW) /* don't allow this command if */ return(rdonly()); /* we are in read only mode */ if(!glo_quote_str || !ucs4_strcmp(glo_quote_str, qstr_def1) || !ucs4_strcmp(glo_quote_str, qstr_def2)) standards_based++; if(!standards_based){ emlwrite("Quote level setting only works with standard \"> \" quotes", NULL); return(FALSE); } /* if region starts midline insert a newline */ if(curwp->w_doto > 0 && curwp->w_doto < llength(curwp->w_dotp)) starts_midline++; /* if region ends midline insert a newline at end */ if(curwp->w_marko > 0 && curwp->w_marko < llength(curwp->w_markp)){ ends_midline++; backuptoprevline++; /* count quote chars for re-insertion */ for(i = 0; i < llength(curwp->w_markp); ++i) if(lgetc(curwp->w_markp, i).c != '>') break; quote_chars = i; } else if(curwp->w_marko == 0) backuptoprevline++; /* find the size of the region */ getregion(®ion, curwp->w_markp, curwp->w_marko); /* cut the paragraph into our fill buffer */ fdelete(); if(!ldelete(region.r_size, finsert)) return(FALSE); line_before_start = lback(curwp->w_dotp); offset_into_start = curwp->w_doto; /* if region starts midline add a newline */ if(starts_midline) lnewline(); i = 0; while(fremove(i) >= 0){ /* remove all quote strs from current line */ if(standards_based){ while((c = fremove(i)) == '>') i++; if(c == ' ') i++; } else{ } /* insert quotelevel quote strs */ if(standards_based){ linsert(quotelevel, '>'); if(quotelevel > 0) linsert(1, ' '); } else{ } /* put back the actual line */ while((c = fremove(i++)) >= 0 && c != '\n') linsert(1, (UCS) c); if(c == '\n') lnewline(); } /* if region ends midline add a newline */ if(ends_midline){ lnewline(); if(quote_chars){ linsert(quote_chars, '>'); if(curwp->w_doto < llength(curwp->w_dotp) && lgetc(curwp->w_dotp, curwp->w_doto).c != ' ') linsert(1, ' '); } } /* * Calculate the size of the region that was added. */ swapmark(0,1); /* mark current location after adds */ addedregion->r_linep = lforw(line_before_start); addedregion->r_offset = offset_into_start; lp = addedregion->r_linep; sz = llength(lp) - addedregion->r_offset; if(lforw(lp) != curwp->w_markp->l_fp){ lp = lforw(lp); while(lp != curwp->w_markp->l_fp){ sz += llength(lp) + 1; lp = lforw(lp); } } sz -= llength(curwp->w_markp) - curwp->w_marko; addedregion->r_size = sz; swapmark(0,1); /* * This puts us at the end of the quoted region instead * of on the following line. This makes it convenient * for the user to follow a quotelevel adjustment with * a Justify if desired. */ if(backuptoprevline){ curwp->w_doto = 0; backchar(0, 1); } if(ends_midline){ /* doesn't need fixing otherwise */ unmarkbuffer(); markregion(1); } return (TRUE); }
int readpattern(char *utf8prompt, int text_mode) { register int s; int i; UCS *b; UCS tpat[NPAT+20]; UCS *tpatp; EXTRAKEYS menu_pat[7]; menu_pat[i = 0].name = "^Y"; menu_pat[i].label = N_("FirstLine"); menu_pat[i].key = (CTRL|'Y'); KS_OSDATASET(&menu_pat[i], KS_NONE); menu_pat[++i].name = "^V"; menu_pat[i].label = N_("LastLine"); menu_pat[i].key = (CTRL|'V'); KS_OSDATASET(&menu_pat[i], KS_NONE); if(text_mode){ menu_pat[++i].name = "^T"; menu_pat[i].label = N_("LineNumber"); menu_pat[i].key = (CTRL|'T'); KS_OSDATASET(&menu_pat[i], KS_NONE); menu_pat[++i].name = "^W"; menu_pat[i].label = N_("Start of Para"); menu_pat[i].key = (CTRL|'W'); KS_OSDATASET(&menu_pat[i], KS_NONE); menu_pat[++i].name = "^O"; menu_pat[i].label = N_("End of Para"); menu_pat[i].key = (CTRL|'O'); KS_OSDATASET(&menu_pat[i], KS_NONE); menu_pat[++i].name = "^U"; menu_pat[i].label = N_("FullJustify"); menu_pat[i].key = (CTRL|'U'); KS_OSDATASET(&menu_pat[i], KS_NONE); } menu_pat[++i].name = NULL; b = utf8_to_ucs4_cpystr(utf8prompt); if(b){ ucs4_strncpy(tpat, b, NPAT+20); tpat[NPAT+20-1] = '\0'; fs_give((void **) &b); } tpatp = &tpat[ucs4_strlen(tpat)]; if(pat[0] != '\0'){ if((tpatp-tpat) < NPAT+20-2){ *tpatp++ = ' '; *tpatp++ = '['; *tpatp = '\0'; } expandp(pat, tpatp, NPAT+20-(tpatp-tpat)); tpat[NPAT+20-1] = '\0'; tpatp += ucs4_strlen(tpatp); if((tpatp-tpat) < NPAT+20-1){ *tpatp++ = ']'; *tpatp = '\0'; } } if((tpatp-tpat) < NPAT+20-3){ *tpatp++ = ' '; *tpatp++ = ':'; *tpatp++ = ' '; *tpatp = '\0'; } tpat[NPAT+20-1] = '\0'; s = mlreplyd(tpat, tpat, NPAT, QNORML, menu_pat); if ((s == TRUE) && ucs4_strcmp(pat,tpat)){ /* Specified */ ucs4_strncpy(pat, tpat, NPAT); pat[NPAT-1] = '\0'; rpat[0] = '\0'; } else if (s == FALSE && pat[0] != '\0') /* CR, but old one */ s = TRUE; return(s); }
/* * spell() - check for potentially missspelled words and offer them for * correction */ int spell(int f, int n) { int status, next, ret; char ccb[NLINE], *sp, *fn, *lp, *wsp, c, spc[NLINE]; UCS *b; UCS wb[NLINE], cb[NLINE]; EML eml; setimark(0, 1); emlwrite(_("Checking spelling..."), NULL); /* greetings */ if(alt_speller) return(alt_editor(1, 0)); /* f == 1 means fork speller */ if((fn = writetmp(0, NULL)) == NULL){ emlwrite(_("Can't write temp file for spell checker"), NULL); return(-1); } if((sp = (char *)getenv("SPELL")) == NULL) sp = SPELLER; /* exists? */ ret = (strlen(sp) + 1); snprintf(spc, sizeof(spc), "%s", sp); for(lp = spc, ret = FIOERR; *lp; lp++){ if((wsp = strpbrk(lp, " \t")) != NULL){ c = *wsp; *wsp = '\0'; } if(strchr(lp, '/')){ ret = fexist(lp, "x", (off_t *)NULL); } else{ char *path, fname[MAXPATH+1]; if(!(path = getenv("PATH"))) path = ":/bin:/usr/bin"; ret = ~FIOSUC; while(ret != FIOSUC && *path && pathcat(fname, &path, lp)) ret = fexist(fname, "x", (off_t *)NULL); } if(wsp) *wsp = c; if(ret == FIOSUC) break; } if(ret != FIOSUC){ eml.s = sp; emlwrite(_("\007Spell-checking file \"%s\" not found"), &eml); return(-1); } snprintf(ccb, sizeof(ccb), "( %s ) < %s", sp, fn); if(P_open(ccb) != FIOSUC){ /* read output from command */ our_unlink(fn); emlwrite(_("Can't fork spell checker"), NULL); return(-1); } ret = 1; while(ffgetline(wb, NLINE, NULL, 0) == FIOSUC && ret){ if((b = ucs4_strchr(wb, (UCS) '\n')) != NULL) *b = '\0'; ucs4_strncpy(cb, wb, NLINE); cb[NLINE-1] = '\0'; gotobob(0, 1); status = TRUE; next = 1; while(status){ if(next++) if(movetoword(wb) != TRUE) break; update(); (*term.t_rev)(1); pputs(wb, 1); /* highlight word */ (*term.t_rev)(0); if(ucs4_strcmp(cb, wb)){ char prompt[2*NLINE + 32]; char *wbu, *cbu; wbu = ucs4_to_utf8_cpystr(wb); cbu = ucs4_to_utf8_cpystr(cb); snprintf(prompt, sizeof(prompt), _("Replace \"%s\" with \"%s\""), wbu, cbu); status=mlyesno_utf8(prompt, TRUE); if(wbu) fs_give((void **) &wbu); if(cbu) fs_give((void **) &cbu); } else{ UCS *p; p = utf8_to_ucs4_cpystr(_("Edit a replacement: ")); status=mlreplyd(p, cb, NLINE, QDEFLT, NULL); if(p) fs_give((void **) &p); } curwp->w_flag |= WFMOVE; /* put cursor back */ sgarbk = 0; /* fake no-keymenu-change! */ update(); pputs(wb, 0); /* un-highlight */ switch(status){ case TRUE: chword(wb, cb, 0); /* correct word */ case FALSE: update(); /* place cursor */ break; case ABORT: emlwrite(_("Spell Checking Cancelled"), NULL); ret = FALSE; status = FALSE; break; case HELPCH: if(Pmaster){ VARS_TO_SAVE *saved_state; saved_state = save_pico_state(); (*Pmaster->helper)(pinespellhelp, _("Help with Spelling Checker"), 1); if(saved_state){ restore_pico_state(saved_state); free_pico_state(saved_state); } } else pico_help(spellhelp, _("Help with Spelling Checker"), 1); case (CTRL|'L'): next = 0; /* don't get next word */ sgarbf = TRUE; /* repaint full screen */ update(); status = TRUE; continue; default: emlwrite("Huh?", NULL); /* shouldn't get here, but.. */ status = TRUE; sleep(1); break; } forwword(0, 1); /* goto next word */ } } P_close(); /* clean up */ our_unlink(fn); swapimark(0, 1); curwp->w_flag |= WFHARD|WFMODE; sgarbk = TRUE; if(ret) emlwrite(_("Done checking spelling"), NULL); return(ret); }
/* Read a replacement pattern. Modeled after readpattern(). */ int srpat(char *utf8prompt, UCS *defpat, size_t defpatlen, int repl_mode) { register int s; int i = 0; UCS *b; UCS prompt[NPMT]; UCS *promptp; EXTRAKEYS menu_pat[8]; menu_pat[i = 0].name = "^Y"; menu_pat[i].label = N_("FirstLine"); menu_pat[i].key = (CTRL|'Y'); KS_OSDATASET(&menu_pat[i], KS_NONE); menu_pat[++i].name = "^V"; menu_pat[i].label = N_("LastLine"); menu_pat[i].key = (CTRL|'V'); KS_OSDATASET(&menu_pat[i], KS_NONE); menu_pat[++i].name = "^R"; menu_pat[i].label = repl_mode ? N_("No Replace") : N_("Replace"); menu_pat[i].key = (CTRL|'R'); KS_OSDATASET(&menu_pat[i], KS_NONE); if(!repl_mode){ menu_pat[++i].name = "^T"; menu_pat[i].label = N_("LineNumber"); menu_pat[i].key = (CTRL|'T'); KS_OSDATASET(&menu_pat[i], KS_NONE); menu_pat[++i].name = "^W"; /* TRANSLATORS: Start of paragraph */ menu_pat[i].label = N_("Start of Para"); menu_pat[i].key = (CTRL|'W'); KS_OSDATASET(&menu_pat[i], KS_NONE); menu_pat[++i].name = "^O"; menu_pat[i].label = N_("End of Para"); menu_pat[i].key = (CTRL|'O'); KS_OSDATASET(&menu_pat[i], KS_NONE); menu_pat[++i].name = "^U"; /* TRANSLATORS: Instead of justifying (formatting) just a single paragraph, Full Justify justifies the entire message. */ menu_pat[i].label = N_("FullJustify"); menu_pat[i].key = (CTRL|'U'); KS_OSDATASET(&menu_pat[i], KS_NONE); } menu_pat[++i].name = NULL; b = utf8_to_ucs4_cpystr(utf8prompt); if(b){ ucs4_strncpy(prompt, b, NPMT); prompt[NPMT-1] = '\0'; fs_give((void **) &b); } promptp = &prompt[ucs4_strlen(prompt)]; if(repl_mode){ b = utf8_to_ucs4_cpystr(" (to replace)"); if(b){ ucs4_strncpy(promptp, b, NPMT-(promptp-prompt)); promptp += ucs4_strlen(promptp); prompt[NPMT-1] = '\0'; fs_give((void **) &b); } } if(pat[0] != '\0'){ if((promptp-prompt) < NPMT-2){ *promptp++ = ' '; *promptp++ = '['; *promptp = '\0'; } expandp(pat, promptp, NPMT-(promptp-prompt)); prompt[NPMT-1] = '\0'; promptp += ucs4_strlen(promptp); if((promptp-prompt) < NPMT-1){ *promptp++ = ']'; *promptp = '\0'; } } if((promptp-prompt) < NPMT-2){ *promptp++ = ':'; *promptp++ = ' '; *promptp = '\0'; } prompt[NPMT-1] = '\0'; s = mlreplyd(prompt, defpat, defpatlen, QDEFLT, menu_pat); if (s == TRUE || s == FALSE){ /* changed or not, they're done */ if(!defpat[0]){ /* use default */ ucs4_strncpy(defpat, pat, defpatlen); defpat[defpatlen-1] = '\0'; } else if(ucs4_strcmp(pat, defpat)){ /* Specified */ ucs4_strncpy(pat, defpat, NPAT); pat[NPAT-1] = '\0'; rpat[0] = '\0'; } s = TRUE; /* let caller know to proceed */ } return(s); }