Web programming in C lang with TCC

Discussion in 'C Programming' started by lovecreatesbeauty, Jun 16, 2011.

  1. lovecreatesbeauty, Jun 16, 2011
    #1
    1. Advertising

  2. lovecreatesbeauty

    Mark Bluemel Guest

    On 06/16/2011 10:31 AM, lovecreatesbeauty wrote:
    > $ cat /usr/lib/cgi-bin/ex1.c
    > #!/usr/local/bin/tcc -run
    >
    > #include<tcclib.h>
    >
    > int main(void)
    > {
    > printf("Content-type: text/html\r\n\r\n");
    > printf("Hello<a href=\"http://bellard.org/tcc/\">TCC</a> cgi
    > \n");
    >
    > return 0;
    > }
    > $
    >
    > Screenshot:
    > https://gknszq.bay.livefilestore.co...P6NGMFXem425vYBBi4JhJJdC5D/tcc_cgi.JPG?psid=1


    Did you have a question or a point to make?
     
    Mark Bluemel, Jun 16, 2011
    #2
    1. Advertising

  3. On Jun 16, 5:54 pm, Mark Bluemel <> wrote:
    > On 06/16/2011 10:31 AM, lovecreatesbeauty wrote:
    >
    >
    >
    >
    >
    >
    >
    >
    >
    > > $ cat /usr/lib/cgi-bin/ex1.c
    > > #!/usr/local/bin/tcc -run

    >
    > > #include<tcclib.h>

    >
    > > int main(void)
    > > {
    > >          printf("Content-type: text/html\r\n\r\n");
    > >          printf("Hello<a href=\"http://bellard.org/tcc/\">TCC</a>  cgi
    > > \n");

    >
    > >          return 0;
    > > }
    > > $

    >
    > > Screenshot:
    > >https://gknszq.bay.livefilestore.com/y1pb88_dv-BFgRHvX54YUSaOhLLDXSfq...

    >
    > Did you have a question or a point to make?


    Thanks for posting.

    I mean I posted this one "The end of C-like script languages - C
    script with TCC" some days ago.

    People seems don't believe the C can be directly used in web
    programming :)

    I wish C (with TCC) eat up PHP, Perl, ..
     
    lovecreatesbeauty, Jun 16, 2011
    #3
  4. lovecreatesbeauty

    Angel Guest

    On 2011-06-16, lovecreatesbeauty <> wrote:
    >
    > People seems don't believe the C can be directly used in web
    > programming :)


    CGI programs written in C have been around longer than PHP and Perl
    have, I think.


    --
    "C provides a programmer with more than enough rope to hang himself.
    C++ provides a firing squad, blindfold and last cigarette."
    - seen in comp.lang.c
     
    Angel, Jun 16, 2011
    #4
  5. lovecreatesbeauty

    Tom St Denis Guest

    On Jun 16, 10:56 am, "io_x" <> wrote:
    > "lovecreatesbeauty" <> ha scritto nel messaggionews:...
    >
    > >$ cat /usr/lib/cgi-bin/ex1.c
    > > #!/usr/local/bin/tcc -run

    >
    > > #include <tcclib.h>

    >
    > > int main(void)
    > > {
    > >        printf("Content-type: text/html\r\n\r\n");

    >
    > i think in some pc, in some compiler, in some OS: "\n\n" could be sufficient
    > but if above there is "\r\n" than below there is need of "\r\n" too;
    > [and this is not here]


    Not only is this ridiculously OT, but in HTTP you must send \r\n\r\n
    to indicate two blank lines REGARDLESS of your platform hosting or
    consuming content.

    > so for me it should be the file as
    > --------------
    > // file name page.c
    > #include <stdio.h>
    >
    > int main(void)
    > {printf("Content-type: text/html \n\n");
    >  printf("Hello <a href=\"http://bellard.org/tcc/\">TCC</a> cgi\n");
    >  return 0;}


    Except this won't work, and you'd know that if you tested it (any half
    decent web server would reject the CGI output and issue an error).

    Tom
     
    Tom St Denis, Jun 16, 2011
    #5
  6. lovecreatesbeauty <> writes:
    [...]
    > I mean I posted this one "The end of C-like script languages - C
    > script with TCC" some days ago.
    >
    > People seems don't believe the C can be directly used in web
    > programming :)


    I don't think anyone has ever suggested that it's not possible.
    And for generating static content, as your program does, it probably
    works as well as any other language -- though not as well as just
    creating an html file in the right place.

    For other purpose, scripting languages offer much easier string
    handling, which is a considerable advantage in this context.

    > I wish C (with TCC) eat up PHP, Perl, ..


    By all means, wish away.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    Nokia
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Jun 16, 2011
    #6
  7. On Jun 17, 12:08 am, Keith Thompson <> wrote:
    >
    > I don't think anyone has ever suggested that it's not possible.
    > And for generating static content, as your program does, it probably
    > works as well as any other language -- though not as well as just
    > creating an html file in the right place.


    Thank you.

    I tried some more examples with TCC just now tonight (01:25 dark and
    silent morning like the night here:).

    You're right. TCC presents static pages easily but lacks of session
    management. And PHP features like $_GET['x'], $_POST['x'] are missing
    from TCC currently. Maybe someone will contribute on this area for
    TCC. Can this guy be me:)

    > For other purpose, scripting languages offer much easier string
    > handling, which is a considerable advantage in this context.


    TCC seems can use the whole C library as well as the stdio.h and
    string.h. I think the string operation function are not a problem for
    TCC to succeed on web.
     
    lovecreatesbeauty, Jun 16, 2011
    #7
  8. lovecreatesbeauty, Jun 16, 2011
    #8
  9. On Jun 17, 12:08 am, Keith Thompson <> wrote:
    >
    > For other purpose, scripting languages offer much easier string
    > handling, which is a considerable advantage in this context.
    >


    I think by now C scripting with TCC can at least kick Perl out of
    stage

    >> I wish C (with TCC) eat up PHP, Perl, ..


    > By all means, wish away.


    What's your opinion on TCC's ability of making C a power script tool?
    C is great and should be used everywhere.
     
    lovecreatesbeauty, Jun 16, 2011
    #9
  10. On Jun 17, 1:46 am, lovecreatesbeauty <>
    wrote:
    > On Jun 17, 12:08 am, Keith Thompson <> wrote:
    >
    > > For other purpose, scripting languages offer much easier string
    > > handling, which is a considerable advantage in this context.

    >


    No more weird languages like Perl, Pythod, Ruby, PHP, ..blah..
     
    lovecreatesbeauty, Jun 16, 2011
    #10
  11. lovecreatesbeauty

    Dr Nick Guest

    Tom St Denis <> writes:

    > On Jun 16, 10:56 am, "io_x" <> wrote:
    >> "lovecreatesbeauty" <> ha scritto nel messaggionews:...
    >>
    >> >$ cat /usr/lib/cgi-bin/ex1.c
    >> > #!/usr/local/bin/tcc -run

    >>
    >> > #include <tcclib.h>

    >>
    >> > int main(void)
    >> > {
    >> >        printf("Content-type: text/html\r\n\r\n");

    >>
    >> i think in some pc, in some compiler, in some OS: "\n\n" could be sufficient
    >> but if above there is "\r\n" than below there is need of "\r\n" too;
    >> [and this is not here]

    >
    > Not only is this ridiculously OT, but in HTTP you must send \r\n\r\n
    > to indicate two blank lines REGARDLESS of your platform hosting or
    > consuming content.


    Hmm. I'm not convinced. Of course, when the HTTP is sent from the
    server it has to have carriage-return line-feed (I'm not using \n for
    very deliberate reasons here) but I think the server is perfectly at
    liberty to take any line separation it wants on the incoming from the
    cgi.

    Indeed, I just went and looked at RFC 3875 and it just says the header
    and body must be "separated by a blank line".

    There's a good reason for this, of course. C is quite at liberty to
    take your \r\n\ and turn it into - say - carriage-return carriage-return
    line-feed.

    Still OT, but at least correct now. I've got good reasons for knowing
    this.
    --
    Online waterways route planner | http://canalplan.eu
    Plan trips, see photos, check facilities | http://canalplan.org.uk
     
    Dr Nick, Jun 16, 2011
    #11
  12. lovecreatesbeauty <> writes:
    > On Jun 17, 12:08 am, Keith Thompson <> wrote:
    >>
    >> For other purpose, scripting languages offer much easier string
    >> handling, which is a considerable advantage in this context.
    >>

    >
    > I think by now C scripting with TCC can at least kick Perl out of
    > stage


    That hardly seems likely.

    >>> I wish C (with TCC) eat up PHP, Perl, ..

    >
    >> By all means, wish away.

    >
    > What's your opinion on TCC's ability of making C a power script tool?
    > C is great and should be used everywhere.


    C is great for some things (implementing Perl, for example), but not for
    everything. I'd go into more detail, but I'm not interested in a
    language flame war.

    It's always been possible to do CGI in C; just write a C program that
    produces HTML, compile it, and put the executable in the right place on
    the server. TCC seems to add the ability to use the source file
    directly, which might be convenient, but I don't see that it's that big
    an advantage.

    If it works for you, that's great. If you expect it to be a
    Perl-killer, you're going to be disappointed.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    Nokia
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Jun 16, 2011
    #12
  13. lovecreatesbeauty

    Tom St Denis Guest

    On Jun 16, 3:03 pm, Dr Nick <> wrote:
    > Tom St Denis <> writes:
    >
    >
    >
    > > On Jun 16, 10:56 am, "io_x" <> wrote:
    > >> "lovecreatesbeauty" <> ha scritto nel messaggionews:....

    >
    > >> >$ cat /usr/lib/cgi-bin/ex1.c
    > >> > #!/usr/local/bin/tcc -run

    >
    > >> > #include <tcclib.h>

    >
    > >> > int main(void)
    > >> > {
    > >> >        printf("Content-type: text/html\r\n\r\n");

    >
    > >> i think in some pc, in some compiler, in some OS: "\n\n" could be sufficient
    > >> but if above there is "\r\n" than below there is need of "\r\n" too;
    > >> [and this is not here]

    >
    > > Not only is this ridiculously OT, but in HTTP you must send \r\n\r\n
    > > to indicate two blank lines REGARDLESS of your platform hosting or
    > > consuming content.

    >
    > Hmm.  I'm not convinced.  Of course, when the HTTP is sent from the
    > server it has to have carriage-return line-feed (I'm not using \n for
    > very deliberate reasons here) but I think the server is perfectly at
    > liberty to take any line separation it wants on the incoming from the
    > cgi.
    >
    > Indeed, I just went and looked at RFC 3875 and it just says the header
    > and body must be "separated by a blank line".
    >
    > There's a good reason for this, of course.  C is quite at liberty to
    > take your \r\n\ and turn it into - say - carriage-return carriage-return
    > line-feed.
    >
    > Still OT, but at least correct now.  I've got good reasons for knowing
    > this.


    Um, things like Apache expect both characters and most platforms do
    not turn \n into two characters. Indeed sizeof("\n") is 2 ...
    always. Where things differ is what \n DOES.

    So no, for a conforming C CGI application your HTTP headers must end
    each line with \r\n.

    Modern servers/browsers might "put up with" just \n, but my experience
    with IIS and Apache is that \r\n is what they required lest you get an
    error.

    More so, it is wicked off topic and completely not news. Indeed my
    first CGI applications were all in C way back when. It was just
    faster. Then I realized that perl was infinitely better at working
    with textual data...

    Tom
     
    Tom St Denis, Jun 16, 2011
    #13
  14. lovecreatesbeauty

    Dr Nick Guest

    Tom St Denis <> writes:

    > On Jun 16, 3:03 pm, Dr Nick <> wrote:
    >> Tom St Denis <> writes:
    >>
    >>
    >>
    >> > On Jun 16, 10:56 am, "io_x" <> wrote:
    >> >> "lovecreatesbeauty" <> ha scritto nel messaggionews:...

    >>
    >> >> >$ cat /usr/lib/cgi-bin/ex1.c
    >> >> > #!/usr/local/bin/tcc -run

    >>
    >> >> > #include <tcclib.h>

    >>
    >> >> > int main(void)
    >> >> > {
    >> >> >        printf("Content-type: text/html\r\n\r\n");

    >>
    >> >> i think in some pc, in some compiler, in some OS: "\n\n" could be sufficient
    >> >> but if above there is "\r\n" than below there is need of "\r\n" too;
    >> >> [and this is not here]

    >>
    >> > Not only is this ridiculously OT, but in HTTP you must send \r\n\r\n
    >> > to indicate two blank lines REGARDLESS of your platform hosting or
    >> > consuming content.

    >>
    >> Hmm.  I'm not convinced.  Of course, when the HTTP is sent from the
    >> server it has to have carriage-return line-feed (I'm not using \n for
    >> very deliberate reasons here) but I think the server is perfectly at
    >> liberty to take any line separation it wants on the incoming from the
    >> cgi.
    >>
    >> Indeed, I just went and looked at RFC 3875 and it just says the header
    >> and body must be "separated by a blank line".
    >>
    >> There's a good reason for this, of course.  C is quite at liberty to
    >> take your \r\n\ and turn it into - say - carriage-return carriage-return
    >> line-feed.
    >>
    >> Still OT, but at least correct now.  I've got good reasons for knowing
    >> this.

    >
    > Um, things like Apache expect both characters and most platforms do
    > not turn \n into two characters. Indeed sizeof("\n") is 2 ...
    > always. Where things differ is what \n DOES.
    >
    > So no, for a conforming C CGI application your HTTP headers must end
    > each line with \r\n.
    >
    > Modern servers/browsers might "put up with" just \n, but my experience
    > with IIS and Apache is that \r\n is what they required lest you get an
    > error.
    >
    > More so, it is wicked off topic and completely not news. Indeed my
    > first CGI applications were all in C way back when. It was just
    > faster. Then I realized that perl was infinitely better at working
    > with textual data...


    No-no-no, I'm afraid you're wrong (apart from saying it's OT!). cgi to
    server is RFC 3875, not HTTP. What you send might look like HTTP
    headers, and might end up as HTTP headers, but it's not HTTP.

    And Apache is perfectly happy getting a \n and has been for 10+ years
    IME.

    How do you write a C program that will always send carriage-return,
    line-feed and nothing else?

    My cgi is in C, but it runs a scripting language because - as you say -
    you have an awful lot of strings to deal with.
    --
    Online waterways route planner | http://canalplan.eu
    Plan trips, see photos, check facilities | http://canalplan.org.uk
     
    Dr Nick, Jun 17, 2011
    #14
  15. Dr Nick <> writes:
    [...]
    > How do you write a C program that will always send carriage-return,
    > line-feed and nothing else?

    [...]

    Probably by setting the output stream to binary mode and writing "\r\n".

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    Nokia
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Jun 17, 2011
    #15
  16. lovecreatesbeauty

    Seebs Guest

    On 2011-06-16, lovecreatesbeauty <> wrote:
    > I think by now C scripting with TCC can at least kick Perl out of
    > stage


    I don't.

    > What's your opinion on TCC's ability of making C a power script tool?
    > C is great and should be used everywhere.


    Frankly... I think it's stupid, and won't work.

    Look, it's not that I don't like C. I love C. But this is not what C
    is good at. C is not really a great language for expressive string
    manpulation. C is good for back-end stuff, but it's simply not a good
    choice for the kinds of things we use scripting languages for.

    It's like watching someone who's working on replacing screws with nails
    on the grounds that he really likes using a hammer, and screws don't
    hammer very well.

    The fact is, even a very good C programmer will not be able to compete
    effectively with someone using a more appropriate language for this kind
    of thing. It's a waste of energy.

    I don't want to give the impression that it's an unheard of waste of
    energy; I wrote a wrapper program which "interpreted" C about twenty years
    ago. It was an interesting curiousity; it was not useful.

    -s
    --
    Copyright 2011, all wrongs reversed. Peter Seebach /
    http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
    http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
    I am not speaking for my employer, although they do rent some of my opinions.
     
    Seebs, Jun 17, 2011
    #16
  17. lovecreatesbeauty

    Seebs Guest

    On 2011-06-16, lovecreatesbeauty <> wrote:
    > No more weird languages like Perl, Pythod, Ruby, PHP, ..blah..


    I don't much care for some of those, but...

    For the sorts of things usually done with CGI, I can run rings around C
    in any of them. (And I say this as someone who has done CGI in C, and in
    shell for that matter...)

    -s
    --
    Copyright 2011, all wrongs reversed. Peter Seebach /
    http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
    http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
    I am not speaking for my employer, although they do rent some of my opinions.
     
    Seebs, Jun 17, 2011
    #17
  18. lovecreatesbeauty

    Seebs Guest

    On 2011-06-16, Tom St Denis <> wrote:
    > Um, things like Apache expect both characters and most platforms do
    > not turn \n into two characters. Indeed sizeof("\n") is 2 ...
    > always. Where things differ is what \n DOES.


    Pretty sure it'll be sizeof(char *), not sizeof(char[2]). :)

    Not disputing the rest, although I think the one thing I've done in C
    that did CGI emitted \n plain and it worked...

    -s
    --
    Copyright 2011, all wrongs reversed. Peter Seebach /
    http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
    http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
    I am not speaking for my employer, although they do rent some of my opinions.
     
    Seebs, Jun 17, 2011
    #18
  19. Seebs <> writes:

    > On 2011-06-16, Tom St Denis <> wrote:
    >> Um, things like Apache expect both characters and most platforms do
    >> not turn \n into two characters. Indeed sizeof("\n") is 2 ...
    >> always. Where things differ is what \n DOES.

    >
    > Pretty sure it'll be sizeof(char *), not sizeof(char[2]). :)


    sizeof "\n" == 2 from 6.3.2.1 p3 (and 6.4.5 p5).

    --
    Ben.
     
    Ben Bacarisse, Jun 17, 2011
    #19
  20. lovecreatesbeauty

    Shao Miller Guest

    On 6/16/2011 8:40 PM, Seebs wrote:
    > On 2011-06-16, Tom St Denis<> wrote:
    >> Um, things like Apache expect both characters and most platforms do
    >> not turn \n into two characters. Indeed sizeof("\n") is 2 ...
    >> always. Where things differ is what \n DOES.

    >
    > Pretty sure it'll be sizeof(char *), not sizeof(char[2]). :)
    >
    > Not disputing the rest, although I think the one thing I've done in C
    > that did CGI emitted \n plain and it worked...
    >


    Then why was he so sure it'd be 2? Was it because of 6.4.5p5 and
    6.3.2.1p3 and 6.5.3.4p3?
     
    Shao Miller, Jun 17, 2011
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jsnX

    What is .tcc?

    jsnX, Apr 5, 2005, in forum: C++
    Replies:
    1
    Views:
    904
    Malte Starostik
    Apr 5, 2005
  2. Replies:
    3
    Views:
    317
    Jack Klein
    Apr 19, 2006
  3. Replies:
    1
    Views:
    1,675
    Ian Collins
    Aug 4, 2008
  4. lovecreatesbeauty

    The end of C-like script languages - C script with TCC

    lovecreatesbeauty, May 20, 2011, in forum: C Programming
    Replies:
    19
    Views:
    1,346
    Malcolm McLean
    Jun 19, 2011
  5. Malcolm McLean

    Tcc won't link libraries.

    Malcolm McLean, Jun 18, 2011, in forum: C Programming
    Replies:
    3
    Views:
    686
    Shao Miller
    Jun 19, 2011
Loading...

Share This Page