⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 etags.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 3 页
字号:
	  continue;	}    }  return (pfcnt);}tail(cp)     char *cp;{  register int len = 0;  while (*cp && (*cp&~' ') == ((*(dbp+len))&~' '))    cp++, len++;  if (*cp == 0)    {      dbp += len;      return (1);    }  return (0);}takeprec(){  while (isspace(*dbp))    dbp++;  if (*dbp != '*')    return;  dbp++;  while (isspace(*dbp))    dbp++;  if (!isdigit(*dbp))    {      --dbp;		/* force failure */      return;    }  do    dbp++;  while (isdigit(*dbp));}getit(){  register char *cp;  char c;  char nambuf[BUFSIZ];  while (isspace(*dbp))    dbp++;  if (*dbp == 0 || !isalpha(*dbp))    return;  for (cp = dbp+1; *cp && (isalpha(*cp) || isdigit(*cp)); cp++)    continue;  c = cp[0];  cp[0] = 0;  strcpy(nambuf, dbp);  cp[0] = c;  pfnote(nambuf, TRUE, lb.buffer, cp - lb.buffer + 1, lineno, linecharno);  pfcnt++;}/* * lisp tag functions * just look for (def or (DEF */L_funcs (fi)     FILE *fi;{  lineno = 0;  charno = 0;  pfcnt = 0;  while (!feof (fi))    {      lineno++;      linecharno = charno;      charno += readline (&lb, fi) + 1;      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++;	  while (isspace(*dbp)) dbp++;	  L_getit();	}    }}L_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;  strcpy(nambuf, dbp);  cp[0] = c;  pfnote(nambuf, TRUE, 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 get_scheme ();Scheme_funcs (fi)     FILE *fi;{  lineno = 0;  charno = 0;  pfcnt = 0;  while (!feof (fi))    {      lineno++;      linecharno = charno;      charno += readline (&lb, fi) + 1;      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 ();	}    }}staticget_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, 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.  */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";struct TEX_tabent *TEX_decode_env (); static char TEX_esc = '\\';static char TEX_opgrp = '{';static char TEX_clgrp = '}';/* * TeX/LaTeX scanning loop. */TEX_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) + 1;      dbp = lb.buffer;      lasthit = dbp;      while (!feof (fi))	{	/* Scan each line in file */	  lineno++;	  linecharno = charno;	  charno += readline (&lb, fi) + 1;	  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 '!'/* Figure out whether TeX's escapechar is '\\' or '!' and set grouping *//* chars accordingly. */TEX_mode (f)     FILE *f;{  int c;  while ((c = getc (f)) != EOF)    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 deafult string to environment. */  env = (char *) 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 = (struct TEX_tabent *) xmalloc (size * sizeof (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.  */TEX_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++;  strncpy (nambuf, name, p - name);  nambuf[p - name] = 0;  pfnote (nambuf, TRUE, 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' */TEX_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;}/* Initialize a linebuffer for use */voidinitbuffer (linebuffer)     struct linebuffer *linebuffer;{  linebuffer->size = 200;  linebuffer->buffer = (char *) xmalloc (200);}/* Read a line of text from `stream' into `linebuffer'. Return the length of the line.  */longreadline (linebuffer, stream)     struct linebuffer *linebuffer;     register FILE *stream;{  char *buffer = linebuffer->buffer;  register char *p = linebuffer->buffer;  register char *pend;  pend = p + linebuffer->size;  while (1)    {      int c = getc (stream);      if (p == pend)	{	  linebuffer->size *= 2;	  buffer = (char *) xrealloc (buffer, linebuffer->size);	  p += buffer - linebuffer->buffer;	  pend = buffer + linebuffer->size;	  linebuffer->buffer = buffer;	}      if (c < 0 || c == '\n')	{	  *p = 0;	  break;	}      *p++ = c;    }  return p - buffer;}char *savestr(cp)     char *cp;{  return savenstr (cp, strlen (cp));}char *savenstr(cp, len)    char *cp;    int len;{  register char *dp;  dp = (char *) xmalloc (len + 1);  strncpy (dp, cp, len);  dp[len] = '\0';  return dp;}/* * Return the ptr in sp at which the character c last * appears; NULL if not found * * Identical to v7 rindex, included for portability. */char *rindex(sp, c)     register char *sp, c;{  register char *r;  r = NULL;  do    {      if (*sp == c)	r = sp;    } while (*sp++);  return(r);}/* * Return the ptr in sp at which the character c first * appears; NULL if not found * * Identical to v7 index, included for portability. */char *index(sp, c)     register char *sp, c;{  do    {      if (*sp == c)	return (sp);    } while (*sp++);  return (NULL);}/* Print error message and exit.  */fatal (s1, s2)     char *s1, *s2;{  error (s1, s2);  exit (BAD);}/* Print error message.  `s1' is printf control string, `s2' is arg for it. */error (s1, s2)     char *s1, *s2;{  fprintf (stderr, "%s: ", progname);  fprintf (stderr, s1, s2);  fprintf (stderr, "\n");}/* Return a newly-allocated string whose contents concatenate those of s1, s2, s3.  */char *concat (s1, s2, s3)     char *s1, *s2, *s3;{  int len1 = strlen (s1), len2 = strlen (s2), len3 = strlen (s3);  char *result = (char *) xmalloc (len1 + len2 + len3 + 1);  strcpy (result, s1);  strcpy (result + len1, s2);  strcpy (result + len1 + len2, s3);  *(result + len1 + len2 + len3) = 0;  return result;}/* Like malloc but get fatal error if memory is exhausted.  */intxmalloc (size)     int size;{  int result = malloc (size);  if (!result)    fatal ("virtual memory exhausted", 0);  return result;}intxrealloc (ptr, size)     char *ptr;     int size;{  int result = realloc (ptr, size);  if (!result)    fatal ("virtual memory exhausted");  return result;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -