Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!romp!auschs!d75!cello!sanders.uucp!sanders From: sanders@sanders.uucp (Tony Sanders) Newsgroups: comp.editors Subject: tag hack in vi Message-ID: <3071@cello.UUCP> Date: 30 Nov 89 20:38:35 GMT Sender: news@cello.UUCP Reply-To: sanders@sanders.uucp (Tony Sanders) Organization: IBM AWD, Austin, TX Lines: 182 Distribution: This will mostly be interesting to you if you have ex 3.7 source and like to hack C code. The other day I generated a /usr/lib/tags file for all of libc, include files and /usr/sys. I found (of course) many duplicate entries. So I set out to "solve" this problem. What I did was remove the compile time switch "FASTTAG" and changed it to a runtime option (:se). When you set fasttags (the default) Everything works like normal. When you turn off fasttags a ":ta foobar" will work like normal and doing a ":ta" (no param) will look up the next tag in the tags file. This allows you to sequence through tags with the same name. Good luck! -- sanders DONT forget to fix ex_vars.h (makeoptions is supposed to do it) -------------- diffs to ex_cmdsub.c, ex_data.c and ex_tagsio.c --------- ex_data.c 54a55 > "fasttags", "ft", ONOFF, 1, 1, 0, ex_tagio.c 10c10 < #ifdef FASTTAG --- > /* #ifdef FASTTAG -- fasttag is now a runtime switch, :se fasttag */ 105c105 < #endif --- > /* #endif FASTTAG */ ex_cmdsub.c 481c481,484 < #ifdef FASTTAG --- > /* tws -- if cmd is :ta then inc number of times we must match */ > static tagcount = 0; > int counter = 0; /* how many times have we matched (for :ta) */ > /* #ifdef FASTTAG -- fasttag is now a runtime option :se fasttag */ 486d488 < #endif 491a494 > tagcount = 1; 501,502c504,508 < } else if (lasttag[0] == 0) < error("No previous tag"); --- > } else { > tagcount++; > if (lasttag[0] == 0) > error("No previous tag"); > } 523,546c529,548 < #ifdef FASTTAG < iof = topen(fn, iofbuf); < if (iof == -1) < continue; < tfcount++; < fstat(iof, &sbuf); < top = sbuf.st_size; < if (top == 0L ) < top = -1L; < bot = 0L; < while (top >= bot) { < #else < /* < * Avoid stdio and scan tag file linearly. < */ < io = open(fn, 0); < if (io<0) < continue; < tfcount++; < if (fstat(io, &sbuf) < 0) < bsize = LBSIZE; < else { < bsize = sbuf.st_blksize; < if (bsize <= 0) --- > > if (value(FASTTAGS)) { > iof = topen(fn, iofbuf); > if (iof == -1) > continue; > tfcount++; > fstat(iof, &sbuf); > top = sbuf.st_size; > if (top == 0L ) > top = -1L; > bot = 0L; > } else { > /* > * Avoid stdio and scan tag file linearly. > */ > io = open(fn, 0); > if (io<0) > continue; > tfcount++; > if (fstat(io, &sbuf) < 0) 547a550,554 > else { > bsize = sbuf.st_blksize; > if (bsize <= 0) > bsize = LBSIZE; > } 549,550c556,557 < while (getfile() == 0) { < #endif --- > > while ( value(FASTTAGS) ? (top >= bot) : (getfile() == 0) ) { 556,559c563,567 < #ifdef FASTTAG < mid = (top + bot) / 2; < tseek(iof, mid); < if (mid > 0) /* to get first tag in file to work */ --- > if (value(FASTTAGS)) { > mid = (top + bot) / 2; > tseek(iof, mid); > /* to get first tag in file to work */ > if (mid > 0) 562,564c570,572 < goto goleft; < /* get the line itself */ < if(tgets(linebuf, sizeof linebuf, iof)==NULL) --- > goto goleft; > /* get the line itself */ > if(tgets(linebuf, sizeof linebuf, iof)==NULL) 567c575,576 < printf("tag: %o %o %o %s\n", bot, mid, top, linebuf); --- > printf("tag: %o %o %o %s\n", bot, mid, top, > linebuf); 569c578,579 < #endif --- > } > 574c584,585 < #ifdef FASTTAG --- > > if (value(FASTTAGS)) { 580c591 < #endif --- > } 584a596,597 > if (!value(FASTTAGS) && (++counter < tagcount)) > continue; 588,592c601,604 < #ifdef FASTTAG < tclose(iof); < #else < close(io); < #endif --- > if (value(FASTTAGS)) > tclose(iof); > else > close(io); 670,674c682,685 < #ifdef FASTTAG < tclose(iof); < #else < close(io); < #endif --- > if (value(FASTTAGS)) > tclose(iof); > else > close(io); ---------------- cut here ------------------ -- sanders Reply-To: cs.utexas.edu!ibmaus!auschs!sanders.austin.ibm.com!sanders Thought should exist outside any governmental framework. Brought to you by Super Global Mega Corp .com