📄 etags.c
字号:
if (*dbp == 0) continue; /* save all values for later tagging */ tline.size = lb.size; strcpy (tline.buffer, lb.buffer); save_lineno = lineno; save_lcno = linecharno; /* grab block name */ for (cp = dbp + 1; *cp && (!endtoken (*cp)); cp++) continue; c = cp[0]; cp[0] = 0; strcpy (nambuf, dbp); cp[0] = c; dbp = cp; /* restore dbp to e-o-token */ get_tagname = FALSE; found_tag = TRUE; continue; /* and proceed to check for "extern" */ } if ((!incomm1) && (!incomm2) && (!inquote) && (!found_tag) && (!get_tagname)) { /* check for proc/fn keywords */ switch (c | ' ') { case 'p': if (tail ("rocedure")) /* c = 'p', dbp has advanced */ get_tagname = TRUE; continue; case 'f': if (tail ("unction")) get_tagname = TRUE; continue; } } } /* while not e-o-f */}/* * lisp tag functions * just look for (def or (DEF */voidL_funcs (fi) FILE *fi;{ lineno = 0; charno = 0; pfcnt = 0; while (!feof (fi)) { lineno++; linecharno = charno; charno += readline (&lb, fi); dbp = lb.buffer; if (dbp[0] == '(') { if (L_isdef (dbp)) { while (!isspace (*dbp)) dbp++; while (isspace (*dbp)) dbp++; L_getit (); } else { /* Check for (foo::defmumble name-defined ... */ while (*dbp && *dbp != ':' && !isspace (*dbp) && *dbp != '(' && *dbp != ')') dbp++; if (*dbp == ':') { while (*dbp == ':') dbp++; if (L_isdef (dbp)) { while (!isspace (*dbp)) dbp++; while (isspace (*dbp)) dbp++; L_getit (); } } } } }}intL_isdef (dbp) char *dbp;{ return ((dbp[1] == 'D' || dbp[1] == 'd') && (dbp[2] == 'E' || dbp[2] == 'e') && (dbp[3] == 'F' || dbp[3] == 'f'));}voidL_getit (){ register char *cp; char c; char nambuf[BUFSIZ]; if (*dbp == 0) return; for (cp = dbp + 1; *cp && *cp != '(' && *cp != ' '; cp++) continue; c = cp[0]; cp[0] = 0; (void) strcpy (nambuf, dbp); cp[0] = c; pfnote (nambuf, TRUE, FALSE, lb.buffer, cp - lb.buffer + 1, lineno, linecharno); pfcnt++;}/* * Scheme tag functions * look for (def... xyzzy * look for (def... (xyzzy * look for (def ... ((...(xyzzy .... * look for (set! xyzzy */static void get_scheme ();voidScheme_funcs (fi) FILE *fi;{ lineno = 0; charno = 0; pfcnt = 0; while (!feof (fi)) { lineno++; linecharno = charno; charno += readline (&lb, fi); dbp = lb.buffer; if (dbp[0] == '(' && (dbp[1] == 'D' || dbp[1] == 'd') && (dbp[2] == 'E' || dbp[2] == 'e') && (dbp[3] == 'F' || dbp[3] == 'f')) { while (!isspace (*dbp)) dbp++; /* Skip over open parens and white space */ while (*dbp && (isspace (*dbp) || *dbp == '(')) dbp++; get_scheme (); } if (dbp[0] == '(' && (dbp[1] == 'S' || dbp[1] == 's') && (dbp[2] == 'E' || dbp[2] == 'e') && (dbp[3] == 'T' || dbp[3] == 't') && (dbp[4] == '!' || dbp[4] == '!') && (isspace (dbp[5]))) { while (!isspace (*dbp)) dbp++; /* Skip over white space */ while (isspace (*dbp)) dbp++; get_scheme (); } }}static voidget_scheme (){ register char *cp; char c; char nambuf[BUFSIZ]; if (*dbp == 0) return; /* Go till you get to white space or a syntactic break */ for (cp = dbp + 1; *cp && *cp != '(' && *cp != ')' && !isspace (*cp); cp++) continue; /* Null terminate the string there. */ c = cp[0]; cp[0] = 0; /* Copy the string */ strcpy (nambuf, dbp); /* Unterminate the string */ cp[0] = c; /* Announce the change */ pfnote (nambuf, TRUE, FALSE, lb.buffer, cp - lb.buffer + 1, lineno, linecharno); pfcnt++;}/* Find tags in TeX and LaTeX input files. *//* TEX_toktab is a table of TeX control sequences that define tags. Each TEX_tabent records one such control sequence. CONVERT THIS TO USE THE Stab TYPE!! */struct TEX_tabent{ char *name; int len;};struct TEX_tabent *TEX_toktab = NULL; /* Table with tag tokens *//* Default set of control sequences to put into TEX_toktab. The value of environment var TEXTAGS is prepended to this. */static char *TEX_defenv =":chapter:section:subsection:subsubsection:eqno:label:ref:cite:bibitem:typeout";void TEX_mode ();struct TEX_tabent *TEX_decode_env ();void TEX_getit ();int TEX_Token ();static char TEX_esc = '\\';static char TEX_opgrp = '{';static char TEX_clgrp = '}';/* * TeX/LaTeX scanning loop. */voidTEX_funcs (fi) FILE *fi;{ char *lasthit; lineno = 0; charno = 0; pfcnt = 0; /* Select either \ or ! as escape character. */ TEX_mode (fi); /* Initialize token table once from environment. */ if (!TEX_toktab) TEX_toktab = TEX_decode_env ("TEXTAGS", TEX_defenv); while (!feof (fi)) { lineno++; linecharno = charno; charno += readline (&lb, fi); dbp = lb.buffer; lasthit = dbp; while (!feof (fi)) { /* Scan each line in file */ lineno++; linecharno = charno; charno += readline (&lb, fi); dbp = lb.buffer; lasthit = dbp; while (dbp = index (dbp, TEX_esc)) /* Look at each escape in line */ { register int i; if (!*(++dbp)) break; linecharno += dbp - lasthit; lasthit = dbp; i = TEX_Token (lasthit); if (0 <= i) { TEX_getit (lasthit, TEX_toktab[i].len); break; /* We only save a line once */ } } } }}#define TEX_LESC '\\'#define TEX_SESC '!'#define TEX_cmt '%'/* Figure out whether TeX's escapechar is '\\' or '!' and set grouping *//* chars accordingly. */voidTEX_mode (f) FILE *f;{ int c; while ((c = getc (f)) != EOF) { /* Skip to next line if we hit the TeX comment char. */ if (c == TEX_cmt) while (c != '\n') c = getc (f); else if (c == TEX_LESC || c == TEX_SESC ) break; } if (c == TEX_LESC) { TEX_esc = TEX_LESC; TEX_opgrp = '{'; TEX_clgrp = '}'; } else { TEX_esc = TEX_SESC; TEX_opgrp = '<'; TEX_clgrp = '>'; } rewind (f);}/* Read environment and prepend it to the default string. *//* Build token table. */struct TEX_tabent *TEX_decode_env (evarname, defenv) char *evarname; char *defenv;{ register char *env, *p; extern char *savenstr (), *index (); struct TEX_tabent *tab; int size, i; /* Append default string to environment. */ env = getenv (evarname); if (!env) env = defenv; else env = concat (env, defenv, ""); /* Allocate a token table */ for (size = 1, p = env; p;) if ((p = index (p, ':')) && *(++p)) size++; tab = xnew (size, struct TEX_tabent); /* Unpack environment string into token table. Be careful about */ /* zero-length strings (leading ':', "::" and trailing ':') */ for (i = 0; *env;) { p = index (env, ':'); if (!p) /* End of environment string. */ p = env + strlen (env); if (p - env > 0) { /* Only non-zero strings. */ tab[i].name = savenstr (env, p - env); tab[i].len = strlen (tab[i].name); i++; } if (*p) env = p + 1; else { tab[i].name = NULL; /* Mark end of table. */ tab[i].len = 0; break; } } return tab;}/* Record a tag defined by a TeX command of length LEN and starting at NAME. The name being defined actually starts at (NAME + LEN + 1). But we seem to include the TeX command in the tag name. */voidTEX_getit (name, len) char *name; int len;{ char *p = name + len; char nambuf[BUFSIZ]; if (*name == 0) return; /* Let tag name extend to next group close (or end of line) */ while (*p && *p != TEX_clgrp) p++; (void) strncpy (nambuf, name, p - name); nambuf[p - name] = 0; pfnote (nambuf, TRUE, FALSE, lb.buffer, strlen (lb.buffer), lineno, linecharno); pfcnt++;}/* If the text at CP matches one of the tag-defining TeX command names, return the index of that command in TEX_toktab. Otherwise return -1. *//* Keep the capital `T' in `Token' for dumb truncating compilers (this distinguishes it from `TEX_toktab' */intTEX_Token (cp) char *cp;{ int i; for (i = 0; TEX_toktab[i].len > 0; i++) if (strncmp (TEX_toktab[i].name, cp, TEX_toktab[i].len) == 0) return i; return -1;}/* Support for Prolog. *//* whole head (not only functor, but also arguments) is gotten in compound term. */voidprolog_getit (s, lineno, linecharno) char *s; int lineno; long linecharno;{ char nambuf[BUFSIZ], *save_s, tmpc; int insquote, npar; save_s = s; insquote = FALSE; npar = 0; while (1) { if (*s == '\0') /* syntax error. */ return; else if (insquote && *s == '\'' && *(s + 1) == '\'') s += 2; else if (*s == '\'') { insquote = !insquote; s++; } else if (!insquote && *s == '(') { npar++; s++; } else if (!insquote && *s == ')') { npar--; s++; if (npar == 0) break; else if (npar < 0) /* syntax error. */ return; } else if (!insquote && *s == '.' && (isspace (*(s + 1)) || *(s + 1) == '\0')) { /* fullstop. */ if (npar != 0) /* syntax error. */ return; s++; break; } else s++; } tmpc = *s; *s = '\0'; strcpy (nambuf, save_s); *s = tmpc; pfnote (nambuf, TRUE, save_s, strlen (nambuf), lineno, linecharno);}/* It is assumed that prolog predicate starts from column 0. */voidprolog_funcs (fi) FILE *fi;{ void skip_comment (), prolog_getit (); lineno = linecharno = charno = 0; while (!feof (fi)) { lineno++; linecharno += charno; charno = readline (&lb, fi) + 1; /* 1 for newline. */ dbp = lb.buffer; if (isspace (dbp[0])) /* not predicate header. */ continue; else if (dbp[0] == '%') /* comment. */ continue; else if (dbp[0] == '/' && dbp[1] == '*') /* comment. */ skip_comment (&lb, fi, &lineno, &linecharno); else /* found. */ prolog_getit (dbp, lineno, linecharno); }}voidskip_comment (plb, fi, plineno, plinecharno) struct linebuffer *plb; FILE *fi; int *plineno; /* result */ long *plinecharno; /* result */{ while (!substr ("*/", plb->buffer)) { (*plineno)++; *plinecharno += readline (plb, fi) + 1; } /* 1 for newline. */}/* Return TRUE if 'sub' exists somewhere in 's'. */intsubstr (sub, s) char *sub; char *s;{ while (*s && (s = index (s, *sub))) if (prestr (sub, s)) return (TRUE); else s++; return (FALSE);}/* Return TRUE if 'pre' is prefix of string 's'. */intprestr (pre, s) char *pre; char *s;{ if (*pre == '\0') return (TRUE); else if (*pre == *s) return (prestr (pre + 1, s + 1)); else return (FALSE);}/* Initialize a linebuffer for use */voidinitbuffer (linebuffer) struct linebuffer *linebuffer;{ linebuffer->size = 200; linebuffer->buffer = xnew (200, char);}/* * Read a line of text from `stream' into `linebuffer'. * Return the number of characters read from `stream', * which is the length of the line including the newline, if any. */longreadline (linebuffer, stream) struct linebuffer *linebuffer; register FILE *stream;{ char *buffer = linebuffer->buffer; register char *p = linebuffer->buffer; register char *pend; int newline; /* 1 if ended with newline, 0 if ended with EOF */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -