Listing 2: ctrldrm.c--Stripping off Ctrl-D
/**********************************************************/
/* Filter to strip off the first character if it is a */
/* CTRL-D. */
/* Added code to remove any blanks before the "%!" in the */
/* the first line of a PostScript file */
/**********************************************************/
#include <stdio.h>
void main() {
char buf[1][BUFSIZ];
char *p,*index();
fgets(buf[0], BUFSIZ, stdin);
/* Check for CTRL-D as first character */
if (buf[0][0] == '\04')
{
printf("%s",buf[0]+1);
}
else if ((p=index(buf[0],'%')) != NULL) /*Check for PostScript*/
{
if (strncmp(p,"%!",2) == 0) /*Verify PostScript*/
printf("%s", p);
else
printf("%s", buf[0]);
}
else
{
printf("%s", buf[0]);
}
fgets(buf[0], BUFSIZ, stdin);
while (!feof(stdin)) {
printf("%s", buf[0]);
fgets(buf[0], BUFSIZ, stdin);
}
}
/* End of File */
|