Version 1.1: fixed all pedantic warnings; cdoc documented.

This commit is contained in:
Neil Edelman 2017-03-26 22:00:13 -04:00
parent 4eba349541
commit 52fc1ceef8
10 changed files with 245 additions and 77 deletions

View File

@ -50,7 +50,7 @@ a relation to other Files by 'parent' and 'favourite' (@(pwd) uses this.)
</p>
<dl>
<dt>minimum standard</dt>
<dd>POSIX</dd>
<dd>POSIX.1</dd>
<dt>author</dt>
<dd>Neil</dd>
<dt>version</dt>
@ -72,11 +72,11 @@ See <a href = "#Files">Files</a>.
</dl>
</div>
<div><a name = "typedef int (*FilesFilter)(struct Files *const, const char *)"><!-- --></a>
<h3>typedef int (*FilesFilter)(struct Files *const, const char *)</h3>
<pre><b>typedef int (*FilesFilter)(struct Files *const, const char *)</b></pre>
<div><a name = "typedef int (*FilesFilter)(struct Files *const files, const char *file)"><!-- --></a>
<h3>typedef int (*FilesFilter)(struct Files *const files, const char *file)</h3>
<pre><b>typedef int (*FilesFilter)(struct Files *const files, const char *file)</b></pre>
<p>
Returns a boolean value.
Returns a boolean value on whether <em>files</em> should include <em>file</em>.
</p>
<dl>
</dl>
@ -197,7 +197,7 @@ Resets the list of favourites.
<pre>const char * <b>FilesEnumPath</b> (struct Files *const files)</pre>
<dl>
<dt>return</dt>
<dd>After FilesSetFarourite, this enumerates them.</dd>
<dd>After <a href = "#FilesSetPath">FilesSetPath</a>, this enumerates them.</dd>
</dl>
</div>
@ -215,7 +215,7 @@ Resets the list of favourites.
<pre>int <b>FilesSize</b> (const struct Files *files)</pre>
<dl>
<dt>return</dt>
<dd>File size of the selected file.</dd>
<dd>File size of the selected file in KB.</dd>
</dl>
</div>

View File

@ -25,13 +25,13 @@
padding: 4px;
}
</style>
<title></title>
<title>Parser</title>
</head>
<body>
<h1></h1>
<h1>Parser</h1>
<ul>
<li><a href = "#_declarations">Declarations</a></li>
@ -39,7 +39,95 @@
<li><a href = "#_detail">Function Detail</a></li>
</ul>
<p>
Copyright 2008, 2012 Neil Edelman, distributed under the terms of the
GNU General Public License, see copying.txt
</p>
<p>
Parsing of strings. '~' on a line by itself is recognised in ".newsfile.rss"
and ".sitemap.xml" as a &lt;head&gt;~&lt;body&gt;~&lt;tail&gt;; there should be two of them.
</p>
<p>
Parsed in ".index.html",
</p>
<ul>
<li>
@(content) prints <em>content.d</em>, or, if it is missing, <em>index.d</em>;
</li>
<li>
@(files){} repeats for all the files in the directory the contents of the
argument;
</li>
<li>
@(htmlcontent);
</li>
<li>
@(pwd){} prints the directory, the argument is the separator;
eg, @(pwd){/};
</li>
<li>
@(root){}, like @(pwd), except up instead of down;
</li>
<li>
@(now) prints the date and the time in UTC.
</li>
</ul>
<p>
Further parsed in @(files)<em></em> in ".index.html",
</p>
<ul>
<li>
@(filealt) prints Dir or File;
</li>
<li>
@(filedesc);
</li>
<li>
@(filehref) prints the filename or the <em>.link</em>;
</li>
<li>
@(fileicon) prints it's <em>.d.jpeg</em>, or if it is not there, <em>dir.jpeg</em> or
<em>file.jpeg</em>;
</li>
<li>
@(filename) prints the file name;
</li>
<li>
@(filesize) prints the file size, if it exits;
</li>
<li>
@(now) prints the date and the time in UTC.
</li>
</ul>
<p>
Parsed in ".newsfeed.rss",
</p>
<ul>
<li>
@(date) prints the date on the news file;
</li>
<li>
@(news) prints the contents of the file (as a text file);
</li>
<li>
@(newsname) prints the filename of the news story;
</li>
<li>
@(now) prints the date and the time in UTC;
</li>
<li>
@(title) prints the second line in the <em>.news</em>.
</li>
</ul>
<dl>
<dt>minimum standard</dt>
<dd>C89/90</dd>
<dt>author</dt>
<dd>Neil</dd>
<dt>version</dt>
<dd>1.1; 2017-03 fixed pedantic warnings; command-line improvements</dd>
<dt>since</dt>
<dd>0.6; 2008-03-21</dd>
</dl>
@ -59,7 +147,7 @@ See <a href = "#Parser">Parser</a>.
<h3>struct Files</h3>
<pre><b>struct Files</b></pre>
<p>
Dependancy on <em>Files</em>
Dependancy on <em>Files</em>.
</p>
<dl>
</dl>
@ -69,7 +157,7 @@ Dependancy on <em>Files</em>
<h3>typedef int (*ParserWidget)(struct Files *const files, FILE *const fp)</h3>
<pre><b>typedef int (*ParserWidget)(struct Files *const files, FILE *const fp)</b></pre>
<p>
All <em>ParserWidget</em>s are in <em>Widget.c</em>
All <em>ParserWidget</em>s are in <em>Widget.c</em>.
</p>
<dl>
</dl>

