static void process_delta(Node *node, enum stringwork func) { long editline = 0, linecnt = 0, adjust = 0; int editor_command; struct diffcmd dc; uchar *ptr; Glog = node->p->log; in_buffer_init((uchar *)node->p->text, 1); Gversion = node->v; cvs_number_string(&Gversion->number, Gversion_number); switch (func) { case ENTER: while( (ptr=in_get_line()) ) insertline(editline++, ptr); case EDIT: dc.dafter = dc.adprev = 0; while ((editor_command = parse_next_delta_command(&dc)) >= 0) { if (editor_command) { editline = dc.line1 + adjust; linecnt = dc.nlines; while(linecnt--) insertline(editline++, in_get_line()); adjust += dc.nlines; } else { deletelines(dc.line1 - 1 + adjust, dc.nlines); adjust -= dc.nlines; } } break; } }
/* * Finish editing. */ static void termedit(void) { if (bufbase) free(bufbase); bufbase = NULL; bufp = NULL; bufsize = 0; bufused = 0; if (filename) free(filename); filename = NULL; searchstring[0] = '\0'; if (lastnum) deletelines(1, lastnum); lastnum = 0; curnum = 0; curline = NULL; }
calculate_id_lines () { register int i, j; int *match, *insdel; int prevmatch = 0; int ded_reckon = 0; match = (int *) alloca (ScreenLength * sizeof (int)); insdel = (int *) alloca (ScreenLength * sizeof (int)); /* Here should check for last few lines matching exactly, or all except last two. */ for (i = 1; i <= ScreenLength; i++) { match[i] = ++ded_reckon; if (PhysScreen[i]->draw_cost < 10) continue; for (j = matchmin; j <= ScreenLength; j++) { if (PhysScreen[i] == DesiredScreen[j] || (PhysScreen[i]->hash == DsiredScreen[j]->hash)) { match[i] = j; ded_reckon = j; matchmin = j + 1; break; } } } /* Now match[i] is the line (origin-1) that line i should move to. */ deficit = 0; ded_reckon = 1; for (i = 1; i <= window_size; i++) { insdel = match[i] - ded_reckon; ded_reckon = match[i] + 1; if (insdel < 0) { topos (i - deficit + insdel, 1); deletelines (- insdel); deficit -= insdel; } } ded_reckon = 1; for (i = 1; i <= window_size; i++) { insdel = match[i] - ded_reckon; ded_reckon = match[i] + 1; if (insdel > 0) { topos (i - deficit, 1); deletelines (insdel); deficit -= insdel; } } if (deficit != 0) abort (); for (i = 1; i < window_size; i++) PhysScreen[i] = 0; for (i = 1; i < window_size; i++) PhysScreen[match[i]] = OPhysScreen[i]; }
/* * Read commands until we are told to stop. */ static void docommands(void) { char *cp; int len; NUM num1; NUM num2; BOOL have1; BOOL have2; while (TRUE) { intflag = FALSE; printf(": "); fflush(stdout); if (fgets(buf, sizeof(buf), stdin) == NULL) return; len = strlen(buf); if (len == 0) return; cp = &buf[len - 1]; if (*cp != '\n') { fprintf(stderr, "Command line too long\n"); do { len = fgetc(stdin); } while ((len != EOF) && (len != '\n')); continue; } while ((cp > buf) && isblank(cp[-1])) cp--; *cp = '\0'; cp = buf; while (isblank(*cp)) *cp++; have1 = FALSE; have2 = FALSE; if ((curnum == 0) && (lastnum > 0)) { curnum = 1; curline = lines.next; } if (!getnum(&cp, &have1, &num1)) continue; while (isblank(*cp)) cp++; if (*cp == ',') { cp++; if (!getnum(&cp, &have2, &num2)) continue; if (!have1) num1 = 1; if (!have2) num2 = lastnum; have1 = TRUE; have2 = TRUE; } if (!have1) num1 = curnum; if (!have2) num2 = num1; switch (*cp++) { case 'a': addlines(num1 + 1); break; case 'c': deletelines(num1, num2); addlines(num1); break; case 'd': deletelines(num1, num2); break; case 'f': if (*cp && !isblank(*cp)) { fprintf(stderr, "Bad file command\n"); break; } while (isblank(*cp)) cp++; if (*cp == '\0') { if (filename) printf("\"%s\"\n", filename); else printf("No filename\n"); break; } cp = strdup(cp); if (cp == NULL) { fprintf(stderr, "No memory for filename\n"); break; } if (filename) free(filename); filename = cp; break; case 'i': addlines(num1); break; case 'k': while (isblank(*cp)) cp++; if ((*cp < 'a') || (*cp > 'a') || cp[1]) { fprintf(stderr, "Bad mark name\n"); break; } marks[*cp - 'a'] = num2; break; case 'l': printlines(num1, num2, TRUE); break; case 'p': printlines(num1, num2, FALSE); break; case 'q': while (isblank(*cp)) cp++; if (have1 || *cp) { fprintf(stderr, "Bad quit command\n"); break; } if (!dirty) return; printf("Really quit? "); fflush(stdout); buf[0] = '\0'; fgets(buf, sizeof(buf), stdin); cp = buf; while (isblank(*cp)) cp++; if ((*cp == 'y') || (*cp == 'Y')) return; break; case 'r': if (*cp && !isblank(*cp)) { fprintf(stderr, "Bad read command\n"); break; } while (isblank(*cp)) cp++; if (*cp == '\0') { fprintf(stderr, "No filename\n"); break; } if (!have1) num1 = lastnum; if (readlines(cp, num1 + 1)) break; if (filename == NULL) filename = strdup(cp); break; case 's': subcommand(cp, num1, num2); break; case 'w': if (*cp && !isblank(*cp)) { fprintf(stderr, "Bad write command\n"); break; } while (isblank(*cp)) cp++; if (!have1) { num1 = 1; num2 = lastnum; } if (*cp == '\0') cp = filename; if (cp == NULL) { fprintf(stderr, "No file name specified\n"); break; } writelines(cp, num1, num2); break; case 'z': switch (*cp) { case '-': printlines(curnum - 21, curnum, FALSE); break; case '.': printlines(curnum - 11, curnum + 10, FALSE); break; default: printlines(curnum, curnum + 21, FALSE); break; } break; case '.': if (have1) { fprintf(stderr, "No arguments allowed\n"); break; } printlines(curnum, curnum, FALSE); break; case '-': if (setcurnum(curnum - 1)) printlines(curnum, curnum, FALSE); break; case '=': printf("%d\n", num1); break; case '\0': if (have1) { printlines(num2, num2, FALSE); break; } if (setcurnum(curnum + 1)) printlines(curnum, curnum, FALSE); break; default: fprintf(stderr, "Unimplemented command\n"); break; } } }