/* * This one is a little more complicated because it comes late in the * filtering sequence after colors have been added and url's hilited and * so on. So if it wants to look at the beginning of the line it has to * wade through some stuff done by the other filters first. This one is * skipping the leading indent added by the viewer-margin stuff and leading * tags. */ int delete_quotes(long int linenum, char *line, LT_INS_S **ins, void *local) { DELQ_S *dq; char *lp; int i, lines, not_a_quote = 0, code; size_t len; dq = (DELQ_S *) local; if(!dq) return(0); if(dq->lines > 0 || dq->lines == Q_DEL_ALL){ lines = (dq->lines == Q_DEL_ALL) ? 0 : dq->lines; /* * First determine if this line is part of a quote. */ /* skip over indent added by viewer-margin-left */ lp = line; for(i = dq->indent_length; i > 0 && !not_a_quote && *lp; i--) if(*lp++ != SPACE) not_a_quote++; while(isspace((unsigned char) *lp)) lp++; /* skip over leading tags */ while(!not_a_quote && ((unsigned char) (*lp) == (unsigned char) TAG_EMBED)){ switch(*++lp){ case '\0': not_a_quote++; break; default: ++lp; break; case TAG_FGCOLOR: case TAG_BGCOLOR: case TAG_HANDLE: switch(*lp){ case TAG_FGCOLOR: case TAG_BGCOLOR: len = RGBLEN + 1; break; case TAG_HANDLE: len = *++lp + 1; break; } if(strlen(lp) < len) not_a_quote++; else lp += len; break; case TAG_EMBED: break; } } len = lp - line; if(strlen(tmp_20k_buf) > len) strcpy(tmp_20k_buf, tmp_20k_buf+len); code = (dq->is_flowed ? IS_FLOWED : NO_FLOWED) | DELETEQUO; select_quote(linenum, lp, ins, &code); if (!not_a_quote && !tmp_20k_buf[0]) not_a_quote++; if(not_a_quote){ if(dq->in_quote > lines+1 && !dq->delete_all){ char tmp[500]; COLOR_PAIR *col = NULL; char cestart[2 * RGBLEN + 5]; char ceend[2 * RGBLEN + 5]; /* * Display how many lines were hidden. */ cestart[0] = ceend[0] = '\0'; if(dq->do_color && ps_global->VAR_METAMSG_FORE_COLOR && ps_global->VAR_METAMSG_BACK_COLOR && (col = new_color_pair(ps_global->VAR_METAMSG_FORE_COLOR, ps_global->VAR_METAMSG_BACK_COLOR))) if(!pico_is_good_colorpair(col)) free_color_pair(&col); if(col){ strncpy(cestart, color_embed(col->fg, col->bg), sizeof(cestart)); cestart[sizeof(cestart)-1] = '\0'; strncpy(ceend, color_embed(ps_global->VAR_NORM_FORE_COLOR, ps_global->VAR_NORM_BACK_COLOR), sizeof(ceend)); ceend[sizeof(ceend)-1] = '\0'; free_color_pair(&col); } snprintf(tmp, sizeof(tmp), "%s[ %s%d lines of quoted text hidden from view%s ]\r\n", repeat_char(dq->indent_length, SPACE), cestart, dq->in_quote - lines, ceend); if(strlen(tmp)-strlen(cestart)-strlen(ceend)-2 > ps_global->ttyo->screen_cols){ snprintf(tmp, sizeof(tmp), "%s[ %s%d lines of quoted text hidden%s ]\r\n", repeat_char(dq->indent_length, SPACE), cestart, dq->in_quote - lines, ceend); if(strlen(tmp)-strlen(cestart)-strlen(ceend)-2 > ps_global->ttyo->screen_cols){ snprintf(tmp, sizeof(tmp), "%s[ %s%d lines hidden%s ]\r\n", repeat_char(dq->indent_length, SPACE), cestart, dq->in_quote - lines, ceend); if(strlen(tmp)-strlen(cestart)-strlen(ceend)-2 > ps_global->ttyo->screen_cols){ snprintf(tmp, sizeof(tmp), "%s[ %s%d hidden%s ]\r\n", repeat_char(dq->indent_length, SPACE), cestart, dq->in_quote - lines, ceend); if(strlen(tmp)-strlen(cestart)-strlen(ceend)-2 > ps_global->ttyo->screen_cols){ snprintf(tmp, sizeof(tmp), "%s[...]\r\n", repeat_char(dq->indent_length, SPACE)); if(strlen(tmp)-2 > ps_global->ttyo->screen_cols){ snprintf(tmp, sizeof(tmp), "%s...\r\n", repeat_char(dq->indent_length, SPACE)); if(strlen(tmp)-2 > ps_global->ttyo->screen_cols){ snprintf(tmp, sizeof(tmp), "%s\r\n", repeat_char(MIN(ps_global->ttyo->screen_cols,3), '.')); } } } } } } ins = gf_line_test_new_ins(ins, line, tmp, strlen(tmp)); mark_handles_in_line(line, dq->handlesp, 1); ps_global->some_quoting_was_suppressed = 1; } else if(dq->in_quote == lines+1 && dq->saved_line && *dq->saved_line){ /* * We would have only had to delete a single line. Instead * of deleting it, just show it. */ ins = gf_line_test_new_ins(ins, line, *dq->saved_line, strlen(*dq->saved_line)); mark_handles_in_line(*dq->saved_line, dq->handlesp, 1); } else mark_handles_in_line(line, dq->handlesp, 1); if(dq->saved_line && *dq->saved_line) fs_give((void **) dq->saved_line); dq->in_quote = 0; } else{ dq->in_quote++; /* count it */ if(dq->in_quote > lines){ /* * If the hidden part is a single line we'll show it instead. */ if(dq->in_quote == lines+1 && !dq->delete_all){ if(dq->saved_line && *dq->saved_line) fs_give((void **) dq->saved_line); *dq->saved_line = fs_get(strlen(line) + 3); snprintf(*dq->saved_line, strlen(line)+3, "%s\r\n", line); } mark_handles_in_line(line, dq->handlesp, 0); /* skip it, at least for now */ return(2); } mark_handles_in_line(line, dq->handlesp, 1); } } return(0); }
int quote_editorial(long int linenum, char *line, LT_INS_S **ins, void *local) { COLOR_PAIR *col = NULL; ins = gf_line_test_new_ins(ins, line, ((EDITORIAL_S *)local)->prefix, ((EDITORIAL_S *)local)->prelen); if(((EDITORIAL_S *)local)->do_color && ps_global->VAR_METAMSG_FORE_COLOR && ps_global->VAR_METAMSG_BACK_COLOR && (col = new_color_pair(ps_global->VAR_METAMSG_FORE_COLOR, ps_global->VAR_METAMSG_BACK_COLOR))){ if(!pico_is_good_colorpair(col)) free_color_pair(&col); if(col){ char *p; char normal_embed[(2 * RGBLEN) + 5]; char quote_color_embed[(2 * RGBLEN) + 5]; strncpy(quote_color_embed, color_embed(col->fg, col->bg), sizeof(quote_color_embed)); quote_color_embed[sizeof(quote_color_embed)-1] = '\0'; ins = gf_line_test_new_ins(ins, line, quote_color_embed, (2 * RGBLEN) + 4); /* * If there was already a color change back to normal color * in the line that was passed in, then instead of allowing * that color change back to normal we want to change that * to a color change back to our METAMSG color instead. * Search line for that and modify it. */ strncpy(normal_embed, color_embed(ps_global->VAR_NORM_FORE_COLOR, ps_global->VAR_NORM_BACK_COLOR), sizeof(normal_embed)); normal_embed[sizeof(normal_embed)-1] = '\0'; for(p = line; (p = strstr(p, normal_embed)); p++){ /* * Replace the normal color with our special quoting * color. No need to change it if there are no * characters after the color change because we're * going to change the color to normal right below * this anyway. */ if(strlen(p) > strlen(quote_color_embed)) rplstr(p, strlen(p)+1, strlen(quote_color_embed), quote_color_embed); } ins = gf_line_test_new_ins(ins, line+strlen(line), normal_embed, (2 * RGBLEN) + 4); free_color_pair(&col); } } ins = gf_line_test_new_ins(ins, line + strlen(line), ((EDITORIAL_S *)local)->postfix, ((EDITORIAL_S *)local)->postlen); return(0); }