From 85d102f3891ea96a81057816e8518c1e2913afb7 Mon Sep 17 00:00:00 2001 From: Neil Edelman Date: Thu, 23 Mar 2017 01:58:20 -0400 Subject: [PATCH] Refreshing. --- Makefile | 128 +++++++++++++++++++++++++---------- readme.txt | 2 +- Files.c => src/Files.c | 43 +++++++----- Files.h => src/Files.h | 6 +- Parser.c => src/Parser.c | 0 Parser.h => src/Parser.h | 0 Recursor.c => src/Recursor.c | 0 Recursor.h => src/Recursor.h | 0 Widget.c => src/Widget.c | 0 Widget.h => src/Widget.h | 0 10 files changed, 125 insertions(+), 54 deletions(-) rename Files.c => src/Files.c (82%) rename Files.h => src/Files.h (64%) rename Parser.c => src/Parser.c (100%) rename Parser.h => src/Parser.h (100%) rename Recursor.c => src/Recursor.c (100%) rename Recursor.h => src/Recursor.h (100%) rename Widget.c => src/Widget.c (100%) rename Widget.h => src/Widget.h (100%) diff --git a/Makefile b/Makefile index 1d0e477..716a77d 100644 --- a/Makefile +++ b/Makefile @@ -1,59 +1,117 @@ -# Tested on MacOSX, GNU bash version 4.2.0(1)-release (x86_64--netbsd) -# x86_64--netbsd make (?) doesn't have all the tricks +# Makefile 1.2 (GNU Make 3.81; MacOSX gcc 4.2.1; MacOSX MinGW 4.3.0) PROJ := MakeIndex VA := 0 -VB := 8 -FILES := Recursor Parser Widget Files +VB := 9 + +# dirs +SDIR := src +TDIR := test +GDIR := build BDIR := bin BACK := backup +DDIR := doc +PREFIX:= /usr/local + +# files in bdir 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? +# extra stuff we should back up +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) - $(CC) $(CF) -o $@ $(OBJS) -# $(CC) $(CF) -o $@ $^ +# select all automatically +SRCS := $(call rwildcard, $(SDIR), *.c) # or *.java +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) - $(CC) $(CF) -c $? -o $@ + $(CC) $(CF) $(OF) $(OBJS) -o $@ -$(BDIR)/Recursor.o: Recursor.c - @mkdir -p $(BDIR) - $(CC) $(CF) -c $? -o $@ +# compiling +$(OBJS): $(GDIR)/%.o: $(SDIR)/%.c $(H) + @mkdir -p $(GDIR) + $(CC) $(CF) -c $(SDIR)/$*.c -o $@ -$(BDIR)/Parser.o: Parser.c - @mkdir -p $(BDIR) - $(CC) $(CF) -c $? -o $@ +$(TOBJS): $(GDIR)/$(TDIR)/%.o: $(TDIR)/%.c $(H) + @mkdir -p $(GDIR) + @mkdir -p $(GDIR)/$(TDIR) + $(CC) $(CF) -c $(TDIR)/$*.c -o $@ -$(BDIR)/Widget.o: Widget.c - @mkdir -p $(BDIR) - $(CC) $(CF) -c $? -o $@ +$(DOCS): $(DDIR)/%.html: $(SDIR)/%.c $(SDIR)/%.h + @mkdir -p $(DDIR) + -cat $^ | $(CDOCS) > $@ -$(BDIR)/Files.o: Files.c - @mkdir -p $(BDIR) - $(CC) $(CF) -c $? -o $@ +###### +# phoney targets + +.PHONY: setup clean backup icon install uninstall -.PHONY: clean backup clean: - -rm $(OBJS) + -rm -f $(OBJS) $(TOBJS) $(DOCS) + -rm -rf $(BDIR)/$(TDIR) 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/ + 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) 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 -f $(BDIR)/$(INST)-MacOSX.dmg + # or rm -f $(BDIR)/$(INST)-Win32.zip + 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) + +install: default + @mkdir -p $(DESTDIR)$(PREFIX)/bin + cp $(BDIR)/$(PROJ) $(DESTDIR)$(PREFIX)/bin/$(PROJ) + +uninstall: + rm -f $(DESTDIR)$(PREFIX)/bin/$(PROJ) diff --git a/readme.txt b/readme.txt index a0667fb..9424a66 100644 --- a/readme.txt +++ b/readme.txt @@ -1,7 +1,7 @@ Copyright (C) 2008, 2012, 2013 Neil Edelman, see copying.txt. neil dot edelman each mail dot mcgill dot ca -Version 0.8. +Version 0.9. Usage: MakeIndex diff --git a/Files.c b/src/Files.c similarity index 82% rename from Files.c rename to src/Files.c index b9e5069..a16cd8e 100644 --- a/Files.c +++ b/src/Files.c @@ -1,9 +1,15 @@ /* 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 - * a relation to other Files by 'parent' and 'favourite' (@(pwd) uses this.) - * Created by Neil Edelman on 2008-03-24. */ + 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.) + + @file Files + @author Neil + @version 0.9; 2017-03 + @since 0.8; 2012 + 0.8; 2008-03-24 */ #include /* malloc free */ #include /* fprintf */ @@ -35,12 +41,12 @@ struct File { }; /* 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); +static struct File *File(const char *name, const int size, const int isDir); +static void File_(struct File *file); +static 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 *)) { +/** parent->this must be the 'file' (directory) that you want to create */ +struct Files *Files(const struct Files *parent, const FilesFilter filter) { char *dirName; struct dirent *de; struct stat st; @@ -86,6 +92,7 @@ struct Files *Files(const struct Files *parent, int (*filter)(const struct Files if(closedir(dir)) { perror(dirCurrent); } return files; } +/** Destructor. */ void Files_(struct Files *files) { if(!files) return; File_(files->firstDir); /* cascading delete */ @@ -95,7 +102,7 @@ void Files_(struct Files *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 */ +/** This is how we access the files sequentially. */ int FilesAdvance(struct Files *f) { static enum { files, dirs } type = dirs; if(!f) return 0; @@ -113,17 +120,17 @@ int FilesAdvance(struct Files *f) { } return 0; } -/* doesn't have a parent */ +/** 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 */ +/** 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 */ +/** After FilesSetFarourite, this enumerates them. */ char *FilesEnumPath(struct Files *f) { char *name; if(!f) return 0; @@ -134,15 +141,17 @@ char *FilesEnumPath(struct Files *f) { return name; } -/* takes from files->this */ +/** @return The file name of the selected file. */ char *FilesName(const struct Files *files) { if(!files || !files->this) return 0; return files->this->name; } +/** @return File size of the selected file. */ int FilesSize(const struct Files *files) { if(!files || !files->this) return 0; return files->this->size; } +/** @return Whether the file is a directory. */ int FilesIsDir(const struct Files *files) { if(!files || !files->this) return 0; 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" */ -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; struct File *file; 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! */ return file; } -void File_(struct File *file) { +static void File_(struct File *file) { struct File *next; /* delete ALL the list of files (not just the one) */ for( ; file; file = next) { @@ -174,7 +183,7 @@ void File_(struct File *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 *prev = 0, *ptr = 0; if(!file || !startAddr) { fprintf(stderr, "File::insert: file is null, not included.\n"); return 0; } diff --git a/Files.h b/src/Files.h similarity index 64% rename from Files.h rename to src/Files.h index 6cdd2e5..4053b00 100644 --- a/Files.h +++ b/src/Files.h @@ -1,7 +1,11 @@ +/** \see{Files}. */ struct Files; 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); int FilesAdvance(struct Files *files); int FilesIsRoot(const struct Files *f); diff --git a/Parser.c b/src/Parser.c similarity index 100% rename from Parser.c rename to src/Parser.c diff --git a/Parser.h b/src/Parser.h similarity index 100% rename from Parser.h rename to src/Parser.h diff --git a/Recursor.c b/src/Recursor.c similarity index 100% rename from Recursor.c rename to src/Recursor.c diff --git a/Recursor.h b/src/Recursor.h similarity index 100% rename from Recursor.h rename to src/Recursor.h diff --git a/Widget.c b/src/Widget.c similarity index 100% rename from Widget.c rename to src/Widget.c diff --git a/Widget.h b/src/Widget.h similarity index 100% rename from Widget.h rename to src/Widget.h