/* Pads text files to fixed length records. Was at one time
very useful; is probably not today, but who knows?
Usage: PADDER INFILE OUTFILE PAD-SIZE
*/
#include <stdio.h>
#include <string.h>
char big_buff[1024];
main(argc,argv)
int argc;
char **argv;
{
char *bb=big_buff;
FILE *ipf,*opf;
int width=100;
int warning=0;
int maxwidth=0;
int line=0;
if (argc < 3) help(argv[0]);
if (argc == 4)
width=atoi(argv[3]);
if (width < 1)
width=100;
if ((ipf=fopen(argv[1],"r"))==NULL)
{
fprintf(stderr,"Can't open %s for input\n",argv[1]);
help(argv[0]);
}
if ((opf=fopen(argv[2],"w"))==NULL)
{
fprintf(stderr,"Can't open %s for output\n",argv[1]);
help(argv[0]);
}
while (fgets(bb,1024,ipf))
{
char *tp;
int mwidth;
line++;
if (tp=strchr(bb,'\n'))
*tp=0;
if ((mwidth=strlen(bb)) > width )
{
if (++warning == 1)
fprintf(stderr,"\007Warning: Input width exceeds %d\n",width);
fprintf(stderr,"Input line %5d , truncated %3d chars:\n %s\n",line,mwidth-width,bb+width);
if (mwidth > maxwidth)
maxwidth=mwidth;
}
fprintf(opf,"%-*.*s\n",width,width,bb);
}
fcloseall();
if (maxwidth)
fprintf(stderr,"(Max input width was %d)\n",maxwidth);
exit(0);
}
help(name)
char *name;
{
fprintf(stderr,"Usage:\n%s input-file output-file [pad-size]\n",name);
fprintf(stderr,"[pad-size] defaults to 100\n");
exit(1);
}
Enter your email address for automatic notification of new posts here
(be sure to whitelist 'feedburner.com' if you use spam filtering)
| Views for this page | ||||
|---|---|---|---|---|
| Today | This Week | This Month | This Year | Overall |
| 2 | 6 | 14 | 241 | 912 |
Have you tried Searching this site?
Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates
This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more. We appreciate comments and article submissions.

Add your comments