Version 1.1: fixed all pedantic warnings; cdoc documented.
This commit is contained in:
parent
4eba349541
commit
52fc1ceef8
@ -50,7 +50,7 @@ a relation to other Files by 'parent' and 'favourite' (@(pwd) uses this.)
|
|||||||
</p>
|
</p>
|
||||||
<dl>
|
<dl>
|
||||||
<dt>minimum standard</dt>
|
<dt>minimum standard</dt>
|
||||||
<dd>POSIX</dd>
|
<dd>POSIX.1</dd>
|
||||||
<dt>author</dt>
|
<dt>author</dt>
|
||||||
<dd>Neil</dd>
|
<dd>Neil</dd>
|
||||||
<dt>version</dt>
|
<dt>version</dt>
|
||||||
@ -72,11 +72,11 @@ See <a href = "#Files">Files</a>.
|
|||||||
</dl>
|
</dl>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div><a name = "typedef int (*FilesFilter)(struct Files *const, const char *)"><!-- --></a>
|
<div><a name = "typedef int (*FilesFilter)(struct Files *const files, const char *file)"><!-- --></a>
|
||||||
<h3>typedef int (*FilesFilter)(struct Files *const, const char *)</h3>
|
<h3>typedef int (*FilesFilter)(struct Files *const files, const char *file)</h3>
|
||||||
<pre><b>typedef int (*FilesFilter)(struct Files *const, const char *)</b></pre>
|
<pre><b>typedef int (*FilesFilter)(struct Files *const files, const char *file)</b></pre>
|
||||||
<p>
|
<p>
|
||||||
Returns a boolean value.
|
Returns a boolean value on whether <em>files</em> should include <em>file</em>.
|
||||||
</p>
|
</p>
|
||||||
<dl>
|
<dl>
|
||||||
</dl>
|
</dl>
|
||||||
@ -197,7 +197,7 @@ Resets the list of favourites.
|
|||||||
<pre>const char * <b>FilesEnumPath</b> (struct Files *const files)</pre>
|
<pre>const char * <b>FilesEnumPath</b> (struct Files *const files)</pre>
|
||||||
<dl>
|
<dl>
|
||||||
<dt>return</dt>
|
<dt>return</dt>
|
||||||
<dd>After FilesSetFarourite, this enumerates them.</dd>
|
<dd>After <a href = "#FilesSetPath">FilesSetPath</a>, this enumerates them.</dd>
|
||||||
</dl>
|
</dl>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -215,7 +215,7 @@ Resets the list of favourites.
|
|||||||
<pre>int <b>FilesSize</b> (const struct Files *files)</pre>
|
<pre>int <b>FilesSize</b> (const struct Files *files)</pre>
|
||||||
<dl>
|
<dl>
|
||||||
<dt>return</dt>
|
<dt>return</dt>
|
||||||
<dd>File size of the selected file.</dd>
|
<dd>File size of the selected file in KB.</dd>
|
||||||
</dl>
|
</dl>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -25,13 +25,13 @@
|
|||||||
padding: 4px;
|
padding: 4px;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<title></title>
|
<title>Parser</title>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<h1></h1>
|
<h1>Parser</h1>
|
||||||
|
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href = "#_declarations">Declarations</a></li>
|
<li><a href = "#_declarations">Declarations</a></li>
|
||||||
@ -39,7 +39,95 @@
|
|||||||
<li><a href = "#_detail">Function Detail</a></li>
|
<li><a href = "#_detail">Function Detail</a></li>
|
||||||
</ul>
|
</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 <head>~<body>~<tail>; 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>
|
<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>
|
</dl>
|
||||||
|
|
||||||
|
|
||||||
@ -59,7 +147,7 @@ See <a href = "#Parser">Parser</a>.
|
|||||||
<h3>struct Files</h3>
|
<h3>struct Files</h3>
|
||||||
<pre><b>struct Files</b></pre>
|
<pre><b>struct Files</b></pre>
|
||||||
<p>
|
<p>
|
||||||
Dependancy on <em>Files</em>
|
Dependancy on <em>Files</em>.
|
||||||
</p>
|
</p>
|
||||||
<dl>
|
<dl>
|
||||||
</dl>
|
</dl>
|
||||||
@ -69,7 +157,7 @@ Dependancy on <em>Files</em>
|
|||||||
<h3>typedef int (*ParserWidget)(struct Files *const files, FILE *const fp)</h3>
|
<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>
|
<pre><b>typedef int (*ParserWidget)(struct Files *const files, FILE *const fp)</b></pre>
|
||||||
<p>
|
<p>
|
||||||
All <em>ParserWidget</em>s are in <em>Widget.c</em>
|
All <em>ParserWidget</em>s are in <em>Widget.c</em>.
|
||||||
</p>
|
</p>
|
||||||
<dl>
|
<dl>
|
||||||
</dl>
|
</dl>
|
||||||
|
@ -25,13 +25,13 @@
|
|||||||
padding: 4px;
|
padding: 4px;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<title>Parser</title>
|
<title>Recursor</title>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<h1>Parser</h1>
|
<h1>Recursor</h1>
|
||||||
|
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href = "#_declarations">Declarations</a></li>
|
<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
|
GNU General Public License, see copying.txt
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<em>MakeIndex</em> is a simple content management system that generates static
|
<em>Recusor</em> is the main part of <em>MakeIndex</em>, a content management system that
|
||||||
content, (mostly index.html,) on all the directories rooted at the directory
|
generates static content, (mostly index.html,) on all the directories rooted
|
||||||
specified by the argument. It is based on a template file, ".index.html" and
|
at the directory specified by the argument. It is based on a template file,
|
||||||
".newsfeed.rss". Also included are files to summarise the directory structure
|
".index.html" and ".newsfeed.rss". Also included are files to summarise the
|
||||||
for a <em>xml</em> site map, compatible with Google, and any <em>.news</em> for an <em>rss</em>
|
directory structure for a <em>xml</em> site map, compatible with Google, and any
|
||||||
feed. It takes one argument, <directory>, which is the root of the recursion.
|
<em>.news</em> for an <em>rss</em> feed.
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
There should be an <example> directory that has a bunch of files in it. Run
|
There should be an <example> 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>
|
</p>
|
||||||
<dl>
|
<dl>
|
||||||
<dt>minimum standard</dt>
|
<dt>minimum standard</dt>
|
||||||
<dd>POSIX</dd>
|
<dd>POSIX.1</dd>
|
||||||
<dt>author</dt>
|
<dt>author</dt>
|
||||||
<dd>Neil</dd>
|
<dd>Neil</dd>
|
||||||
<dt>version</dt>
|
<dt>version</dt>
|
||||||
@ -117,7 +117,7 @@ If this is not the case, the constants are in <em>Files.c</em>.
|
|||||||
<dt>fixme</dt>
|
<dt>fixme</dt>
|
||||||
<dd>Have a subset of LaTeX converted into html for the .d files?</dd>
|
<dd>Have a subset of LaTeX converted into html for the .d files?</dd>
|
||||||
<dt>fixme</dt>
|
<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>
|
<dt>fixme</dt>
|
||||||
<dd>It's not robust; eg @(files)<em>@(files){Don't do this.}</em>.</dd>
|
<dd>It's not robust; eg @(files)<em>@(files){Don't do this.}</em>.</dd>
|
||||||
</dl>
|
</dl>
|
||||||
@ -146,15 +146,13 @@ See <a href = "#Recursor">Recursor</a>.
|
|||||||
<td>const char *idx, const char *map, const char *news</td>
|
<td>const char *idx, const char *map, const char *news</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>int</td>
|
<td>void</td>
|
||||||
<td><a href = "#RecursorGo">RecursorGo</a></td>
|
<td><a href = "#Recursor_">Recursor_</a></td>
|
||||||
<td>void</td>
|
<td>void</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>}
|
<td>int</td>
|
||||||
|
<td><a href = "#RecursorGo">RecursorGo</a></td>
|
||||||
static void</td>
|
|
||||||
<td><a href = "#usage">usage</a></td>
|
|
||||||
<td>void</td>
|
<td>void</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
@ -175,6 +173,16 @@ static void</td>
|
|||||||
</dl>
|
</dl>
|
||||||
</div>
|
</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>
|
<div><a name = "RecursorGo"><!-- --></a>
|
||||||
<h3>RecursorGo</h3>
|
<h3>RecursorGo</h3>
|
||||||
<pre>int <b>RecursorGo</b> (void)</pre>
|
<pre>int <b>RecursorGo</b> (void)</pre>
|
||||||
@ -185,18 +193,6 @@ Actually does the recursion.
|
|||||||
</dl>
|
</dl>
|
||||||
</div>
|
</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>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -25,13 +25,13 @@
|
|||||||
padding: 4px;
|
padding: 4px;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<title></title>
|
<title>Widget</title>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<h1></h1>
|
<h1>Widget</h1>
|
||||||
|
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href = "#_declarations">Declarations</a></li>
|
<li><a href = "#_declarations">Declarations</a></li>
|
||||||
@ -39,7 +39,37 @@
|
|||||||
<li><a href = "#_detail">Function Detail</a></li>
|
<li><a href = "#_detail">Function Detail</a></li>
|
||||||
</ul>
|
</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>
|
<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>
|
</dl>
|
||||||
|
|
||||||
|
|
||||||
|
21
src/Files.c
21
src/Files.c
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
@title Files
|
@title Files
|
||||||
@author Neil
|
@author Neil
|
||||||
@std POSIX
|
@std POSIX.1
|
||||||
@version 1.1; 2017-03 fixed pedantic warnings; command-line improvements
|
@version 1.1; 2017-03 fixed pedantic warnings; command-line improvements
|
||||||
@since 0.6; 2008-03-24 */
|
@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;
|
if(!de->d_name || (filter && !filter(files, de->d_name))) continue;
|
||||||
/* get status of the file */
|
/* get status of the file */
|
||||||
if(stat(de->d_name, &st)) { perror(de->d_name); continue; }
|
if(stat(de->d_name, &st)) { perror(de->d_name); continue; }
|
||||||
/* get the File(name, size) */
|
/* get the File(name, size) (in KB) */
|
||||||
file = File(de->d_name, ((int)st.st_size + 512) >> 10, S_ISDIR(st.st_mode));
|
file = File(de->d_name,
|
||||||
|
((int)st.st_size + 512) >> 10, S_ISDIR(st.st_mode));
|
||||||
if(!file) error = -1;
|
if(!file) error = -1;
|
||||||
/* put it in the appropreate spot */
|
/* put it in the appropreate spot */
|
||||||
if(file->isDir) {
|
if(file->isDir) {
|
||||||
@ -91,7 +92,8 @@ struct Files *Files(struct Files *const parent, const FilesFilter filter) {
|
|||||||
if(!FileInsert(file, &files->firstFile)) error = -1;
|
if(!FileInsert(file, &files->firstFile)) error = -1;
|
||||||
}
|
}
|
||||||
/* error */
|
/* 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); }
|
if(closedir(dir)) { perror(dir_current); }
|
||||||
return files;
|
return files;
|
||||||
@ -136,7 +138,7 @@ void FilesSetPath(struct Files *f) {
|
|||||||
for( ; f->parent; f = f->parent) f->parent->favourite = 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) {
|
const char *FilesEnumPath(struct Files *const files) {
|
||||||
struct Files *f = files;
|
struct Files *f = files;
|
||||||
const char *name;
|
const char *name;
|
||||||
@ -154,7 +156,7 @@ const char *FilesName(const struct Files *const files) {
|
|||||||
return files->this->name;
|
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) {
|
int FilesSize(const struct Files *files) {
|
||||||
if(!files || !files->this) return 0;
|
if(!files || !files->this) return 0;
|
||||||
return files->this->size;
|
return files->this->size;
|
||||||
@ -197,8 +199,11 @@ static void File_(struct File *file) {
|
|||||||
static int FileInsert(struct File *file, struct File **startAddr) {
|
static int FileInsert(struct File *file, struct File **startAddr) {
|
||||||
struct File *start;
|
struct File *start;
|
||||||
struct File *prev = 0, *ptr = 0;
|
struct File *prev = 0, *ptr = 0;
|
||||||
if(!file || !startAddr) { fprintf(stderr, "File::insert: file is null, not included.\n"); return 0; }
|
if(!file || !startAddr)
|
||||||
if(file->next) { fprintf(stderr, "File::insert: <%s> is already in some other list!\n", file->name); return 0; }
|
{ 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;
|
start = (struct File *)*startAddr;
|
||||||
/* 'prev' is where to insert; 'ptr' is next node */
|
/* 'prev' is where to insert; 'ptr' is next node */
|
||||||
for(prev = 0, ptr = start; ptr; prev = ptr, ptr = ptr->next) {
|
for(prev = 0, ptr = start; ptr; prev = ptr, ptr = ptr->next) {
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
/** See \see{Files}. */
|
/** See \see{Files}. */
|
||||||
struct Files;
|
struct Files;
|
||||||
|
|
||||||
/** Returns a boolean value. */
|
/** Returns a boolean value on whether {files} should include {file}. */
|
||||||
typedef int (*FilesFilter)(struct Files *const, const char *);
|
typedef int (*FilesFilter)(struct Files *const files, const char *file);
|
||||||
|
|
||||||
struct Files *Files(struct Files *const parent, const FilesFilter filter);
|
struct Files *Files(struct Files *const parent, const FilesFilter filter);
|
||||||
void Files_(struct Files *files);
|
void Files_(struct Files *files);
|
||||||
|
@ -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
|
GNU General Public License, see copying.txt
|
||||||
|
|
||||||
Parsing of strings. '~' on a line by itself is recognised in ".newsfile.rss"
|
Parsing of strings. '~' on a line by itself is recognised in ".newsfile.rss"
|
||||||
@ -7,11 +7,12 @@
|
|||||||
Parsed in ".index.html",
|
Parsed in ".index.html",
|
||||||
|
|
||||||
* @(content) prints {content.d}, or, if it is missing, {index.d};
|
* @(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;
|
argument;
|
||||||
* @(htmlcontent);
|
* @(htmlcontent);
|
||||||
* @(pwd){} prints the directory, the argument is the separator; eg, @(pwd){/};
|
* @(pwd)\{} prints the directory, the argument is the separator;
|
||||||
* @(root){}, like @(pwd), except up instead of down;
|
eg, @(pwd)\{/};
|
||||||
|
* @(root)\{}, like @(pwd), except up instead of down;
|
||||||
* @(now) prints the date and the time in UTC.
|
* @(now) prints the date and the time in UTC.
|
||||||
|
|
||||||
Further parsed in @(files){} in ".index.html",
|
Further parsed in @(files){} in ".index.html",
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
/** See \see{Parser}. */
|
/** See \see{Parser}. */
|
||||||
struct Parser;
|
struct Parser;
|
||||||
|
|
||||||
/** Dependancy on {Files} */
|
/** Dependancy on {Files}. */
|
||||||
struct 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);
|
typedef int (*ParserWidget)(struct Files *const files, FILE *const fp);
|
||||||
|
|
||||||
struct Parser *Parser(char *const str);
|
struct Parser *Parser(char *const str);
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
/** 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
|
GNU General Public License, see copying.txt
|
||||||
|
|
||||||
{MakeIndex} is a simple content management system that generates static
|
{Recusor} is the main part of {MakeIndex}, a content management system that
|
||||||
content, (mostly index.html,) on all the directories rooted at the directory
|
generates static content, (mostly index.html,) on all the directories rooted
|
||||||
specified by the argument. It is based on a template file, ".index.html" and
|
at the directory specified by the argument. It is based on a template file,
|
||||||
".newsfeed.rss". Also included are files to summarise the directory structure
|
".index.html" and ".newsfeed.rss". Also included are files to summarise the
|
||||||
for a {xml} site map, compatible with Google, and any {.news} for an {rss}
|
directory structure for a {xml} site map, compatible with Google, and any
|
||||||
feed. It takes one argument, <directory>, which is the root of the recursion.
|
{.news} for an {rss} feed.
|
||||||
|
|
||||||
There should be an <example> directory that has a bunch of files in it. Run
|
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
|
{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.
|
and '/' is the directory separator; works for UNIX, MacOS, Windows.
|
||||||
If this is not the case, the constants are in {Files.c}.
|
If this is not the case, the constants are in {Files.c}.
|
||||||
|
|
||||||
@title Parser
|
@title Recursor
|
||||||
@author Neil
|
@author Neil
|
||||||
@std POSIX
|
@std POSIX.1
|
||||||
@version 1.1; 2017-03 fixed pedantic warnings; command-line improvements
|
@version 1.1; 2017-03 fixed pedantic warnings; command-line improvements
|
||||||
@since 1.0; 2016-09-19 Added umask
|
@since 1.0; 2016-09-19 Added umask
|
||||||
0.8; 2013-07 case-insensitive sort
|
0.8; 2013-07 case-insensitive sort
|
||||||
@ -45,7 +45,7 @@
|
|||||||
0.6; 2008-03-27
|
0.6; 2008-03-27
|
||||||
@fixme Don't have <directory> be an argument; just do it in the current.
|
@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 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.}}. */
|
@fixme It's not robust; eg @(files){@(files){Don't do this.}}. */
|
||||||
|
|
||||||
#include <stdlib.h> /* malloc free fgets */
|
#include <stdlib.h> /* malloc free fgets */
|
||||||
@ -66,7 +66,7 @@ static const int version_minor = 1;
|
|||||||
|
|
||||||
static const size_t granularity = 1024;
|
static const size_t granularity = 1024;
|
||||||
static const int max_read = 0x1000;
|
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 *xml_sitemap = "sitemap.xml";
|
||||||
static const char *rss_newsfeed = "newsfeed.rss";
|
static const char *rss_newsfeed = "newsfeed.rss";
|
||||||
static const char *template_index = ".index.html";
|
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;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Destructor. */
|
||||||
void Recursor_(void) {
|
void Recursor_(void) {
|
||||||
if(!r) return;
|
if(!r) return;
|
||||||
if(r->sitemapParser && r->sitemap) {
|
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 "
|
fprintf(stderr, "Opened '%s' and alloted %lu bytes to read %lu "
|
||||||
"characters.\n", filename, bufSize, bufPos);
|
"characters.\n", filename, bufSize, bufPos);
|
||||||
if(fclose(fp)) perror(filename);
|
if(fclose(fp)) perror(filename);
|
||||||
return buf; /** you must free() the memory! */
|
return buf; /* you must free() the memory! */
|
||||||
}
|
}
|
||||||
|
|
||||||
static void usage(void) {
|
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"
|
"Version %d.%d.\n\n"
|
||||||
"MakeIndex is a content management system that generates static\n"
|
"MakeIndex is a content management system that generates static\n"
|
||||||
"content, (mostly index.html,) on all the directories rooted at the\n"
|
"content, (mostly index.html,) on all the directories rooted at the\n"
|
||||||
"<directory> based on <%s>.\n\n"
|
"<directory> based on <%s>.\n\n"
|
||||||
"It also does some other stuff. See readme.txt or\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);
|
version_major, version_minor, template_index);
|
||||||
fprintf(stderr, "MakeIndex Copyright 2008, 2012 Neil Edelman\n"
|
fprintf(stderr, "MakeIndex Copyright 2008, 2012 Neil Edelman\n"
|
||||||
"This program comes with ABSOLUTELY NO WARRANTY.\n"
|
"This program comes with ABSOLUTELY NO WARRANTY.\n"
|
||||||
@ -317,18 +328,54 @@ int main(int argc, char **argv) {
|
|||||||
is_help = -1;
|
is_help = -1;
|
||||||
} else if(!strcmp("--directory", av) || !strcmp("-d", av)) {
|
} else if(!strcmp("--directory", av) || !strcmp("-d", av)) {
|
||||||
if(directory) {
|
if(directory) {
|
||||||
break;
|
is_invalid = -1; break;
|
||||||
} else if(++ac < argc) {
|
} else if(++ac < argc) {
|
||||||
directory = argv[ac];
|
directory = argv[ac];
|
||||||
} else {
|
} else {
|
||||||
is_invalid = -1; break;
|
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) {
|
if(is_help || !directory) {
|
||||||
usage();
|
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);
|
fprintf(stderr, "Changing directory to <%s>.\n", directory);
|
||||||
|
@ -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
|
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};
|
* stick the code below implementing {ParserWidget};
|
||||||
* create a prototype in Widget.h;
|
* create a prototype in Widget.h;
|
||||||
* in {Parser.c}, add to the symbol table, sym[] with the symbol you want, in
|
* in {Parser.c}, add to the symbol table, sym[] with the symbol you want, in
|
||||||
ASCIIbetical order.
|
ASCIIbetical order.
|
||||||
|
|
||||||
|
See Parser for more information.
|
||||||
|
|
||||||
@title Widget
|
@title Widget
|
||||||
@author Neil
|
@author Neil
|
||||||
@std C89/90
|
@std POSIX.1
|
||||||
@version 1.1; 2017-03 fixed pedantic warnings; command-line improvements
|
@version 1.1; 2017-03 fixed pedantic warnings; command-line improvements
|
||||||
@since 0.6; 2008-03-25 */
|
@since 0.6; 2008-03-25 */
|
||||||
|
|
||||||
@ -46,7 +48,6 @@ const char *dot_desc = ".d"; /* used in multiple files */
|
|||||||
const char *dot_news = ".news";
|
const char *dot_news = ".news";
|
||||||
extern const char *dir_current;
|
extern const char *dir_current;
|
||||||
extern const char *dir_parent;
|
extern const char *dir_parent;
|
||||||
extern const char *html_index;
|
|
||||||
|
|
||||||
/* global, ick: news */
|
/* global, ick: news */
|
||||||
static int year = 1983;
|
static int year = 1983;
|
||||||
|
Loading…
Reference in New Issue
Block a user