PADDER.C Tony Lawrence:

download padder.c



/* Pads text files to fixed length records.  Was at one time
very useful; is probably not today, but who knows?


Hate these ads?



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;


LOD Communications, Inc.



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)

Or use any RSS reader

Delivered by FeedBurner


Views for this page
Today This Week This Month This Year  Overall
2614241 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.

Publishing your articles here

pavatar.jpg
More:




Unix/Linux Consultants

Your ad here - $48.00 yearly!

http://www.m3ipinc.com Security, firewalls, ids, audits, vulnerability assesments, BS7799, HIPAA, GLB, incident handling


http://thatitguy.com Business networking servers, Linux and Unix experts. In business since 1997! Windows and Exchange to Samba and Scalix migration experts.


larryi@ccamedical.com SCO OS5, Debian Linux, RedHat Linux, MySQL, Apache, AJAX development using dXport/dL4/Unibasic, Windows Connectivity, Sharing Resouces, Automation, Shell Scripting



Twitter
  • Nov 21 07:40
    @loudmouthman: well, a digital signature could prove it hadn't been altered. Text is no more insecure than anything else in that sense.
  • Nov 21 07:38
    Uggh. Lost $11.50 at poker last night by playing thoughtlessly and carelessly.




card_image








Change Congress


Related Posts