Back to index

tetex-bin  3.0
Functions | Variables
deref.c File Reference
#include <stdio.h>
#include <ctype.h>
#include <errno.h>

Go to the source code of this file.

Functions

int fclose (FILE *fp)
int fprintf (FILE *fp, const char *str,...)
int fputs (char *buf, FILE *fp)
char * strerror (int errno)
char * strchr (char *cp, int ch)
int strncmp (const char *s1, const char *s2, int count)
void process (FILE *fp)
void repair (char *line, char *ref, int toffset)
int main (int argc, char **argv)
int isref (char *cp)

Variables

int errno
int Errs = 0
char * Name = "stdin"
int Line = 0
char * Me

Function Documentation

int fclose ( FILE fp)
int fprintf ( FILE fp,
const char *  str,
  ... 
)
int fputs ( char *  buf,
FILE fp 
)
int isref ( char *  cp)

Definition at line 93 of file deref.c.

{
       if (strncmp(cp, "@ref{", 5) == 0)
              return 5;
       if (strncmp(cp, "@xref{", 6) == 0)
              return 6;
       if (strncmp(cp, "@pxref{", 7) == 0)
              return 7;
       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int main ( int  argc,
char **  argv 
)

Definition at line 62 of file deref.c.

{
       FILE *fp;

       Me = argv[0];

       if (argc == 1)
              process(stdin);
       else
              for (argc--, argv++; *argv != NULL; argc--, argv++) {
                     if (argv[0][0] == '-' && argv[0][1] == '\0') {
                            Name = "stdin";
                            Line = 0;
                            process(stdin);
                     } else if ((fp = fopen(*argv, "r")) != NULL) {
                            Name = *argv;
                            Line = 0;
                            process(fp);
                            fclose(fp);
                     } else {
                            fprintf(stderr, "%s: can not open: %s\n",
                                   *argv, strerror(errno));
                            Errs++;
                     }
              }
       return Errs != 0;
}

Here is the call graph for this function:

void process ( FILE fp)

Definition at line 107 of file deref.c.

{
       char buf[BUFSIZ];
       char *cp;
       int count;

       while (fgets(buf, sizeof buf, fp) != NULL) {
              Line++;
              cp = strchr(buf, '@');
              if (cp == NULL) {
                     fputs(buf, stdout);
                     continue;
              }
              do {
                     count = isref(cp);
                     if (count == 0) {
                            cp++;
                            cp = strchr(cp, '@');
                            if (cp == NULL) {
                                   fputs(buf, stdout);
                                   goto next;
                            }
                            continue;
                     }
                     /* got one */
                     repair(buf, cp, count);
                     break;
              } while (cp != NULL);
       next: ;
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void repair ( char *  line,
char *  ref,
int  toffset 
)

Definition at line 142 of file deref.c.

{
       int braces = 1;             /* have seen first left brace */
       char *cp;

       ref += toffset;

       /* output line up to and including left brace in reference */
       for (cp = line; cp <= ref; cp++)
              putchar(*cp);

       /* output node name */
       for (; *cp && *cp != '}' && *cp != ',' && *cp != '\n'; cp++)
              putchar(*cp);

       if (*cp != '}')      {      /* could have been one arg xref */
              /* skip to matching right brace */
              for (; braces > 0; cp++) {
                     switch (*cp) {
                     case '@':
                            cp++;  /* blindly skip next character */
                            break;
                     case '{':
                            braces++;
                            break;
                     case '}':
                            braces--;
                            break;
                     case '\n':
                     case '\0':
                            Errs++;
                            fprintf(stderr,
                                   "%s: %s: %d: mismatched braces\n",
                                   Me, Name, Line);
                            goto out;
                     default:
                            break;
                     }
              }
       out:
              ;
       }

       putchar('}');
       if (*cp == '}')
              cp++;

       /* now the rest of the line */
       for (; *cp; cp++)
              putchar(*cp);
       return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* strchr ( char *  cp,
int  ch 
)
char* strerror ( int  errno)
int strncmp ( const char *  s1,
const char *  s2,
int  count 
)

Variable Documentation

int Errs = 0

Definition at line 54 of file deref.c.

int Line = 0

Definition at line 56 of file deref.c.

char* Me

Definition at line 57 of file deref.c.

char* Name = "stdin"

Definition at line 55 of file deref.c.