Back to index

courier  0.68.2
Functions
cgitextarea.c File Reference
#include "cgi.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>

Go to the source code of this file.

Functions

void cgi_output_unicode_escapes (const unicode_char *value, const char *escapes, void(*output_func)(const char *, size_t, void *), void *output_arg)
static void do_cgi_textarea (const char *name, int rows, int cols, const unicode_char *value, const char *opts, const char *wrap, void(*output_func)(const char *, size_t, void *), void *output_arg)
static void cnt_bytes (const char *str, size_t cnt, void *arg)
static void save_bytes (const char *str, size_t cnt, void *arg)
char * cgi_textarea (const char *name, int rows, int cols, const unicode_char *value, const char *wrap, const char *opts)

Function Documentation

void cgi_output_unicode_escapes ( const unicode_char value,
const char *  escapes,
void(*)(const char *, size_t, void *)  output_func,
void *  output_arg 
)

Definition at line 15 of file cgiinput.c.

{
       while (value && *value)
       {
              size_t i;

              for (i=0; value[i]; i++)
              {
                     if (value[i] > 127 ||
                         strchr(escapes, value[i]))
                            break;
              }

              while (i)
              {
                     char buf[100];

                     size_t n=sizeof(buf);
                     size_t j;

                     if (n > i)
                            n=i;

                     for (j=0; j<n; j++)
                            buf[j]=value[j];

                     (*output_func)(buf, j, output_arg);

                     value += j;
                     i -= j;
              }

              if (*value)
              {
                     char buf[100];

                     sprintf(buf, "&#%lu;", (unsigned long)value[i]);

                     (*output_func)(buf, 0, output_arg);
                     ++value;
              }
       }
}

Here is the caller graph for this function:

char* cgi_textarea ( const char *  name,
int  rows,
int  cols,
const unicode_char value,
const char *  wrap,
const char *  opts 
)

Definition at line 95 of file cgitextarea.c.

{
       size_t cnt=1;
       char *buf;
       char *ptr;

       if (!opts)
              opts="";

       do_cgi_textarea(name, rows, cols, value, opts, wrap, cnt_bytes, &cnt);

       buf=malloc(cnt);

       if (!buf)
              return NULL;

       ptr=buf;
       do_cgi_textarea(name, rows, cols, value, opts, wrap, save_bytes, &ptr);
       *ptr=0;
       return buf;
}

Here is the call graph for this function:

static void cnt_bytes ( const char *  str,
size_t  cnt,
void *  arg 
) [static]

Definition at line 75 of file cgitextarea.c.

{
       if (!cnt)
              cnt=strlen(str);

       *(size_t *)arg += cnt;
}

Here is the caller graph for this function:

static void do_cgi_textarea ( const char *  name,
int  rows,
int  cols,
const unicode_char value,
const char *  opts,
const char *  wrap,
void(*)(const char *, size_t, void *)  output_func,
void *  output_arg 
) [static]

Definition at line 22 of file cgitextarea.c.

{
       (*output_func)("<textarea name='", 0, output_arg);
       (*output_func)(name, 0, output_arg);
       (*output_func)("'", 0, output_arg);

       if (strchr(opts, 'r'))
              (*output_func)(" readonly='readonly'", 0, output_arg);
       if (strchr(opts, 'd'))
              (*output_func)(" disabled='disabled'", 0, output_arg);

       (*output_func)("'", 0, output_arg);

       if (rows)
       {
              char buf[100];

              sprintf(buf, " rows='%d'", rows);

              (*output_func)(buf, 0, output_arg);
       }

       if (cols)
       {
              char buf[100];

              sprintf(buf, " cols='%d'", cols);

              (*output_func)(buf, 0, output_arg);
       }

       if (wrap)
       {
              (*output_func)(" wrap='", 0, output_arg);
              (*output_func)(wrap, 0, output_arg);
              (*output_func)("'", 0, output_arg);
       }

       (*output_func)(">", 0, output_arg);

       cgi_output_unicode_escapes(value, "<>'&", output_func, output_arg);

       (*output_func)("</textarea>", 0, output_arg);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void save_bytes ( const char *  str,
size_t  cnt,
void *  arg 
) [static]

Definition at line 83 of file cgitextarea.c.

{
       char **p=(char **)arg;

       if (!cnt)
              cnt=strlen(str);

       memcpy(*p, str, cnt);

       *p += cnt;
}

Here is the caller graph for this function: