Back to index

texmacs  1.0.7.15
p_out.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 
00003 int main(int argc,char **argv)
00004 { FILE *in,*out; int c;
00005   if (argc>2)
00006   { out=fopen(argv[2],"w");
00007     if (!out)
00008     { fprintf(stderr,"cannot write to %s\n",argv[2]); exit(1); }
00009   }
00010   else
00011   { out=stdout;
00012     if (argc>1)
00013     { in=fopen(argv[1],"r");
00014       if (!in)
00015       { fprintf(stderr,"cannot read from %s\n",argv[1]); exit(1); }
00016     }
00017     else in=stdin;
00018   }
00019   while (1)
00020   { c=fgetc(in);
00021     if (c==EOF) break;
00022     else if (c=='[') fputs("[[",out);
00023     else if (c==']') fputs("]]",out);
00024     else if (c=='\n') fprintf(out,"[%02x]\n",c);
00025     else if ((c>=' ')&&(c<=0x7e)) fputc(c,out);
00026     else fprintf(out,"[%02x]",c);
00027     fflush(out);
00028   }
00029 }