Index: levelstate.c =================================================================== --- levelstate.c (revision 16607) +++ levelstate.c (working copy) @@ -1,8 +1,8 @@ /* * - * gPlanarity: + * gPlanarity: * The geeky little puzzle game with a big noodly crunch! - * + * * gPlanarity copyright (C) 2005 Monty * Original Flash game by John Tantalo * Original game concept by Mary Radcliffe @@ -11,17 +11,17 @@ * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. - * + * * gPlanarity 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 Postfish; see the file COPYING. If not, write to the * Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. * - * + * */ #define _GNU_SOURCE @@ -30,6 +30,20 @@ #include #include #include + +#ifdef __FreeBSD__ +/* + getline.c --- Implementation of replacement getline function. + Copyright (C) 2005 Free Software Foundation, Inc. +*/ +#ifndef SIZE_MAX +# define SIZE_MAX ((size_t) -1) +#endif +#ifndef SSIZE_MAX +# define SSIZE_MAX ((ssize_t) (SIZE_MAX / 2)) +#endif +#endif + #include "graph.h" #include "levelstate.h" #include "gameboard.h" @@ -50,7 +64,7 @@ int in_progress; long highscore; - + } levelstate; static levelstate *head=0; @@ -65,7 +79,7 @@ static int selectflag = 0; static int level_limit = 1; - + static levelstate *new_level(){ levelstate *ret; int num=0; @@ -87,7 +101,7 @@ ret->next=0; ret->prev=tail; - + if(tail){ ret->prev->next=ret; }else{ @@ -112,12 +126,12 @@ impress_location(&g); gameboard_write_icon(ret->gm.id,"1",gameboard,&g,1,1); - + // releases the temporary graph memory graph_release(&g); } - + return ret; } @@ -136,8 +150,8 @@ } return 0; }else{ - // make new levels to fill - + // make new levels to fill + while(tail->gm.numin_progress || gameboard->finish_dialog_active)){ gameboard_write(curr->gm.id,gameboard); gameboard_write_icon(curr->gm.id,"2",gameboard,&gameboard->g, - !gameboard->hide_lines,gameboard->show_intersections); + !gameboard->hide_lines,gameboard->show_intersections); } f = fopen(name,"wb"); if(f==NULL){ fprintf(stderr,_("ERROR: Could not save game state file \"%s\":\n\t%s\n"), - curr->gm.id,strerror(errno)); + curr->gm.id,strerror(errno)); return errno; } - + fprintf(f,"current %d : %s\n",strlen(curr->gm.id),curr->gm.id); { levelstate *l=head; while(l){ fprintf(f,"level %ld %d %d : %s\n", - l->highscore,l->in_progress, - strlen(l->gm.id),l->gm.id); + l->highscore,l->in_progress, + strlen(l->gm.id),l->gm.id); l=l->next; } } @@ -191,11 +205,108 @@ fprintf(f,"finish 1\n"); if(gameboard->level_dialog_active) fprintf(f,"select 1\n"); - + fclose(f); return 0; } +#ifdef __FreeBSD__ +/* + getline.c --- Implementation of replacement getline function. + Copyright (C) 2005 Free Software Foundation, Inc. + + getdelim.c --- Implementation of replacement getdelim function. + Copyright (C) 1994, 1996, 1997, 1998, 2001, 2003, 2005 Free + Software Foundation, Inc. +*/ + +ssize_t +getline (char **lineptr, size_t *n, FILE *stream) +{ + return getdelim (lineptr, n, '\n', stream); +} + +ssize_t +getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp) +{ + + ssize_t result; + size_t cur_len = 0; + + if (lineptr == NULL || n == NULL || fp == NULL) + { + errno = EINVAL; + return -1; + } + + flockfile (fp); + + if (*lineptr == NULL || *n == 0) + { + *n = 120; + *lineptr = (char *) malloc (*n); + if (*lineptr == NULL) + { + result = -1; + goto unlock_return; + } + } + + for (;;) + { + int i; + + i = getc (fp); + if (i == EOF) + { + result = -1; + break; + } + + /* Make enough space for len+1 (for final NUL) bytes. */ + if (cur_len + 1 >= *n) + { + size_t needed_max = + SSIZE_MAX < SIZE_MAX ? (size_t) SSIZE_MAX + 1 : SIZE_MAX; + size_t needed = 2 * *n + 1; /* Be generous. */ + char *new_lineptr; + + if (needed_max < needed) + needed = needed_max; + if (cur_len + 1 >= needed) + { + result = -1; + goto unlock_return; + } + + new_lineptr = (char *) realloc (*lineptr, needed); + if (new_lineptr == NULL) + { + result = -1; + goto unlock_return; + } + + *lineptr = new_lineptr; + *n = needed; + } + + (*lineptr)[cur_len] = i; + cur_len++; + + if (i == delimiter) + break; + } + (*lineptr)[cur_len] = '\0'; + result = cur_len ? cur_len : result; + + + unlock_return: + funlockfile (fp); + return result; +} + +#endif + // also functions as the levelstate init; always called once upon startup int levelstate_read(){ char *line=NULL; @@ -212,15 +323,15 @@ f = fopen(name,"rb"); if(f==NULL){ - if(errno!=ENOENT){ + if(errno!=ENOENT){ fprintf(stderr,_("ERROR: Could not read game state file \"%s\":\n\t%s\n"), - curr->gm.id,strerror(errno)); + curr->gm.id,strerror(errno)); } return errno; } - + // get all levels we've seen. - while(getline(&line,&n,f)>0){ + while(getline(&line, &n, f)>0){ long l; int i; unsigned int j; @@ -228,19 +339,19 @@ char *name=strchr(line,':'); // guard against bad edits if(name && - (strlen(line) - (name - line + 2) >= j)){ - levelstate *le; - name += 2; - name[j]=0; - le = ensure_level(name); - if(le){ - le->highscore=l; - le->in_progress=i; + (strlen(line) - (name - line + 2) >= j)){ + levelstate *le; + name += 2; + name[j]=0; + le = ensure_level(name); + if(le){ + le->highscore=l; + le->in_progress=i; - if(le->highscore) - if(le->gm.unlock_plus + le->gm.num > level_limit) - level_limit = le->gm.unlock_plus + le->gm.num; - } + if(le->highscore) + if(le->gm.unlock_plus + le->gm.num > level_limit) + level_limit = le->gm.unlock_plus + le->gm.num; + } } } } @@ -254,32 +365,32 @@ char *name=strchr(line,':'); // guard against bad edits if(name && - (strlen(line) - (name - line + 2) >= (unsigned)i)){ - levelstate *le; - name += 2; - name[i]=0; - le = ensure_level(name); - if(le) - curr=le; + (strlen(line) - (name - line + 2) >= (unsigned)i)){ + levelstate *le; + name += 2; + name[i]=0; + le = ensure_level(name); + if(le) + curr=le; } } if(sscanf(line,"about %d",&i)==1) if(i==1) - aboutflag=1; - + aboutflag=1; + if(sscanf(line,"pause %d",&i)==1) if(i==1) - pauseflag=1; - + pauseflag=1; + if(sscanf(line,"finish %d",&i)==1) if(i==1) - finishflag=1; + finishflag=1; if(sscanf(line,"select %d",&i)==1) if(i==1) - selectflag=1; - + selectflag=1; + } while(curr->gm.num >= level_limit){ @@ -366,7 +477,7 @@ } void levelstate_finish(){ - int score = graphscore_get_score(&gameboard->g) + + int score = graphscore_get_score(&gameboard->g) + graphscore_get_bonus(&gameboard->g); curr->in_progress=0; if(score > curr->highscore) Index: Makefile =================================================================== --- Makefile (revision 16607) +++ Makefile (working copy) @@ -2,8 +2,11 @@ # Fuck the horse it rode in on # and Fuck its little dog Libtool too +# FreeBSD Installation: +# - install /usr/ports/devel/libgetline + TARGET = gPlanarity -CC = gcc +CC = gcc -ggdb LD = gcc export INSTALL = install PREFIX = /usr/local @@ -11,14 +14,14 @@ ETCDIR = /etc/$(TARGET) MANDIR = $(PREFIX)/man -#DISABLE_NLS = true +DISABLE_NLS = true # White space delimited list of locales you want to support. Defaults to all # available ones. #export WANT_LINGUAS := cs # All subdirs with Makefiles -SUBDIRS = +SUBDIRS = # By default, enable NLS ifeq ($(origin DISABLE_NLS), undefined) @@ -55,7 +58,7 @@ all: all-local all-recursive -all-local: +all-local: pkg-config --cflags "gtk+-2.0 $(GTKVER) cairo $(CAIROVER) freetype2" 1>/dev/null $(MAKE) target CFLAGS='-O2 -ffast-math $(GCF) $(ADD_DEF)' @@ -89,7 +92,7 @@ include $(SRC:.c=.d) endif -target: $(OBJ) +target: $(OBJ) ./touch-version $(LD) $(OBJ) $(CFLAGS) -o $(TARGET) $(LIBS) $(LDF) Index: timer.h =================================================================== --- timer.h (revision 16607) +++ timer.h (working copy) @@ -1,8 +1,8 @@ /* * - * gPlanarity: + * gPlanarity: * The geeky little puzzle game with a big noodly crunch! - * + * * gPlanarity copyright (C) 2005 Monty * Original Flash game by John Tantalo * Original game concept by Mary Radcliffe @@ -11,12 +11,12 @@ * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. - * + * * gPlanarity 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 Postfish; see the file COPYING. If not, write to the * Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. @@ -28,12 +28,13 @@ #include #include #include +#include -#include "nls.h" +//#include "nls.h" extern time_t get_timer(); extern char *get_timer_string(); -extern void set_timer(time_t off); +extern void set_timer(); extern void pause_timer(); extern void unpause_timer(); extern int timer_paused_p(); Index: version.h =================================================================== --- version.h (revision 16607) +++ version.h (working copy) @@ -1,2 +1,2 @@ #define VERSION "$Id$ " -/* DO NOT EDIT: Automated versioning hack [Sat Sep 12 21:09:15 EDT 2009] */ +/* DO NOT EDIT: Automated versioning hack [Mon Oct 5 02:37:54 CEST 2009] */