cmay
June 24th, 2009, 08:00 PM
hi.
i could not sleep last night so i wrote a small yes program from this describiton http://linux.about.com/library/cmd/blcmdl1_yes.htm
i never used the yes command or have it on my system but i seen the program before from here http://minnie.tuhs.org/UnixTree/V7/usr/src/cmd/yes.c.html
i would like to know what you think of it.
/*
* usage; a simple yes program that print 'y' to stdout unless string giving as second option
* synopsis
* yes [option]
* yes [string]
* yes [default , will print'y' to stdout]
*
* options
* --version
* --help
* --license
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
void help();
void license();
void version();
int main(int argc, char** argv)
{
int i;
if( argc == 1)
{
for(;;)
fprintf(stdout,"y\n");
}
for(i=1;i < argc;i++)
{
if(strcmp(argv[i],"--version") == 0)
{
version(argv[0]);
}
else if (strcmp(argv[i],"--license") == 0)
{
license(argv[0]);
}
else if (strcmp(argv[i],"--help") == 0)
{
help(argv[0]);
} else {
for(;;)
fprintf(stdout,"%s\n",argv[i]);
}
}
return 0;
}
void help(const char *progname)
{
printf("%s: usage no option [option] [string] \n"
"\t--version prints version number to stdout\n"
"\t--help this help \n"
"\t--license prints license to stdout\n"
"\tno option prints singel char y to stdout until program killed\n"
"\t%s [string] prints string to stdout until program killed\n",progname,progname);
exit(0);
}
void license(const char *progname)
{
fprintf(stdout,"%s\tauthor carsten may 2009\n license BSD\n",progname);
exit(0);
}
void version(const char *progname)
{
fprintf(stdout,"%s\tversion 0.0.1\n",progname);
exit(0);
}
i could not sleep last night so i wrote a small yes program from this describiton http://linux.about.com/library/cmd/blcmdl1_yes.htm
i never used the yes command or have it on my system but i seen the program before from here http://minnie.tuhs.org/UnixTree/V7/usr/src/cmd/yes.c.html
i would like to know what you think of it.
/*
* usage; a simple yes program that print 'y' to stdout unless string giving as second option
* synopsis
* yes [option]
* yes [string]
* yes [default , will print'y' to stdout]
*
* options
* --version
* --help
* --license
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
void help();
void license();
void version();
int main(int argc, char** argv)
{
int i;
if( argc == 1)
{
for(;;)
fprintf(stdout,"y\n");
}
for(i=1;i < argc;i++)
{
if(strcmp(argv[i],"--version") == 0)
{
version(argv[0]);
}
else if (strcmp(argv[i],"--license") == 0)
{
license(argv[0]);
}
else if (strcmp(argv[i],"--help") == 0)
{
help(argv[0]);
} else {
for(;;)
fprintf(stdout,"%s\n",argv[i]);
}
}
return 0;
}
void help(const char *progname)
{
printf("%s: usage no option [option] [string] \n"
"\t--version prints version number to stdout\n"
"\t--help this help \n"
"\t--license prints license to stdout\n"
"\tno option prints singel char y to stdout until program killed\n"
"\t%s [string] prints string to stdout until program killed\n",progname,progname);
exit(0);
}
void license(const char *progname)
{
fprintf(stdout,"%s\tauthor carsten may 2009\n license BSD\n",progname);
exit(0);
}
void version(const char *progname)
{
fprintf(stdout,"%s\tversion 0.0.1\n",progname);
exit(0);
}