Back to index

texmacs  1.0.7.15
Functions
p_in.c File Reference
#include <stdio.h>
#include <stdio_ext.h>

Go to the source code of this file.

Functions

int hex (int c, int *n)
int main (int argc, char **argv)

Function Documentation

int hex ( int  c,
int *  n 
)

Definition at line 4 of file p_in.c.

{ if ((c>='0')&&(c<='9')) { *n=c-'0'; return 1; }
  else if ((c>='a')&&(c<='f')) { *n=c-'a'+10; return 1; }
  else if ((c>='A')&&(c<='F')) { *n=c-'A'+10; return 1; }
  else return 0;
}

Here is the caller graph for this function:

int main ( int  argc,
char **  argv 
)

Definition at line 11 of file p_in.c.

{ FILE *in,*out; int c,c2,c3,n,n2,ok=1;
  if (argc>2)
  { in=fopen(argv[2],"r");
    if (!in)
    { fprintf(stderr,"cannot read from %s\n",argv[2]); exit(1); }
  }
  else
    { in=stdin;
    if (argc>1)
    { out=fopen(argv[1],"w");
      if (!out)
      {fprintf(stderr,"cannot write to %s\n",argv[1]); exit(1); }
    }
    else out=stdout;
  }
  while (1)
  { c=fgetc(in);
    if (c==EOF) break;
    else if (c=='[')
    { c=fgetc(in);
      if (c=='[') fputc('[',out);
      else if (hex(c,&n))
      { c2=fgetc(in);
       if (hex(c2,&n2))
        { n=16*n+n2; c3=fgetc(in);
         if (c3==']') fputc(n,out);
         else { fprintf(stderr,"error: [%c%c%c\n",c,c2,c3); ok=0; }
        }
       else { fprintf(stderr,"error: [%c%c\n",c,c2); ok=0; }
      }
      else { fprintf(stderr,"error: [%c\n",c); ok=0; }
    }
    else if (c==']')
    { c=fgetc(in);
      if (c==']') fputc(']',out);
      else { fprintf(stderr,"error: ]%c\n",c); ok=0; }
    }
    else if (c=='\n')
      if (ok) fflush(out); else { __fpurge(out); ok=1; }
    else if ((c>=' ')&&(c<=0x7e)) fputc(c,out);
  }
}

Here is the call graph for this function: