commit c6923b35940e47b54d8c472fb0ed4f0baaeac823 Author: Neil Edelman Date: Sun Sep 11 02:40:29 2016 -0400 New version control using git. diff --git a/Files.c b/Files.c new file mode 100644 index 0000000..b9e5069 --- /dev/null +++ b/Files.c @@ -0,0 +1,194 @@ +/* Copyright 2008, 2012 Neil Edelman, distributed under the terms of the + GNU General Public License, see copying.txt */ + +/* Files is a list of File (private class defiend below,) the Files can have + * a relation to other Files by 'parent' and 'favourite' (@(pwd) uses this.) + * Created by Neil Edelman on 2008-03-24. */ + +#include /* malloc free */ +#include /* fprintf */ +#include /* strcmp strstr */ +#include /* opendir readdir closedir */ +#include /* fstat */ +#include "Files.h" + +/* constants */ +const char *dirCurrent = "."; /* used in multiple files */ +const char *dirParent = ".."; +static const int maxFilename = 128; + +/* public */ +struct Files { + struct Files *parent; /* the parent, could be 0 */ + struct Files *favourite; /* temp var used to access a certain child */ + struct File *file; /* THIS dir, could be 0 if it's home */ + struct File *firstFile; /* the Files in this dir */ + struct File *firstDir; /* the Files in this dir that are dirs */ + struct File *this; /* temp var, one of the firstDir, firstFile list */ +}; +/* private */ +struct File { + struct File *next; + char *name; + int size; + int isDir; +}; + +/* private */ +struct File *File(const char *name, const int size, const int isDir); +void File_(struct File *file); +int FileInsert(struct File *file, struct File **startAddr); + +/* Alert! parent->this must be the 'file' (directory) that you want to create */ +struct Files *Files(const struct Files *parent, int (*filter)(const struct Files *, const char *)) { + char *dirName; + struct dirent *de; + struct stat st; + struct File *file; + struct Files *files; + DIR *dir; + if(parent && !parent->this) { fprintf(stderr, "Files: tried creating a directory without selecting a file (parent->this.)\n"); return 0; } + files = malloc(sizeof(struct Files)); + if(!files) { perror("files"); Files_(files); return 0; } + /* does not check for recusive dirs - assumes that it is a tree */ + files->parent = (struct Files *)parent; + files->favourite = 0; + files->file = parent ? parent->this : 0; + files->firstFile = 0; + files->firstDir = 0; + files->this = 0; + /* print path on stderr */ + FilesSetPath(files); + fprintf(stderr, "Files: directory <"); + while((dirName = FilesEnumPath(files))) fprintf(stderr, "%s/", dirName); + fprintf(stderr, ">.\n"); + /* read the current dir */ + dir = opendir(dirCurrent); + if(!dir) { perror(dirParent); Files_(files); return 0; } + while((de = readdir(dir))) { + int error = 0; + /* ignore certain files, incomplete 'files'! -> Recusor.c */ + 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)); + if(!file) error = -1; + /* put it in the appropreate spot */ + if(file->isDir) { + if(!FileInsert(file, &files->firstDir)) error = -1; + } else { + 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(closedir(dir)) { perror(dirCurrent); } + return files; +} +void Files_(struct Files *files) { + if(!files) return; + File_(files->firstDir); /* cascading delete */ + File_(files->firstFile); + free(files); +} +/* this is how we used to access files before 'invisiblity' + if((f->this)) return f->this->next ? -1 : f->firstFile ? -1 : 0; + if((f->this)) return f->this->next ? -1 : 0; */ +/* this is how we access the files sequentially */ +int FilesAdvance(struct Files *f) { + static enum { files, dirs } type = dirs; + if(!f) return 0; + switch(type) { + case dirs: + if(!f->this) f->this = f->firstDir; + else f->this = f->this->next; + if((f->this)) return -1; + type = files; + case files: + if(!f->this) f->this = f->firstFile; + else f->this = f->this->next; + if((f->this)) return -1; + type = dirs; + } + return 0; +} +/* doesn't have a parent */ +int FilesIsRoot(const struct Files *f) { + if(!f) return 0; + return (f->parent) ? 0 : -1; +} +/* resets the list of favourites */ +void FilesSetPath(struct Files *f) { + if(!f) return; + for( ; f->parent; f = f->parent) f->parent->favourite = f; +} +/* after FilesSetFarourite, this enumerates them */ +char *FilesEnumPath(struct Files *f) { + char *name; + if(!f) return 0; + for( ; f->parent && f->parent->favourite; f = f->parent); + if(!f->favourite) return 0; /* clear favourite, done */ + name = f->favourite->file ? f->favourite->file->name : "(wtf?)"; + f->favourite = 0; + return name; +} + +/* takes from files->this */ +char *FilesName(const struct Files *files) { + if(!files || !files->this) return 0; + return files->this->name; +} +int FilesSize(const struct Files *files) { + if(!files || !files->this) return 0; + return files->this->size; +} +int FilesIsDir(const struct Files *files) { + if(!files || !files->this) return 0; + return files->this->isDir; +} + +/* this is just a list of filenames, (not public) "class File" */ + +struct File *File(const char *name, const int size, const int isDir) { + int len; + struct File *file; + if(!name || !*name) { fprintf(stderr, "File: file has no name.\n"); return 0; } + if((len = strlen(name)) > maxFilename) { fprintf(stderr, "File: file name \"%s\" is too long (%d.)\n", name, maxFilename); return 0; } + file = malloc(sizeof(struct File) + (len + 1)); + if(!file) { File_(file); return 0; } + file->next = 0; + file->name = (char *)(file + 1); + strncpy(file->name, name, len + 1); + file->size = size; + file->isDir = isDir; + /* fprintf(stderr, " File(\"%s\" %p)\n", file->name, (void *)file); debug . . . caught bug! */ + return file; +} +void File_(struct File *file) { + struct File *next; + /* delete ALL the list of files (not just the one) */ + for( ; file; file = next) { + next = file->next; + /* fprintf(stderr, " File~(\"%s\" %p)...", file->name, (void *)file); fflush(stderr); debug */ + free(file); + } +} +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; } + start = (struct File *)*startAddr; + /* 'prev' is where to insert; 'ptr' is next node */ + for(prev = 0, ptr = start; ptr; prev = ptr, ptr = ptr->next) { + /* ansi doesn't have stricmp; strcasecmp not working? + #define _XOPEN_SOURCE_EXTENDED? or just use strcmp */ + if(strcasecmp(file->name, ptr->name) <= 0) break; + } + file->next = ptr; + if(!prev) start = file; + else prev->next = file; + *startAddr = start; + return -1; +} diff --git a/Files.h b/Files.h new file mode 100644 index 0000000..6cdd2e5 --- /dev/null +++ b/Files.h @@ -0,0 +1,12 @@ +struct Files; +struct Recursor; + +struct Files *Files(const struct Files *parent, int (*filter)(const struct Files *, const char *)); +void Files_(struct Files *files); +int FilesAdvance(struct Files *files); +int FilesIsRoot(const struct Files *f); +void FilesSetPath(struct Files *files); +char *FilesEnumPath(struct Files *files); +char *FilesName(const struct Files *files); +int FilesSize(const struct Files *files); +int FilesIsDir(const struct Files *files); diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..1d0e477 --- /dev/null +++ b/Makefile @@ -0,0 +1,59 @@ +# Tested on MacOSX, GNU bash version 4.2.0(1)-release (x86_64--netbsd) +# x86_64--netbsd make (?) doesn't have all the tricks + +PROJ := MakeIndex +VA := 0 +VB := 8 +FILES := Recursor Parser Widget Files +BDIR := bin +BACK := backup +INST := $(PROJ)-$(VA)_$(VB) +OBJS := $(patsubst %,$(BDIR)/%.o,$(FILES)) +SRCS := $(patsubst %,%.c,$(FILES)) +H := $(patsubst %,%.h,$(FILES)) +OBJS := bin/Recursor.o bin/Parser.o bin/Widget.o bin/Files.o + +CC := gcc +CF := -Wall -O3 -fasm -fomit-frame-pointer -ffast-math -funroll-loops -pedantic -ansi # not ansi! but compiles; POSIX? + +default: $(BDIR)/$(PROJ) + +$(BDIR)/$(PROJ): $(OBJS) + $(CC) $(CF) -o $@ $(OBJS) +# $(CC) $(CF) -o $@ $^ + +$(BDIR)/%.o: %.c + @mkdir -p $(BDIR) + $(CC) $(CF) -c $? -o $@ + +$(BDIR)/Recursor.o: Recursor.c + @mkdir -p $(BDIR) + $(CC) $(CF) -c $? -o $@ + +$(BDIR)/Parser.o: Parser.c + @mkdir -p $(BDIR) + $(CC) $(CF) -c $? -o $@ + +$(BDIR)/Widget.o: Widget.c + @mkdir -p $(BDIR) + $(CC) $(CF) -c $? -o $@ + +$(BDIR)/Files.o: Files.c + @mkdir -p $(BDIR) + $(CC) $(CF) -c $? -o $@ + +.PHONY: clean backup +clean: + -rm $(OBJS) + +backup: + @mkdir -p $(BACK) + zip $(BACK)/$(INST)-`date +%Y-%m-%dT%H%M%S`.zip readme.txt gpl.txt copying.txt Makefile Makefile.mingw $(SRCS) $(H) -r $(BDIR)/example/ + +setup: $(BDIR)/$(PROJ) + @mkdir -p $(BDIR)/$(INST) + cp $(BDIR)/$(PROJ) readme.txt gpl.txt copying.txt $(BDIR)/$(INST) + cp -R $(BDIR)/example $(BDIR)/$(INST) + rm -f $(BDIR)/$(INST).dmg + hdiutil create $(BDIR)/$(INST).dmg -volname "MakeIndex $(VA).$(VB)" -srcfolder $(BDIR)/$(INST) + rm -R $(BDIR)/$(INST) diff --git a/Makefile.mingw b/Makefile.mingw new file mode 100644 index 0000000..257186f --- /dev/null +++ b/Makefile.mingw @@ -0,0 +1,37 @@ +# Windows port cross-compiling with MacOSX MinGW 4.3.0 +# (good luck) + +PROJ := MakeIndex +VA := 0 +VB := 8 +FILES := Recursor Parser Widget Files +BDIR := win +BACK := backup +EXE := $(PROJ).exe +INST := $(PROJ)-$(VA)_$(VB) +OBJS := $(patsubst %,$(BDIR)/%.o,$(FILES)) +SRCS := $(patsubst %,%.c,$(FILES)) +H := $(patsubst %,%.h,$(FILES)) + +CC := /usr/local/i386-mingw32-4.3.0/bin/i386-mingw32-gcc +CF := -Wall -O3 -fasm -fomit-frame-pointer -ffast-math -funroll-loops -pedantic -ansi + +default: $(BDIR)/$(EXE) + +$(BDIR)/$(EXE): $(OBJS) + $(CC) $(CF) -o $@ $^ + +$(BDIR)/%.o: %.c + @mkdir -p $(BDIR) + $(CC) $(CF) -c $? -o $@ + +.PHONY: clean backup +clean: + -rm $(OBJS) + +setup: $(BDIR)/$(EXE) + @mkdir -p $(INST) + cp $(BDIR)/$(EXE) readme.txt gpl.txt copying.txt $(INST) + cp -a bin/example $(INST) + zip $(BDIR)/$(INST)-Win32-`date +%Y-%m-%dT%H%M%S` $(INST)/$(EXE) -r $(INST) + rm -R $(INST) diff --git a/Parser.c b/Parser.c new file mode 100644 index 0000000..c400116 --- /dev/null +++ b/Parser.c @@ -0,0 +1,137 @@ +/* Copyright 2008, 2012 Neil Edelman, distributed under the terms of the + GNU General Public License, see copying.txt */ + +/* Parsing of strings. + * Created by Neil Edelman on 2008-03-21. */ + +#include /* [f]printf FILE */ +#include /* malloc */ +#include /* strstr, strpbrk */ +#include "Widget.h" +#include "Parser.h" + +/* private */ +static const int maxRecursion = 16; + +/* public */ +struct Parser { + char *str; + char *pos; + char *rew; + int recursion; +}; +/* private - this is the list of 'widgets', see Widget.c - add widgets to here + to make them recognised - ASCIIbetical */ +struct Symbol { + char *symbol; + int (*handler)(const struct Files *, FILE *fp); + int onlyInRoot; /* fixme: not used, just trust the users? haha */ +} static const sym[] = { + { "content", &WidgetContent, 0 }, /* index */ + { "date", &WidgetDate, 0 }, /* news */ + { "filealt", &WidgetFilealt, 0 }, /* files */ + { "filedesc", &WidgetFiledesc, 0 }, /* files */ + { "filehref", &WidgetFilehref, 0 }, /* files */ + { "fileicon", &WidgetFileicon, 0 }, /* files */ + { "filename", &WidgetFilename, 0 }, /* files */ + { "files", &WidgetFiles, -1 }, /* index */ + { "filesize", &WidgetFilesize, 0 }, /* files */ + /*{ "folder", 0, -1 }, *//* replaced by ~ - scetchy */ + { "htmlcontent",&WidgetContent,0 }, /* index */ + { "news", &WidgetNews, 0 }, /* news */ + { "newsname", &WidgetNewsname, 0 }, /* news */ + { "now", &WidgetNow, 0 }, /* any */ + { "pwd", &WidgetPwd, -1 }, /* don't put it where it doesn't make sense */ + { "root", &WidgetRoot, -1 }, /* like pwd exept up instead of dn */ + { "title", &WidgetTitle, 0 } /* news */ +}; + +/* private */ +int parse(struct Parser *p, int invisible, FILE *fp); + +struct Parser *Parser(const char *str) { + struct Parser *p; + p = malloc(sizeof(struct Parser)); + p->str = (char *)str; + p->pos = p->str; + p->rew = p->str; + p->recursion = 0; + return p; +} +void Parser_(struct Parser *p) { + if(!p) return; + if(p->recursion) fprintf(stderr, "Parser~: a file was closed with recursion level of %d; syntax error?\n", p->recursion); + free(p); +} + +/** binary search */ +const struct Symbol *match(const char *str, const char *end) { + const int N = sizeof(sym) / sizeof(struct Symbol); + int a, lenMatch, lenComp, lo = 0, mid, hi = N - 1; + lenMatch = end - str; + while(lo <= hi) { + mid = (lo + hi) >> 1; + /* this is highly inefficient */ + lenComp = strlen(sym[mid].symbol); + a = strncmp(str, sym[mid].symbol, lenMatch > lenComp ? lenMatch : lenComp); + if (a < 0) hi = mid - 1; + else if(a > 0) lo = mid + 1; + else return &sym[mid]; + } + return 0; +} +void ParserRewind(struct Parser *p) { + if(!p) return; + p->pos = p->rew; +} +/** parse, called recusively (invisible, hack) fixme: this fn needs rewriting, messy */ +int ParserParse(struct Parser *p, const struct Files *f, int invisible, FILE *fp) { + char *mark; + if(!p || !fp || !p->pos) return 0; + if(++p->recursion > maxRecursion) fprintf(stderr, "Parser::parse: %d recursion levels reached (Ctrl-C to stop!)\n", p->recursion); + mark = p->pos; + if(p->recursion == 1) p->rew = mark; + for( ; ; ) { + p->pos = strpbrk(p->pos, "@}~"); + if(!p->pos) { + if(!invisible) fprintf(fp, "%.*s", (int)(p->pos - mark), mark); + break; + } else if(*p->pos == '}') { + if(!invisible) fprintf(fp, "%.*s", (int)(p->pos - mark), mark); + p->pos++; + break; + } else if(*p->pos == '~') { + /* a tilde on a line by itself */ + if(p->recursion == 1 && + ((p->pos <= p->str || *(p->pos - 1) == '\n') && + *(p->pos + 1) == '\n')) { + if(!invisible) fprintf(fp, "%.*s", (int)(p->pos - mark), mark); + p->pos += 2; /* "~\n" */ + p->recursion = 0; + return -1; + } + p->pos++; + } else if(*(p->pos + 1) == '(') { /* the only one left is @ */ + const struct Symbol *m; + int over = 0, open; + char *start = p->pos + 2, *end; + if(!invisible) fprintf(fp, "%.*s", (int)(p->pos - mark), mark); + if(!(end = strpbrk(start, ")"))) break; /* syntax error */ + if(!(m = match(start, end))) fprintf(stderr, "Parser::parse: symbol not reconised, '%.*s.'\n", (int)(end - start), start); + /* if(p->recursion == 1 && m && m->onlyInRoot) return -1; ? */ + open = *(end + 1) == '{' ? -1 : 0; + do { + /* -> widget.c */ + if(m && m->handler && !invisible) over = m->handler(f, fp); + p->pos = end + (open ? 2 : 1); + /* recurse between {} */ + if(open) ParserParse(p, f, invisible || !over, fp); + } while(over); + mark = p->pos; + } else { /* @ by itself */ + p->pos++; + } + } + p->recursion--; + return 0; +} diff --git a/Parser.h b/Parser.h new file mode 100644 index 0000000..9baf1e8 --- /dev/null +++ b/Parser.h @@ -0,0 +1,7 @@ +struct Parser; +struct Files; + +struct Parser *Parser(const char *str); +void Parser_(struct Parser *p); +void ParserRewind(struct Parser *p); +int ParserParse(struct Parser *p, const struct Files *f, int invisible, FILE *fp); diff --git a/Recursor.c b/Recursor.c new file mode 100644 index 0000000..d9dc529 --- /dev/null +++ b/Recursor.c @@ -0,0 +1,245 @@ +/* Copyright 2008, 2012 Neil Edelman, distributed under the terms of the + GNU General Public License, see copying.txt */ + +/* This is the main program. I didn't know what to call it. + * Created by Neil Edelman on 2008-03-27. */ + +#include /* malloc free fgets */ +#include /* fprintf FILE */ +#include /* strcmp */ +#include /* chdir (POSIX, not ANSI) */ +#include "Files.h" +#include "Widget.h" +#include "Parser.h" +#include "Recursor.h" + +/* public */ +struct Recursor { + char *indexString; + struct Parser *indexParser; /* depends on indexString */ + FILE *sitemap; + char *sitemapString; + struct Parser *sitemapParser; /* depends on sitemapString */ + FILE *newsfeed; + char *newsfeedString; + struct Parser *newsfeedParser; /* depends on newsfeedString */ +}; + +/* private */ +int filter(const struct Files *, const char *fn); +int recurse(const struct Files *parent); +char *readFile(const char *filename); +void usage(const char *programme); + +/* constants */ +static const int versionMajor = 0; +static const int versionMinor = 8; +static const int granularity = 1024; +static const int maxRead = 0x1000; +const char *htmlIndex = "index.html"; /* in multiple files */ +static const char *xmlSitemap = "sitemap.xml"; +static const char *rssNewsfeed = "newsfeed.rss"; +static const char *tmplIndex = ".index.html"; +static const char *tmplSitemap = ".sitemap.xml"; +static const char *tmplNewsfeed= ".newsfeed.rss"; +/* in Files.c */ +extern const char *dirCurrent; +extern const char *dirParent; +/* in Widget.c */ +extern const char *desc; +extern const char *news; + +/* there can only be one recursor at a time, sorry */ +static struct Recursor *r = 0; + +/* public */ +struct Recursor *Recursor(const char *index, const char *map, const char *news) { + if(!index || !index || !map || !news) return 0; + if(r) { fprintf(stderr, "Recursor: there is already a Recursor.\n"); return 0; } + r = malloc(sizeof(struct Recursor)); + if(!r) { perror("recursor"); Recursor_(); return 0; } + r->indexString = 0; + r->indexParser = 0; + r->sitemap = 0; + r->sitemapString = 0; + r->sitemapParser = 0; + r->newsfeed = 0; + r->newsfeedString = 0; + r->newsfeedParser = 0; + /* open the files for writing (index is opened multiple times in the directories) */ + if(!(r->sitemap = fopen(xmlSitemap, "w"))) perror(xmlSitemap); + if(!(r->newsfeed = fopen(rssNewsfeed, "w"))) perror(rssNewsfeed); + /* read from the input files */ + if( !(r->indexString = readFile(index))) { + fprintf(stderr, "Recursor: to make an index, create the file <%s>.\n", index); + } + if(r->sitemap && !(r->sitemapString = readFile(map))) { + fprintf(stderr, "Recursor: to make an sitemap, create the file <%s>.\n", map); + } + if(r->newsfeed && !(r->newsfeedString = readFile(news))) { + fprintf(stderr, "Recursor: to make a newsfeed, create the file <%s>.\n", news); + } + /* create Parsers attached to them */ + if(r->indexString && !(r->indexParser = Parser(r->indexString))) { + fprintf(stderr, "Recursor: error generating Parser from <%s>.\n", index); + } + if(r->sitemapString && !(r->sitemapParser = Parser(r->sitemapString))) { + fprintf(stderr, "Recursor: error generating Parser from <%s>.\n", map); + } + if(r->newsfeedString && !(r->newsfeedParser = Parser(r->newsfeedString))) { + fprintf(stderr, "Recursor: error generating Parser from <%s>.\n", news); + } + /* if theirs no content, we have nothing to do */ + if(!r->indexParser && !r->sitemapParser && !r->newsfeedParser) { + fprintf(stderr, "Recursor: no Parsers defined, it would be useless to continue.\n"); + Recursor_(); + return 0; + } + /* parse the "header," ie, everything up to ~, the second arg is null + because we haven't set up the Files, so @files{}, @pwd{}, etc are undefined */ + ParserParse(r->sitemapParser, 0, 0, r->sitemap); + ParserParse(r->newsfeedParser, 0, 0, r->newsfeed); + return r; +} +void Recursor_(void) { + if(!r) return; + if(r->sitemapParser && r->sitemap) { + ParserParse(r->sitemapParser, 0, -1, r->sitemap); + ParserParse(r->sitemapParser, 0, 0, r->sitemap); + } + if(r->sitemap && fclose(r->sitemap)) perror(xmlSitemap); + if(r->newsfeedParser && r->newsfeed) { + ParserParse(r->newsfeedParser, 0, -1, r->newsfeed); + ParserParse(r->newsfeedParser, 0, 0, r->newsfeed); + } + if(r->newsfeed && fclose(r->newsfeed)) perror(rssNewsfeed); + Parser_(r->indexParser); + free(r->indexString); + Parser_(r->sitemapParser); + free(r->sitemapString); + Parser_(r->newsfeedParser); + free(r->newsfeedString); + free(r); + r = 0; +} + +/* entry-point (shouldn't have a prototype) */ +int main(int argc, char **argv) { + int ret; + /* set up; fixme: dangerous! use stdarg, have a -delete, -write, and -help */ + if(argc <= 1) { usage(argv[0]); return EXIT_SUCCESS; } + fprintf(stderr, "Changing directory to <%s>.\n", argv[1]); + if(chdir(argv[1])) { perror(argv[1]); return EXIT_FAILURE; } + /* recursing; fixme: this should be configurable */ + if(!Recursor(tmplIndex, tmplSitemap, tmplNewsfeed)) return EXIT_FAILURE; + ret = recurse(0); + Recursor_(); + return ret ? EXIT_SUCCESS : EXIT_FAILURE; +} + +/* private */ + +int filter(const struct Files *files, const char *fn) { + char *str, filed[64]; + FILE *fd; + if(!r) { fprintf(stderr, "Recusor::filter: recursor not initialised.\n"); return 0; } + /* *.d[.0]* */ + for(str = (char *)fn; (str = strstr(str, desc)); ) { + str += strlen(desc); + if(*str == '\0' || *str == '.') return 0; + } + /* *.news$ */ + if((str = strstr(fn, news))) { + str += strlen(news); + if(*str == '\0') { + if(WidgetSetNews(fn) && ParserParse(r->newsfeedParser, files, 0, r->newsfeed)) { + ParserRewind(r->newsfeedParser); + } else { + fprintf(stderr, "Recursor::filter: error writing news <%s>.\n", fn); + } + return 0; + } + } + /* . */ + if(!strcmp(fn, dirCurrent)) return 0; + /* .. */ + if(!strcmp(fn, dirParent) && FilesIsRoot(files)) return 0; + /* index.html */ + if(!strcmp(fn, htmlIndex)) return 0; + /* add .d, check 1 line for \n (hmm, this must be a real time waster) */ + if(strlen(fn) > sizeof(filed) - strlen(desc) - 1) { + fprintf(stderr, "Recusor::filter: regected '%s' because it was too long (%d.)\n", fn, (int)sizeof(filed)); + return 0; + } + strcpy(filed, fn); + strcat(filed, desc); + if((fd = fopen(filed, "r"))) { + int ch = fgetc(fd); + if(ch == '\n' || ch == '\r' || ch == EOF) { + fprintf(stderr, "Recursor::filter: '%s' rejected.\n", fn); + return 0; + } + if(fclose(fd)) perror(filed); + } + return -1; +} +int recurse(const struct Files *parent) { + struct Files *f; + char *name; + FILE *fp; + f = Files(parent, &filter); + /* write the index */ + if((fp = fopen(htmlIndex, "w"))) { + ParserParse(r->indexParser, f, 0, fp); + ParserRewind(r->indexParser); + fclose(fp); + } else perror(htmlIndex); + /* sitemap */ + ParserParse(r->sitemapParser, f, 0, r->sitemap); + ParserRewind(r->sitemapParser); + /* recurse */ + while(FilesAdvance(f)) { + if(!FilesIsDir(f) || + !(name = FilesName(f)) || + !strcmp(dirCurrent, name) || + !strcmp(dirParent, name) || + !(name = FilesName(f))) continue; + if(chdir(name)) { perror(name); continue; } + recurse(f); + /* this happens on Windows; I don't know what to do */ + if(chdir(dirParent)) perror(dirParent); + } + Files_(f); + return -1; +} +char *readFile(const char *filename) { + char *buf = 0, *newBuf; + int bufPos = 0, bufSize = 0, read; + FILE *fp; + if(!filename) return 0; + if(!(fp = fopen(filename, "r"))) { perror(filename); return 0; } + for( ; ; ) { + newBuf = realloc(buf, (bufSize += granularity) * sizeof(char)); + if(!newBuf) { perror(filename); free(buf); return 0; } + buf = newBuf; + read = fread(buf + bufPos, sizeof(char), granularity, fp); + bufPos += read; + if(read < granularity) { buf[bufPos] = '\0'; break; } + } + fprintf(stderr, "Opened '%s' and alloted %d bytes to read %d characters.\n", filename, bufSize, bufPos); + if(fclose(fp)) perror(filename); + return buf; /** you must free() the memory! */ +} +void usage(const char *programme) { + fprintf(stderr, "Usage: %s \n\n", programme); + fprintf(stderr, "Version %d.%d.\n\n", versionMajor, versionMinor); + fprintf(stderr, "MakeIndex is a content generator that places a changing\n"); + fprintf(stderr, "index.html on all the directories under \n"); + fprintf(stderr, "based on a template file in called <%s>.\n", tmplIndex); + fprintf(stderr, "It also does some other stuff.\n\n"); + fprintf(stderr, "See readme.txt or http://neil.chaosnet.org/ for further info.\n\n"); + fprintf(stderr, "MakeIndex Copyright 2008, 2012 Neil Edelman\n"); + fprintf(stderr, "This program comes with ABSOLUTELY NO WARRANTY.\n"); + fprintf(stderr, "This is free software, and you are welcome to redistribute it\n"); + fprintf(stderr, "under certain conditions; see gpl.txt.\n\n"); +} diff --git a/Recursor.h b/Recursor.h new file mode 100644 index 0000000..0ee0e5c --- /dev/null +++ b/Recursor.h @@ -0,0 +1,4 @@ +struct Recursor; + +struct Recursor *Recursor(const char *index, const char *map, const char *news); +void Recursor_(void); diff --git a/Widget.c b/Widget.c new file mode 100644 index 0000000..4ae42bf --- /dev/null +++ b/Widget.c @@ -0,0 +1,226 @@ +/* Copyright 2008, 2012 Neil Edelman, distributed under the terms of the + GNU General Public License, see copying.txt */ + +/* Widgets like @files @pwd. How to create a widget? + 1. stick the code below, it's prototype must be the same, int(FILE *), where + the FILE* is called with the output file + 2. create a prototype in Widget.h + 3. in Parser.c, add to the symbol table, sym[] with the symbol you want, in + ASCIIbetical order + * Created by Neil Edelman on 2008-03-25. */ + +#include /* strncat strncpy */ +#include /* fprintf FILE */ +#include /* time gmtime - for @date */ +#include "Files.h" +#include "Parser.h" +#include "Recursor.h" +#include "Widget.h" + +/* constants */ +static const char *htmlDesc = "index.d"; +static const char *htmlContent = "content.d"; +static const char *separator = "/"; +static const char *picture = ".jpeg"; /* yeah, I hard coded this */ +static const size_t maxRead = 512; +static const char *link = ".link"; +const char *desc = ".d"; /* used in multiple files */ +const char *news = ".news"; +extern const char *dirCurrent; +extern const char *dirParent; +extern const char *htmlIndex; + +/* global, ick: news */ +static int year = 1983; +static int month = 1; +static int day = 30; +static char title[64] = "(no title)"; +static char filenews[64] = "(no file name)"; + +/* private */ +int correctNo(int no, const int low, const int high); + +int WidgetSetNews(const char *fn) { + char *dot; + int read, tLen; + FILE *fp; + if(!fn || !(dot = strstr(fn, news))) return 0; + if(strlen(fn) > sizeof(filenews) / sizeof(char) - sizeof(char)) { + fprintf(stderr, "Widget::SetNews: news file name, \"%s,\" doesn't fit in buffer (%d.)\n", fn, (int)(sizeof(filenews) / sizeof(char))); + return 0; + } + /* save the fn, safe because we checked it, and strip off .news */ + strcpy(filenews, fn); + filenews[dot - fn] = '\0'; + /* open .news */ + if(!(fp = fopen(fn, "r"))) { perror(fn); return 0; } + read = fscanf(fp, "%d-%d-%d\n", &year, &month, &day); + if(read < 3) fprintf(stderr, "Widget::setNews: error parsing ISO 8601 date, .\n"); + month = correctNo(month, 1, 12); + day = correctNo(day, 1, 31); + /* fgets reads a newline at the end (annoying) so we strip that off */ + if(!fgets(title, sizeof(title), fp)) { perror(fn); *title = '\0'; } + else if((tLen = strlen(title)) > 0 && title[tLen - 1] == '\n') title[tLen - 1] = '\0'; + if(fclose(fp)) perror(fn); + fprintf(stderr, "News <%s>, '%s' %d-%d-%d.\n", filenews, title, year, month, day); + return -1; +} + +/* the widget handlers */ +int WidgetContent(const struct Files *f, FILE *fp) { + char buf[81], *bufpos; + int i; + FILE *in; + /* it's a nightmare to test if this is text (which most is,) in which case + we should insert

