+ {
+ add_len = CHAR_STRING (c, str);
+ add_stuff = str;
+ }
+
+ /* If we want to copy part of a previous match,
+ set up ADD_STUFF and ADD_LEN to point to it. */
+ if (idx >= 0)
+ {
+ int begbyte = CHAR_TO_BYTE (search_regs.start[idx]);
+ add_len = CHAR_TO_BYTE (search_regs.end[idx]) - begbyte;
+ if (search_regs.start[idx] < GPT && GPT < search_regs.end[idx])
+ move_gap (search_regs.start[idx]);
+ add_stuff = BYTE_POS_ADDR (begbyte);
+ }
+
+ /* Now the stuff we want to add to SUBSTED
+ is invariably ADD_LEN bytes starting at ADD_STUFF. */
+
+ /* Make sure SUBSTED is big enough. */
+ if (substed_len + add_len >= substed_alloc_size)
+ {
+ substed_alloc_size = substed_len + add_len + 500;
+ substed = (unsigned char *) xrealloc (substed,
+ substed_alloc_size + 1);
+ }
+
+ /* Now add to the end of SUBSTED. */
+ if (add_stuff)
+ {
+ bcopy (add_stuff, substed + substed_len, add_len);
+ substed_len += add_len;
+ }