View File

@ -25,13 +25,13 @@
padding: 4px;
}
</style>
<title>Parser</title>
<title>Recursor</title>
</head>
<body>
<h1>Parser</h1>
<h1>Recursor</h1>
<ul>
<li><a href = "#_declarations">Declarations</a></li>
@ -44,12 +44,12 @@ Copyright 2008, 2012 Neil Edelman, distributed under the terms of the
GNU General Public License, see copying.txt
</p>
<p>
<em>MakeIndex</em> is a simple content management system that generates static
content, (mostly index.html,) on all the directories rooted at the directory
specified by the argument. It is based on a template file, ".index.html" and
".newsfeed.rss". Also included are files to summarise the directory structure
for a <em>xml</em> site map, compatible with Google, and any <em>.news</em> for an <em>rss</em>
feed. It takes one argument, &lt;directory&gt;, which is the root of the recursion.
<em>Recusor</em> is the main part of <em>MakeIndex</em>, a content management system that
generates static content, (mostly index.html,) on all the directories rooted
at the directory specified by the argument. It is based on a template file,
".index.html" and ".newsfeed.rss". Also included are files to summarise the
directory structure for a <em>xml</em> site map, compatible with Google, and any
<em>.news</em> for an <em>rss</em> feed.
</p>
<p>
There should be an &lt;example&gt; directory that has a bunch of files in it. Run
@ -102,7 +102,7 @@ If this is not the case, the constants are in <em>Files.c</em>.
</p>
<dl>
<dt>minimum standard</dt>
<dd>POSIX</dd>
<dd>POSIX.1</dd>
<dt>author</dt>
<dd>Neil</dd>
<dt>version</dt>
@ -117,7 +117,7 @@ If this is not the case, the constants are in <em>Files.c</em>.
<dt>fixme</dt>
<dd>Have a subset of LaTeX converted into html for the .d files?</dd>
<dt>fixme</dt>
<dd>Encoding is an issue; especially the newsfeed, 7bit.</dd>
<dd>Encoding is an issue; especially the newsfeed, which requires 7-bit.</dd>
<dt>fixme</dt>
<dd>It's not robust; eg @(files)<em>@(files){Don't do this.}</em>.</dd>
</dl>
@ -146,15 +146,13 @@ See <a href = "#Recursor">Recursor</a>.
<td>const char *idx, const char *map, const char *news</td>
</tr>
<tr>
<td>int</td>
<td><a href = "#RecursorGo">RecursorGo</a></td>
<td>void</td>
<td><a href = "#Recursor_">Recursor_</a></td>
<td>void</td>
</tr>
<tr>
<td>}
static void</td>
<td><a href = "#usage">usage</a></td>
<td>int</td>
<td><a href = "#RecursorGo">RecursorGo</a></td>
<td>void</td>
</tr>
</table>
@ -175,6 +173,16 @@ static void</td>
</dl>
</div>
<div><a name = "Recursor_"><!-- --></a>
<h3>Recursor_</h3>
<pre>void <b>Recursor_</b> (void)</pre>
<p>
Destructor.
</p>
<dl>
</dl>
</div>
<div><a name = "RecursorGo"><!-- --></a>
<h3>RecursorGo</h3>
<pre>int <b>RecursorGo</b> (void)</pre>
@ -185,18 +193,6 @@ Actually does the recursion.
</dl>
</div>
<div><a name = "usage"><!-- --></a>
<h3>usage</h3>
<pre>}
static void <b>usage</b> (void)</pre>
<p>
you must free() the memory!
</p>
<dl>
</dl>
</div>
</body>
</html>

