/***********************************************
* released under (E) licensing ... *
* (E) RULES AND REGULATIONS *
* permission to use/rewrite/add : granted *
* permission to trojan/steal : denied *
* permission to use illegally : denied *
* permission to use on /dev/urandom : denied *
***********************************************/
/* contact el8@press.co.jp for full license */
/* code copyrighted by ~el8 -- don't infringe! */
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#define loop(n) for(;n;)
char *TAG="[(%i) %s]";
char *TOCTAG="~el8|*iSSue1*[(%u) %s]*iSSue1|~el8";
extern char *optarg;
FILE *out;
void t4gz(char *,char*,int);
int
main (int argc, char *argv[])
{
int p;
char *file;
int type;
char *t4g = TAG;
if (argc < 3)
{
fprintf (stderr, "usage: %s <format> <-t> [-f infile] <-o outfile>\n"
"formats:\n"
"\t[-i]: integer output\n"
"\t[-X]: uppercase hexidecimal output\n"
"\t[-O]: octal output\n"
"\t[-x]: lowercase hexadecimal\n"
"[-t] = output table of contents\n",argv[0]);
exit (-1);
}
while ( (p = getopt(argc,argv,"tiXOxf:o:"))!=EOF){
switch(p){
case 't':
t4g = TOCTAG;
break;
case 'i':
type = p;
break;
case 'X':
type = p;
break;
case 'O':
type = p;
break;
case 'x':
type = p;
break;
case 'f':
file = optarg;
break;
case 'o':
if ((out=fopen(optarg,"w+"))==NULL)
{
perror(optarg);
exit (-1);
}
break;
default:
exit(-1);
}
}
if (out==NULL) out=stderr;
t4gz(file,t4g, type);
exit (0);
}
void
t4gz (char *T,char *tag,int io)
{
char articlename[80];
unsigned articleno=0;
int lineno;
FILE *TFD;
char buf[80];
if ((TFD = fopen (T, "r")) == NULL)
{
perror(T);
exit (-1);
}
bzero((char*)&buf,sizeof(buf));
lineno-=lineno;
loop (!feof (TFD))
{
lineno++;
fgets (buf, sizeof(buf), TFD);
if (sscanf(buf,tag,&articleno,articlename) == 2)
{
if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = '\0';
switch (io) {
case 'i':
fprintf(stderr,"[(%04i) %20s]\t @ \033[1mLine %i\033[m\n",articleno,articlename,lineno);
break;
case 'X':
fprintf(stderr,"[(%4X) %20s]\t @ \033[1mLine %i\033[m\n",articleno,
articlename,lineno);
break;
case 'O':
fprintf(stderr,"[(%4o) %20s]\t @ \033[1mLine %i\033[m\n",articleno,
articlename,lineno);
break;
case 'x':
fprintf(stderr,"[(%4x) %20s]\t @ \033[1mLine %i\033[m\n",articleno,
articlename,lineno);
break;
default:
fprintf(stderr,"[(%04i) %20s]\t @ \033[1mLine #%i\033[m\n",
articleno,articlename,lineno);
break;
}
}
bzero((char*)&buf,sizeof(buf));
}
fclose (out);
fclose (TFD);
exit (0);
}
syntax highlighted by Code2HTML, v. 0.9.1