76 short count, new_kill;
77 char *ptr, *text_start, delimiter, *ptr1, *ptr2, *ptr3;
78 char *delimLoc, *editNext, *charList;
79 static char kill[4096], buffer[4096];
81 int global, conditional, conditionalReturn, here, i;
84 int stackLevel, stackDepth, doPush, parenCount, invert;
88 printf(
"text = %s\nedit = %s\n", text, edit0);
92 if (!(editSeq = malloc(
sizeof(*editSeq) * (stackDepth = 10))))
94 cp_str(&editSeq[0].editText, edit0);
96 for (i = 0; i < stackDepth; i++)
97 editSeq[i].pending = 0;
98 editSeq[0].editPtr = NULL;
102 while (stackLevel >= 0) {
104 printf(
"stackLevel = %ld\n", stackLevel);
106 while (editSeq[stackLevel].pending || editSeq[stackLevel].count--) {
107 if (!editSeq[stackLevel].pending)
108 editSeq[stackLevel].editPtr = editSeq[stackLevel].editText;
109 editSeq[stackLevel].pending = 0;
110 if (!editSeq[stackLevel].editPtr)
113 printf(
"Count = %ld\n", editSeq[stackLevel].count + 1);
114 printf(
"EditPtr = %s\n", editSeq[stackLevel].editPtr);
116 edit = editSeq[stackLevel].editPtr;
117 while (*(editSeq[stackLevel].editPtr = edit)) {
119 while (isdigit(*edit))
120 count = count * 10 + (*edit++ -
'0');
126 printf(
"count = %ld command = %c\n", count, *edit);
137 while (parenCount && *++edit) {
140 else if (*edit ==
')')
144 editSeq[stackLevel].pending = 1;
145 editSeq[stackLevel].editPtr = edit + 1;
147 editSeq[stackLevel].pending = 1;
148 editSeq[stackLevel].editPtr = NULL;
150 if (stackLevel >= stackDepth &&
151 !(editSeq = realloc(editSeq,
sizeof(*editSeq) * (stackDepth += 10)))) {
152 fprintf(stderr,
"memory allocation failure (edit_string)");
156 editSeq[stackLevel].count = count;
159 cp_str(&editSeq[stackLevel].editText, ptr);
161 editSeq[stackLevel].editPtr = NULL;
164 printf(
"stack pushing: %ld*>%s<\n", count,
165 editSeq[stackLevel].editText);
174 if (count > (
long)strlen(text))
175 count = strlen(text);
181 if (count > (
long)strlen(text))
182 count = strlen(text);
188 if ((text -= count) < text_start)
194 while (count-- && (ptr = strpbrk(text,
" \t_-"))) {
195 while (IS_WORD_END(*ptr))
205 while (count-- && (ptr = strpbrk(text,
" \t_-"))) {
206 while (IS_WORD_END(*ptr))
211 text += strlen(text);
217 while (IS_WORD_END(*text) && text > text_start)
219 while (!IS_WORD_END(*text) && text > text_start)
222 if (IS_WORD_END(*text))
232 text += strlen(text);
238 if ((ptr = strchr(++edit, delimiter))) {
242 ptr = edit + strlen(edit) - 1;
245 printf(
"insert string = >%s<\n", edit);
249 text += strlen(edit);
262 if (delimiter ==
'-') {
269 if ((editNext = strchr(++edit, delimiter))) {
273 editNext = edit + strlen(edit) - 1;
276 if (*charList ==
'[' && *(charList + strlen(charList) - 1) ==
']') {
283 printf(
"x-kill string = >%s< (was >%s<)\n", charList, edit);
284 printf(
"text position: >%s<\n", text);
291 if ((ptr = strpbrk(text, charList))) {
292 strncat(kill, text, ptr - text);
299 int i, length, found;
301 length = strlen(charList);
303 while (found && *ptr) {
305 for (i = 0; i < length; i++) {
306 if (*ptr == *(charList + i)) {
314 strncat(kill, text, ptr - text);
320 *delimLoc = delimiter;
325 if (!(delimiter = *++edit))
328 if (delimiter ==
'?') {
330 if (!(delimiter = *++edit))
334 if ((ptr = strchr(++edit, delimiter))) {
338 ptr = edit + strlen(edit) - 1;
341 printf(
"search string = >%s<\n", edit);
343 conditionalReturn = 0;
348 ptr2 = strstr(text, edit);
351 conditionalReturn = conditional;
354 if (strlen(ptr2) <= j) {
356 conditionalReturn = conditional;
359 text = ptr2 + strlen(edit);
361 ptr2 = strstr(text, edit);
362 if ((ptr2 == NULL) || (strlen(ptr2) <= j)) {
365 text = ptr2 + strlen(edit);
368 text -= strlen(edit);
374 if (conditionalReturn)
379 if (!(delimiter = *++edit))
382 if (delimiter ==
'?') {
384 if (!(delimiter = *++edit))
388 if ((ptr = strchr(++edit, delimiter))) {
392 ptr = edit + strlen(edit) - 1;
395 printf(
"search string = >%s<\n", edit);
397 conditionalReturn = 0;
402 ptr2 = strstr(text, edit);
405 conditionalReturn = conditional;
408 if (strlen(ptr2) <= j) {
410 conditionalReturn = conditional;
413 text = ptr2 + strlen(edit);
415 ptr2 = strstr(text, edit);
416 if ((ptr2 == NULL) || (strlen(ptr2) <= j)) {
419 text = ptr2 + strlen(edit);
421 text -= strlen(edit);
427 if (conditionalReturn)
432 if (!(delimiter = *++edit))
435 if (delimiter ==
'?') {
437 if (!(delimiter = *++edit))
441 if ((ptr = strchr(++edit, delimiter))) {
445 ptr = edit + strlen(edit) - 1;
448 printf(
"search string = >%s<\n", edit);
450 conditionalReturn = 0;
452 if ((ptr2 = strstr(text, edit)))
453 text = ptr2 + strlen(edit);
455 conditionalReturn = conditional;
463 if (conditionalReturn)
468 if (!(delimiter = *++edit))
471 if (delimiter ==
'?') {
473 if (!(delimiter = *++edit))
477 if ((ptr = strchr(++edit, delimiter))) {
481 ptr = edit + strlen(edit) - 1;
484 printf(
"search string = >%s<\n", edit);
486 conditionalReturn = 0;
488 if ((ptr2 = strstr(text, edit))) {
490 text = ptr2 + strlen(edit);
494 conditionalReturn = conditional;
502 if (conditionalReturn)
509 strncat(kill, text, count);
513 printf(
"kill buffer: >%s<\n", kill);
520 while (count-- && (ptr = strpbrk(text,
" \t_-"))) {
521 while (IS_WORD_END(*ptr))
523 strncat(kill, text, ptr - text);
530 printf(
"kill buffer: >%s<\n", kill);
535 if (!(delimiter = *++edit))
541 if ((ptr = strchr(text, delimiter))) {
542 if (*(edit - 1) ==
'Z')
544 strncat(kill, text, ptr - text);
549 printf(
"kill buffer: >%s<\n", kill);
551 if (*(edit - 1) ==
'z')
558 printf(
"yank string = >%s<\n", kill);
562 text += strlen(kill);
568 if (*(edit + 1) ==
'g') {
572 if (*(edit + 1) ==
'h') {
576 if (!(delimiter = *++edit))
579 printf(
"delimiter = %c\n", delimiter);
582 if (!(repl = strchr(orig + 1, delimiter)))
585 if (!(ptr = strchr(repl, delimiter)))
589 printf(
"orig: >%s< repl: >%s<\n", orig, repl);
604 *(repl - 1) = delimiter;
615 free(editSeq[stackLevel].editText);
616 editSeq[stackLevel].editPtr = NULL;