...

after every paragraph, <>& -> <>&, + but we have to not translate already encoded html; the only solution that + a could see is have a new langauge (like-LaTeX) that gracefully handles + plain-text */ + if((in = fopen(htmlContent, "r")) || (in = fopen(htmlDesc, "r"))) { + for(i = 0; (i < maxRead) && (bufpos = fgets(buf, sizeof(buf), in)); i++) { + fprintf(fp, "%s", bufpos); + } + if(fclose(in)) perror(htmlDesc); + } + return 0; +} +int WidgetDate(const struct Files *f, FILE *fp) { + /* ISO 8601 - YYYY-MM-DD */ + fprintf(fp, "%4.4d-%2.2d-%2.2d", year, month, day); + return 0; +} +int WidgetFilealt(const struct Files *f, FILE *fp) { + fprintf(fp, "%s", FilesIsDir(f) ? "Dir" : "File"); + return 0; +} +int WidgetFiledesc(const struct Files *f, FILE *fp) { + char buf[256], *name; + FILE *in; + if(!(name = FilesName(f))) return 0; + if(FilesIsDir(f)) { + /* /index.d */ + strncpy(buf, name, sizeof(buf) - 9); + strncat(buf, separator, 1); + strncat(buf, htmlDesc, 7); + } else { + /* .d */ + strncpy(buf, name, sizeof(buf) - 6); + strncat(buf, desc, 5); + } + if((in = fopen(buf, "r"))) { + char *bufpos; + int i; + for(i = 0; (i < maxRead) && (bufpos = fgets(buf, sizeof(buf), in)); i++) { + fprintf(fp, "%s", bufpos); + } + if(fclose(in)) perror(buf); + } + return 0; +} +int WidgetFilehref(const struct Files *f, FILE *fp) { + char *str, *name; + int ch; + FILE *fhref; + if(!(name = FilesName(f))) return 0; + if((str = strstr(name, link)) && *(str += strlen(link)) == '\0' && (fhref = fopen(name, "r"))) { + /* fixme: not too good, with the reading one char at a time */ + for( ; ; ) { + ch = fgetc(fhref); + if(ch == '\n' || ch == '\r' || ch == EOF) break; + fprintf(fp, "%c", ch); + } + if(fclose(fhref)) perror(name); + } else { + fprintf(fp, "%s", name); + } + return 0; +} +int WidgetFileicon(const struct Files *f, FILE *fp) { + char buf[256], *name; + FILE *in; + if(!(name = FilesName(f))) return 0; + /* insert .d.jpeg if available */ + strncpy(buf, name, sizeof(buf) - 12); + strncat(buf, desc, 5); + strncat(buf, picture, 6); + if((in = fopen(buf, "r"))) { + fprintf(fp, "%s", buf); + if(fclose(in)) perror(buf); + } else { + /* added thing to get to root instead of / because sometimes 'root' + is not the real root! eg www.geocities.com/~foo/; does the same thing + as having a @root{/} */ + FilesSetPath((struct Files *)f); + while(FilesEnumPath((struct Files *)f)) { + fprintf(fp, "%s%s", dirParent, separator); + } + fprintf(fp, "%s%s", FilesIsDir(f) ? "dir" : "file", picture); + } + return 0; +} +int WidgetFilename(const struct Files *f, FILE *fp) { + fprintf(fp, "%s", FilesName(f)); + return 0; +} +int WidgetFiles(const struct Files *f, FILE *fp) { + return FilesAdvance((struct Files *)f) ? -1 : 0; +} +int WidgetFilesize(const struct Files *f, FILE *fp) { /* eww */ + if(!FilesIsDir(f)) fprintf(fp, " (%d KB)", FilesSize(f)); + return 0; +} +int WidgetNews(const struct Files *f, FILE *fp) { + char buf[256], *bufpos; + int i; + FILE *in; + if(!filenews[0]) return 0; + if(!(in = fopen(filenews, "r"))) { perror(filenews); return 0; } + for(i = 0; (i < maxRead) && (bufpos = fgets(buf, sizeof(buf), in)); i++) { + fprintf(fp, "%s", bufpos); + } + if(fclose(in)) perror(filenews); + return 0; +} +int WidgetNewsname(const struct Files *f, FILE *fp) { + fprintf(fp, "%s", filenews); + return 0; +} +int WidgetNow(const struct Files *f, FILE *fp) { + char t[22]; + time_t currentTime; + struct tm *formatedTime; + if((currentTime = time(0)) == (time_t)(-1)) { perror("@date"); return 0; } + formatedTime = gmtime(¤tTime); + /* ISO 8601 - YYYY-MM-DDThh:mm:ssTZD */ + strftime(t, 21, "%Y-%m-%dT%H:%M:%SZ", formatedTime); + fprintf(fp, "%s", t); + return 0; +} +int WidgetPwd(const struct Files *f, FILE *fp) { + static int persistant = 0; /* ick, be very careful! */ + char *pwd; + if(!persistant) { persistant = -1; FilesSetPath((struct Files *)f); } + pwd = FilesEnumPath((struct Files *)f); + if(!pwd) { persistant = 0; return 0; } + fprintf(fp, "%s", pwd); + return -1; +} +int WidgetRoot(const struct Files *f, FILE *fp) { + static int persistant = 0; /* ick, be very careful! */ + char *pwd; + if(!persistant) { persistant = -1; FilesSetPath((struct Files *)f); } + pwd = FilesEnumPath((struct Files *)f); + if(!pwd) { persistant = 0; return 0; } + fprintf(fp, "%s", dirParent); + return -1; +} +int WidgetTitle(const struct Files *f, FILE *fp) { + fprintf(fp, "%s", title); + return 0; +} + +int correctNo(int no, const int low, const int high) { + if(no < low) no = low; + else if(no > high) no = high; + return no; +} diff --git a/Widget.h b/Widget.h new file mode 100644 index 0000000..e46325f --- /dev/null +++ b/Widget.h @@ -0,0 +1,21 @@ +struct Recursor; +struct Files; + +void WidgetSetRecursor(const struct Recursor *recursor); +int WidgetSetNews(const char *fn); +/* the widget handlers */ +int WidgetDate(const struct Files *f, FILE *fp); +int WidgetContent(const struct Files *f, FILE *fp); +int WidgetFilealt(const struct Files *f, FILE *fp); +int WidgetFiledesc(const struct Files *f, FILE *fp); +int WidgetFilehref(const struct Files *f, FILE *fp); +int WidgetFileicon(const struct Files *f, FILE *fp); +int WidgetFilename(const struct Files *f, FILE *fp); +int WidgetFiles(const struct Files *f, FILE *fp); +int WidgetFilesize(const struct Files *f, FILE *fp); +int WidgetNews(const struct Files *f, FILE *fp); +int WidgetNewsname(const struct Files *f, FILE *fp); +int WidgetNow(const struct Files *f, FILE *fp); +int WidgetPwd(const struct Files *f, FILE *fp); +int WidgetRoot(const struct Files *f, FILE *fp); +int WidgetTitle(const struct Files *f, FILE *fp); diff --git a/copying.txt b/copying.txt new file mode 100644 index 0000000..d60be69 --- /dev/null +++ b/copying.txt @@ -0,0 +1,15 @@ +Copyright (C) 2008, 2012, 2013 Neil Edelman + +MakeIndex 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, either version 3 of the License, or +(at your option) any later version. + +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 MakeIndex (see gnu.txt.) If not, see +. diff --git a/gpl.txt b/gpl.txt new file mode 100644 index 0000000..bc08fe2 --- /dev/null +++ b/gpl.txt @@ -0,0 +1,619 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. diff --git a/readme.txt b/readme.txt new file mode 100644 index 0000000..a0667fb --- /dev/null +++ b/readme.txt @@ -0,0 +1,83 @@ +Copyright (C) 2008, 2012, 2013 Neil Edelman, see copying.txt. +neil dot edelman each mail dot mcgill dot ca + +Version 0.8. + +Usage: MakeIndex + +MakeIndex is a static compiler that generates content +(index.html, mostly) on all the directories rooted at the +directory specified by the argument, , based on a +template file in . Also included are files to +summarise the directory structure for a xml site map and any +news for an rss feed. + +There should be an directory that has a bunch of +files in it. Run <./MakeIndex example/> (from the command +line;) it should make a webpage out of the directory +structure and <.index.html>, open example/index.html after +running to see. + +* If the <.index.html> file exists in the , +prints recursively; overwrites any index.html +on all the directories rooted at . +* If the <.sitemap.xml> file exists in , +prints (and overwrites) an index called . +* If the <.newsfeed.rss> file exists in , +prints (and overwrites) to all the <.news> +files (if there are any.) + +* Treats <.d> as a description of the file without the <.d>. +If this is an empty text-file or a zero-byte file, it skips over this file. +* Treats as a description of the directory. +* Treats as an in-depth description of the directory, +replacing when in the directory. +* Treats <.d.jpg> as a image that will go with the description. +* Treats <.news> as a newsworthy item; ISO 8601 date (YYYY-MM-DD,) next line title. +* Treats <.link> as a link with the href in the file. + +<.index.html>, <.sitemap.xml>, <.newsfeed.rss> recognised symbols, + +* @(now) - prints the date and the time in UTC; +* @(date) - prints the date on the news file; +* @(title) - prints the second line in the .news; +* @(content) - prints content.d, or if it is missing, index.d; +* @(files){} - (only in index) repeats for all the files in the directory, + * @(filealt) - prints Dir or File; + * @(filehref) - prints the filename or the .link; + * @(fileicon) - prints .d.jpeg, root dir.jpeg, or file.jpeg; + * @(filename) - prints the file name; + * @(filesize) - prints the file size, if it exits; +* @(news) - prints the contents of the file (as a text file;) +* @(newsname) - prints the filename of the news story; +* @(pwd){} - (only in index) prints the directory, the argument is the separator; eg, @(pwd){/}; +* @(root){} - (only in index) prints .. all the way +up to the root; eg, @root{/}. +* ~ on a line by itself is recognised in .newsfile.rss and .sitemap.xml +as a ~~, there should be two of them. + +I use this for my webpage, but I have a Christmas wish list that will +probably never get done, eg, + +* I would really like to have a subset of LaTeX converted into html +for the .d files; +* encoding is an issue, especially the newsfeed (which I believe needs +to be 7bit;) I need to build a unicode-to-html converter; +* it's not robust; eg @(files){@(files){Don't do this.}}. + +If you downloaded the source and have GCC, type ; otherwise +you're on your own. It should be entirely POSIX compatible. + +Assumes .. is the parent directory, . is the current directory, and +/ is the directory separator; works for UNIX, MacOS, Windows. +If this is not the case, the constants are in Files.c. + +Changes + +0.7 -- 0.8 +Okay, strcasecmp instead of strcmp to sort (case-insensitive sort.) + +0.6 -- 0.7 +Fixed bug: .d.d used to show up in the page +because the first d said "I do want to show in the list" +without checking the second.