-
Notifications
You must be signed in to change notification settings - Fork 0
/
arealist.cpp
110 lines (98 loc) · 3.26 KB
/
arealist.cpp
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
// Copyright (c) 1999 Peter Karlsson
//
// $Id$
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#include <string>
#include <fstream.h>
#include <stdlib.h>
#include "config.h"
#include "select.h"
#include "getarg.h"
// main
// - lists defined areas
int main(void)
{
// Check if we have a guest user
char *p = getenv("REMOTE_USER");
bool isguest = p ? (strcmp(p, GUEST) == 0) : true;
// HTTP preamble
cout << "Content-type: text/html" << endl;
cout << endl;
// HTML body
cout << "<html>" << endl;
cout << "<head>" << endl;
cout << " <title>List of areas</title>" << endl;
cout << " <meta name=\"generator\" content=\"arealist.exe\">" << endl;
cout << " <link rel=\"stylesheet\" href=\"fido.css\" type=\"text/css\">"
<< endl;
cout << "</head>" << endl;
cout << "<body>" << endl;
// Retrieve parameters
// arealist.exe[?frame=1]
string frame = getarg("frame", true);
bool framed = frame == "1";
char iname[256], ipath[256], ititle[256];
// Open area definition file
fstream input(AREADEF, ios::in);
if (!(input.is_open()))
{
cout << "Unable to read area file, please try again." << endl;
cout << "</body></html>" << endl;
return 0;
}
// Create a table containing all the areas
cout << " <table>" << endl;
cout << " <tr><th>Title<th>Tag" << (isguest ? "" : "<th>Post")
<< endl;
while (!input.eof())
{
// File format:
// Line 1: Area tag
// Line 2: Area path
// Line 3: Area title
input.getline(iname, 256);
if (input.eof()) break;
input.getline(ipath, 256);
if (input.eof()) break;
input.getline(ititle, 256);
// Area tag "<hr>" creates a horizontal ruler
if (string("<hr>") == iname)
{
cout << " <tr><td colspan=" << (isguest ? '2' : '3')
<< "><hr>" << endl;
}
else
{
cout << " <tr><td valign=top><a href=\"messages.exe?area="
<< iname /*<< "&start=0"*/
<< (framed ? "&frame=1\" target=\"upper\"" : "\"")
<< '>' << ititle << "</a><br>" << endl;
cout << " <td valign=top>" << iname << "" << endl;
if (!isguest)
{
cout << " <td valign=top>[<a href=\"new.exe?area="
<< iname << "\""
<< (framed ? " target=\"_new\"" : "")
<< ">Post</a>]" << endl;
}
}
}
input.close();
// Close off the HTML code
cout << " </table>" << endl;
cout << "</body>" << endl;
cout << "</html>" << endl;
return 0;
}