Link to home
Start Free TrialLog in
Avatar of nickswanjan
nickswanjanFlag for United States of America

asked on

Anything similar to Perl's qq or "here document" available for CGIs written in C?

I am new to writing CGIs in C, and wonder if there is anything available similar to Perl's qq or "here document" so that I don't have to printf every single line separately and escape all of the double quotes - especially when I have a block of html to output.  I could make every block of html a file and read it in, but that gets messy and I would much rather have a single CGI program.  Is there any nice way to do this in C?  If not, any suggestions for something better than the printf method I described are much appreciated.

#!/bin/perl

print qq{
<html>
<font color="red"><b>Isn't there some way to do this in C?</b></font>
</html>
};

print <<endofmultilinetext
<html>
<font color="yellow"><b>Or this?</b></font>
</html>
endofmultilinetext

Avatar of Kent Olsen
Kent Olsen
Flag of United States of America image


Sorry.  C is still in the dark ages here.

If the contents of the html are static the "copy a file" method really isn't too bad.  Within your program you can just:

  system ("cp HtmlFilePath");

It's pretty easy and straight-forward.

Kent
ASKER CERTIFIED SOLUTION
Avatar of Kent Olsen
Kent Olsen
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nickswanjan

ASKER

Not as clean as I would like, but the file conversion looks like a decent workaround - I can even make it put in the printf syntax as well.  What is the maximum line length though?  Sometimes individual html lines can get pretty long (I will qq several pages).  Although I suppose I could chop all lines at 75 characters or so using the same translation method...


C doesn't impose line length limits in the C source file or in its I/O.  The only limit that you might encounter is string length.  16-bit systems usually limit strings to 65K.

The file conversion approach can actually be made quite attractive.  Generate each page into its own file as the string returned by the convert program.  Then your source could look like this:

char *HtmlMainPage  =
#include <Htmlmainpage.c>
;

char *HtmlLoginPage =
#include <Htmlloginpage.c>
;



Good Luck!
Kent