/* * Save the current contents of linebuf, if it has changed. */ void vsave(void) { char temp[LBSIZE]; CP(temp, linebuf); if (FIXUNDO && vundkind == VCHNG || vundkind == VCAPU) { /* * If the undo state is saved in the temporary buffer * vutmp, then we sync this into the temp file so that * we will be able to undo even after we have moved off * the line. It would be possible to associate a line * with vutmp but we assume that vutmp is only associated * with line dot (e.g. in case ':') above, so beware. */ prepapp(); CP(linebuf, vutmp); putmark(dot); vremote(1, yank, 0); vundkind = VMCHNG; notecnt = 0; undkind = UNDCHANGE; } /* * Get the line out of the temp file and do nothing if it hasn't * changed. This may seem like a loss, but the line will * almost always be in a read buffer so this may well avoid disk i/o. */ getDOT(); if (strcmp(linebuf, temp) == 0) return; strcLIN(temp); putmark(dot); }
int substitute(int c) { register line *addr; register int n; int gsubf; gsubf = compsub(c); if (!inglobal) save12(), undkind = UNDCHANGE; stotal = 0; slines = 0; for (addr = addr1; addr <= addr2; addr++) { scount = 0; if (dosubcon(0, addr) == 0) continue; if (gsubf) while (*loc2) if (dosubcon(1, addr) == 0) break; if (scount) { stotal += scount; slines++; putmark(addr); n = append(getsub, addr); addr += n; addr2 += n; } } if (stotal == 0 && !inglobal && !xflag) error("Fail|Substitute pattern match failed"); snote(stotal, slines); return (stotal); }
void shift(int c, int cnt) { register int *addr; char *cp = genbuf; char *dp; register int i; if (!inglobal) save12(), undkind = UNDCHANGE; cnt *= value(SHIFTWIDTH); for (addr = addr1; addr <= addr2; addr++) { ex_getline(*addr); i = whitecnt(linebuf); switch (c) { case '>': if (linebuf[0] == 0) continue; cp = genindent(i + cnt); break; case '<': if (i == 0) continue; i -= cnt; cp = i > 0 ? genindent(i) : genbuf; break; } dot = addr; if (cp + strlen(dp = vpastwh(linebuf)) >= &genbuf[LBSIZE - 2]) error("Line too long|Result line after shift would be too long"); strcpy(cp, dp); strcLIN(genbuf); putmark(addr); } }
int reconnect(void) { int sts; int ctx; time_t now; __pmContext *ctxp; if ((ctx = pmWhichContext()) >= 0) ctxp = __pmHandleToPtr(ctx); if (ctx < 0 || ctxp == NULL) { fprintf(stderr, "%s: reconnect botch: cannot get context: %s\n", pmProgname, pmErrStr(ctx)); exit(1); } sts = pmReconnectContext(ctx); if (sts >= 0) { pmcdfd = ctxp->c_pmcd->pc_fd; __pmFD_SET(pmcdfd, &fds); numfds = maxfd() + 1; } PM_UNLOCK(ctxp->c_lock); if (sts < 0) return sts; time(&now); fprintf(stderr, "%s: re-established connection to PMCD on \"%s\" at %s", pmProgname, pmcd_host, ctime(&now)); /* * Metrics may have changed while PMCD was unreachable, so we * need to recheck each metric to make sure that its PMID and * semantics have not changed. We cannot recover if there is * an incompatible change - must defer to controlling scripts * or processes (a new-named archive will have to be created, * from a new pmlogger process, and pmlogrewrite/pmlogextract * will need to become involved if they need to be merged). */ validate_metrics(); /* * All metrics have been validated, however, this state change * represents a potential gap in the stream of metrics. So we * must store a <mark> record at this point. */ if ((sts = putmark()) < 0) { fprintf(stderr, "putmark: %s\n", pmErrStr(sts)); exit(1); } return 0; }
/* * Append after line a lines returned by function f. * Be careful about intermediate states to avoid scramble * if an interrupt comes in. */ int append(int (*f)(void), line *a) { register line *a1, *a2, *rdot; int nline; nline = 0; dot = a; if(FIXUNDO && !inopen && f!=getsub) { undap1 = undap2 = dot + 1; undkind = UNDCHANGE; } while ((*f)() == 0) { if (truedol >= endcore) { if (morelines() < 0) { if (FIXUNDO && f == getsub) { undap1 = addr1; undap2 = addr2 + 1; } error(catgets(catd, 1, 39, "Out of memory@- too many lines in file")); } } nline++; a1 = truedol + 1; a2 = a1 + 1; dot++; undap2++; dol++; unddol++; truedol++; for (rdot = dot; a1 > rdot;) *--a2 = *--a1; *rdot = 0; putmark(rdot); if (f == gettty) { dirtcnt++; TSYNC(); } } return (nline); }
/* **************************************************************** * Rotina de Tratamento de Erros * **************************************************************** */ void tic_error (ERRTYPE tipo, MARKTYPE marca, const char *mens, const char *var) { /* * Coloca a Marca indicativa do Erro */ putmark (marca); /* * Coloca o Tipo do Erro */ fputs ("******** ", stderr); switch (tipo) { case ADVR: fputs ("ADVR: ", stderr); nadvr++; break; case ERRO: fputs ("ERRO: ", stderr); nerro++; break; case FATAL: fputs ("ERRO FATAL: ", stderr); break; case COMP: fputs ("ERRO INTERNO: ", stderr); } /* end switch (tipo) */ fprintf (stderr, mens, var); putc ('\n', stderr); putc ('\n', stderr); if (tipo == COMP) quit (1); } /* end tic_error */