#include <stdio.h>

/*

	perlcr.c -- by Chris Candreva  <chris@westnet.com>  Aug 25 2000
	v 0.1   -- It's a single printf -- how many versions do you want ??

	Questions -- IT'S A PRINTF !!! What more do you want to know ?
	:-)

	This program is designed to be named  perl<cr> -- as in what is run if
	someone uploads a perl script from a DOS/WIN machine in binary mode.
	It prints out some helpful hints on what they did wrong.

	I save this file as /usr/local/bin/perlcr , then create a symlink with
	/usr/local/bin as the pwd using this little piece of perl:
	
	#!/usr/local/bin/perl
	$m=chr(13);	
	system ( "ln -s ./perlcr ./perl$m" );

	History:
	v0.0  Aug 2000  Initial version, one big multiline printf
	
	v0.1  Nov 11, 2003:
			Multiline-Strings are no longer allowed in gcc. Changed
			to many individual "...\n"\ lines
			
			Add a different print if no command line option is passed.
			Otherwise we would segfault.
*/


main (int argc, char **argv)

{

if (argc < 2) {
	printf ("\n  This program should be linked as \"perl<cr>\". In this way it will be invoked\n"\
  		"by any script uploaded in binary mode from a windows machine.\n\n");
	exit(0);
}

	printf ("Content-type: text/html\n"\
"\n"\
"<html><head><title>Invalid Script Format</title></head>\n"\
"<body>\n"\
"\n"\
"<h1>Error in script:</h1>\n"\
"<h2>%s</h2>\n"\
"\n"\
"Your script can not be run, probably because it is in the Windows text file\n"\
"format. This usually happens with a script uploaded from a Windows machine.\n"\
"<P>\n"\
"\n"\
"If you are using FTP to send your files to the server, Perl scripts should\n"\
"be transfered in ASCII mode, not binary.  WS-FTP has an Automatic mode, where\n"\
"it will attempt to automatically determine what type to use for a file.\n"\
"<P>\n"\
"\n"\
"From a Unix command prompt, you may also use the command: <b>dos2unix\n"\
"<i>infile outfile</i></b> to convert a file from DOS to Unix format.  If the\n"\
"<i>infile</i> and <i>outfile</i> are the same, it will write the output back\n"\
"out to the same file. File permissions, however, will then be wrong and\n"\
"should be reset. <P>\n"\
"\n"\
"</body>\n"\
"</html>\n"
, argv[1]);


}

