qtads: remove 2.0.1 since it's in portage now
[gentoo-interactive-fiction.git] / games-engines / git / files / git-1.2.2-gargoyle.patch
blobf965b233585050ed0516c8f09b26d06ef63f94dc
1 Source: extracted from gargoyle-2008-12-25-sources.zip
2 Upstream: Gentoo-specific hack
3 Reason: use Gargoyle extension functions to set a nice window title;
4 also print error messages in a possibly nicer way
6 --- git-1.2.2/git_unix.c~ 2009-01-21 18:12:38.000000000 +0000
7 +++ git-1.2.2/git_unix.c 2009-01-24 18:16:14.000000000 +0000
8 @@ -8,6 +8,8 @@
9 #include <glk.h>
10 #include <glkstart.h> // This comes with the Glk library.
12 +#include <string.h>
14 #ifdef USE_MMAP
15 #include <fcntl.h>
16 #include <sys/mman.h>
17 @@ -25,24 +27,70 @@
18 #define CACHE_SIZE (256 * 1024L)
19 #define UNDO_SIZE (512 * 1024L)
21 +int gHasInited = 0;
23 +#ifdef GARGLK
25 +void fatalError (const char * s)
27 + winid_t win;
28 + if (!gHasInited)
29 + {
30 + win = glk_window_open(0, 0, 0, wintype_TextBuffer, 0);
31 + glk_set_window(win);
32 + }
33 + /* pray that this goes somewhere reasonable... */
34 + glk_put_string("\n*** fatal error: ");
35 + glk_put_string((char*)s);
36 + glk_put_string(" ***\n");
37 + glk_exit();
40 +#else
42 void fatalError (const char * s)
44 fprintf (stderr, "*** fatal error: %s ***\n", s);
45 exit (1);
48 +#endif /* GARGLK */
50 #ifdef USE_MMAP
51 // Fast loader that uses some fancy Unix features.
53 const char * gFilename = 0;
54 +char * gStartupError = 0;
56 int glkunix_startup_code(glkunix_startup_t *data)
58 +#ifdef GARGLK
59 + {
60 + char buf[32];
61 + sprintf(buf, "Git %d.%d.%d", GIT_MAJOR, GIT_MINOR, GIT_PATCH);
62 + garglk_set_program_name(buf);
63 + sprintf(buf, "Git %d.%d.%d by Iain Merrick\n",
64 + GIT_MAJOR, GIT_MINOR, GIT_PATCH);
65 + garglk_set_program_info(buf);
66 + }
67 +#endif /* GARGLK */
69 if (data->argc <= 1)
71 - printf ("usage: git gamefile.ulx\n");
72 - return 0;
73 + gStartupError = "No file given";
74 + return 1;
77 +#ifdef GARGLK
78 + {
79 + char *s;
80 + s = strrchr(data->argv[1], '\\');
81 + if (s) garglk_set_story_name(s+1);
82 + s = strrchr(data->argv[1], '/');
83 + if (s) garglk_set_story_name(s+1);
84 + }
85 +#endif /* GARGLK */
87 gFilename = data->argv[1];
88 return 1;
90 @@ -53,6 +101,9 @@
91 struct stat info;
92 const char * ptr;
94 + if (gStartupError)
95 + fatalError(gStartupError);
97 file = open (gFilename, O_RDONLY);
98 if (file < 0)
99 goto error;
100 @@ -61,45 +112,72 @@
101 goto error;
103 if (info.st_size < 256)
105 - fprintf (stderr, "This is too small to be a glulx file.\n");
106 - exit (1);
108 + fatalError("This is too small to be a glulx file.");
110 ptr = mmap (NULL, info.st_size, PROT_READ, MAP_PRIVATE, file, 0);
111 if (ptr == MAP_FAILED)
112 goto error;
114 + gHasInited = 1;
116 git (ptr, info.st_size, CACHE_SIZE, UNDO_SIZE);
117 munmap ((void*) ptr, info.st_size);
118 return;
120 error:
121 - perror ("git");
122 - exit (errno);
123 + sprintf(errmsg, "git: %s", strerror(errno));
124 + fatalError(errmsg);
127 #else
128 // Generic loader that should work anywhere.
130 strid_t gStream = 0;
131 +char * gStartupError = 0;
133 int glkunix_startup_code(glkunix_startup_t *data)
135 +#ifdef GARGLK
137 + char buf[32];
138 + sprintf(buf, "Git %d.%d.%d", GIT_MAJOR, GIT_MINOR, GIT_PATCH);
139 + garglk_set_program_name(buf);
140 + sprintf(buf, "Git %d.%d.%d by Iain Merrick\n",
141 + GIT_MAJOR, GIT_MINOR, GIT_PATCH);
142 + garglk_set_program_info(buf);
144 +#endif /* GARGLK */
146 if (data->argc <= 1)
148 - printf ("usage: git gamefile.ulx\n");
149 - return 0;
150 + gStartupError = "No file given";
151 + return 1;
154 +#ifdef GARGLK
156 + char *s;
157 + s = strrchr(data->argv[1], '\\');
158 + if (s) garglk_set_story_name(s+1);
159 + s = strrchr(data->argv[1], '/');
160 + if (s) garglk_set_story_name(s+1);
162 +#endif /* GARGLK */
164 gStream = glkunix_stream_open_pathname ((char*) data->argv[1], 0, 0);
165 return 1;
168 void glk_main ()
170 + if (gStartupError)
171 + fatalError(gStartupError);
173 if (gStream == NULL)
174 fatalError ("could not open game file");
176 + gHasInited = 1;
178 gitWithStream (gStream, CACHE_SIZE, UNDO_SIZE);