Here are a bunch of patches to angband-2.9.5-alpha, many of them (the numbered ones) updates from my 293-beta-fixes. Each patch can be applied independently of the others, except 3 patches marked as dependents at the top. -- Hallvard B Furuseth ======================================================================== *.dif file Summary 16-xaw-struct Bugfix: Followup to half-applied 293-beta-fixes patch 26-mk-o-gtk Bugfix: Fix a lowercased `-O' option in Makefile.gtk. 50-gtk-color Bugfix: GDK color handling. 65-visuals Bug: 'Interact with visuals' displays negative char numbers. 66-uchar-inkey Bug: 8-bit keyboard input can misbehave when `char' is signed 67-uchar Bugfix: more `unsigned char' fixes. See 66-uchar-inkey.dif. 68-fmt-fix Bugfix: Fix printf(%ld, s32b_val) --> (long) s32b_val 83-help-opts Bugfix: option.txt flag names still differ from C. 91-vcs-fix Bugfix: main-vcs was buggy. 94-strnicmp Bugfix: my_strnicmp in main-acn.c was quite buggy. conf-datadir Bug: Failure if `--with-libpath=' doesn't end with `/'. gets Bug: gets() is a naughty buffer-overrun invitation. help-avail Bug: When '?' goes to tagged topic, other help is unreachable short-int Bug: 256*256 == 0 on 16-bit hosts. slang Bug: Term_curs_sla() had too many parameters. 31-fix-conf-xaw Portability: Put back Configure -Xaw paranoia from 2.9.2. 64-shift-unsigned Portability: Change (integer << n) to (unsigned integer << n) aix-term Portability: Avoid name conflict with `struct term' on AIX. usleep Portability: Obey HAVE_USLEEP. Rename private usleep. 28-mk-typo Cleanup: Minor typos in Makefiles. mk-dep Cleanup: Fix makefile dependencies in Makefile.. noop-cast Cleanup: Kill off some no-op casts (XKeyEvent* -> XKeyEvent*) randart-namelist Cleanup: build_prob() could run off end of names_list[] sizeof-basic Cleanup: Make N_ELEMENTS() global. sizeof-color Cleanup: 16/256 -> BASIC_COLORS/MAX_COLORS for colormaps sizeof-fgets Cleanup: *fgets(, buffer, NUMBER) -> *fgets(,,sizeof(buffer)) sizeof-path Bugfix/Cleanup: number -> sizeof(buffer) for pathname buffers sizeof-various Bugfix/Cleanup: sizeof patches of various types. warn-arr Warning cleanup: Change `&array' to `array'. 23-compile Feature: Expand on compile.txt instructions about configure. 25-mk-std Feature: Merge modules GTK,LSL,SLA,VCS,XPJ into Makefile.std. conf-gtk Feature: Implement `./configure --enable-gtk'. fulldump Feature: OBJECT_FLAGS_KNOWN cmd for character/endgame dump. help-better Feature: Help in more places. Directly to topic more places. help-help Feature: Update help.hlp with description of browser keys. lost-art OPTION: Tell user when he lost an artifact forever. recursive-setuid Feature: Allow nested drop/grab of privileges. userdir-delay Feature: Delay mkdir(~/.angband/) until needed. 21-comments Trivial: Add a source code comment (warning to programmers) randart-mem Trivial: Save 40K memory with tables of smaller datatypes. ======================================================================== FULL DESCRIPTION OF PATCHES (copied from each patch) ====== 16-xaw-struct.dif ====== Bugfix: Followup to half-applied 293-beta-fixes patch 15-xaw-struct.dif. main-xaw assumes XFree86 unless OLDXAW is #defined. That fails since OLDXAW is an XFree86 invention; standard X11R6 doesn't #define it. Fix, from : ====== 21-comments.dif ====== Trivial: Add a source code comment (warning to programmers) ====== 23-compile.dif ====== Feature: Expand on the instructions in compile.txt about configure. Note that readme.txt needs a similar update. it contains an outdated copy of this section of compile.txt. Maybe you want to replace it, or maybe you want to merge them and mention Makefile.std. ====== 25-mk-std.dif ====== Feature: Merge modules GTK, LSL, SLA, VCS, and XPJ into Makefile.std. (With warnings about VCS and SLA not being tested for a while.) Also add missing dependencies `main-xaw.o main-xpj.o: maid-x11.h'. (That belongs in the mk-dep patch, but would conflict with this patch.) - Adding XPJ, VCS and now GTK reflects what configure does (with my `configure --enable-gtk' patch). Besides, Makefile.gtk is buggy and out of date, and VCS has no Makefile. - The LSL entry copies exactly what Makefile.lsl does (except the dependencies have been updated). - VCS and SLA had no Makefiles, and get warnings about being untested. Note: If USE_TRANSPARENCY (whatever that is) is incompatible with GTK, - the line in the patch with USE_TRANSPARENCY should not mention GTK, - main-gtk.c needs this after `#ifdef USE_GTK': #ifdef USE_TRANSPARENCY %: error USE_GTK does not support USE_TRANSPARENCY. #endif Makefile.gtk and Makefile.lsl can now be deleted. ====== 26-mk-o-gtk.dif ====== Bugfix: Fix a lowercased `-O' option in Makefile.gtk. [Update of 293-beta-fixes*.tar.gz:26-mk-o-gtk.dif] An `-O' (optimize) was lowercased, causing the next argument to be taken as the output file name. Which means Makefile.gtk never worked, BTW. So you might delete it in favour of the GTK addition to Makefile.std in patch 25-mk-std.dif and the `configure --enable-gtk' patch. ====== 28-mk-typo.dif ====== Cleanup: Minor typos in Makefiles. - Spelling error in comment in Makefile.std & Makefile.gtk. ====== 31-fix-conf-xaw.dif ====== Portability: Put back some Configure paranoia about -Xaw (from angband 2.9.2). This tests that X11 Athena will compile, not only that the -lXaw will link. (The 2.9.2 test said Xaw #include files could be outside the normal X11 tree; the 2.9.3 test does not catch that.) Configure uses the same Athena #include files as Angband itself. This patch does not try to find the missing #includes like 2.9.2 did, it just disables Athena if it doesn't compile+link. I don't remember what was wrong with the 2.9.2 Athena detection, and didn't want to put back a possible problem. ====== 50-gtk-color.dif ====== Bugfix: GDK color handling. * If gdk_colormap_alloc_color() failed, gtk would set the foreground anyway - to the color in an uninitialized variable. It would then spew out repeating "Couldn't allocate color" messages, I changed that so the message is only printed once. To reproduce, start Netscape or something on a display with few colors, followed by `angband -mgtk'. * Also, it originally did gdk_colormap_alloc_color(, , writeable=TRUE, best_match=FALSE) which seems silly, so I swapped them. 'best_match' means: use the best available match when the exact colour cannot be allocated. 'writable' means: "can be changed by gdk_color_change()", but the Angband code doesn't call gdk_color_change(). With the original code, the allocation always failed on my machine. Still, I don't know gtk so it's possible there is some sense to the original code. * Finally I factored this code out to a single function. ====== 64-shift-unsigned.dif ====== Portability: Change (integer << n) to (unsigned integer << n). [Slight modification of 293-beta-fixes.tar.gz:64-shift-unsigned.dif. Also obsoletes easyread-292.tar.gz:ansi.dif.] To shift into the sign bit of a signed integer causes undefined behavior. (Usually it either acts as expected or signals an error.) E.g. operations like (1L << 31) if 'long' is 32 bits wide. This patch: - changes (long_constant << foo) to ((u32b) constant << foo). All cases affect code where the result is assigned to or AND/ORed with a variable of type u32b. (I could have used 'unsigned long' instead, but this is faster on hosts where 'long' is wider than 'u32b'.) - changes '1 << foo' to '1U << foo'. In all cases, the result meets an unsigned ('byte' or 'u16b') variable. - simplifies the BOOK1/BOOK2 macros a bit since they are patched anyway: Makes sure X in BOOK*'s the `1 << X' expression is positive even when not evaluated, since some idiot compilers complain about even unreachable '1 << -1' expressions. Accordingly, this patch should have no effect on hosts/compilers where it is safe to shift into the sign bit - except it's an optimization on hosts where 'long' is a larger type than 'u32b'. (I'm sure there are other overflow problems in the code, but these were so easy to spot.) ====== 65-visuals.dif ====== Bug: 'Interact with visuals' can display negative char numbers. Also a junk character is left after it when you get back to small values, since -128 takes 4 characters and the format assumes max 3. To reproduce: CC='gcc -fsigned-char' ./configure # or use a host where char is signed ... enter Interact with Visual menu '7'/'8'/'9' 'ccccc'... -> -128 ... -1 'ESC' This happens since dc and cc are possibly signed 'char' values and printed with %d. The fix is to declare it as byte or print (byte)cc. (BTW, printing with %u doesn't help, that just prints a huge number.) ====== 66-uchar-inkey.dif ====== Bug: 8-bit keyboard input can misbehave when `char' is signed. The old source code generally assumes that character data is 7-bit. That will fail in a number of ways for 8-bit character data on hosts where `char' is signed (and thus 8-bit characters are negative). The most common error is to call the ctype.h functions with `char' arguments. These functions expect an argument in the *range* of `unsigned char' (or EOF), thus `char' data must be cast to `unsigned char' before they are passed to ctype.h functions. (The actual integer type of the argument is irrelevant, of course.) This patch fixes the simplest cases: Keyboard input (from inkey(), get_com() and get_string() which is passed to ctype.h functions. It's simple enough that each chunk can be applied independently of the other chunks, if that's of any interest. Note: My 8-bit patches do not change any behavior for any 7-bit character values. Note: My 8-bit patches do not make isalpha() & co treat any 8bit latin-1 characters as letters, since Angband uses the C locale. They just make sure these functions do not return garbage. (To make them letters, one would call setlocale(LC_CTYPE,""). However, that would break code like "num = (isalpha(c) ? tolower(c)-'a' : -1);".) ====== 67-uchar.dif ====== Bugfix: more `unsigned char' fixes. See 66-uchar-inkey.dif for explanation. This one fixes various fairly obvious details, each change is independent of the others: Handle 8-bit characters in files when checking menu item numbers in show_file(). Don't break on 8-bit X11 resource names. Don't break on: #1: 8-bit font data, #2: 8-bit X11 resource names. Don't break on 8-bit in a -d= command line option. Handle any 8-bit characters in randart's names_list[] Handle 8-bit characters in user name Handle 8-bit input to my_fgets() Handle 8-bit c_roff() output ====== 68-fmt-fix.dif ====== Bugfix: Fix printf(%ld, s32b_val) --> printf(%ld, (long) s32b_val) It failed on 64-bit hosts, where it did printf(%ld, int). ====== 83-help-opts.dif ====== Bugfix: Followup to 82-help-opts.dif. option.txt flag names differ from C. My old patch 82-help-opts.dif was incorrectly applied. It updated the help file option.txt to use the names from option_text[] in src/tables.c. This patch completes the change. Old option name Current option.txt name New name, from tables.c find_cut -> run_cut -> run_cut_corners find_examine -> run_examine -> run_use_corners ====== 91-vcs-fix.dif ====== Bugfix: main-vcs was buggy. - s_width, s_height, cx, cy were declared as 'int' even though they were read() in and written as single-byte entities. (That would "accidentally" work on little-endian hosts.) - init_vcs() was defined with no args but declared and called with 2 args. - coredump if ttyname() failed: NULL pointer would be followed. - fix a file descriptor leak if init_vcs() failed. ====== 94-strnicmp.dif ====== Bugfix: my_strnicmp in main-acn.c was quite buggy. This patch combines 293-beta-fixes-2.tar.gz:92-strnicmp.dif (which was wrong) + 293-beta-fixes-3.tar.gz:93-fix-strnicmp.dif Fix my_strnicmp() to: * cast tolower's arguments to unsigned char (since tolower expects that), * return 0 if the n-length substrings are equal, * return 0 if the strings are equal and shorter than n, * negate the return value: return negative if arg1, not arg2, is smaller. ====== aix-term.dif ====== Portability: Avoid name conflict with `struct term' on AIX. main-gcu.c didn't compile on AIX. (A cleaner fix might be to rename struct term to struct Term or Angband_term and maybe typedef term -> Term and variable Term -> term, but that is a _lot_ more typing:-) ====== conf-datadir.dif ====== Bug: Install fails if `--with-libpath=' doesn't end with `/'. To reproduce: ./configure --with-setgid=games --with-libpath=/tmp/angband make install This installs directories /tmp/angbanddata/, /tmp/angbandscript/ and so on. Fix: Append "/" to game_datadir unless it is empty or ends with "/". (If it's empty, appending "/" would give the root directory, which is *very* wrong:-) ====== conf-gtk.dif ====== Feature: Implement `./configure --enable-gtk'. If --enable-gtk, run gtk-config to set gtk CFLAGS and LIBS, skip AC_PATH_EXTRA, and try to check that it works. Note: gtk-config and AC_PATH_XTRA both set CFLAGS and LIBS for X11, so it seems best to only use one of them. Since AC_PATH_XTRA puts options both before and after where other X11 libraries should be put, I imagine the ordering could be ruined if we used both. So, trust gtk-config for now. So far I've had no problems. If problems do crop up, we can let --with-x11 put back AC_PATH_XTRA anyway and see if that works better, or make --enable-gtk imply --without-x11 by default. ====== fulldump.dif ====== Feature: OBJECT_FLAGS_KNOWN command 'F' for character/endgame dump. Add an 'F' command in the character dump screen, which dumps all known abilities of each item instead of just the random abilities. That way it's easier to use a character dump to pick the items to wear; you don't have to remember e.g. that Westernesse gives See Invisible. Let 'F' in the endgame character dump do the same. (Previously both 'f' and 'F' just dumped random abilities.) [Update of easyread-292.tar.gz:fulldump.dif] Patch: Add the 'F' command to character dump -- cmd4.c hunk 1-2: Update the help message. cmd4.c hunk 3-4: When 'F' is pressed, give TRUE to file_character(,full). Make 'F' in endgame dump do the same -- files.c hunk 7-8 (last 2 hunks). Implement the previously unused `full' argument to file_character() -- files.c hunk 1-6: Set `mode' from `full'. Replace identify_random_gen(x), which merely does identify_fully_aux2(x,OBJECT_FLAGS_RANDOM), with identify_fully_aux2(x,mode). defines.h, object1.c, externs.h: Make identify_fully_aux2() and modes of object_flags_aux() global. ====== gets.dif ====== Bug: gets() is a naughty buffer-overrun invitation. Use fgets() instead. In this case, it the terminating \n doesn't matter. ====== help-avail.dif ====== Bug: When '?' takes you to a tagged topic, other helpfiles are unreachable. [Rewrite of part of of help-292beta.diff.gz.] To reproduce: Enter "User Interface Options". Push '?' to get help to some option. Push '?' again and you are taken *out* of help; there is no path to help.hlp. Well, you could use '%' (Goto File), but that's clumsy. This patch to show_file() makes another '?' take you to help.hlp in that case. It also makes '?' enter Help from infodumps like Known Uniques (recognized by != NULL). Note: If you don't like static variables, you can make help_level an extra parameter to show_file() and drop old_help_level. Or tell me to do so. Note: It may be that the now-unused parameter was intended to cover this function, but I didn't know so I didn't touch it. Besides, a change now to make do that, without changing the prototype of show_file to something that gives a compiler error when called with today's arguments, would probably have to be checked against all Angband variants. ====== help-better.dif ====== Feature: Help in more places. Go directly to a help topic from more places. [This is an update of part of help-292beta.diff.gz.] The patch makes Angband accept the '?' key in more places, and make more of them take the user directly to the relevant file or section instead of to help.hlp. The files.c and externs.h patches add do_cmd_help_target(), a generalized do_cmd_help(). The rest add more calls to help, and more help targeets to the help files. ====== help-help.dif ====== Feature: Update help.hlp with a description of the browser keys. [Slightly modified extract from help-292beta.diff.gz.] ====== lost-art.dif ====== OPTION: Tell the user when he has left a level and lost an artifact forever. Note: I'm not quite sure whether 'if (p_ptr->playing)' is the correct test for whether the game is being played; I don't know the flags that well. It seems to work. Note: The logic of the tests when !defined(NOTIFY_LOST_ARTIFACTS) is unchanged. Note: Maybe this should be a gameplay user option, but I don't know how to add user options. [Slightly updated from easyread-292.tar.gz:lost-art.dif.] ====== mk-dep.dif ====== Cleanup: Update makefile dependencies in Makefile.. Add missing dependency lines: l-*.o in Makefile. script.o use-obj.o in Makefile. main-lsl.o in Makefile.lsl ! maid-x11.o in Makefile.std Add missing .h files: cmd6.o init2.o wizard2.o: script.h in Makefile. init*.o: init.h in Makefile. randart.o: init.h in Makefile. readdib.o: remove $(INCS) in Makefile.cyg main-x11.o main-xaw.o: maid-x11.h in Makefile.lsl script.o: script.h lua/*.h in Makefile.std Two dependencies are not added, since 25-mk-std.dif adds them: main-x11.o main-xaw.o: + maid-x11.h in Makefile.std. (There are some other missing dependencies, e.g. main-ami.o should depend on sound-ami.h if defined(USE_AMI). However, sound-ami.h is missing, so that dependency seemed a bit dangerous.) Note: Instead of the LSL patches you might want to delete Makefile.lsl and instead apply 25-mk-std.dif to include LSL in Makefile.std. ====== noop-cast.dif ====== Cleanup: Kill off some no-op casts (XKeyEvent* -> XKeyEvent*) Removes unnecessary code, does not change its operation. ====== randart-mem.dif ====== Trivial: Save 40K memory with tables of smaller datatypes. ====== randart-namelist.dif ====== Cleanup: build_prob() runs off end of names_list[] if last char is alphabetic. (Currently it isn't alphabetic, but someone might modify it.) ====== recursive-setuid.dif ====== Feature: Allow nested drop/grab of privileges. *** THIS PATCH IS NEEDED BY userdir-delay.dif *** The new function `bool safe_setuid_set(bool grab)' can be used to drop/grab privileges regardless of the previous setting. It returns the old setting, so we can use that to restore the old setting later. Changed safe_setuid_drop() and safe_setuid_grab() to be interfaces to it, though they don't emply the nesting feature. If you are interested, there is a slight semantic change in how *incorrect* use of safe_setuid_() will misbehave: foo() { safe_setuid_grab(); /* Write file#1 */ safe_setuid_drop(); } bar() { safe_setuid_grab(); foo(); /* Write file#2 */ safe_setuid_drop(); } Previously bar() would write file#1 _with_ permissions and file#2 _without_ permissions if HAVE_SETEGID or SAFE_SETUID_POSIX were defined, but reverse this otherwise (file#1 with, file#2 without perms.) With this change, we always get the former behaviour. Such cases, if any exist, can now be fixed by writing foo() as foo() { bool privileged = safe_setuid_set(TRUE); /* Write file#1 */ safe_setuid_set(privileged); } though except in very low-level routines you'd probably want to explicitly drop permissions and rewrite bar() instead. ====== short-int.dif ====== Bug: 256*256 == 0 on 16-bit hosts. Use 256L instead. ====== sizeof-basic.dif ====== Cleanup: Make N_ELEMENTS() global. ** THIS PATCH IS NEEDED BY OTHER SIZEOF PATCHES. ** Move N_ELEMENTS() from wizard1.c to defines.h. ====== sizeof-color.dif ====== Cleanup: 16/256 -> BASIC_COLORS/MAX_COLORS for colormaps ** THIS PATCH DEPENDS ON sizeof-basic.dif ** This patch gets rid of a bunch of magic constants. It: - Replaces 16 and 256 with BASIC_COLORS and MAX_COLORS many places, - #defines a few similar constants - typically as 16 or 32 - in files where I couldn't prove that the 16 is the "same" 16 as BASIC_COLORS, and not just a local colorcount which happens to equal BASIC_COLORS, E.g. NUM_PENS NUM_PUBPENS in main-ami.c. - Introduces a few N_ELEMENTS() calls where none of the above seemed proper. - Replaces (attr & 0x0F) with (attr % BASIC_COLORS). I checked that the "attr"s are nonnegative. - Expresses 8 color pairs as BASIC_COLORS/2 in main-gcu.c. - In main-ami.c, p in PEN(p) calls is always either a small constant or (expr & 0x0F), so I moved the '& 0x0F' into the #definition of PEN() and forced the operation to be unsigned. - Expresses COLOR_OFFSET 240 as (256 - BASIC_COLORS) in main-dos.c and main-lsl.c. I suspect the 256 is MAX_COLORS but couldn't prove it. ====== sizeof-fgets.dif ====== Cleanup: *fgets(, buffer, NUMBER) -> *fgets(,, sizeof(buffer)) This patch does not change the compiled code, it only gets rid of magic constants. Tell me if you prefer me to #define these constants instead - after all a change in buffer sizes here affect the max accepted lengths of lines in input files. ====== sizeof-path.dif ====== Bugfix/Cleanup: number -> sizeof(buffer) for pathname buffers. This patch gets rid of a bunch of magic constants. It introduces sizeof() in: - path_build(,length,,) - path_parse(,length,) - my_fopen_temp(,length) - strncpy(filename,,length) - path[last byte] = '\0'; It causes a few changes to compiled code: - Bugfix: Reduces a 1024 to 256 in main-dos.c:play_song(). - Increases a 1024 to 4096 in main-ibm.c:init_ibm() and to 2048 in monster1.c:describe_monster_desc(). The resulting strings are not used for anything else than opening a file. ====== sizeof-various.dif ====== Bugfix/Cleanup: sizeof patches of various types. ** THIS PATCH DEPENDS ON sizeof-basic.dif ** Some trivial changes, one bugfix: Change char str[1024]; sprint(str, "format", buf) in init2.c to char str[sizeof(buf) + sizeof("format"]; ... ====== slang.dif ====== Bug: Term_curs_sla() had too many parameters. ====== userdir-delay.dif ====== Feature: Delay mkdir(~/.angband/) until that directory is needed. *** THIS PATCH DEPENDS ON recursive-setuid.dif *** I always find it irritating when programs create useless junk in $HOME. Changes: - Change create_user_dir() to create_user_dir_when_needed(file), which temporarily drops privileges (if any) and creates ANGBAND_USER_DIR if starts with that directory. Call it from my_fopen() & co. - Also keep track of whether or not ANGBAND_USER_DIR has been created from PRIVATE_USER_PATH at all. ====== usleep.dif ====== Portability: Obey autoconf.h:HAVE_USLEEP. Rename private usleep to my_usleep. This patch treats usleep the way Configure recommends. - Rename HAS_USLEEP (which is set "by hand" in h-config.h) to configure's name HAVE_USLEEP (which already exists in autoconf.h but is not used). - Obey autoconf.h's (already existing) setting when defined(HAVE_CONFIG_H), otherwise retain the old code to decide whether or not to define a private usleep(). - if !HAVE_USLEEP, `#define usleep my_usleep' in extern.h. This avoids collision with the system usleep if one exists but HAVE_USLEEP is not defined. ====== warn-arr.dif ====== Warning cleanup: Change `&array' to `array'. cc on OSF Alpha complains about &array (but does accept it). The &'s are superfluous here.