Subject: Re: Compiling pine 4.60 fails for first time.

From: Jeff Franklin <[email-masked]>
Date: Fri, 4 Jun 2004 15:45:59 -0700 (PDT)

On Tue, 11 May 2004, Jared Griffith wrote:

> Pine has compiled successfully on my HP-UX 10.20 workstation since about
> 4.33, until now.  I am trying to compile 4.60 and I get the following:
>
>  Making Pine and rpload/rpdump.
>  make CC=gcc DEBUG=-O3 -f makefile.ghp
>          rm -f os.h
>          ln -s osdep/os-hpx.h os.h
>          gcc   -O3     -DHPP -DSYSTYPE=\"GHP\" -DMOUSE -c filter.c
>  filter.c: In function `gf_wrap':
>  filter.c:7657: virtual memory exhausted
>  *** Error exit code 1
>
>  Stop.

There were some macros in filter.c that grew a good deal in 4.60, which 
apparently some systems are having trouble with.  The attached patch ought 
to fix it to compile on your system.

Jeff

--- filter.c	2004/05/07 17:43:31	4.260
+++ filter.c	2004/06/04 22:21:48
@@ -1,5 +1,5 @@
 #if !defined(lint) && !defined(DOS)
-static char rcsid[] = "$Id: filter.c,v 4.260 2004/05/07 17:43:31 mikes Exp $";
+static char rcsid[] = "$Id: filter.c,v 4.264 2004/06/04 22:14:37 jpf Exp $";
 #endif
 /*----------------------------------------------------------------------
 
@@ -718,17 +718,20 @@
 #define	GF_QUE_END(F)	(&(F)->queue[GF_MAXBUF - 1])
 
 #define	GF_IP_INIT(F)	ip  = (F) ? &(F)->queue[(F)->queuein] : NULL
+#define	GF_IP_INIT_GLO(F)  (*ipp)  = (F) ? &(F)->queue[(F)->queuein] : NULL
 #define	GF_EIB_INIT(F)	eib = (F) ? GF_QUE_END(F) : NULL
+#define	GF_EIB_INIT_GLO(F)  (*eibp) = (F) ? GF_QUE_END(F) : NULL
 #define	GF_OP_INIT(F)	op  = (F) ? &(F)->queue[(F)->queueout] : NULL
 #define	GF_EOB_INIT(F)	eob = (F) ? &(F)->queue[(F)->queuein] : NULL
 
 #define	GF_IP_END(F)	(F)->queuein  = ip - GF_QUE_START(F)
+#define	GF_IP_END_GLO(F)  (F)->queuein  = (unsigned char *)(*ipp) - (unsigned char *)GF_QUE_START(F)
 #define	GF_OP_END(F)	(F)->queueout = op - GF_QUE_START(F)
 
-#define	GF_INIT(FI, FO)	register unsigned char *GF_OP_INIT(FI);	 \
-			register unsigned char *GF_EOB_INIT(FI); \
-			register unsigned char *GF_IP_INIT(FO);  \
-			register unsigned char *GF_EIB_INIT(FO);
+#define	GF_INIT(FI, FO)	unsigned char *GF_OP_INIT(FI);	 \
+			unsigned char *GF_EOB_INIT(FI); \
+			unsigned char *GF_IP_INIT(FO);  \
+			unsigned char *GF_EIB_INIT(FO);
 
 #define	GF_CH_RESET(F)	(op = eob = GF_QUE_START(F), \
 					    (F)->queueout = (F)->queuein = 0)
@@ -737,23 +740,35 @@
 
 #define	GF_FLUSH(F)	((int)(GF_IP_END(F), (*(F)->f)((F), GF_DATA), \
 			       GF_IP_INIT(F), GF_EIB_INIT(F)))
+#define	GF_FLUSH_GLO(F)	((int)(GF_IP_END_GLO(F), (*(F)->f)((F), GF_DATA), \
+			       GF_IP_INIT_GLO(F), GF_EIB_INIT_GLO(F)))
 
 #define	GF_PUTC(F, C)	((int)(*ip++ = (C), (ip >= eib) ? GF_FLUSH(F) : 1))
+#define	GF_PUTC_GLO(F, C) ((int)(*(*ipp)++ = (C), ((*ipp) >= (*eibp)) ? GF_FLUSH_GLO(F) : 1))
+/*
+ * Introducing the *_GLO macros for use in splitting the big macros out
+ * into functions (wrap_flush, wrap_eol).  The reason we need a
+ * separate macro is because of the vars ip, eib, op, and eob, which are
+ * set up locally in a call to GF_INIT.  To preserve these variables
+ * in the new functions, we now pass pointers to these four vars.  Each
+ * of these new functions expects the presence of pointer vars
+ * ipp, eibp, opp, and eobp.  
+ */
 
 #define	GF_GETC(F, C)	((op < eob) ? (((C) = *op++), 1) : GF_CH_RESET(F))
 
 #define GF_COLOR_PUTC(F, C) {                                            \
                               char *p;                                   \
-                              GF_PUTC((F)->next, TAG_EMBED);             \
-                              GF_PUTC((F)->next, TAG_FGCOLOR);           \
+                              GF_PUTC_GLO((F)->next, TAG_EMBED);         \
+                              GF_PUTC_GLO((F)->next, TAG_FGCOLOR);       \
                               p = color_to_asciirgb((C)->fg);            \
                               for(; *p; p++)                             \
-                                GF_PUTC((F)->next, *p);                  \
-                              GF_PUTC((F)->next, TAG_EMBED);             \
-                              GF_PUTC((F)->next, TAG_BGCOLOR);           \
+                                GF_PUTC_GLO((F)->next, *p);              \
+                              GF_PUTC_GLO((F)->next, TAG_EMBED);         \
+                              GF_PUTC_GLO((F)->next, TAG_BGCOLOR);       \
                               p = color_to_asciirgb((C)->bg);            \
                               for(; *p; p++)                             \
-                                GF_PUTC((F)->next, *p);                  \
+                                GF_PUTC_GLO((F)->next, *p);              \
                             }
 
 /*
@@ -772,7 +787,6 @@
     unsigned long  n;
 } gf_in, gf_out;
 
-
 #define	GF_SO_STACK	struct gf_so_stack
 static GF_SO_STACK {
     STORE_S	*so;
@@ -6747,7 +6761,6 @@
     char	special[256];
 } WRAP_S;
 
-
 #define	WRAP_MARG_L(F)	(((WRAP_S *)(F)->opt)->margin_l)
 #define	WRAP_MARG_R(F)	(((WRAP_S *)(F)->opt)->margin_r)
 #define	WRAP_COL(F)	(((WRAP_S *)(F)->opt)->wrap_col - WRAP_MARG_R(F) - ((((WRAP_S *)(F)->opt)->leave_flowed) ? 1 : 0))
@@ -6780,91 +6793,6 @@
 #define	WRAP_COLOR(F)	(((WRAP_S *)(F)->opt)->color)
 #define	WRAP_COLOR_SET(F)  ((WRAP_COLOR(F)) && (WRAP_COLOR(F)->fg[0]))
 #define	WRAP_SPACES(F)	(((WRAP_S *)(F)->opt)->spaces)
-#define	WRAP_EOL(F, C)	{						\
-			    if((C) && WRAP_LV_FLD(F))			\
-			      GF_PUTC((F)->next, ' ');			\
-			    if(WRAP_BOLD(F)){				\
-				GF_PUTC((F)->next, TAG_EMBED);		\
-				GF_PUTC((F)->next, TAG_BOLDOFF);	\
-			    }						\
-			    if(WRAP_ULINE(F)){				\
-				GF_PUTC((F)->next, TAG_EMBED);		\
-				GF_PUTC((F)->next, TAG_ULINEOFF);	\
-			    }						\
-			    if(WRAP_INVERSE(F) || WRAP_ANCHOR(F)){	\
-				GF_PUTC((F)->next, TAG_EMBED);		\
-				GF_PUTC((F)->next, TAG_INVOFF);		\
-			    }						\
-			    if(WRAP_COLOR_SET(F)){			\
-				char *p;				\
-				GF_PUTC((F)->next, TAG_EMBED);		\
-				GF_PUTC((F)->next, TAG_FGCOLOR);	\
-				p = color_to_asciirgb(ps_global->VAR_NORM_FORE_COLOR);\
-				for(; *p; p++)				\
-				  GF_PUTC((F)->next, *p);		\
-				GF_PUTC((F)->next, TAG_EMBED);		\
-				GF_PUTC((F)->next, TAG_BGCOLOR);	\
-				p = color_to_asciirgb(ps_global->VAR_NORM_BACK_COLOR);\
-				for(; *p; p++)				\
-				  GF_PUTC((F)->next, *p);		\
-			    }						\
-			    GF_PUTC((F)->next, '\015');			\
-			    GF_PUTC((F)->next, '\012');			\
-			    (F)->n = 0L;				\
-			    so_truncate(WRAP_SPACES(F), 0L);		\
-			    WRAP_SPC_LEN(F) = 0;			\
-			}
-
-#define	WRAP_BOL(F,I,Q)	{						\
-			    int n = WRAP_MARG_L(F) + ((I) ? WRAP_INDENT(F) : 0); \
-			    while(n-- > 0){				\
-			      (F)->n++;				        \
-			      GF_PUTC((F)->next, ' ');		        \
-			    }						\
-			    WRAP_ALLWSP(F) = 1;				\
-			    if(Q){					\
-                              WRAP_QUOTE_INSERT(F);                     \
-			    }						\
-			    if(WRAP_BOLD(F)){				\
-				GF_PUTC((F)->next, TAG_EMBED);		\
-				GF_PUTC((F)->next, TAG_BOLDON);		\
-			    }						\
-			    if(WRAP_ULINE(F)){				\
-				GF_PUTC((F)->next, TAG_EMBED);		\
-				GF_PUTC((F)->next, TAG_ULINEON);	\
-			    }						\
-			    if(WRAP_INVERSE(F)){			\
-				GF_PUTC((F)->next, TAG_EMBED);		\
-				GF_PUTC((F)->next, TAG_INVON);		\
-			    }						\
-			    if(WRAP_COLOR_SET(F)){			\
-				char *p;				\
-				if(WRAP_COLOR(F)->fg[0]){		\
-				  GF_PUTC((F)->next, TAG_EMBED);	\
-				  GF_PUTC((F)->next, TAG_FGCOLOR);	\
-				  p = color_to_asciirgb(WRAP_COLOR(F)->fg);\
-				  for(; *p; p++)			\
-				    GF_PUTC((F)->next, *p);		\
-				}					\
-				if(WRAP_COLOR(F)->bg[0]){		\
-				  GF_PUTC((F)->next, TAG_EMBED);	\
-				  GF_PUTC((F)->next, TAG_BGCOLOR);	\
-				  p = color_to_asciirgb(WRAP_COLOR(F)->bg);\
-				  for(; *p; p++)			\
-				    GF_PUTC((F)->next, *p);		\
-				}					\
-			    }						\
-			    if(WRAP_ANCHOR(F)){				\
-				char buf[64]; int i;			\
-				GF_PUTC((F)->next, TAG_EMBED);		\
-				GF_PUTC((F)->next, TAG_HANDLE);		\
-				sprintf(buf, "%d", WRAP_ANCHOR(F));	\
-				GF_PUTC((F)->next, (int) strlen(buf));	\
-				for(i = 0; buf[i]; i++)			\
-				  GF_PUTC((F)->next, buf[i]);		\
-			    }						\
-			}
-
 #define	WRAP_PUTC(F,C,V) {						\
 			    if((F)->linep == WRAP_LASTC(F)){		\
 				size_t offset = (F)->linep - (F)->line;	\
@@ -6891,183 +6819,20 @@
 			    }						\
 			}
 
-#define WRAP_FLUSH_S(F,s,n,V) {						\
-			    for(; n > 0; n--,s++){			\
-				if(*s == TAG_EMBED){			\
-				    if(n-- > 0){			\
-					switch(*++s){			\
-					  case TAG_BOLDON :		\
-					    GF_PUTC((F)->next,TAG_EMBED);\
-					    GF_PUTC((F)->next,TAG_BOLDON);\
-					    WRAP_BOLD(F) = 1;		\
-					    break;			\
-					  case TAG_BOLDOFF :		\
-					    GF_PUTC((F)->next,TAG_EMBED);\
-					    GF_PUTC((F)->next,TAG_BOLDOFF);\
-					    WRAP_BOLD(F) = 0;		\
-					    break;			\
-					  case TAG_ULINEON :		\
-					    GF_PUTC((F)->next,TAG_EMBED);\
-					    GF_PUTC((F)->next,TAG_ULINEON);\
-					    WRAP_ULINE(F) = 1;		\
-					    break;			\
-					  case TAG_ULINEOFF :		\
-					    GF_PUTC((F)->next,TAG_EMBED);\
-					    GF_PUTC((F)->next,TAG_ULINEOFF);\
-					    WRAP_ULINE(F) = 0;		\
-					    break;			\
-					  case TAG_INVOFF :		\
-					    GF_PUTC((F)->next,TAG_EMBED);\
-					    GF_PUTC((F)->next,TAG_INVOFF);\
-					    WRAP_ANCHOR(F) = 0;		\
-					    break;			\
-					  case TAG_HANDLE :		\
-					    GF_PUTC((F)->next,TAG_EMBED);\
-					    if(n-- > 0){		\
-						int i = *++s;		\
-						GF_PUTC((F)->next, TAG_HANDLE); \
-						if(i <= n){		\
-						    n -= i;		\
-						    GF_PUTC((F)->next, i); \
-						    WRAP_ANCHOR(F) = 0;	\
-						    while(i-- > 0){	\
-							WRAP_ANCHOR(F)	\
-							  = (WRAP_ANCHOR(F) \
-							        * 10)	\
-								+ (*++s-'0');\
-							  GF_PUTC((F)->next,*s);\
-						    }			\
-						}			\
-					    }				\
-					    break;			\
-					  case TAG_FGCOLOR :		\
-					    if(pico_usingcolor()	\
-					       && n >= RGBLEN){		\
-					      GF_PUTC((F)->next,TAG_EMBED);\
-					      GF_PUTC((F)->next,TAG_FGCOLOR);\
-					      if(!WRAP_COLOR(F))	\
-						WRAP_COLOR(F)=new_color_pair(NULL,NULL); \
-					      strncpy(WRAP_COLOR(F)->fg, \
-						      s+1, RGBLEN);	\
-					      WRAP_COLOR(F)->fg[RGBLEN]='\0'; \
-					      i = RGBLEN;		\
-					      n -= i;			\
-					      while(i-- > 0)		\
-						GF_PUTC((F)->next,	\
-							(*++s) & 0xff);	\
-					    }				\
-					    break;			\
-					  case TAG_BGCOLOR :		\
-					    if(pico_usingcolor()	\
-					       && n >= RGBLEN){		\
-					      GF_PUTC((F)->next,TAG_EMBED);\
-					      GF_PUTC((F)->next,TAG_BGCOLOR);\
-					      if(!WRAP_COLOR(F))	\
-						WRAP_COLOR(F)=new_color_pair(NULL,NULL); \
-					      strncpy(WRAP_COLOR(F)->bg,\
-						      s+1, RGBLEN);	\
-					      WRAP_COLOR(F)->bg[RGBLEN]='\0'; \
-					      i = RGBLEN;		\
-					      n -= i;			\
-					      while(i-- > 0)		\
-						GF_PUTC((F)->next,	\
-							(*++s) & 0xff);	\
-					    }				\
-					    break;			\
-					  default :			\
-					    break;			\
-					}				\
-				    }					\
-				}					\
-				else if(V){				\
-				    if(*s == TAB)			\
-				      while(++(F)->n & 0x07) ;		\
-				    else				\
-				      (F)->n += (iscntrl((unsigned char) *s) ? 2 : 1); \
-				    if((F)->n <= WRAP_MAX_COL(F)){	\
-				      GF_PUTC((F)->next, (*s) & 0xff);	\
-				    }					\
-				    else{					\
-				      dprint(2, (debugfile, "-- gf_wrap: OVERRUN: %c\n", (*s) & 0xff)); \
-				    }					\
-				    WRAP_ALLWSP(F) = 0;			\
-				}					\
-			    }						\
-			}
-
-#define	WRAP_FLUSH_EMBED(F)	{					\
-			    register char *s;				\
-			    register int   n;				\
-			    s = (char *)so_text(WRAP_SPACES(F));	\
-			    n = so_tell(WRAP_SPACES(F));		\
-			    so_seek(WRAP_SPACES(F), 0L, 0);		\
-			    WRAP_FLUSH_S(F,s,n,0);			\
-			    so_truncate(WRAP_SPACES(F), 0L);		\
-			    WRAP_SPC_LEN(F) = 0;			\
-}
-
-#define	WRAP_FLUSH(F)	{						\
-			    register char *s;				\
-			    register int   n;				\
-			    s = (char *)so_text(WRAP_SPACES(F));	\
-			    n = so_tell(WRAP_SPACES(F));		\
-			    so_seek(WRAP_SPACES(F), 0L, 0);		\
-			    WRAP_FLUSH_S(F,s,n,1);			\
-			    so_truncate(WRAP_SPACES(F), 0L);		\
-			    WRAP_SPC_LEN(F) = 0;			\
-			    s = (F)->line;				\
-			    n = (F)->linep - (F)->line;			\
-			    WRAP_FLUSH_S(F,s,n,1);			\
-			    (F)->f2    = 0;				\
-			    (F)->linep = (F)->line;			\
-			    WRAP_PB_OFF(F) = 0;				\
-			    WRAP_PB_LEN(F) = 0;				\
-			}
-
-#define WRAP_QUOTE_INSERT(F) {                                              \
-    int j;                                                                  \
-    COLOR_PAIR *col = NULL;                                                 \
-    for(j = 0; j < WRAP_FL_QD(F); j++){                                     \
-	(F)->n += 2;                                                        \
-	if(WRAP_USE_CLR(f)){                                                \
-	    if((j % 3) == 0                                                 \
-	       && ps_global->VAR_QUOTE1_FORE_COLOR                          \
-	       && ps_global->VAR_QUOTE1_BACK_COLOR                          \
-	       && (col = new_color_pair(ps_global->VAR_QUOTE1_FORE_COLOR,   \
-					ps_global->VAR_QUOTE1_BACK_COLOR))  \
-	       && pico_is_good_colorpair(col)){                             \
-                GF_COLOR_PUTC((F), col);                                    \
-            }                                                               \
-	    else if((j % 3) == 1                                            \
-		    && ps_global->VAR_QUOTE2_FORE_COLOR                     \
-		    && ps_global->VAR_QUOTE2_BACK_COLOR                     \
-		    && (col = new_color_pair(ps_global->VAR_QUOTE2_FORE_COLOR, \
-					     ps_global->VAR_QUOTE2_BACK_COLOR)) \
-		    && pico_is_good_colorpair(col)){                        \
-	        GF_COLOR_PUTC((F), col);                                    \
-            }                                                               \
-	    else if((j % 3) == 2                                            \
-		    && ps_global->VAR_QUOTE3_FORE_COLOR                     \
-		    && ps_global->VAR_QUOTE3_BACK_COLOR                     \
-		    && (col = new_color_pair(ps_global->VAR_QUOTE3_FORE_COLOR, \
-					     ps_global->VAR_QUOTE3_BACK_COLOR)) \
-		    && pico_is_good_colorpair(col)){                        \
-	        GF_COLOR_PUTC((F), col);                                    \
-            }                                                               \
-	    if(col){                                                        \
-		free_color_pair(&col);                                      \
-		col = NULL;                                                 \
-	    }                                                               \
-	}                                                                   \
-	GF_PUTC((F)->next, '>');                                            \
-	if(!WRAP_LV_FLD(F))                                                 \
-	  GF_PUTC((F)->next, ' ');                                          \
-    }                                                                       \
-    if(j && WRAP_LV_FLD(F)){                                                \
-	GF_PUTC((F)->next, ' ');                                            \
-	(F)->n++;                                                           \
-    }                                                                       \
-}
+int     wrap_flush PROTO((FILTER_S *, unsigned char **, unsigned char **,
+			  unsigned char **, unsigned char **));
+int     wrap_flush_embed PROTO((FILTER_S *, unsigned char **, unsigned char **,
+				unsigned char **, unsigned char **));
+int     wrap_flush_s PROTO((FILTER_S *,char *, int, int, unsigned char **,
+			    unsigned char **,
+			    unsigned char **, unsigned char **));
+int     wrap_eol PROTO((FILTER_S *, int, unsigned char **, unsigned char **,
+			  unsigned char **, unsigned char **));
+int     wrap_bol PROTO((FILTER_S *, int, int, unsigned char **,
+			unsigned char **, unsigned char **, unsigned char **));
+int     wrap_quote_insert PROTO((FILTER_S *, unsigned char **,
+				 unsigned char **, unsigned char **, 
+				 unsigned char **));
 
 /*
  * the no longer simple filter, breaks lines at end of white space nearest
@@ -7157,8 +6922,8 @@
 		    }
 		    else{				/* fixed line */
 			WRAP_HARD(f) = 1;
-			WRAP_FLUSH(f);			/* it's a newline to us */
-			WRAP_EOL(f, 0);
+			wrap_flush(f, &ip, &eib, &op, &eob);
+			wrap_eol(f, 0, &ip, &eib, &op, &eob);
 
 			/*
 			 * When we get to a real end of line, we don't need to
@@ -7175,8 +6940,8 @@
 		    /* else c is first char of new line, fall thru */
 		}
 		else{
-		    WRAP_FLUSH(f);			/* it's a newline to us */
-		    WRAP_EOL(f, 0);
+		    wrap_flush(f, &ip, &eib, &op, &eob);
+		    wrap_eol(f, 0, &ip, &eib, &op, &eob);
 		    WRAP_COLOR_UNSET(f);		/* see note above */
 		    if(c == '\012'){
 			break;
@@ -7204,20 +6969,21 @@
 			    WRAP_FL_QD(f) = 0;
 			    if(WRAP_HARD(f) == 0){
 				WRAP_HARD(f) = 1;
-				WRAP_FLUSH(f);		/* it's a newline to us */
-				WRAP_EOL(f, 0);
+				wrap_flush(f, &ip, &eib, &op, &eob);
+				wrap_eol(f, 0, &ip, &eib, &op, &eob);
 				WRAP_COLOR_UNSET(f);	/* see note above */
 			    }
 			}
 
 			if(WRAP_HARD(f)){
-			    WRAP_BOL(f,0,1);		/* write quoting prefix */
+			    wrap_bol(f, 0, 1, &ip, &eib, &op,
+				     &eob);   /* write quoting prefix */
 			    WRAP_HARD(f) = 0;			    
 			}
 
 			switch (c) {
 			  case '\015' :			/* a blank line? */
-			    WRAP_FLUSH(f);		/* flush what we got */
+			    wrap_flush(f, &ip, &eib, &op, &eob);
 			    state = CCR;		/* go collect it */
 			    break;
 
@@ -7226,11 +6992,9 @@
 			    break;
 
 			  case '-' :			/* possible sig-dash */
-			    if(!WRAP_FL_SIG(f)){	/* only one allowed? */
 				WRAP_FL_SIG(f) = 1;	/* init state */
 				state = FL_SIG;		/* go collect it */
 				break;
-			    }
 
 			  default :
 			    state = DFL;		/* go back to normal */
@@ -7241,11 +7005,12 @@
 		else{
 		    state = DFL;
 		    if(WRAP_COMMA(f) && c == TAB){
-			WRAP_BOL(f,1,0);		/* convert to normal indent */
+			wrap_bol(f, 1, 0, &ip, &eib, &op,
+				 &eob);    /* convert to normal indent */
 			break;
 		    }
 
-		    WRAP_BOL(f,0,0);
+		    wrap_bol(f,0,0, &ip, &eib, &op, &eob);
 		    goto case_dfl;			/* handle c like DFL case */
 		}
 
@@ -7269,20 +7034,20 @@
 			WRAP_FL_QD(f) = WRAP_FL_QC(f);
 			if(WRAP_HARD(f) == 0){		/* add hard newline */ 
 			    WRAP_HARD(f) = 1;		/* hard newline */
-			    WRAP_FLUSH(f);
-			    WRAP_EOL(f, 0);
+			    wrap_flush(f, &ip, &eib, &op, &eob);
+			    wrap_eol(f, 0, &ip, &eib, &op, &eob);
 			    WRAP_COLOR_UNSET(f);	/* see note above */
 			}
 		    }
 
 		    if(WRAP_HARD(f)){
-			WRAP_BOL(f,0,1);
+			wrap_bol(f,0,1, &ip, &eib, &op, &eob);
 			WRAP_HARD(f) = 0;
 		    }
 
 		    switch (c) {
 		      case '\015' :			/* a blank line? */
-			WRAP_FLUSH(f);			/* flush what we got */
+			wrap_flush(f, &ip, &eib, &op, &eob);
 			state = CCR;			/* go collect it */
 			break;
 
@@ -7291,11 +7056,9 @@
 			break;
 
 		      case '-' :			/* sig dash? */
-			if(!WRAP_FL_SIG(f)){		/* only one allowed? */
 			    WRAP_FL_SIG(f) = 1;
 			    state = FL_SIG;
 			    break;
-			}
 
 		      default :				/* something else */
 			state = DFL;
@@ -7308,7 +7071,7 @@
 	      case FL_STF :				/* space stuffed */
 		switch (c) {
 		  case '\015' :				/* a blank line? */
-		    WRAP_FLUSH(f);			/* flush what we got */
+		    wrap_flush(f, &ip, &eib, &op, &eob);
 		    state = CCR;			/* go collect it */
 		    break;
 
@@ -7319,12 +7082,10 @@
 		    continue;
 
 		  case '-' :				/* sig dash? */
-		    if(!WRAP_FL_SIG(f)){
 			WRAP_FL_SIG(f) = 1;
 			WRAP_ALLWSP(f) = 0;
 			state = FL_SIG;
 			break;
-		    }
 
 		  default :				/* something else */
 		    state = DFL;
@@ -7338,9 +7099,12 @@
 		  case 1 :
 		    if(c != '-'){			/* not a sigdash */
 			if((f->n + WRAP_SPC_LEN(f) + 1) > WRAP_COL(f)){
-			    WRAP_FLUSH_EMBED(f);	/* note any embedded */
-			    WRAP_EOL(f, 1);		/* plunk down newline */
-			    WRAP_BOL(f,1,1);		/* write any prefix */
+			    wrap_flush_embed(f, &ip, &eib, &op,
+					     &eob);      /* note any embedded*/
+			    wrap_eol(f, 1, &ip, &eib,
+				     &op, &eob);       /* plunk down newline */
+			    wrap_bol(f, 1, 1, &ip, &eib,
+				     &op, &eob);         /* write any prefix */
 			}
 
 			WRAP_PUTC(f,'-', 1);		/* write what we got */
@@ -7357,9 +7121,12 @@
 		  case 2 :
 		    if(c != ' '){			/* not a sigdash */
 			if((f->n + WRAP_SPC_LEN(f) + 2) > WRAP_COL(f)){
-			    WRAP_FLUSH_EMBED(f);	/* note any embedded */
-			    WRAP_EOL(f, 1);		/* plunk down newline */
-			    WRAP_BOL(f,1,1);		/* write any prefix */
+			    wrap_flush_embed(f, &ip, &eib, &op,
+					     &eob);      /* note any embedded*/
+			    wrap_eol(f, 1, &ip, &eib,
+				     &op, &eob);       /* plunk down newline */
+			    wrap_bol(f, 1, 1, &ip, &eib, &op, 
+				     &eob);   	         /* write any prefix */
 			}
 
 			WRAP_PUTC(f,'-', 1);		/* write what we got */
@@ -7395,7 +7162,7 @@
 
 		      default :				/* that's no sigdash! */
 			WRAP_FL_SIG(f) = 0;
-			WRAP_FLUSH(f);
+			wrap_flush(f, &ip, &eib, &op, &eob);
 			WRAP_SPC_LEN(f) = 1;
 			state = DFL;			/* set normal state */
 			goto case_dfl;			/* and go do "c" */
@@ -7435,9 +7202,8 @@
 				WRAP_PB_LEN(f) = f->f2;
 				break;
 			    }
-			    else{
-				WRAP_FLUSH(f);
-			    }
+			    else
+			      wrap_flush(f, &ip, &eib, &op, &eob);
 			}
 
 			switch(c){			/* remember separator */
@@ -7475,9 +7241,9 @@
 			continue;
 
 		      case '\012' :			/* bare LF in text? */
-			WRAP_FLUSH(f);			/* they must've meant */
-			WRAP_EOL(f, 0);			/* newline... */
-			WRAP_BOL(f,1,1);
+			wrap_flush(f, &ip, &eib, &op, &eob); /* they must've */
+			wrap_eol(f, 0, &ip, &eib, &op, &eob);       /* meant */
+			wrap_bol(f,1,1, &ip, &eib, &op, &eob); /* newline... */
 			continue;
 
 		      case (unsigned char) TAG_EMBED :
@@ -7489,16 +7255,19 @@
 		      case ',' :
 			if(!WRAP_QUOTED(f)){
 			    if(f->n + WRAP_SPC_LEN(f) + f->f2 + 1 > WRAP_COL(f)){
-				if(WRAP_ALLWSP(f)){	/* if anything visible */
-				    WRAP_FLUSH(f);	/* blat buf'd chars */
-				}
-
-				WRAP_EOL(f, 1);		/* plunk down newline */
-				WRAP_BOL(f,1,1);	/* write any prefix */
+				if(WRAP_ALLWSP(f))    /* if anything visible */
+				  wrap_flush(f, &ip, &eib, &op,
+					     &eob);  /* ... blat buf'd chars */
+
+				wrap_eol(f, 1, &ip, &eib, &op,
+					 &eob);  /* plunk down newline */
+				wrap_bol(f, 1, 1, &ip, &eib, &op,
+					 &eob);    /* write any prefix */
 			    }
 
 			    WRAP_PUTC(f, ',', 1);	/* put out comma */
-			    WRAP_FLUSH(f);		/* write buf'd chars */
+			    wrap_flush(f, &ip, &eib, &op,
+				       &eob);       /* write buf'd chars */
 			    continue;
 			}
 
@@ -7541,7 +7310,8 @@
 
 			    f->linep = p1;
 
-			    WRAP_FLUSH(f);		/* flush shortened buf */
+			    wrap_flush(f, &ip, &eib, &op,
+				       &eob); /* flush shortened buf */
 			    
 			    while(p1 < p2){
 				char c2 = *p1++;
@@ -7553,18 +7323,21 @@
 				vis--;
 			    }
 			}
-			else{
-			    WRAP_FLUSH(f);		/* flush what's buf'd */
-			}
+			else
+			  wrap_flush(f, &ip, &eib, &op, &eob);
 
-			WRAP_EOL(f, 1);			/* plunk down newline */
-			WRAP_BOL(f,1,1);		/* write any prefix */
+			wrap_eol(f, 1, &ip, &eib, &op,
+				 &eob);     /* plunk down newline */
+			wrap_bol(f,1,1, &ip, &eib, &op,
+				 &eob);      /* write any prefix */
 		    }
 		}
 		else if((f->n + WRAP_SPC_LEN(f) + f->f2 + x) > WRAP_COL(f)){
-		    WRAP_FLUSH_EMBED(f);		/* note any embedded */
-		    WRAP_EOL(f, 1);			/* plunk down newline */
-		    WRAP_BOL(f,1,1);			/* write any prefix */
+		    wrap_flush_embed(f, &ip, &eib, &op, &eob);
+		    wrap_eol(f, 1, &ip, &eib, &op,
+			     &eob);	    /* plunk down newline */
+		    wrap_bol(f,1,1, &ip, &eib, &op,
+			     &eob);	      /* write any prefix */
 		}
 
 		WRAP_PUTC(f, c, 1);
@@ -7617,7 +7390,7 @@
 	GF_END(f, f->next);
     }
     else if(flg == GF_EOD){
-	WRAP_FLUSH(f);
+	wrap_flush(f, &ip, &eib, &op, &eob);
 	if(WRAP_COLOR(f))
 	  free_color_pair(&WRAP_COLOR(f));
 
@@ -7656,6 +7429,313 @@
     }
 }
 
+int
+wrap_flush(f, ipp, eibp, opp, eobp)
+    FILTER_S *f;
+    unsigned char **ipp;
+    unsigned char **eibp;
+    unsigned char **opp;
+    unsigned char **eobp;
+{
+    register char *s;
+    register int   n;
+    s = (char *)so_text(WRAP_SPACES(f));
+    n = so_tell(WRAP_SPACES(f));
+    so_seek(WRAP_SPACES(f), 0L, 0);
+    wrap_flush_s(f, s, n, 1, ipp, eibp, opp, eobp);
+    so_truncate(WRAP_SPACES(f), 0L);
+    WRAP_SPC_LEN(f) = 0;
+    s = f->line;
+    n = f->linep - f->line;
+    wrap_flush_s(f, s, n, 1, ipp, eibp, opp, eobp);
+    f->f2    = 0;
+    f->linep = f->line;
+    WRAP_PB_OFF(f) = 0;
+    WRAP_PB_LEN(f) = 0;
+}
+
+int
+wrap_flush_embed(f, ipp, eibp, opp, eobp)
+    FILTER_S    *f;
+    unsigned char **ipp;
+    unsigned char **eibp;
+    unsigned char **opp;
+    unsigned char **eobp;
+{
+  register char *s;
+  register int   n;
+  s = (char *)so_text(WRAP_SPACES(f));
+  n = so_tell(WRAP_SPACES(f));
+  so_seek(WRAP_SPACES(f), 0L, 0);
+  wrap_flush_s(f, s, n, 0, ipp, eibp, opp, eobp);
+  so_truncate(WRAP_SPACES(f), 0L);
+  WRAP_SPC_LEN(f) = 0;
+}
+
+int
+wrap_flush_s(f, s, n, v, ipp, eibp, opp, eobp)
+    FILTER_S    *f;
+    char        *s;
+    int          n;
+    int          v;
+    unsigned char **ipp;
+    unsigned char **eibp;
+    unsigned char **opp;
+    unsigned char **eobp;
+{
+    for(; n > 0; n--,s++){
+	if(*s == TAG_EMBED){
+	    if(n-- > 0){
+		switch(*++s){
+		  case TAG_BOLDON :
+		    GF_PUTC_GLO(f->next,TAG_EMBED);
+		    GF_PUTC_GLO(f->next,TAG_BOLDON);
+		    WRAP_BOLD(f) = 1;
+		    break;
+		  case TAG_BOLDOFF :
+		    GF_PUTC_GLO(f->next,TAG_EMBED);
+		    GF_PUTC_GLO(f->next,TAG_BOLDOFF);
+		    WRAP_BOLD(f) = 0;
+		    break;
+		  case TAG_ULINEON :
+		    GF_PUTC_GLO(f->next,TAG_EMBED);
+		    GF_PUTC_GLO(f->next,TAG_ULINEON);
+		    WRAP_ULINE(f) = 1;
+		    break;
+		  case TAG_ULINEOFF :
+		    GF_PUTC_GLO(f->next,TAG_EMBED);
+		    GF_PUTC_GLO(f->next,TAG_ULINEOFF);
+		    WRAP_ULINE(f) = 0;
+		    break;
+		  case TAG_INVOFF :
+		    GF_PUTC_GLO(f->next,TAG_EMBED);
+		    GF_PUTC_GLO(f->next,TAG_INVOFF);
+		    WRAP_ANCHOR(f) = 0;
+		    break;
+		  case TAG_HANDLE :
+		    GF_PUTC_GLO(f->next,TAG_EMBED);
+		    if(n-- > 0){
+			int i = *++s;
+			GF_PUTC_GLO(f->next, TAG_HANDLE);
+			if(i <= n){
+			    n -= i;
+			    GF_PUTC_GLO(f->next, i);
+			    WRAP_ANCHOR(f) = 0;
+			    while(i-- > 0){
+				WRAP_ANCHOR(f) = (WRAP_ANCHOR(f) * 10) + (*++s-'0');
+				GF_PUTC_GLO(f->next,*s);
+			    }
+			}
+		    }
+		    break;
+		  case TAG_FGCOLOR :
+		    if(pico_usingcolor() && n >= RGBLEN){
+			int i;
+			GF_PUTC_GLO(f->next,TAG_EMBED);
+			GF_PUTC_GLO(f->next,TAG_FGCOLOR);
+			if(!WRAP_COLOR(f))
+			  WRAP_COLOR(f)=new_color_pair(NULL,NULL);
+			strncpy(WRAP_COLOR(f)->fg, s+1, RGBLEN);
+			WRAP_COLOR(f)->fg[RGBLEN]='\0';
+			i = RGBLEN;
+			n -= i;
+			while(i-- > 0)
+			  GF_PUTC_GLO(f->next,
+				  (*++s) & 0xff);
+		    }
+		    break;
+		  case TAG_BGCOLOR :
+		    if(pico_usingcolor() && n >= RGBLEN){
+			int i;
+			GF_PUTC_GLO(f->next,TAG_EMBED);
+			GF_PUTC_GLO(f->next,TAG_BGCOLOR);
+			if(!WRAP_COLOR(f))
+			  WRAP_COLOR(f)=new_color_pair(NULL,NULL);
+			strncpy(WRAP_COLOR(f)->bg, s+1, RGBLEN);
+			WRAP_COLOR(f)->bg[RGBLEN]='\0';
+			i = RGBLEN;
+			n -= i;
+			while(i-- > 0)
+			  GF_PUTC_GLO(f->next,
+				  (*++s) & 0xff);
+		    }
+		    break;
+		  default :
+		    break;
+		}
+	    }
+	}
+	else if(v){
+	    if(*s == TAB)
+	      while(++f->n & 0x07) ;
+	    else
+	      f->n += (iscntrl((unsigned char) *s) ? 2 : 1);
+	    if(f->n <= WRAP_MAX_COL(f)){
+		GF_PUTC_GLO(f->next, (*s) & 0xff);
+	    }
+	    else{
+		dprint(2, (debugfile, "-- gf_wrap: OVERRUN: %c\n", (*s) & 0xff));
+	    }
+	    WRAP_ALLWSP(f) = 0;
+	}
+    }
+}
+
+int
+wrap_eol(f, c, ipp, eibp, opp, eobp)
+    FILTER_S *f;
+    int c;
+    unsigned char **ipp;
+    unsigned char **eibp;
+    unsigned char **opp;
+    unsigned char **eobp;
+{
+    if(c && WRAP_LV_FLD(f))
+      GF_PUTC_GLO(f->next, ' ');
+    if(WRAP_BOLD(f)){
+	GF_PUTC_GLO(f->next, TAG_EMBED);
+	GF_PUTC_GLO(f->next, TAG_BOLDOFF);
+    }
+    if(WRAP_ULINE(f)){
+	GF_PUTC_GLO(f->next, TAG_EMBED);
+	GF_PUTC_GLO(f->next, TAG_ULINEOFF);
+    }
+    if(WRAP_INVERSE(f) || WRAP_ANCHOR(f)){
+	GF_PUTC_GLO(f->next, TAG_EMBED);
+	GF_PUTC_GLO(f->next, TAG_INVOFF);
+    }
+    if(WRAP_COLOR_SET(f)){
+	char *p;
+	GF_PUTC_GLO(f->next, TAG_EMBED);
+	GF_PUTC_GLO(f->next, TAG_FGCOLOR);
+	p = color_to_asciirgb(ps_global->VAR_NORM_FORE_COLOR);
+	for(; *p; p++)
+	  GF_PUTC_GLO(f->next, *p);
+	GF_PUTC_GLO(f->next, TAG_EMBED);
+	GF_PUTC_GLO(f->next, TAG_BGCOLOR);
+	p = color_to_asciirgb(ps_global->VAR_NORM_BACK_COLOR);
+	for(; *p; p++)
+	  GF_PUTC_GLO(f->next, *p);
+    }
+    GF_PUTC_GLO(f->next, '\015');
+    GF_PUTC_GLO(f->next, '\012');
+    f->n = 0L;
+    so_truncate(WRAP_SPACES(f), 0L);
+    WRAP_SPC_LEN(f) = 0;
+}
+
+int
+wrap_bol(f,ivar,q, ipp, eibp, opp, eobp)
+    FILTER_S *f;
+    int ivar;
+    int q;
+    unsigned char **ipp;
+    unsigned char **eibp;
+    unsigned char **opp;
+    unsigned char **eobp;
+{
+    int n = WRAP_MARG_L(f) + (ivar ? WRAP_INDENT(f) : 0);
+    while(n-- > 0){
+	f->n++;
+	GF_PUTC_GLO(f->next, ' ');
+    }
+    WRAP_ALLWSP(f) = 1;
+    if(q)
+      wrap_quote_insert(f, ipp, eibp, opp, eobp);
+
+    if(WRAP_BOLD(f)){
+	GF_PUTC_GLO(f->next, TAG_EMBED);
+	GF_PUTC_GLO(f->next, TAG_BOLDON);
+    }
+    if(WRAP_ULINE(f)){
+	GF_PUTC_GLO(f->next, TAG_EMBED);
+	GF_PUTC_GLO(f->next, TAG_ULINEON);
+    }
+    if(WRAP_INVERSE(f)){
+	GF_PUTC_GLO(f->next, TAG_EMBED);
+	GF_PUTC_GLO(f->next, TAG_INVON);
+    }
+    if(WRAP_COLOR_SET(f)){
+	char *p;
+	if(WRAP_COLOR(f)->fg[0]){
+	    GF_PUTC_GLO(f->next, TAG_EMBED);
+	    GF_PUTC_GLO(f->next, TAG_FGCOLOR);
+	    p = color_to_asciirgb(WRAP_COLOR(f)->fg);
+	    for(; *p; p++)
+	      GF_PUTC_GLO(f->next, *p);
+	}
+	if(WRAP_COLOR(f)->bg[0]){
+	    GF_PUTC_GLO(f->next, TAG_EMBED);
+	    GF_PUTC_GLO(f->next, TAG_BGCOLOR);
+	    p = color_to_asciirgb(WRAP_COLOR(f)->bg);
+	    for(; *p; p++)
+	      GF_PUTC_GLO(f->next, *p);
+	}
+    }
+    if(WRAP_ANCHOR(f)){
+	char buf[64]; int i;
+	GF_PUTC_GLO(f->next, TAG_EMBED);
+	GF_PUTC_GLO(f->next, TAG_HANDLE);
+	sprintf(buf, "%d", WRAP_ANCHOR(f));
+	GF_PUTC_GLO(f->next, (int) strlen(buf));
+	for(i = 0; buf[i]; i++)
+	  GF_PUTC_GLO(f->next, buf[i]);
+    }
+}
+
+int
+wrap_quote_insert(f, ipp, eibp, opp, eobp)
+    FILTER_S *f;
+    unsigned char **ipp;
+    unsigned char **eibp;
+    unsigned char **opp;
+    unsigned char **eobp;
+{
+    int j;
+    COLOR_PAIR *col = NULL;
+    for(j = 0; j < WRAP_FL_QD(f); j++){
+	f->n += (WRAP_LV_FLD(f) ? 1 : 2);
+	if(WRAP_USE_CLR(f)){
+	    if((j % 3) == 0
+	       && ps_global->VAR_QUOTE1_FORE_COLOR
+	       && ps_global->VAR_QUOTE1_BACK_COLOR
+	       && (col = new_color_pair(ps_global->VAR_QUOTE1_FORE_COLOR,
+					ps_global->VAR_QUOTE1_BACK_COLOR))
+	       && pico_is_good_colorpair(col)){
+                GF_COLOR_PUTC(f, col);
+            }
+	    else if((j % 3) == 1
+		    && ps_global->VAR_QUOTE2_FORE_COLOR
+		    && ps_global->VAR_QUOTE2_BACK_COLOR
+		    && (col = new_color_pair(ps_global->VAR_QUOTE2_FORE_COLOR,
+					     ps_global->VAR_QUOTE2_BACK_COLOR))
+		    && pico_is_good_colorpair(col)){
+	        GF_COLOR_PUTC(f, col);
+            }
+	    else if((j % 3) == 2
+		    && ps_global->VAR_QUOTE3_FORE_COLOR
+		    && ps_global->VAR_QUOTE3_BACK_COLOR
+		    && (col = new_color_pair(ps_global->VAR_QUOTE3_FORE_COLOR,
+					     ps_global->VAR_QUOTE3_BACK_COLOR))
+		    && pico_is_good_colorpair(col)){
+	        GF_COLOR_PUTC(f, col);
+            }
+	    if(col){
+		free_color_pair(&col);
+		col = NULL;
+	    }
+	}
+	GF_PUTC_GLO(f->next, '>');
+	if(!WRAP_LV_FLD(f))
+	  GF_PUTC_GLO(f->next, ' ');
+    }
+    if(j && WRAP_LV_FLD(f)){
+	GF_PUTC_GLO(f->next, ' ');
+	f->n++;
+    }
+}
+
+
 /*
  * function called from the outside to set
  * wrap filter's width option