Permalink
Browse files

Sun Jun 27 10:41:49 PDT 2004

    Minor Makefile cleanup.

Fri Aug  6 13:01:45 PDT 2004
    Implemented suggestions from Denis Klykvin: now loads config file
    from $HOME/.netwalk/ and if it doesn't exist, a default one will be
    created.

    Updated outdated README.

    [netwalk-0.4.5.tgz]
  • Loading branch information...
1 parent 64a2ea7 commit 4a1320c5852a6e3ac07915723adff31a7dd705f3 Ben Lynn committed Aug 6, 2004
Showing with 307 additions and 174 deletions.
  1. +28 −13 Makefile
  2. +12 −0 NEWS
  3. +4 −6 README
  4. +0 −4 config
  5. +129 −0 config.c
  6. +18 −0 config.h
  7. +61 −0 linux/config_file.c
  8. +8 −151 main.c
  9. +14 −0 util.h
  10. +33 −0 win32/config_file.c
View
@@ -1,9 +1,9 @@
-VERSION=0.4.4
-ALLFILES = *.[ch] Makefile LICENSE README NEWS config helmetr.ttf
+VERSION=0.4.5
+ALLFILES = *.[ch] Makefile LICENSE README NEWS linux/*.[ch] win32/*.[ch] helmetr.ttf
PROJNAME = netwalk
-ifdef WIN32
+OS ?= linux
+ifeq ("$(OS)", "win32")
CC = i586-mingw32msvc-gcc
-EFLAGS=-boost -O2 -I /home/ben/cross/SDL/include/SDL
CFLAGS=-O2 -Wall -I /home/ben/cross/SDL/include/SDL -mwindows
SDL_LIBS=-L /home/ben/cross/SDL/lib -lmingw32 -lSDLmain -lSDL
LIBS = $(SDL_LIBS) -lSDL_ttf
@@ -12,6 +12,8 @@ CC = gcc
CFLAGS=-Wall -O2 -fomit-frame-pointer `sdl-config --cflags`
SDL_LIBS=`sdl-config --libs`
LIBS = $(SDL_LIBS) -lSDL_ttf
+INSTALL = /usr/bin/install
+PREFIX = /usr
endif
.PHONY: target clean dist
@@ -21,32 +23,45 @@ target : version.h $(PROJNAME)
version.h : ./Makefile
echo '#define VERSION_STRING "'$(VERSION)'"' > version.h
-$(PROJNAME) : main.c game.c colour.c widget.c
+config_file.c : $(OS)/config_file.c
+ ln -s $^ $@
+
+$(PROJNAME) : main.c game.c colour.c widget.c config.c config_file.c
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
DISTNAME=$(PROJNAME)-$(VERSION)
-dist: $(ALLFILES)
- -rm version.h
+clean :
+ -rm $(PROJNAME) *.o version.h config_file.c
+
+dist: $(ALLFILES) clean
-rm -rf $(DISTNAME)
mkdir $(DISTNAME)
cp -rl --parents $(ALLFILES) $(DISTNAME)
tar chfz $(DISTNAME).tgz $(DISTNAME)
-rm -rf $(DISTNAME)
-ifdef WIN32
-bindist : $(PROJNAME)
+ifeq ("$(OS)", "win32")
+zip : target
-rm -rf $(DISTNAME)
mkdir $(DISTNAME)
cp -l LICENSE $(DISTNAME)
cp -l $(PROJNAME) $(DISTNAME)/$(PROJNAME).exe
cp -l *.ttf $(DISTNAME)
- cp -l config $(DISTNAME)
+ #cp -l config $(DISTNAME)
cp -l /home/ben/cross/SDL/lib/SDL.dll $(DISTNAME)
cp -l /home/ben/cross/SDL/lib/SDL_ttf.dll $(DISTNAME)
zip $(DISTNAME)-win.zip $(DISTNAME)/*
-rm -rf $(DISTNAME)
-endif
+else
-clean :
- -rm $(PROJNAME) *.o version.h
+install : netwalk
+ $(INSTALL) -m 755 netwalk $(PREFIX)/bin
+ $(INSTALL) -d $(PREFIX)/share/$(PROJNAME)
+ $(INSTALL) -m 644 helmetr.ttf $(PREFIX)/share/$(PROJNAME)/
+
+uninstall : clean
+ -rm -f $(PREFIX)/bin/$(PROJNAME)
+ -rm -rf $(PREFIX)/share/$(PROJNAME)
+
+endif
View
12 NEWS
@@ -1,3 +1,15 @@
+Fri Aug 6 13:01:45 PDT 2004
+ Implemented suggestions from Denis Klykvin: now loads config file
+ from $HOME/.netwalk/ and if it doesn't exist, a default one will be
+ created.
+
+ Updated outdated README.
+
+ [netwalk-0.4.5.tgz]
+
+Sun Jun 27 10:41:49 PDT 2004
+ Minor Makefile cleanup.
+
Tue Jun 22 23:13:04 PDT 2004
Interface is better: shading of widgets, current menu item is highlighted,
menu item is activated on mouse button up, rather than a second click.
View
10 README
@@ -1,10 +1,10 @@
-README for NetWalk v0.4.2
+README for NetWalk v0.4.5
Ben Lynn
INTRODUCTION
NetWalk is a puzzle game where the object is to connect every terminal to the
-main server. (These are represented by coloured boxes, so I guess you could
+main server. (These are represented by coloured boxes, so you could
also imagine them to be water mains, electricity cables, phone lines, etc.)
In this version, not only must every terminal be connected, but every piece of
@@ -15,15 +15,13 @@ USAGE
Click on a square to rotate its contents. A left click performs an
anticlockwise rotation and a right click performs a clockwise rotation.
-You can select presets, or make a custom game in the options window.
-
There is one shortcut key: F2 starts a new game.
-Edit the "config" file to configure the game and add presets.
+Edit the ".netwalk/config" file to configure the game.
COMPILATION
-Type "make" to compile the project.
+Type "make" to compile.
LICENSE
View
4 config
@@ -1,4 +0,0 @@
-font helmetr.ttf
-fontsize 11
-hiscores hiscores.txt
-showmoves 0
View
129 config.c
@@ -0,0 +1,129 @@
+#include "config.h"
+#include "util.h"
+
+static void parse_option(config_ptr config, char *s1, char *s2)
+{
+ if (!strcmp(s1, "showmoves")) {
+ config->showmoves = atoi(s2);
+ }
+ if (!strcmp(s1, "fontsize")) {
+ config->fontsize = atoi(s2);
+ }
+ if (!strcmp(s1, "font")) {
+ config->fontname = clonestr(s2);
+ }
+ if (!strcmp(s1, "hiscores")) {
+ config->hsfile = clonestr(s2);
+ }
+}
+
+static int is_whitespace(char c)
+{
+ if (strchr(" \t\r\n", c)) return -1;
+ return 0;
+}
+
+static void skip_whitespace(FILE *fp)
+{
+ for (;;) {
+ int c;
+ c = getc(fp);
+ if (feof(fp)) return;
+ if (!is_whitespace(c)) {
+ ungetc(c, fp);
+ break;
+ }
+ }
+}
+
+/*
+static void read_word(char *s, FILE *fp)
+{
+ int i = 0;
+
+ skip_whitespace(fp);
+ if (feof(fp)) return;
+
+ for (;;) {
+ int c;
+ c = getc(fp);
+ if (feof(fp)) return;
+ if (is_whitespace(c)) {
+ ungetc(c, fp);
+ break;
+ }
+ s[i] = c;
+ i++;
+ if (i >= 128 - 1) break;
+ }
+ s[i] = 0;
+}
+*/
+
+static void read_line(char *s, FILE *fp)
+{
+ int i = 0;
+
+ for (;;) {
+ int c;
+ c = getc(fp);
+ if (feof(fp)) return;
+ if (c == '\r') {
+ //safest thing to do?
+ continue;
+ }
+ if (c == '\n') {
+ ungetc(c, fp);
+ break;
+ }
+ s[i] = c;
+ i++;
+ if (i >= 1024 - 1) break;
+ }
+ s[i] = 0;
+}
+
+void config_load(config_ptr config)
+{
+ FILE *fp;
+
+ fp = config_get_fp();
+
+ for(;;) {
+ int i;
+ char s1[1024], *s2;
+
+ skip_whitespace(fp);
+ if (feof(fp)) {
+ break;
+ }
+ read_line(s1, fp);
+ if (feof(fp)) {
+ break;
+ }
+
+ i = 0;
+ for(;;) {
+ if (!s1[i]) {
+ s2 = &s1[i];
+ break;
+ }
+ if (is_whitespace(s1[i])) {
+ s1[i] = 0;
+ i++;
+ for(;;) {
+ if (!s1[i] || !is_whitespace(s1[i])) {
+ s2 = &s1[i];
+ break;
+ }
+ }
+ break;
+ }
+ i++;
+ }
+
+ parse_option(config, s1, s2);
+ }
+
+ fclose(fp);
+}
View
@@ -0,0 +1,18 @@
+#ifndef CONFIG_H
+#define CONFIG_H
+
+#include <stdio.h>
+
+struct config_s {
+ char *fontname;
+ char *hsfile;
+ int fontsize;
+ int showmoves;
+};
+typedef struct config_s *config_ptr;
+typedef struct config_s config_t[1];
+
+void config_load(config_ptr config);
+FILE *config_get_fp();
+
+#endif //CONFIG_H
View
@@ -0,0 +1,61 @@
+#include "config.h"
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#define NETWALK_SHARE_DIR "."
+//#define NETWALK_SHARE_DIR "/usr/share/netwalk"
+
+FILE *config_get_fp()
+{
+ FILE *fp;
+
+ char *home_dir = getenv("HOME");
+ char *netwalk_dir;
+ char *config_file;
+ struct stat stbuf;
+
+ if (!home_dir) {
+ fprintf(stderr, "$HOME is not set\n");
+ exit(1);
+ }
+
+ netwalk_dir = malloc(strlen(home_dir) + 100);
+ config_file = malloc(strlen(home_dir) + 100);
+
+ strcpy(netwalk_dir, home_dir);
+ strcat(netwalk_dir,"/.netwalk");
+
+ if (stat(netwalk_dir, &stbuf)) {
+ if (mkdir(netwalk_dir, 0755)) {
+ fprintf(stderr, "Can't stat nor mkdir %s\n", netwalk_dir);
+ exit(1);
+ }
+ }
+
+ strcpy(config_file, netwalk_dir);
+ strcat(config_file, "/config");
+
+ if (stat(config_file, &stbuf)) {
+ fprintf(stderr, "Creating config file at %s\n", config_file);
+ fp = fopen(config_file, "w");
+ if (!fp) {
+ fprintf(stderr, "Can't create %s\n", config_file);
+ exit(1);
+ }
+ fprintf(fp, "font %s/helmetr.ttf\n", NETWALK_SHARE_DIR);
+ fprintf(fp, "fontsize 11\n");
+ fprintf(fp, "hiscores %s/hiscores.txt\n", netwalk_dir);
+ fprintf(fp, "showmoves 0\n");
+ fclose(fp);
+ }
+
+ fp = fopen(config_file, "r");
+
+ free(netwalk_dir);
+ free(config_file);
+
+ return fp;
+}
Oops, something went wrong.

0 comments on commit 4a1320c

Please sign in to comment.