Changeset 127
- Timestamp:
- 05/11/07 20:18:29 (2 years ago)
- Files:
-
- trunk/configure.ac (modified) (2 diffs)
- trunk/src/Makefile.src (modified) (2 props)
- trunk/src/Makefile.std (modified) (2 props)
- trunk/src/autoconf.h.in (modified) (1 diff)
- trunk/src/externs.h (modified) (1 diff)
- trunk/src/h-config.h (modified) (4 diffs)
- trunk/src/main-sdl.c (modified) (3 diffs)
- trunk/src/util.c (modified) (1 diff)
- trunk/src/wizard1.c (modified) (1 diff)
- trunk/src/z-file.c (modified) (1 diff)
- trunk/src/z-file.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/configure.ac
r84 r127 172 172 dnl AC_HEADER_STDBOOL -- not yet 173 173 AC_HEADER_TIME 174 AC_CHECK_HEADERS([unistd.h fcntl.h limits.h stdint.h sys/time.h termios.h])174 AC_CHECK_HEADERS([unistd.h fcntl.h dirent.h limits.h stdint.h sys/time.h termios.h]) 175 175 176 176 dnl Check for types. … … 187 187 AC_FUNC_STAT 188 188 AC_FUNC_SELECT_ARGTYPES 189 AC_CHECK_FUNCS([memmove memset strrchr mkdir strtol usleepmkstemp setegid can_change_color])189 AC_CHECK_FUNCS([memmove memset strrchr mkdir strtol mkstemp setegid can_change_color]) 190 190 191 191 dnl XXX: Work around some autoconf bugs. trunk/src/Makefile.src
- Property svn:mime-type set to text/plain
- Property svn:eol-style set to native
trunk/src/Makefile.std
- Property svn:mime-type set to text/plain
- Property svn:eol-style set to LF
trunk/src/autoconf.h.in
r89 r127 6 6 /* Define to 1 if you have the `can_change_color' function. */ 7 7 #undef HAVE_CAN_CHANGE_COLOR 8 9 /* Define to 1 if you have the <dirent.h> header file. */ 10 #undef HAVE_DIRENT_H 8 11 9 12 /* Define to 1 if you have the <fcntl.h> header file. */ trunk/src/externs.h
r120 r127 791 791 792 792 #ifdef SET_UID 793 # ifndef HAVE_USLEEP794 /* util.c */795 extern int usleep(unsigned long usecs);796 # endif /* HAVE_USLEEP */797 793 extern void user_name(char *buf, size_t len, int id); 798 794 #endif /* SET_UID */ trunk/src/h-config.h
r89 r127 67 67 */ 68 68 #if !defined(MACH_O_CARBON) && !defined(WINDOWS) && \ 69 !defined(MSDOS) && !defined(USE_EMX) && \ 70 !defined(AMIGA) && !defined(RISCOS) && !defined(GAMEBOY) 69 !defined(MSDOS) && !defined(RISCOS) && !defined(GAMEBOY) 71 70 # define SET_UID 72 71 #endif … … 105 104 # define FILE_TYPE(X) (_ftype = (X)) 106 105 107 108 /* Mac OS X has usleep(). */109 #ifndef HAVE_USLEEP110 # define HAVE_USLEEP111 #endif112 113 106 #else 114 107 … … 117 110 #endif 118 111 112 119 113 /* 120 * OPTION: Define "HAVE_USLEEP" only if "usleep()" exists. 121 * Note that this is only relevant for "SET_UID" machines. 122 * 123 * (Set in autoconf.h when HAVE_CONFIG_H -- i.e. when configure is used.) 114 * Assume UNIX-style directory handling. 124 115 */ 125 #if defined(SET_UID) && !defined(HAVE_CONFIG_H)126 # define HAVE_USLEEP116 #if !defined(HAVE_CONFIG_H) && !defined(WINDOWS) && !defined(RISCOS) 117 #define HAVE_DIRENT_H 127 118 #endif 128 129 119 130 120 … … 132 122 133 123 124 trunk/src/main-sdl.c
r122 r127 3446 3446 char buf[1024]; 3447 3447 FILE *fff; 3448 ang_dir *dir; 3448 3449 3449 3450 /* Build the gfx path */ … … 3453 3454 /* Build the "font" path */ 3454 3455 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "font"); 3455 3456 /* Allocate the path */3457 3456 ANGBAND_DIR_XTRA_FONT = string_make(path); 3458 3457 … … 3464 3463 3465 3464 for (i = 0; i < MAX_FONTS; i++) 3466 {3467 3465 FontList[i] = NULL; 3468 } 3469 3470 /* Load the fonts */ 3471 path_build(path, sizeof(path), ANGBAND_DIR_XTRA_FONT, "fontlist.txt"); 3472 validate_file(path); 3473 3474 /* Open the file */ 3475 fff = my_fopen(path, "r"); 3476 3477 /* Process the file */ 3478 while (0 == my_fgets(fff, buf, sizeof(buf))) 3479 { 3480 if (!buf[0]) continue; 3481 3482 if (buf[0] == '#') continue; 3483 3484 FontList[num_fonts++] = string_make(buf); 3485 3466 3467 3468 /** Scan for fonts **/ 3469 3470 /* Open the directory */ 3471 dir = my_dopen(ANGBAND_DIR_XTRA_FONT); 3472 if (!dir) return; 3473 3474 /* Read every font to the limit */ 3475 while (my_dread(dir, buf, sizeof buf)) 3476 { 3477 /* Check for at least an extension */ 3478 signed extension_pos = strlen(buf) - 4; 3479 if (extension_pos <= 0) continue; 3480 3481 /* Check for file extension */ 3482 if (strcmp((buf + extension_pos), ".fon") == 0) 3483 FontList[num_fonts++] = string_make(buf); 3484 3485 /* Don't grow to long */ 3486 3486 if (num_fonts == MAX_FONTS) break; 3487 3487 } 3488 3489 my_fclose(fff); 3488 3489 /* Done */ 3490 my_dclose(dir); 3490 3491 } 3491 3492 trunk/src/util.c
r120 r127 11 11 #include "angband.h" 12 12 #include "randname.h" 13 14 15 #ifdef SET_UID16 17 # ifndef HAVE_USLEEP18 19 /*20 * struct timeval (used below) requires sys/time.h.21 *22 * Unix systems that neither have usleep nor sys/time.h are screwed, since23 * they have no way of delaying.24 */25 #include <sys/time.h>26 27 /*28 * For those systems that don't have "usleep()" but need it.29 *30 * Fake "usleep()" function grabbed from the inl netrek server -cba31 */32 int usleep(unsigned long usecs)33 {34 struct timeval Timer;35 36 /* Paranoia -- No excessive sleeping */37 if (usecs > 4000000L) quit("Illegal usleep() call");38 39 /* Wait for it */40 Timer.tv_sec = (usecs / 1000000L);41 Timer.tv_usec = (usecs % 1000000L);42 43 /* Wait for it */44 if (select(0, NULL, NULL, NULL, &Timer) < 0)45 {46 /* Hack -- ignore interrupts */47 if (errno != EINTR) return -1;48 }49 50 /* Success */51 return 0;52 }53 54 # endif /* HAVE_USLEEP */55 #endif /* SET_UID */56 57 13 58 14 trunk/src/wizard1.c
r16 r127 10 10 11 11 #include "angband.h" 12 #include "z-file.h" 12 13 13 14 trunk/src/z-file.c
r48 r127 760 760 #endif /* RISCOS */ 761 761 762 /*** Directory scanning code ***/ 763 764 /* 765 * This code was originally written for the SDL port so it could scan for fonts 766 * without needing a fontlist text file. 767 */ 768 769 770 /* 771 * Opens a directory handle. 772 * 773 * `dirname` must be a system-specific pathname to the directory 774 * you want scanned. 775 * 776 * Returns a valid directory handle on success, NULL otherwise. 777 */ 778 ang_dir *my_dopen(const char *dirname); 779 780 781 /* 782 * Reads a directory entry. 783 * 784 * `dir` must point to a directory handle previously returned by my_dopen(). 785 * `fname` must be a pointer to a writeable chunk of memory `len` long. 786 * 787 * Returns TRUE on successful reading, FALSE otherwise. 788 * (FALSE generally indicates that there are no more files to be read.) 789 */ 790 bool my_dread(ang_dir *dir, char *fname, size_t len); 791 792 793 /* 794 * Close a directory handle. 795 */ 796 void my_dclose(ang_dir *dir); 797 798 799 800 #ifdef WINDOWS 801 802 /* Paranoia */ 803 # ifdef HAVE_DIRENT_H 804 # undef HAVE_DIRENT_H 805 # endif 806 807 /* Include Windows header */ 808 #include <windows.h> 809 810 /* System-specific struct */ 811 struct ang_dir 812 { 813 HANDLE h; 814 const char *first_file; 815 }; 816 817 /* Specified above */ 818 ang_dir *my_dopen(const char *dirname) 819 { 820 WIN32_FIND_DATA fd; 821 ang_dir *dir; 822 823 dir = ralloc(sizeof dir); 824 if (!dir) return NULL; 825 826 /* Try to open it */ 827 dir->h = FindFirstFile(format("%s\\*", dirname), &fd); 828 829 /* Abort */ 830 if (dir->h == INVALID_HANDLE_VALUE) 831 { 832 FREE(dir); 833 return NULL; 834 } 835 836 /* Remember this one */ 837 dir->first_file = string_make(fd.cFileName); 838 839 /* Success */ 840 return dir; 841 } 842 843 /* Specified above */ 844 bool my_dread(ang_dir *dir, char *fname, size_t len) 845 { 846 WIN32_FIND_DATA fd; 847 BOOL ok; 848 bool next = TRUE; 849 850 /* Try the first file */ 851 if (dir->first_file) 852 { 853 /* Copy the string across, then free it */ 854 my_strcpy(fname, dir->first_file, len); 855 string_free(dir->first_file); 856 dir->first_file = NULL; 857 858 /* Wild success */ 859 return TRUE; 860 } 861 862 /* Try the next file */ 863 while (next) 864 { 865 ok = FindNextFile(dir->h, &fd); 866 if (!ok) return FALSE; 867 868 /* Skip directories */ 869 if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY || 870 strcmp(fd.cFileName, ".") == 0 || 871 strcmp(fd.cFileName, "..") == 0) 872 continue; 873 874 /* Take this one */ 875 my_strcpy(fname, fd.cFileName, len); 876 next = FALSE; 877 } 878 879 return TRUE; 880 } 881 882 void my_dclose(ang_dir *dir) 883 { 884 /* Close directory */ 885 if (dir->h) 886 FindClose(dir->h); 887 888 /* Free memory */ 889 FREE(dir); 890 } 891 892 #endif /* WINDOWS */ 893 894 895 #ifdef HAVE_DIRENT_H 896 897 /* Include relevant types */ 898 #include <sys/types.h> 899 #include <dirent.h> 900 901 /* Define our ang_dir type */ 902 struct ang_dir 903 { 904 DIR *d; 905 }; 906 907 /* Specified above */ 908 ang_dir *my_dopen(const char *dirname) 909 { 910 ang_dir *dir; 911 912 dir = ralloc(sizeof dir); 913 if (!dir) return NULL; 914 915 /* Try to open the directory */ 916 dir->d = opendir(dirname); 917 if (!dir->d) 918 { 919 FREE(dir); 920 return NULL; 921 } 922 923 /* Success */ 924 return dir; 925 } 926 927 /* Specified above */ 928 bool my_dread(ang_dir *dir, char *fname, size_t len) 929 { 930 struct dirent *entry; 931 struct stat filedata; 932 933 assert(dir != NULL); 934 935 /* Try reading another entry */ 936 entry = readdir(dir->d); 937 if (!entry) return FALSE; 938 939 /* Copy the filename */ 940 /* XXX ignore overflow */ 941 my_strcpy(fname, entry->d_name, len); 942 943 return TRUE; 944 } 945 946 void my_dclose(ang_dir *dir) 947 { 948 /* Close directory */ 949 if (dir->d) 950 closedir(dir->d); 951 952 /* Free memory */ 953 FREE(dir); 954 } 955 956 #endif /* HAVE_DIRENT_H */ 957 trunk/src/z-file.h
r113 r127 73 73 74 74 75 typedef struct ang_dir ang_dir; 76 77 ang_dir *my_dopen(const char *dirname); 78 bool my_dread(ang_dir *dir, char *fname, size_t len); 79 void my_dclose(ang_dir *dir); 80 81 75 82 #endif
