Refreshing.

This commit is contained in:
Neil Edelman 2017-03-23 01:58:20 -04:00
parent 6c5dd43af4
commit 85d102f389
10 changed files with 125 additions and 54 deletions

128
Makefile
View File

@ -1,59 +1,117 @@
# Tested on MacOSX, GNU bash version 4.2.0(1)-release (x86_64--netbsd) # Makefile 1.2 (GNU Make 3.81; MacOSX gcc 4.2.1; MacOSX MinGW 4.3.0)
# x86_64--netbsd make (?) doesn't have all the tricks
PROJ := MakeIndex PROJ := MakeIndex
VA := 0 VA := 0
VB := 8 VB := 9
FILES := Recursor Parser Widget Files
# dirs
SDIR := src
TDIR := test
GDIR := build
BDIR := bin BDIR := bin
BACK := backup BACK := backup
DDIR := doc
PREFIX:= /usr/local
# files in bdir
INST := $(PROJ)-$(VA)_$(VB) 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 # extra stuff we should back up
CF := -Wall -O3 -fasm -fomit-frame-pointer -ffast-math -funroll-loops -pedantic -ansi # not ansi! but compiles; POSIX? EXTRA :=
default: $(BDIR)/$(PROJ) # John Graham-Cumming:
# rwildcard is a recursive wildcard
rwildcard=$(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d))
$(BDIR)/$(PROJ): $(OBJS) # select all automatically
$(CC) $(CF) -o $@ $(OBJS) SRCS := $(call rwildcard, $(SDIR), *.c) # or *.java
# $(CC) $(CF) -o $@ $^ TEST := $(call rwildcard, $(TDIR), *.c)
H := $(call rwildcard, $(SDIR), *.h) $(call rwildcard, $(TDIR), *.h)
OBJS := $(patsubst $(SDIR)/%.c, $(GDIR)/%.o, $(SRCS)) # or *.class
TOBJS := $(patsubst $(TDIR)/%.c, $(GDIR)/$(TDIR)/%.o, $(TEST))
DOCS := $(patsubst $(SDIR)/%.c, $(DDIR)/%.html, $(SRCS))
$(BDIR)/%.o: %.c CC := gcc # /usr/local/i386-mingw32-4.3.0/bin/i386-mingw32-gcc javac nxjc
CF := -Wall -Wextra -Wno-format-y2k -W -Wstrict-prototypes \
-Wmissing-prototypes -Wpointer-arith -Wreturn-type -Wcast-qual -Wwrite-strings \
-Wswitch -Wshadow -Wcast-align -Wbad-function-cast -Wchar-subscripts -Winline \
-Wnested-externs -Wredundant-decls -O3 -ffast-math -funroll-loops -pedantic -ansi # or -std=c99 -mwindows or -g:none -O -verbose -d $(BDIR) $(SDIR)/*.java -Xlint:unchecked -Xlint:deprecation
OF := # -framework OpenGL -framework GLUT or -lglut -lGLEW
CDOC := cdoc
# props Jakob Borg and Eldar Abusalimov
# $(ARGS) is all the extra arguments
# $(BRGS) is_all_the_extra_arguments
EMPTY :=
SPACE := $(EMPTY) $(EMPTY)
ifeq (backup, $(firstword $(MAKECMDGOALS)))
ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
BRGS := $(subst $(SPACE),_,$(ARGS))
ifneq (,$(BRGS))
BRGS := -$(BRGS)
endif
$(eval $(ARGS):;@:)
endif
######
# compiles the programme by default
default: $(BDIR)/$(PROJ) $(DOCS)
# . . . success; executable is in $(BDIR)/$(PROJ)
# linking
$(BDIR)/$(PROJ): $(OBJS) $(TOBJS)
@mkdir -p $(BDIR) @mkdir -p $(BDIR)
$(CC) $(CF) -c $? -o $@ $(CC) $(CF) $(OF) $(OBJS) -o $@
$(BDIR)/Recursor.o: Recursor.c # compiling
@mkdir -p $(BDIR) $(OBJS): $(GDIR)/%.o: $(SDIR)/%.c $(H)
$(CC) $(CF) -c $? -o $@ @mkdir -p $(GDIR)
$(CC) $(CF) -c $(SDIR)/$*.c -o $@
$(BDIR)/Parser.o: Parser.c $(TOBJS): $(GDIR)/$(TDIR)/%.o: $(TDIR)/%.c $(H)
@mkdir -p $(BDIR) @mkdir -p $(GDIR)
$(CC) $(CF) -c $? -o $@ @mkdir -p $(GDIR)/$(TDIR)
$(CC) $(CF) -c $(TDIR)/$*.c -o $@
$(BDIR)/Widget.o: Widget.c $(DOCS): $(DDIR)/%.html: $(SDIR)/%.c $(SDIR)/%.h
@mkdir -p $(BDIR) @mkdir -p $(DDIR)
$(CC) $(CF) -c $? -o $@ -cat $^ | $(CDOCS) > $@
$(BDIR)/Files.o: Files.c ######
@mkdir -p $(BDIR) # phoney targets
$(CC) $(CF) -c $? -o $@
.PHONY: setup clean backup icon install uninstall
.PHONY: clean backup
clean: clean:
-rm $(OBJS) -rm -f $(OBJS) $(TOBJS) $(DOCS)
-rm -rf $(BDIR)/$(TDIR)
backup: backup:
@mkdir -p $(BACK) @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/ zip $(BACK)/$(INST)-`date +%Y-%m-%dT%H%M%S`$(BRGS).zip readme.txt gpl.txt copying.txt Makefile $(SRCS) $(TEST) $(H) $(SDIR)/$(ICON) $(EXTRA)
#git commit -am "$(ARGS)"
setup: $(BDIR)/$(PROJ) icon: default
# . . . setting icon on a Mac.
cp $(MDIR)/$(ICON) $(BDIR)/$(ICON)
-sips --addIcon $(BDIR)/$(ICON)
-DeRez -only icns $(BDIR)/$(ICON) > $(BDIR)/$(RSRC)
-Rez -append $(BDIR)/$(RSRC) -o $(BDIR)/$(PROJ)
-SetFile -a C $(BDIR)/$(PROJ)
setup: default icon
@mkdir -p $(BDIR)/$(INST) @mkdir -p $(BDIR)/$(INST)
cp $(BDIR)/$(PROJ) readme.txt gpl.txt copying.txt $(BDIR)/$(INST) cp $(BDIR)/$(PROJ) readme.txt gpl.txt copying.txt $(BDIR)/$(INST)
cp -R $(BDIR)/example $(BDIR)/$(INST) rm -f $(BDIR)/$(INST)-MacOSX.dmg
rm -f $(BDIR)/$(INST).dmg # or rm -f $(BDIR)/$(INST)-Win32.zip
hdiutil create $(BDIR)/$(INST).dmg -volname "MakeIndex $(VA).$(VB)" -srcfolder $(BDIR)/$(INST) hdiutil create $(BDIR)/$(INST)-MacOSX.dmg -volname "$(PROJ) $(VA).$(VB)" -srcfolder $(BDIR)/$(INST)
# or zip $(BDIR)/$(INST)-Win32.zip -r $(BDIR)/$(INST)
rm -R $(BDIR)/$(INST) rm -R $(BDIR)/$(INST)
install: default
@mkdir -p $(DESTDIR)$(PREFIX)/bin
cp $(BDIR)/$(PROJ) $(DESTDIR)$(PREFIX)/bin/$(PROJ)
uninstall:
rm -f $(DESTDIR)$(PREFIX)/bin/$(PROJ)