View File

@ -25,13 +25,13 @@
padding: 4px;
}
</style>
<title></title>
<title>Widget</title>
</head>
<body>
<h1></h1>
<h1>Widget</h1>
<ul>
<li><a href = "#_declarations">Declarations</a></li>
@ -39,7 +39,37 @@
<li><a href = "#_detail">Function Detail</a></li>
</ul>
<p>
Copyright 2008, 2012 Neil Edelman, distributed under the terms of the
GNU General Public License, see copying.txt
</p>
<p>
Widgets like @(files), @(pwd). To create a widget:
</p>
<ul>
<li>
stick the code below implementing <em>ParserWidget</em>;
</li>
<li>
create a prototype in Widget.h;
</li>
<li>
in <em>Parser.c</em>, add to the symbol table, sym[] with the symbol you want, in
ASCIIbetical order.
</li>
</ul>
<p>
See Parser for more information.
</p>
<dl>
<dt>minimum standard</dt>
<dd>POSIX.1</dd>
<dt>author</dt>
<dd>Neil</dd>
<dt>version</dt>
<dd>1.1; 2017-03 fixed pedantic warnings; command-line improvements</dd>
<dt>since</dt>
<dd>0.6; 2008-03-25</dd>
</dl>

View File

@ -7,7 +7,7 @@
@title Files
@author Neil
@std POSIX
@std POSIX.1
@version 1.1; 2017-03 fixed pedantic warnings; command-line improvements
@since 0.6; 2008-03-24 */
@ -81,8 +81,9 @@ struct Files *Files(struct Files *const parent, const FilesFilter filter) {
if(!de->d_name || (filter && !filter(files, de->d_name))) continue;
/* get status of the file */
if(stat(de->d_name, &st)) { perror(de->d_name); continue; }
/* get the File(name, size) */
file = File(de->d_name, ((int)st.st_size + 512) >> 10, S_ISDIR(st.st_mode));
/* get the File(name, size) (in KB) */
file = File(de->d_name,
((int)st.st_size + 512) >> 10, S_ISDIR(st.st_mode));
if(!file) error = -1;
/* put it in the appropreate spot */
if(file->isDir) {
@ -91,7 +92,8 @@ struct Files *Files(struct Files *const parent, const FilesFilter filter) {
if(!FileInsert(file, &files->firstFile)) error = -1;
}
/* error */
if(error) fprintf(stderr, "Files: <%s> missed being included on the list.\n", de->d_name);
if(error) fprintf(stderr, "Files: <%s> missed being included on the "
"list.\n", de->d_name);
}
if(closedir(dir)) { perror(dir_current); }
return files;
@ -136,7 +138,7 @@ void FilesSetPath(struct Files *f) {
for( ; f->parent; f = f->parent) f->parent->favourite = f;
}
/** @return After FilesSetFarourite, this enumerates them. */
/** @return After \see{FilesSetPath}, this enumerates them. */
const char *FilesEnumPath(struct Files *const files) {
struct Files *f = files;
const char *name;
@ -154,7 +156,7 @@ const char *FilesName(const struct Files *const files) {
return files->this->name;
}
/** @return File size of the selected file. */
/** @return File size of the selected file in KB. */
int FilesSize(const struct Files *files) {
if(!files || !files->this) return 0;
return files->this->size;
@ -197,8 +199,11 @@ static void File_(struct File *file) {
static int FileInsert(struct File *file, struct File **startAddr) {
struct File *start;
struct File *prev = 0, *ptr = 0;
if(!file || !startAddr) { fprintf(stderr, "File::insert: file is null, not included.\n"); return 0; }
if(file->next) { fprintf(stderr, "File::insert: <%s> is already in some other list!\n", file->name); return 0; }
if(!file || !startAddr)
{ fprintf(stderr, "FileInsert: file is null.\n"); return 0; }
if(file->next)
{ fprintf(stderr, "FileInsert: <%s> is already in some other list.\n",
file->name); return 0; }
start = (struct File *)*startAddr;
/* 'prev' is where to insert; 'ptr' is next node */
for(prev = 0, ptr = start; ptr; prev = ptr, ptr = ptr->next) {

View File

@ -1,8 +1,8 @@
/** See \see{Files}. */
struct Files;
/** Returns a boolean value. */
typedef int (*FilesFilter)(struct Files *const, const char *);
/** Returns a boolean value on whether {files} should include {file}. */
typedef int (*FilesFilter)(struct Files *const files, const char *file);
struct Files *Files(struct Files *const parent, const FilesFilter filter);
void Files_(struct Files *files);

View File

@ -1,4 +1,4 @@
/* Copyright 2008, 2012 Neil Edelman, distributed under the terms of the
/** Copyright 2008, 2012 Neil Edelman, distributed under the terms of the
GNU General Public License, see copying.txt
Parsing of strings. '~' on a line by itself is recognised in ".newsfile.rss"
@ -7,11 +7,12 @@
Parsed in ".index.html",
* @(content) prints {content.d}, or, if it is missing, {index.d};
* @(files){} repeats for all the files in the directory the contents of the
* @(files)\{} repeats for all the files in the directory the contents of the
argument;
* @(htmlcontent);
* @(pwd){} prints the directory, the argument is the separator; eg, @(pwd){/};
* @(root){}, like @(pwd), except up instead of down;
* @(pwd)\{} prints the directory, the argument is the separator;
eg, @(pwd)\{/};
* @(root)\{}, like @(pwd), except up instead of down;
* @(now) prints the date and the time in UTC.
Further parsed in @(files){} in ".index.html",

View File

@ -1,10 +1,10 @@
/** See \see{Parser}. */
struct Parser;
/** Dependancy on {Files} */
/** Dependancy on {Files}. */
struct Files;
/** All {ParserWidget}s are in {Widget.c} */
/** All {ParserWidget}s are in {Widget.c}. */
typedef int (*ParserWidget)(struct Files *const files, FILE *const fp);
struct Parser *Parser(char *const str);

View File

@ -1,12 +1,12 @@
/** Copyright 2008, 2012 Neil Edelman, distributed under the terms of the
GNU General Public License, see copying.txt
{MakeIndex} is a simple content management system that generates static
content, (mostly index.html,) on all the directories rooted at the directory
specified by the argument. It is based on a template file, ".index.html" and
".newsfeed.rss". Also included are files to summarise the directory structure
for a {xml} site map, compatible with Google, and any {.news} for an {rss}
feed. It takes one argument, <directory>, which is the root of the recursion.
{Recusor} is the main part of {MakeIndex}, a content management system that
generates static content, (mostly index.html,) on all the directories rooted
at the directory specified by the argument. It is based on a template file,
".index.html" and ".newsfeed.rss". Also included are files to summarise the
directory structure for a {xml} site map, compatible with Google, and any
{.news} for an {rss} feed.
There should be an <example> directory that has a bunch of files in it. Run
{bin/MakeIndex example/}; it should make a webpage out of the directory
@ -35,9 +35,9 @@
and '/' is the directory separator; works for UNIX, MacOS, Windows.
If this is not the case, the constants are in {Files.c}.
@title Parser
@title Recursor
@author Neil
@std POSIX
@std POSIX.1
@version 1.1; 2017-03 fixed pedantic warnings; command-line improvements
@since 1.0; 2016-09-19 Added umask
0.8; 2013-07 case-insensitive sort
@ -45,7 +45,7 @@
0.6; 2008-03-27
@fixme Don't have <directory> be an argument; just do it in the current.
@fixme Have a subset of LaTeX converted into html for the .d files?
@fixme Encoding is an issue; especially the newsfeed, 7bit.
@fixme Encoding is an issue; especially the newsfeed, which requires 7-bit.
@fixme It's not robust; eg @(files){@(files){Don't do this.}}. */
#include <stdlib.h> /* malloc free fgets */
@ -66,7 +66,7 @@ static const int version_minor = 1;
static const size_t granularity = 1024;
static const int max_read = 0x1000;
const char *html_index = "index.html"; /* in multiple files */
static const char *html_index = "index.html";
static const char *xml_sitemap = "sitemap.xml";
static const char *rss_newsfeed = "newsfeed.rss";
static const char *template_index = ".index.html";
@ -161,6 +161,7 @@ struct Recursor *Recursor(const char *idx, const char *map, const char *news) {
return r;
}
/** Destructor. */
void Recursor_(void) {
if(!r) return;
if(r->sitemapParser && r->sitemap) {
@ -286,17 +287,27 @@ static char *readFile(const char *filename) {
fprintf(stderr, "Opened '%s' and alloted %lu bytes to read %lu "
"characters.\n", filename, bufSize, bufPos);
if(fclose(fp)) perror(filename);
return buf; /** you must free() the memory! */
return buf; /* you must free() the memory! */
}
static void usage(void) {
fprintf(stderr, "Usage: %s [--directory|-d] <directory> | [--help|-h]\n\n"
fprintf(stderr, "Usage: %s [--directory|-d] <directory> | [\n"
"\t [--input-index |-ti] <.index.html>\n"
"\t| [--input-newsfeed|-tn] <.newsfeed.rss>\n"
"\t| [--input-sitemap |-ts] <.sitemap.xml>\n"
"\t| [--output-index |-i] <index.html>\n"
"\t| [--output-newsfeed|-n] <newsfeed.rss>\n"
"\t| [--output-sitemap |-s] <sitemap.xml>\n"
"] | [--help|-h]\n\n", programme);
fprintf(stderr, "All the defaults are listed, except --directory, which "
"requires a value.\n"
"Input are in <directory>.\n\n"
"Version %d.%d.\n\n"
"MakeIndex is a content management system that generates static\n"
"content, (mostly index.html,) on all the directories rooted at the\n"
"<directory> based on <%s>.\n\n"
"It also does some other stuff. See readme.txt or\n"
"http://neil.chaosnet.org/ for further info.\n\n", programme,
"http://neil.chaosnet.org/ for further info.\n\n",
version_major, version_minor, template_index);
fprintf(stderr, "MakeIndex Copyright 2008, 2012 Neil Edelman\n"
"This program comes with ABSOLUTELY NO WARRANTY.\n"
@ -317,18 +328,54 @@ int main(int argc, char **argv) {
is_help = -1;
} else if(!strcmp("--directory", av) || !strcmp("-d", av)) {
if(directory) {
break;
is_invalid = -1; break;
} else if(++ac < argc) {
directory = argv[ac];
} else {
is_invalid = -1; break;
}
}
} else if(!strcmp("--input-index", av) || !strcmp("-ii", av)) {
if(++ac < argc) {
template_index = argv[ac];
} else {
is_invalid = -1; break;
}
} else if(!strcmp("--input-newsfeed", av) || !strcmp("-in", av)) {
if(++ac < argc) {
template_newsfeed = argv[ac];
} else {
is_invalid = -1; break;
}
} else if(!strcmp("--input-sitemap", av) || !strcmp("-is", av)) {
if(++ac < argc) {
template_sitemap = argv[ac];
} else {
is_invalid = -1; break;
}
} else if(!strcmp("--output-index", av) || !strcmp("-oi", av)) {
if(++ac < argc) {
html_index = argv[ac];
} else {
is_invalid = -1; break;
}
} else if(!strcmp("--output-newsfeed", av) || !strcmp("-on", av)) {
if(++ac < argc) {
rss_newsfeed = argv[ac];
} else {
is_invalid = -1; break;
}
} else if(!strcmp("--output-sitemap", av) || !strcmp("-os", av)) {
if(++ac < argc) {
xml_sitemap = argv[ac];
} else {
is_invalid = -1; break;
}
}
}
if(is_help || !directory) {
usage();
return is_help ? EXIT_SUCCESS : EXIT_FAILURE;
return is_help && !is_invalid ? EXIT_SUCCESS : EXIT_FAILURE;
}
fprintf(stderr, "Changing directory to <%s>.\n", directory);

View File

@ -1,16 +1,18 @@
/* Copyright 2008, 2012 Neil Edelman, distributed under the terms of the
/** Copyright 2008, 2012 Neil Edelman, distributed under the terms of the
GNU General Public License, see copying.txt
Widgets like @files @pwd. To create a widget:
Widgets like @(files), @(pwd). To create a widget:
* stick the code below implementing {ParserWidget};
* create a prototype in Widget.h;
* in {Parser.c}, add to the symbol table, sym[] with the symbol you want, in
ASCIIbetical order.
See Parser for more information.
@title Widget
@author Neil
@std C89/90
@std POSIX.1
@version 1.1; 2017-03 fixed pedantic warnings; command-line improvements
@since 0.6; 2008-03-25 */
@ -46,7 +48,6 @@ const char *dot_desc = ".d"; /* used in multiple files */
const char *dot_news = ".news";
extern const char *dir_current;
extern const char *dir_parent;
extern const char *html_index;
/* global, ick: news */
static int year = 1983;