R/cgi.R

Defines functions writeRequestInfo

Documented in writeRequestInfo

getParameters =
  #
  #
  #
function(str = Sys.getenv("QUERY_STRING"))
{
  params = strsplit(strsplit(str, "&")[[1]], "=")
  names(params) = sapply(params, function(x) x[1])
  params = lapply(params, function(x) x[-1])
}

writeRequestInfo =
function(env = c("PATH_INFO", "HTTP_HOST", "HTTP_USER_AGENT", "HTTP_REFERER", "REMOTE_ADDR"), size = -1)
{
   cat('<center><hr width="50%"></center>\n')
   cat('<font size="', as.integer(size), '">\n', sep = '')
   cat("Generated by CGIwithR, version ", packageDescription('CGIwithR')$Version, "<br/>\n")
   cat("QUERY_STRING = <pre>", Sys.getenv("QUERY_STRING"), "</pre><p/>\n")

   if(is.logical(env) && env)
     env = Sys.getenv()

   if(length(env))
     showEnvironmentVariables(env)

   cat('</font>\n')

   invisible(env)
}

showEnvironmentVariables =
  #
  # Display the values of some or all environment variables
  # for help in debugging or reporting the settings for the
  # actual computations in the CGI script.
  #
function(env = Sys.getenv())
{
 if(is.null(names(env))) 
    env = Sys.getenv(env)

  cat("<table>\n")
  for(i in names(env))
      cat('<tr align="left"><th>', i, '</th><th>', env[i], '</th></tr>\n')
  cat("</table>\n")

  invisible(env)
}
duncantl/CGIwithR documentation built on Nov. 23, 2023, 3:38 p.m.