View File

@ -1,7 +1,7 @@
Copyright (C) 2008, 2012, 2013 Neil Edelman, see copying.txt. Copyright (C) 2008, 2012, 2013 Neil Edelman, see copying.txt.
neil dot edelman each mail dot mcgill dot ca neil dot edelman each mail dot mcgill dot ca
Version 0.8. Version 0.9.
Usage: MakeIndex <directory> Usage: MakeIndex <directory>

View File

@ -1,9 +1,15 @@
/* 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, or
\url{ https://opensource.org/licenses/GPL-3.0 }.
/* Files is a list of File (private class defiend below,) the Files can have 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.) a relation to other Files by 'parent' and 'favourite' (@(pwd) uses this.)
* Created by Neil Edelman on 2008-03-24. */
@file Files
@author Neil
@version 0.9; 2017-03
@since 0.8; 2012
0.8; 2008-03-24 */
#include <stdlib.h> /* malloc free */ #include <stdlib.h> /* malloc free */
#include <stdio.h> /* fprintf */ #include <stdio.h> /* fprintf */
@ -35,12 +41,12 @@ struct File {
}; };
/* private */ /* private */
struct File *File(const char *name, const int size, const int isDir); static struct File *File(const char *name, const int size, const int isDir);
void File_(struct File *file); static void File_(struct File *file);
int FileInsert(struct File *file, struct File **startAddr); static int FileInsert(struct File *file, struct File **startAddr);
/* Alert! parent->this must be the 'file' (directory) that you want to create */ /** 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 *)) { struct Files *Files(const struct Files *parent, const FilesFilter filter) {
char *dirName; char *dirName;
struct dirent *de; struct dirent *de;
struct stat st; struct stat st;
@ -86,6 +92,7 @@ struct Files *Files(const struct Files *parent, int (*filter)(const struct Files
if(closedir(dir)) { perror(dirCurrent); } if(closedir(dir)) { perror(dirCurrent); }
return files; return files;
} }
/** Destructor. */
void Files_(struct Files *files) { void Files_(struct Files *files) {
if(!files) return; if(!files) return;
File_(files->firstDir); /* cascading delete */ File_(files->firstDir); /* cascading delete */
@ -95,7 +102,7 @@ void Files_(struct Files *files) {
/* this is how we used to access files before 'invisiblity' /* 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 : f->firstFile ? -1 : 0;
if((f->this)) return f->this->next ? -1 : 0; */ if((f->this)) return f->this->next ? -1 : 0; */
/* this is how we access the files sequentially */ /** This is how we access the files sequentially. */
int FilesAdvance(struct Files *f) { int FilesAdvance(struct Files *f) {
static enum { files, dirs } type = dirs; static enum { files, dirs } type = dirs;
if(!f) return 0; if(!f) return 0;
@ -113,17 +120,17 @@ int FilesAdvance(struct Files *f) {
} }
return 0; return 0;
} }
/* doesn't have a parent */ /** Doesn't have a parent? */
int FilesIsRoot(const struct Files *f) { int FilesIsRoot(const struct Files *f) {
if(!f) return 0; if(!f) return 0;
return (f->parent) ? 0 : -1; return (f->parent) ? 0 : -1;
} }
/* resets the list of favourites */ /** Resets the list of favourites. */
void FilesSetPath(struct Files *f) { void FilesSetPath(struct Files *f) {
if(!f) return; if(!f) return;
for( ; f->parent; f = f->parent) f->parent->favourite = f; for( ; f->parent; f = f->parent) f->parent->favourite = f;
} }
/* after FilesSetFarourite, this enumerates them */ /** After FilesSetFarourite, this enumerates them. */
char *FilesEnumPath(struct Files *f) { char *FilesEnumPath(struct Files *f) {
char *name; char *name;
if(!f) return 0; if(!f) return 0;
@ -134,15 +141,17 @@ char *FilesEnumPath(struct Files *f) {
return name; return name;
} }
/* takes from files->this */ /** @return The file name of the selected file. */
char *FilesName(const struct Files *files) { char *FilesName(const struct Files *files) {
if(!files || !files->this) return 0; if(!files || !files->this) return 0;
return files->this->name; return files->this->name;
} }
/** @return File size of the selected file. */
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;
} }
/** @return Whether the file is a directory. */
int FilesIsDir(const struct Files *files) { int FilesIsDir(const struct Files *files) {
if(!files || !files->this) return 0; if(!files || !files->this) return 0;
return files->this->isDir; return files->this->isDir;
@ -150,7 +159,7 @@ int FilesIsDir(const struct Files *files) {
/* this is just a list of filenames, (not public) "class File" */ /* this is just a list of filenames, (not public) "class File" */
struct File *File(const char *name, const int size, const int isDir) { static struct File *File(const char *name, const int size, const int isDir) {
int len; int len;
struct File *file; struct File *file;
if(!name || !*name) { fprintf(stderr, "File: file has no name.\n"); return 0; } if(!name || !*name) { fprintf(stderr, "File: file has no name.\n"); return 0; }
@ -165,7 +174,7 @@ struct File *File(const char *name, const int size, const int isDir) {
/* fprintf(stderr, " File(\"%s\" %p)\n", file->name, (void *)file); debug . . . caught bug! */ /* fprintf(stderr, " File(\"%s\" %p)\n", file->name, (void *)file); debug . . . caught bug! */
return file; return file;
} }
void File_(struct File *file) { static void File_(struct File *file) {
struct File *next; struct File *next;
/* delete ALL the list of files (not just the one) */ /* delete ALL the list of files (not just the one) */
for( ; file; file = next) { for( ; file; file = next) {
@ -174,7 +183,7 @@ void File_(struct File *file) {
free(file); free(file);
} }
} }
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) { fprintf(stderr, "File::insert: file is null, not included.\n"); return 0; }

View File

@ -1,7 +1,11 @@
/** \see{Files}. */
struct Files; struct Files;
struct Recursor; struct Recursor;
struct Files *Files(const struct Files *parent, int (*filter)(const struct Files *, const char *)); /** Returns a boolean value. */
typedef int (*FilesFilter)(const struct Files *, const char *);
struct Files *Files(const struct Files *parent, const FilesFilter filter);
void Files_(struct Files *files); void Files_(struct Files *files);
int FilesAdvance(struct Files *files); int FilesAdvance(struct Files *files);
int FilesIsRoot(const struct Files *f); int FilesIsRoot(const struct Files *f);