summary refs log tree commit diff homepage
diff options
context:
space:
mode:
-rw-r--r--.gitignore3
-rw-r--r--play.c41
2 files changed, 33 insertions, 11 deletions
diff --git a/.gitignore b/.gitignore
index 07811c8..a0eaf1b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,6 @@
 *.o
-2048.scores
+*.scores
+*.weekly
 chroot.tar
 config.mk
 play
diff --git a/play.c b/play.c
index 520b563..268530e 100644
--- a/play.c
+++ b/play.c
@@ -111,7 +111,9 @@ static char board[BoardWidth + 1];
 static char *boardTitle(const char *title) {
 	snprintf(
 		board, sizeof(board),
-		"%*s", (int)(BoardWidth + strlen(title)) / 2, title
+		"%*s%*s",
+		(int)(BoardWidth + strlen(title)) / 2, title,
+		BoardWidth, ""
 	);
 	return board;
 }
@@ -196,7 +198,8 @@ int main(int argc, char *argv[]) {
 	}
 
 	curse();
-	FILE *file = scoresOpen("2048.scores");
+	FILE *top = scoresOpen("2048.scores");
+	FILE *weekly = scoresOpen("2048.weekly");
 
 #ifdef __FreeBSD__
 	int error = cap_enter();
@@ -205,7 +208,10 @@ int main(int argc, char *argv[]) {
 	cap_rights_t rights;
 	cap_rights_init(&rights, CAP_READ, CAP_WRITE, CAP_SEEK, CAP_FLOCK);
 
-	error = cap_rights_limit(fileno(file), &rights);
+	error = cap_rights_limit(fileno(top), &rights);
+	if (error) err(EX_OSERR, "cap_rights_limit");
+
+	error = cap_rights_limit(fileno(weekly), &rights);
 	if (error) err(EX_OSERR, "cap_rights_limit");
 #endif
 
@@ -214,11 +220,12 @@ int main(int argc, char *argv[]) {
 		.score = play2048(),
 	};
 
-	scoresRead(file);
+	curse();
+
+	scoresRead(weekly);
 	size_t index = scoresInsert(new);
+	draw("WEEKLY SCORES", index);
 
-	curse();
-	draw("TOP SCORES", index);
 	if (index < ScoresLen) {
 		attr_set(A_BOLD, 0, NULL);
 		while (!new.name[0]) {
@@ -231,16 +238,30 @@ int main(int argc, char *argv[]) {
 			if (*ch < ' ') *ch = ' ';
 		}
 
-		scoresLock(file);
-		scoresRead(file);
+		scoresLock(weekly);
+		scoresRead(weekly);
 		scoresInsert(new);
-		scoresWrite(file);
-		fclose(file);
+		scoresWrite(weekly);
+		fclose(weekly);
 	}
 
 	noecho();
 	curs_set(0);
 	getch();
+
+	scoresRead(top);
+	index = scoresInsert(new);
+	draw("TOP SCORES", index);
+
+	if (index < ScoresLen) {
+		scoresLock(top);
+		scoresRead(top);
+		scoresInsert(new);
+		scoresWrite(top);
+		fclose(top);
+	}
+
+	getch();
 	endwin();
 	printf(
 		"This program is AGPLv3 Free Software!\n"
7f8e947a36&follow=1'>Set EXINITJune McEnroe 2021-01-09Add c -t flag to print expression typeJune McEnroe 2021-01-05Update taglineJune McEnroe