rename this file so it is visible by metacpan et al
[catagits/fcgi2.git] / examples / echo.c
index e1aa10d..52323ce 100644 (file)
@@ -1,4 +1,4 @@
-/* 
+/*
  * echo.c --
  *
  *     Produce a page containing all FastCGI inputs
@@ -6,66 +6,82 @@
  *
  * Copyright (c) 1996 Open Market, Inc.
  *
- * See the file "LICENSE.TERMS" for information on usage and redistribution
+ * See the file "LICENSE" for information on usage and redistribution
  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  *
  */
-
 #ifndef lint
-static const char rcsid[] = "$Id: echo.c,v 1.1 1997/09/16 15:36:28 stanleyg Exp $";
+static const char rcsid[] = "$Id: echo.c,v 1.5 1999/07/28 00:29:37 roberts Exp $";
 #endif /* not lint */
 
-#include "fcgi_stdio.h"
+#include "fcgi_config.h"
+
 #include <stdlib.h>
 
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
 #ifdef _WIN32
 #include <process.h>
 #else
 extern char **environ;
 #endif
 
-void PrintEnv(char *label, char **envp)
+#include "fcgi_stdio.h"
+
+
+static void PrintEnv(char *label, char **envp)
 {
     printf("%s:<br>\n<pre>\n", label);
-    for(; *envp != NULL; envp++) {
+    for ( ; *envp != NULL; envp++) {
         printf("%s\n", *envp);
     }
     printf("</pre><p>\n");
 }
 
-void main ()
+int main ()
 {
     char **initialEnv = environ;
     int count = 0;
-    while(FCGI_Accept() >= 0) {
+
+    while (FCGI_Accept() >= 0) {
         char *contentLength = getenv("CONTENT_LENGTH");
         int len;
+
        printf("Content-type: text/html\r\n"
-              "\r\n"
-              "<title>FastCGI echo</title>"
-              "<h1>FastCGI echo</h1>\n"
-               "Request number %d,  Process ID: %d<p>\n", ++count, getpid());
-        if(contentLength != NULL) {
+           "\r\n"
+           "<title>FastCGI echo</title>"
+           "<h1>FastCGI echo</h1>\n"
+            "Request number %d,  Process ID: %d<p>\n", ++count, getpid());
+
+        if (contentLength != NULL) {
             len = strtol(contentLength, NULL, 10);
-        } else {
+        }
+        else {
             len = 0;
         }
-        if(len <= 0) {
+
+        if (len <= 0) {
            printf("No data from standard input.<p>\n");
-        } else {
+        }
+        else {
             int i, ch;
+
            printf("Standard input:<br>\n<pre>\n");
-            for(i = 0; i < len; i++) {
-                if((ch = getchar()) < 0) {
-                    printf("Error: Not enough bytes received "
-                           "on standard input<p>\n");
+            for (i = 0; i < len; i++) {
+                if ((ch = getchar()) < 0) {
+                    printf("Error: Not enough bytes received on standard input<p>\n");
                     break;
                }
                 putchar(ch);
             }
             printf("\n</pre><p>\n");
         }
+
         PrintEnv("Request environment", environ);
         PrintEnv("Initial environment", initialEnv);
     } /* while */
+
+    return 0;
 }