File: html-lib.c

package info (click to toggle)
ctn 3.2.0~dfsg-8
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 16,924 kB
  • sloc: ansic: 179,652; makefile: 7,006; java: 1,863; csh: 1,067; yacc: 523; sh: 424; cpp: 394; sql: 389; lex: 170
file content (125 lines) | stat: -rw-r--r-- 2,289 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/* html-lib.c - C routines that output various HTML constructs
   Eugene Kim, <eekim@eekim.com>
   $Id: html-lib.c,v 1.1 2001-10-23 19:08:22 smm Exp $

   Copyright (C) 1996, 1997 Eugene Eric Kim
   All Rights Reserved
*/

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include "html-lib.h"

/* HTTP headers */

void html_header()
{
  printf("Content-type: text/html\n\n");
}

void mime_header(char *mime)
/* char *mime = valid mime type */
{
  printf("Content-type: %s\n\n",mime);
}

void nph_header(char *status)
{
  printf("HTTP/1.0 %s\n",status);
  printf("Server: CGI using cgihtml\n");
}

void show_html_page(char *loc)
{
  printf("Location: %s\n\n",loc);
}

void status(char *status)
{
  printf("Status: %s\n",status);
}

void pragma(char *msg)
{
  printf("Pragma: %s\n",msg);
}

void set_cookie(char *name, char *value, char *expires, char *path,
		char *domain, short secure)
{
  /* in later version, do checks for valid variables */
  printf("Set-Cookie: %s=%s;",name,value);
  if (expires != NULL)
    printf(" EXPIRES=%s;",expires);
  if (path != NULL)
    printf(" PATH=%s;",path);
  if (domain != NULL)
    printf(" DOMAIN=%s;",domain);
  if (secure)
    printf(" SECURE");
  printf("\n");
}

/* HTML shortcuts */

void html_begin(char *title)
{
  printf("<html> <head>\n");
  printf("<title>%s</title>\n",title);
  printf("</head>\n\n");
  printf("<body>\n");
}

void html_begin_body_options(char *title, const char* options)
{
  printf("<html> <head>\n");
  printf("<title>%s</title>\n",title);
  printf("</head>\n\n");
  printf("<body %s>\n", options);
}

void html_end()
{
  printf("</body> </html>\n");
}

/* what's the best way to implement these tags?  Think about this a little
more before you settle on a way to do this. */

void h1(char *header)
{
  printf("<h1>%s</h1>\n",header);
}

void h2(char *header)
{
  printf("<h2>%s</h2>\n",header);
}

void h3(char *header)
{
  printf("<h3>%s</h3>\n",header);
}

void h4(char *header)
{
  printf("<h4>%s</h4>\n",header);
}

void h5(char *header)
{
  printf("<h5>%s</h5>\n",header);
}

void h6(char *header)
{
  printf("<h6>%s</h6>\n",header);
}

/* state related functions */
void hidden(char *name, char *value)
{
  printf("<input type=hidden name=\"%s\" value=\"%s\">\n",name,value);
}