pente-2.2.5/README0100664000076400007640000001173407331642773011746 0ustar wmswmsREADME for Pente 2.2.5, 31 July 2001 QUICK BUILD RULES: Run "./configure", then "make", then "pente". If all goes well, you're now playing the game! MORE ABOUT COMPILING: To compile Pente, you need an ANSI compatible C compiler, such as gcc. If you want a graphic interface, you need X11R3 or later; otherwise you will only be able to use the curses or text interfaces. Pente will intelligently configure itself to run on the interfaces available. Pente uses Gnu's "autoconfig" utility. To build a makefile, type "./configure" and (hopefully) configure will do the rest. If you have problems building, see the end of this document. Once you have a Makefile you may want to edit the following parts: prefix, bindir, mandir: These should point to the directories where the executable and the man pages should be put. These can also be set with "configure --prefix=...", etc. CC This is the C compiler that will be used. If you want to use a different compiler than the one that "configure" wants to use, you shouldn't just change the Makefile. Instead, set the shell environment variable "CC" to the name of your C compiler before running "configure". If you just change the Makefile after "configure" runs, then "configure" will build configuration files for the wrong compiler. CFLAGS: Set this to optimize as well as your C compiler can. "configure" will try to guess at the best value. LFLAGS: If configure doesn't add all the libraries it needs you can add them here. After you have built the Makefile and (optionally) edited it, you can build pente by typing "make". You can then run pente straight from the build area. There will be a symbolic link, "pente", that you can run. The actual binary will be called "pente-". For example, on my linux system I get "pente-i586-Linux". This is done so that you can build pente for different computers on a single file system. "pente" will always point to the last binary built. To install pente, you must first set the bindir and mandir as described above, then type "make install". Instructions on how to play pente are part of the X interface. The man page contains information on running pente. Please send bug reports, comments, etc. to William shubert, internet address "wms@igoweb.org", and don't forget to check out my web page at "http://www.igoweb.org/~wms/"! Enjoy! LICENCE This source code and all associated documentation is covered by the Gnu General Public Licence version 2. You should have gotten a copy of this document with the source code in a file called "COPYING". If you didn't, it is available from the Free Software Foundation, Inc. of Cambridge, MA or by anonymous FTP from prep.ai.mit.edu. The X11 version also has the licence in one of the help pages. RELEASE HISTORY 2.2.4 Changed some text in help files and comments. 2.2.2 Last release. 2.1.7 Got a bunch of bugs out. Ready for another post to rec.games.abstract. 2.1.0 Got network play working again! Much nicer than before. Beta release to find bugs. 2.0.5 Added French text thanks to Eric Dupas, fixed several minor bugs and several major portability bugs. 2.0.0 Major rewrite on the interface code. Also added the "redo" button, the setup window, and greatly improved the help window. 1.1.1 Fixed bug in "pente -perf" that made comparing numbers useless. Announced in rec.games.go and hand-mailed to people who ask for it. 1.1.0 Bug fixes, user interface enhancements, and portability changes. Fixed innumerable bugs in the user interface and the computer strategy system. No changes were made to computer strategy except where it didn't do what I intended when I first wrote it. Added the help window and generally tweaks up every part of the user interface to look and feel as nice as possible. Added use of Gnu Autonfig utility and tried system on several different machines. 1.0.0 First release. Put into alt.games.abstact FTP site. REQUEST FOR HELP If this program doesn't just configure and build on your system, drop me a note about what went wrong and I'll try to fix it in a patch release. Also, I want it to support different languages. Currently it can run in English, French or Italian. If you want to translate my strings into another language, great! Get in touch with me! I'd like to make the sound interface more portable; right now I only know how to do sound on a Sparc or a Linux machine. If you can port it to other machines, by all means let me know. ACKNOWLEDGEMENTS Thanks to Eric Dupas for translating the X11 strings into French and to Andrea Borgia for translating them into Italian. Thanks to Yary Hluchan for helping to rewrite the man page. And thanks for all the people who submitted bug reports or ideas for the program, who tried to compile on their machines, or who were willing to beta test the program! pente-2.2.5/COPYING0100664000076400007640000004307607045637743012130 0ustar wmswms GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 675 Mass Ave, Cambridge, MA 02139, USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program 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 this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19yy name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. pente-2.2.5/man6/pente.60100664000076400007640000000561707331643002013116 0ustar wmswms.\" I really don't like to write man pages. .ds ]W Pente 2.2.4 .TH Pente 6 "31 July 2001" .SH NAME pente \- Game of five in a row .SH SYNOPSIS .LP .B pente -help .LP .B pente [ .I ] .SH HOW TO PLAY PENTE Pente is the American name of a Japanese game called ``ni-nuki'', which is a variant of the ancient game ``go-moku''. Pente is played on a 19x19 grid with stones of two different colors. Each player chooses one set of stones; then the players take turns placing their stones on any unoccupied intersection until one player wins. .LP There are two ways to win. If a player makes five or more stones in a straight line (across, down, or diagonally), then that player wins. Or, if a player captures five pairs of his or her opponent's stones, that player also wins. .LP Stones may be captured in pairs only. To capture a pair of stones, a player must place one stone on either side of the pair. .LP The first move is placed in the center of the board. To make up for the advantage of going first, the first player's second move must be at least three spaces from their first. This sounds confusing, so don't worry about it; just play, and if the computer won't let you move where you want on your second move, play somewhere farther away. .LP That's it! These directions are pretty terse, but if you have an X display there are better directions available through the ``help'' button. You can also try playing a few games; the rules are simple enough that you can pick them up easily just by playing. .SH THE PROGRAM This program has support for many different display types. Depending on the compile options used, X Windows, Curses, and a plain text format may be available. The exact display type used will be chosen by the program, or it may be selected with a command line switch. Information on the switches is available with .B pente .BR \-help . .LP Most of the command line switches can also be set with the ``setup'' window of the X interface. Any changes you make there will be saved in the .B .pente.ad file and remembered the next time that you play. .LP The command line switches can also be set with an X default. For example, if you want to set black and white to be the default mode, you can run pente with .B pente .BR -nocolor , or you can add .B pente*color: 0 to your X defaults, or you can just turn off color in the ``setup'' window. .LP Pente will store a new .B .pente.ad file every time you run it. In this file it will save the current state of Pente. This is handy; you don't normally have to set command line switches since Pente will remember them in the .B .pente.ad file. .SH BUGS Sometimes the .B .pente.ad file gets some bad data in it. Just delete the file and then you can start from scratch again. .SH AUTHOR Bill Shubert (wms@igoweb.org) .LP French text by Eric Dupas (dupas@univ-mlv.fr) .LP Italian text by Andrea Borgia (email: borgia@cs.unibo.it; homepage: http://www.cs.unibo.it/~borgia) pente-2.2.5/configure0100775000076400007640000025302307331643015012762 0ustar wmswms#! /bin/sh # Guess values for system-dependent variables and create Makefiles. # Generated automatically using autoconf version 2.13 # Copyright (C) 1992, 93, 94, 95, 96 Free Software Foundation, Inc. # # This configure script is free software; the Free Software Foundation # gives unlimited permission to copy, distribute and modify it. # Defaults: ac_help= ac_default_prefix=/usr/local # Any additions from configure.in: ac_help="$ac_help --with-x use the X Window System" # Initialize some variables set by options. # The variables have the same names as the options, with # dashes changed to underlines. build=NONE cache_file=./config.cache exec_prefix=NONE host=NONE no_create= nonopt=NONE no_recursion= prefix=NONE program_prefix=NONE program_suffix=NONE program_transform_name=s,x,x, silent= site= srcdir= target=NONE verbose= x_includes=NONE x_libraries=NONE bindir='${exec_prefix}/bin' sbindir='${exec_prefix}/sbin' libexecdir='${exec_prefix}/libexec' datadir='${prefix}/share' sysconfdir='${prefix}/etc' sharedstatedir='${prefix}/com' localstatedir='${prefix}/var' libdir='${exec_prefix}/lib' includedir='${prefix}/include' oldincludedir='/usr/include' infodir='${prefix}/info' mandir='${prefix}/man' # Initialize some other variables. subdirs= MFLAGS= MAKEFLAGS= SHELL=${CONFIG_SHELL-/bin/sh} # Maximum number of lines to put in a shell here document. ac_max_here_lines=12 ac_prev= for ac_option do # If the previous option needs an argument, assign it. if test -n "$ac_prev"; then eval "$ac_prev=\$ac_option" ac_prev= continue fi case "$ac_option" in -*=*) ac_optarg=`echo "$ac_option" | sed 's/[-_a-zA-Z0-9]*=//'` ;; *) ac_optarg= ;; esac # Accept the important Cygnus configure options, so we can diagnose typos. case "$ac_option" in -bindir | --bindir | --bindi | --bind | --bin | --bi) ac_prev=bindir ;; -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*) bindir="$ac_optarg" ;; -build | --build | --buil | --bui | --bu) ac_prev=build ;; -build=* | --build=* | --buil=* | --bui=* | --bu=*) build="$ac_optarg" ;; -cache-file | --cache-file | --cache-fil | --cache-fi \ | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c) ac_prev=cache_file ;; -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \ | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*) cache_file="$ac_optarg" ;; -datadir | --datadir | --datadi | --datad | --data | --dat | --da) ac_prev=datadir ;; -datadir=* | --datadir=* | --datadi=* | --datad=* | --data=* | --dat=* \ | --da=*) datadir="$ac_optarg" ;; -disable-* | --disable-*) ac_feature=`echo $ac_option|sed -e 's/-*disable-//'` # Reject names that are not valid shell variable names. if test -n "`echo $ac_feature| sed 's/[-a-zA-Z0-9_]//g'`"; then { echo "configure: error: $ac_feature: invalid feature name" 1>&2; exit 1; } fi ac_feature=`echo $ac_feature| sed 's/-/_/g'` eval "enable_${ac_feature}=no" ;; -enable-* | --enable-*) ac_feature=`echo $ac_option|sed -e 's/-*enable-//' -e 's/=.*//'` # Reject names that are not valid shell variable names. if test -n "`echo $ac_feature| sed 's/[-_a-zA-Z0-9]//g'`"; then { echo "configure: error: $ac_feature: invalid feature name" 1>&2; exit 1; } fi ac_feature=`echo $ac_feature| sed 's/-/_/g'` case "$ac_option" in *=*) ;; *) ac_optarg=yes ;; esac eval "enable_${ac_feature}='$ac_optarg'" ;; -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \ | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \ | --exec | --exe | --ex) ac_prev=exec_prefix ;; -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \ | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \ | --exec=* | --exe=* | --ex=*) exec_prefix="$ac_optarg" ;; -gas | --gas | --ga | --g) # Obsolete; use --with-gas. with_gas=yes ;; -help | --help | --hel | --he) # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat << EOF Usage: configure [options] [host] Options: [defaults in brackets after descriptions] Configuration: --cache-file=FILE cache test results in FILE --help print this message --no-create do not create output files --quiet, --silent do not print \`checking...' messages --version print the version of autoconf that created configure Directory and file names: --prefix=PREFIX install architecture-independent files in PREFIX [$ac_default_prefix] --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX [same as prefix] --bindir=DIR user executables in DIR [EPREFIX/bin] --sbindir=DIR system admin executables in DIR [EPREFIX/sbin] --libexecdir=DIR program executables in DIR [EPREFIX/libexec] --datadir=DIR read-only architecture-independent data in DIR [PREFIX/share] --sysconfdir=DIR read-only single-machine data in DIR [PREFIX/etc] --sharedstatedir=DIR modifiable architecture-independent data in DIR [PREFIX/com] --localstatedir=DIR modifiable single-machine data in DIR [PREFIX/var] --libdir=DIR object code libraries in DIR [EPREFIX/lib] --includedir=DIR C header files in DIR [PREFIX/include] --oldincludedir=DIR C header files for non-gcc in DIR [/usr/include] --infodir=DIR info documentation in DIR [PREFIX/info] --mandir=DIR man documentation in DIR [PREFIX/man] --srcdir=DIR find the sources in DIR [configure dir or ..] --program-prefix=PREFIX prepend PREFIX to installed program names --program-suffix=SUFFIX append SUFFIX to installed program names --program-transform-name=PROGRAM run sed PROGRAM on installed program names EOF cat << EOF Host type: --build=BUILD configure for building on BUILD [BUILD=HOST] --host=HOST configure for HOST [guessed] --target=TARGET configure for TARGET [TARGET=HOST] Features and packages: --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) --enable-FEATURE[=ARG] include FEATURE [ARG=yes] --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) --x-includes=DIR X include files are in DIR --x-libraries=DIR X library files are in DIR EOF if test -n "$ac_help"; then echo "--enable and --with options recognized:$ac_help" fi exit 0 ;; -host | --host | --hos | --ho) ac_prev=host ;; -host=* | --host=* | --hos=* | --ho=*) host="$ac_optarg" ;; -includedir | --includedir | --includedi | --included | --include \ | --includ | --inclu | --incl | --inc) ac_prev=includedir ;; -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \ | --includ=* | --inclu=* | --incl=* | --inc=*) includedir="$ac_optarg" ;; -infodir | --infodir | --infodi | --infod | --info | --inf) ac_prev=infodir ;; -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*) infodir="$ac_optarg" ;; -libdir | --libdir | --libdi | --libd) ac_prev=libdir ;; -libdir=* | --libdir=* | --libdi=* | --libd=*) libdir="$ac_optarg" ;; -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \ | --libexe | --libex | --libe) ac_prev=libexecdir ;; -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \ | --libexe=* | --libex=* | --libe=*) libexecdir="$ac_optarg" ;; -localstatedir | --localstatedir | --localstatedi | --localstated \ | --localstate | --localstat | --localsta | --localst \ | --locals | --local | --loca | --loc | --lo) ac_prev=localstatedir ;; -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \ | --localstate=* | --localstat=* | --localsta=* | --localst=* \ | --locals=* | --local=* | --loca=* | --loc=* | --lo=*) localstatedir="$ac_optarg" ;; -mandir | --mandir | --mandi | --mand | --man | --ma | --m) ac_prev=mandir ;; -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*) mandir="$ac_optarg" ;; -nfp | --nfp | --nf) # Obsolete; use --without-fp. with_fp=no ;; -no-create | --no-create | --no-creat | --no-crea | --no-cre \ | --no-cr | --no-c) no_create=yes ;; -no-recursion | --no-recursion | --no-recursio | --no-recursi \ | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r) no_recursion=yes ;; -oldincludedir | --oldincludedir | --oldincludedi | --oldincluded \ | --oldinclude | --oldinclud | --oldinclu | --oldincl | --oldinc \ | --oldin | --oldi | --old | --ol | --o) ac_prev=oldincludedir ;; -oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \ | --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \ | --oldin=* | --oldi=* | --old=* | --ol=* | --o=*) oldincludedir="$ac_optarg" ;; -prefix | --prefix | --prefi | --pref | --pre | --pr | --p) ac_prev=prefix ;; -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*) prefix="$ac_optarg" ;; -program-prefix | --program-prefix | --program-prefi | --program-pref \ | --program-pre | --program-pr | --program-p) ac_prev=program_prefix ;; -program-prefix=* | --program-prefix=* | --program-prefi=* \ | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*) program_prefix="$ac_optarg" ;; -program-suffix | --program-suffix | --program-suffi | --program-suff \ | --program-suf | --program-su | --program-s) ac_prev=program_suffix ;; -program-suffix=* | --program-suffix=* | --program-suffi=* \ | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*) program_suffix="$ac_optarg" ;; -program-transform-name | --program-transform-name \ | --program-transform-nam | --program-transform-na \ | --program-transform-n | --program-transform- \ | --program-transform | --program-transfor \ | --program-transfo | --program-transf \ | --program-trans | --program-tran \ | --progr-tra | --program-tr | --program-t) ac_prev=program_transform_name ;; -program-transform-name=* | --program-transform-name=* \ | --program-transform-nam=* | --program-transform-na=* \ | --program-transform-n=* | --program-transform-=* \ | --program-transform=* | --program-transfor=* \ | --program-transfo=* | --program-transf=* \ | --program-trans=* | --program-tran=* \ | --progr-tra=* | --program-tr=* | --program-t=*) program_transform_name="$ac_optarg" ;; -q | -quiet | --quiet | --quie | --qui | --qu | --q \ | -silent | --silent | --silen | --sile | --sil) silent=yes ;; -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) ac_prev=sbindir ;; -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ | --sbi=* | --sb=*) sbindir="$ac_optarg" ;; -sharedstatedir | --sharedstatedir | --sharedstatedi \ | --sharedstated | --sharedstate | --sharedstat | --sharedsta \ | --sharedst | --shareds | --shared | --share | --shar \ | --sha | --sh) ac_prev=sharedstatedir ;; -sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \ | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \ | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \ | --sha=* | --sh=*) sharedstatedir="$ac_optarg" ;; -site | --site | --sit) ac_prev=site ;; -site=* | --site=* | --sit=*) site="$ac_optarg" ;; -srcdir | --srcdir | --srcdi | --srcd | --src | --sr) ac_prev=srcdir ;; -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*) srcdir="$ac_optarg" ;; -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \ | --syscon | --sysco | --sysc | --sys | --sy) ac_prev=sysconfdir ;; -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \ | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*) sysconfdir="$ac_optarg" ;; -target | --target | --targe | --targ | --tar | --ta | --t) ac_prev=target ;; -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*) target="$ac_optarg" ;; -v | -verbose | --verbose | --verbos | --verbo | --verb) verbose=yes ;; -version | --version | --versio | --versi | --vers) echo "configure generated by autoconf version 2.13" exit 0 ;; -with-* | --with-*) ac_package=`echo $ac_option|sed -e 's/-*with-//' -e 's/=.*//'` # Reject names that are not valid shell variable names. if test -n "`echo $ac_package| sed 's/[-_a-zA-Z0-9]//g'`"; then { echo "configure: error: $ac_package: invalid package name" 1>&2; exit 1; } fi ac_package=`echo $ac_package| sed 's/-/_/g'` case "$ac_option" in *=*) ;; *) ac_optarg=yes ;; esac eval "with_${ac_package}='$ac_optarg'" ;; -without-* | --without-*) ac_package=`echo $ac_option|sed -e 's/-*without-//'` # Reject names that are not valid shell variable names. if test -n "`echo $ac_package| sed 's/[-a-zA-Z0-9_]//g'`"; then { echo "configure: error: $ac_package: invalid package name" 1>&2; exit 1; } fi ac_package=`echo $ac_package| sed 's/-/_/g'` eval "with_${ac_package}=no" ;; --x) # Obsolete; use --with-x. with_x=yes ;; -x-includes | --x-includes | --x-include | --x-includ | --x-inclu \ | --x-incl | --x-inc | --x-in | --x-i) ac_prev=x_includes ;; -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \ | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*) x_includes="$ac_optarg" ;; -x-libraries | --x-libraries | --x-librarie | --x-librari \ | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l) ac_prev=x_libraries ;; -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \ | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*) x_libraries="$ac_optarg" ;; -*) { echo "configure: error: $ac_option: invalid option; use --help to show usage" 1>&2; exit 1; } ;; *) if test -n "`echo $ac_option| sed 's/[-a-z0-9.]//g'`"; then echo "configure: warning: $ac_option: invalid host type" 1>&2 fi if test "x$nonopt" != xNONE; then { echo "configure: error: can only configure for one host and one target at a time" 1>&2; exit 1; } fi nonopt="$ac_option" ;; esac done if test -n "$ac_prev"; then { echo "configure: error: missing argument to --`echo $ac_prev | sed 's/_/-/g'`" 1>&2; exit 1; } fi trap 'rm -fr conftest* confdefs* core core.* *.core $ac_clean_files; exit 1' 1 2 15 # File descriptor usage: # 0 standard input # 1 file creation # 2 errors and warnings # 3 some systems may open it to /dev/tty # 4 used on the Kubota Titan # 6 checking for... messages and results # 5 compiler messages saved in config.log if test "$silent" = yes; then exec 6>/dev/null else exec 6>&1 fi exec 5>./config.log echo "\ This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. " 1>&5 # Strip out --no-create and --no-recursion so they do not pile up. # Also quote any args containing shell metacharacters. ac_configure_args= for ac_arg do case "$ac_arg" in -no-create | --no-create | --no-creat | --no-crea | --no-cre \ | --no-cr | --no-c) ;; -no-recursion | --no-recursion | --no-recursio | --no-recursi \ | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r) ;; *" "*|*" "*|*[\[\]\~\#\$\^\&\*\(\)\{\}\\\|\;\<\>\?]*) ac_configure_args="$ac_configure_args '$ac_arg'" ;; *) ac_configure_args="$ac_configure_args $ac_arg" ;; esac done # NLS nuisances. # Only set these to C if already set. These must not be set unconditionally # because not all systems understand e.g. LANG=C (notably SCO). # Fixing LC_MESSAGES prevents Solaris sh from translating var values in `set'! # Non-C LC_CTYPE values break the ctype check. if test "${LANG+set}" = set; then LANG=C; export LANG; fi if test "${LC_ALL+set}" = set; then LC_ALL=C; export LC_ALL; fi if test "${LC_MESSAGES+set}" = set; then LC_MESSAGES=C; export LC_MESSAGES; fi if test "${LC_CTYPE+set}" = set; then LC_CTYPE=C; export LC_CTYPE; fi # confdefs.h avoids OS command line length limits that DEFS can exceed. rm -rf conftest* confdefs.h # AIX cpp loses on an empty file, so make sure it contains at least a newline. echo > confdefs.h # A filename unique to this package, relative to the directory that # configure is in, which we can look for to find out if srcdir is correct. ac_unique_file= # Find the source files, if location was not specified. if test -z "$srcdir"; then ac_srcdir_defaulted=yes # Try the directory containing this script, then its parent. ac_prog=$0 ac_confdir=`echo $ac_prog|sed 's%/[^/][^/]*$%%'` test "x$ac_confdir" = "x$ac_prog" && ac_confdir=. srcdir=$ac_confdir if test ! -r $srcdir/$ac_unique_file; then srcdir=.. fi else ac_srcdir_defaulted=no fi if test ! -r $srcdir/$ac_unique_file; then if test "$ac_srcdir_defaulted" = yes; then { echo "configure: error: can not find sources in $ac_confdir or .." 1>&2; exit 1; } else { echo "configure: error: can not find sources in $srcdir" 1>&2; exit 1; } fi fi srcdir=`echo "${srcdir}" | sed 's%\([^/]\)/*$%\1%'` # Prefer explicitly selected file to automatically selected ones. if test -z "$CONFIG_SITE"; then if test "x$prefix" != xNONE; then CONFIG_SITE="$prefix/share/config.site $prefix/etc/config.site" else CONFIG_SITE="$ac_default_prefix/share/config.site $ac_default_prefix/etc/config.site" fi fi for ac_site_file in $CONFIG_SITE; do if test -r "$ac_site_file"; then echo "loading site script $ac_site_file" . "$ac_site_file" fi done if test -r "$cache_file"; then echo "loading cache $cache_file" . $cache_file else echo "creating cache $cache_file" > $cache_file fi ac_ext=c # CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options. ac_cpp='$CPP $CPPFLAGS' ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&5' ac_link='${CC-cc} -o conftest${ac_exeext} $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5' cross_compiling=$ac_cv_prog_cc_cross ac_exeext= ac_objext=o if (echo "testing\c"; echo 1,2,3) | grep c >/dev/null; then # Stardent Vistra SVR4 grep lacks -e, says ghazi@caip.rutgers.edu. if (echo -n testing; echo 1,2,3) | sed s/-n/xn/ | grep xn >/dev/null; then ac_n= ac_c=' ' ac_t=' ' else ac_n=-n ac_c= ac_t= fi else ac_n= ac_c='\c' ac_t= fi # # $Source: /home/wms/cvs/pente/configure.in,v $ # $Revision: 1.5 $ # $Date: 2001/07/29 17:12:25 $ # # Remember to change these in "README", and "pente.6" too. # DATE must be in DAY MONTH YEAR format. date="31 7 2001" VERSION=\"2.2.5\" ###################################################################### # My own, personal functions. # ###################################################################### # I don't really know what will clearly tell whether you have sockets or not, # so I just took a bunch of socket-related functions and stuck them in # a routine. If it builds and links, I assume I can build sockets code; # otherwise I assume I can't. ###################################################################### # Done with my own functions. On to the real configure file. # ###################################################################### export VERSION cat >> confdefs.h <> confdefs.h <> confdefs.h <> confdefs.h <&2; exit 1; } fi ac_config_guess=$ac_aux_dir/config.guess ac_config_sub=$ac_aux_dir/config.sub ac_configure=$ac_aux_dir/configure # This should be Cygnus configure. # Find a good install program. We prefer a C program (faster), # so one script is as good as another. But avoid the broken or # incompatible versions: # SysV /etc/install, /usr/sbin/install # SunOS /usr/etc/install # IRIX /sbin/install # AIX /bin/install # AIX 4 /usr/bin/installbsd, which doesn't work without a -g flag # AFS /usr/afsws/bin/install, which mishandles nonexistent args # SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff" # ./install, which can be erroneously created by make from ./install.sh. echo $ac_n "checking for a BSD compatible install""... $ac_c" 1>&6 echo "configure:620: checking for a BSD compatible install" >&5 if test -z "$INSTALL"; then if eval "test \"`echo '$''{'ac_cv_path_install'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else IFS="${IFS= }"; ac_save_IFS="$IFS"; IFS=":" for ac_dir in $PATH; do # Account for people who put trailing slashes in PATH elements. case "$ac_dir/" in /|./|.//|/etc/*|/usr/sbin/*|/usr/etc/*|/sbin/*|/usr/afsws/bin/*|/usr/ucb/*) ;; *) # OSF1 and SCO ODT 3.0 have their own names for install. # Don't use installbsd from OSF since it installs stuff as root # by default. for ac_prog in ginstall scoinst install; do if test -f $ac_dir/$ac_prog; then if test $ac_prog = install && grep dspmsg $ac_dir/$ac_prog >/dev/null 2>&1; then # AIX install. It has an incompatible calling convention. : else ac_cv_path_install="$ac_dir/$ac_prog -c" break 2 fi fi done ;; esac done IFS="$ac_save_IFS" fi if test "${ac_cv_path_install+set}" = set; then INSTALL="$ac_cv_path_install" else # As a last resort, use the slow shell script. We don't cache a # path for INSTALL within a source directory, because that will # break other packages using the cache if that directory is # removed, or if the path is relative. INSTALL="$ac_install_sh" fi fi echo "$ac_t""$INSTALL" 1>&6 # Use test -z because SunOS4 sh mishandles braces in ${var-val}. # It thinks the first close brace ends the variable substitution. test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}' test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL_PROGRAM}' test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644' # Extract the first word of "gcc", so it can be a program name with args. set dummy gcc; ac_word=$2 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 echo "configure:675: checking for $ac_word" >&5 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":" ac_dummy="$PATH" for ac_dir in $ac_dummy; do test -z "$ac_dir" && ac_dir=. if test -f $ac_dir/$ac_word; then ac_cv_prog_CC="gcc" break fi done IFS="$ac_save_ifs" fi fi CC="$ac_cv_prog_CC" if test -n "$CC"; then echo "$ac_t""$CC" 1>&6 else echo "$ac_t""no" 1>&6 fi if test -z "$CC"; then # Extract the first word of "cc", so it can be a program name with args. set dummy cc; ac_word=$2 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 echo "configure:705: checking for $ac_word" >&5 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":" ac_prog_rejected=no ac_dummy="$PATH" for ac_dir in $ac_dummy; do test -z "$ac_dir" && ac_dir=. if test -f $ac_dir/$ac_word; then if test "$ac_dir/$ac_word" = "/usr/ucb/cc"; then ac_prog_rejected=yes continue fi ac_cv_prog_CC="cc" break fi done IFS="$ac_save_ifs" if test $ac_prog_rejected = yes; then # We found a bogon in the path, so make sure we never use it. set dummy $ac_cv_prog_CC shift if test $# -gt 0; then # We chose a different compiler from the bogus one. # However, it has the same basename, so the bogon will be chosen # first if we set CC to just the basename; use the full file name. shift set dummy "$ac_dir/$ac_word" "$@" shift ac_cv_prog_CC="$@" fi fi fi fi CC="$ac_cv_prog_CC" if test -n "$CC"; then echo "$ac_t""$CC" 1>&6 else echo "$ac_t""no" 1>&6 fi if test -z "$CC"; then case "`uname -s`" in *win32* | *WIN32*) # Extract the first word of "cl", so it can be a program name with args. set dummy cl; ac_word=$2 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 echo "configure:756: checking for $ac_word" >&5 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":" ac_dummy="$PATH" for ac_dir in $ac_dummy; do test -z "$ac_dir" && ac_dir=. if test -f $ac_dir/$ac_word; then ac_cv_prog_CC="cl" break fi done IFS="$ac_save_ifs" fi fi CC="$ac_cv_prog_CC" if test -n "$CC"; then echo "$ac_t""$CC" 1>&6 else echo "$ac_t""no" 1>&6 fi ;; esac fi test -z "$CC" && { echo "configure: error: no acceptable cc found in \$PATH" 1>&2; exit 1; } fi echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works""... $ac_c" 1>&6 echo "configure:788: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5 ac_ext=c # CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options. ac_cpp='$CPP $CPPFLAGS' ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&5' ac_link='${CC-cc} -o conftest${ac_exeext} $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5' cross_compiling=$ac_cv_prog_cc_cross cat > conftest.$ac_ext << EOF #line 799 "configure" #include "confdefs.h" main(){return(0);} EOF if { (eval echo configure:804: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then ac_cv_prog_cc_works=yes # If we can't run a trivial program, we are probably using a cross compiler. if (./conftest; exit) 2>/dev/null; then ac_cv_prog_cc_cross=no else ac_cv_prog_cc_cross=yes fi else echo "configure: failed program was:" >&5 cat conftest.$ac_ext >&5 ac_cv_prog_cc_works=no fi rm -fr conftest* ac_ext=c # CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options. ac_cpp='$CPP $CPPFLAGS' ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&5' ac_link='${CC-cc} -o conftest${ac_exeext} $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5' cross_compiling=$ac_cv_prog_cc_cross echo "$ac_t""$ac_cv_prog_cc_works" 1>&6 if test $ac_cv_prog_cc_works = no; then { echo "configure: error: installation or configuration problem: C compiler cannot create executables." 1>&2; exit 1; } fi echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler""... $ac_c" 1>&6 echo "configure:830: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler" >&5 echo "$ac_t""$ac_cv_prog_cc_cross" 1>&6 cross_compiling=$ac_cv_prog_cc_cross echo $ac_n "checking whether we are using GNU C""... $ac_c" 1>&6 echo "configure:835: checking whether we are using GNU C" >&5 if eval "test \"`echo '$''{'ac_cv_prog_gcc'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.c <&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then ac_cv_prog_gcc=yes else ac_cv_prog_gcc=no fi fi echo "$ac_t""$ac_cv_prog_gcc" 1>&6 if test $ac_cv_prog_gcc = yes; then GCC=yes else GCC= fi ac_test_CFLAGS="${CFLAGS+set}" ac_save_CFLAGS="$CFLAGS" CFLAGS= echo $ac_n "checking whether ${CC-cc} accepts -g""... $ac_c" 1>&6 echo "configure:863: checking whether ${CC-cc} accepts -g" >&5 if eval "test \"`echo '$''{'ac_cv_prog_cc_g'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else echo 'void f(){}' > conftest.c if test -z "`${CC-cc} -g -c conftest.c 2>&1`"; then ac_cv_prog_cc_g=yes else ac_cv_prog_cc_g=no fi rm -f conftest* fi echo "$ac_t""$ac_cv_prog_cc_g" 1>&6 if test "$ac_test_CFLAGS" = set; then CFLAGS="$ac_save_CFLAGS" elif test $ac_cv_prog_cc_g = yes; then if test "$GCC" = yes; then CFLAGS="-g -O2" else CFLAGS="-g" fi else if test "$GCC" = yes; then CFLAGS="-O2" else CFLAGS= fi fi echo $ac_n "checking how to run the C preprocessor""... $ac_c" 1>&6 echo "configure:895: checking how to run the C preprocessor" >&5 # On Suns, sometimes $CPP names a directory. if test -n "$CPP" && test -d "$CPP"; then CPP= fi if test -z "$CPP"; then if eval "test \"`echo '$''{'ac_cv_prog_CPP'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else # This must be in double quotes, not single quotes, because CPP may get # substituted into the Makefile and "${CC-cc}" will confuse make. CPP="${CC-cc} -E" # On the NeXT, cc -E runs the code through the compiler's parser, # not just through cpp. cat > conftest.$ac_ext < Syntax Error EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" { (eval echo configure:916: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then : else echo "$ac_err" >&5 echo "configure: failed program was:" >&5 cat conftest.$ac_ext >&5 rm -rf conftest* CPP="${CC-cc} -E -traditional-cpp" cat > conftest.$ac_ext < Syntax Error EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" { (eval echo configure:933: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then : else echo "$ac_err" >&5 echo "configure: failed program was:" >&5 cat conftest.$ac_ext >&5 rm -rf conftest* CPP="${CC-cc} -nologo -E" cat > conftest.$ac_ext < Syntax Error EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" { (eval echo configure:950: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then : else echo "$ac_err" >&5 echo "configure: failed program was:" >&5 cat conftest.$ac_ext >&5 rm -rf conftest* CPP=/lib/cpp fi rm -f conftest* fi rm -f conftest* fi rm -f conftest* ac_cv_prog_CPP="$CPP" fi CPP="$ac_cv_prog_CPP" else ac_cv_prog_CPP="$CPP" fi echo "$ac_t""$CPP" 1>&6 echo $ac_n "checking for best CFLAGS argument""... $ac_c" 1>&6 echo "configure:975: checking for best CFLAGS argument" >&5 if test $ac_cv_prog_gcc = yes ; then CFLAGS='-O2 -fomit-frame-pointer' else CFLAGS='-O' fi echo "$ac_t""$CFLAGS" 1>&6 PROGS="pente" BUILD_DIR=`pwd` LIBDIR="-L\$(BUILD_DIR)/wmslib" INCDIR="-I\$(BUILD_DIR)/wmslib/src -I\$(BUILD_DIR)/obj-\$(SYSTEM_TYPE)" echo $ac_n "checking for machine type""... $ac_c" 1>&6 echo "configure:989: checking for machine type" >&5 if test ${target} = NONE ; then SYSTEM_TYPE=`uname -m | sed sx/xxg` if test $? '!=' 0 ; then SYSTEM_TYPE=unknown ; fi os=`uname -s | sed sx/xxg` if test $? '=' 0 ; then SYSTEM_TYPE=${SYSTEM_TYPE}-${os} ; fi if test ${os} '=' SunOS ; then SYSTEM_TYPE=${SYSTEM_TYPE}`uname -r | sed -e 's/\.//g' -e 's/_.*//'` fi echo "$ac_t""$SYSTEM_TYPE" 1>&6 else SYSTEM_TYPE=${target} echo "$ac_t""$SYSTEM_TYPE (set by user)" 1>&6 fi export SYSTEM_TYPE rm -rf obj-${SYSTEM_TYPE} obj-d${SYSTEM_TYPE} pente-${SYSTEM_TYPE} mkdir obj-${SYSTEM_TYPE} if test x"$HOME" = x/home/wms ; then mkdir obj-d${SYSTEM_TYPE} fi cp configure.h.in obj-${SYSTEM_TYPE}/configure.h.in # Extract the first word of "ranlib", so it can be a program name with args. set dummy ranlib; ac_word=$2 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 echo "configure:1015: checking for $ac_word" >&5 if eval "test \"`echo '$''{'ac_cv_prog_RANLIB'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else if test -n "$RANLIB"; then ac_cv_prog_RANLIB="$RANLIB" # Let the user override the test. else IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":" ac_dummy="$PATH" for ac_dir in $ac_dummy; do test -z "$ac_dir" && ac_dir=. if test -f $ac_dir/$ac_word; then ac_cv_prog_RANLIB="ranlib" break fi done IFS="$ac_save_ifs" test -z "$ac_cv_prog_RANLIB" && ac_cv_prog_RANLIB=":" fi fi RANLIB="$ac_cv_prog_RANLIB" if test -n "$RANLIB"; then echo "$ac_t""$RANLIB" 1>&6 else echo "$ac_t""no" 1>&6 fi echo $ac_n "checking for POSIXized ISC""... $ac_c" 1>&6 echo "configure:1043: checking for POSIXized ISC" >&5 if test -d /etc/conf/kconfig.d && grep _POSIX_VERSION /usr/include/sys/unistd.h >/dev/null 2>&1 then echo "$ac_t""yes" 1>&6 ISC=yes # If later tests want to check for ISC. cat >> confdefs.h <<\EOF #define _POSIX_SOURCE 1 EOF if test "$GCC" = yes; then CC="$CC -posix" else CC="$CC -Xp" fi else echo "$ac_t""no" 1>&6 ISC= fi ac_safe=`echo "minix/config.h" | sed 'y%./+-%__p_%'` echo $ac_n "checking for minix/config.h""... $ac_c" 1>&6 echo "configure:1065: checking for minix/config.h" >&5 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" { (eval echo configure:1075: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then rm -rf conftest* eval "ac_cv_header_$ac_safe=yes" else echo "$ac_err" >&5 echo "configure: failed program was:" >&5 cat conftest.$ac_ext >&5 rm -rf conftest* eval "ac_cv_header_$ac_safe=no" fi rm -f conftest* fi if eval "test \"`echo '$ac_cv_header_'$ac_safe`\" = yes"; then echo "$ac_t""yes" 1>&6 MINIX=yes else echo "$ac_t""no" 1>&6 MINIX= fi if test "$MINIX" = yes; then cat >> confdefs.h <<\EOF #define _POSIX_SOURCE 1 EOF cat >> confdefs.h <<\EOF #define _POSIX_1_SOURCE 2 EOF cat >> confdefs.h <<\EOF #define _MINIX 1 EOF fi echo $ac_n "checking for AIX""... $ac_c" 1>&6 echo "configure:1113: checking for AIX" >&5 cat > conftest.$ac_ext <&5 | egrep "yes" >/dev/null 2>&1; then rm -rf conftest* echo "$ac_t""yes" 1>&6; cat >> confdefs.h <<\EOF #define _ALL_SOURCE 1 EOF else rm -rf conftest* echo "$ac_t""no" 1>&6 fi rm -f conftest* echo $ac_n "checking for main in -lm""... $ac_c" 1>&6 echo "configure:1137: checking for main in -lm" >&5 ac_lib_var=`echo m'_'main | sed 'y%./+-%__p_%'` if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else ac_save_LIBS="$LIBS" LIBS="-lm $LIBS" cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_lib_$ac_lib_var=yes" else echo "configure: failed program was:" >&5 cat conftest.$ac_ext >&5 rm -rf conftest* eval "ac_cv_lib_$ac_lib_var=no" fi rm -f conftest* LIBS="$ac_save_LIBS" fi if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then echo "$ac_t""yes" 1>&6 ac_tr_lib=HAVE_LIB`echo m | sed -e 's/[^a-zA-Z0-9_]/_/g' \ -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'` cat >> confdefs.h <&6 fi echo $ac_n "checking for main in -lseq""... $ac_c" 1>&6 echo "configure:1180: checking for main in -lseq" >&5 ac_lib_var=`echo seq'_'main | sed 'y%./+-%__p_%'` if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else ac_save_LIBS="$LIBS" LIBS="-lseq $LIBS" cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_lib_$ac_lib_var=yes" else echo "configure: failed program was:" >&5 cat conftest.$ac_ext >&5 rm -rf conftest* eval "ac_cv_lib_$ac_lib_var=no" fi rm -f conftest* LIBS="$ac_save_LIBS" fi if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then echo "$ac_t""yes" 1>&6 ac_tr_lib=HAVE_LIB`echo seq | sed -e 's/[^a-zA-Z0-9_]/_/g' \ -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'` cat >> confdefs.h <&6 fi echo $ac_n "checking for main in -lnsl""... $ac_c" 1>&6 echo "configure:1223: checking for main in -lnsl" >&5 ac_lib_var=`echo nsl'_'main | sed 'y%./+-%__p_%'` if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else ac_save_LIBS="$LIBS" LIBS="-lnsl $LIBS" cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_lib_$ac_lib_var=yes" else echo "configure: failed program was:" >&5 cat conftest.$ac_ext >&5 rm -rf conftest* eval "ac_cv_lib_$ac_lib_var=no" fi rm -f conftest* LIBS="$ac_save_LIBS" fi if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then echo "$ac_t""yes" 1>&6 ac_tr_lib=HAVE_LIB`echo nsl | sed -e 's/[^a-zA-Z0-9_]/_/g' \ -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'` cat >> confdefs.h <&6 fi echo $ac_n "checking for main in -lsocket""... $ac_c" 1>&6 echo "configure:1266: checking for main in -lsocket" >&5 ac_lib_var=`echo socket'_'main | sed 'y%./+-%__p_%'` if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else ac_save_LIBS="$LIBS" LIBS="-lsocket $LIBS" cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_lib_$ac_lib_var=yes" else echo "configure: failed program was:" >&5 cat conftest.$ac_ext >&5 rm -rf conftest* eval "ac_cv_lib_$ac_lib_var=no" fi rm -f conftest* LIBS="$ac_save_LIBS" fi if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then echo "$ac_t""yes" 1>&6 ac_tr_lib=HAVE_LIB`echo socket | sed -e 's/[^a-zA-Z0-9_]/_/g' \ -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'` cat >> confdefs.h <&6 fi ac_safe=`echo "curses.h" | sed 'y%./+-%__p_%'` echo $ac_n "checking for curses.h""... $ac_c" 1>&6 echo "configure:1310: checking for curses.h" >&5 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" { (eval echo configure:1320: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then rm -rf conftest* eval "ac_cv_header_$ac_safe=yes" else echo "$ac_err" >&5 echo "configure: failed program was:" >&5 cat conftest.$ac_ext >&5 rm -rf conftest* eval "ac_cv_header_$ac_safe=no" fi rm -f conftest* fi if eval "test \"`echo '$ac_cv_header_'$ac_safe`\" = yes"; then echo "$ac_t""yes" 1>&6 echo $ac_n "checking for main in -lcurses""... $ac_c" 1>&6 echo "configure:1337: checking for main in -lcurses" >&5 ac_lib_var=`echo curses'_'main | sed 'y%./+-%__p_%'` if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else ac_save_LIBS="$LIBS" LIBS="-lcurses $LIBS" cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_lib_$ac_lib_var=yes" else echo "configure: failed program was:" >&5 cat conftest.$ac_ext >&5 rm -rf conftest* eval "ac_cv_lib_$ac_lib_var=no" fi rm -f conftest* LIBS="$ac_save_LIBS" fi if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then echo "$ac_t""yes" 1>&6 cat >> confdefs.h <<\EOF #define CURSES_DISP 1 EOF echo $ac_n "checking for main in -ltermcap""... $ac_c" 1>&6 echo "configure:1372: checking for main in -ltermcap" >&5 ac_lib_var=`echo termcap'_'main | sed 'y%./+-%__p_%'` if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else ac_save_LIBS="$LIBS" LIBS="-ltermcap $LIBS" cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_lib_$ac_lib_var=yes" else echo "configure: failed program was:" >&5 cat conftest.$ac_ext >&5 rm -rf conftest* eval "ac_cv_lib_$ac_lib_var=no" fi rm -f conftest* LIBS="$ac_save_LIBS" fi if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then echo "$ac_t""yes" 1>&6 ac_tr_lib=HAVE_LIB`echo termcap | sed -e 's/^a-zA-Z0-9_/_/g' \ -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'` cat >> confdefs.h <&6 fi LIBS="-lcurses $LIBS" else echo "$ac_t""no" 1>&6 fi else echo "$ac_t""no" 1>&6 fi echo $ac_n "checking for ANSI C header files""... $ac_c" 1>&6 echo "configure:1424: checking for ANSI C header files" >&5 if eval "test \"`echo '$''{'ac_cv_header_stdc'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < #include #include #include EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" { (eval echo configure:1437: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then rm -rf conftest* ac_cv_header_stdc=yes else echo "$ac_err" >&5 echo "configure: failed program was:" >&5 cat conftest.$ac_ext >&5 rm -rf conftest* ac_cv_header_stdc=no fi rm -f conftest* if test $ac_cv_header_stdc = yes; then # SunOS 4.x string.h does not declare mem*, contrary to ANSI. cat > conftest.$ac_ext < EOF if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | egrep "memchr" >/dev/null 2>&1; then : else rm -rf conftest* ac_cv_header_stdc=no fi rm -f conftest* fi if test $ac_cv_header_stdc = yes; then # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI. cat > conftest.$ac_ext < EOF if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | egrep "free" >/dev/null 2>&1; then : else rm -rf conftest* ac_cv_header_stdc=no fi rm -f conftest* fi if test $ac_cv_header_stdc = yes; then # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi. if test "$cross_compiling" = yes; then : else cat > conftest.$ac_ext < #define ISLOWER(c) ('a' <= (c) && (c) <= 'z') #define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c)) #define XOR(e, f) (((e) && !(f)) || (!(e) && (f))) int main () { int i; for (i = 0; i < 256; i++) if (XOR (islower (i), ISLOWER (i)) || toupper (i) != TOUPPER (i)) exit(2); exit (0); } EOF if { (eval echo configure:1504: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null then : else echo "configure: failed program was:" >&5 cat conftest.$ac_ext >&5 rm -fr conftest* ac_cv_header_stdc=no fi rm -fr conftest* fi fi fi echo "$ac_t""$ac_cv_header_stdc" 1>&6 if test $ac_cv_header_stdc = yes; then cat >> confdefs.h <<\EOF #define STDC_HEADERS 1 EOF fi for ac_hdr in memory.h sys/select.h unistd.h assert.h stdlib.h string.h netinet/in.h sys/in.h sys/inet.h arpa/nameser.h resolv.h sys/time.h do ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'` echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6 echo "configure:1531: checking for $ac_hdr" >&5 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" { (eval echo configure:1541: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then rm -rf conftest* eval "ac_cv_header_$ac_safe=yes" else echo "$ac_err" >&5 echo "configure: failed program was:" >&5 cat conftest.$ac_ext >&5 rm -rf conftest* eval "ac_cv_header_$ac_safe=no" fi rm -f conftest* fi if eval "test \"`echo '$ac_cv_header_'$ac_safe`\" = yes"; then echo "$ac_t""yes" 1>&6 ac_tr_hdr=HAVE_`echo $ac_hdr | sed 'y%abcdefghijklmnopqrstuvwxyz./-%ABCDEFGHIJKLMNOPQRSTUVWXYZ___%'` cat >> confdefs.h <&6 fi done echo $ac_n "checking whether time.h and sys/time.h may both be included""... $ac_c" 1>&6 echo "configure:1568: checking whether time.h and sys/time.h may both be included" >&5 if eval "test \"`echo '$''{'ac_cv_header_time'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < #include #include int main() { struct tm *tp; ; return 0; } EOF if { (eval echo configure:1582: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_header_time=yes else echo "configure: failed program was:" >&5 cat conftest.$ac_ext >&5 rm -rf conftest* ac_cv_header_time=no fi rm -f conftest* fi echo "$ac_t""$ac_cv_header_time" 1>&6 if test $ac_cv_header_time = yes; then cat >> confdefs.h <<\EOF #define TIME_WITH_SYS_TIME 1 EOF fi ac_safe=`echo "sun/audioio.h" | sed 'y%./+-%__p_%'` echo $ac_n "checking for sun/audioio.h""... $ac_c" 1>&6 echo "configure:1604: checking for sun/audioio.h" >&5 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" { (eval echo configure:1614: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then rm -rf conftest* eval "ac_cv_header_$ac_safe=yes" else echo "$ac_err" >&5 echo "configure: failed program was:" >&5 cat conftest.$ac_ext >&5 rm -rf conftest* eval "ac_cv_header_$ac_safe=no" fi rm -f conftest* fi if eval "test \"`echo '$ac_cv_header_'$ac_safe`\" = yes"; then echo "$ac_t""yes" 1>&6 cat >> confdefs.h <<\EOF #define SUN_SOUND 1 EOF else echo "$ac_t""no" 1>&6 ac_safe=`echo "machine/soundcard.h" | sed 'y%./+-%__p_%'` echo $ac_n "checking for machine/soundcard.h""... $ac_c" 1>&6 echo "configure:1638: checking for machine/soundcard.h" >&5 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" { (eval echo configure:1648: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then rm -rf conftest* eval "ac_cv_header_$ac_safe=yes" else echo "$ac_err" >&5 echo "configure: failed program was:" >&5 cat conftest.$ac_ext >&5 rm -rf conftest* eval "ac_cv_header_$ac_safe=no" fi rm -f conftest* fi if eval "test \"`echo '$ac_cv_header_'$ac_safe`\" = yes"; then echo "$ac_t""yes" 1>&6 cat >> confdefs.h <<\EOF #define LINUX_SOUND 1 EOF else echo "$ac_t""no" 1>&6 fi fi echo $ac_n "checking for h_errno""... $ac_c" 1>&6 echo "configure:1675: checking for h_errno" >&5 cat > conftest.$ac_ext < #include #if HAVE_NETINET_IN_H #include #endif #if HAVE_SYS_IN_H #include #endif #if HAVE_SYS_INET_H #include #endif #include #if HAVE_ARPA_NAMESER_H #include #endif #if HAVE_RESOLV_H #include #endif int main() { h_errno = 0; ; return 0; } EOF if { (eval echo configure:1701: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* echo "$ac_t""yes" 1>&6; cat >> confdefs.h <<\EOF #define HAVE_H_ERRNO 1 EOF else echo "configure: failed program was:" >&5 cat conftest.$ac_ext >&5 rm -rf conftest* echo "$ac_t""no" 1>&6 fi rm -f conftest* echo $ac_n "checking for sockets""... $ac_c" 1>&6 echo "configure:1715: checking for sockets" >&5 cat > conftest.$ac_ext < #include #if HAVE_NETINET_IN_H #include #endif #if HAVE_SYS_IN_H #include #endif #if HAVE_SYS_INET_H #include #endif #include #if HAVE_ARPA_NAMESER_H #include #endif #if HAVE_RESOLV_H #include #endif #include #include #include int main() { struct sockaddr_in sa; bind(0,(struct sockaddr *)&sa, sizeof(sa)); listen(0,2); socket(AF_INET,SOCK_STREAM,0); gethostbyname("foo"); ; return 0; } EOF if { (eval echo configure:1749: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* echo "$ac_t""yes" 1>&6; cat >> confdefs.h <<\EOF #define HAVE_SOCKETS 1 EOF else echo "configure: failed program was:" >&5 cat conftest.$ac_ext >&5 rm -rf conftest* echo "$ac_t""no" 1>&6 fi rm -f conftest* if test "$cross_compiling" = "yes" ; then echo "********* IMPORTANT *************************************************" echo "*** It looks like either you are cross compiling, or configure cannot" echo "*** figure out how to run your C compiler." echo "*** If you are cross compiling, then configure cannot detect the " echo "*** size of various types and the endian style of your machine. " echo "*** You will have to edit the file obj-${SYSTEM_TYPE}/configure.h " echo "*** by hand." echo "*** If you are NOT cross compiling, then please see the README file" echo "*** for instructions on how to tell ./configure how to run your" echo "*** C compiler." echo "*********************************************************************" else echo $ac_n "checking size of short""... $ac_c" 1>&6 echo "configure:1776: checking size of short" >&5 if eval "test \"`echo '$''{'ac_cv_sizeof_short'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else if test "$cross_compiling" = yes; then { echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; } else cat > conftest.$ac_ext < main() { FILE *f=fopen("conftestval", "w"); if (!f) exit(1); fprintf(f, "%d\n", sizeof(short)); exit(0); } EOF if { (eval echo configure:1795: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null then ac_cv_sizeof_short=`cat conftestval` else echo "configure: failed program was:" >&5 cat conftest.$ac_ext >&5 rm -fr conftest* ac_cv_sizeof_short=0 fi rm -fr conftest* fi fi echo "$ac_t""$ac_cv_sizeof_short" 1>&6 cat >> confdefs.h <&6 else if test "$cross_compiling" = yes; then { echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; } else cat > conftest.$ac_ext < main() { FILE *f=fopen("conftestval", "w"); if (!f) exit(1); fprintf(f, "%d\n", sizeof(int)); exit(0); } EOF if { (eval echo configure:1848: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null then ac_cv_sizeof_int=`cat conftestval` else echo "configure: failed program was:" >&5 cat conftest.$ac_ext >&5 rm -fr conftest* ac_cv_sizeof_int=0 fi rm -fr conftest* fi fi echo "$ac_t""$ac_cv_sizeof_int" 1>&6 cat >> confdefs.h <&6 echo "configure:1868: checking size of long" >&5 if eval "test \"`echo '$''{'ac_cv_sizeof_long'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else if test "$cross_compiling" = yes; then { echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; } else cat > conftest.$ac_ext < main() { FILE *f=fopen("conftestval", "w"); if (!f) exit(1); fprintf(f, "%d\n", sizeof(long)); exit(0); } EOF if { (eval echo configure:1887: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null then ac_cv_sizeof_long=`cat conftestval` else echo "configure: failed program was:" >&5 cat conftest.$ac_ext >&5 rm -fr conftest* ac_cv_sizeof_long=0 fi rm -fr conftest* fi fi echo "$ac_t""$ac_cv_sizeof_long" 1>&6 cat >> confdefs.h <&6 echo "configure:1907: checking size of long long" >&5 if eval "test \"`echo '$''{'ac_cv_sizeof_long_long'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else if test "$cross_compiling" = yes; then { echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; } else cat > conftest.$ac_ext < main() { FILE *f=fopen("conftestval", "w"); if (!f) exit(1); fprintf(f, "%d\n", sizeof(long long)); exit(0); } EOF if { (eval echo configure:1926: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null then ac_cv_sizeof_long_long=`cat conftestval` else echo "configure: failed program was:" >&5 cat conftest.$ac_ext >&5 rm -fr conftest* ac_cv_sizeof_long_long=0 fi rm -fr conftest* fi fi echo "$ac_t""$ac_cv_sizeof_long_long" 1>&6 cat >> confdefs.h <&6 echo "configure:1946: checking whether byte ordering is bigendian" >&5 if eval "test \"`echo '$''{'ac_cv_c_bigendian'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else ac_cv_c_bigendian=unknown # See if sys/param.h defines the BYTE_ORDER macro. cat > conftest.$ac_ext < #include int main() { #if !BYTE_ORDER || !BIG_ENDIAN || !LITTLE_ENDIAN bogus endian macros #endif ; return 0; } EOF if { (eval echo configure:1964: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* # It does; now see whether it defined to BIG_ENDIAN or not. cat > conftest.$ac_ext < #include int main() { #if BYTE_ORDER != BIG_ENDIAN not big endian #endif ; return 0; } EOF if { (eval echo configure:1979: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_c_bigendian=yes else echo "configure: failed program was:" >&5 cat conftest.$ac_ext >&5 rm -rf conftest* ac_cv_c_bigendian=no fi rm -f conftest* else echo "configure: failed program was:" >&5 cat conftest.$ac_ext >&5 fi rm -f conftest* if test $ac_cv_c_bigendian = unknown; then if test "$cross_compiling" = yes; then { echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; } else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null then ac_cv_c_bigendian=no else echo "configure: failed program was:" >&5 cat conftest.$ac_ext >&5 rm -fr conftest* ac_cv_c_bigendian=yes fi rm -fr conftest* fi fi fi echo "$ac_t""$ac_cv_c_bigendian" 1>&6 if test $ac_cv_c_bigendian = yes; then cat >> confdefs.h <<\EOF #define WORDS_BIGENDIAN 1 EOF fi fi for ac_func in strerror getdtablesize memmove strcasecmp do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 echo "configure:2039: checking for $ac_func" >&5 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < /* Override any gcc2 internal prototype to avoid an error. */ /* We use char because int might match the return type of a gcc2 builtin and then its argument prototype would still apply. */ char $ac_func(); int main() { /* The GNU C library defines this for functions which it implements to always fail with ENOSYS. Some functions are actually named something starting with __ and the normal name is an alias. */ #if defined (__stub_$ac_func) || defined (__stub___$ac_func) choke me #else $ac_func(); #endif ; return 0; } EOF if { (eval echo configure:2067: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func_$ac_func=yes" else echo "configure: failed program was:" >&5 cat conftest.$ac_ext >&5 rm -rf conftest* eval "ac_cv_func_$ac_func=no" fi rm -f conftest* fi if eval "test \"`echo '$ac_cv_func_'$ac_func`\" = yes"; then echo "$ac_t""yes" 1>&6 ac_tr_func=HAVE_`echo $ac_func | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'` cat >> confdefs.h <&6 fi done echo $ac_n "checking return type of signal handlers""... $ac_c" 1>&6 echo "configure:2092: checking return type of signal handlers" >&5 if eval "test \"`echo '$''{'ac_cv_type_signal'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < #include #ifdef signal #undef signal #endif #ifdef __cplusplus extern "C" void (*signal (int, void (*)(int)))(int); #else void (*signal ()) (); #endif int main() { int i; ; return 0; } EOF if { (eval echo configure:2114: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_type_signal=void else echo "configure: failed program was:" >&5 cat conftest.$ac_ext >&5 rm -rf conftest* ac_cv_type_signal=int fi rm -f conftest* fi echo "$ac_t""$ac_cv_type_signal" 1>&6 cat >> confdefs.h <&6 echo "configure:2137: checking for X" >&5 # Check whether --with-x or --without-x was given. if test "${with_x+set}" = set; then withval="$with_x" : fi # $have_x is `yes', `no', `disabled', or empty when we do not yet know. if test "x$with_x" = xno; then # The user explicitly disabled X. have_x=disabled else if test "x$x_includes" != xNONE && test "x$x_libraries" != xNONE; then # Both variables are already set. have_x=yes else if eval "test \"`echo '$''{'ac_cv_have_x'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else # One or both of the vars are not set, and there is no cached value. ac_x_includes=NO ac_x_libraries=NO rm -fr conftestdir if mkdir conftestdir; then cd conftestdir # Make sure to not put "make" in the Imakefile rules, since we grep it out. cat > Imakefile <<'EOF' acfindx: @echo 'ac_im_incroot="${INCROOT}"; ac_im_usrlibdir="${USRLIBDIR}"; ac_im_libdir="${LIBDIR}"' EOF if (xmkmf) >/dev/null 2>/dev/null && test -f Makefile; then # GNU make sometimes prints "make[1]: Entering...", which would confuse us. eval `${MAKE-make} acfindx 2>/dev/null | grep -v make` # Open Windows xmkmf reportedly sets LIBDIR instead of USRLIBDIR. for ac_extension in a so sl; do if test ! -f $ac_im_usrlibdir/libX11.$ac_extension && test -f $ac_im_libdir/libX11.$ac_extension; then ac_im_usrlibdir=$ac_im_libdir; break fi done # Screen out bogus values from the imake configuration. They are # bogus both because they are the default anyway, and because # using them would break gcc on systems where it needs fixed includes. case "$ac_im_incroot" in /usr/include) ;; *) test -f "$ac_im_incroot/X11/Xos.h" && ac_x_includes="$ac_im_incroot" ;; esac case "$ac_im_usrlibdir" in /usr/lib | /lib) ;; *) test -d "$ac_im_usrlibdir" && ac_x_libraries="$ac_im_usrlibdir" ;; esac fi cd .. rm -fr conftestdir fi if test "$ac_x_includes" = NO; then # Guess where to find include files, by looking for this one X11 .h file. test -z "$x_direct_test_include" && x_direct_test_include=X11/Intrinsic.h # First, try using that file with no special directory specified. cat > conftest.$ac_ext < EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" { (eval echo configure:2204: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then rm -rf conftest* # We can compile using X headers with no special include directory. ac_x_includes= else echo "$ac_err" >&5 echo "configure: failed program was:" >&5 cat conftest.$ac_ext >&5 rm -rf conftest* # Look for the header file in a standard set of common directories. # Check X11 before X11Rn because it is often a symlink to the current release. for ac_dir in \ /usr/X11/include \ /usr/X11R6/include \ /usr/X11R5/include \ /usr/X11R4/include \ \ /usr/include/X11 \ /usr/include/X11R6 \ /usr/include/X11R5 \ /usr/include/X11R4 \ \ /usr/local/X11/include \ /usr/local/X11R6/include \ /usr/local/X11R5/include \ /usr/local/X11R4/include \ \ /usr/local/include/X11 \ /usr/local/include/X11R6 \ /usr/local/include/X11R5 \ /usr/local/include/X11R4 \ \ /usr/X386/include \ /usr/x386/include \ /usr/XFree86/include/X11 \ \ /usr/include \ /usr/local/include \ /usr/unsupported/include \ /usr/athena/include \ /usr/local/x11r5/include \ /usr/lpp/Xamples/include \ \ /usr/openwin/include \ /usr/openwin/share/include \ ; \ do if test -r "$ac_dir/$x_direct_test_include"; then ac_x_includes=$ac_dir break fi done fi rm -f conftest* fi # $ac_x_includes = NO if test "$ac_x_libraries" = NO; then # Check for the libraries. test -z "$x_direct_test_library" && x_direct_test_library=Xt test -z "$x_direct_test_function" && x_direct_test_function=XtMalloc # See if we find them without any special options. # Don't add to $LIBS permanently. ac_save_LIBS="$LIBS" LIBS="-l$x_direct_test_library $LIBS" cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* LIBS="$ac_save_LIBS" # We can link X programs with no special library path. ac_x_libraries= else echo "configure: failed program was:" >&5 cat conftest.$ac_ext >&5 rm -rf conftest* LIBS="$ac_save_LIBS" # First see if replacing the include by lib works. # Check X11 before X11Rn because it is often a symlink to the current release. for ac_dir in `echo "$ac_x_includes" | sed s/include/lib/` \ /usr/X11/lib \ /usr/X11R6/lib \ /usr/X11R5/lib \ /usr/X11R4/lib \ \ /usr/lib/X11 \ /usr/lib/X11R6 \ /usr/lib/X11R5 \ /usr/lib/X11R4 \ \ /usr/local/X11/lib \ /usr/local/X11R6/lib \ /usr/local/X11R5/lib \ /usr/local/X11R4/lib \ \ /usr/local/lib/X11 \ /usr/local/lib/X11R6 \ /usr/local/lib/X11R5 \ /usr/local/lib/X11R4 \ \ /usr/X386/lib \ /usr/x386/lib \ /usr/XFree86/lib/X11 \ \ /usr/lib \ /usr/local/lib \ /usr/unsupported/lib \ /usr/athena/lib \ /usr/local/x11r5/lib \ /usr/lpp/Xamples/lib \ /lib/usr/lib/X11 \ \ /usr/openwin/lib \ /usr/openwin/share/lib \ ; \ do for ac_extension in a so sl; do if test -r $ac_dir/lib${x_direct_test_library}.$ac_extension; then ac_x_libraries=$ac_dir break 2 fi done done fi rm -f conftest* fi # $ac_x_libraries = NO if test "$ac_x_includes" = NO || test "$ac_x_libraries" = NO; then # Didn't find X anywhere. Cache the known absence of X. ac_cv_have_x="have_x=no" else # Record where we found X for the cache. ac_cv_have_x="have_x=yes \ ac_x_includes=$ac_x_includes ac_x_libraries=$ac_x_libraries" fi fi fi eval "$ac_cv_have_x" fi # $with_x != no if test "$have_x" != yes; then echo "$ac_t""$have_x" 1>&6 no_x=yes else # If each of the values was on the command line, it overrides each guess. test "x$x_includes" = xNONE && x_includes=$ac_x_includes test "x$x_libraries" = xNONE && x_libraries=$ac_x_libraries # Update the cache value to reflect the command line values. ac_cv_have_x="have_x=yes \ ac_x_includes=$x_includes ac_x_libraries=$x_libraries" echo "$ac_t""libraries $x_libraries, headers $x_includes" 1>&6 fi if test '!' "$no_x" ; then cat >> confdefs.h <<\EOF #define X11_DISP 1 EOF if test "$x_includes" ; then INCDIR="$INCDIR -I$x_includes" fi LIBS="-lX11 $LIBS" if test "$x_libraries" ; then LIBDIR="$LIBDIR -L$x_libraries" fi fi subdirs='comp xio' for dname in ${subdirs}; do mkdir obj-${SYSTEM_TYPE}/$dname if test x"$HOME" = x/home/wms ; then mkdir obj-d${SYSTEM_TYPE}/$dname fi done TOP_FILES='pente pe_snd play board cio textio' PENTE_INCS='src/pente.h src/play.h src/board.h src/comp/comp.h src/comp/eval.h src/xio/xio.h src/xio/setup.h src/xio/helpwin.h src/xio/sound.h src/xio/remAcc.h' COMP_FILES='comp spawn eval move lmove deeptree' XIO_FILES='plasma xio mainwin helpwin strings pentebuts cm2pm setup remote sound remAcc' ofiles=' ' sfiles="README COPYING man6/pente.6 configure Makefile.in configure.h.in install-sh $PENTE_INCS" for ofile in ${TOP_FILES}; do ofiles="${ofiles} obj-\$(SYSTEM_TYPE)/${ofile}.o" sfiles="${sfiles} src/${ofile}.c" done for ofile in ${COMP_FILES}; do ofiles="${ofiles} obj-\$(SYSTEM_TYPE)/comp/${ofile}.o" sfiles="${sfiles} src/comp/${ofile}.c" done for ofile in ${XIO_FILES}; do ofiles="${ofiles} obj-\$(SYSTEM_TYPE)/xio/${ofile}.o" sfiles="${sfiles} src/xio/${ofile}.c" done OBJS=${ofiles} trap '' 1 2 15 cat > confcache <<\EOF # This file is a shell script that caches the results of configure # tests run on this system so they can be shared between configure # scripts and configure runs. It is not useful on other systems. # If it contains results you don't want to keep, you may remove or edit it. # # By default, configure uses ./config.cache as the cache file, # creating it if it does not exist already. You can give configure # the --cache-file=FILE option to use a different cache file; that is # what configure does when it calls configure scripts in # subdirectories, so they share the cache. # Giving --cache-file=/dev/null disables caching, for debugging configure. # config.status only pays attention to the cache file if you give it the # --recheck option to rerun configure. # EOF # The following way of writing the cache mishandles newlines in values, # but we know of no workaround that is simple, portable, and efficient. # So, don't put newlines in cache variables' values. # Ultrix sh set writes to stderr and can't be redirected directly, # and sets the high bit in the cache file unless we assign to the vars. (set) 2>&1 | case `(ac_space=' '; set | grep ac_space) 2>&1` in *ac_space=\ *) # `set' does not quote correctly, so add quotes (double-quote substitution # turns \\\\ into \\, and sed turns \\ into \). sed -n \ -e "s/'/'\\\\''/g" \ -e "s/^\\([a-zA-Z0-9_]*_cv_[a-zA-Z0-9_]*\\)=\\(.*\\)/\\1=\${\\1='\\2'}/p" ;; *) # `set' quotes correctly as required by POSIX, so do not add quotes. sed -n -e 's/^\([a-zA-Z0-9_]*_cv_[a-zA-Z0-9_]*\)=\(.*\)/\1=${\1=\2}/p' ;; esac >> confcache if cmp -s $cache_file confcache; then : else if test -w $cache_file; then echo "updating cache $cache_file" cat confcache > $cache_file else echo "not updating unwritable cache $cache_file" fi fi rm -f confcache trap 'rm -fr conftest* confdefs* core core.* *.core $ac_clean_files; exit 1' 1 2 15 test "x$prefix" = xNONE && prefix=$ac_default_prefix # Let make expand exec_prefix. test "x$exec_prefix" = xNONE && exec_prefix='${prefix}' # Any assignment to VPATH causes Sun make to only execute # the first set of double-colon rules, so remove it if not needed. # If there is a colon in the path, we need to keep it. if test "x$srcdir" = x.; then ac_vpsub='/^[ ]*VPATH[ ]*=[^:]*$/d' fi trap 'rm -f $CONFIG_STATUS conftest*; exit 1' 1 2 15 DEFS=-DHAVE_CONFIG_H # Without the "./", some shells look in PATH for config.status. : ${CONFIG_STATUS=./config.status} echo creating $CONFIG_STATUS rm -f $CONFIG_STATUS cat > $CONFIG_STATUS </dev/null | sed 1q`: # # $0 $ac_configure_args # # Compiler output produced by configure, useful for debugging # configure, is in ./config.log if it exists. ac_cs_usage="Usage: $CONFIG_STATUS [--recheck] [--version] [--help]" for ac_option do case "\$ac_option" in -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r) echo "running \${CONFIG_SHELL-/bin/sh} $0 $ac_configure_args --no-create --no-recursion" exec \${CONFIG_SHELL-/bin/sh} $0 $ac_configure_args --no-create --no-recursion ;; -version | --version | --versio | --versi | --vers | --ver | --ve | --v) echo "$CONFIG_STATUS generated by autoconf version 2.13" exit 0 ;; -help | --help | --hel | --he | --h) echo "\$ac_cs_usage"; exit 0 ;; *) echo "\$ac_cs_usage"; exit 1 ;; esac done ac_given_srcdir=$srcdir ac_given_INSTALL="$INSTALL" trap 'rm -fr `echo "Makefile obj-${SYSTEM_TYPE}/configure.h" | sed "s/:[^ ]*//g"` conftest*; exit 1' 1 2 15 EOF cat >> $CONFIG_STATUS < conftest.subs <<\\CEOF $ac_vpsub $extrasub s%@SHELL@%$SHELL%g s%@CFLAGS@%$CFLAGS%g s%@CPPFLAGS@%$CPPFLAGS%g s%@CXXFLAGS@%$CXXFLAGS%g s%@FFLAGS@%$FFLAGS%g s%@DEFS@%$DEFS%g s%@LDFLAGS@%$LDFLAGS%g s%@LIBS@%$LIBS%g s%@exec_prefix@%$exec_prefix%g s%@prefix@%$prefix%g s%@program_transform_name@%$program_transform_name%g s%@bindir@%$bindir%g s%@sbindir@%$sbindir%g s%@libexecdir@%$libexecdir%g s%@datadir@%$datadir%g s%@sysconfdir@%$sysconfdir%g s%@sharedstatedir@%$sharedstatedir%g s%@localstatedir@%$localstatedir%g s%@libdir@%$libdir%g s%@includedir@%$includedir%g s%@oldincludedir@%$oldincludedir%g s%@infodir@%$infodir%g s%@mandir@%$mandir%g s%@INSTALL_PROGRAM@%$INSTALL_PROGRAM%g s%@INSTALL_SCRIPT@%$INSTALL_SCRIPT%g s%@INSTALL_DATA@%$INSTALL_DATA%g s%@CC@%$CC%g s%@CPP@%$CPP%g s%@PROGS@%$PROGS%g s%@BUILD_DIR@%$BUILD_DIR%g s%@SYSTEM_TYPE@%$SYSTEM_TYPE%g s%@LIBDIR@%$LIBDIR%g s%@INCDIR@%$INCDIR%g s%@VERSION@%$VERSION%g s%@DATE@%$DATE%g s%@RANLIB@%$RANLIB%g s%@OBJS@%$OBJS%g CEOF EOF cat >> $CONFIG_STATUS <<\EOF # Split the substitutions into bite-sized pieces for seds with # small command number limits, like on Digital OSF/1 and HP-UX. ac_max_sed_cmds=90 # Maximum number of lines to put in a sed script. ac_file=1 # Number of current file. ac_beg=1 # First line for current file. ac_end=$ac_max_sed_cmds # Line after last line for current file. ac_more_lines=: ac_sed_cmds="" while $ac_more_lines; do if test $ac_beg -gt 1; then sed "1,${ac_beg}d; ${ac_end}q" conftest.subs > conftest.s$ac_file else sed "${ac_end}q" conftest.subs > conftest.s$ac_file fi if test ! -s conftest.s$ac_file; then ac_more_lines=false rm -f conftest.s$ac_file else if test -z "$ac_sed_cmds"; then ac_sed_cmds="sed -f conftest.s$ac_file" else ac_sed_cmds="$ac_sed_cmds | sed -f conftest.s$ac_file" fi ac_file=`expr $ac_file + 1` ac_beg=$ac_end ac_end=`expr $ac_end + $ac_max_sed_cmds` fi done if test -z "$ac_sed_cmds"; then ac_sed_cmds=cat fi EOF cat >> $CONFIG_STATUS <> $CONFIG_STATUS <<\EOF for ac_file in .. $CONFIG_FILES; do if test "x$ac_file" != x..; then # Support "outfile[:infile[:infile...]]", defaulting infile="outfile.in". case "$ac_file" in *:*) ac_file_in=`echo "$ac_file"|sed 's%[^:]*:%%'` ac_file=`echo "$ac_file"|sed 's%:.*%%'` ;; *) ac_file_in="${ac_file}.in" ;; esac # Adjust a relative srcdir, top_srcdir, and INSTALL for subdirectories. # Remove last slash and all that follows it. Not all systems have dirname. ac_dir=`echo $ac_file|sed 's%/[^/][^/]*$%%'` if test "$ac_dir" != "$ac_file" && test "$ac_dir" != .; then # The file is in a subdirectory. test ! -d "$ac_dir" && mkdir "$ac_dir" ac_dir_suffix="/`echo $ac_dir|sed 's%^\./%%'`" # A "../" for each directory in $ac_dir_suffix. ac_dots=`echo $ac_dir_suffix|sed 's%/[^/]*%../%g'` else ac_dir_suffix= ac_dots= fi case "$ac_given_srcdir" in .) srcdir=. if test -z "$ac_dots"; then top_srcdir=. else top_srcdir=`echo $ac_dots|sed 's%/$%%'`; fi ;; /*) srcdir="$ac_given_srcdir$ac_dir_suffix"; top_srcdir="$ac_given_srcdir" ;; *) # Relative path. srcdir="$ac_dots$ac_given_srcdir$ac_dir_suffix" top_srcdir="$ac_dots$ac_given_srcdir" ;; esac case "$ac_given_INSTALL" in [/$]*) INSTALL="$ac_given_INSTALL" ;; *) INSTALL="$ac_dots$ac_given_INSTALL" ;; esac echo creating "$ac_file" rm -f "$ac_file" configure_input="Generated automatically from `echo $ac_file_in|sed 's%.*/%%'` by configure." case "$ac_file" in *Makefile*) ac_comsub="1i\\ # $configure_input" ;; *) ac_comsub= ;; esac ac_file_inputs=`echo $ac_file_in|sed -e "s%^%$ac_given_srcdir/%" -e "s%:% $ac_given_srcdir/%g"` sed -e "$ac_comsub s%@configure_input@%$configure_input%g s%@srcdir@%$srcdir%g s%@top_srcdir@%$top_srcdir%g s%@INSTALL@%$INSTALL%g " $ac_file_inputs | (eval "$ac_sed_cmds") > $ac_file fi; done rm -f conftest.s* # These sed commands are passed to sed as "A NAME B NAME C VALUE D", where # NAME is the cpp macro being defined and VALUE is the value it is being given. # # ac_d sets the value in "#define NAME VALUE" lines. ac_dA='s%^\([ ]*\)#\([ ]*define[ ][ ]*\)' ac_dB='\([ ][ ]*\)[^ ]*%\1#\2' ac_dC='\3' ac_dD='%g' # ac_u turns "#undef NAME" with trailing blanks into "#define NAME VALUE". ac_uA='s%^\([ ]*\)#\([ ]*\)undef\([ ][ ]*\)' ac_uB='\([ ]\)%\1#\2define\3' ac_uC=' ' ac_uD='\4%g' # ac_e turns "#undef NAME" without trailing blanks into "#define NAME VALUE". ac_eA='s%^\([ ]*\)#\([ ]*\)undef\([ ][ ]*\)' ac_eB='$%\1#\2define\3' ac_eC=' ' ac_eD='%g' if test "${CONFIG_HEADERS+set}" != set; then EOF cat >> $CONFIG_STATUS <> $CONFIG_STATUS <<\EOF fi for ac_file in .. $CONFIG_HEADERS; do if test "x$ac_file" != x..; then # Support "outfile[:infile[:infile...]]", defaulting infile="outfile.in". case "$ac_file" in *:*) ac_file_in=`echo "$ac_file"|sed 's%[^:]*:%%'` ac_file=`echo "$ac_file"|sed 's%:.*%%'` ;; *) ac_file_in="${ac_file}.in" ;; esac echo creating $ac_file rm -f conftest.frag conftest.in conftest.out ac_file_inputs=`echo $ac_file_in|sed -e "s%^%$ac_given_srcdir/%" -e "s%:% $ac_given_srcdir/%g"` cat $ac_file_inputs > conftest.in EOF # Transform confdefs.h into a sed script conftest.vals that substitutes # the proper values into config.h.in to produce config.h. And first: # Protect against being on the right side of a sed subst in config.status. # Protect against being in an unquoted here document in config.status. rm -f conftest.vals cat > conftest.hdr <<\EOF s/[\\&%]/\\&/g s%[\\$`]%\\&%g s%#define \([A-Za-z_][A-Za-z0-9_]*\) *\(.*\)%${ac_dA}\1${ac_dB}\1${ac_dC}\2${ac_dD}%gp s%ac_d%ac_u%gp s%ac_u%ac_e%gp EOF sed -n -f conftest.hdr confdefs.h > conftest.vals rm -f conftest.hdr # This sed command replaces #undef with comments. This is necessary, for # example, in the case of _POSIX_SOURCE, which is predefined and required # on some systems where configure will not decide to define it. cat >> conftest.vals <<\EOF s%^[ ]*#[ ]*undef[ ][ ]*[a-zA-Z_][a-zA-Z_0-9]*%/* & */% EOF # Break up conftest.vals because some shells have a limit on # the size of here documents, and old seds have small limits too. rm -f conftest.tail while : do ac_lines=`grep -c . conftest.vals` # grep -c gives empty output for an empty file on some AIX systems. if test -z "$ac_lines" || test "$ac_lines" -eq 0; then break; fi # Write a limited-size here document to conftest.frag. echo ' cat > conftest.frag <> $CONFIG_STATUS sed ${ac_max_here_lines}q conftest.vals >> $CONFIG_STATUS echo 'CEOF sed -f conftest.frag conftest.in > conftest.out rm -f conftest.in mv conftest.out conftest.in ' >> $CONFIG_STATUS sed 1,${ac_max_here_lines}d conftest.vals > conftest.tail rm -f conftest.vals mv conftest.tail conftest.vals done rm -f conftest.vals cat >> $CONFIG_STATUS <<\EOF rm -f conftest.frag conftest.h echo "/* $ac_file. Generated automatically by configure. */" > conftest.h cat conftest.in >> conftest.h rm -f conftest.in if cmp -s $ac_file conftest.h 2>/dev/null; then echo "$ac_file is unchanged" rm -f conftest.h else # Remove last slash and all that follows it. Not all systems have dirname. ac_dir=`echo $ac_file|sed 's%/[^/][^/]*$%%'` if test "$ac_dir" != "$ac_file" && test "$ac_dir" != .; then # The file is in a subdirectory. test ! -d "$ac_dir" && mkdir "$ac_dir" fi rm -f $ac_file mv conftest.h $ac_file fi fi; done EOF cat >> $CONFIG_STATUS <> $CONFIG_STATUS <<\EOF exit 0 EOF chmod +x $CONFIG_STATUS rm -fr confdefs* $ac_clean_files test "$no_create" = yes || ${CONFIG_SHELL-/bin/sh} $CONFIG_STATUS || exit 1 for ofile in ${TOP_FILES}; do cat <>Makefile obj-\$(SYSTEM_TYPE)/${ofile}.o: src/${ofile}.c cd src; \$(CC) \$(CFLAGS) -c ${ofile}.c mv src/${ofile}.o obj-\$(SYSTEM_TYPE)/${ofile}.o EOF done for ofile in ${COMP_FILES}; do cat <>Makefile obj-\$(SYSTEM_TYPE)/comp/${ofile}.o: src/comp/${ofile}.c cd src/comp; \$(CC) \$(CFLAGS) -c ${ofile}.c mv src/comp/${ofile}.o obj-\$(SYSTEM_TYPE)/comp/${ofile}.o EOF done for ofile in ${XIO_FILES}; do cat <>Makefile obj-\$(SYSTEM_TYPE)/xio/${ofile}.o: src/xio/${ofile}.c cd src/xio; \$(CC) \$(CFLAGS) -c ${ofile}.c mv src/xio/${ofile}.o obj-\$(SYSTEM_TYPE)/xio/${ofile}.o EOF done # I blow away the cache every time. Why? Here's why: # A) You hopefully only ever run configure once per machine type, so # it won't buy most users any time. # B) If you have several machine types sharing a file system, the cache will # make configure break! There's NO CHECK to make sure that the cache is # for the appropriate machine! # These two reasons - especially B - lead me to conclude that autoconf's # caching is not useful in it's current implementation. If code is added # to make it check to ensure that it's on the right machine, great, otherwise # forget it. echo Destroying config.cache rm -f config.cache # Add in wmslib's Makefile TOP_FILES='wms' WMS_FILES='clp clp-x rnd snd str' BUT_FILES='net box but canvas checkbox ctext i_finder i_general i_snd i_win menu menu_snd plain rcur slide tblock text textin timer write' ABUT_FILES='abut swin msg' cfiles=' ' hfiles=' ' ofiles=' ' for tfile in ${TOP_FILES}; do cfiles="${cfiles} wmslib/src/${tfile}.c" hfiles="${hfiles} wmslib/src/${tfile}.h" ofiles="${ofiles} wmslib/obj-\$(SYSTEM_TYPE)/${tfile}.o" done for tfile in ${WMS_FILES}; do cfiles="${cfiles} wmslib/src/wms/${tfile}.c" hfiles="${hfiles} wmslib/src/wms/${tfile}.h" ofiles="${ofiles} wmslib/obj-\$(SYSTEM_TYPE)/wms_${tfile}.o" done for tfile in ${BUT_FILES}; do cfiles="${cfiles} wmslib/src/but/${tfile}.c" hfiles="${hfiles} wmslib/src/but/${tfile}.h" ofiles="${ofiles} wmslib/obj-\$(SYSTEM_TYPE)/but_${tfile}.o" done for tfile in ${ABUT_FILES}; do cfiles="${cfiles} wmslib/src/abut/${tfile}.c" hfiles="${hfiles} wmslib/src/abut/${tfile}.h" ofiles="${ofiles} wmslib/obj-\$(SYSTEM_TYPE)/abut_${tfile}.o" done sfiles="${sfiles} ${cfiles} ${hfiles}" rm -rf wmslib/obj-${SYSTEM_TYPE} wmslib/obj-d${SYSTEM_TYPE} mkdir wmslib/obj-${SYSTEM_TYPE} if test x"$HOME" = x/home/wms ; then mkdir wmslib/obj-d${SYSTEM_TYPE} fi arofiles=`echo ${ofiles} | sed 's&wmslib/obj-$(SYSTEM_TYPE)/&&g'` cat <>Makefile wmslib/libwms-\$(SYSTEM_TYPE).a: ${ofiles} cd wmslib/obj-\$(SYSTEM_TYPE); ar -r libwms-\$(SYSTEM_TYPE).a ${arofiles} mv wmslib/obj-\$(SYSTEM_TYPE)/libwms-\$(SYSTEM_TYPE).a wmslib/libwms-\$(SYSTEM_TYPE).a EOF if test "$RANLIB" '!=' : ; then echo " cd wmslib; ${RANLIB} libwms-\$(SYSTEM_TYPE).a" >>Makefile fi cat <>Makefile EOF for cfile in ${cfiles}; do scfile=`echo $cfile | sed 'sx.*/xx'` sofile=`echo $scfile | sed 's/c$/o/'` dname=`echo $cfile | sed 's&/'${scfile}'$&&'` ofile=`echo $cfile | sed -e 's/src/obj-$(SYSTEM_TYPE)/' -e 'sxbut/xbut_x' -e 'sxabut/xabut_x' -e 'sxwms/xwms_x' -e 's/c$/o/'` cat <>Makefile ${ofile}: ${cfile} cd ${dname}; \$(CC) \$(CFLAGS) -c ${scfile} mv ${dname}/${sofile} ${ofile} EOF done # I only make tar for myself. Why? Because nobody else really needs it # and the line ends up so long it breaks some editors. if test x"$HOME" = x/home/wms ; then tsfiles=' ' for sfile in ${sfiles}; do tsfiles="${tsfiles} pente-\$(VERSION)/${sfile}" done cat <>Makefile tar: cd ..; tar cvf pente-\$(VERSION).tar ${tsfiles} pente-\$(VERSION)/configure.in; gzip -f -9v pente-\$(VERSION).tar EOF fi echo '# DO NOT DELETE' >>Makefile mv Makefile Makefile-${SYSTEM_TYPE} ln -s Makefile-${SYSTEM_TYPE} Makefile if test x"$HOME" = x/home/wms ; then sed Makefile-d${SYSTEM_TYPE} -e 's/SYSTEM_TYPE = /SYSTEM_TYPE = d/' -e 's/^CFLAGS/# Old CFLAGS/' -e 's/# CFLAGS/CFLAGS/' -e 's/^LFLAGS/# Old LFLAGS/' -e 's/# LFLAGS/LFLAGS/' rm -f Makefile-d ln -s Makefile-d${SYSTEM_TYPE} Makefile-d cd obj-d${SYSTEM_TYPE} ln -s ../obj-${SYSTEM_TYPE}/configure.h . fi pente-2.2.5/Makefile.in0100664000076400007640000001040307045637743013126 0ustar wmswms# Makefile, part of Pente (game program) # Copyright (C) 1994-1995 William Shubert # See "configure.h.in" for more copyright information. VERSION = @VERSION@ DATE = @DATE@ # The SYSTEM_TYPE is used to figure out where to put the object files and # the binary. It's handy if you want to keep around ".o" files for, # let's say, both sun3 machines and sun4 machines. SYSTEM_TYPE = @SYSTEM_TYPE@ # NOTE: This Makefile requires the following directories be created before # it can run: # obj-$(SYSTEM_TYPE) # obj-$(SYSTEM_TYPE)/comp # obj-$(SYSTEM_TYPE)/xio # wmslib/obj-$(SYSTEM_TYPE) # If you run "configure", these directories should be generated automatically. # If, for whatever reason, this is NOT done, you should generate them by # hand. # If you do create these by hand, make sure to copy "configure.h.in" into # your top lever obj directory, rename it "configure.h", and edit it. # How to edit it should be self-explanatory. # CC must be ANSI compliant. "gcc" works well for me. CC = @CC@ # Programs used to move the binary and the man page to the proper place. INSTALL = @INSTALL@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_DATA = @INSTALL_DATA@ # Change these values to tell make where to put the binary and the man page # when it's done compiling. PREFIX = /usr/games BINDIR = $(PREFIX)/bin MANDIR = $(PREFIX)/man # This should be set to the directory containing this Makefile. BUILD_DIR = @BUILD_DIR@ INCS = @INCDIR@ LIBS = @LIBDIR@ -lwms-$(SYSTEM_TYPE) @LIBS@ # Various CFLAGS options. Pick what fits your compiler. # I try to guess what will give the best optimization, but I may be wrong. CFLAGS = @CFLAGS@ $(INCS) # CFLAGS = -ggdb -DDEBUG=1 -Wall $(INCS) LFLAGS = $(LIBS) # LFLAGS = $(LIBS) -static OBJS = @OBJS@ pente-$(SYSTEM_TYPE): $(OBJS) wmslib/libwms-$(SYSTEM_TYPE).a $(CC) -o pente-$(SYSTEM_TYPE) $(OBJS) $(LFLAGS) rm -f pente ln -s pente-$(SYSTEM_TYPE) pente clean: rm -f $(OBJS) pente-$(SYSTEM_TYPE) wmslib/libwms-$(SYSTEM_TYPE).a wmslib/obj-$(SYSTEM_TYPE)/*.o install: pente-$(SYSTEM_TYPE) man6/pente.6 $(INSTALL_PROGRAM) pente-$(SYSTEM_TYPE) $(BINDIR)/pente $(INSTALL_DATA) man6/pente.6 $(MANDIR)/man6/pente.6 # This depend may not work for you, but you probably won't care because you'll # just build once. If you do want to modify my source tree change this to # a depend that works for your system. Good luck. # This is so messy because I'm trying to do a make depend (but makedepend # breaks on my system for some reason) then strip out hard-coded paths to # the build directory, then remove all system includes that'll # never change anyway. Oh yeah I also have to move the .o's that the # make depend emits to the proper directory. Whew! depend: sed -n 1,'/^# DO NOT DELETE/'p Makefile-$(SYSTEM_TYPE)-temp rm Makefile-$(SYSTEM_TYPE) mv Makefile-$(SYSTEM_TYPE)-temp Makefile-$(SYSTEM_TYPE) $(CC) -M $(CFLAGS) src/*.c | sed -n -e 's&$(BUILD_DIR)/&&g' -e 's& /[^ ]*&&g' -e '/o *:/s&^&obj-$$(SYSTEM_TYPE)/&' -e 's&obj-$(SYSTEM_TYPE)&obj-$$(SYSTEM_TYPE)&g' -e '/[^ \\]/p' -e '/^[ ]*$$/p' >>Makefile-$(SYSTEM_TYPE) $(CC) -M $(CFLAGS) src/comp/*.c | sed -n -e 's&$(BUILD_DIR)/&&g' -e 's& /[^ ]*&&g' -e '/o *:/s&^&obj-$$(SYSTEM_TYPE)/comp/&' -e 's&obj-$(SYSTEM_TYPE)&obj-$$(SYSTEM_TYPE)&g' -e '/[^ \\]/p' -e '/^[ ]*$$/p' >>Makefile-$(SYSTEM_TYPE) $(CC) -M $(CFLAGS) src/xio/*.c | sed -n -e 's&$(BUILD_DIR)/&&g' -e 's& /[^ ]*&&g' -e '/o *:/s&^&obj-$$(SYSTEM_TYPE)/xio/&' -e 's&obj-$(SYSTEM_TYPE)&obj-$$(SYSTEM_TYPE)&g' -e '/[^ \\]/p' -e '/^[ ]*$$/p' >>Makefile-$(SYSTEM_TYPE) $(CC) -M $(CFLAGS) wmslib/src/*.c | sed -n -e 's&$(BUILD_DIR)/&&g' -e 's& /[^ ]*&&g' -e '/o *:/s&^&wmslib/obj-$$(SYSTEM_TYPE)/&' -e 's&obj-$(SYSTEM_TYPE)&obj-$$(SYSTEM_TYPE)&g' -e '/[^ \\]/p' -e '/^[ ]*$$/p' >>$(BUILD_DIR)/Makefile-$(SYSTEM_TYPE) $(CC) -M $(CFLAGS) wmslib/src/but/*.c | sed -n -e 's&$(BUILD_DIR)/&&g' -e 's& /[^ ]*&&g' -e '/o *:/s&^&wmslib/obj-$$(SYSTEM_TYPE)/but_&' -e 's&obj-$(SYSTEM_TYPE)&obj-$$(SYSTEM_TYPE)&g' -e '/[^ \\]/p' -e '/^[ ]*$$/p' >>$(BUILD_DIR)/Makefile-$(SYSTEM_TYPE) $(CC) -M $(CFLAGS) wmslib/src/abut/*.c | sed -n -e 's&$(BUILD_DIR)/&&g' -e 's& /[^ ]*&&g' -e '/o *:/s&^&wmslib/obj-$$(SYSTEM_TYPE)/abut_&' -e 's&obj-$(SYSTEM_TYPE)&obj-$$(SYSTEM_TYPE)&g' -e '/[^ \\]/p' -e '/^[ ]*$$/p' >>$(BUILD_DIR)/Makefile-$(SYSTEM_TYPE) pente-2.2.5/configure.h.in0100664000076400007640000000700207331041405013577 0ustar wmswms/* * $Source: /home/wms/cvs/pente/configure.h.in,v $ * $Revision: 1.2 $ * $Date: 2001/07/29 17:08:21 $ * * configure.h, part of Pente (game program) * Copyright (C) 1994-1995 William Shubert * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program 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 this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * The author can be reached at wms@igoweb.org. * * After being processed by "configure", this file is placed in the * object directory. This is done because a different configure.h is * needed for each target architecture; the object directory seems (to me) * like the natural place to keep object-dependant files, but it does * tend to look a little weird to have a .h mixed in with the .o's. */ #ifndef _CONFIGURE_H_ #define _CONFIGURE_H_ 1 #undef VERSION #undef DATE #undef DATE_FRENCH #undef DATE_ITALIAN /* * Define X11_DISP to be 1 if you have X11. * Also be sure that the LIBS and INCS flags in Makefile and wmslib/Makefile * are set correctly. */ #undef X11_DISP /* * Define CURSES_DISP to be 1 if you have curses. * Also be sure that the LIBS and INCS flags in Makefile and wmslib/Makefile * are set correctly. * Many versions of curses require you to link with -ltermcap if curses is * to be used. */ #undef CURSES_DISP /* * Define STDC_HEADERS to be 1 if you have the headers described in the ANSI * C standard. */ #undef STDC_HEADERS /* * For these header macros, define them to be 1 if you have the header * described. */ #undef HAVE_STRING_H #undef HAVE_UNISTD_H #undef HAVE_ASSERT_H #undef HAVE_STDLIB_H #undef HAVE_STRING_H #undef HAVE_SYS_SELECT_H #undef HAVE_NETINET_IN_H #undef HAVE_SYS_IN_H #undef HAVE_SYS_INET_H #undef HAVE_RESOLV_H #undef HAVE_ARPA_NAMESER_H #undef HAVE_SYS_TIME_H #undef TIME_WITH_SYS_TIME /* * If you have TCP/IP sockets turn on HAVE_SOCKETS. You need this to play * networked against another player. */ #undef HAVE_SOCKETS #undef HAVE_H_ERRNO /* * RETSIGTYPE should be set to "int" or "void", whichever your particular * C compiler and OS define signal handlers to return. */ #undef RETSIGTYPE /* * LINUX_SOUND should be set to 1 if you have linux-style sound. Mostly * this means that you have "linux/soundcard.h". */ #undef LINUX_SOUND /* * SUN_SOUND should be set to 1 if you have sun sparc-style sound. Mostly * this means that you have "sun/audioio.h". */ #undef SUN_SOUND /* * The size of various types. */ #undef SIZEOF_SHORT #undef SIZEOF_INT #undef SIZEOF_LONG /* * If your compiler doesn't have long longs, set this to zero. */ #undef SIZEOF_LONG_LONG /* * Is your machine big endian? */ #undef WORDS_BIGENDIAN /* * Do you have strerror()? * If so, define this. It will make some error messages more user friendly. */ #undef HAVE_STRERROR /* * Do you have getdtablesize()? */ #undef HAVE_GETDTABLESIZE #endif /* _CONFIGURE_H_ */ pente-2.2.5/install-sh0100775000076400007640000001124307045637743013070 0ustar wmswms#!/bin/sh # # install - install a program, script, or datafile # This comes from X11R5. # # Calling this script install-sh is preferred over install.sh, to prevent # `make' implicit rules from creating a file called install from it # when there is no Makefile. # # This script is compatible with the BSD install script, but was written # from scratch. # # set DOITPROG to echo to test this script # Don't use :- since 4.3BSD and earlier shells don't like it. doit="${DOITPROG-}" # put in absolute paths if you don't have them in your path; or use env. vars. mvprog="${MVPROG-mv}" cpprog="${CPPROG-cp}" chmodprog="${CHMODPROG-chmod}" chownprog="${CHOWNPROG-chown}" chgrpprog="${CHGRPPROG-chgrp}" stripprog="${STRIPPROG-strip}" rmprog="${RMPROG-rm}" mkdirprog="${MKDIRPROG-mkdir}" tranformbasename="" transform_arg="" instcmd="$mvprog" chmodcmd="$chmodprog 0755" chowncmd="" chgrpcmd="" stripcmd="" rmcmd="$rmprog -f" mvcmd="$mvprog" src="" dst="" dir_arg="" while [ x"$1" != x ]; do case $1 in -c) instcmd="$cpprog" shift continue;; -d) dir_arg=true shift continue;; -m) chmodcmd="$chmodprog $2" shift shift continue;; -o) chowncmd="$chownprog $2" shift shift continue;; -g) chgrpcmd="$chgrpprog $2" shift shift continue;; -s) stripcmd="$stripprog" shift continue;; -t=*) transformarg=`echo $1 | sed 's/-t=//'` shift continue;; -b=*) transformbasename=`echo $1 | sed 's/-b=//'` shift continue;; *) if [ x"$src" = x ] then src=$1 else # this colon is to work around a 386BSD /bin/sh bug : dst=$1 fi shift continue;; esac done if [ x"$src" = x ] then echo "install: no input file specified" exit 1 else true fi if [ x"$dir_arg" != x ]; then dst=$src src="" if [ -d $dst ]; then instcmd=: else instcmd=mkdir fi else # Waiting for this to be detected by the "$instcmd $src $dsttmp" command # might cause directories to be created, which would be especially bad # if $src (and thus $dsttmp) contains '*'. if [ -f $src -o -d $src ] then true else echo "install: $src does not exist" exit 1 fi if [ x"$dst" = x ] then echo "install: no destination specified" exit 1 else true fi # If destination is a directory, append the input filename; if your system # does not like double slashes in filenames, you may need to add some logic if [ -d $dst ] then dst="$dst"/`basename $src` else true fi fi ## this sed command emulates the dirname command dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'` # Make sure that the destination directory exists. # this part is taken from Noah Friedman's mkinstalldirs script # Skip lots of stat calls in the usual case. if [ ! -d "$dstdir" ]; then defaultIFS=' ' IFS="${IFS-${defaultIFS}}" oIFS="${IFS}" # Some sh's can't handle IFS=/ for some reason. IFS='%' set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'` IFS="${oIFS}" pathcomp='' while [ $# -ne 0 ] ; do pathcomp="${pathcomp}${1}" shift if [ ! -d "${pathcomp}" ] ; then $mkdirprog "${pathcomp}" else true fi pathcomp="${pathcomp}/" done fi if [ x"$dir_arg" != x ] then $doit $instcmd $dst && if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi && if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi && if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi && if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi else # If we're going to rename the final executable, determine the name now. if [ x"$transformarg" = x ] then dstfile=`basename $dst` else dstfile=`basename $dst $transformbasename | sed $transformarg`$transformbasename fi # don't allow the sed command to completely eliminate the filename if [ x"$dstfile" = x ] then dstfile=`basename $dst` else true fi # Make a temp file name in the proper directory. dsttmp=$dstdir/#inst.$$# # Move or copy the file name to the temp name $doit $instcmd $src $dsttmp && trap "rm -f ${dsttmp}" 0 && # and set any options; do chmod last to preserve setuid bits # If any of these fail, we abort the whole thing. If we want to # ignore errors from any of these, just make sure not to ignore # errors from the above "$doit $instcmd $src $dsttmp" command. if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi && if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi && if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi && if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi && # Now rename the file to the real destination. $doit $rmcmd -f $dstdir/$dstfile && $doit $mvcmd $dsttmp $dstdir/$dstfile fi && exit 0 pente-2.2.5/src/pente.h0100664000076400007640000000370107045637747013143 0ustar wmswms/* * src/pente.h, part of Pente (game program) * Copyright (C) 1994 William Shubert. * See "configure.h.in" for more copyright information. */ #ifndef _PENTE_H_ #define _PENTE_H_ #include #include #include #include #include "board.h" #include "play.h" #define MAXSTRLEN 80 /* In "pente.c" */ #define PE_CONTINUE (BD_LOC_MAX) #define PE_CANTPLAY (BD_LOC_MAX+1) #define PE_UNDO (BD_LOC_MAX+2) #define PE_REDO (BD_LOC_MAX+3) #define PE_RESTART (BD_LOC_MAX+4) #define PE_PAUSE (BD_LOC_MAX+5) #define PE_COMP (BD_LOC_MAX+6) extern Clp *pe_clp; extern Rnd *pe_rnd; extern void pe_output_vars(void); extern bool pe_perfmode; /* In "pe_snd.c" */ extern Snd pe_gameover_snd, pe_capture_snd, pe_move_snd; /* In "xio/xio.c" */ #if X11_DISP extern bd_loc_t xio_init(int *comp_level, uint winner, pl_t *game); extern void xio_draw(pl_t *game, bool forced); extern bd_loc_t xio_selectmove(pl_t *game, int compfd); extern void xio_think(bd_loc_t pos, uint player); #endif /* X11_DISP */ /* In "cio/cio.c" */ #ifdef CURSES_DISP extern bd_loc_t cio_init(int *comp_level, uint winner, pl_t *game); extern void cio_draw(pl_t *game, bool forced); extern bd_loc_t cio_selectmove(pl_t *game, int compfd); extern void cio_think(bd_loc_t pos, uint player); #endif /* In "textio/textio.c" */ extern bd_loc_t text_init(int *comp_level, uint winner, pl_t *game); extern void text_draw(pl_t *game, bool forced); extern bd_loc_t text_selectmove(pl_t *game, int compfd); extern void text_think(bd_loc_t pos, uint player); /* In "comp/comp.c" */ extern void comp_start(pl_t *game, uint level, int to_c); extern bd_loc_t comp_getmove(int from_c, void think(bd_loc_t pos, uint player), uint player); extern bd_loc_t comp_noSpawnGetMove(pl_t *game, int level); extern void comp_spawn(int *recv_from_c, int *send_to_c); extern void comp_reset(int *recv_from_c, int *send_to_c); #endif pente-2.2.5/src/play.h0100664000076400007640000000430407045637747012775 0ustar wmswms/* * src/play.h, part of Pente (game program) * Copyright (C) 1994 William Shubert. * See "configure.h.in" for more copyright information. */ /* Exported features: * pl_t * Data type. No user accessible components. * void pl_init(pl_t *game) * Initializes game to be a new game with an empty board and no moves * made yet. * uint pl_turn(pl_t *game) * Returns the turn number, 0 or more. * uint pl_player(pl_t *game) * Returns the player number (0 or 1) who is to move next. * uint pl_nmoves(pl_t *game) * Returns the total number of moves that have been made so far. * uint pl_maxmoves(pl_t *game) * Returns the maximum number of moves that have been made so far. * This is only diffeurent from pl_nmoves(game) if there have been undos. * bd_loc_t pl_getmove(pl_t *game, uint movenum) * Returns the move made at move movenum. * bd_t *pl_board(pl_t *game) * Returns the board at the current point in time. * bool pl_movep(pl_t *game, bd_loc_t loc) * Returns TRUE if loc is a valid move, or FALSE if it is not. * void pl_move(pl_t *game, bd_loc_t loc) * Makes the move specified, updating the board, the turn count, etc. * void pl_undo(pl_t *game) * Move the board back one move. * void pl_redo(pl_t *game) * Move the board forward one move. */ #ifndef _PL_H_ #define _PL_H_ #include "pente.h" #include "board.h" /* * DYNIX/ptx defines pl_t to be something else, so I have to undefine it * here. Ugh! */ #ifdef pl_t #undef pl_t #endif /* pl_t */ #define PL_MVNUM_MAX (19*19 + 5*2*2) typedef struct { bd_t board; bd_loc_t movelist[PL_MVNUM_MAX]; uint move, maxmove; } pl_t; extern void pl_init(pl_t *game); extern uint pl_turn(pl_t *game), pl_player(pl_t *game); extern uint pl_nmoves(pl_t *game); extern uint pl_maxmoves(pl_t *game); extern bd_loc_t pl_getmove(pl_t *game, uint movenum); extern bd_t *pl_board(pl_t *game); extern bool pl_movep(pl_t *game, bd_loc_t loc); extern bool pl_move(pl_t *game, bd_loc_t loc); extern void pl_undo(pl_t *game); extern bool pl_redo(pl_t *game); extern void pl_game_str(pl_t *game, char *str); extern void pl_str_game(const char *str, pl_t *game); #endif pente-2.2.5/src/board.h0100664000076400007640000000663507045637747013130 0ustar wmswms/* * src/board.h, part of Pente (game program) * Copyright (C) 1994 William Shubert. * See "configure.h.in" for more copyright information. */ /* * Exported features: * bd_t * Board data type. User accessible features: * uint captures[0..1] * Number of pairs captured by the player in question. * uint grid[BD_LOC_MIN..BD_LOC_MAX] * Array containing the grid values. * bool gameover * TRUE if the game has been won (or tied) * bd_init(bd_t *board) * Clears the board, leaving you with a completely empty playing field * and no captures for either player. * bd_loc_t * Data type. Points to a location on the board. Values of BD_LOC_MAX * or larger are guaranteed to be invalid board locations. * BD_EMPTYA, BD_EMPTYB, BD_EMPTYC * Three different types of empty board locations. Use at will; they all * behave the same. * bool BD_EMPTYP(val) * TRUE iff val is BD_EMPTYA, BD_EMPTYB, or BD_EMPTYC. * BD_EDGE * The value of a board location off the board. There is guaranteed to be * at least one line of BD_EDGE values off each edge of the board. * uint BD_PLAYER(player) * The value respresenting a piece of player. * uint BD_WINNER(player) * The value respresenting a piece just used to win the game. * uint BD_OWNER(val) * Returns the player number whose piece this is. * uint BD_OPP(player) * The value representing a piece of player's opponent. * bool BD_PLAYERP(val) * Returns TRUE if val is BD_PLAYER(0), BD_PLAYER(1), BD_WINNER(0), or * BD_WINNER(1). * bool BD_WINNERP(val) * Returns TRUE if val is BD_WINNER(0) or BD_WINNER(1). * BD_MAXPLAYERS * The most players supported. 2. * int bd_dvec[8] * Values added to a bd_loc_t to move it in one of the eight cardinal * directions. bd_dvec[x+4] is the opposite of bd_dvec[x]. * int bd_loc_x(bd_loc_t loc) * Gets the x coordinate of a location. 0..18. * int bd_loc_y(bd_loc_t loc) * Gets the y coordinate of a location. 0..18. * bd_loc_t bd_xy_loc(int x, int y) * Gets the location from the x and y coordinates. * bd_loc_t bd_str_loc(char *str, char **strout) * Gets a board loc from a string. Returns the end of the string in * strout if strout is non-NULL. * char *bd_loc_str(bd_loc_t loc, char *str) * Writes loc to str. Returns pointer to null-terminated end of string. */ #ifndef _BOARD_H_ #define _BOARD_H_ 1 #define BD_LOC_MIN (22*3+3) #define BD_LOC_MAX (BD_LOC_MIN + 18*22 + 19) #define BD_GRIDSIZE (BD_LOC_MAX + 22*3+3) #define BD_MAXPLAYERS 2 typedef struct { uint grid[BD_GRIDSIZE]; uint captures[BD_MAXPLAYERS]; uint gameover; } bd_t; #define BD_EMPTYA 0 /* Empty & Amusing */ #define BD_EMPTYB 1 /* Empty & Boring */ #define BD_EMPTYP(x) ((x) <= 1) #define BD_EDGE 3 #define BD_PLAYER(n) (4+(n)) #define BD_OWNER(n) ((n)&1) #define BD_OPP(n) (5-(n)) #define BD_WINNER(n) (6+(n)) #define BD_PLAYERP(n) ((n) >= BD_PLAYER(0)) #define BD_WINNERP(n) ((n) >= BD_WINNER(0)) typedef uint bd_loc_t; extern const int bd_dvec[8]; extern int bd_loc_x(bd_loc_t loc), bd_loc_y(bd_loc_t loc); extern bd_loc_t bd_xy_loc(int x, int y); extern void bd_init(bd_t *board); extern bd_loc_t bd_str_loc(const char *str, const char **strout); extern char *bd_loc_str(bd_loc_t loc, char *str); #endif /* _BOARD_H_ */ pente-2.2.5/src/comp/comp.h0100664000076400007640000000412307045640330013701 0ustar wmswms/* * src/comp/comp.h, part of Pente (game program) * Copyright (C) 1994 William Shubert. * See "configure.h.in" for more copyright information. */ #ifndef _COMP_H_ #define _COMP_H_ 1 #ifdef COMP_DEBUG extern int l1_repnum, l2_repnum, l3_repnum; #endif /* score_t must be at least 32 bits. */ typedef int32 score_t; #ifdef COMP_DEBUG #define D_PAR char *info, #define D_VAR char tmpinfo[100]; #define D_ARG tmpinfo, #define D_CPY() strcpy(info+4,tmpinfo) #define D_WIN(l)\ do {\ sprintf(info+4,"%c%2d",bd_loc_x(l)+'A',bd_loc_y(l)+1);\ info[3] = ' ';\ info[4] = '\0';\ } while (0) #define D_INIT(l, a)\ if (!BD_EMPTYP(board->grid[l])) {\ fprintf(stderr, "!!!MOVE ONTO NONEMPTY!!! %d\n", a);\ for(;;);\ }\ do {\ sprintf(info,"%c%2d",bd_loc_x(l)+'A',bd_loc_y(l)+1);\ info[3] = ' ';\ info[4] = '\0';\ } while (0) #else /* !COMP_DEBUG */ #define D_PAR #define D_VAR #define D_ARG #define D_CPY() #define D_WIN(l) #define D_INIT(l, a) #endif /* From "comp_move.c" */ extern score_t comp_move(D_PAR bd_t *board, bd_loc_t loc, uint player, bool check_simple); extern score_t comp_lmove(D_PAR bd_t *board, bd_loc_t loc, uint player); extern score_t comp_end_eval(D_PAR bd_t *board, bd_loc_t loc, uint player); extern score_t comp_deeptree(D_PAR bd_t *board, bd_loc_t loc, int level, int player); extern bd_loc_t comp_selectmove(pl_t *game, uint level); /* From "comp_spawn.c" */ extern void comp_think(bd_loc_t move); /* From "comp_eval.c" */ #define SCORE_MAX ((score_t)0x7fffffff) #define SCORE_MIN (-(SCORE_MAX)) #define WINVAL ((score_t)0x20000000) #define V_WIN(b) ((score_t)((WINVAL / 2) * 3)) #define V_D4FORCE(b) ((score_t)(b?WINVAL/ 8:WINVAL/ 4)) #define V_D3FORCE(b) ((score_t)(b?WINVAL/64:WINVAL/32)) #define V_FORCE(b) ((score_t)(WINVAL/32768)) #define CAP0VAL ((score_t)((V_FORCE(0)*3)+2)) #define V_CAP0 ((score_t)(CAP0VAL - 2)) extern const score_t comp_capval[]; extern score_t comp_eval(bd_t *board, bd_loc_t loc, uint player, score_t *cpmscore, bool *iscore); #endif pente-2.2.5/src/comp/eval.h0100664000076400007640000002663107045640330013702 0ustar wmswms/* * src/comp/eval.h, part of Pente (game program) * Copyright (C) 1994 William Shubert. * See "configure.h.in" for more copyright information. */ #ifdef COMPLEX #undef COMPLEX #endif #ifdef ISCORE #define COMPLEX #endif #ifdef OSCORE #define COMPLEX #endif { uint ev_fcaps, ev_dir; int ev_dvec; uint ev_fcg, ev_ecg, ev_ffg, ev_efg, ev_fbg, ev_ebg, ev_temp; bd_loc_t ev_ffloc, ev_fbloc, ev_efloc, ev_ebloc; #ifdef OSCORE uint ev_ef3, ev_ef4, ev_ecaps; #endif #ifdef CPM uint ev_ff3, ev_ff4; #endif ev_fcaps = BOARD->captures[PLAYER]; #ifdef CPM ev_ff4 = 0; ev_ff3 = 0; #endif SSCORE = 0; #ifdef ISCORE ISCORE = FALSE; #endif /* ISCORE */ #ifdef OSCORE OSCORE = 0; ev_ecaps = BOARD->captures[PLAYER^1]; ev_ef3 = 0; ev_ef4 = 0; #endif /* OSCORE */ for (ev_dir = 0; ev_dir < 4; ++ev_dir) { ev_fcg = 1; ev_ecg = 1; ev_ffg = 0; ev_efg = 0; ev_fbg = 0; ev_ebg = 0; ev_dvec = bd_dvec[ev_dir]; ev_efloc = ev_ffloc = LOC + ev_dvec; if (BOARD->grid[ev_ffloc] == BD_PLAYER(PLAYER)) { do { ++ev_fcg; ev_ffloc += ev_dvec; } while (BOARD->grid[ev_ffloc] == BD_PLAYER(PLAYER)); if (ev_fcg == 3) { if (BOARD->grid[ev_ffloc] == BD_OPP(PLAYER)) { SSCORE += V_FORCE(0); #ifdef ISCORE ISCORE = TRUE; #endif #ifdef OSCORE OSCORE += comp_capval[ev_ecaps++]; #endif } #ifdef OSCORE else if (BD_EMPTYP(BOARD->grid[ev_ffloc])) OSCORE += V_FORCE(0); #endif } } else if (BOARD->grid[ev_ffloc] == BD_OPP(PLAYER)) { #ifndef COMPLEX if (BOARD->grid[ev_ffloc+ev_dvec] == BD_OPP(PLAYER)) { if (BOARD->grid[ev_ffloc+ev_dvec+ev_dvec] == BD_PLAYER(PLAYER)) { SSCORE += comp_capval[ev_fcaps++]; } else if (BD_EMPTYP(BOARD->grid[ev_ffloc+ev_dvec+ev_dvec])) SSCORE += V_FORCE(DEGEN); } #else /* COMPLEX */ do { ++ev_ecg; ev_efloc += ev_dvec; } while (BOARD->grid[ev_efloc] == BD_OPP(PLAYER)); if (ev_ecg == 3) { if (BOARD->grid[ev_efloc] == BD_PLAYER(PLAYER)) { SSCORE += comp_capval[ev_fcaps++]; #ifdef ISCORE ISCORE = TRUE; #endif #ifdef OSCORE OSCORE += V_FORCE(0); #endif } else if (BD_EMPTYP(BOARD->grid[ev_efloc])) { SSCORE += V_FORCE(DEGEN); #ifdef ISCORE ISCORE = TRUE; #endif } } #endif /* COMPLEX */ } if (BD_EMPTYP(BOARD->grid[ev_ffloc]) && (BOARD->grid[ev_ffloc + ev_dvec] == BD_PLAYER(PLAYER))) { ++ev_ffg; ev_ffloc = ev_ffloc + ev_dvec + ev_dvec; while (BOARD->grid[ev_ffloc] == BD_PLAYER(PLAYER)) { ++ev_ffg; ev_ffloc += ev_dvec; } } #ifdef COMPLEX else if (BD_EMPTYP(BOARD->grid[ev_efloc]) && (BOARD->grid[ev_efloc + ev_dvec] == BD_OPP(PLAYER))) { ++ev_efg; ev_efloc = ev_efloc + ev_dvec + ev_dvec; while (BOARD->grid[ev_efloc] == BD_OPP(PLAYER)) { ++ev_efg; ev_efloc += ev_dvec; } } #endif ev_ebloc = ev_fbloc = LOC - ev_dvec; if (BOARD->grid[ev_fbloc] == BD_PLAYER(PLAYER)) { ev_temp = 1; ev_fbloc -= ev_dvec; while (BOARD->grid[ev_fbloc] == BD_PLAYER(PLAYER)) { ++ev_temp; ev_fbloc -= ev_dvec; } ev_fcg += ev_temp; if (ev_temp == 2) { if (BOARD->grid[ev_fbloc] == BD_OPP(PLAYER)) { SSCORE += V_FORCE(0); #ifdef ISCORE ISCORE = TRUE; #endif /* ISCORE */ #ifdef OSCORE OSCORE += comp_capval[ev_ecaps++]; #endif } #ifdef OSCORE else if (BD_EMPTYP(BOARD->grid[ev_fbloc] == BD_OPP(PLAYER))) OSCORE += V_FORCE(0); #endif } } else if (BOARD->grid[ev_fbloc] == BD_OPP(PLAYER)) { #ifndef COMPLEX if (BOARD->grid[ev_fbloc-ev_dvec] == BD_OPP(PLAYER)) { if (BOARD->grid[ev_fbloc-ev_dvec-ev_dvec] == BD_PLAYER(PLAYER)) { SSCORE += comp_capval[ev_fcaps++]; } else if (BD_EMPTYP(BOARD->grid[ev_fbloc-ev_dvec-ev_dvec])) SSCORE += V_FORCE(DEGEN); } #else /* COMPLEX */ ev_temp = 1; ev_ebloc -= ev_dvec; while (BOARD->grid[ev_ebloc] == BD_OPP(PLAYER)) { ++ev_temp; ev_ebloc -= ev_dvec; } ev_ecg += ev_temp; if (ev_temp == 2) { if (BOARD->grid[ev_ebloc] == BD_PLAYER(PLAYER)) { SSCORE += comp_capval[ev_fcaps++]; #ifdef ISCORE ISCORE = TRUE; #endif #ifdef OSCORE OSCORE += V_FORCE(0); #endif } else if (BD_EMPTYP(BOARD->grid[ev_ebloc])) { SSCORE += V_FORCE(DEGEN); #ifdef ISCORE ISCORE = TRUE; #endif } } #endif /* COMPLEX */ } if (BD_EMPTYP(BOARD->grid[ev_fbloc]) && (BOARD->grid[ev_fbloc - ev_dvec] == BD_PLAYER(PLAYER))) { ++ev_fbg; ev_fbloc = ev_fbloc - ev_dvec - ev_dvec; while (BOARD->grid[ev_fbloc] == BD_PLAYER(PLAYER)) { ++ev_fbg; ev_fbloc -= ev_dvec; } } #ifdef COMPLEX else if (BD_EMPTYP(BOARD->grid[ev_ebloc]) && (BOARD->grid[ev_ebloc - ev_dvec] == BD_OPP(PLAYER))) { ++ev_ebg; ev_ebloc = ev_ebloc - ev_dvec - ev_dvec; while (BOARD->grid[ev_ebloc] == BD_OPP(PLAYER)) { ++ev_ebg; ev_ebloc -= ev_dvec; } } #endif /* COMPLEX */ switch(ev_fcg) { case 1: if ((ev_ffg == 2) && BD_EMPTYP(BOARD->grid[ev_ffloc]) && (BD_EMPTYP(BOARD->grid[ev_fbloc]) || (ev_fbg != 0))) { SSCORE += V_FORCE(DEGEN); #ifdef ISCORE ISCORE = TRUE; #endif /* ISCORE */ #ifdef CPM ++ev_ff3; #endif /* CPM */ } else if (ev_ffg >= 3) { SSCORE += V_FORCE(DEGEN); #ifdef ISCORE ISCORE = TRUE; #endif /* ISCORE */ #ifdef CPM ++ev_ff4; #endif /* CPM */ } if ((ev_fbg == 2) && BD_EMPTYP(BOARD->grid[ev_fbloc]) && (BD_EMPTYP(BOARD->grid[ev_ffloc]) || (ev_ffg != 0))) { SSCORE += V_FORCE(DEGEN); #ifdef ISCORE ISCORE = TRUE; #endif /* ISCORE */ #ifdef CPM ++ev_ff3; #endif /* CPM */ } else if (ev_fbg >= 3) { SSCORE += V_FORCE(DEGEN); #ifdef ISCORE ISCORE = TRUE; #endif /* ISCORE */ #ifdef CPM ++ev_ff4; #endif /* CPM */ } break; case 2: ev_temp = 0; if (ev_ffg != 0) ev_temp = 1; else { if (BD_EMPTYP(BOARD->grid[ev_ffloc])) ev_temp = 1; else if (BOARD->grid[ev_ffloc] == BD_OPP(PLAYER)) ev_temp = 2; } if (ev_fbg != 0) ev_temp |= 1; else { if (BD_EMPTYP(BOARD->grid[ev_fbloc])) ev_temp |= 1; else if (BOARD->grid[ev_fbloc] == BD_OPP(PLAYER)) ev_temp |= 2; } if (ev_temp == 3) SSCORE -= 2*V_FORCE(DEGEN); if ((ev_ffg == 1) && BD_EMPTYP(BOARD->grid[ev_ffloc]) && (BD_EMPTYP(BOARD->grid[ev_fbloc]) || (ev_fbg != 0))) { SSCORE += V_FORCE(DEGEN); #ifdef ISCORE ISCORE = TRUE; #endif /* ISCORE */ #ifdef CPM ++ev_ff3; #endif /* CPM */ } else if (ev_ffg >= 2) { SSCORE += V_FORCE(DEGEN); #ifdef ISCORE ISCORE = TRUE; #endif /* ISCORE */ #ifdef CPM ++ev_ff4; #endif /* CPM */ } if ((ev_fbg == 1) && BD_EMPTYP(BOARD->grid[ev_fbloc]) && (BD_EMPTYP(BOARD->grid[ev_ffloc]) || (ev_ffg != 0))) { SSCORE += V_FORCE(DEGEN); #ifdef ISCORE ISCORE = TRUE; #endif /* ISCORE */ #ifdef CPM ++ev_ff3; #endif /* CPM */ } else if (ev_fbg >= 2) { SSCORE += V_FORCE(DEGEN); #ifdef ISCORE ISCORE = TRUE; #endif /* ISCORE */ #ifdef CPM ++ev_ff4; #endif /* CPM */ } break; case 3: if ((ev_ffg == 0) && (ev_fbg == 0) && BD_EMPTYP(BOARD->grid[ev_fbloc]) && BD_EMPTYP(BOARD->grid[ev_ffloc])) { SSCORE += V_FORCE(DEGEN); #ifdef ISCORE ISCORE = TRUE; #endif /* ISCORE */ #ifdef CPM ++ev_ff3; #endif /* CPM */ } else { if (ev_ffg) { SSCORE += V_FORCE(DEGEN); #ifdef ISCORE ISCORE = TRUE; #endif /* ISCORE */ #ifdef CPM ++ev_ff4; #endif /* CPM */ } if (ev_fbg) { SSCORE += V_FORCE(DEGEN); #ifdef ISCORE ISCORE = TRUE; #endif /* ISCORE */ #ifdef CPM ++ev_ff4; #endif /* CPM */ } } break; case 4: if ((ev_ffg != 0) || (BD_EMPTYP(BOARD->grid[ev_ffloc]))) { SSCORE += V_FORCE(DEGEN); #ifdef ISCORE ISCORE = TRUE; #endif /* ISCORE */ #ifdef CPM ++ev_ff4; #endif /* CPM */ } if ((ev_fbg != 0) || (BD_EMPTYP(BOARD->grid[ev_fbloc]))) { SSCORE += V_FORCE(DEGEN); #ifdef ISCORE ISCORE = TRUE; #endif /* ISCORE */ #ifdef CPM ++ev_ff4; #endif /* CPM */ } break; default: SSCORE = V_WIN(DEGEN); #ifdef ISCORE ISCORE = TRUE; #endif /* ISCORE */ } #ifdef COMPLEX switch(ev_ecg) { case 1: if ((ev_efg == 2) && BD_EMPTYP(BOARD->grid[ev_efloc]) && (BD_EMPTYP(BOARD->grid[ev_ebloc]) || (ev_ebg != 0))) { #ifdef OSCORE #ifdef CPM ++ev_ef3; #endif OSCORE += V_FORCE(0); #endif #ifdef ISCORE ISCORE = TRUE; #endif } else if (ev_efg >= 3) { #ifdef OSCORE #ifdef CPM ++ev_ef4; #endif OSCORE += V_FORCE(0); #endif #ifdef ISCORE ISCORE = TRUE; #endif } if ((ev_ebg == 2) && BD_EMPTYP(BOARD->grid[ev_ebloc]) && (BD_EMPTYP(BOARD->grid[ev_efloc]) || (ev_efg != 0))) { #ifdef OSCORE #ifdef CPM ++ev_ef3; #endif OSCORE += V_FORCE(0); #endif #ifdef ISCORE ISCORE = TRUE; #endif } else if (ev_ebg >= 3) { #ifdef OSCORE #ifdef CPM ++ev_ef4; #endif OSCORE += V_FORCE(0); #endif #ifdef ISCORE ISCORE = TRUE; #endif } break; case 2: #ifdef OSCORE ev_temp = 0; if (ev_efg != 0) ev_temp = 1; else { if (BD_EMPTYP(BOARD->grid[ev_efloc])) ev_temp = 1; else if (BOARD->grid[ev_efloc] == BD_PLAYER(PLAYER)) ev_temp = 2; } if (ev_ebg != 0) ev_temp |= 1; else { if (BD_EMPTYP(BOARD->grid[ev_ebloc])) ev_temp |= 1; else if (BOARD->grid[ev_ebloc] == BD_PLAYER(PLAYER)) ev_temp |= 2; } if (ev_temp == 3) OSCORE -= 2*V_FORCE(0); #endif if ((ev_efg == 1) && BD_EMPTYP(BOARD->grid[ev_efloc]) && (BD_EMPTYP(BOARD->grid[ev_ebloc]) || (ev_ebg != 0))) { #ifdef OSCORE #ifdef CPM ++ev_ef3; #endif OSCORE += V_FORCE(0); #endif #ifdef ISCORE ISCORE = TRUE; #endif } else if (ev_efg >= 2) { #ifdef OSCORE #ifdef CPM ++ev_ef4; #endif OSCORE += V_FORCE(0); #endif #ifdef ISCORE ISCORE = TRUE; #endif } if ((ev_ebg == 1) && BD_EMPTYP(BOARD->grid[ev_ebloc]) && (BD_EMPTYP(BOARD->grid[ev_efloc]) || (ev_efg != 0))) { #ifdef OSCORE #ifdef CPM ++ev_ef3; #endif OSCORE += V_FORCE(0); #endif #ifdef ISCORE ISCORE = TRUE; #endif } else if (ev_ebg >= 2) { #ifdef OSCORE #ifdef CPM ++ev_ef4; #endif OSCORE += V_FORCE(0); #endif #ifdef ISCORE ISCORE = TRUE; #endif } break; case 3: if ((ev_efg == 0) && (ev_ebg == 0) && BD_EMPTYP(BOARD->grid[ev_ebloc]) && BD_EMPTYP(BOARD->grid[ev_efloc])) { #ifdef OSCORE #ifdef CPM ++ev_ef3; #endif OSCORE += V_FORCE(0); #endif #ifdef ISCORE ISCORE = TRUE; #endif } else { if (ev_efg) { #ifdef OSCORE #ifdef CPM ++ev_ef4; #endif OSCORE += V_FORCE(0); #endif #ifdef ISCORE ISCORE = TRUE; #endif } if (ev_ebg) { #ifdef OSCORE #ifdef CPM ++ev_ef4; #endif OSCORE += V_FORCE(0); #endif #ifdef ISCORE ISCORE = TRUE; #endif } } break; case 4: if ((ev_efg != 0) || (BD_EMPTYP(BOARD->grid[ev_efloc]))) { #ifdef OSCORE #ifdef CPM ++ev_ef4; #endif OSCORE += V_FORCE(0); #endif #ifdef ISCORE ISCORE = TRUE; #endif } if ((ev_ebg != 0) || (BD_EMPTYP(BOARD->grid[ev_ebloc]))) { #ifdef OSCORE #ifdef CPM ++ev_ef4; #endif OSCORE += V_FORCE(0); #endif #ifdef ISCORE ISCORE = TRUE; #endif } break; default: #ifdef OSCORE OSCORE = V_WIN(0); #endif #ifdef ISCORE ISCORE = TRUE; #endif break; } #endif /* COMPLEX */ } #ifdef CPM if (ev_ff4 > 1) { SSCORE += V_D4FORCE(DEGEN); } else if (ev_ff3 + ev_ff4 > 1) { SSCORE += V_D3FORCE(DEGEN); } #ifdef OSCORE if (ev_ef4 > 1) { OSCORE += V_D4FORCE(0); } else if (ev_ef3 + ev_ef4 > 1) { OSCORE += V_D4FORCE(0); } #endif #endif } pente-2.2.5/src/xio/xio.h0100664000076400007640000002024407331147374013415 0ustar wmswms/* * src/xio/xio.h, part of Pente (game program) * Copyright (C) 1994-1995 William Shubert. * See "configure.h.in" for more copyright information. */ #ifndef _XIO_H_ #define _XIO_H_ 1 #ifndef XIO_DEBUG #define XIO_DEBUG 0 #endif enum { XIO_LANG_ENGLISH, XIO_LANG_FRENCH, XIO_LANG_ITALIAN, XIO_LANG_COUNT}; extern bool xio_gameover, xio_paused, xio_stopped, xio_safe_shutdown; extern bool xio_color; extern int xio_turn, xio_turn_num; extern bd_loc_t xio_lastmove, xio_moveSelected; #define XIO_PIC_OUTLINE (BUT_DCOLORS+ 0) /* The edges of the pieces. */ #define XIO_PIC_BLACK (BUT_DCOLORS+ 1) /* Used for board markings. */ #define XIO_PIC_DIMOUTLINE (BUT_DCOLORS+ 2) /* Edges of dimmed pieces. */ #define XIO_PIC_STAMP (BUT_DCOLORS+3) /* The "Pente" stamp. */ #define XIO_PIC_BUT1FG (BUT_DCOLORS+4) /* fg player 1's menu. */ #define XIO_PIC_PL1 (BUT_DCOLORS+5) /* Player 1's pieces. */ #define XIO_PIC_PL2 (BUT_DCOLORS+6) /* Player 2's pieces. */ #define XIO_PIC_DIMPL1 (BUT_DCOLORS+7) /* Player 1's dimmed pieces. */ #define XIO_PIC_DIMPL2 (BUT_DCOLORS+8) /* Player 2's dimmed pieces. */ #define XIO_PIC_MARK1 (BUT_DCOLORS+9) /* Mark on Player 1's pieces. */ #define XIO_PIC_MARK2 (BUT_DCOLORS+10) /* Mark on Player 2's pieces. */ #define XIO_PIC_BOARD(n) (BUT_DCOLORS+ 11+(n)) /* These three MUST go */ #define XIO_PIC_HIBD(n) (BUT_DCOLORS+267+(n)) /* in sequence. */ #define XIO_PIC_LOBD(n) (BUT_DCOLORS+523+(n)) #define XIO_NPICS (BUT_DCOLORS+779) #define XIO_COMPCHAR "\1\1" #define XIO_PL1CHAR "\1\2" #define XIO_PL2CHAR "\1\3" #define XIO_PL1MARKCHAR "\1\4" #define XIO_PL2MARKCHAR "\1\5" struct XioSetup_struct; struct XioHelp_struct; struct XioRemAcc_struct; struct XioMsgwin_struct; typedef struct Xio_struct { Abut *abut; ButEnv *env; int openWindows; int dpy_depth; int color; /* TrueColor, PseudoColor, or GrayScale */ int bgColor, litColor, shadColor; ButWin *mainwin, *iconwin, *tiwin; int buth; int lang; GC gc; But *gridbuts[BD_LOC_MAX], *iconbuts[BD_LOC_MAX]; But *caps1[5], *caps2[5], *digits[3], *turnlabel[15]; But *undobut, *redobut, *helpbut, *setupbut, *startbut, *quitbut; But *menu1, *menu2, *soundbut; But *tiwinok, *tiwinbox, *tiwintext, *tiwinin, *tiwincan; But *copbox, *copback, *copwords1, *copwords2, *copwords3, *copwords4; ButTimer *coptimer; Pixmap bgpic, ibgpic; But *bgbut, *ibgbut; bool wait_nonicon; /* Window mapped; on any press, record this. */ bool restart_x; bd_t iboard; bd_loc_t markpos; bool netMaster; ButLnet *lnet; ButRnet *rnet; int rcMajor, rcMinor, rcBugFix; bool remoteEnd; struct XioSetup_struct *swin; struct XioHelp_struct *hwin; struct xioRemote_struct *rwin; struct XioRemAcc_struct *remAcc; AbutMsg *waitWindow; struct { ClpEntry *ceVol, *ceOldVol, *ceSilent, *ceErr; int volume, oldVolume; bool silent, err; } sound; } Xio; typedef struct XioCompBroadcast_struct { StdInt32 think, pos, player; } XioCompBroadcast; typedef struct xio_tb_struct { int align, font; char *text; } xio_tb_t; #define XIO_ICONPIECE 3 #define XIO_ICONBORDER 2 #define XIO_ICONSIZE (19*XIO_ICONPIECE+2*XIO_ICONBORDER) extern void xio_resize(Xio *xio, bd_t *board); extern void xio_new_bg(Xio *xio, Pixmap bp, int xoff, int size, int boxw); /* From "xio.c" */ extern ButColor *xio_setup_colors(void); extern ButOut xio_press_undo(But *info); extern ButOut xio_press_move(But *info); extern ButOut xio_press_redo(But *info); extern ButOut xio_press_start(But *info); extern ButOut xio_press_help(But *info); extern ButOut xio_press_setup(But *info); extern ButOut xio_press_quit(But *info); extern ButOut xio_change_menu(But *but, int value); extern int xio_shutdown(Display *dpy); extern bool xio_opendisp(Xio *xio); extern void xio_sound_check(void); /* From "plasma.c" */ extern uchar *xio_plasma(void); /* From "mainwin.c" */ extern void xio_m_create(Xio *xio, const char *name, const char *geometry, bool iconic, bool color); extern void xio_draw_comp(void *packet, ButWin *win, int x, int y, int w, int h); extern void xio_m_set_turn(Xio *xio, int turn, int oldturn); /* From "pentebuts.c" */ extern void xio_draw_pl1char(void *packet, ButWin *win, int x, int y, int w, int h); extern void xio_draw_pl2char(void *packet, ButWin *win, int x, int y, int w, int h); extern void xio_draw_pl1markchar(void *packet, ButWin *win, int x, int y, int w, int h); extern void xio_draw_pl2markchar(void *packet, ButWin *win, int x, int y, int w, int h); extern But *but_grid_create(ButOut (*func)(But *but), ButWin *win, int layer, int flags, bd_loc_t pos); extern void but_grid_change(But *but, uint newpiece, bool marked); extern bd_loc_t but_grid_loc(But *but); extern But *but_cap_create(ButWin *win, int layer, int flags, int capnum, int player); extern void but_cap_change(But *but, uint newcap); /* From "cm2pm.c" */ extern Pixmap cm2pm(Xio *xio, uchar *cmap, uint cmapw,uint cmaph, uint w,uint h, int pic0, int npic); extern Pixmap cm2pm_chop(Xio *xio, uchar *cmap, uint cmapw,uint cmaph, uint w, uint h, int pic0, int npic, int gridw, int buth); /* From "remote.c" */ extern bool xio_r_init(Xio *xio); extern void xio_r_disable(Xio *xio); extern void xio_r_create(Xio *xio); extern void xioRemote_newState(Xio *xio); extern void xioRemote_comp(Xio *xio, bool think, bd_loc_t loc, int player); extern void xioRemote_destroy(Xio *xio); /* From "strings.c" */ extern const char *xioStr_langlist[XIO_LANG_COUNT][XIO_LANG_COUNT+1]; extern char *xioStr_mfonts[]; extern char *xioStr_bfonts[]; extern char *xioStr_language[]; extern char *xioStr_turn[]; extern char *xioStr_captures[]; extern char *xioStr_undo[]; extern char *xioStr_start[]; extern char *xioStr_stop[]; extern char *xioStr_continue[]; extern char *xioStr_redo[]; extern char *xioStr_help[]; extern char *xioStr_quit[]; extern char *xioStr_ok[]; extern char *xioStr_cancel[]; extern char *xioStr_netConn[]; extern char *xioStr_machine[]; extern char *xioStr_reject[]; extern char *xioStr_noRemote[]; extern char *xioStr_player1[]; extern char *xioStr_player2[]; extern char *xioStr_human[]; extern char *xioStr_remote[]; extern char *xioStr_comp1[]; extern char *xioStr_comp2[]; extern char *xioStr_comp3[]; extern char *xioStr_comp4[]; extern char *xioStr_comp5[]; extern char *xioStr_comp6[]; extern char *xioStr_notEnoughColors[]; extern char *xioStr_copyright[]; extern char *xioStr_nowarr[]; extern char *xioStr_seehelp[]; extern char *xioStr_setup[]; extern char *xioStr_pentesetup[]; extern char *xioStr_language[]; extern char *xioStr_color[]; extern char *xioStr_showThink[]; extern char *xioStr_soundvol[]; extern char *xioStr_off[]; extern char *xioStr_max[]; extern char *xioStr_transtab[]; extern char *xioStr_size[]; extern char *xioStr_autosize[]; extern char *xioStr_netplay[]; extern char *xioStr_enabled[]; extern char *xioStr_socket[]; extern char *xioStr_disabled[]; extern char *xioStr_connect[], *xioStr_disconnect[]; extern char *xioStr_netOffer[]; extern char *xioStr_netReject[]; extern char *xioStr_netWait[]; extern char *xioStr_netDisconnect[]; extern char *xioStr_netBusy[]; extern char *xioStr_netClosed[]; extern char *xioStr_noSockets[]; extern char *xioStr_errProtSocket[]; extern char *xioStr_errSockInUse[]; extern char *xioStr_errLSockGeneric[]; extern char *xioStr_errSockNumInvalid[]; extern char *xioStr_errRSockGeneric[]; extern char *xioStr_errRSockRefused[]; extern char *xioStr_errHostTemp[]; extern char *xioStr_errHostPerm[]; extern char *xioStr_hmenu[]; extern char *xioStr_phelp[]; extern char *xioStr_ghelp[]; extern char *xioStr_shelp[]; extern char *xioStr_nhelp[]; extern char *xioStr_cphelp[]; extern char *xioStr_ahelp[]; extern char *xioStr_chelp[]; extern xio_tb_t *xioStr_proghelp[]; extern xio_tb_t *xioStr_gamehelp[]; extern xio_tb_t *xioStr_setuphelp[]; extern xio_tb_t *xioStr_networkhelp[]; extern xio_tb_t *xioStr_comphelp[]; extern xio_tb_t *xioStr_abouthelp[]; extern xio_tb_t *xioStr_copyinghelp[]; #endif /* _XIO_H_ */ pente-2.2.5/src/xio/setup.h0100664000076400007640000000264707045637747013777 0ustar wmswms/* * src/xio/setup.h, part of Pente (game program) * Copyright (C) 1995 William Shubert. * See "configure.h.in" for more copyright information. * * Header file for routines to manage the setup window. */ /********************************************************************** * Types **********************************************************************/ typedef struct XioSetup_struct { Xio *xio; int lastVol, vol; ButWin *win; But *title, *mainbox; But *box1, *box2, *box3, *box4; But *langs, *colorb, *colorl; But *showThinkTxt, *showThinkBox; But *svt1, *svoff, *svmax, *svbar, *svout, *svtoggle; But *ttlab, *ttsize, *ttsizebox, *ttsizeout, *ttsizeup, *ttsizedown; But *ttauto, *ttsizebg; But *remote, *rmchk, *rmchklab, *rmsock, *rmsockin, *rmConn; But *ok, *help; } XioSetup; /********************************************************************** * Functions available externally. **********************************************************************/ extern struct XioSetup_struct *xioSetup_create(Xio *xio); extern void xioSetup_resize(struct XioSetup_struct *swin); extern void xioSetup_newVol(XioSetup *swin, int vol); extern void xioSetup_freshPortName(struct XioSetup_struct *swin); #define xioSetup_newRemoteEnable(s,e) \ do{if (s) butCb_set((s)->rmchk,(e),FALSE);}while(0) #define xioSetup_win(setup) ((setup)->win) extern void xioSetup_remoteRelabel(XioSetup *swin); pente-2.2.5/src/xio/helpwin.h0100664000076400007640000000130307045637747014271 0ustar wmswms/* * src/xio/helpwin.h, part of Pente (game program) * Copyright (C) 1995 William Shubert. * See "configure.h.in" for more copyright information. * * Header file for routines to manage the setup window. */ /********************************************************************** * Functions available externally. **********************************************************************/ /* Set pagenum to -1 if you don't care which page pops up. */ extern struct XioHelp_struct *xioHelp_create(Xio *xio, int pageNum); extern void xioHelp_resize(struct XioHelp_struct *help); extern void xioHelp_newPlayers(struct XioHelp_struct *help); extern void xioHelp_storeInfo(struct XioHelp_struct *help); pente-2.2.5/src/xio/sound.h0100664000076400007640000000153607045637747013763 0ustar wmswms/* * src/xio/sound.h, part of Pente (game program) * Copyright (C) 1995 William Shubert. * See "configure.h.in" for more copyright information. * * Header file for routines to manage the setup window. */ /********************************************************************** * Types **********************************************************************/ /* The nameless struct for sound is defined in xio.h. */ /********************************************************************** * Functions available externally. **********************************************************************/ extern void xioSound_create(Xio *xio); extern void xioSound_check(Xio *xio); extern ButOut xioSound_toggle(But *but, bool press); extern void xioSound_setVol(Xio *xio, int newVol, bool setLast); #define xioSound_showErr(xio) ((xio)->sound.err = FALSE) pente-2.2.5/src/xio/remAcc.h0100664000076400007640000000152507045637747014023 0ustar wmswms/* * src/xio/remAcc.h, part of Pente (game program) * Copyright (C) 1995 William Shubert. * See "configure.h.in" for more copyright information. * * Header file for routines to manage the remote accept/reject window. */ #ifndef _REMACC_H_ #define _REMACC_H_ 1 struct XioMsgwin_struct; /********************************************************************** * Types **********************************************************************/ typedef struct XioRemAcc_struct { Xio *xio; AbutMsg *mwin; ButRnet *net; MAGIC_STRUCT } XioRemAcc; /********************************************************************** * Functions available externally. **********************************************************************/ XioRemAcc *xioRemAcc_create(ButRnet *net); void xioRemAcc_destroy(XioRemAcc *ra); #endif /* _REMACC_H_ */ pente-2.2.5/src/pente.c0100644000076400007640000002320507331643351013117 0ustar wmswms/* * $Source: /home/wms/cvs/pente/src/pente.c,v $ * $Revision: 1.2 $ * $Date: 2001/08/01 00:01:45 $ * * src/pente.c, part of Pente (game program) * Copyright (C) 1994-1995 William Shubert. * See "configure.h.in" for more copyright information. */ #include "pente.h" static void stealth(void); static void play_pente(int level[BD_MAXPLAYERS], uint init(int level[BD_MAXPLAYERS], uint winner, pl_t *game), void draw(pl_t *game, bool forced), bd_loc_t selectmove(pl_t *game, int compfd), void show_think(bd_loc_t pos, uint player), pl_t *game, bd_loc_t firstmove, int from_c, int to_c); static pl_t game; Clp *pe_clp; Rnd *pe_rnd; static struct { char *name; uint (*init)(int level[BD_MAXPLAYERS], uint winner, pl_t *game); void (*draw)(pl_t *game, bool forced); bd_loc_t (*selectmove)(pl_t *game, int compfd); void (*show_think)(bd_loc_t pos, uint player); } disp[] = { #if X11_DISP {"X11", xio_init, xio_draw, xio_selectmove, xio_think}, #endif #if CURSES_DISP {"curses", cio_init, cio_draw, cio_selectmove, cio_think}, #endif {"text", text_init, text_draw, text_selectmove, text_think}, {NULL, NULL, NULL}}; static ClpSetup clpVars[] = { CLPSETUP_MSG("Pente " VERSION " by William Shubert - " DATE), CLPSETUP_MSG(""), {"VersionNumber", VERSION, NULL, 0, NULL}, {"version,-version", "f", "Print version information", CLPSETUP_BOOL|CLPSETUP_NOSAVE, NULL}, {"showthink", "t", "Show computer thinking", CLPSETUP_BOOL, NULL}, CLPSETUP_MSG(""), CLPSETUP_MSG("Display type options:"), #if X11_DISP {"X11,x11", "f", "X11", CLPSETUP_BOOL|CLPSETUP_SHOWBOOL|CLPSETUP_NOSAVE, NULL}, #endif #if CURSES_DISP {"curses", "f", "Curses", CLPSETUP_BOOL|CLPSETUP_SHOWBOOL|CLPSETUP_NOSAVE, NULL}, #endif {"text", "f", "Plain text", CLPSETUP_BOOL|CLPSETUP_SHOWBOOL|CLPSETUP_NOSAVE, NULL}, #if X11_DISP CLPSETUP_MSG(""), CLPSETUP_MSG("X11 Switches:"), {"name", "pente", "Name to use for X resource database", CLPSETUP_NOSAVE, NULL}, {"adfile", "~/.pente.ad", "Set name of ad file", CLPSETUP_NOSAVE, NULL}, {"iconic", "f", "Start up as an icon", CLPSETUP_SHOWBOOL|CLPSETUP_BOOL, NULL}, {"geometry", "430x430", "Starting geometry", 0, NULL}, {"icongeom", "63x63", "Icon geometry", 0, NULL}, {"display", NULL, "Display to use", 0, NULL}, {"color", "t", "Use color if possible", CLPSETUP_SHOWBOOL|CLPSETUP_BOOL, NULL}, {"wasColor", "t", NULL, CLPSETUP_BOOL, NULL}, {"stealth", "t", "Stealth mode", CLPSETUP_SHOWBOOL|CLPSETUP_BOOL, NULL}, {"language", "English", "Language", 0, NULL}, #if SND_AVAILABLE {"volume", "75", "Sound volume, 0..100", 0, NULL}, {"volumeLast", "75", NULL, 0, NULL}, {"silent", "f", "Same as \"-volume 0\"", CLPSETUP_BOOL, NULL}, {"soundErr", "f", NULL, CLPSETUP_BOOL, NULL}, #else /* !SND_AVAILABLE */ {"volume", "0", NULL, 0, NULL}, {"volumeLast", "0", NULL, 0, NULL}, {"silent", "f", NULL, CLPSETUP_BOOL, NULL}, {"soundErr", "t", NULL, CLPSETUP_BOOL, NULL}, #endif /* SND_AVAILABLE */ {"x.setup", "f", NULL, 0, NULL}, {"x.setup.geom", "", NULL, 0, NULL}, {"x.help", "f", NULL, 0, NULL}, {"x.help.geom", "", NULL, 0, NULL}, {"x.help.page", "0", NULL, 0, NULL}, {"x.help.bookmark", "0.0", NULL, 0, NULL}, {"x.remote.wanted", "t", NULL, 0, NULL}, {"x.remote.enabled", "t", NULL, 0, NULL}, {"x.remote.lsock", "15023", NULL, 0, NULL}, {"x.remote.rsock", "15023", NULL, 0, NULL}, {"x.remote.rname", "", NULL, 0, NULL}, #endif {"perf", "f", NULL, CLPSETUP_BOOL, NULL}, {"player1", "0", NULL, 0, NULL}, {"player2", "3", NULL, 0, NULL}, {"board", NULL, NULL, 0, NULL}, CLPSETUP_END}; static int play_level[BD_MAXPLAYERS] = {3, 0}; int main(int argc, char *argv[]) { int tnum, defnum; bd_loc_t resp; int from_c, to_c; pe_clp = clp_create(clpVars); if ((argc = clp_rCmdline(pe_clp, argv)) == CLP_ARGS_NOGOOD) { exit(1); } play_level[0] = clp_getInt(pe_clp, "player1"); play_level[1] = clp_getInt(pe_clp, "player2"); if (clp_getBool(pe_clp, "version")) { printf("Pente " VERSION " by William Shubert (wms@igoweb.org) " DATE "\n"); exit(0); } if (clp_getBool(pe_clp, "perf")) { /* Analyze the performance of pente...have the computer play itself * at level 5, with a known random seed, to get the same game * every time. Time this on different machines to determine * how fast that machine is. */ bd_loc_t loc; bool game_over; pe_rnd = rnd_create(0); pl_init(&game); do { loc = comp_noSpawnGetMove(&game, 5); game_over = pl_move(&game, loc); } while (!game_over); if (pl_nmoves(&game) != 34) { fprintf(stderr, "pente: Timing invalid. Game play was not deterministic. " "%d moves.\n", pl_nmoves(&game)); exit(1); } printf("pente: Timed game was %d moves long.\n", pl_nmoves(&game)); exit(0); } for (tnum = 0, defnum = 0; disp[tnum].init; ++tnum) { if (clp_getBool(pe_clp, disp[tnum].name)) ++defnum; } pe_rnd = rnd_create(time(NULL) ^ getpid()); #ifdef DEBUG #define STEALTH_VALID (!(DEBUG)) #else #define STEALTH_VALID 1 #endif /* * It's really more convient, IMHO, to do the stealth in the X11 code. * But, alas, doing stealth after spawning comp causes errors on some * operating systems. :-( */ #if X11_DISP if (clp_getBool(pe_clp, "stealth") && STEALTH_VALID && ((defnum == 0) || clp_getBool(pe_clp, "x11"))) stealth(); #endif comp_spawn(&from_c, &to_c); pl_init(&game); switch(defnum) { case 0: for (tnum = 0; disp[tnum].init; ++tnum) { resp = disp[tnum].init(play_level, BD_MAXPLAYERS, &game); if (resp != PE_CANTPLAY) { play_pente(play_level, disp[tnum].init, disp[tnum].draw, disp[tnum].selectmove, disp[tnum].show_think, &game, resp, from_c, to_c); break; } else { fprintf(stderr, "Pente: Could not start up %s display.\n" " Other displays are available with these commands:\n", disp[tnum].name); for (++tnum; disp[tnum].name != NULL; ++tnum) { fprintf(stderr, " pente -%s\n", disp[tnum].name); } exit(1); } } if (!disp[tnum].init) { fprintf(stderr, "pente: Error - Init failed.\n"); exit(1); } break; case 1: for (tnum = 0; !clp_getBool(pe_clp, disp[tnum].name); ++tnum); resp = disp[tnum].init(play_level, BD_MAXPLAYERS, &game); if (resp != PE_CANTPLAY) { play_pente(play_level, disp[tnum].init, disp[tnum].draw, disp[tnum].selectmove, disp[tnum].show_think, &game, resp, from_c, to_c); } else { fprintf(stderr, "pente: Display type \"%s\" failed.\n", disp[tnum].name); exit(1); } break; default: fprintf(stderr, "pente: At most one display type can be specified.\n"); exit(1); } exit(0); } static void play_pente(int level[BD_MAXPLAYERS], uint init(int level[BD_MAXPLAYERS], uint winner, pl_t *game), void draw(pl_t *game, bool forced), bd_loc_t selectmove(pl_t *game, int compfd), void show_think(bd_loc_t pos, uint player), pl_t *game, bd_loc_t firstmove, int from_c, int to_c) { bd_loc_t loc = firstmove; bool game_over = FALSE, paused = FALSE; uint turn_num, old_cap, player = pl_player(game); char gameStr[4*(19*19+20)]; for (;;) { switch(loc) { case PE_CONTINUE: paused = FALSE; break; case PE_UNDO: player ^= 1; paused = TRUE; game_over = FALSE; pl_undo(game); draw(game, TRUE); break; case PE_REDO: paused = TRUE; old_cap = pl_board(game)->captures[player]; game_over = pl_redo(game); draw(game, TRUE); while (old_cap < pl_board(game)->captures[player]) { snd_play(&pe_capture_snd); ++old_cap; } player ^= 1; if (game_over) snd_play(&pe_gameover_snd); break; case PE_PAUSE: paused = TRUE; break; case PE_RESTART: pl_init(game); player = pl_player(game); turn_num = pl_turn(game); paused = FALSE; game_over = FALSE; break; default: if (paused) paused = FALSE; assert(pl_movep(game, loc)); if (!pl_movep(game, loc)) { fprintf(stderr, "pente: Illegal move reported.\n"); exit(1); } old_cap = pl_board(game)->captures[player]; game_over = pl_move(game, loc); pl_game_str(game, gameStr); clp_setStr(pe_clp, "board", gameStr); while (old_cap < pl_board(game)->captures[player]) { snd_play(&pe_capture_snd); ++old_cap; } if (game_over) snd_play(&pe_gameover_snd); player ^= 1; break; } draw(game, (game_over || paused || ((level[player^1] == 0) || (level[player] != 0)))); if (game_over || paused) loc = init(level, player^1, game); else { if (level[player] < 1) { loc = selectmove(game, from_c); } else { comp_start(game, level[player], to_c); do { loc = selectmove(game, from_c); if (loc == PE_COMP) { loc = comp_getmove(from_c, show_think, player); } else { comp_reset(&from_c, &to_c); } } while (loc == PE_COMP); } } } } void pe_output_vars(void) { #if X11_DISP clp_wFile(pe_clp, clp_getStr(pe_clp, "adfile"), clp_getStr(pe_clp, "name")); #else clp_wFile(pe_clp, "~/.pente.ad", "pente"); #endif } static void stealth(void) { int pid; #ifdef TIOCNOTTY int tty; #endif pid = fork(); if (pid < 0) { perror("pente: fork() failed"); return; } else if (pid > 0) /* Parent just exits. */ exit(0); /* Go stealth (ditch our controlling tty). */ #ifdef TIOCNOTTY tty = open("/dev/tty", 0); if (tty < 0) return; ioctl(tty, TIOCNOTTY, 0); close(tty); #endif } pente-2.2.5/src/pe_snd.c0100664000076400007640000003772707045637747013312 0ustar wmswms/* * src/pe_snd.c, part of Pente (game program) * Copyright (C) 1994 William Shubert. * See "configure.h.in" for more copyright information. */ #include #include #include "pente.h" static uchar gameover_buf[] = { 255,173,159,154,152,154,159,173,255,46,31,26,24,26,31,46,255,174,159,154,153, 154,159,174,255,46,31,27,25,27,31,46,255,174,160,155,153,155,160,174,255,46, 32,27,25,27,32,46,255,174,160,155,154,155,160,175,255,47,33,27,26,27,33,47, 255,175,161,156,154,156,161,175,255,47,33,28,26,28,33,47,255,175,162,156,155, 156,162,175,255,47,34,28,27,28,34,47,255,175,162,156,155,157,162,175,255,47, 35,29,27,29,35,47,255,175,163,157,155,157,163,176,255,48,35,29,28,29,35,48, 255,176,164,157,156,157,164,176,255,48,36,30,28,30,36,49,255,177,164,158,156, 158,164,177,255,49,36,30,28,30,37,49,255,177,165,158,157,158,165,178,255,50, 37,30,29,30,37,50,255,178,165,158,157,159,165,178,255,50,38,31,29,31,38,50, 255,179,166,159,158,159,166,179,255,51,38,31,30,31,38,51,255,179,166,159,158, 159,167,179,255,51,39,31,30,31,39,52,255,180,167,160,158,160,167,180,255,52, 39,32,30,32,39,52,255,180,168,160,159,160,168,181,255,53,40,33,31,33,40,53, 255,181,168,161,159,161,168,181,255,53,40,33,31,33,40,53,255,181,169,162,159, 162,169,182,255,54,41,34,32,34,41,54,255,182,169,162,160,162,169,182,255,54, 41,35,32,35,41,54,255,182,170,163,161,163,170,183,255,55,42,35,33,35,42,55, 255,183,170,164,161,164,170,183,255,55,42,36,34,36,42,55,255,183,170,164,162, 164,171,184,255,56,43,36,34,37,43,56,255,184,171,165,163,165,171,184,255,56, 43,37,35,37,43,56,255,184,171,165,163,165,172,185,255,57,44,38,36,38,44,57, 255,185,172,166,164,166,172,185,255,57,44,38,36,38,44,57,255,185,172,166,164, 167,172,186,255,58,44,39,37,39,45,58,255,186,173,167,165,167,173,186,255,58, 45,39,37,39,45,58,255,186,173,168,166,168,173,186,255,59,45,40,38,40,45,59, 255,187,173,168,166,168,174,187,255,59,46,40,38,40,46,59,255,187,174,169,167, 169,174,187,255,59,46,41,39,41,46,60,255,188,174,169,167,169,174,188,255,60, 46,41,40,41,47,60,255,188,175,170,168,170,175,188,255,60,47,42,40,42,47,60, 255,188,175,170,168,170,175,189,255,61,47,42,41,42,47,61,255,189,175,170,169, 171,175,189,255,61,47,43,41,43,47,61,255,189,175,171,169,171,175,189,255,61, 47,43,42,43,47,61,255,190,176,171,170,171,176,190,255,62,48,44,42,44,48,62, 255,190,176,172,170,172,176,190,255,62,49,44,42,44,49,62,255,190,177,172,171, 172,177,190,255,62,49,44,43,45,49,63,255,191,178,173,171,173,178,191,255,63, 50,45,43,45,50,63,255,191,178,173,172,173,178,192,255,64,50,45,44,45,51,64, 255,192,179,173,172,174,179,192,255,64,51,46,44,46,51,65,255,193,179,174,172, 174,180,193,255,65,52,46,45,46,52,65,255,193,180,174,173,174,180,193,255,66, 52,46,45,46,52,66,255,194,181,175,173,175,181,194,255,66,53,47,45,47,53,66, 255,194,181,175,174,175,181,195,255,67,53,47,46,47,53,67,255,195,182,175,174, 175,182,195,255,67,54,47,46,47,54,68,255,196,182,175,174,175,182,196,255,68, 54,47,47,47,55,68,255,196,183,176,175,176,183,196,255,68,55,48,47,48,55,69, 255,197,183,176,175,176,183,197,255,69,55,49,47,49,56,69,255,197,184,177,175, 177,184,198,255,70,56,49,47,49,56,70,255,198,184,178,175,178,184,198,255,70, 56,50,48,50,57,70,255,198,185,178,176,178,185,199,255,71,57,50,48,51,57,71, 255,199,185,179,177,179,185,199,255,71,57,51,49,51,57,71,255,199,186,179,177, 179,186,200,255,72,58,52,50,52,58,72,255,200,186,180,178,180,186,200,255,72, 58,52,50,52,58,72,255,200,186,181,178,181,187,200,255,73,59,53,51,53,59,73, 255,201,187,181,179,181,187,201,255,73,59,53,51,53,59,73,255,201,187,182,180, 182,187,201,255,73,60,54,52,54,60,74,255,202,188,182,180,182,188,202,255,74, 60,54,53,54,60,74,255,202,188,183,181,183,188,202,255,74,60,55,53,55,60,74, 255,203,189,183,181,183,189,203,255,75,61,55,54,56,61,75,255,203,189,184,182, 184,189,203,255,75,61,56,54,56,61,75,255,203,189,184,182,184,189,204,255,163, 156,169,55,26,20,29,255,157,148,154,183,41,28,35,255,163,157,170,55,26,21,29, 255,157,149,154,183,42,29,36,255,164,157,170,56,26,21,30,255,158,149,155,184, 42,29,36,255,164,157,170,56,27,22,30,255,158,150,155,184,43,30,37,255,165, 158,171,57,27,22,30,255,158,150,156,185,43,30,38,255,166,158,171,57,28,23,31, 255,159,151,156,185,44,30,38,255,166,159,172,58,28,23,31,255,159,152,156,186, 44,31,39,255,167,159,172,58,29,24,31,255,159,152,157,186,44,31,39,255,167, 159,173,58,29,24,32,255,160,153,157,187,45,32,40,255,168,160,173,59,29,25,33, 255,161,153,158,187,45,32,40,255,168,160,173,59,30,25,33,255,161,154,158,188, 46,33,41,255,169,161,174,60,30,26,34,255,162,154,158,188,46,34,41,255,169, 162,174,60,31,26,35,255,163,155,159,188,46,34,42,255,170,162,175,61,31,27,35, 255,163,155,159,189,47,35,42,255,170,163,175,61,31,27,36,255,164,155,159,189, 47,35,43,255,171,164,175,61,32,28,37,255,165,156,160,189,47,36,43,255,171, 164,175,62,33,28,37,255,165,156,161,190,47,37,44,255,172,165,175,62,33,29,38, 255,166,157,162,190,48,37,44,255,172,165,176,62,34,29,38,255,166,157,162,191, 49,38,44,255,172,166,177,63,35,29,39,255,167,158,163,191,49,38,45,255,173, 167,177,64,35,30,39,255,167,158,163,192,50,39,45,255,173,167,178,64,36,30,40, 255,168,158,164,193,50,39,46,255,174,168,179,65,36,31,40,255,168,159,165,193, 51,40,46,255,174,168,179,65,37,31,41,255,169,159,165,194,52,41,46,255,174, 169,180,66,38,31,41,255,169,159,166,194,52,41,47,255,175,169,180,67,38,32,42, 255,170,160,166,195,53,42,47,255,175,170,181,67,39,33,42,255,170,161,167,196, 53,42,47,255,175,170,182,68,39,33,43,255,171,161,167,196,54,42,47,255,175, 171,182,68,40,34,43,255,171,162,168,197,54,43,48,255,176,171,183,69,40,34,44, 255,172,163,168,197,55,43,48,255,177,171,183,70,41,35,44,255,172,163,169,198, 55,44,49,255,177,172,184,70,41,36,45,255,173,164,169,198,56,44,50,255,178, 172,184,71,42,36,45,255,173,164,170,199,56,45,50,255,178,173,185,71,42,37,45, 255,173,165,170,199,57,45,51,255,179,173,185,72,43,38,46,255,174,166,171,200, 57,45,52,255,180,174,186,72,43,38,46,255,174,166,171,200,58,46,52,255,180, 174,186,72,44,39,46,255,175,167,172,201,58,46,53,255,181,174,186,73,44,39,47, 255,175,167,172,201,59,47,53,255,181,175,187,73,44,40,47,255,175,168,173,202, 59,47,54,255,182,175,187,74,45,40,47,255,175,168,173,202,60,47,54,255,182, 175,188,74,45,41,47,255,175,169,173,202,60,47,55,255,183,175,188,75,46,41,48, 255,176,169,174,203,60,47,55,255,183,176,188,75,46,42,49,255,177,170,174,203, 61,48,56,255,184,176,189,76,46,42,49,255,177,170,175,204,61,49,56,255,184, 177,189,76,47,43,50,255,178,171,175,204,61,49,57,255,185,178,190,76,47,43,51, 255,179,171,175,204,62,50,57,255,185,178,190,77,47,44,51,255,179,172,175,205, 62,51,58,255,186,179,190,77,47,44,52,255,180,172,175,205,63,51,58,255,186, 179,191,77,48,44,52,255,180,172,176,206,63,52,59,255,187,180,191,78,49,45,53, 255,181,173,177,206,64,52,59,255,187,181,192,78,49,45,53,255,181,173,177,206, 65,53,59,255,188,181,193,78,50,46,54,255,182,174,178,207,65,54,60,255,188, 182,193,79,50,46,54,255,183,174,179,207,66,54,60,255,188,182,194,79,51,46,55, 255,183,174,179,207,66,55,61,255,189,183,195,79,52,47,55,255,184,175,180,208, 67,55,61,255,189,183,195,80,52,47,56,255,184,175,180,208,68,56,61,255,189, 184,196,81,53,47,56,255,185,175,181,209,68,56,62,255,190,184,196,81,53,47,57, 255,185,175,182,209,69,57,62,255,190,185,197,82,54,48,57,255,185,176,182,210, 69,57,62,255,191,185,197,82,54,48,58,255,186,177,183,211,70,58,63,255,191, 186,198,83,55,49,58,255,186,177,183,211,70,58,64,255,192,186,198,83,55,50,59, 255,187,178,184,212,71,58,64,255,193,187,199,84,56,50,59,255,147,178,30,212, 155,59,21,255,149,187,27,84,158,51,20,255,148,179,30,213,155,59,21,255,149, 187,27,85,158,52,20,255,148,180,30,213,156,60,22,255,150,188,28,85,159,52,21, 255,149,180,31,214,156,60,22,255,150,188,28,86,159,53,22,255,150,181,31,214, 157,60,23,255,151,189,29,86,159,53,22,255,150,181,31,215,157,61,23,255,151, 189,29,87,160,54,23,255,151,182,32,215,157,61,24,255,152,189,30,87,160,54,23, 255,151,182,33,215,158,62,24,255,153,190,30,88,161,55,24,255,152,183,33,216, 158,62,25,255,153,190,30,88,162,55,24,255,152,183,34,216,159,62,25,255,154, 190,31,89,162,56,25,255,153,184,35,217,159,63,26,255,154,191,31,89,163,56,25, 255,153,184,35,217,159,63,26,255,154,192,31,89,164,57,26,255,154,185,36,218, 160,64,27,255,155,192,32,90,164,57,26,255,154,185,36,218,161,65,27,255,155, 193,33,90,165,58,27,255,155,186,37,218,161,65,28,255,156,194,33,91,165,58,27, 255,155,186,38,219,162,66,28,255,156,194,34,91,166,59,28,255,156,187,38,219, 162,67,29,255,157,195,35,91,167,59,28,255,156,187,39,219,163,67,29,255,157, 195,35,92,167,59,28,255,157,188,39,220,164,68,29,255,157,196,36,92,168,60,29, 255,157,188,40,220,164,68,30,255,158,196,37,92,168,60,29,255,157,188,40,220, 165,69,30,255,158,197,37,93,169,61,30,255,158,189,41,221,166,69,31,255,159, 198,38,93,169,61,30,255,158,189,41,221,166,70,31,255,159,198,38,93,170,61,30, 255,158,189,42,221,167,70,31,255,159,199,39,94,170,62,31,255,159,190,42,222, 167,71,32,255,160,199,39,94,171,62,31,255,159,190,43,222,168,71,33,255,161, 200,40,94,171,62,32,255,160,191,43,222,168,72,33,255,161,200,40,94,171,63,32, 255,160,191,44,223,169,72,34,255,162,201,41,95,172,64,33,255,161,192,44,223, 169,73,34,255,163,201,41,95,172,64,34,255,162,193,44,223,170,73,35,255,163, 201,42,95,173,65,34,255,162,193,45,223,170,74,36,255,164,202,42,96,173,66,35, 255,163,194,45,224,171,74,36,255,164,202,43,96,174,66,36,255,164,194,46,224, 171,75,37,255,165,203,43,97,174,67,36,255,164,195,46,225,172,75,38,255,166, 203,44,97,174,67,37,255,165,196,46,225,172,75,38,255,166,204,44,98,175,68,37, 255,165,196,47,226,172,76,39,255,167,204,45,98,175,69,38,255,166,197,47,226, 173,76,39,255,167,204,45,99,175,69,38,255,167,197,47,227,173,77,40,255,168, 205,45,99,175,70,39,255,167,198,47,227,174,77,40,255,168,205,46,100,176,70, 40,255,168,198,48,228,174,77,41,255,169,205,46,100,176,71,40,255,168,199,49, 228,174,78,41,255,169,206,46,100,177,71,41,255,169,199,49,229,175,78,42,255, 170,206,47,101,178,72,41,255,169,200,50,229,175,78,42,255,170,206,47,101,178, 72,42,255,170,200,50,229,175,79,43,255,171,207,47,102,179,73,42,255,170,201, 51,230,175,79,43,255,171,207,47,102,179,73,42,255,171,201,52,230,176,79,44, 255,172,207,48,102,180,74,43,255,171,202,52,231,176,80,44,255,172,208,49,103, 181,74,43,255,171,202,53,231,177,80,44,255,172,209,49,103,181,74,44,255,172, 203,53,231,178,81,45,255,173,209,50,103,182,75,44,255,172,203,54,232,178,82, 45,255,173,210,51,104,182,75,45,255,173,203,54,232,179,82,46,255,174,210,51, 104,183,76,45,255,173,204,55,232,180,83,46,255,174,211,52,105,183,76,45,255, 174,204,55,233,180,83,46,255,174,211,52,105,184,76,46,255,174,204,56,233,181, 84,47,255,175,212,53,105,184,77,46,255,174,205,56,233,181,84,47,255,175,212, 53,105,185,77,47,255,175,205,57,234,182,85,47,255,175,213,54,106,185,77,47, 255,175,206,57,234,182,85,47,255,175,213,54,106,186,78,47,255,175,206,58,234, 183,86,48,255,176,214,55,106,186,78,47,255,175,206,58,234,183,86,48,255,176, 214,56,107,187,79,48,255,176,207,59,235,184,87,49,255,177,215,56,107,187,79, 48,255,176,207,59,235,184,87,50,255,178,215,56,107,187,79,49,255,177,207,60, 235,185,88,50,255,178,216,57,107,188,79,49,255,178,208,60,236,185,88,51}; static uchar move_buf[] = { /* Actual noise: Me rapping on my box of business cards. */ 246,254,118,108,104,103,105,107,111,247,234,235,222,219,215,212,82,33,32,46, 184,147,68,28,87,156,150,166,192,34,54,25,37,58,159,102,26,174,153,155,165, 166,214,172,175,198,56,18,21,28,74,157,29,28,165,155,165,165,192,25,47,154, 176,55,23,174,171,20,36,39,166,149,175,44,44,152,172,162,59,20,34,33,56,57, 40,59,57,173,144,150,175,33,46,161,217,30,47,47,184,148,154,158,162,204,35, 43,47,70,176,174,170,186,54,21,22,28,29,36,40,61,176,154,150,157,158,181,43, 50,226,75,51,48,47,47,92,198,191,64,57,172,161,188,47,56,237,234,80,64,53,91, 183,179,200,80,94,202,186,183,181,178,191,88,88,96,53,47,52,67,122,62,59,60, 75,204,200,93,64,72,206,201,91,86,229,188,201,77,58,52,61,92,95,88,105,201, 184,185,199,211,206,213,248,76,75,235,202,187,197,216,236,90,80,94,104,89, 236,204,111,61,72,123,73,59,59,81,215,106,92,90,77,93}; static uchar capture_buf[] = { /* Actual sound: Artificially generated. */ 255,156,152,162,191,250,102,51,29,24,37,178,154,154,171,209,255,81,43,27,26, 51,166,153,158,181,231,123,65,36,26,30,255,158,154,165,194,251,104,54,31,26, 39,181,156,157,173,212,255,84,45,29,28,54,168,155,160,183,233,123,68,39,28, 33,255,161,156,168,197,251,106,56,34,29,42,184,158,159,175,214,255,86,47,31, 30,56,171,157,164,186,235,123,71,42,30,36,255,164,158,170,199,252,107,59,37, 31,44,186,160,161,177,216,255,88,49,34,33,59,173,159,167,188,236,124,73,44, 32,39,255,167,161,172,202,252,108,61,40,33,46,188,163,164,180,218,255,90,52, 37,36,61,175,163,169,190,237,124,75,46,36,41,255,169,164,174,204,252,110,62, 42,36,47,190,166,167,183,220,255,92,55,40,39,63,177,166,171,192,238,124,77, 47,38,44,255,172,167,176,206,252,111,66,44,39,51,193,169,170,185,222,255,94, 57,42,42,66,180,168,174,195,239,125,79,50,41,46,255,174,169,179,207,253,111, 69,46,42,53,196,171,172,187,223,255,95,59,44,44,69,182,171,175,198,241,125, 81,53,43,47,255,175,172,182,210,253,113,71,48,44,56,198,173,174,189,225,255, 98,61,46,46,71,185,173,178,201,242,125,84,56,45,50,255,178,174,184,213,253, 115,74,51,46,58,201,175,175,191,228,255,100,64,48,47,74,187,175,181,203,243, 125,87,58,47,53,255,181,175,187,215,253,116,76,54,47,60,203,177,178,195,230, 255,102,67,51,50,76,189,176,183,205,245,125,89,60,50,55,255,184,178,189,217, 253,117,77,56,50,62,205,180,181,197,232,255,104,70,54,53,78,191,180,186,206, 246,125,91,62,52,58,255,186,181,190,219,254,118,79,59,53,65,207,183,184,200, 233,255,105,72,56,56,79,194,182,188,209,247,126,93,65,55,60,255,188,183,194, 221,254,119,82,61,56,68,209,185,186,202,235,255,107,74,59,58,82,197,185,190, 211,247,126,94,68,58,62,255,190,186,197,222,254,119,85,63,58,71,212,188,188, 204,236,255,108,76,61,60,85,200,187,192,214,248,126,95,71,60,64,255,193,188, 199,224,254,120,87,66,60,73,214,190,190,206,237,255,109,78,62,62,87,202,189, 195,216,249,126,98,73,62,67,255,196,190,202,227,254,121,89,69,62,75,217,192, 193,208,238,255,110,80,66,65,89,204,191,198,218,249,126,100,75,64,70,255,198, 193,204,229,254,122,91,71,65,77,219,195,196,211,239,255,111,83,68,68,91,206, 194,201,220,250,126,102,77,67,73,255,201,196,206,231,254,122,93,74,68,79,220, 198,199,213,241,255,113,86,71,71,93,208,197,203,222,250,126,104,79,70,75,255, 203,198,207,232,254,123,94,76,71,82,222,200,201,216,242,255,114,88,73,73,94, 211,200,205,223,251,126,106,81,72,77,255,205,201,210,234,254,123,96,78,73,84, 223,203,203,218,244,255,116,90,76,75,96,213,202,206,225,251,126,107,84,75,79, 255,207,203,213,235,254,123,98,79,75,87,226,205,205,220,245,255,117,92,77,77, 98,216,204,209,228,252,126,108,87,77,81,255,209,205,215,237,254,124,100,82, 77,89,228,206,207,221,246,255,118,93,79,79,101,218,206,211,230,252,126,110, 89,78,84,255,212,207,217,238,254,124,102,85,79,91,230,208,209,223,247,255, 119,95,82,81,103,219,207,214,231,252,126,111,91,80,86,255,214,209,219,239, 254,124,104,87,81,93,232,211,212,225,247,255,119,97,84,84,104,221,210,216, 233,253,126,111,92,83,88,255,216,212,221,240,254,125,106,89,84,94,233,214, 214,227,248,255,120,99,87,86,106,223,213,218,235,253,126,113,94,86,90,255, 218,214,222,242,254,125,107,91,86,96,235,216,217,229,249,255,121,101,89,89, 107,225,215,220,236,253,255,115,95,88,92,255,220,216,224,243,254,125,109,93, 89,98,236,218,219,231,249,255,121,103,91,91,109,227,217,222,237,253,255,116, 98,90,94,255,222,218,226,244,255,125,110,94,91,100,237,220,220,233,250,255, 122,105,93,92,110,229,219,223,238,253,255,117,100,92,95,255,223,220,229,245, 255,125,111,96,92,102,238,222,222,234,250,255,122,106,94,94,111,231,221,225, 239,253,255,118,102,94,97,255,226,222,231,246,255,125,112,98,94,104,239,223, 223,236,251,255,123,108,96,95,112,233,223,228,241,254,255,119,104,95,100,255, 228,223,232,247,255,126,113}; Snd pe_gameover_snd = snd_define(gameover_buf); Snd pe_move_snd = snd_define(move_buf); Snd pe_capture_snd = snd_define(capture_buf); pente-2.2.5/src/play.c0100664000076400007640000001004107045637747012763 0ustar wmswms/* * src/play.c, part of Pente (game program) * Copyright (C) 1994 William Shubert. * See "configure.h.in" for more copyright information. * * Functions used to play a game. No concern for I/O is provided. */ #include "pente.h" void pl_init(pl_t *game) { bd_init(&game->board); game->move = 0; game->maxmove = 0; } /* Returns TRUE if it is a valid move, FALSE otherwise. */ bool pl_movep(pl_t *game, bd_loc_t loc) { uint turn = pl_turn(game), player = pl_player(game); if ((turn == 0) && (player == 0)) return(loc == bd_xy_loc(9, 9)); if ((loc > BD_GRIDSIZE) || !BD_EMPTYP(game->board.grid[loc])) return(FALSE); if ((turn == 1) && (player == 0)) { int x, y; x = bd_loc_x(loc); y = bd_loc_y(loc); if ((x >= 9-2) && (x <= 9+2) && (y >= 9-2) && (y <= 9+2)) return(FALSE); } return(TRUE); } /* * Returns TRUE if the move caused a win. */ bool pl_move(pl_t *game, bd_loc_t loc) { bd_t *board = &(game->board); uint player = pl_player(game); uint captures = game->board.captures[player]; uint dir; int dvec; bool win = FALSE; game->movelist[game->move++] = loc; game->maxmove = game->move; board->grid[loc] = BD_PLAYER(player); for (dir = 0; dir < 8; ++dir) { dvec = bd_dvec[dir]; if (BD_PLAYERP(board->grid[loc+dvec]) && (board->grid[loc+dvec] != BD_PLAYER(player)) && (board->grid[loc+dvec] == board->grid[loc+dvec+dvec]) && (board->grid[loc+dvec+dvec+dvec] == BD_PLAYER(player))) { ++captures; board->grid[loc+dvec] = BD_EMPTYA; board->grid[loc+dvec+dvec] = BD_EMPTYA; } } board->captures[player] = captures; if (captures >= 5) win = TRUE; for (dir = 0; dir < 4; ++dir) { int run_length = 1; bd_loc_t curloc; dvec = bd_dvec[dir]; curloc = loc+dvec; while (board->grid[curloc] == BD_PLAYER(player)) { curloc += dvec; ++run_length; } curloc = loc-dvec; while (board->grid[curloc] == BD_PLAYER(player)) { curloc -= dvec; ++run_length; } if (run_length >= 5) { win = TRUE; board->grid[loc] = BD_WINNER(player); curloc = loc+dvec; while (board->grid[curloc] == BD_PLAYER(player)) { board->grid[curloc] = BD_WINNER(player); curloc += dvec; } curloc = loc-dvec; while (board->grid[curloc] == BD_PLAYER(player)) { board->grid[curloc] = BD_WINNER(player); curloc -= dvec; } } } return(board->gameover = win); } void pl_undo(pl_t *game) { uint turn, newturns, maxturns; if (game->move == 0) { fprintf(stderr, "pente: Internal error detected. move=0, undo.\n"); exit(1); } maxturns = game->maxmove; newturns = game->move - 1; pl_init(game); for (turn = 0; turn < newturns; ++turn) pl_move(game, game->movelist[turn]); game->maxmove = maxturns; } bool pl_redo(pl_t *game) { uint turn, newturns, maxturns; bool game_over = FALSE; if (game->move == game->maxmove) { fprintf(stderr, "pente: Internal error detected. move=maxmove=%d, redo.\n", game->move); exit(1); } maxturns = game->maxmove; newturns = game->move + 1; pl_init(game); for (turn = 0; turn < newturns; ++turn) game_over = pl_move(game, game->movelist[turn]); game->maxmove = maxturns; return(game_over); } uint pl_turn(pl_t *game) { return(game->move >> 1); } uint pl_player(pl_t *game) { return(game->move & 1); } bd_t *pl_board(pl_t *game) { return(&(game->board)); } uint pl_nmoves(pl_t *game) { return(game->move); } uint pl_maxmoves(pl_t *game) { return(game->maxmove); } bd_loc_t pl_getmove(pl_t *game, uint movenum) { return(game->movelist[movenum]); } void pl_game_str(pl_t *game, char *str) { int i; for (i = 0; i < pl_nmoves(game); ++i) { str = bd_loc_str(pl_getmove(game, i), str); *(str++) = ','; } if (i) *(str-1) = '\0'; else *str = '\0'; } void pl_str_game(const char *str, pl_t *game) { while (*str != '\0') { pl_move(game, bd_str_loc(str, &str)); if (*str == ',') ++str; } } pente-2.2.5/src/board.c0100664000076400007640000000457707045637747013126 0ustar wmswms/* * src/board.c, part of Pente (game program) * Copyright (C) 1994 William Shubert. * See "configure.h.in" for more copyright information. * * Defines the board data type and related data types. * Types: * bd_t - The board itself. * bd_loc_t - The location; used as an index into the board. Useful values * range from BD_LOC_MIN to BD_LOC_MAX. Valid values are from * 0 to BD_GRIDSIZE. * x,y - The x and y coordinates of a space on the board. Range from * 0 through 18. If you want to access board locations through * integers, here's how to do it. */ #include "pente.h" /* * Direction vectors for the 8 directions. * That is, to move in direction 3, add bd_dvec[3] to loc. * Opposite directions are space 4 directions apart. * That is, bd_dvec[n] = -bd_dvec[n+4]. * * lvec[] in xio/xdraw.c is based on this array. Be sure to change both or * neither. */ const int bd_dvec[8] = {-22-1, -22, -22+1, -1, 22+1, 22, 22-1, 1}; int bd_loc_x(bd_loc_t loc) { return((loc-BD_LOC_MIN)%22); } int bd_loc_y(bd_loc_t loc) { return((loc-BD_LOC_MIN)/22); } bd_loc_t bd_xy_loc(int x, int y) { return(x + y*22 + BD_LOC_MIN); } void bd_init(bd_t *board) { uint player; int x, y; bd_loc_t loc; for (player = 0; player < BD_MAXPLAYERS; ++player) board->captures[player] = 0; for (loc = 0; loc < BD_GRIDSIZE; ++loc) board->grid[loc] = BD_EDGE; for (x = 0; x < 19; ++x) { for (y = 0; y < 19; ++y) board->grid[bd_xy_loc(x, y)] = BD_EMPTYB; } board->gameover = FALSE; } bd_loc_t bd_str_loc(const char *str, const char **strout) { int x, y; if (isdigit(str[0])) { y = str[0] - '0'; ++str; if (isdigit(str[0])) { y = (y * 10) + str[0] - '0'; ++str; } x = tolower(*(str++)) - 'a'; } else { x = tolower(*(str++)) - 'a'; y = str[0] - '0'; ++str; if (isdigit(str[0])) { y = (y * 10) + str[0] - '0'; ++str; } } --y; if ((x == 'i' - 'a') || ((uint)x > 19) || ((uint) y > 18)) { return(BD_LOC_MAX); } if (x > 'i' - 'a') --x; if (strout != NULL) *strout = str; return(bd_xy_loc(x, y)); } char *bd_loc_str(bd_loc_t loc, char *str) { char cout[] = "abcdefghjklmnopqrst"; sprintf(str, "%c%d", cout[bd_loc_x(loc)], bd_loc_y(loc) + 1); while (*(++str)); return(str); } pente-2.2.5/src/cio.c0100644000076400007640000002016407331643351012557 0ustar wmswms/* * $Source: /home/wms/cvs/pente/src/cio.c,v $ * $Revision: 1.2 $ * $Date: 2001/08/01 00:01:45 $ * * src/cio.c, part of Pente (game program) * Copyright (C) 1994-1995 William Shubert. * See "configure.h.in" for more copyright information. */ /* * Typically a file will include wms.h, which includes configure.h. * But many curses.h files are SO BADLY put together that I have conflicts * all over the place, so I can't include wms.h. */ #include #if CURSES_DISP #include #include "pente.h" #define CTRLKEY(ch) ((ch)-'A'+1) static WINDOW *win; static const char plchar[2] = {'#', 'O'}; static const char xname[] = "ABCDEFGHJKLMNOPQRST"; static char plname[2][9] = {"Player 1", "Player 2"}; static int *levels; static void quit(void); static bool open_window(void); static bool readstr(uint x, uint y, char *prompt, char *buf, int buflen); static void redraw(void); bd_loc_t cio_init(int *comp_level, uint winner, pl_t *game) { static bool open_needed = TRUE; int i, scans; levels = comp_level; if (open_needed) { pl_t game; if (!open_window()) return(PE_CANTPLAY); open_needed = FALSE; pl_init(&game); cio_draw(&game, TRUE); } if (winner != BD_MAXPLAYERS) { move(22,0); clrtobot(); mvprintw(22,29, "%s [%c] has won!", plname[winner], plchar[winner]); } for (i = 0; i < 2; ++i) { char level_q[100], tmpbuf[10]; sprintf(level_q, "Level of player %d [0=Player, 1..6=Computer]: ", i+1); do { tmpbuf[0] = '\0'; if (!readstr(23,17, level_q, tmpbuf, 2)) { i = -1; break; } if (tmpbuf[0] == 'U') { if ((pl_turn(game) >= 1) && ((comp_level[0] < 1) || (comp_level[1] < 1))) return(PE_UNDO); else { putchar('\a'); i = -1; break; } } if ((scans = sscanf(tmpbuf, "%d", comp_level + i)) == 1) if (comp_level[i] > 6) scans = 0; } while (scans != 1); if (comp_level[i] == 0) sprintf(plname[i], "Player %d", i+1); else sprintf(plname[i], "Comp Lv%d", comp_level[i]); } move(23,0); clrtoeol(); return(PE_RESTART); } static bool open_window(void) { if (getenv("TERM") == NULL) return(FALSE); printf("Pente version " VERSION ", Copyright (C) 1994-1995 William Shubert\n" " Pente comes with ABSOLUTELY NO WARRANTY and is distrubuted\n" " under the Gnu General Public Licence, Version 2\n" " See the file \"COPYING\" for details.\n"); sleep(5); win = initscr(); if (win == NULL) return(FALSE); cbreak(); noecho(); nonl(); erase(); return(TRUE); } void cio_draw(pl_t *game, bool forced) { bd_t *board = pl_board(game); int x, y; bd_loc_t loc; char c1, c2; c1 = c2 = ' '; if (pl_player(game) == 0) c1 = '<'; else c2 = '>'; mvprintw( 4,1, "Selecting moves:"); mvprintw( 5,4, "I P"); mvprintw( 6,3, "J K B F"); mvprintw( 7,4, "M N"); mvprintw( 8,2, "Or arrow keys."); mvprintw( 9,2, ", :"); mvprintw(10,4, "Make Move"); mvprintw(12,1, "U: Undo"); mvprintw(13,1, "Q: Quit"); mvprintw(14,1, "R: Restart"); mvprintw(15,1, "L: Redraw"); mvprintw(4,62, "Pente " VERSION); mvprintw(5,62, DATE); mvprintw(6,62, "Bill Shubert"); mvprintw(7,62, "wms@igoweb.org"); mvprintw(0,18, "%s [%c]: ", plname[0], plchar[0]); if (board->captures[0] > 4) standout(); printw("%d", board->captures[0]); standend(); printw("%c%c%cTurn%3d%c%c%c%s [%c]: ", c1,c1,c1, pl_turn(game)+1, c2,c2,c2, plname[1], plchar[1]); if (board->captures[1] > 4) standout(); printw("%d", board->captures[1]); standend(); for (x = 0; x < 19; ++x) { mvaddch(1, x*2+21, xname[x]); mvaddch(21, x*2+21, xname[x]); } for (y = 0; y < 19; ++y) { mvprintw(2+y, 18, "%2d", 19-y); mvprintw(2+y, 18+3+19*2, "%d", 19-y); } for (x = 0; x < 19; ++x) { for (y = 0; y < 19; ++y) { move((18-y)+2, x*2+21); loc = bd_xy_loc(x, y); if (BD_EMPTYP(board->grid[loc])) addch('.'); else { if (BD_WINNERP(board->grid[loc])) standout(); addch(plchar[BD_OWNER(board->grid[loc])]); if (BD_WINNERP(board->grid[loc])) standend(); } } } if (pl_nmoves(game) > 0) { loc = pl_getmove(game, pl_nmoves(game) - 1); mvprintw(22, 18, "%s [%c] moved at %c%d.", plname[1 - pl_player(game)], plchar[1-pl_player(game)], xname[bd_loc_x(loc)], bd_loc_y(loc) + 1); } else move(22,0); clrtoeol(); if (!forced) { move(23,0); clrtoeol(); } refresh(); } bd_loc_t cio_selectmove(pl_t *game, int compfd) { static int last_turn = -1, last_player = -1; uint player = pl_player(game), turn_num = pl_turn(game); int x, y, ch; bd_loc_t loc; uint esc_chars = 0; if (levels[player] > 0) return(PE_COMP); last_turn = turn_num; last_player = player; if ((turn_num == 0) && (player == 0)) return(bd_xy_loc(9,9)); loc = pl_getmove(game, pl_nmoves(game) - 1); x = bd_loc_x(loc); y = bd_loc_y(loc); mvprintw(23,18, "Select a move, player %d [%c].", player+1, plchar[player]); clrtoeol(); for (;;) { move((18-y)+2, x*2+21); refresh(); ch = getch(); switch(ch) { case '\33': esc_chars = 1; break; case '[': if (esc_chars == 1) esc_chars = 2; else esc_chars = 0; break; case 'B': if (esc_chars != 2) { esc_chars = 0; --x; if (x < 0) x = 0; break; } case CTRLKEY('N'): case 'n':case 'N': case 'm':case 'M': esc_chars = 0; --y; if (y < 0) y = 0; break; case 'A': if (esc_chars != 2) break; case CTRLKEY('P'): case 'p':case 'P': case 'i':case 'I': esc_chars = 0; ++y; if (y > 18) y = 18; break; case 'C': if (esc_chars != 2) break; case CTRLKEY('F'): case 'f':case 'F': case 'k':case 'K': esc_chars = 0; ++x; if (x > 18) x = 18; break; case 'D': if (esc_chars != 2) break; case CTRLKEY('B'): case 'b': case 'j':case 'J': esc_chars = 0; --x; if (x < 0) x = 0; break; case '\n':case'\r':case ' ': esc_chars = 0; if (pl_movep(game, bd_xy_loc(x, y))) { return(bd_xy_loc(x,y)); } else putchar('\a'); break; case CTRLKEY('Q'): case 'q':case 'Q': quit(); break; case CTRLKEY('U'): case 'u':case 'U': esc_chars = 0; if (turn_num > 1) return(PE_UNDO); else putchar('\a'); break; case CTRLKEY('R'): case 'r':case 'R': esc_chars = 0; return(PE_RESTART); break; case CTRLKEY('L'): case 'l':case 'L': esc_chars = 0; redraw(); break; default: esc_chars = 0; putchar('\a'); break; } } } void cio_think(bd_loc_t pos, uint player) { move((18-bd_loc_y(pos))+2, bd_loc_x(pos)*2+21); refresh(); } static void quit(void) { nl(); /* On some systems endwin() doesn't properly reset this. */ endwin(); pe_output_vars(); exit(0); } /* Returns FALSE if you need a total redo. */ static bool readstr(uint y, uint x, char *prompt, char *buf, int buflen) { char ch; int ch_no; move(y, 0); clrtobot(); mvaddstr(y, x, prompt); x += strlen(prompt); ch_no = 0; move(y, x); for (;;) { refresh(); ch = getch(); switch(ch) { case CTRLKEY('Q'): case 'q':case 'Q': quit(); break; case CTRLKEY('L'): case 'l':case 'L': redraw(); break; case CTRLKEY('R'): case 'r':case 'R': return(FALSE); break; case CTRLKEY('U'): case 'u':case 'U': buf[0] = 'U'; buf[1] = '\0'; return(TRUE); break; case '\177': case '\010': if (ch_no) { --ch_no; --x; mvaddstr(y, x, " "); move(y, x); } break; case '\n': case '\r': if (ch_no != 0) { buf[ch_no] = '\0'; return(TRUE); } break; default: if (isprint(ch) && (ch_no < buflen)) { mvaddch(y, x, ch); ++x; buf[ch_no++] = ch; break; } } } } static void redraw(void) { #ifdef clearok clearok(win, TRUE); #endif refresh(); #ifdef clearok clearok(win, FALSE); #endif } #endif pente-2.2.5/src/textio.c0100664000076400007640000000743607045637747013350 0ustar wmswms/* * src/textio.c, part of Pente (game program) * Copyright (C) 1995 William Shubert. * See "configure.h.in" for more copyright information. */ #include #include "pente.h" static void quit(void); static char prefix[] = " ", plchar[2] = {'#','O'}; static const char xname[] = "ABCDEFGHJKLMNOPQRST"; static bool thinking_needed = TRUE; static int *levels; static char plname[2][9]; bd_loc_t text_init(int *comp_level, uint winner, pl_t *game) { int i, scans; static bool first_time = TRUE; if (first_time) { printf("Pente version " VERSION ", Copyright (C) 1994-1995 " "William Shubert\n" " Pente comes with ABSOLUTELY NO WARRANTY and is distrubuted\n" " under the Gnu General Public Licence, Version 2\n" " See the file \"COPYING\" for details.\n"); first_time = FALSE; } levels = comp_level; if (winner != BD_MAXPLAYERS) printf("\n%s [%c] has won!\n\n", plname[winner], plchar[winner]); for (i = 0; i < 2; ++i) { do { printf("Level of player %d [0=Player, 1..9=Computer]: ", i+1); if ((scans = scanf("%d%*[^\n]%*c", comp_level + i)) == EOF) { quit(); exit(0); } else if (scans == 0) scanf("%*[^\n]%*c"); if ((comp_level[i] < 0) || (comp_level[i] > 9)) scans = 0; } while (scans != 1); if (comp_level[i] == 0) sprintf(plname[i], "Player %d", i+1); else sprintf(plname[i], "Comp Lv%d", comp_level[i]); } return(PE_RESTART); } void text_draw(pl_t *game, bool forced) { bd_t *board = pl_board(game); int x, y; bd_loc_t loc; char c1, c2, mvout[4]; printf("\n"); if (!thinking_needed) { thinking_needed = TRUE; printf("\n"); } c1 = c2 = ' '; if (pl_player(game) == 0) c1 = '<'; else c2 = '>'; printf("%s%s [%c]: %d%c%c%cTurn%3d%c%c%c%s [%c]: %d\n", prefix, plname[0], plchar[0], board->captures[0], c1,c1,c1, pl_turn(game)+1, c2,c2,c2, plname[1], plchar[1], board->captures[1]); printf("%s ", prefix); for (x = 0; x < 19; ++x) printf("%c ", xname[x]); printf("\n"); for (y = 18; y >= 0; --y) { printf("%s%2d ", prefix, y+1); for (x = 0; x < 19; ++x) { loc = bd_xy_loc(x, y); if (BD_EMPTYP(board->grid[loc])) printf(". "); else printf("%c ", plchar[BD_OWNER(board->grid[loc])]); } printf("%2d\n", y+1); } printf("%s ", prefix); for (x = 0; x < 19; ++x) printf("%c ", xname[x]); if (pl_nmoves(game) > 0) { loc = pl_getmove(game, pl_nmoves(game) - 1); bd_loc_str(loc, mvout); printf("\n%s%s [%c] moved at %s.", prefix, plname[pl_player(game)^1], plchar[1-pl_player(game)], mvout); } printf("\n"); } bd_loc_t text_selectmove(pl_t *game, int compfd) { uint player = pl_player(game), turn_num = pl_turn(game); static int last_turn = -1, last_player = -1; int scancount; char temp[100]; bd_loc_t move; if (levels[player] > 0) return(PE_COMP); if ((last_turn == turn_num) && (last_player == player)) { /* Last move was invalid, so I'm removing. */ putchar('\a'); } last_turn = turn_num; last_player = player; if ((turn_num == 0) && (player == 0)) return(bd_xy_loc(9,9)); printf("%sPlayer %d [%c]: ", prefix, player+1, plchar[player]); if ((scancount = scanf("%*c%99[^\n]", temp)) == EOF) quit(); if (scancount != 1) return(PE_CONTINUE); move = bd_str_loc(temp, NULL); if ((move == BD_LOC_MAX) || !pl_movep(game, move)) { putchar('\a'); return(PE_CONTINUE); } return(move); } void text_think(bd_loc_t pos, uint player) { char mvout[4]; if (thinking_needed) { printf("I'm thinking..."); thinking_needed = FALSE; } bd_loc_str(pos, mvout); printf("%s...", mvout); fflush(stdout); } static void quit(void) { printf("\n\nBye!\n"); pe_output_vars(); exit(0); } pente-2.2.5/src/comp/comp.c0100664000076400007640000001364707045640330013707 0ustar wmswms/* * src/comp/comp.c, part of Pente (game program) * Copyright (C) 1994 William Shubert. * See "configure.h.in" for more copyright information. */ #include "../pente.h" #include "comp.h" volatile bool comp_active = FALSE, comp_abort = FALSE; volatile bd_loc_t comp_abortval; static void init_comp(bd_t *board); static bd_loc_t turn_2(bd_t *board); #ifdef COMP_DEBUG static char debug_info[100], *dip; #endif typedef struct movinfo { score_t score, cpmscore; bd_loc_t loc; bool iscore; } movinfo; static int movinfo_cmp(const void *ta, const void *tb) { movinfo *a = (movinfo *)ta; movinfo *b = (movinfo *)tb; if (b->cpmscore == a->cpmscore) return(b->loc - a->loc); else return(b->cpmscore - a->cpmscore); } bd_loc_t comp_selectmove(pl_t *game, uint level) { D_VAR bd_t *board = pl_board(game); uint player = pl_player(game), turn_num = pl_turn(game); score_t best_score, cur_score; int mn, movnum; uint scores; bd_loc_t cur_loc; movinfo movlist[19*19]; bool iscore; score_t cpmscore; if ((turn_num == 0) && (player == 0)) return(bd_xy_loc(9, 9)); if ((turn_num == 1) && (player == 0)) return(turn_2(board)); do { movnum = 0; init_comp(board); for (cur_loc = BD_LOC_MIN; cur_loc < BD_LOC_MAX; ++cur_loc) { if (board->grid[cur_loc] == BD_EMPTYA) { cur_score = comp_eval(board, cur_loc, player, &cpmscore, &iscore); if (cur_score >= WINVAL) return(cur_loc); movlist[movnum].score = cur_score; movlist[movnum].cpmscore = cpmscore; movlist[movnum].loc = cur_loc; movlist[movnum].iscore = iscore; ++movnum; } } qsort(movlist, movnum, sizeof(movinfo), movinfo_cmp); scores = 0; best_score = -WINVAL + 1; for (mn = 0; mn < movnum; ++mn) { cur_score = movlist[mn].score; cur_loc = movlist[mn].loc; if (cur_score < WINVAL) { if (level >= 4) { cur_score -= comp_move(D_ARG board, cur_loc, player, movlist[mn].iscore); if ((level > 4) && ((cur_score & 1) == 0) && (cur_score > -WINVAL)) { if (cur_score > best_score) { if (cur_score >= WINVAL) return(cur_loc); best_score = cur_score; } movlist[scores].loc = cur_loc; movlist[scores].score = movlist[mn].score; movlist[scores].cpmscore = cur_score + (rnd_int32(pe_rnd) & (V_FORCE(0) - 1)); movlist[scores].iscore = movlist[mn].iscore; ++scores; } } else if (level == 3) cur_score -= comp_lmove(D_ARG board, cur_loc, player); else if (level == 2) cur_score -= comp_end_eval(D_ARG board, cur_loc, player); } #ifdef COMP_DEBUG if (level <= 4) printf("%s: %c%8x %d\n", tmpinfo, (cur_score<0?'-':' '), (cur_score>0?cur_score:-cur_score), movlist[mn].cpmscore); #endif if ((level <= 4) && ((cur_score & 1) == 0) && (cur_score >= best_score)) { if (cur_score >= WINVAL) return(cur_loc); if (cur_score > best_score) { best_score = cur_score; scores = 0; } movlist[scores++].loc = cur_loc; } } if (!scores) { #ifdef COMP_DEBUG printf("\tLoss. L%d ->L%d\n", level, (level-2)|1); #endif level = (level - 2) | 1; } else if (level > 4) { int limit = level, i; int snum = scores, simples; simples = level - (level / 3); best_score = -WINVAL + 1; qsort(movlist, scores, sizeof(movinfo), movinfo_cmp); if ((scores == 1) || (movlist[1].cpmscore <= -WINVAL)) return(movlist[0].loc); scores = 0; for (i = 0; (i < limit) && (i < snum); ++i) { if (!simples && !movlist[i].iscore) { ++limit; continue; } if (movlist[i].cpmscore <= -WINVAL) break; comp_think(movlist[i].loc); simples += movlist[i].iscore - 1; cur_score = movlist[i].score - comp_deeptree(D_ARG board, movlist[i].loc, level-1, player); if (((cur_score & 1) == 0) && (cur_score >= best_score)) { if (cur_score > best_score) { if (cur_score >= WINVAL) return(movlist[i].loc); scores = 0; best_score = cur_score; } movlist[scores++].loc = movlist[i].loc; } #ifdef COMP_DEBUG printf("%s: %c%8x %d\n", tmpinfo, (cur_score<0?'-':' '), (cur_score>0?cur_score:-cur_score), (movlist[i].cpmscore&~(V_FORCE(0)-1))/V_FORCE(0)); #endif } if (!scores) { #ifdef COMP_DEBUG printf("Loss.\n"); #endif level = (level - 2)|1; } } } while (!scores); #ifdef COMP_DEBUG printf("\n\n"); #endif return(movlist[rnd_int32(pe_rnd) % scores].loc); } /* The first player's second move. */ static bd_loc_t turn_2(bd_t *board) { static int turn2x[] = { 6, 7, 8, 9,10,11,12, 6,12, 6,12, 6,12, 6,12, 6,12, 6, 7, 8, 9,10,11,12}; static int turn2y[] = { 6, 6, 6, 6, 6, 6, 6, 7, 7, 8, 8, 9, 9, 10,10, 11,11, 12,12,12,12,12,12,12}; uint move2; bd_loc_t loc; do { move2 = rnd_int32(pe_rnd) % (sizeof(turn2x) / sizeof(*turn2x)); loc = bd_xy_loc(turn2x[move2], turn2y[move2]); } while (!BD_EMPTYP(board->grid[loc])); return(loc); } static void init_comp(bd_t *board) { bd_loc_t loc; uint dir; int dvec; for (loc = BD_LOC_MIN; loc < BD_LOC_MAX; ++loc) { if (BD_EMPTYP(board->grid[loc])) { board->grid[loc] = BD_EMPTYB; for (dir = 0; dir < 8; ++dir) { if (BD_PLAYERP(board->grid[loc+bd_dvec[dir]])) { board->grid[loc] = BD_EMPTYA; } } } } for (loc = BD_LOC_MIN; loc < BD_LOC_MAX; ++loc) { if (BD_PLAYERP(board->grid[loc])) { for (dir = 0; dir < 8; ++dir) { dvec = bd_dvec[dir]; if ((board->grid[loc+dvec] == board->grid[loc]) && (board->grid[loc+dvec*3] == BD_EMPTYB)) board->grid[loc+dvec*3] = BD_EMPTYA; } } } } #ifdef COMP_DEBUG void comp_addinfo(int l, bd_loc_t m) { static int ml = 0; if (l > ml) { ml = l; dip = debug_info + 98 - 4*ml; } sprintf(debug_info+98-l*4, "%c%2d", bd_loc_x(m)+'A', bd_loc_y(m)+1); debug_info[98-l*4+3] = ' '; } #endif pente-2.2.5/src/comp/spawn.c0100664000076400007640000000724707045640330014100 0ustar wmswms/* * src/comp/spawn.c, part of Pente (game program) * Copyright (C) 1994 William Shubert. * See "configure.h.in" for more copyright information. * * Spawn off the computer. */ #include #include #include #include "../pente.h" #include "comp.h" static void comp_dispatch(void); static pid_t comp_pid; static int recv_from_p, send_to_p; static bool comp_active = FALSE; static bool think_enabled = TRUE; void comp_spawn(int *recv_from_c, int *send_to_c) { pid_t forkout; int pipe_res; int pipes[2]; pipe_res = pipe(pipes); if (pipe_res == -1) { fprintf(stderr, "pente: Error: Could not start computer opponent.\n"); exit(1); } *recv_from_c = pipes[0]; send_to_p = pipes[1]; pipe_res = pipe(pipes); if (pipe_res == -1) { fprintf(stderr, "pente: Error: Could not start computer opponent.\n"); exit(1); } recv_from_p = pipes[0]; *send_to_c = pipes[1]; forkout = fork(); if (forkout == -1) { fprintf(stderr, "pente: Error: Could not start computer opponent.\n"); exit(1); } if (forkout == 0) { int i, maxFiles; maxFiles = getdtablesize(); /* * Close off all file descriptors that the audio child doesn't need. */ for (i = 3; i < maxFiles; ++i) { if ((i != recv_from_p) && (i != send_to_p)) close(i); } comp_dispatch(); exit(0); } else { close(recv_from_p); close(send_to_p); comp_pid = forkout; } } /* Kill the computer player, and restart! */ void comp_reset(int *recv_from_c, int *send_to_c) { int status; if (comp_active) { close(*recv_from_c); close(*send_to_c); kill(comp_pid, SIGKILL); wait(&status); comp_spawn(recv_from_c, send_to_c); comp_active = FALSE; } } static void comp_dispatch(void) { const int msgin_size = (19*19+10)*4+4; char msgin[(19*19+10)*4+4], *mp; int amt_read, level; pl_t game; bd_loc_t movout; /* Make sure that we don't save OUR state! */ signal(SIGTERM, SIG_DFL); signal(SIGINT, SIG_DFL); signal(SIGPIPE, SIG_DFL); signal(SIGHUP, SIG_DFL); rnd_destroy(pe_rnd); pe_rnd = rnd_create(time(NULL) ^ getpid()); for (;;) { amt_read = read(recv_from_p, msgin, msgin_size - 1); msgin[amt_read] = '\0'; if (amt_read == 0) exit(0); if (amt_read == -1) { /* Dead pipe or something. */ perror("Pente computer logic: Error "); exit(1); } level = atoi(msgin); for (mp = msgin; *mp != ' '; ++mp); ++mp; pl_init(&game); pl_str_game(mp, &game); movout = comp_selectmove(&game, level); msgin[0] = 'M'; *bd_loc_str(movout, msgin+1) = ' '; write(send_to_p, msgin, 4); } } void comp_think(bd_loc_t move) { char msgout[5]; if (think_enabled) { msgout[0] = 'T'; *bd_loc_str(move, msgout+1) = ' '; write(send_to_p, msgout, 4); } } void comp_start(pl_t *game, uint level, int to_c) { char msgout[(19*19+10)*4+4]; char *c; comp_active = TRUE; sprintf(msgout, "%d ", level); for (c = msgout; *c; ++c); pl_game_str(game, c); write(to_c, msgout, strlen(msgout)); } bd_loc_t comp_getmove(int from_c, void think(bd_loc_t pos, uint player), uint player) { char msgin[5]; bd_loc_t loc; read(from_c, msgin, 4); msgin[4] = '\0'; loc = bd_str_loc(msgin+1, NULL); if (msgin[0] == 'T') { if (think) think(loc, player); loc = PE_COMP; } else { /* It's a move command. The computer is no longer active. */ comp_active = FALSE; snd_play(&pe_move_snd); } return(loc); } bd_loc_t comp_noSpawnGetMove(pl_t *game, int level) { think_enabled = FALSE; return(comp_selectmove(game, level)); } pente-2.2.5/src/comp/eval.c0100664000076400007640000000141507045640330013666 0ustar wmswms/* * src/comp/eval.c, part of Pente (game program) * Copyright (C) 1994 William Shubert. * See "configure.h.in" for more copyright information. */ #include "../pente.h" #include "comp.h" const score_t comp_capval[13] = {CAP0VAL, CAP0VAL+ V_FORCE(0)+2, CAP0VAL+2*V_FORCE(0)+4, CAP0VAL+3*V_FORCE(0)+6, V_WIN(0), 0,0,0,0,0,0,0,0}; score_t comp_eval(bd_t *board, bd_loc_t loc, uint player, score_t *cpmscore, bool *iscore) { score_t score = 0; #define SSCORE score #define ISCORE (*iscore) #define BOARD board #define LOC loc #define PLAYER player #define DEGEN FALSE #include "eval.h" #undef SSCORE #define SSCORE (*cpmscore) #undef ISCORE #define CPM TRUE #include "eval.h" return(score); } pente-2.2.5/src/comp/move.c0100664000076400007640000001043007045640330013702 0ustar wmswms/* * src/comp/move.c, part of Pente (game program) * Copyright (C) 1994 William Shubert. * See "configure.h.in" for more copyright information. */ #include "../pente.h" #include "comp.h" #ifdef COMP_DEBUG int l1_repnum=0, l2_repnum=0, l3_repnum=0; #endif extern score_t comp_move(D_PAR bd_t *board, bd_loc_t loc, uint player, bool check_simple) { D_VAR uint bdsave[2*8], orig_caps, caps; uint movlistlen; uint dir; score_t best_score, cur_score; bd_loc_t cur_loc, movlist[19*19]; score_t sscore, sscores[19*19]; int dvec; uint fa,fb, ba,bb; bool iscore, iscores[19*19]; #ifdef COMP_DEBUG l2_repnum = 0; ++l1_repnum; if ((l1_repnum != 2) && (l1_repnum != 4)) l2_repnum = -1; else printf("%c%2d:\n",bd_loc_x(loc)+'A',bd_loc_y(loc)+1); #endif D_INIT(loc, 2); /* Save old board layout and update the board to reflect this move. */ orig_caps = board->captures[player]; caps = orig_caps; board->grid[loc] = BD_PLAYER(player); for (dir = 0; dir < 4; ++dir) { dvec = bd_dvec[dir]; bdsave[dir+ 0] = fa = board->grid[loc+dvec]; bdsave[dir+ 4] = fb = board->grid[loc+dvec+dvec]; bdsave[dir+ 8] = ba = board->grid[loc-dvec]; bdsave[dir+12] = bb = board->grid[loc-(dvec+dvec)]; if (fb == BD_EMPTYB) board->grid[loc+dvec+dvec] = BD_EMPTYA; if (fa == BD_EMPTYB) board->grid[loc+dvec] = BD_EMPTYA; else if ((fa == BD_OPP(player)) && (fb == BD_OPP(player)) && (board->grid[loc+dvec+dvec+dvec] == BD_PLAYER(player))) { ++caps; board->grid[loc+dvec] = BD_EMPTYA; board->grid[loc+dvec+dvec] = BD_EMPTYA; } if (bb == BD_EMPTYB) board->grid[loc-(dvec+dvec)] = BD_EMPTYA; if (ba == BD_EMPTYB) board->grid[loc-dvec] = BD_EMPTYA; else if ((ba == BD_OPP(player)) && (bb == BD_OPP(player)) && (board->grid[loc-(dvec+dvec+dvec)] == BD_PLAYER(player))) { ++caps; board->grid[loc-dvec] = BD_EMPTYA; board->grid[loc-(dvec+dvec)] = BD_EMPTYA; } } board->captures[player] = caps; player ^= 1; /* Generate the list of moves. */ movlistlen = 0; best_score = -WINVAL*3-1; for (cur_loc = BD_LOC_MIN; cur_loc < BD_LOC_MAX; ++cur_loc) { if (board->grid[cur_loc] == BD_EMPTYA) { #define SSCORE sscore #define BOARD board #define LOC cur_loc #define PLAYER player #define DEGEN FALSE #define ISCORE iscore #include "eval.h" if (sscore >= WINVAL) { D_WIN(cur_loc); best_score = WINVAL*2; movlistlen = 0; break; } else if (check_simple || iscore) { if (sscore > V_FORCE(0)) { cur_score = sscore - comp_lmove(D_ARG board, cur_loc, player); #ifdef COMP_DEBUG if (l2_repnum >= 0) { printf(" %c%2d: %8x %8x\n",bd_loc_x(cur_loc)+'A', bd_loc_y(cur_loc)+1,sscore, cur_score); } #endif if (((cur_score & 1) == 0) && (cur_score > best_score)) { D_CPY(); if ((best_score = cur_score) >= WINVAL) { movlistlen = 0; break; } } } else { movlist[movlistlen] = cur_loc; sscores[movlistlen] = sscore; iscores[movlistlen++] = iscore; } } } } while (movlistlen--) { cur_score = sscores[movlistlen] - comp_lmove(D_ARG board, movlist[movlistlen], player); #ifdef COMP_DEBUG if (l2_repnum >= 0) { printf(" %c%2d: %8x %8x\n",bd_loc_x(movlist[movlistlen])+'A', bd_loc_y(movlist[movlistlen])+1,sscores[movlistlen], cur_score); } #endif if (((cur_score & 1) == 0) && (cur_score > best_score)) { D_CPY(); if ((best_score = cur_score) >= WINVAL) break; } } #ifdef COMP_DEBUG_LOTS if (1) { int i; printf("\n%x %d:\n",best_score,2); for (i=0; i < movlistlen; ++i) { printf("%8x %8x %c%2d\n", movlist[i].blscore, movlist[i].sscore, bd_loc_x(movlist[i].loc)+'A', bd_loc_y(movlist[i].loc)+1); } } #endif /* Restore the board to its original state. */ board->captures[player^1] = orig_caps; for (dir = 0; dir < 4; ++dir) { dvec = bd_dvec[dir]; board->grid[loc+dvec ] = bdsave[dir+ 0]; board->grid[loc+dvec+dvec ] = bdsave[dir+ 4]; board->grid[loc-dvec ] = bdsave[dir+ 8]; board->grid[loc-(dvec+dvec)] = bdsave[dir+12]; } board->grid[loc] = BD_EMPTYA; /* Return the best move found. */ return(best_score); } pente-2.2.5/src/comp/lmove.c0100664000076400007640000002413607045640330014066 0ustar wmswms/* * src/comp/lmove.c, part of Pente (game program) * Copyright (C) 1994 William Shubert. * See "configure.h.in" for more copyright information. */ #include "../pente.h" #include "comp.h" typedef struct { bd_loc_t loc; score_t score; } loc_info; static score_t comp_end_tiny(D_PAR bd_t *board, bd_loc_t loc, uint player, loc_info *nlcheck); extern score_t comp_lmove(D_PAR bd_t *board, bd_loc_t loc, uint player) { D_VAR uint bdsave[2*8], orig_caps, caps; bd_loc_t cur_loc, sscheck[19*19], capcheck[(19*19+2)/3], nscheck = BD_LOC_MAX; loc_info nlcheck[10]; int dvec, nlnum, capnum = 0, capscore[(19*19+2)/3]; uint dir; score_t best_score = -WINVAL*2, best_sscore = -WINVAL*2, best_nsscore = -WINVAL*2, cur_score; uint fa,fb, ba,bb; int num_sscores = 0; score_t ss_nsc = -WINVAL*2, sscore, nsscore; nlcheck[0].score = SCORE_MAX; nlcheck[1].score = SCORE_MIN; nlcheck[2].score = SCORE_MIN; nlcheck[3].score = SCORE_MIN; nlcheck[4].score = SCORE_MIN; nlcheck[5].score = SCORE_MIN; nlcheck[6].score = SCORE_MIN; nlcheck[7].score = SCORE_MIN; nlcheck[8].score = SCORE_MIN; nlcheck[9].score = SCORE_MIN; D_INIT(loc, 1); /* Save old board layout and update the board to reflect this move. */ orig_caps = board->captures[player]; caps = orig_caps; board->grid[loc] = BD_PLAYER(player); for (dir = 0; dir < 4; ++dir) { dvec = bd_dvec[dir]; bdsave[dir+ 0] = fa = board->grid[loc+dvec]; bdsave[dir+ 4] = fb = board->grid[loc+dvec+dvec]; bdsave[dir+ 8] = ba = board->grid[loc-dvec]; bdsave[dir+12] = bb = board->grid[loc-(dvec+dvec)]; if (fb == BD_EMPTYB) board->grid[loc+dvec+dvec] = BD_EMPTYA; if (fa == BD_EMPTYB) board->grid[loc+dvec] = BD_EMPTYA; else if ((fa == BD_OPP(player)) && (fb == BD_OPP(player)) && (board->grid[loc+dvec+dvec+dvec] == BD_PLAYER(player))) { ++caps; board->grid[loc+dvec] = BD_EMPTYA; board->grid[loc+dvec+dvec] = BD_EMPTYA; } if (bb == BD_EMPTYB) board->grid[loc-(dvec+dvec)] = BD_EMPTYA; if (ba == BD_EMPTYB) board->grid[loc-dvec] = BD_EMPTYA; else if ((ba == BD_OPP(player)) && (bb == BD_OPP(player)) && (board->grid[loc-(dvec+dvec+dvec)] == BD_PLAYER(player))) { ++caps; board->grid[loc-dvec] = BD_EMPTYA; board->grid[loc-(dvec+dvec)] = BD_EMPTYA; } } board->captures[player] = caps; player ^= 1; /* Generate the list of moves. */ for (cur_loc = BD_LOC_MIN; cur_loc < BD_LOC_MAX; ++cur_loc) { if (board->grid[cur_loc] == BD_EMPTYA) { #define SSCORE sscore #define OSCORE nsscore #define BOARD board #define LOC cur_loc #define PLAYER player #define DEGEN FALSE #define CPM #include "eval.h" #undef SSCORE #undef OSCORE #undef BOARD #undef LOC #undef PLAYER #undef DEGEN #undef CPM if (nlcheck[9].score < nsscore) { for (nlnum = 8; nlcheck[nlnum].score < nsscore; --nlnum) nlcheck[nlnum+1] = nlcheck[nlnum]; nlcheck[nlnum+1].loc = cur_loc; nlcheck[nlnum+1].score = nsscore; } if (sscore >= WINVAL) { best_score = WINVAL*2; break; } else if (sscore & 0x1e) { capcheck[capnum] = cur_loc; capscore[capnum++] = sscore; } else if ((sscore > best_sscore) || ((sscore == best_sscore) && (sscore > V_FORCE(1)))) { if (sscore > best_sscore) { num_sscores = 0; best_sscore = sscore; } sscheck[num_sscores++] = cur_loc; #ifdef COMP_DEBUG_LOTS_N_LOTS printf(" >! %2d%c: %11d", bd_loc_y(cur_loc)+1, bd_loc_x(cur_loc)+'A',sscore); #endif } if (!(sscore & 0x1e)) { if ((nsscore > best_nsscore) || ((nsscore == best_nsscore) && (sscore > ss_nsc))) { best_nsscore = nsscore; nscheck = cur_loc; ss_nsc = sscore; #ifdef COMP_DEBUG_LOTS_N_LOTS printf(" >! %2d%c: %11d", bd_loc_y(cur_loc)+1, bd_loc_x(cur_loc)+'A',sscore); #endif } } } } while (capnum--) { cur_score = capscore[capnum] - comp_end_tiny(D_ARG board, capcheck[capnum], player, nlcheck + 1); if (cur_score > best_score) { D_CPY(); best_score = cur_score; } } while (num_sscores--) { cur_score = best_sscore - comp_end_tiny(D_ARG board, sscheck[num_sscores], player, nlcheck + 1); if (cur_score > best_score) { D_CPY(); best_score = cur_score; } } if (nscheck != BD_LOC_MAX) { cur_score = ss_nsc - comp_end_tiny(D_ARG board, nscheck, player, nlcheck + 1); if (cur_score > best_score) { D_CPY(); best_score = cur_score; } } /* Restore the board to its original state. */ board->captures[player^1] = orig_caps; for (dir = 0; dir < 4; ++dir) { dvec = bd_dvec[dir]; board->grid[loc+dvec ] = bdsave[dir+ 0]; board->grid[loc+dvec+dvec ] = bdsave[dir+ 4]; board->grid[loc-dvec ] = bdsave[dir+ 8]; board->grid[loc-(dvec+dvec)] = bdsave[dir+12]; } board->grid[loc] = BD_EMPTYA; /* Return the best move found. */ return(best_score); } static score_t comp_end_tiny(D_PAR bd_t *board, bd_loc_t loc, uint player, loc_info *nlcheck) { uint bdsave[2*8]; bd_loc_t cur_loc, cappos[4], mycap[16]; uint dir; score_t best_score = -WINVAL*2, cur_score; int dvec, i, ncappos = 0, nmycap = 0; uint fa,fb, ba,bb; D_INIT(loc, 0); #ifdef COMP_DEBUG info += 4; #endif /* Save old board layout and update the board to reflect this move. */ board->grid[loc] = BD_PLAYER(player); for (dir = 0; dir < 4; ++dir) { dvec = bd_dvec[dir]; bdsave[dir+ 0] = fa = board->grid[loc+dvec]; bdsave[dir+ 4] = fb = board->grid[loc+dvec+dvec]; bdsave[dir+ 8] = ba = board->grid[loc-dvec]; bdsave[dir+12] = bb = board->grid[loc-(dvec+dvec)]; if (fa == BD_OPP(player)) { if ((fb == BD_OPP(player)) && (board->grid[loc+dvec+dvec+dvec] == BD_PLAYER(player))) { board->grid[mycap[nmycap++] = loc+dvec] = BD_EMPTYA; board->grid[mycap[nmycap++] = loc+dvec+dvec] = BD_EMPTYA; } else if ((ba == BD_PLAYER(player)) && BD_EMPTYP(bb)) { cappos[ncappos++] = loc-(dvec+dvec); } } else if (BD_EMPTYP(fa) && (ba == BD_PLAYER(player)) && (bb == BD_OPP(player))) { cappos[ncappos++] = loc+dvec; } if (ba == BD_OPP(player)) { if ((bb == BD_OPP(player)) && (board->grid[loc-(dvec+dvec+dvec)] == BD_PLAYER(player))) { board->grid[mycap[nmycap++] = loc-dvec] = BD_EMPTYA; board->grid[mycap[nmycap++] = loc-(dvec+dvec)] = BD_EMPTYA; } else if ((fa == BD_PLAYER(player)) && BD_EMPTYP(fb)) { cappos[ncappos++] = loc+dvec+dvec; } } else if (BD_EMPTYP(ba) && (fa == BD_PLAYER(player)) && (fb == BD_OPP(player))) { cappos[ncappos++] = loc-dvec; } } player ^= 1; for (i = 0; i < ncappos; ++i) { cur_loc = cappos[i]; #define SSCORE cur_score #define BOARD board #define LOC cur_loc #define PLAYER player #define DEGEN TRUE #define CPM TRUE #include "eval.h" if (cur_score > best_score) { D_INIT(cur_loc, -1); best_score = cur_score; } } for (i = 0; i < nmycap; ++i) { cur_loc = mycap[i]; #define SSCORE cur_score #define BOARD board #define LOC cur_loc #define PLAYER player #define DEGEN TRUE #define CPM TRUE #include "eval.h" if (cur_score > best_score) { D_INIT(cur_loc, -1); best_score = cur_score; } } for (i = 0; i < 9; ++i) { cur_loc = nlcheck[i].loc; if (!BD_EMPTYP(board->grid[cur_loc])) continue; #define SSCORE cur_score #define BOARD board #define LOC cur_loc #define PLAYER player #define DEGEN TRUE #define CPM TRUE #include "eval.h" if (cur_score > best_score) { D_INIT(cur_loc, -1); best_score = cur_score; } if (cur_score >= nlcheck[i].score) break; } /* Restore the board to its original state. */ for (dir = 0; dir < 4; ++dir) { dvec = bd_dvec[dir]; board->grid[loc+dvec ] = bdsave[dir+ 0]; board->grid[loc+dvec+dvec ] = bdsave[dir+ 4]; board->grid[loc-dvec ] = bdsave[dir+ 8]; board->grid[loc-(dvec+dvec)] = bdsave[dir+12]; } board->grid[loc] = BD_EMPTYA; return(best_score); } score_t comp_end_eval(D_PAR bd_t *board, bd_loc_t loc, uint player) { uint bdsave[2*8]; bd_loc_t cur_loc; uint dir; score_t best_score = -WINVAL*2, cur_score; int dvec; uint fa,fb, ba,bb; D_INIT(loc, 0); #ifdef COMP_DEBUG info += 4; #endif /* Save old board layout and update the board to reflect this move. */ board->grid[loc] = BD_PLAYER(player); for (dir = 0; dir < 4; ++dir) { dvec = bd_dvec[dir]; bdsave[dir+ 0] = fa = board->grid[loc+dvec]; bdsave[dir+ 4] = fb = board->grid[loc+dvec+dvec]; bdsave[dir+ 8] = ba = board->grid[loc-dvec]; bdsave[dir+12] = bb = board->grid[loc-(dvec+dvec)]; if (fa == BD_EMPTYB) board->grid[loc+dvec] = BD_EMPTYA; else if ((fa == BD_OPP(player)) && (fb == BD_OPP(player)) && (board->grid[loc+dvec+dvec+dvec] == BD_PLAYER(player))) { board->grid[loc+dvec] = BD_EMPTYA; board->grid[loc+dvec+dvec] = BD_EMPTYA; } if (ba == BD_EMPTYB) board->grid[loc-dvec] = BD_EMPTYA; else if ((ba == BD_OPP(player)) && (bb == BD_OPP(player)) && (board->grid[loc-(dvec+dvec+dvec)] == BD_PLAYER(player))) { board->grid[loc-dvec] = BD_EMPTYA; board->grid[loc-(dvec+dvec)] = BD_EMPTYA; } } player ^= 1; for (cur_loc = BD_LOC_MIN; cur_loc < BD_LOC_MAX; ++cur_loc) { if (board->grid[cur_loc] == BD_EMPTYA) { #define SSCORE cur_score #define BOARD board #define LOC cur_loc #define PLAYER player #define DEGEN TRUE #define CPM TRUE #include "eval.h" if (cur_score > best_score) { D_INIT(cur_loc, -1); best_score = cur_score; } } } /* Restore the board to its original state. */ for (dir = 0; dir < 4; ++dir) { dvec = bd_dvec[dir]; board->grid[loc+dvec ] = bdsave[dir+ 0]; board->grid[loc+dvec+dvec ] = bdsave[dir+ 4]; board->grid[loc-dvec ] = bdsave[dir+ 8]; board->grid[loc-(dvec+dvec)] = bdsave[dir+12]; } board->grid[loc] = BD_EMPTYA; return(best_score); } pente-2.2.5/src/comp/deeptree.c0100664000076400007640000000762507045640330014545 0ustar wmswms/* * src/comp/deeptree.c, part of Pente (game program) * Copyright (C) 1994 William Shubert. * See "configure.h.in" for more copyright information. */ #include "../pente.h" #include "comp.h" typedef struct { bd_loc_t loc; bool iscore; score_t score, modscore, evscore; } dtinfo; static int dtcmp(const void *a, const void *b) { const dtinfo *dta = a, *dtb = b; if (dtb->modscore == dta->modscore) return(dtb->loc - dta->loc); else return(dtb->modscore - dta->modscore); } score_t comp_deeptree(D_PAR bd_t *board, bd_loc_t loc, int level, int player) { D_VAR dtinfo dtd[19*19]; int dtdnum=0, simples = 0, i, limit; bool iscore; score_t cscore, cpmscore, best_score = -WINVAL*3-1, evs; bd_loc_t cur_loc; uint orig_caps, caps, fa,fb, ba,bb, dir, bdsave[2*8]; int dvec; D_INIT(loc, level-1); /* Update the board for the move. */ /* Save old board layout and update the board to reflect this move. */ orig_caps = board->captures[player]; caps = orig_caps; board->grid[loc] = BD_PLAYER(player); for (dir = 0; dir < 4; ++dir) { dvec = bd_dvec[dir]; bdsave[dir+ 0] = fa = board->grid[loc+dvec]; bdsave[dir+ 4] = fb = board->grid[loc+dvec+dvec]; bdsave[dir+ 8] = ba = board->grid[loc-dvec]; bdsave[dir+12] = bb = board->grid[loc-(dvec+dvec)]; if (fb == BD_EMPTYB) board->grid[loc+dvec+dvec] = BD_EMPTYA; if (fa == BD_EMPTYB) board->grid[loc+dvec] = BD_EMPTYA; else if ((fa == BD_OPP(player)) && (fb == BD_OPP(player)) && (board->grid[loc+dvec+dvec+dvec] == BD_PLAYER(player))) { ++caps; board->grid[loc+dvec] = BD_EMPTYA; board->grid[loc+dvec+dvec] = BD_EMPTYA; } if (bb == BD_EMPTYB) board->grid[loc-(dvec+dvec)] = BD_EMPTYA; if (ba == BD_EMPTYB) board->grid[loc-dvec] = BD_EMPTYA; else if ((ba == BD_OPP(player)) && (bb == BD_OPP(player)) && (board->grid[loc-(dvec+dvec+dvec)] == BD_PLAYER(player))) { ++caps; board->grid[loc-dvec] = BD_EMPTYA; board->grid[loc-(dvec+dvec)] = BD_EMPTYA; } } board->captures[player] = caps; player ^= 1; best_score = -WINVAL*2; for (cur_loc = BD_LOC_MIN; cur_loc < BD_LOC_MAX; ++cur_loc) { if (board->grid[cur_loc] == BD_EMPTYA) { cscore = evs = comp_eval(board, cur_loc, player, &cpmscore, &iscore); if (evs < WINVAL) cscore -= comp_move(D_ARG board, cur_loc, player, iscore); else { D_WIN(cur_loc); best_score = WINVAL*2; dtdnum = 1; level = 4; break; } if (((cscore & 1) == 0) && (cscore > -WINVAL)) { if (cscore > best_score) { if (cscore >= WINVAL) { D_WIN(cur_loc); best_score = WINVAL*2; dtdnum = 1; level = 4; break; } D_CPY(); best_score = cscore; } dtd[dtdnum].loc = cur_loc; dtd[dtdnum].iscore = iscore; dtd[dtdnum].score = cscore; dtd[dtdnum].modscore = cscore + (rnd_int32(pe_rnd) & (V_FORCE(0) - 1)); dtd[dtdnum].evscore = evs; ++dtdnum; } } } if (dtdnum && (level > 4)) { qsort(dtd, dtdnum, sizeof(dtinfo), dtcmp); simples = level - (level / 3); limit = level; best_score = -WINVAL*3-1; for (i = 0; (i < limit) && (i < dtdnum); ++i) { if (!simples && !dtd[i].iscore) { ++limit; continue; } if (dtd[i].score <= -WINVAL) break; simples += dtd[i].iscore - 1; cscore = dtd[i].evscore - comp_deeptree(D_ARG board, dtd[i].loc, level-1, player); if (cscore > best_score) best_score = cscore; } } /* Restore the board to its original state. */ board->captures[player^1] = orig_caps; for (dir = 0; dir < 4; ++dir) { dvec = bd_dvec[dir]; board->grid[loc+dvec ] = bdsave[dir+ 0]; board->grid[loc+dvec+dvec ] = bdsave[dir+ 4]; board->grid[loc-dvec ] = bdsave[dir+ 8]; board->grid[loc-(dvec+dvec)] = bdsave[dir+12]; } board->grid[loc] = BD_EMPTYA; return(best_score); } pente-2.2.5/src/xio/plasma.c0100664000076400007640000000426607045637747014106 0ustar wmswms/* * src/xio/plasma.c, part of Pente (game program) * Copyright (C) 1994 William Shubert. * See "configure.h.in" for more copyright information. */ #include #ifdef X11_DISP #include #include "../pente.h" #define FACTOR 0.8 #define SIZE 512 static void diag(int *, int, int), perp(int *, int, int); static int my_random(int limit); uchar *xio_plasma(void) { static bool done = FALSE; int *cloud, x; static unsigned char *cout; unsigned step, i; float fskew; if (done) return(cout); done = TRUE; cout = (uchar *)wms_malloc(SIZE * SIZE * sizeof(char)); fskew = (float)(750 << 8); cloud = (int *)wms_malloc(SIZE * SIZE * sizeof(int)); if (cloud == NULL) { fprintf(stderr, "Could not allocate enough memory.\n"); exit(1); } *cloud = my_random(256 << 16); for (step = SIZE/2; step; step /= 2) { diag(cloud, step, (int)fskew); fskew *= FACTOR; perp(cloud, step, (int)fskew); fskew *= FACTOR; } for (i = 0; i < SIZE*SIZE; ++i) { x = (cloud[i] >> 8) & 511; if (x > 255) x = 511 - x; cout[i] = x; } wms_free(cloud); return(cout); } #define CLACC(x, y) cloud[(x) + ((y)*SIZE)] static void diag(int *cloud, int step, int skew) { int i, j; int sum; for (i = 0; i < SIZE; i += step) for (j = 0; j < SIZE; j += step) { if (((i & step) != 0) && ((j & step) != 0)) { sum = (CLACC(i-step, j-step) + CLACC(i-step, (j+step)&(SIZE-1)) + CLACC((i+step)&(SIZE-1), j-step) + CLACC((i+step)&(SIZE-1), (j+step)&(SIZE-1))) / 4; CLACC(i, j) = sum + my_random(skew); } } } static void perp(int *cloud, int step, int skew) { int i, j; int sum; for (i = 0; i < SIZE; i += step) for (j = 0; j < SIZE; j += step) { if ((i & step) != (j & step)) { sum = (CLACC((i-step)&(SIZE-1), j) + CLACC(i, (j+step)&(SIZE-1)) + CLACC((i+step)&(SIZE-1), j) + CLACC(i, (j-step)&(SIZE-1))) / 4.0; CLACC(i, j) = sum + my_random(skew); } } } static int my_random(int limit) { int i; i = rnd_int32(pe_rnd); if (i & (1 << 30)) return(i % limit); else return(-(i % limit)); } #endif pente-2.2.5/src/xio/xio.c0100664000076400007640000004253407331147374013416 0ustar wmswms/* * src/xio/xio.c, part of Pente (game program) * Copyright (C) 1994-1995 William Shubert. * See "configure.h.in" for more copyright information. */ #include #if X11_DISP #include #include #include #include #include #include #include "../pente.h" #include "xio.h" #include "setup.h" #include "sound.h" #include "helpwin.h" #ifndef DEBUG #define DEBUG 0 #endif bool xio_gameover = TRUE, xio_paused = TRUE, xio_stopped = TRUE; int xio_turn = 2, xio_turn_num = 1, xio_mbutnum; bd_loc_t xio_lastmove = -1; char *xio_helpname; static Xio pxio; static int *level; bool xio_safe_shutdown; static void init_xio_struct(Xio *xio); static void enable_moving(pl_t *game); static void disable_moving(void); static void update_undo(pl_t *game); static bool setup_colors(Xio *xio, ButEnv *env); static ButOut xioCompRequest(void *packet, int fd); #if !DEBUG static RETSIGTYPE term_handler(int signum); #endif bd_loc_t xio_moveSelected; bool xio_color = TRUE; bd_loc_t xio_init(int *comp_level, uint winner, pl_t *game) { static bool first_time = TRUE; bool grid_on = FALSE; level = comp_level; xio_lastmove = -1; if (first_time) { if (!xio_opendisp(&pxio)) return(PE_CANTPLAY); pl_str_game(clp_getStr(pe_clp, "board"), game); bd_init(&pxio.iboard); XFlush(pxio.env->dpy); #if !DEBUG signal(SIGTERM, term_handler); /* Catch these signals gracefully. */ signal(SIGINT, term_handler); signal(SIGHUP, term_handler); signal(SIGPIPE, SIG_IGN); /* Seems like you can't catch a SIGPIPE. */ #endif } xio_draw(game, TRUE); if (first_time) { xio_stopped = TRUE; first_time = FALSE; } if (!xio_gameover && (( pxio.remoteEnd && (comp_level[xio_turn] == -1)) || (!pxio.remoteEnd && (comp_level[xio_turn] == -2)))) { grid_on = TRUE; enable_moving(game); } xio_moveSelected = PE_CANTPLAY; do { butEnv_events(pxio.env); if (pxio.restart_x) { xio_opendisp(&pxio); pxio.restart_x = FALSE; } } while (xio_moveSelected == PE_CANTPLAY); if (grid_on) disable_moving(); return(xio_moveSelected); } bool xio_opendisp(Xio *xio) { static bool first_time = TRUE; bool enough_colors = TRUE; int i, envinit; bool showColorError; ClpEntry *ce; ce = clp_lookup(pe_clp, "wasColor"); if (!first_time) { xio_safe_shutdown = TRUE; butEnv_destroy(xio->env); xio_safe_shutdown = FALSE; } /* Make sure the windows don't think that they're already open! */ init_xio_struct(&pxio); if ((xio->env = butEnv_create("pente " VERSION, clp_getStr(pe_clp, "display"), xio_shutdown)) == NULL) return(FALSE); if (first_time) { const char *lang; int parses; first_time = FALSE; clp_rXDefaults(pe_clp, butEnv_dpy(xio->env), clp_getStr(pe_clp, "name")); clp_rFile(pe_clp, clp_getStr(pe_clp, "adfile")); parses = sscanf(clp_getStr(pe_clp, "VersionNumber"), "Pente %d.%d.%d", &xio->rcMajor, &xio->rcMinor, &xio->rcBugFix); if (parses != 3) xio->rcMajor = xio->rcMinor = xio->rcBugFix = 0; clp_setStr(pe_clp, "VersionNumber", "Pente " VERSION); level[0] = clp_getInt(pe_clp, "player1"); level[1] = clp_getInt(pe_clp, "player2"); lang = clp_getStr(pe_clp, "language"); for (i = 0; (i < XIO_LANG_COUNT) && strcmp(lang, xioStr_langlist[0][i]); ++i); if (i == XIO_LANG_COUNT) { i = 0; fprintf(stderr, "Pente: Error; unknown language \"%s\". Switching " "to \"%s\".\n", lang, xioStr_langlist[0][i]); } xio->lang = i; if (level[0] == 0) level[0] = -2; if (level[1] == 0) level[1] = -2; } showColorError = (clpEntry_getBool(ce) && clp_getBool(pe_clp, "color")); envinit = butEnv_init(xio->env, xio, "Pente", xio_color && clp_getBool(pe_clp, "color")); if (envinit == 3) xio->color = TrueColor; else if (envinit == 2) xio->color = PseudoColor; else xio->color = GrayScale; if (envinit == 1) /* Couldn't get the colors it wanted! */ enough_colors = FALSE; if (!setup_colors(xio, xio->env)) enough_colors = FALSE; if (!enough_colors) { xio_color = FALSE; xio->color = GrayScale; if (xio_opendisp(xio)) { if (showColorError) { abutMsg_winCreate(xio->abut, "Pente: Error", xioStr_notEnoughColors[xio->lang]); } return(TRUE); } else return(FALSE); } clpEntry_setBool(ce, xio_color); butEnv_setChar(xio->env, 1.0, XIO_COMPCHAR, xio_draw_comp, NULL); butEnv_setChar(xio->env, 1.0, XIO_PL1CHAR, xio_draw_pl1char, NULL); butEnv_setChar(xio->env, 1.0, XIO_PL2CHAR, xio_draw_pl2char, NULL); butEnv_setChar(xio->env, 1.0, XIO_PL1MARKCHAR, xio_draw_pl1markchar, NULL); butEnv_setChar(xio->env, 1.0, XIO_PL2MARKCHAR, xio_draw_pl2markchar, NULL); xio->abut = abut_create(xio->env, xioStr_ok[xio->lang], xioStr_cancel[xio->lang]); abut_setColors(xio->abut, xio->litColor, xio->shadColor, xio->bgColor); xio_m_create(xio, "Pente", clp_getStr(pe_clp, "geometry"), clp_getBool(pe_clp, "iconic"), xio->color); xioSound_create(xio); butMenu_set(xio->menu1, level[0] + 2); butMenu_set(xio->menu2, level[1] + 2); if (clp_getBool(pe_clp, "x.setup")) { xio->swin = xioSetup_create(xio); } xio->hwin = NULL; if (clp_getBool(pe_clp, "x.help")) { xio->hwin = xioHelp_create(xio, -1); } if (xio->lnet == NULL) xio_r_init(xio); return(TRUE); } void xio_draw(pl_t *game, bool forced) { bd_t *newboard = pl_board(game); int i, oldturn; uint piece; bd_loc_t loc; bool old_gameover = xio_gameover, gameover_new = FALSE; update_undo(game); xio_think(BD_LOC_MAX, 0); xio_gameover = newboard->gameover; if (xio_gameover != old_gameover) gameover_new = TRUE; if (!old_gameover && xio_gameover) butCt_setText(pxio.startbut, xioStr_start[pxio.lang]); oldturn = xio_turn_num; xio_turn_num = pl_turn(game)+1; for (loc = BD_LOC_MIN; loc < BD_LOC_MAX; ++loc) { piece = newboard->grid[loc]; if ((xio_gameover || xio_stopped) && BD_PLAYERP(piece)) { if (BD_WINNERP(piece)) piece = BD_PLAYER(BD_OWNER(piece)); else piece = BD_WINNER(BD_OWNER(piece)); } if (pxio.iboard.grid[loc] != piece) { pxio.iboard.grid[loc] = piece; but_grid_change(pxio.gridbuts[loc], pxio.iboard.grid[loc], FALSE); but_grid_change(pxio.iconbuts[loc], pxio.iboard.grid[loc], FALSE); } } if (pl_nmoves(game) >= 1) { if (!xio_gameover) { loc = pl_getmove(game, pl_nmoves(game) - 1); but_grid_change(pxio.gridbuts[loc], pxio.iboard.grid[loc], TRUE); pxio.markpos = loc; if (pxio.rnet && (level[xio_turn] > 0)) { xioRemote_comp(&pxio, FALSE, loc, xio_turn); } } if (pl_nmoves(game) >= 2) { loc = pl_getmove(game, pl_nmoves(game) - 2); but_grid_change(pxio.gridbuts[loc], pxio.iboard.grid[loc], FALSE); } } if (xio_turn_num != oldturn) { xio_m_set_turn(&pxio, xio_turn_num, oldturn); } if (gameover_new || (newboard->captures[0] != pxio.iboard.captures[0])) { pxio.iboard.captures[0] = newboard->captures[0]; for (i = 0; i < 5; ++i) { but_cap_change(pxio.caps1[i], pxio.iboard.captures[0]); } } if (gameover_new || (newboard->captures[1] != pxio.iboard.captures[1])) { pxio.iboard.captures[1] = newboard->captures[1]; for (i = 0; i < 5; ++i) { but_cap_change(pxio.caps2[i], pxio.iboard.captures[1]); } } if (xio_gameover) xio_turn = 2; else xio_turn = pl_player(game); XFlush(pxio.env->dpy); } bd_loc_t xio_selectmove(pl_t *game, int compfd) { int movenum; bool comp; #if DEBUG wms_alloc_stat(); #endif comp = (level[pl_player(game)] > 0); xio_gameover = FALSE; if ((pl_turn(game) == 0) && (pl_player(game) == 0)) { if (comp) return(PE_COMP); else { snd_play(&pe_move_snd); return(bd_xy_loc(9,9)); } } movenum = pl_nmoves(game); xio_turn = pl_player(game); xio_moveSelected = PE_CANTPLAY; do { if (comp) { if (!pxio.remoteEnd) { butEnv_addFile(pxio.env, BUT_READFILE, compfd, &xio_moveSelected, xioCompRequest); } } else { if (( pxio.remoteEnd && (level[pl_player(game)] == -1)) || (!pxio.remoteEnd && (level[pl_player(game)] == -2))) enable_moving(game); } butEnv_events(pxio.env); if (comp) butEnv_rmFile(pxio.env, BUT_READFILE, compfd); if (pxio.restart_x) { xio_opendisp(&pxio); pxio.restart_x = FALSE; } } while (xio_moveSelected == PE_CANTPLAY); disable_moving(); if (pl_movep(game, xio_moveSelected)) xio_turn ^= 1; return(xio_moveSelected); } static ButOut xioCompRequest(void *packet, int fd) { int *msel = packet; *msel = PE_COMP; return(BUTOUT_STOPWAIT); } void xio_think(bd_loc_t pos, uint player) { static bd_loc_t last_think = BD_LOC_MAX; static uint last_player = 0; bool drawn = FALSE; if (pos == PE_REDO) pos = last_think; if (player == -1) player = last_player; last_player = player; if (pxio.rnet && (level[player] > 0)) xioRemote_comp(&pxio, TRUE, pos, player); if (last_think != BD_LOC_MAX) { but_grid_change(pxio.gridbuts[last_think], BD_EMPTYA, FALSE); drawn = TRUE; } last_think = pos; if ((pos != BD_LOC_MAX) && clp_getBool(pe_clp, "showthink")) { but_grid_change(pxio.gridbuts[pos], BD_WINNER(player), FALSE); drawn = TRUE; } if (drawn) XFlush(pxio.env->dpy); } static void enable_moving(pl_t *game) { int x, y; bd_loc_t loc; Xio *xio = &pxio; if (!xio->env) return; for (x = 0; x < 19; ++x) { for (y = 0; y < 19; ++y) { loc = bd_xy_loc(x, y); if (pl_movep(game, loc)) { but_setFlags(xio->gridbuts[loc], BUT_PRESSABLE|BUT_TWITCHABLE); } } } } static void disable_moving(void) { int x, y; for (x = 0; x < 19; ++x) { for (y = 0; y < 19; ++y) { but_setFlags(pxio.gridbuts[bd_xy_loc(x, y)], BUT_NOPRESS|BUT_NOTWITCH); } } } static void update_undo(pl_t *game) { static bool undo_was_legal = FALSE, redo_was_legal = FALSE; if (pl_turn(game) >= 1) { if (!undo_was_legal) { but_setFlags(pxio.undobut, BUT_PRESSABLE|BUT_TWITCHABLE); undo_was_legal = TRUE; } } else if (undo_was_legal) { but_setFlags(pxio.undobut, BUT_NOPRESS|BUT_NOTWITCH); undo_was_legal = FALSE; } if (pl_maxmoves(game) > pl_nmoves(game)) { if (!redo_was_legal) { but_setFlags(pxio.redobut, BUT_PRESSABLE|BUT_TWITCHABLE); redo_was_legal = TRUE; } } else if (redo_was_legal) { but_setFlags(pxio.redobut, BUT_NOPRESS|BUT_NOTWITCH); redo_was_legal = FALSE; } } #if !DEBUG static RETSIGTYPE term_handler(int signum) { xio_shutdown(NULL); exit(0); } #endif ButOut xio_press_undo(But *info) { if (pxio.wait_nonicon) { pxio.wait_nonicon = FALSE; clp_setBool(pe_clp, "iconic", FALSE); } xio_moveSelected = PE_UNDO; xio_paused = TRUE; xio_stopped = FALSE; butCt_setText(pxio.startbut, xioStr_continue[pxio.lang]); return(BUTOUT_STOPWAIT); } ButOut xio_press_move(But *info) { if (pxio.wait_nonicon) { pxio.wait_nonicon = FALSE; clp_setBool(pe_clp, "iconic", FALSE); } if (xio_paused || xio_stopped) butCt_setText(pxio.startbut, xioStr_stop[pxio.lang]); xio_paused = FALSE; xio_stopped = FALSE; xio_moveSelected = but_grid_loc(info); return(BUTOUT_STOPWAIT); } ButOut xio_press_redo(But *info) { if (pxio.wait_nonicon) { pxio.wait_nonicon = FALSE; clp_setBool(pe_clp, "iconic", FALSE); } xio_moveSelected = PE_REDO; xio_paused = TRUE; xio_stopped = FALSE; butCt_setText(pxio.startbut, xioStr_continue[pxio.lang]); return(BUTOUT_STOPWAIT); } ButOut xio_press_start(But *info) { if (pxio.wait_nonicon) { pxio.wait_nonicon = FALSE; clp_setBool(pe_clp, "iconic", FALSE); } if (xio_gameover || xio_stopped) { xio_stopped = FALSE; xio_paused = FALSE; xio_moveSelected = PE_RESTART; butCt_setText(info, xioStr_stop[pxio.lang]); } else if (xio_paused) { xio_paused = FALSE; xio_moveSelected = PE_CONTINUE; butCt_setText(info, xioStr_stop[pxio.lang]); } else { xio_moveSelected = PE_PAUSE; xio_stopped = TRUE; butCt_setText(info, xioStr_start[pxio.lang]); } return(BUTOUT_STOPWAIT); } ButOut xio_press_help(But *info) { Xio *xio = butEnv_packet(butWin_env(but_win(info))); if (pxio.wait_nonicon) { pxio.wait_nonicon = FALSE; clp_setBool(pe_clp, "iconic", FALSE); } xio->hwin = xioHelp_create(butEnv_packet(butWin_env(but_win(info))), -1); return(BUTOUT_STOPWAIT); } ButOut xio_press_setup(But *info) { if (pxio.wait_nonicon) { pxio.wait_nonicon = FALSE; clp_setBool(pe_clp, "iconic", FALSE); } pxio.swin = xioSetup_create(&pxio); return(0); } ButOut xio_press_quit(But *info) { if (pxio.wait_nonicon) { pxio.wait_nonicon = FALSE; clp_setBool(pe_clp, "iconic", FALSE); } xio_shutdown(NULL); return(0); } int xio_shutdown(Display *dpy) { char geom[100], setupgeom[30]; snd_deinit(); sprintf(geom, "%dx%d+%d+%d", butWin_w(pxio.mainwin), butWin_h(pxio.mainwin), butWin_x(pxio.mainwin), butWin_y(pxio.mainwin)); clp_setStr(pe_clp, "geometry", geom); if (pxio.swin) { sprintf(setupgeom, "+%d+%d", butWin_x(xioSetup_win(pxio.swin)), butWin_y(xioSetup_win(pxio.swin))); clp_setStr(pe_clp, "x.setup.geom", setupgeom); } xioHelp_storeInfo(pxio.hwin); pe_output_vars(); if (dpy != NULL) { fprintf(stderr, "pente: Exiting; IO error on X connection.\n"); exit(1); } exit(0); } ButOut xio_change_menu(But *info, int value) { Xio *xio = &pxio; int l1, l2; l1 = butMenu_get(xio->menu1) - 2; l2 = butMenu_get(xio->menu2) - 2; if (xio->remoteEnd) { /* * If we're the remote end, then we don't want our computer to swing * into action (we use the other guy's computer), so we set the * level to -3-level. We don't want to just use -3, because then * the tests (l1 == level[0]) and (l2 == level[1]) would give * different results on the two ends of a network connection. */ if (l1 > 0) l1 = -3 - l1; if (l2 > 0) l2 = -3 - l2; } /* * If the user set one to "remote" and there isn't a remote connection, * then make one! */ if ((((l1 == -1) && (info == xio->menu1)) || ((l2 == -1) && (info == xio->menu2))) && (xio->rnet == NULL) && (xio->waitWindow == NULL) && (xio->remAcc == NULL) && (xio->rwin == NULL)) xio_r_create(xio); if ((l1 == level[0]) && (l2 == level[1])) return(0); xio_moveSelected = PE_PAUSE; if (!xio_paused && !xio_gameover && !xio_stopped) { xio_paused = TRUE; butCt_setText(pxio.startbut, xioStr_continue[pxio.lang]); } level[0] = l1; level[1] = l2; clp_setInt(pe_clp, "player1", l1); clp_setInt(pe_clp, "player2", l2); return(BUTOUT_STOPWAIT); } static bool setup_colors(Xio *xio, ButEnv *env) { ButColor colorset[XIO_NPICS]; ButColor bd0, bd7, bdavg, black, white; int i, num_shades; for (i = 0; i < XIO_NPICS; ++i) colorset[i].greyLevel = -1; black = butColor_create(0,0,0,0); white = butColor_create(255,255,255,16); bd0 = butColor_create(208,168,121, 8); bd7 = butColor_create(205,145, 82, 8); bdavg = butColor_mix(bd0,1, bd7,1); colorset[XIO_PIC_OUTLINE] = white; colorset[XIO_PIC_BLACK] = black; colorset[XIO_PIC_DIMOUTLINE] = butColor_mix(white,3, black,1); colorset[XIO_PIC_STAMP] = butColor_create(184,120,57, 4); if (xio->color == TrueColor) num_shades = 256; else num_shades = 8; for (i = 0; i < num_shades; ++i) { colorset[XIO_PIC_BOARD(i)] = butColor_mix(bd0,i, bd7,num_shades-1-i); colorset[XIO_PIC_BOARD(i+num_shades)] = butColor_mix(colorset[XIO_PIC_BOARD(i)],4, white,1); colorset[XIO_PIC_BOARD(i+2*num_shades)] = butColor_mix(colorset[XIO_PIC_BOARD(i)],4, black,1); } colorset[XIO_PIC_PL1] = butColor_create(0,200,0, 0); colorset[XIO_PIC_PL2] = butColor_create(0,0,255, 16); colorset[XIO_PIC_DIMPL1] = butColor_mix(colorset[XIO_PIC_PL1],2, black,1); colorset[XIO_PIC_DIMPL1].greyLevel = 4; colorset[XIO_PIC_DIMPL2] = butColor_mix(colorset[XIO_PIC_PL2],2, black,1); colorset[XIO_PIC_DIMPL2].greyLevel = 12; colorset[XIO_PIC_BUT1FG] = butColor_create(0,0,0, 16); colorset[XIO_PIC_MARK1] = butColor_create(255,255,255, 16); colorset[XIO_PIC_MARK2] = butColor_create(255,255,255, 0); for (i = 0; i < XIO_NPICS; ++i) if (colorset[i].greyLevel != -1) { /* The color was changed. */ if (!butEnv_setColor(env, i, colorset[i])) { return(FALSE); } } if (xio->color == PseudoColor) { xio->bgColor = XIO_PIC_BOARD(4); xio->litColor = XIO_PIC_BOARD(8+7); xio->shadColor = XIO_PIC_BOARD(16); } else if (xio->color == TrueColor) { xio->bgColor = XIO_PIC_BOARD(128); xio->litColor = XIO_PIC_BOARD(511); xio->shadColor = XIO_PIC_BOARD(512); } else { /* xio->color == GrayScale */ xio->bgColor = BUT_BG; xio->litColor = BUT_LIT; xio->shadColor = BUT_SHAD; } return(TRUE); } static void init_xio_struct(Xio *xio) { xio->env = NULL; xio->mainwin = NULL; xio->remoteEnd = FALSE; xio->hwin = NULL; xio->swin = NULL; xio->tiwin = NULL; xio->wait_nonicon = FALSE; xio->restart_x = FALSE; xio->copbox = NULL; xio->openWindows = 0; xio->remAcc = NULL; xio->waitWindow = NULL; } #endif pente-2.2.5/src/xio/mainwin.c0100664000076400007640000005437107331147374014263 0ustar wmswms/* * src/xio/mainwin.c, part of Pente (game program) * Copyright (C) 1994-1995 William Shubert. * See "configure.h.in" for more copyright information. * * Routines to manage the main window for pente. */ #include #if X11_DISP #include #include #include #include #include #include #include #include #include #include #include "../pente.h" #include "xio.h" #include "setup.h" #include "sound.h" #include "helpwin.h" static ButOut unmap(ButWin *win); static ButOut map(ButWin *win); static ButOut resize(ButWin *win); static ButOut iresize(ButWin *win); static ButOut destroy(ButWin *win); static Pixmap decorate_bg(Xio *xio, Pixmap bp, int winw, int winh, int gridw, int grid0x, int grid0y, bool icon); static void pente_stamp(ButEnv *env, Pixmap pm, int x,int y, int w,int h); static ButOut kill_copyright(ButTimer *timer); static bool color_enabled; void xio_m_create(Xio *xio, const char *name, const char *geometry, bool iconic, bool color) { int x, y; int i; bd_loc_t pos; const char *optlist[10]; static bool first_time = TRUE; static ButKey quitkeys[] = {{XK_Q, 0,0}, {XK_q, 0,0}, {0,0,0}}; static ButKey helpkeys[] = {{XK_H, 0,0}, {XK_h, 0,0}, {XK_Help, 0,0}, {XK_question, 0,0}, {0,0,0}}; static ButKey soundkeys[] = {{XK_S, 0,0}, {XK_s, 0,0}, {0,0,0}}; static ButKey undokeys[] = {{XK_BackSpace, 0,0}, {XK_Left, 0,0}, {0,0,0}}; static ButKey redokeys[] = {{XK_Right, 0,0}, {0,0,0}}; color_enabled = (color != GrayScale); xio->mainwin = butWin_iCreate(NULL, xio->env, name, 430, 430, &xio->iconwin, iconic, 63, 63, unmap, map, resize, iresize, destroy); butWin_setMinW(xio->mainwin, 100); butWin_setMinH(xio->mainwin, 100); butWin_setMaxW(xio->mainwin, 0); butWin_setMaxH(xio->mainwin, 0); butWin_setWHRatio(xio->mainwin, 1, 1); butWin_setGeom(xio->mainwin, geometry); butWin_activate(xio->mainwin); butWin_setId(xio->mainwin, 0); for (x = 0; x < 19; ++x) { for (y = 0; y < 19; ++y) { pos = bd_xy_loc(x, y); xio->gridbuts[pos] = but_grid_create(xio_press_move, xio->mainwin, 2, BUT_DRAWABLE, pos); xio->iconbuts[pos] = but_grid_create(NULL, xio->iconwin, 2, BUT_DRAWABLE, pos); but_setId(xio->gridbuts[pos],x+y*19); if (!BD_EMPTYP(xio->iboard.grid[pos])) { but_grid_change(xio->gridbuts[pos], xio->iboard.grid[pos], pos == xio->markpos); but_grid_change(xio->iconbuts[pos], xio->iboard.grid[pos], pos == xio->markpos); } } } for (i = 0; i < 5; ++i) { xio->caps1[i] = but_cap_create(xio->mainwin, 1, BUT_DRAWABLE, i+1, 1); xio->caps2[i] = but_cap_create(xio->mainwin, 1, BUT_DRAWABLE, i+1, 0); } for (i = 0; i < 3; ++i) { xio->digits[i] = butText_create(xio->mainwin, 1, BUT_DRAWABLE, "", butText_center); butText_setFont(xio->digits[i], 1); } xio_m_set_turn(xio, xio_turn_num, -1); for (i = 0; xioStr_turn[xio->lang][i]; ++i) { char temp[2]; temp[1] = '\0'; temp[0] = xioStr_turn[xio->lang][i]; xio->turnlabel[i] = butText_create(xio->mainwin, 1, BUT_DRAWABLE, temp, butText_center); butText_setFont(xio->turnlabel[i], 1); } xio->turnlabel[i] = NULL; xio->undobut = butAct_create(xio_press_undo, NULL, xio->mainwin, 1, BUT_DRAWABLE, xioStr_undo[xio->lang], BUT_ALEFT|BUT_RRIGHT); but_setKeys(xio->undobut, undokeys); but_setId(xio->undobut, 19*19+0); xio->redobut = butAct_create(xio_press_redo, NULL, xio->mainwin, 1, BUT_DRAWABLE, xioStr_redo[xio->lang], BUT_RLEFT|BUT_ARIGHT); but_setKeys(xio->redobut, redokeys); but_setId(xio->redobut, 19*19+1); xio->helpbut = butCt_create(xio_press_help, NULL, xio->mainwin, 1, BUT_DRAWABLE|BUT_PRESSABLE, xioStr_help[xio->lang]); but_setKeys(xio->helpbut, helpkeys); but_setId(xio->helpbut, 19*19+2); butCt_setNetAction(xio->helpbut, FALSE); xio->setupbut = butCt_create(xio_press_setup, xio->swin, xio->mainwin, 1, BUT_DRAWABLE|BUT_PRESSABLE, xioStr_setup[xio->lang]); but_setId(xio->setupbut, 19*19+3); butCt_setNetAction(xio->setupbut, FALSE); xio->startbut = butCt_create(xio_press_start, NULL, xio->mainwin, 1, BUT_DRAWABLE|BUT_PRESSABLE, xioStr_start[xio->lang]); but_setId(xio->startbut, 19*19+4); xio->quitbut = butCt_create(xio_press_quit, NULL, xio->mainwin, 1, BUT_DRAWABLE|BUT_PRESSABLE, xioStr_quit[xio->lang]); but_setKeys(xio->quitbut, quitkeys); but_setId(xio->quitbut, 19*19+5); butCt_setNetAction(xio->quitbut, FALSE); xio->soundbut = butKeytrap_create(xioSound_toggle, xio, xio->mainwin, BUT_DRAWABLE|BUT_PRESSABLE); but_setKeys(xio->soundbut, soundkeys); if (xio->remoteEnd) { optlist[0] = xioStr_remote[xio->lang]; optlist[1] = xioStr_human[xio->lang]; } else { optlist[0] = xioStr_human[xio->lang]; optlist[1] = xioStr_remote[xio->lang]; } optlist[2] = BUTMENU_OLBREAK; optlist[3] = xioStr_comp1[xio->lang]; optlist[4] = xioStr_comp2[xio->lang]; optlist[5] = xioStr_comp3[xio->lang]; optlist[6] = xioStr_comp4[xio->lang]; optlist[7] = xioStr_comp5[xio->lang]; optlist[8] = xioStr_comp6[xio->lang]; optlist[9] = BUTMENU_OLEND; xio->menu1 = butMenu_upCreate(xio_change_menu, NULL, xio->mainwin, 1, 3, BUT_DRAWABLE|BUT_PRESSABLE, xioStr_player1[xio->lang], optlist, 0); butMenu_setColor(xio->menu1, XIO_PIC_BUT1FG, XIO_PIC_PL1); #if !HAVE_SOCKETS butMenu_setFlags(xio->menu1, 1, BUTMENU_DISABLED); #endif but_setId(xio->menu1, 19*19+6); xio->menu2 = butMenu_upCreate(xio_change_menu, NULL, xio->mainwin, 1, 3, BUT_DRAWABLE|BUT_PRESSABLE, xioStr_player2[xio->lang], optlist, 0); butMenu_setColor(xio->menu2, BUT_FG, XIO_PIC_PL2); #if !HAVE_SOCKETS butMenu_setFlags(xio->menu2, 1, BUTMENU_DISABLED); #endif but_setId(xio->menu2, 19*19+7); xio->bgpic = None; xio->bgbut = butPixmap_create(xio->mainwin, 0, BUT_DRAWABLE, None); xio->ibgpic = None; xio->ibgbut = butPixmap_create(xio->iconwin, 0, BUT_DRAWABLE, None); if (first_time) { /* Put up the copyright. */ first_time = FALSE; xio->copbox = butBox_create(xio->mainwin, 5, BUT_DRAWABLE); xio->copback = butPlain_create(xio->mainwin, 4, BUT_DRAWABLE|BUT_PRESSABLE, BUT_BG); xio->copwords1 = butTblock_create(xio->mainwin, 5, BUT_DRAWABLE, "Pente " VERSION, butText_center); butTblock_setFont(xio->copwords1, 1); xio->copwords2 = butTblock_create(xio->mainwin, 5, BUT_DRAWABLE, xioStr_copyright[xio->lang], butText_center); xio->copwords3 = butTblock_create(xio->mainwin, 5, BUT_DRAWABLE, xioStr_nowarr[xio->lang], butText_center); xio->copwords4 = butTblock_create(xio->mainwin, 5, BUT_DRAWABLE, xioStr_seehelp[xio->lang], butText_center); } } static ButOut unmap(ButWin *win) { Xio *xio = butEnv_packet(butWin_env(win)); xio->wait_nonicon = FALSE; clp_setBool(pe_clp, "iconic", TRUE); --xio->openWindows; xioSound_check(xio); return(0); } static ButOut map(ButWin *win) { Xio *xio = butEnv_packet(butWin_env(win)); xio->wait_nonicon = TRUE; ++xio->openWindows; xioSound_check(xio); return(0); } static ButOut resize(ButWin *win) { Xio *xio; int i, x, y, w, h, winw, winh, buth, bw; int gridw; int grid0x, grid0y, capSpc, capHt; bd_loc_t loc; uchar *bgcmap; struct timeval five_secs; xio = butEnv_packet(butWin_env(win)); if (xio->wait_nonicon) { xio->wait_nonicon = FALSE; clp_setBool(pe_clp, "iconic", FALSE); } winw = butWin_w(win); winh = butWin_h(win); gridw = (winw * 19 + 215) / 430; buth = xio->abut->butH = xio->buth = (winh*5+42)/86; while (gridw * 22 > winw) --gridw; while (gridw * 20 + buth*2 > winh) --gridw; butEnv_setFont(xio->env, 0, xioStr_mfonts[xio->lang], (buth + 1) / 2); butEnv_setFont(xio->env, 1, xioStr_bfonts[xio->lang], (gridw * 16 + 9)/19); butEnv_drawAll(butWin_env(win)); grid0x = (winw - gridw * 19) / 2; grid0y = (winh - buth * 2 - gridw * 19) / 2; for (x = 0; x < 19; ++x) { for (y = 0; y < 19; ++y) { loc = bd_xy_loc(x, y); but_resize(xio->gridbuts[loc], grid0x+x*gridw, grid0y+y*gridw, gridw, gridw); } } capSpc = (buth - gridw) / 2; capHt = winh - buth*2; for (i = 0; i < 5; ++i) { but_resize(xio->caps1[i], capSpc, (capHt*i)/5 + capHt/10 - gridw, gridw, gridw*2); but_resize(xio->caps2[i], winw-gridw-capSpc, (capHt*i)/5 + capHt/10 - gridw, gridw, gridw*2); } x = 8 + ((strlen(xioStr_turn[xio->lang]) + 4) / 2); x = grid0x + (gridw * x) + (gridw+1)/2; y = grid0y + (gridw+1)/2; for (i = 0; i < 3; ++i) { but_resize(xio->digits[i], x-i*gridw,y, gridw,gridw); } x = 9 - ((strlen(xioStr_turn[xio->lang]) + 4) / 2); x = grid0x + (gridw * x) + (gridw+1)/2; for (i = 0; xio->turnlabel[i] != NULL; ++i) { but_resize(xio->turnlabel[i], x+i*gridw,y, gridw,gridw); } but_resize(xio->menu1, 0,winh-2*buth, winw/5,2*buth); but_resize(xio->menu2, winw-(winw/5),winh-2*buth, winw/5,2*buth); but_resize(xio->undobut, winw/5,winh-2*buth, winw/5,buth); but_resize(xio->setupbut, winw/5,winh-buth, winw/5,buth); but_resize(xio->redobut, winw-2*(winw/5),winh-2*buth, winw/5,buth); but_resize(xio->quitbut, winw-2*(winw/5),winh-buth, winw/5,buth); but_resize(xio->startbut, 2*(winw/5),winh-2*buth, winw-4*(winw/5),buth); but_resize(xio->helpbut, 2*(winw/5),winh-buth, winw-4*(winw/5),buth); if (xio->bgpic != None) XFreePixmap(butEnv_dpy(xio->env), xio->bgpic); xio->bgpic = None; bgcmap = xio_plasma(); if (color_enabled) { if (xio->color == TrueColor) { xio->bgpic = cm2pm_chop(xio, bgcmap, 512,512, winw,winh, XIO_PIC_BOARD(0), 256, gridw, buth); } else { xio->bgpic = cm2pm_chop(xio, bgcmap, 512,512, winw,winh, XIO_PIC_BOARD(0), 8, gridw, buth); } } xio->bgpic = decorate_bg(xio, xio->bgpic, winw, winh, gridw, grid0x, grid0y, FALSE); butPixmap_setPic(xio->bgbut, xio->bgpic, 0,0); but_resize(xio->bgbut, 0,0, winw,winh); if (xio->copbox != NULL) { w = (winw*2+1)/3; h = (winh+1)/3; x = (winw - w) / 2; y = (winh - h + 1) / 3; bw = butEnv_stdBw(xio->env); but_resize(xio->copbox, x,y, w,h); but_resize(xio->copback, x,y, w,h); but_resize(xio->copwords1, x+bw,y+bw*2, w-bw*2,buth); y += bw*3+buth; y += butTblock_resize(xio->copwords2, x+bw*2,y, w-bw*4); y += butTblock_resize(xio->copwords3, x+bw*2,y, w-bw*4); butTblock_resize(xio->copwords4, x+bw*2,y, w-bw*4); if (xio->coptimer == NULL) { /* * Wait until the resize to set the "kill copyright" timer. * If set the timer at window creation, it may be more than five * seconds until the window is drawn, in which case the user will * never see the copyright! */ five_secs.tv_sec = 5; five_secs.tv_usec = 0; xio->coptimer = butTimer_create(xio, xio->copbox, five_secs, five_secs, FALSE, kill_copyright); } } xioSetup_resize(xio->swin); xioHelp_resize(xio->hwin); return(0); } static Pixmap decorate_bg(Xio *xio, Pixmap bp, int winw, int winh, int gridw, int grid0x, int grid0y, bool icon) { uint i, j; int halfgw; int buth = xio->buth; ButEnv *env = xio->env; Display *dpy = butEnv_dpy(env); GC gc = butEnv_gc(env); int capHt; if (bp == None) { bp = XCreatePixmap(dpy, RootWindow(dpy, DefaultScreen(dpy)), winw, winw, DefaultDepth(dpy, DefaultScreen(dpy))); butEnv_setXFg(env, XIO_PIC_BOARD(0)); XFillRectangle(dpy, bp, gc, 0,0,winw,winw); } if (icon) pente_stamp(env, bp, 0,0, winw,winw); else pente_stamp(env, bp, (winw-gridw*20)/2, 0, gridw*20, gridw*20); /* Draw the actual grid itself. */ butEnv_setXFg(env, XIO_PIC_BLACK); if (gridw > 5) { /* Grid lines. */ i = (gridw+6)/12; if (i < 1) i = 1; XSetLineAttributes(dpy, gc, i, LineSolid, CapProjecting, JoinMiter); halfgw = (gridw+1)/2; for (i = 0; i < 19; ++i) { XDrawLine(dpy, bp, gc, grid0x+halfgw, grid0y+halfgw+gridw*i, grid0x+halfgw+gridw*18, grid0y+halfgw+gridw*i); XDrawLine(dpy, bp, gc, grid0x+halfgw+gridw*i, grid0y+halfgw, grid0x+halfgw+gridw*i, grid0y+halfgw+gridw*18); } if (!icon) { XFontStruct *fs = butEnv_fontStr(env, 1); XCharStruct *xcs; /* Put the word "Captures" down the sides. */ capHt = winh - buth*2; XSetFont(dpy, gc, fs->fid); j = strlen(xioStr_captures[xio->lang]); for (i = 0; i < j; ++i) { if (fs->per_char == NULL) xcs = &(fs->min_bounds); else xcs = &(fs->per_char[xioStr_captures[xio->lang][i] - fs->min_char_or_byte2]); XDrawString(dpy, bp, gc, (buth-xcs->width)/2 - xcs->lbearing, (capHt*i/j)+(capHt/(2*j))+(fs->ascent - fs->descent)/2, &xioStr_captures[xio->lang][i], 1); XDrawString(dpy, bp, gc, winw-(buth+xcs->width)/2 - xcs->lbearing, (capHt*i/j)+(capHt/(2*j))+(fs->ascent - fs->descent)/2, &xioStr_captures[xio->lang][i], 1); } } } return(bp); } /* Stamp a giant "Pente" logo on the board. */ static void pente_stamp(ButEnv *env, Pixmap pm, int x,int y, int w,int h) { static XPoint polyf0[] = /* Left part of "P" */ {{48,793},{225,793},{225,1196},{236,1208},{244,1209},{274,1210},{282,1211}, {286,1211},{286,1250},{48,1250},{48,1211},{81,1209},{88,1209},{90,1208}, {93,1208},{105,1195},{105,844},{95,834},{57,833},{55,832},{48,832}, {48,793}}; static XPoint polyf2[] = /* Right part of "P" */ {{225,793},{290,793},{292,794},{305,794},{307,795},{324,796},{326,797}, {337,798},{339,799},{359,803},{386,812},{403,821},{424,836},{441,856}, {452,879},{457,897},{459,911},{460,927},{459,952},{458,954},{457,966}, {456,968},{452,985},{450,989},{443,1006},{429,1027},{409,1047}, {404,1049},{396,1056},{373,1067},{346,1076},{327,1080},{306,1083}, {276,1085},{241,1085},{239,1084},{225,1084},{225,1039},{245,1039}, {261,1037},{275,1034},{291,1028},{307,1016},{318,1003},{324,990}, {326,986},{328,978},{329,976},{331,963},{332,961},{332,952}, {333,950},{333,931},{332,917},{330,905},{327,893},{320,876},{313,867}, {312,864},{296,850},{285,845},{279,842},{266,840},{264,839},{225,839}, {225,793}}; static XPoint polyf1[] = {{1454,826},{1514,826},{1514,923},{1618,923},{1618,973},{1514,973}, {1514,1146},{1515,1148},{1516,1159},{1517,1161},{1520,1171}, {1528,1181},{1533,1183},{1537,1186},{1550,1190},{1570,1192}, {1589,1192},{1591,1191},{1601,1191},{1603,1190},{1615,1189}, {1617,1188},{1618,1190},{1618,1226},{1590,1236},{1558,1245}, {1534,1250},{1513,1253},{1497,1254},{1482,1254},{1480,1253}, {1467,1252},{1465,1251},{1452,1248},{1448,1246},{1432,1239}, {1418,1227},{1409,1215},{1408,1210},{1407,1208},{1404,1194}, {1402,1170},{1402,973},{1353,973},{1353,942},{1412,905},{1418,892}, {1422,887},{1432,866},{1436,861},{1445,842},{1449,837},{1454,826}}; static XPoint polyf3[] = /* Top of "e" */ {{678,903},{704,903},{706,904},{716,904},{718,905},{731,906},{733,907}, {751,911},{755,913},{761,914},{771,919},{786,926},{807,942},{824,960}, {826,965},{833,974},{844,998},{851,1022},{736,1039},{736,1033}, {735,1011},{731,987},{724,969},{715,957},{703,949},{694,947}, {692,946},{675,946},{675,947},{671,947},{669,948},{662,949}, {646,959},{634,976},{629,991},{628,993},{627,1000},{626,1002}, {625,1015},{624,1017},{624,1039},{513,1017},{515,1013},{519,1002}, {531,980},{549,957},{575,935}, {580,933},{585,929},{608,918},{636,909},{649,907},{651,906},{665,905}, {667,904},{678,904},{678,903}}; static XPoint polyf6[] = /* Bottom of "e" */ {{624,1039},{736,1039},{851,1022},{854,1042},{855,1052}, {856,1068},{856,1081},{621,1081},{622,1100},{623,1102},{624,1112}, {625,1114},{627,1123},{628,1125},{635,1142},{647,1160},{665,1176}, {684,1185},{704,1190},{718,1191},{736,1191},{738,1190},{757,1189}, {759,1188},{778,1185},{780,1184},{797,1180},{801,1178},{824,1170}, {854,1155},{854,1217},{849,1218},{831,1227},{801,1238},{773,1246}, {760,1248},{752,1250},{735,1252},{729,1253},{697,1255},{675,1255}, {673,1254},{662,1254},{660,1253},{646,1252},{644,1251},{625,1247}, {604,1240},{598,1237},{579,1228},{552,1207},{531,1182},{528,1175}, {522,1167},{521,1162},{515,1150},{508,1127},{507,1119},{506,1117}, {504,1099},{503,1081},{504,1057},{505,1055},{506,1042},{507,1040}, {513,1017},{624,1039}}; static XPoint polyf4[] = /* Top of 2nd "e" */ {{1822,903},{1848,903},{1850,904},{1860,904},{1862,905},{1875,906}, {1877,907},{1895,911},{1899,913},{1905,914},{1915,919},{1930,926}, {1951,942},{1968,960},{1970,965},{1977,974},{1988,998},{1995,1022}, {1880,1039},{1880,1033},{1879,1011},{1875,987},{1868,969},{1859,957}, {1847,949},{1838,947},{1836,946},{1819,946},{1819,947},{1815,947}, {1813,948},{1806,949},{1790,959},{1778,976},{1773,991},{1772,993}, {1771,1000},{1770,1002},{1769,1015},{1768,1017},{1768,1039}, {1657,1017},{1659,1013},{1663,1002},{1675,980}, {1693,957},{1719,935},{1724,933},{1729,929},{1752,918},{1780,909}, {1793,907},{1795,906},{1809,905},{1811,904},{1822,904},{1822,903}}; static XPoint polyf7[] = /* Bottom of 2nd "e" */ {{1768,1039},{1880,1039},{1995,1022}, {1998,1042},{1999,1052},{2000,1068},{2000,1081},{1765,1081},{1766,1100}, {1767,1102},{1768,1112},{1769,1114},{1771,1123},{1772,1125},{1779,1142}, {1791,1160},{1809,1176},{1828,1185},{1848,1190},{1862,1191},{1880,1191}, {1882,1190},{1901,1189},{1903,1188},{1922,1185},{1924,1184},{1941,1180}, {1945,1178},{1968,1170},{1998,1155},{1998,1217},{1993,1218},{1975,1227}, {1945,1238},{1917,1246},{1904,1248},{1896,1250},{1879,1252},{1873,1253}, {1841,1255},{1819,1255},{1817,1254},{1806,1254},{1804,1253},{1790,1252}, {1788,1251},{1769,1247},{1748,1240},{1742,1237},{1723,1228},{1696,1207}, {1675,1182},{1672,1175},{1666,1167},{1665,1162},{1659,1150},{1652,1127}, {1651,1119},{1650,1117},{1648,1099},{1647,1081},{1648,1057},{1649,1055}, {1650,1042},{1651,1040},{1657,1017},{1768,1039}}; static XPoint polyf5[] = {{1018,905},{1058,905},{1058,950},{1101,929},{1133,916},{1159,908}, {1170,907},{1172,906},{1188,905},{1199,905},{1201,906},{1213,907}, {1215,908},{1228,911},{1247,921},{1264,938},{1266,943},{1270,948}, {1277,966},{1281,982},{1284,1002},{1285,1024},{1285,1203},{1293,1212}, {1313,1213},{1315,1214},{1324,1214},{1326,1215},{1329,1215},{1329,1250}, {1139,1250},{1139,1215},{1164,1212},{1167,1211},{1174,1202},{1174,1041}, {1173,1039},{1172,1024},{1171,1022},{1167,1008},{1159,995},{1148,986}, {1136,981},{1122,978},{1106,977},{1083,977},{1081,978},{1060,979}, {1058,981},{1058,1203},{1068,1212},{1083,1213},{1085,1214},{1092,1214}, {1094,1215},{1096,1215},{1096,1250},{902,1250},{902,1215},{934,1212}, {938,1212},{939,1209},{945,1203},{945,977},{897,977},{897,945}, {1017,906},{1018,905}}; static XPoint *(polyf[]) = {polyf0, polyf1, polyf2, polyf3, polyf4, polyf5, polyf6, polyf7}; int pflen[] = {sizeof(polyf0)/sizeof(polyf0[0]), sizeof(polyf1)/sizeof(polyf1[0]), sizeof(polyf2)/sizeof(polyf2[0]), sizeof(polyf3)/sizeof(polyf3[0]), sizeof(polyf4)/sizeof(polyf4[0]), sizeof(polyf5)/sizeof(polyf5[0]), sizeof(polyf6)/sizeof(polyf6[0]), sizeof(polyf7)/sizeof(polyf7[0])}; XPoint tx[200]; Display *dpy = butEnv_dpy(env); GC gc = butEnv_gc(env); int i, j; butEnv_setXFg(env, XIO_PIC_STAMP); for (i = 0; i < 8; ++i) { for (j = 0; j < pflen[i]; ++j) { tx[j].x = x + (polyf[i][j].x * w + 1024) / 2048; tx[j].y = y + (polyf[i][j].y * h + 1024) / 2048; } XFillPolygon(dpy, pm, gc, tx, pflen[i], Complex, CoordModeOrigin); } } static ButOut iresize(ButWin *win) { int x, y, winw, winh; int gw, gh, g0x, g0y; bd_loc_t loc; Xio *xio; uchar *bgcmap; xio = butEnv_packet(butWin_env(win)); winw = butWin_w(win); winh = butWin_h(win); gw = winw / 20; gh = winh / 20; g0x = (winw - 19*gw) / 2; g0y = (winh - 19*gh) / 2; for (x = 0; x < 19; ++x) { for (y = 0; y < 19; ++y) { loc = bd_xy_loc(x, y); but_resize(xio->iconbuts[loc], g0x+x*gw, g0y+y*gh, gw, gh); } } if (xio->ibgpic != None) XFreePixmap(butEnv_dpy(xio->env), xio->ibgpic); xio->ibgpic = None; bgcmap = xio_plasma(); if (color_enabled) { if (xio->color == TrueColor) { xio->ibgpic = cm2pm_chop(xio, bgcmap, 512,512, winw,winh, XIO_PIC_BOARD(0), 256, 0, 0); } else { xio->ibgpic = cm2pm_chop(xio, bgcmap, 512,512, winw,winh, XIO_PIC_BOARD(0), 8, 0, 0); } } xio->ibgpic = decorate_bg(xio, xio->ibgpic, winw, winh, gw, g0x, g0y, TRUE); butPixmap_setPic(xio->ibgbut, xio->ibgpic, 0,0); but_resize(xio->ibgbut, 0,0, winw,winh); return(0); } static ButOut destroy(ButWin *win) { static char geom[100]; sprintf(geom, "%dx%d%+d%+d", butWin_w(win), butWin_h(win), butWin_x(win), butWin_y(win)); clp_setStr(pe_clp, "geometry", geom); if (!xio_safe_shutdown) xio_shutdown(NULL); return(0); } static ButOut kill_copyright(ButTimer *timer) { Xio *xio = butTimer_packet(timer); xio->coptimer = NULL; butTimer_destroy(timer); but_destroy(xio->copwords1); but_destroy(xio->copwords2); but_destroy(xio->copwords3); but_destroy(xio->copwords4); but_destroy(xio->copbox); but_destroy(xio->copback); xio->copbox = NULL; return(0); } void xio_m_set_turn(Xio *xio, int turn, int oldturn) { char textout[2]; if (oldturn == -1) oldturn = turn + 111; textout[1] = '\0'; textout[0] = (turn % 10) + '0'; butText_set(xio->digits[0], textout); if (turn/10 != oldturn/10) { if (turn <= 9) textout[0] = '\0'; else textout[0] = ((turn / 10) % 10) + '0'; butText_set(xio->digits[1], textout); } if (turn/100 != oldturn/100) { if (turn <= 99) textout[0] = '\0'; else textout[0] = ((turn / 100) % 10) + '0'; butText_set(xio->digits[1], textout); } } #endif /* X11_DISP */ pente-2.2.5/src/xio/helpwin.c0100664000076400007640000002257307045637747014300 0ustar wmswms/* * src/xio/helpwin.c, part of Pente (game program) * Copyright (C) 1994 William Shubert. * See "configure.h.in" for more copyright information. */ #include #if X11_DISP #include #include #include #include #include #include #include #include #include #include #include "../pente.h" #include "xio.h" #include "sound.h" #include "helpwin.h" typedef struct XioHelp_struct { Xio *xio; But *box, *dbg, *ok, *soundbut; But *menu; But **textbuts; int n_textbuts, max_textbuts; AbutSwin *swin; ButWin *win, *dwin; int litcolor, shadcolor, bgcolor; int canw, canh, lastViewW; MAGIC_STRUCT } XioHelp; static bool wait_for_open = FALSE; static ButOut unmap(ButWin *win); static ButOut resize(ButWin *win); static ButOut destroy(ButWin *win); static ButOut ok_pressed(But *but); static ButOut dwin_resize(ButWin *win); static ButOut change_menu(But *but, int value); static void setup_text(Xio *xio, XioHelp *hwin, bool destroy); XioHelp *xioHelp_create(Xio *xio, int pagenum) { static ButKey ka_ok[] = {{XK_Return, 0,0}, {XK_KP_Enter, 0,0}, {0,0,0}}; static ButKey soundkeys[] = {{XK_S, 0,0}, {XK_s, 0,0}, {0,0,0}}; XioHelp *hwin; ButWin *win; char geometry[100]; const char *optlist[8]; int w, h, minh; clp_setBool(pe_clp, "x.help", TRUE); if (xio->hwin && !wait_for_open) { hwin = xio->hwin; assert(MAGIC(hwin)); XRaiseWindow(butEnv_dpy(xio->env), butWin_xwin(hwin->win)); if ((pagenum != -1) && (pagenum != butMenu_get(hwin->menu))) { butMenu_set(hwin->menu, pagenum); change_menu(hwin->menu, pagenum); } return(hwin); } if (pagenum != -1) { clp_setInt(pe_clp, "x.help.page", pagenum); clp_setDouble(pe_clp, "x.help.bookmark", 0.0); } w = butWin_w(xio->mainwin); h = butWin_h(xio->mainwin); if (w == 0) { /* Main window hasn't been opened! */ wait_for_open = TRUE; return(NULL); } else wait_for_open = FALSE; hwin = wms_malloc(sizeof(XioHelp)); MAGIC_SET(hwin); hwin->xio = xio; hwin->box = NULL; hwin->dbg = NULL; hwin->ok = NULL; hwin->soundbut = NULL; hwin->menu = NULL; hwin->textbuts = NULL; hwin->n_textbuts = hwin->max_textbuts = 0; hwin->swin = NULL; hwin->win = hwin->dwin = NULL; hwin->lastViewW = 0; minh = (but_h(xio->helpbut)*4+butEnv_stdBw(xio->env)*9) * 2; if (h < minh) h = minh; if (w < minh) w = minh; if (clp_getStr(pe_clp, "x.help.geom")[0] == '\0') { sprintf(geometry, "%dx%d", w, h); } else { sprintf(geometry, "%s", clp_getStr(pe_clp, "x.help.geom")); } if (xio->color == PseudoColor) { hwin->bgcolor = XIO_PIC_BOARD(4); hwin->litcolor = XIO_PIC_BOARD(8+7); hwin->shadcolor = XIO_PIC_BOARD(16); } else if (xio->color == TrueColor) { hwin->bgcolor = XIO_PIC_BOARD(128); hwin->litcolor = XIO_PIC_BOARD(511); hwin->shadcolor = XIO_PIC_BOARD(512); } else { /* xio->color == GrayScale */ hwin->bgcolor = BUT_BG; hwin->litcolor = BUT_LIT; hwin->shadcolor = BUT_SHAD; } ++xio->openWindows; hwin->win = win = butWin_create(hwin, xio->env, "Pente Help", w,h, unmap, NULL, resize, destroy); butWin_setMinW(win, 100); butWin_setMinH(win, 100); butWin_setMaxW(win, 0); butWin_setMaxH(win, 0); butWin_setGeom(win, geometry); butWin_activate(win); hwin->box = butBoxFilled_create(win, 0, BUT_DRAWABLE); butBoxFilled_setColors(hwin->box, hwin->litcolor, hwin->shadcolor, hwin->bgcolor); optlist[0] = xioStr_phelp[xio->lang]; optlist[1] = xioStr_ghelp[xio->lang]; optlist[2] = xioStr_shelp[xio->lang]; optlist[3] = xioStr_nhelp[xio->lang]; optlist[4] = xioStr_cphelp[xio->lang]; optlist[5] = xioStr_ahelp[xio->lang]; optlist[6] = xioStr_chelp[xio->lang]; optlist[7] = BUTMENU_OLEND; hwin->xio = xio; hwin->menu = butMenu_downCreate(change_menu, NULL, win, 1, 3, BUT_DRAWABLE|BUT_PRESSABLE, xioStr_hmenu[xio->lang], optlist, clp_getInt(pe_clp, "x.help.page")); hwin->ok = butCt_create(ok_pressed, NULL, win, 1, BUT_DRAWABLE|BUT_PRESSABLE, "OK"); but_setKeys(hwin->ok, ka_ok); hwin->soundbut = butKeytrap_create(xioSound_toggle, xio, win, BUT_DRAWABLE|BUT_PRESSABLE); but_setKeys(hwin->soundbut, soundkeys); hwin->swin = abutSwin_create(hwin, win, 1, ABUTSWIN_LSLIDE, dwin_resize); hwin->swin->yCenter = clp_getDouble(pe_clp, "x.help.bookmark"); hwin->dwin = hwin->swin->win; setup_text(xio, hwin, FALSE); hwin->dbg = butPlain_create(hwin->dwin, 0, BUT_DRAWABLE, BUT_BG); return(hwin); } void xioHelp_resize(XioHelp *hwin) { if (hwin) { assert(MAGIC(hwin)); resize(hwin->win); } } static void setup_text(Xio *xio, XioHelp *hwin, bool destroy) { xio_tb_t *tblist; static int last_menu = -1; int this_menu; int i; assert(MAGIC(hwin)); if (destroy) { last_menu = -1; hwin->n_textbuts = 0; return; } clp_setInt(pe_clp, "x.help.page", this_menu = butMenu_get(hwin->menu)); if (this_menu == last_menu) return; last_menu = this_menu; for (i = 0; i < hwin->n_textbuts; ++i) but_destroy(hwin->textbuts[i]); hwin->n_textbuts = 0; switch(this_menu) { case 0: /* Program help. */ tblist = xioStr_proghelp[xio->lang]; break; case 1: /* Game help. */ tblist = xioStr_gamehelp[xio->lang]; break; case 2: /* Setup help. */ tblist = xioStr_setuphelp[xio->lang]; break; case 3: /* Network play. */ tblist = xioStr_networkhelp[xio->lang]; break; case 4: /* Abouth the computer players. */ tblist = xioStr_comphelp[xio->lang]; break; case 5: /* About the author. */ tblist = xioStr_abouthelp[xio->lang]; break; case 6: /* Copying. */ tblist = xioStr_copyinghelp[xio->lang]; break; default: /* -1; closing down. */ return; } for (i = 0; tblist[i].text != NULL; ++i); hwin->n_textbuts = i; if (hwin->max_textbuts < hwin->n_textbuts) { if (hwin->textbuts != NULL) wms_free(hwin->textbuts); hwin->textbuts = wms_malloc(hwin->n_textbuts * sizeof(But *)); hwin->max_textbuts = hwin->n_textbuts; } for (i = 0; i < hwin->n_textbuts; ++i) { hwin->textbuts[i] = butTblock_create(hwin->dwin, 1, BUT_DRAWABLE, tblist[i].text, tblist[i].align); butTblock_setFont(hwin->textbuts[i], tblist[i].font); } } static ButOut unmap(ButWin *win) { XioHelp *hwin = butWin_packet(win); assert(MAGIC(hwin)); clp_setBool(pe_clp, "x.help", FALSE); xioHelp_storeInfo(hwin); butWin_destroy(win); return(0); } static ButOut resize(ButWin *win) { int w, h, buth; ButEnv *env = butWin_env(win); int bw = butEnv_stdBw(env); XioHelp *hwin = butWin_packet(win); Xio *xio = hwin->xio; int fontsize; assert(MAGIC(hwin)); w = butWin_w(win); h = butWin_h(win); buth = but_h(xio->helpbut); but_resize(hwin->box, 0,0, w,h); but_resize(hwin->menu, bw*2,bw*2, w-bw*4,buth*2); but_resize(hwin->ok, bw*2, h-bw*2-buth, w - bw*4, buth); fontsize = butEnv_fontStr(env, 0)->ascent + butEnv_fontStr(env, 0)->descent; abutSwin_resize(hwin->swin, bw*2, bw*3+buth*2, w-bw*4, h-bw*6-buth*3, buth, fontsize); return(0); } static ButOut dwin_resize(ButWin *win) { AbutSwin *swin; XioHelp *hwin; int w, h, i, cur_h, butbw; assert(MAGIC(win)); swin = butWin_packet(win); assert(MAGIC(swin)); hwin = swin->packet; assert(MAGIC(hwin)); w = butWin_viewW(win); h = butWin_viewH(win); if (w != hwin->lastViewW) { hwin->lastViewW = w; butbw = butEnv_stdBw(butWin_env(win)); cur_h = 0; for (i = 0; i < hwin->n_textbuts; ++i) cur_h += butTblock_resize(hwin->textbuts[i], butbw, cur_h, w-butbw*2); if (cur_h < h) cur_h = h; but_resize(hwin->dbg, 0,0, w,cur_h); butCan_resizeWin(hwin->swin->win, w, cur_h, TRUE); } return(0); } static ButOut ok_pressed(But *but) { XioHelp *hwin = butWin_packet(but_win(but)); assert(MAGIC(hwin)); clp_setBool(pe_clp, "x.help", FALSE); xioHelp_storeInfo(hwin); butWin_destroy(but_win(but)); return(BUTOUT_STOPWAIT); } static ButOut destroy(ButWin *win) { XioHelp *hwin = butWin_packet(win); Xio *xio; assert(MAGIC(hwin)); xio = hwin->xio; setup_text(butEnv_packet(butWin_env(win)), hwin, TRUE); abutSwin_destroy(hwin->swin); --xio->openWindows; xioSound_check(hwin->xio); MAGIC_UNSET(hwin); wms_free(hwin); xio->hwin = NULL; return(0); } void xioHelp_storeInfo(XioHelp *hwin) { static char geom[60]; ButWin *win; if (hwin) { assert(MAGIC(hwin)); win = hwin->win; sprintf(geom, "%dx%d+%d+%d", butWin_w(win), butWin_h(win), butWin_x(win), butWin_y(win)); clp_setStr(pe_clp, "x.help.geom", geom); clp_setDouble(pe_clp, "x.help.bookmark", hwin->swin->yCenter); } } static ButOut change_menu(But *but, int value) { XioHelp *hwin = butWin_packet(but_win(but)); assert(MAGIC(hwin)); if (value != clp_getInt(pe_clp, "x.help.page")) { clp_setDouble(pe_clp, "x.help.bookmark", 0.0); setup_text(butEnv_packet(butWin_env(but_win(but))), hwin, FALSE); abutSwin_resize(hwin->swin, BUT_NOCHANGE,BUT_NOCHANGE, BUT_NOCHANGE,BUT_NOCHANGE, BUT_NOCHANGE, BUT_NOCHANGE); /* Set lastViewW to 0 to force it to resize the canvas. */ hwin->lastViewW = 0; dwin_resize(hwin->dwin); abutSwin_vMove(hwin->swin, 0); } return(0); } #endif /* X11_DISP */ pente-2.2.5/src/xio/strings.c0100664000076400007640000034040307331041405014270 0ustar wmswms/* * $Source: /home/wms/cvs/pente/src/xio/strings.c,v $ * $Revision: 1.3 $ * $Date: 2001/07/29 17:08:21 $ * * src/xio/strings.c, part of Pente (game program) * Copyright (C) 1994-1995 William Shubert. * See "configure.h.in" for more copyright information. */ #include #ifdef X11_DISP #include #include #include #include #include #include #include #include "../pente.h" #include "xio.h" /* Names of the languages...in each language! */ const char *xioStr_langlist[XIO_LANG_COUNT][XIO_LANG_COUNT+1] = { {"English", "French", "Italian", BUTMENU_OLEND}, {"Anglais", "Français", "Italian", BUTMENU_OLEND}, {"Inglese", "Francese", "Italiano", BUTMENU_OLEND}}; /* * Fonts to use in each language. * If more than one will do, put the first choice with a "/" then the next, * then the next, etc. */ char *xioStr_mfonts[] = { "-bitstream-charter-medium-r-normal--%d-*-*-*-*-*-*-*", "-bitstream-charter-medium-r-normal--%d-*-*-*-*-*-*-*", "-bitstream-charter-medium-r-normal--%d-*-*-*-*-*-*-*"}; char *xioStr_bfonts[] = { "-bitstream-charter-black-r-normal--%d-*-*-*-*-*-*-*/" "-bitstream-charter-bold-r-normal--%d-*-*-*-*-*-*-*", "-bitstream-charter-black-r-normal--%d-*-*-*-*-*-*-*/" "-bitstream-charter-bold-r-normal--%d-*-*-*-*-*-*-*", "-bitstream-charter-black-r-normal--%d-*-*-*-*-*-*-*/" "-bitstream-charter-bold-r-normal--%d-*-*-*-*-*-*-*"}; /* Buttons in the setup window. */ char *xioStr_pentesetup[] = {"Pente Setup", "Configuration de Pente", "Configurazione di Pente"}; char *xioStr_language[] = {"Language", "Langue", "Lingua"}; char *xioStr_color[] = {"Color", "Couleur", "Colore"}; char *xioStr_showThink[] = {"Show thinking", XIO_COMPCHAR " visible", XIO_COMPCHAR " visibile"}; char *xioStr_soundvol[] = {"Sound Volume", "Volume Sonore", "Volume del suono"}; char *xioStr_off[] = {"Off", "Aucun", "Spento"}; char *xioStr_max[] = {"Max", "Max", "Massimo"}; char *xioStr_transtab[] = {"Transposition Table", "Table de Transposition", "Tabella di trasposizione"}; char *xioStr_size[] = {"Size:", "Taille:", "Dimensione:"}; char *xioStr_autosize[] = {"Autosize", "Taille Automatique", "Automatica"}; char *xioStr_netplay[] = {"Network Play", "Jeu en Réseau", "Gioco in rete"}; char *xioStr_enabled[] = {"Enabled", "Activé", "Abilitato"}; char *xioStr_socket[] = {"Port:", "Port:", "Porta:"}; char *xioStr_disabled[] = {"Disabled", "Désactivé", "Disattivato"}; char *xioStr_connect[] = {"Connect", "Connexion", "Connetti"}; char *xioStr_disconnect[] = {"Disconnect", "Déconnexion", "Disconnetti"}; char *xioStr_noSockets[] = { "Sorry, this program was compiled on a system that doesn't support " "sockets. You cannot play networked.", "Désolé, ce programme a été compilé sur un système ne " "gérant pas les sockets. Vous ne pouvez pas jouer en réseau.", "Spiacente, il programma è stato compilato su un sistema che non " "supporta i socket. Non puoi giocare in rete."}; /* Labels on the board. */ char *xioStr_turn[] = {"Turn", "Tour", "Turno"}; char *xioStr_captures[] = {"CAPTURES", "CAPTURES", "CATTURATE"}; char *xioStr_copyright[] = {"Copyright \251 1994-1995 William Shubert.", "Copyright \251 1994-1995 William Shubert.", "Copyright \251 1994-1995 William Shubert."}; char *xioStr_nowarr[] = {"Pente comes with ABSOLUTELY NO WARRANTY and " "is free software.", "Pente est fourni sans AUCUNE GARANTIE et " "est un logiciel libre", "Pente è fornito senza ALCUNA GARANZIA ed " "è un programma libero."}; char *xioStr_seehelp[] = {"Please see the \"Copying and Non-Warranty\" help " "page for details.", "Veuillez consulter la page d'aide \"" "Copie et Non-Garantie\" pour plus de détails.", "Si prega di consultare la pagina di aiuto \"" "Copia e Non-Garanzia\" per maggiori dettagli."}; /* Button labels. */ char *xioStr_undo[] = {"Undo", "Défaire", "Indietro"}; char *xioStr_start[] = {"Start", "Débuter", "Inizia"}; char *xioStr_stop[] = {"Stop", "Arrêter", "Ferma"}; char *xioStr_continue[] = {"Continue", "Continuer", "Continua"}; char *xioStr_redo[] = {"Redo", "Refaire", "Ripeti"}; char *xioStr_setup[] = {"Setup", "Config.", "Configura"}; char *xioStr_help[] = {"Help", "Aide", "Aiuto"}; char *xioStr_quit[] = {"Quit", "Quitter", "Esci"}; char *xioStr_ok[] = {"OK", "OK", "OK"}; char *xioStr_cancel[] = {"Cancel", "Annuler", "Annulla"}; char *xioStr_netConn[] = {"Network Connect", "Connexion Réseau", "Connessione in rete"}; char *xioStr_machine[] = {"Machine:", "Machine:", "Macchina:"}; char *xioStr_reject[] = {"Reject", "Rejet", "Rifiuta"}; char *xioStr_noRemote[] = {"Sorry, Pente " VERSION " doesn't have " "networking yet. Please wait for a later " "version to arrive!", "Désolé, Pente " VERSION " n'a pas encore " "la fonctionnalité réseau. Veuillez " "attendre une prochaine version!", "Spiacente, Pente " VERSION " non ha ancora " "la funzionalità di rete. Si prega di " "attendere una versione successiva!"}; /* Menu entries. */ char *xioStr_player1[] = {"Player 1", "Joueur 1", "Giocatore 1"}; char *xioStr_player2[] = {"Player 2", "Joueur 2", "Giocatore 2"}; char *xioStr_human[] = {"Human", "Humain", "Umano"}; char *xioStr_remote[] = {"Remote", "Distant", "Remoto"}; char *xioStr_comp1[] = {XIO_COMPCHAR " Simple", XIO_COMPCHAR " Simple", XIO_COMPCHAR " Semplice"}; char *xioStr_comp2[] = {XIO_COMPCHAR " Easy", XIO_COMPCHAR " Facile", XIO_COMPCHAR " Facile"}; char *xioStr_comp3[] = {XIO_COMPCHAR " Med", XIO_COMPCHAR " Moyen", XIO_COMPCHAR " Medio"}; char *xioStr_comp4[] = {XIO_COMPCHAR " Hard", XIO_COMPCHAR " Difficile", XIO_COMPCHAR " Difficile"}; char *xioStr_comp5[] = {XIO_COMPCHAR " Expert", XIO_COMPCHAR " Expert", XIO_COMPCHAR " Esperto"}; char *xioStr_comp6[] = {XIO_COMPCHAR " Master", XIO_COMPCHAR " Maître", XIO_COMPCHAR " Maestro"}; /* Messages for message windows. */ char *xioStr_notEnoughColors[] = {"Pente couldn't allocate enough colors. " "It will still run, but in black and " "white.", "Pas assez de couleurs.", "Pente non è riuscito ad allocare " "abbastanza colori. Funzionerà " "ugualmente, ma in bianco e nero."}; /* Messages to be used for network play. */ char *xioStr_netOffer[] = {"Player \"%s\" wants to play pente against " "you. Accept?", "Le joueur \"%s\" souhaite " "jouer à pente contre vous. Acceptez-vous ?", "Il giocatore \"%s\" vuole giocare a pente " "contro di te. Accetti?"}; char *xioStr_netReject[] = {"Player \"%s\" rejected your offer to play " "pente.", "Le joueur \"%s\" a rejeté votre " "offre de jouer à pente.", "Il giocatore \"%s\" ha rifiutato il vostro " "invito di giocare a pente."}; char *xioStr_netWait[] = {"Waiting for connection to be accepted. Press " "\"Cancel\" to give up.", "En attente de la validation de la connexion." " Appuyer sur \"Annuler\" pour abandonner.", "In attesa che la connessione sia accettata." " Premere \"Annulla\" per abbandonare."}; char *xioStr_netDisconnect[] = {"Your connection with \"%s\" has been " "disconnected because of \"%s\".", "La connexion avec \"%s\" a été " "interrompue à cause de \"%s\".", "La connessione con \"%s\" è stata " "interrotta da \"%s\"."}; char *xioStr_netBusy[] = {"Sorry, player \"%s\" is already playing a " "networked game of pente.", "Désolé, le joueur \"%s\" est déjà en train de " "jouer une partie de pente en réseau.", "Spiacente, il giocatore \"%s\" sta già " "giocando a pente in rete."}; char *xioStr_netClosed[] = {"Your opponent has closed your network " "connection.", "Votre adversaire a fermé la connexion.", "Il vostro avversario ha terminato " "la connessione."}; /* Error messages! */ char *xioStr_errProtSocket[] = {"You can't use local port %s. Ports up " "to %d are reserved for superuser access " "only.", "Vous ne pouvez pas utiliser le port %s. " "Les ports jusqu'à %d sont réservés à " "l'accès pour le super utilisateur " "uniquement.", "Non potete utilizzare la porta %s. " "Le porte fino a %d sono riservate " "al super utente."}; char *xioStr_errSockInUse[] = {"Port %s is already in use on this " "machine. If you want to play networked, " "you will have to choose a different " "port number.", "Le port %s est déjà " "utilisé sur cette machine. Si vous " "souhaitez jouer en réseau, vous devez " "choisir un numéro de port différent.", "La porta %s è già in uso su questa " "macchina. Se volete giocare in rete, " "dovete scegliere un numero di porta " "diverso."}; char *xioStr_errLSockGeneric[] = {"Error opening local port %s: \"%s\".", "Erreur d'ouverture du port local %s: " " \"%s\".", "Errore durante l'apertura della " "porta locale %s: \"%s\"."}; char *xioStr_errSockNumInvalid[] = { "\"%s\" is not a valid port. Ports are integers in the " "range from 1 through %d. The default Pente port is 15023; " "you should use that unless port 15023 is already in use.", "\"%s\" n'est pas un port valide. Les ports valides sont les " "entiers qui vont " "de 1 à %d. Le port de Pente par défaut " "est 15023; c'est celui que vous devriez utiliser à moins que " "le port 15023 soit déjà utilisé.", "\"%s\" non è una porta valida. Le porte valide sono gli interi " "nell'intervallo che va da 1 a %d. La porta standard di Pente " "è 15023; dovreste usare quella a meno che non sia già in uso."}; char *xioStr_errRSockGeneric[] = {"Error \"%s\" occurred while opening " "port %s on machine \"%s\".", "L'erreur \"%s\" est survenue lors de " "l'ouverture du port %s sur la " "machine \"%s\".", "L'errore \"%s\" si è verificato " "durante l'apertura della porta %s " "sulla macchina \"%s\"."}; char *xioStr_errRSockRefused[] = {"Your connection to machine \"%s\" port " "%s was refused. Probably there is no " "Pente running that is set up to " "listen on that port.", "La connexion à la machine \"%s\" sur " "le port %s a été refusée. Il n'y a " "probablement aucun Pente de " "configuré pour écouter sur ce port.", "La vostra connessione alla macchina " "\"%s\" è stata rifiutata. Probabilmente " "non c'è nessun Pente configurato per " "ascoltare su quella porta."}; char *xioStr_errHostTemp[] = {"Machine \"%s\" couldn't be found. This may " "be a temporary situation; you may want to " "try again later.", "La machine \"%s\" n'a pas pu être " "localisée. Il se peut que ce soit un " "problème temporaire; vous " "pouvez réessayer plus tard.", "La macchina \"%s\" non è stata trovata. " "Potrebbe trattarsi di un problema temporaneo; " "si prega di riprovare più tardi."}; char *xioStr_errHostPerm[] = {"Machine \"%s\" couldn't be found.", "Impossible de localiser la machine \"%s\".", "La macchina \"%s\" non è stata trovata."}; /* Help */ char *xioStr_hmenu[] = {"Help topics", "Sujets D'aide", "Argomenti Della Guida"}; char *xioStr_phelp[] = {"Program Help", "Aide Du Programme", "Aiuto Del Programma"}; char *xioStr_ghelp[] = {"How To Play Pente", "Comment Jouer A Pente", "Come Giocare A Pente"}; char *xioStr_shelp[] = {"The Setup Window", "La Fenêtre De Configuration", "La Finestra Di Configurazione"}; char *xioStr_nhelp[] = {"Network Play", "Jeu En Réseau", "Gioco In Rete"}; char *xioStr_cphelp[] = {"About The Computer Players", "A Propos Des " "Joueurs Gérés Par L'ordinateur", "I Giocatori Controllati Dalla Macchina"}; char *xioStr_ahelp[] = {"About the Author", "A Propos De L'auteur", "Informazioni Sull'Autore"}; char *xioStr_chelp[] = {"Copying and Non-Warranty", "Copie Et Non-Garantie", "Copia E Non-Garanzia"}; /* Help on using the program. */ static xio_tb_t proghelp_eng[] = { {butText_center, 1, "Pente " VERSION}, {butText_center, 0, "By Bill Shubert"}, {butText_center, 0, DATE}, {butText_just, 0, ""}, {butText_just, 1, "Help on the program Pente"}, {butText_just, 0, " This help page explains how to use the features of " "Pente version " VERSION ". At the top of this help window is a menu; " "click on it and drag with the mouse to pop up a list of other help " "pages available."}, {butText_just, 0, ""}, {butText_just, 0, " To scroll the text in this help window, you may " "either use the slider bar to the left or right-click and drag on the " "text itself."}, {butText_just, 0, ""}, {butText_just, 0, " The main window of Pente shows the pente board with " "some controls at the bottom. The board itself looks like a regular " "pente board and should be mostly self-explanatory. Simply click on an " "intersection to place a piece there. To either side of " "the pente board are pits where captured pieces are kept. Below the " "board are eight controls. These are the player 1 selector, the player " "2 selector, the undo button, the redo button, the start/stop button, " "the setup button, the help button, and the quit button."}, {butText_just, 0, ""}, {butText_just, 0, " The player 1 and player 2 selectors are menus " "found on the far left and far right of the controls. " "When the menu is opened by pressing the left mouse button, there are " "several choices. The first choice, " "\"Human\", lets you play that player. For example, if both selectors " "are set to \"Human\", then two people can use the same computer to " "play pente against each other."}, {butText_just, 0, " The next selection in a player selector is " "\"Remote\". If your Pente program is configured correctly, then this " "option can be used to play pente against somebody on another computer. " "See the networking help page for more information on this."}, {butText_just, 0, " The bottom six options in the player selectors are " "the computer opponents, represented by a " XIO_COMPCHAR " icon and the " "difficulty of that opponent. Selecting one of these players makes the " "computer play for that player. For example, setting the player 1 " "selector to \"Human\" and the player 2 selector to \"" XIO_COMPCHAR " Simple\" will let you play as player 1, and make the computer play " "for player 2. This particular computer opponent is very easy to beat. " "The computer players are listed from easiest to beat to hardest to " "beat in the player selector."}, {butText_just, 0, ""}, {butText_just, 0, " In the upper center of the controls is the start/" "stop button. This button will start a new game when no game is " "being played, or stop a game in progress. The label on the button " "will change to reflect it's action."}, {butText_just, 0, " Sometimes the game will be paused (for example, if " "you change players in the middle of a game). When this happens the " "label on the start/stop button will change to \"Continue\". Pressing " "the button then will resume the game."}, {butText_just, 0, ""}, {butText_just, 0, " To either side of the start/stop button are the " "undo and redo buttons. Pressing undo will take back moves, one at a " "time. Pressing redo will replay moves, one at a time. Using these " "buttons you can review a game to see what moves led to the current " "position."}, {butText_just, 0, " Undo can also be used to take back a move. If you " "press undo until the move you want to take back is gone, then move " "somewhere else, the game will continue from there."}, {butText_just, 0, ""}, {butText_just, 0, " The help button is in the bottom center of the " "controls. Since you're reading this, you must already know how to " "use this button."}, {butText_just, 0, ""}, {butText_just, 0, " The setup button, to the left of the help button, " "lets you change the configuration of Pente. See the setup window " "help page for more information."}, {butText_just, 0, ""}, {butText_just, 0, " The quit button, which is to the right of the help " "button, exits Pente immediately."}, {butText_just, 0, ""}, {butText_just, 0, " There are some keyboard accelerators available as " "well. Pressing \"Enter\" or \"Return\" is the same as pressing the " "\"OK\" button in a window. Pressing \"H\" or \"Help\" is the same as " "pressing the \"Help\" button. Pressing \"Q\" in the main window will " "quit the program. Pressing \"S\" will toggle sound on and off. " "The left and right arrow keys will undo and redo moves."}, {butText_just, 0, " If you press \"Q\" by accident and lose your game, " "don't worry! Just restart Pente and your game will still be there, " "exactly where you left off."}, {butText_just, 0, ""}, {butText_center, 0, XIO_PL1CHAR XIO_PL2CHAR XIO_PL1MARKCHAR XIO_PL2CHAR XIO_PL1CHAR}, {butText_just, 0, ""}, {0,0,NULL}}; static xio_tb_t proghelp_french[] = { {butText_center, 1, "Pente " VERSION}, {butText_center, 0, "Par Bill Shubert"}, {butText_center, 0, DATE_FRENCH}, {butText_just, 0, ""}, {butText_just, 1, "Aide du programme Pente"}, {butText_just, 0, " Cette page d'aide explique comment utiliser les " "caractéristiques de Pente version " VERSION ". En haut de cette fenêtre " "d'aide se trouve un menu; cliquer dessus et tirer avec la " "souris pour accéder à une liste des pages d'aide disponibles."}, {butText_just, 0, ""}, {butText_just, 0, " Pour faire défiler le texte dans cette fenêtre " "d'aide, vous pouvez soit utiliser la barre de défilement à gauche, " "soit cliquer avec le bouton droit et tirer le texte lui-même."}, {butText_just, 0, ""}, {butText_just, 0, " La fenêtre principale de Pente montre le plateau " "de jeu de pente comportant quelques boutons de contrôle en bas. " "Le plateau de jeu lui-même ressemble à un plateau de jeu de " "pente habituel et devrait être suffisamment explicite. " "Il suffit de cliquer sur une " "intersection pour mettre un jeton à cet endroit. On trouve de chaque " "côté du plateau du jeu de pente des renfoncements où les jetons " "capturés sont conservés. On trouve sous le plateau de jeu huit " "boutons de contrôle. Il s'agit du sélectionneur du joueur 1, du " "sélectionneur du joueur 2, du bouton pour défaire un coup, du " "bouton pour refaire un coup, du bouton de début/arrêt de " "partie, du bouton de configuration, " "du bouton d'aide et du bouton pour quitter."}, {butText_just, 0, ""}, {butText_just, 0, " Les sélectionneurs du joueur 1 et du joueur 2 sont " "des menus qui se trouvent à l'extrême gauche et à l'extrême droite " "des boutons de contrôle. Une fois le menu ouvert en appuyant sur " "le bouton gauche de la souris, on a accès à plusieurs choix. " "Le premier choix \"Humain\", vous " "permet d'utiliser ce joueur. Par exemple, lorsque " "les deux sélectionneurs " "sont positionnés sur \"Humain\", deux personnes peuvent utiliser le " "même ordinateur pour jouer l'un contre l'autre."}, {butText_just, 0, " Le choix suivant du sélectionneur de joueur est " "\"Distant\". Si le programme Pente est configuré correctement cette " "option peut être utilisée pour jouer à pente contre quelqu'un sur " "un autre ordinateur. Consultez la page d'aide concernant le réseau pour " "obtenir de plus amples information."}, {butText_just, 0, " Les six dernières options du sélectionneur de joueur " "sont les adversaires gérés par l'ordinateur, elles sont représentées " "par une icône " XIO_COMPCHAR " suivi de la difficulté de cet " "adversaire. La sélection d'un de ces joueurs permet de jouer contre " "ce joueur géré par l'ordinateur. Par exemple, si on positionne le " "sélectionneur du joueur 1 à \"Humain\" et le sélectionneur du joueur 2 à " "\"" XIO_COMPCHAR " Simple\", on jouera alors en tant que joueur 1, et " "l'ordinateur gérera le joueur 2. Cet adversaire là est très facile à " "battre. Les joueurs gérés par l'ordinateur sont affichés dans l'ordre " "croissant de difficulté dans le sélectionneur de joueur."}, {butText_just, 0, ""}, {butText_just, 0, " Le bouton de début/arrêt se trouve en haut et au " "milieu des boutons de contrôle. Ce bouton permet débuter une nouvelle " "partie lorsqu'aucune partie n'est en cours, ou d'arrêter un jeu en " "cours. Le nom de ce bouton change suivant le contexte."}, {butText_just, 0, " Parfois le jeu est en pause (par exemple, si vous " "changez les joueurs en plein milieu d'une partie). Dans ce cas, le nom " "du bouton de début/arrêt se change en \"Continuer\". L'appui sur ce " "bouton permet alors de reprendre la partie."}, {butText_just, 0, ""}, {butText_just, 0, " Les boutons défaire et refaire se trouvent des deux " "côtés du bouton de début/arrêt. L'appui sur défaire permet de " "revenir en arrière, d'un coup à la fois. L'appui sur refaire permet " "de rejouer les coups, un à la fois. En utilisant ces boutons " "vous pouvez compulser une partie afin de voir quels coups ont " "conduit à la position actuelle."}, {butText_just, 0, " Défaire peut également être utilisé pour revenir " "en arrière. Si vous appuyez sur Défaire jusqu'à ce que le coup " "que vous souhaitez enlever ne soit plus là, puis si vous bougez " "le curseur autre part, alors la partie continuera depuis cette " "position."}, {butText_just, 0, ""}, {butText_just, 0, " Le bouton d'aide se trouve au milieu et en bas " "des boutons de contrôle. Puisque vous êtes en train de lire ceci, vous " "devez déjà savoir comment utiliser ce bouton."}, {butText_just, 0, ""}, {butText_just, 0, " Le bouton de configuration, à gauche du bouton " "d'aide, permet de modifier la configuration de Pente. Consultez " "la page d'aide de la fenêtre de configuration pour obtenir de " "plus amples renseignements."}, {butText_just, 0, ""}, {butText_just, 0, " Le bouton pour quitter, qui se trouve à droite " "du bouton d'aide, permet de sortir de Pente immédiatement."}, {butText_just, 0, ""}, {butText_just, 0, " Il existe aussi quelques raccourcis clavier. " "L'appui sur \"Entrée\" ou \"Retour Chariot\" revient au même qu'un " "appui sur le bouton \"OK\" d'une fenêtre. L'appui sur \"H\" ou " "\"Aide\" revient au même qu'un appui sur le bouton \"Aide\". " "L'appui sur \"Q\" dans la fenêtre principale permet de sortir du " "programme. L'appui sur \"S\" permet de mettre ou d'enlever le son. " "Les touches de flèches gauche et droite permettent de défaire ou " "refaire les coups."}, {butText_just, 0, " Si vous appuyez sur \"Q\" par mégarde et perdez " "votre partie, pas de panique! Il suffit de relancer Pente et votre " "partie sera toujours là, exactement où vous en étiez."}, {butText_just, 0, ""}, {butText_center, 0, XIO_PL1CHAR XIO_PL2CHAR XIO_PL1MARKCHAR XIO_PL2CHAR XIO_PL1CHAR}, {butText_just, 0, ""}, {0,0,NULL}}; static xio_tb_t proghelp_italian[] = { {butText_center, 1, "Pente " VERSION}, {butText_center, 0, "di Bill Shubert"}, {butText_center, 0, DATE_ITALIAN}, {butText_just, 0, ""}, {butText_just, 1, "Aiuto del programma Pente"}, {butText_just, 0, " Questa pagina di aiuto spiega come usare le opzioni di " "Pente versione " VERSION ". In cima a questa finestra di aiuto c'è un menu; " "cliccatelo e trascinate il mouse per ottenere la lista delle altre pagine " "di aiuto disponibili."}, {butText_just, 0, ""}, {butText_just, 0, " Per scorrere il testo in questa finestra di aiuto, " "potete usare la barra di scorrimento sul lato sinistro o cliccare il " "testo stesso con il tasto destro del mouse per trascinarlo."}, {butText_just, 0, ""}, {butText_just, 0, " La finestra principale di Pente mostra una griglia di " "pente con alcuni comandi in fondo. La griglia ha l'aspetto di una comune " "griglia di pente e dovrebbe essere autoesplicativa. Basta cliccare su " "un'intersezione per metterci una pedina. Su ciascun lato della griglia di " "pente ci sono le buche nelle quali vengono messe le pedine catturate. " "Sotto la griglia ci sono otto comandi. Questi sono il selettore per il " "giocatore 1, il selettore per il giocatore 2, il pulsante Indietro, " "il pulsante Ripeti, il pulsante Inizia/Ferma, il pulsante Configura, " "il pulsante Aiuto e il pulsante Esci."}, {butText_just, 0, ""}, {butText_just, 0, " I selettori per il giocatore 1 e il giocatore 2 sono i " "menu che si trovano all'estrema sinistra e all'estrema destra dei comandi. " "Quando il menu viene aperto premendo il tasto sinistro del mouse, si hanno " "varie scelte. La prima scelta, " "\"Umano\", vi consente di usare quel giocatore. Per esempio, se entrambe " "i selettori sono impostati a \"Umano\", due persone possono usare lo " "stesso computer per giocare a pente una contro l'altra."}, {butText_just, 0, " La scelta successiva in un selettore di giocatore è " "\"Remoto\". Se il vostro programma di Pente è configurato correttamente, " "questa opzione può essere usata per giocare a pente contro qualcuno su " "un altro computer. " "Fate riferimento alla pagina di aiuto sul gioco in rete per maggiori " "informazioni su questo."}, {butText_just, 0, " Le ultime sei opzioni nei selettori dei giocatori " "sono gli avversari gestiti dal computer, rappresentati da una icona " XIO_COMPCHAR " e la difficoltà per quel giocatore. Selezionando uno " "di quei giocatori il computer muove per esso. Per esempio, impostando " "il selettore del giocatore 1 a \"Umano\" e il selettore del giocatore 2 " "a \"" XIO_COMPCHAR " Semplice\" giocherete come giocatore 1 e il " "computer muoverà per il giocatore 2. Questo specifico giocatore del " "computer è molto facile da battere. " "I giocatori controllati dal computer sono elencati dal più facile al " "più difficile da battere nel selettore del giocatore."}, {butText_just, 0, ""}, {butText_just, 0, " Nella parte superiore centrale dei comandi si trova il " "pulsante inizia/ferma. Questo pulsante fa iniziare una nuova partita " "se nessuna è in corso o ferma quella corrente. L'etichetta del " "pulsante cambia per riflettere la sua funzione."}, {butText_just, 0, " Qualche volta il gioco verrà temporaneamente sospeso " "(per esempio, se cambiate i giocatori nel corso di una partita). Quando " "questo accade, l'etichetta del pulsante inizia/ferma diventerà \"Continua\". " " Premendo il pulsante il gioco riprenderà."}, {butText_just, 0, ""}, {butText_just, 0, " Su ciascun lato del pulsante inizia/ferma si trovano " "i pulsanti indietro e ripeti. Premendo indietro si potranno " "annullare le proprie mosse, una alla volta. Premendo ripeti le mosse " "verranno effettuate nuovamente, una alla volta. Usando questi pulsanti " "potete rivedere una partita per capire quali mosse hanno portato alla " "situazione corrente."}, {butText_just, 0, " indietro può anche essere usato per correggere " "una mossa. Se premete indietro fino a cancellare la mossa che vi " "interessa poi ne fate una diversa, il gioco continuerà da li."}, {butText_just, 0, ""}, {butText_just, 0, " Il pulsante aiuto è nella parte inferiore centrale " "dei comandi. Dal momento che state leggendo questo, dovete già sapere " "come usare questo pulsante."}, {butText_just, 0, ""}, {butText_just, 0, " Il pulsante Configura, a sinistra del pulsante " "aiuto, vi consente di cambiare la configurazione di Pente. Fate riferimento " "alla pagina di aiuto sulla configurazione per maggiori informazione."}, {butText_just, 0, ""}, {butText_just, 0, " Il pulsante esci, che si trova a destra del pulsante " "aiuto, esce da Pente immediatamente."}, {butText_just, 0, ""}, {butText_just, 0, " Ci sono diversi tasti di scelta rapida disponibili. " "Premendo \"Invio\" o \"Return\" equivale a premere il pulsante \"OK\" " "in una finestra. Premere \"H\" è come premere il pulsante \"aiuto\". " "Premendo \"Q\" nella finestra principale si esce dal programma. " "Premendo \"S\" si attiva/disattiva il sonoro. " "I tasti freccia sinistra e destra si comportano come i pulsanti " "indietro e ripeti."}, {butText_just, 0, " Se premete \"Q\" per sbaglio e uscite dal gioco, " "non preoccupatevi! Basta rilanciare Pente e la vostra partita sarà " "ancora li, esattamente dove l'avevate lasciata."}, {butText_just, 0, ""}, {butText_center, 0, XIO_PL1CHAR XIO_PL2CHAR XIO_PL1MARKCHAR XIO_PL2CHAR XIO_PL1CHAR}, {butText_just, 0, ""}, {0,0,NULL}}; static xio_tb_t gamehelp_eng[] = { {butText_center, 1, "Pente " VERSION}, {butText_center, 0, "By Bill Shubert"}, {butText_center, 0, DATE}, {butText_just, 0, ""}, {butText_just, 1, "How to play Pente"}, {butText_just, 0, " Pente is the English name of the Asian game of " "ni-nuki, which is itself a version of the game of go-moku. Pente " "is played on a 19x19 grid with stones in two different colors. " "Each player chooses one set of stones; then the players take turns " "placing their stones on any unoccupied intersection until one player " "wins."}, {butText_just, 0, " There are two ways to win. If a player makes five " "or more stones in a straight line (across, down, or diagonally), then " "that player wins. Or, if a player captures five pairs of his or her " "opponent's stones, that player also wins."}, {butText_just, 0, " Stones may be captured in pairs only. To capture " "a pair of stones, a player must place one stone on either side of the " "pair. For example:"}, {butText_center, 0, XIO_PL1CHAR XIO_PL2CHAR XIO_PL2CHAR}, {butText_just, 0, " If another " XIO_PL1CHAR " stone is placed on the " "right side of this group, the two center stones will be captured. " "This will count as one capture."}, {butText_just, 0, " That's it!"}, {butText_just, 0, ""}, {butText_center, 0, XIO_PL1CHAR XIO_PL2CHAR XIO_PL1MARKCHAR XIO_PL2CHAR XIO_PL1CHAR}, {butText_just, 0, ""}, {0,0,NULL}}; static xio_tb_t gamehelp_french[] = { {butText_center, 1, "Pente " VERSION}, {butText_center, 0, "Par Bill Shubert"}, {butText_center, 0, DATE_FRENCH}, {butText_just, 0, ""}, {butText_just, 1, "Comment jouer à Pente"}, {butText_just, 0, " Pente est le nom Anglais du jeu asiatique " "ni-nuki, qui est lui-même une version du jeu go-moku. " " Pente se joue sur une grille de 19x19 cases en utilisant des " "pierres de deux couleurs différentes. Chaque joueur choisit un " "ensemble de pierres; puis les joueurs placent à tour de rôle leurs " "pierres sur les intersections innocupées jusqu'à " "ce qu'un des joueurs gagne."}, {butText_just, 0, " Il y a deux façons de gagner. Un joueur peut " "gagner s'il aligne (verticalement, horizontalement ou en diagonale) " "consécutivement cinq pierres ou plus. Un joueur peut aussi gagner en " "capturant cinq paires de pierres de son adversaire."}, {butText_just, 0, " Les pierres peuvent être uniquement capturées par " "paires. Pour capturer une paire de pierres, un joueur doit placer une " "pierre de part et d'autre de la paire. Par exemple:"}, {butText_center, 0, XIO_PL1CHAR XIO_PL2CHAR XIO_PL2CHAR}, {butText_just, 0, " Si une autre " XIO_PL1CHAR " pierre est placée " "sur le côté droit de ce groupe, les deux pierres centrales seront " "capturées. Cela comptera alors pour une capture."}, {butText_just, 0, " Et c'est tout!"}, {butText_just, 0, ""}, {butText_center, 0, XIO_PL1CHAR XIO_PL2CHAR XIO_PL1MARKCHAR XIO_PL2CHAR XIO_PL1CHAR}, {butText_just, 0, ""}, {0,0,NULL}}; static xio_tb_t gamehelp_italian[] = { {butText_center, 1, "Pente " VERSION}, {butText_center, 0, "di Bill Shubert"}, {butText_center, 0, DATE_ITALIAN}, {butText_just, 0, ""}, {butText_just, 1, "Come giocare a Pente"}, {butText_just, 0, " Pente è il nome Inglese del gioco Asiatico " "ni-nuki, che è esso stesso una versione del gioco go-moku. Pente " "è giocato su una griglia 19x19 con pedine di due colori diversi. " "Ogni giocatore sceglie un set di pedine; i giocatori a turno " "mettono le loro pedine sugli incroci liberi fino a quando uno " "dei due vince."}, {butText_just, 0, " Ci sono due modi in cui si vince. Se un giocatore " "mette cinque o più pedine in linea retta (orizzontale, verticale o " "diagonale), vince. Oppure si può vincere anche catturando cinque " "coppie di pedine del proprio avversario."}, {butText_just, 0, " Le pedine possono essere catturate solo a coppie. " "Per catturare una coppia di pedine, un giocatore deve mettere una pedina " "su ciascuna lato della coppia. Per esempio:"}, {butText_center, 0, XIO_PL1CHAR XIO_PL2CHAR XIO_PL2CHAR}, {butText_just, 0, " Se un'altra pedina " XIO_PL1CHAR " viene messa a " "destra di questo gruppo, le due pedine centrali verranno catturate. " "Questo conta come una presa."}, {butText_just, 0, " Tutto qua!"}, {butText_just, 0, ""}, {butText_center, 0, XIO_PL1CHAR XIO_PL2CHAR XIO_PL1MARKCHAR XIO_PL2CHAR XIO_PL1CHAR}, {butText_just, 0, ""}, {0,0,NULL}}; static xio_tb_t setuphelp_eng[] = { {butText_center, 1, "Pente " VERSION}, {butText_center, 0, "By Bill Shubert"}, {butText_center, 0, DATE}, {butText_just, 0, ""}, {butText_just, 1, "Help on the setup window"}, {butText_just, 0, " This help page explains the features of the setup " "window in Pente. To see the setup window, press the \"setup\" button " "on the main window."}, {butText_just, 0, " There are four subsections of the setup window. " "These are the options section, the sound section, the " "transposition table section, and the networking section."}, {butText_just, 0, ""}, {butText_just, 0, " The options section, in the upper left portion of " "the setup window, has three controls. There is a \"Language\" menu " "that selects which language text messages should appear in. Currently " "the only languages supported are English, French and Italian. If you " "know another language and are willing to do the translations, by all " "means get in touch with me! I'd like to translate this program into " "as many languages as possible."}, {butText_just, 0, " In the options section there is also a checkbox " "for color. If you have a color screen, pressing this checkbox will " "switch between using color and black and white."}, {butText_just, 0, " The last control in the options section is the " "\"Show thinking\" check box. If this is checked, you can see the " "moves that the computer is thinking about when it is playing at " "the \"Expert\" and \"Master\" levels. If this is not checked, you " "cannot see the moves that the computer is considering."}, {butText_just, 0, ""}, {butText_just, 0, " The sound section is in the lower left of the " "setup window. It contains one control: a slider which sets the sound " "volume. If you have sound, sliding this control will set how loud the " "sound effects should be. Sliding all the way to zero will turn off " "all sound."}, {butText_just, 0, ""}, {butText_just, 0, " The transposition table section is in the upper " "right of the setup window. This is currently disabled."}, {butText_just, 0, ""}, {butText_just, 0, ""}, {butText_just, 0, " At the bottom of the setup window are two buttons, " "labeled \"OK\" and \"Help\". Pressing \"OK\" closes the setup window " "and pressing \"Help\" opens this help page."}, {butText_just, 0, ""}, {butText_center, 0, XIO_PL1CHAR XIO_PL2CHAR XIO_PL1MARKCHAR XIO_PL2CHAR XIO_PL1CHAR}, {butText_just, 0, ""}, {0,0,NULL}}; static xio_tb_t setuphelp_french[] = { {butText_center, 1, "Pente " VERSION}, {butText_center, 0, "Par Bill Shubert"}, {butText_center, 0, DATE_FRENCH}, {butText_just, 0, ""}, {butText_just, 1, "Aide sur la fenêtre de configuration"}, {butText_just, 0, " Cette page d'aide explique les différentes options " "de la fenêtre de configuration de Pente. Pour accèder à la fenêtre " "de configuration, appuyez sur le bouton \"Config.\" de la fenêtre " "principale."}, {butText_just, 0, " Il y a quatre parties dans la fenêtre de " "configuration. On y trouve la partie des options, la partie " "son, la partie de la table de transposition et la partie " "réseau."}, {butText_just, 0, ""}, {butText_just, 0, " La partie des options, en haut et à gauche de la " "fenêtre de configuration, contient trois options de contrôle. On trouve " "le menu \"Langue\" qui permet de choisir dans quelle langue " "les messages s'affichent. Pour l'instant, les seules langues " "disponibles sont l'Anglais et le Français. Si vous connaissez une " "autre langue et si vous avez envie de réaliser la traduction, alors " "surtout contactez moi! J'aimerais traduire mon programme dans " "autant de langues que possible."}, {butText_just, 0, " Dans la partie des options, il y a également une " "boîte à cocher pour la couleur. Si vous avez un moniteur couleur, lors " "de l'appui sur la boîte à cocher vous pouvez basculer entre la couleur " "et le noir et blanc."}, {butText_just, 0, " Le dernier bouton do contrôle de la partie des " "options est la boîte á cocher \"" XIO_COMPCHAR " visible\". " "Si elle est cochée, vous pouvez visualiser les déplacements " "auxquels l'ordinateur réfléchit lorsqu'il joue aux niveaux " "\"Expert\" et \"Maître\". Si elle n'est pas cochée, vous ne " "pouvez pas voir les déplacements que l'ordinateur est en train de " "considérer."}, {butText_just, 0, ""}, {butText_just, 0, " La partie son se trouve en bas et à gauche " "de la fenêtre de configuration. On y trouve une seule option de " "contrôle: une barre de défilement qui permet d'ajuster le volume " "sonore. Si vous avez du son, en glissant le curseur vous pouvez " "spécifiez le volume du son. En glissant le curseur vers zéro " "vous pouvez arrêter tout effet sonore."}, {butText_just, 0, ""}, {butText_just, 0, " La partie de la table de transposition se trouve en " "haut et à droite de la fenêtre de configuration. Pour l'instant, elle " "n'est pas en fonction."}, {butText_just, 0, ""}, {butText_just, 0, " La partie réseau se trouve en bas et à droite de " "la fenêtre de configuration. Pour l'instant, elle " "n'est pas en fonction."}, {butText_just, 0, ""}, {butText_just, 0, " Tout en bas de la fenêtre de configuration, on " "trouve deux boutons dont le nom est \"OK\" et \"Aide\". L'appui sur " "\"OK\" ferme la fenêtre de configuration et l'appui sur \"Aide\" " "permet d'activer cette page d'aide."}, {butText_just, 0, ""}, {butText_center, 0, XIO_PL1CHAR XIO_PL2CHAR XIO_PL1MARKCHAR XIO_PL2CHAR XIO_PL1CHAR}, {butText_just, 0, ""}, {0,0,NULL}}; static xio_tb_t setuphelp_italian[] = { {butText_center, 1, "Pente " VERSION}, {butText_center, 0, "di Bill Shubert"}, {butText_center, 0, DATE_ITALIAN}, {butText_just, 0, ""}, {butText_just, 1, "Aiuto sulla finestra di configurazione"}, {butText_just, 0, " Questa pagina di aiuto spiega le opzioni della " "finestra di configurazione in Pente. Per accedere alla finestra di " "configurazione, premere il pulsante \"Configura\" nella " "finestra principale."}, {butText_just, 0, " Vi sono quattro sottosezioni nella finestra di " "configurazione. Si tratta della sezione delle opzioni, di quella " "del sonoro, di quella della tabella di trasposizione e di quella " "per il gioco in rete."}, {butText_just, 0, ""}, {butText_just, 0, " La sezione delle opzioni, nella parte superiore " "sinistra della finestra di configurazione, ha tre comandi. C'è il " "menu della \"Lingua\" che seleziona la lingua da usare per i messaggi " "all'utente. Attualmente, le uniche lingue supportate sono l'Inglese, " "il Francese e l'Italiano. Se conoscete un'altra lingua e siete " "disposti a fare la traduzione, contattatemi senza ulteriori indugi! " "Vorrei tradurre questo programma nel maggior numero possibile di lingue."}, {butText_just, 0, " Sempre nella sezione delle opzioni, c'è una casella " "per il colore. Se avete uno schermo a colori, cliccando su questa casella " "passerete da colore a bianco e nero e viceversa."}, {butText_just, 0, " L'ultimo comando nella sezione delle opzioni è la " "casella \"Visibile\". Se questa è marcata, potete vedere le mosse che " "il computer sta pensando quando gioca ai livelli \"Esperto\" e " "\"Maestro\". Se non è abilitata, non potete vedere le mosse che il " "computer sta esaminando."}, {butText_just, 0, ""}, {butText_just, 0, " La sezione del sonoro è nella parte inferiore " "sinistra della finestra di configurazione. Contiene un solo comando: " "un cursore per regolare il volume del sonoro. Se il vostro sistema " "è dotato di sonoro, spostando questo controllo imposterete il volume degli " "effetti sonori. Spostandolo completamente a zero disabiliterete " "il sonoro."}, {butText_just, 0, ""}, {butText_just, 0, " La sezione della tabella di trasposizione è nella " "parte superiore destra della finestra di configurazione ed è " "attualmente disabilitata."}, {butText_just, 0, ""}, {butText_just, 0, " La sezione della rete è nella parte inferiore destra " "della finestra di setup. Contiene una casella, un pulsante ed un campo " "di immissione. La casella vi consente di decidere se Pente deve accettare " "o meno le richieste remote di giocare in rete. Il pulsante \"Connetti\" " "può essere usato per iniziare subito una partita in rete e il campo " "\"Porta\" imposta il numero di porta di rete usata da Pente. Si prega di " "consultare la pagina di aiuto sul \"Gioco in rete\" per maggiori " "informazioni."}, {butText_just, 0, ""}, {butText_just, 0, " In fondo alla finestra di configurazione, si trovano " "due pulsanti, etichettati \"OK\" e \"aiuto\". Premendo \"OK\" si chiude " "la finestra di configurazione e premendo \"aiuto\" si apre questa pagina."}, {butText_just, 0, ""}, {butText_center, 0, XIO_PL1CHAR XIO_PL2CHAR XIO_PL1MARKCHAR XIO_PL2CHAR XIO_PL1CHAR}, {butText_just, 0, ""}, {0,0,NULL}}; static xio_tb_t network_eng[] = { {butText_center, 1, "Pente " VERSION}, {butText_center, 0, "By Bill Shubert"}, {butText_center, 0, DATE}, {butText_just, 0, ""}, {butText_just, 1, "Setting Up Network Play"}, {butText_just, 0, " To play pente against somebody on a different " "machine, both players have to start by running Pente (version 2.1.0 or " "later). In the setup window, there's a control panel that lets you set " "your port number. Exactly which port number you choose is pretty " "unimportant; they're all the same. This is the port where your Pente " "program will be listening for network games. You should probably leave " "it at 15023, which is the standard Pente port."}, {butText_just, 0, " Once both players have run Pente, decide who will " "connect and who will listen. The player who listens must make sure " "that remote operation is turned on with the checkbox in the setup " "window. Then the player who will connect can either press the " "\"Connect\" button in his setup window or select \"Remote\" on one of " "his player menus. The connecting player then gets a window where he is " "asked for the name of the machine to connect to and the port. He " "should type in the name of the listening player's machine and the same " "port than the listening player has set in his setup window (this will " "be 15023 unless the listening player decided to be different). After " "pressing OK, the two players should be connected and ready to go!"}, {butText_just, 0, ""}, {butText_just, 1, "Using Network Play"}, {butText_just, 0, " Once the two players are connected, you should see " "each other's mice. Your opponent's mouse will be upside down. Now " "just set one player to \"Remote\" and the other to \"human\" and you'll " "be playing against each other."}, {butText_just, 0, ""}, {butText_just, 0, " If a player wishes to stop using network play, they " "should press the \"Disconnect\" button in the setup window."}, {butText_just, 0, ""}, {butText_center, 0, XIO_PL1CHAR XIO_PL2CHAR XIO_PL1MARKCHAR XIO_PL2CHAR XIO_PL1CHAR}, {butText_just, 0, ""}, {0,0,NULL}}; static xio_tb_t network_french[] = { {butText_center, 1, "Pente " VERSION}, {butText_center, 0, "Par Bill Shubert"}, {butText_center, 0, DATE_FRENCH}, {butText_just, 0, ""}, {butText_just, 1, "Configurer le Jeu en Réseau"}, {butText_just, 0, " Pour jouer à pente contre quelqu'un sur une machine " "différente, les deux joueurs doivent démarrer Pente (version 2.1.0 ou " "plus). Dans la fenêtre de configuration, on trouve un panneau de " "contrôle permettant de sélectionner le numéro de port. Peu importe le " "numéro de port que vous choisissez; ce sont tous les mêmes. Il " "s'agit du port sur lequel le programme Pente va se mettre à l'écoute " "pour les jeux en réseau. Vous devriez laisser le numéro de port à " "15023, c'est le port standard de Pente."}, {butText_just, 0, " Une fois que les deux joueurs ont lancé Pente, il " "faut décider qui va se connecter et qui va écouter. Le joueur " "qui écoute doit s'assurer que l'option de connexion " "est validée par une coche dans la fenêtre de configuration. " "Ensuite, le joueur qui se connecte " "peut soit appuyer sur le bouton \"Connexion\" de sa fenêtre de " "configuration, soit sélectionner \"Distant\" sur l'un des menus " "des sélectionneurs de joueur. Le joueur qui se connecte " "obtient alors une fenêtre où il " "doit saisir le nom de la machine où se connecter ainsi que le port. " "Le nom à saisir est celui de la machine du joueur distant et le " "port est le même que celui choisi par le joueur distant (ce sera " "15023 à moins que le joueur distant en ait décidé autrement). Après " "avoir appuyé sur OK, les deux joueurs devraient être connectés et " "prêts à jouer!"}, {butText_just, 0, ""}, {butText_just, 1, "Utilisation du jeu en réseau"}, {butText_just, 0, " Une fois que les deux joueurs sont connectés, " "vous devriez voir la souris de chacun des deux. La souris de votre " "adversaire est retournée. A présent il suffit de sélectionner l'un des " "joueurs comme \"Distant\" et l'autre comme \"Humain\" afin de " "jouer l'un contre l'autre."}, {butText_just, 0, ""}, {butText_just, 0, " FRENCH If a player wishes to stop using network play, " "they should press the \"Disconnect\" button in the setup window."}, {butText_just, 0, ""}, {butText_center, 0, XIO_PL1CHAR XIO_PL2CHAR XIO_PL1MARKCHAR XIO_PL2CHAR XIO_PL1CHAR}, {butText_just, 0, ""}, {0,0,NULL}}; static xio_tb_t network_italian[] = { {butText_center, 1, "Pente " VERSION}, {butText_center, 0, "di Bill Shubert"}, {butText_center, 0, DATE_ITALIAN}, {butText_just, 0, ""}, {butText_just, 1, "Impostare il gioco in rete"}, {butText_just, 0, " Per giocare a pente contro qualcuno su una macchina " "diversa, entrambe i giocatori devono iniziare con l'eseguire Pente " "(versione 2.1.0 o successiva). Nella finestra di configurazione, c'è " "un pannello nel quale potete impostare il numero della porta di rete. " "Non è molto importante il numero che scegliete: sono tutti equivalenti. " "Questa è la porta sulla quale il vostro programma di Pente aspetterà " "eventuali richieste per il gioco in rete. Tutto sommato, è meglio che " "la lasciate a 15023, che è la porta standard di Pente."}, {butText_just, 0, " Una volta che entrambe i giocatori stanno eseguendo " "Pente, decidete chi chiamerà e chi ascolterà. Il giocatore in ascolto " "deve assicurarsi di avere abilitato il gioco in rete nella casella della " "finestra di configurazione. A questo punto, il giocatore chiamante " "può o premere il pulsante \"Connetti\" nella sua finestra di configurazione " "o selezionare \"Remoto\" in uno dei suoi selettori di giocatore. Al " "giocatore chiamante comparirà una finestra in cui dovrà specificare " "il nome della macchina a cui connettersi e il numero della porta. " "Dovrà scrivere il nome della macchina del giocatore in ascolto e lo " "stesso numero di porta da lui impostato nella propria finestra di " "configurazione (che sarà 15023 a meno che il ricevente non abbia deciso " "altrimenti). Dopo aver premuto OK, i due giocatori dovrebbero essere " "connessi e pronti per giocare!"}, {butText_just, 0, ""}, {butText_just, 1, "Giocare in rete"}, {butText_just, 0, " Una volta che i due giocatori sono collegati, " "ognuno dovrebbe vedere il mouse dell'altro. Il mouse del vostro " "avversario sarà capovolto. Adesso basta impostare un giocatore " "a \"Remoto\" e l'altro a \"Umano\" e potrete giocare uno contro " "l'altro."}, {butText_just, 0, ""}, {butText_just, 0, " Se un giocatore desidera interrompere una partita in " "rete, gli basterà premere il pulsante \"Disconnetti\" nella finestra " "di configurazione."}, {butText_just, 0, ""}, {butText_center, 0, XIO_PL1CHAR XIO_PL2CHAR XIO_PL1MARKCHAR XIO_PL2CHAR XIO_PL1CHAR}, {butText_just, 0, ""}, {0,0,NULL}}; static xio_tb_t computer_eng[] = { {butText_center, 1, "Pente " VERSION}, {butText_center, 0, "By Bill Shubert"}, {butText_center, 0, DATE}, {butText_just, 0, ""}, {butText_just, 1, "About the Computer Players"}, {butText_just, 0, " The computer players use a tree search to determine " "their moves. Making a threat (such as three in a row, open on both " "ends) counts as good thing; captures count even better. So pretty " "much they analyze all possible moves, looking for sequences that let " "them make lots more threats and captures than their opponents."}, {butText_just, 0, " Each computer player searches one move farther " "ahead than the previous one. So \"" XIO_COMPCHAR " Simple\" only looks " "one move ahead, but \"" XIO_COMPCHAR " Master\" looks six moves ahead."}, {butText_just, 0, " At deeper searches, pruning is done. I wanted " "to experiment with different pruning algorithms besides regular " "alpha-beta, but my results haven't been that great. I prune off all " "sequences that last 3 or more moves with no threats or captures; and " "I never even consider moves that are more than 2 spaces from all other " "pieces on the board. Lastly, if the computer is searching more than " "4 moves ahead, I do a 4 ply search then search deeper on the \"n\" most " "promising moves, where \"n\" is the overall search depth. This last " "pruning algorithm is a lot like alpha-beta, but probably not as good."}, {butText_just, 0, " I plan on doing a major rewrite, replacing all " "this weird stuff with normal alpha-beta and installing a transposition " "table, then comparing the result against my current algorithms. I " "suspect that this new version will be able to search deeper in less " "time, and thus play a better game."}, {butText_just, 0, " As an aside, originally I used a pattern matching " "algorithm instead of deep searches. The pattern matcher trained " "itself using simulated annealing. After letting the annealing " "algorithm run for a week or two, it played a surprisingly strong " "game for only one ply lookahead. I tried training it to recognize " "patterns useful for a two ply search, but unfortunately the annealing " "algorithm was far too slow for this. After giving up on tuning the " "algorithm enough for reasonable performance, I switched to the search " "that I use today."}, {butText_just, 0, ""}, {butText_center, 0, XIO_PL1CHAR XIO_PL2CHAR XIO_PL1MARKCHAR XIO_PL2CHAR XIO_PL1CHAR}, {butText_just, 0, ""}, {0,0,NULL}}; static xio_tb_t computer_french[] = { {butText_center, 1, "Pente " VERSION}, {butText_center, 0, "Par Bill Shubert"}, {butText_center, 0, DATE_FRENCH}, {butText_just, 0, ""}, {butText_just, 1, "A Propos des Joueurs Gérés par l'Ordinateur"}, {butText_just, 0, " Les joueurs gérés par l'ordinateur utilisent une " "recherche d'arbre pour déterminer leurs coups. Porter une menace " "(telle que trois pierres alignées avec une ouverture de chaque côté) " "compte comme une bonne chose; les captures compte pour encore plus. " "Ils analysent donc tous les coups possibles, en recherchant des " "séquences leur permettant de faire beaucoup plus de menaces et de " "captures que leurs adversaires."}, {butText_just, 0, " Chaque joueur géré par l'ordinateur cherche un coup " "en avance de plus que le précédent joueur. " "Donc \"" XIO_COMPCHAR " Simple\" " "regarde juste un coup en avance, mais \"" XIO_COMPCHAR " Maître\" " "regarde six coups en avance."}, {butText_just, 0, " Pour les recherches plus profondes, on a recours à " "un élagage. Je voulais expérimenter différents algorithmes " "d'élagage en plus de l'alpha-beta habituel, mais mes résultats n'ont " "pas été si bons que ça. " "J'élague toutes les séquences de 3 coups ou plus sans menaces " "ni captures; et je ne prends jamais en considération les coups qui " "se trouvent à plus de 2 cases des autres jetons du plateau de jeu. " "Finalement, si l'ordinateur cherche plus de 4 coups en avance, je " "commence la recherche de 4 coups en avance puis je cherche plus " "profondément dans " "les \"n\" plus prometteurs coups, où \"n\" est la profondeur de " "recherche globale. Ce dernier algorithme d'élagage ressemble " "beaucoup à de l'alpha-beta, mais n'est peut être pas aussi bon."}, {butText_just, 0, " Je projette de réaliser une grande réécriture, de " "remplacer toutes ces choses étranges par de l'alpha-beta normal et " "d'installer une table de transposition, puis de comparer le résultat " "avec l'algorithme que j'utilise pour le moment. Je suppose que " "cette nouvelle version sera capable de chercher encore plus " "profondément et en moins de temps, et de jouer encore mieux."}, {butText_just, 0, " Un petit mot en en apparté: au départ " "j'utilisais un algorithme de " "comparaison de motif à la place de recherches en profondeur. Le " "comparateur de motif s'entraînait tout seul en utilisant une " "heuristique. Après avoir laissé tourner l'heuristique pendant " "une semaine ou deux, le programme était étonnement fort pour " "seulement une recherche d'un coup " "d'avance. J'ai essayé de l'entraîner à reconnaître des motifs utiles " "pour une recherche de deux coups en avance, mais malheureusement " "l'heuristique était beaucoup trop lente. Après avoir abandonné la " "mise au point de l'algorithme, suffisamment pour obtenir des " "performances raisonnables, je suis passé à la recherche que j'utilise " "à présent."}, {butText_just, 0, ""}, {butText_center, 0, XIO_PL1CHAR XIO_PL2CHAR XIO_PL1MARKCHAR XIO_PL2CHAR XIO_PL1CHAR}, {butText_just, 0, ""}, {0,0,NULL}}; static xio_tb_t computer_italian[] = { {butText_center, 1, "Pente " VERSION}, {butText_center, 0, "By Bill Shubert"}, {butText_center, 0, DATE_ITALIAN}, {butText_just, 0, ""}, {butText_just, 1, "A proposito dei giocatori controllati dalla macchina"}, {butText_just, 0, " I giocatori del computer usano un albero di ricerca " "per scegliere le loro mosse. Portare un attacco (come tre pedine allineate, " "libere da entrambe gli estremi) è una buona cosa; le prese sono anche meglio. " "Quindi, in pratica, analizzano tutto le mosse possibili, alla ricerca di " "sequenze che consentano loro di portare più attacchi ed effettuare più " "prese dei loro avversari."}, {butText_just, 0, " Ogni giocatore del computer esamina una mossa in più " "del precedente. Quindi, \"" XIO_COMPCHAR " Semplice\" guarda solo una " "mossa avanti, mentre \"" XIO_COMPCHAR " Maestro\" ne guarda sei."}, {butText_just, 0, " Man mano che la profondità della ricerca cresce, " "l'albero di ricerca viene sfoltito. Volevo fare delle prove con " "algoritmi di sfoltimento diversi dai classici alfa-beta, ma i " "miei risultati non sono stati particolarmente incoraggianti. Escludo " "dalla ricerca tutte le sequenze di 3 o più mosse senza attacchi o prese " "e non considero nemmeno le mosse che distano più di due posizioni da " "tutte le altre pedine sulla griglia. Infine, se il computer sta " "esaminando oltre la quarta mossa successiva, eseguo prima una ricerca " "fino al quarto livello, poi continuo la ricerca sulle \"n\" mosse più " "promettenti, dove \"n\" è la profondità complessiva della ricerca. " "Quest'ultimo algoritmo di sfoltimento assomiglia molto all'alfa-beta, " "ma probabilmente non è altrettanto buono."}, {butText_just, 0, " Sto meditando di riscriverne buona parte, sostituendo " "tutta questa strana roba con un normale alfa-beta e installando una " "tabella di trasposizione, per poi confrontare i risultati con quelli dei " "miei algoritmi attuali. Ho idea che questa nuova versione sarà in " "grado di cercare più in profondità in meno tempo e quindi giocherà meglio."}, {butText_just, 0, " Per inciso, originariamente utilizzavo un'algoritmo di " "riconoscimento delle configurazioni invece della ricerca in profondità. " "Tale algoritmo si allenava con un procedimento chiamato \"raffreddamento " "simulato\". Dopo averlo lasciato girare per una settimana o due, giocava " "veramente bene considerato che guardava solo fino alla mossa successiva. " "Ho provato ad allenarlo per riconoscere le configurazioni utili per una " "ricerca al secondo livello, ma l'algoritmo di raffreddamento era " "decisamente troppo lento per fare ciò. Dopo aver abbandonato i tentativi " "di migliorare l'algoritmo per ottenere delle prestazioni accettabili, " "sono passato all'algoritmo di ricerca che uso ancora oggi."}, {butText_just, 0, ""}, {butText_center, 0, XIO_PL1CHAR XIO_PL2CHAR XIO_PL1MARKCHAR XIO_PL2CHAR XIO_PL1CHAR}, {butText_just, 0, ""}, {0,0,NULL}}; static xio_tb_t author_eng[] = { {butText_center, 1, "Pente " VERSION}, {butText_center, 0, "By Bill Shubert"}, {butText_center, 0, DATE}, {butText_just, 0, ""}, {butText_just, 1, "About the author"}, {butText_just, 0, " Hello! My name is Bill Shubert. I've always loved " "playing pente, and computer algorithms to play human-oriented games " "fascinate me, so writing a computer program to play pente seemed " "like a natural thing to try. Then I wanted to learn X, so I wrote " "the GUI to go with it. It seems like I can always think of a way to " "improve this program so I'm never really done."}, {butText_just, 0, " Feel free to get in touch with me if you have any " "comments about this program! As of the date at the top of this " "help page, you can contact me at:"}, {butText_left, 0, " Email: wms@igoweb.org"}, {butText_left, 0, " WWW: http://www.igoweb.org/~wms/"}, {butText_just, 0, ""}, {butText_just, 0, " I'd like to thank Eric Dupas for translating all " "text into French and Andrea Borgia (email: borgia@cs.unibo.it; " "homepage: http://www.cs.unibo.it/~borgia) for translating the text into " "Italian."}, {butText_just, 0, ""}, {butText_just, 0, " Thanks for trying out my program. I hope you like " "it!"}, {butText_just, 0, ""}, {butText_center, 0, XIO_PL1CHAR XIO_PL2CHAR XIO_PL1MARKCHAR XIO_PL2CHAR XIO_PL1CHAR}, {butText_just, 0, ""}, {0,0,NULL}}; static xio_tb_t author_french[] = { {butText_center, 1, "Pente " VERSION}, {butText_center, 0, "Par Bill Shubert"}, {butText_center, 0, DATE_FRENCH}, {butText_just, 0, ""}, {butText_just, 1, "A Propos de l'Auteur"}, {butText_just, 0, " Bonjour! Mon nom est Bill Shubert. J'ai toujours " "aimé jouer à pente, et les algorithmes pour jouer " "à des jeux pour humains me fascinent, il m'a donc semblé naturel " "d'écrire un programme pour jouer à pente. " "Ensuite j'ai voulu apprendre X, donc j'ai écrit l'Interface Graphique " "Utilisateur qui fonctionne avec. J'ai toujours l'impression d'avoir " "une façon d'améliorer ce programme, je n'en ai donc jamais " "vraiment terminé."}, {butText_just, 0, " Vous pouvez me joindre si vous avez des commentaires " "concernant ce programme! A la date qui se trouve en haut de cette page " "d'aide, vous pouvez me contacter de plusieurs manières:"}, {butText_left, 0, " Email: wms@igoweb.org"}, {butText_left, 0, " WWW: http://www.igoweb.org/~wms/"}, {butText_just, 0, ""}, {butText_just, 0, " J'aimerais remercier Eric Dupas pour la traduction " "de tout le texte en Français."}, {butText_just, 0, ""}, {butText_just, 0, " Merci d'essayer mon programme. J'espère que " "vous l'appréciez!"}, {butText_just, 0, ""}, {butText_center, 0, XIO_PL1CHAR XIO_PL2CHAR XIO_PL1MARKCHAR XIO_PL2CHAR XIO_PL1CHAR}, {butText_just, 0, ""}, {0,0,NULL}}; static xio_tb_t author_italian[] = { {butText_center, 1, "Pente " VERSION}, {butText_center, 0, "di Bill Shubert"}, {butText_center, 0, DATE_ITALIAN}, {butText_just, 0, ""}, {butText_just, 1, "A proposito dell'autore"}, {butText_just, 0, " Salve! Il mio nome è Bill Shubert. Mi è sempre " "piaciuto giocare a pente e gli algoritmi per giocare dei giochi per " "umani mi affascinano, per cui mi è sembrato naturale scrivere un " "programma per giocare a pente col computer. Poi volevo imparare X, " "quindi ho scritto l'interfaccia che lo accompagna. Sembra che io trovi " "sempre nuovi modi per migliorare questo programma, per cui non l'ho " "mai davvero finito."}, {butText_just, 0, " Siete liberi di contattarmi se avete dei commenti su " "questo programma! Alla data riportata in cima a questa pagina di aiuto, " "potete contattarmi in questi modi:"}, {butText_left, 0, " Email: wms@igoweb.org"}, {butText_left, 0, " WWW: http://www.igoweb.org/~wms/"}, {butText_just, 0, ""}, {butText_just, 0, " Desidero ringraziare Eric Dupas per la traduzione del " "testo in Francese e Andrea Borgia (email: borgia@cs.unibo.it; homepage: " "http://www.cs.unibo.it/~borgia) per quella in Italiano."}, {butText_just, 0, ""}, {butText_just, 0, " Grazie di aver provato il mio programma: spero che vi piaccia."}, {butText_just, 0, ""}, {butText_center, 0, XIO_PL1CHAR XIO_PL2CHAR XIO_PL1MARKCHAR XIO_PL2CHAR XIO_PL1CHAR}, {butText_just, 0, ""}, {0,0,NULL}}; static xio_tb_t copying_eng[] = { {butText_center, 1, "Pente " VERSION}, {butText_center, 0, "By Bill Shubert"}, {butText_center, 0, DATE}, {butText_just, 0, ""}, {butText_just, 1, "Distribution"}, {butText_just, 0, " This program is distributed under the Gnu General " "Public License, version 2. This should have been included with your " "copy of the source code in a file called \"COPYING\". In any case, the " "license is also included below."}, {butText_just, 0, " Basically, there are three things that most of you " "will care about in this license. One is that you can give away free " "copies to all your friends. Another is that you have to be told where " "you can get the source code from. You can get it from me; see the " "\"About the Author\" help page for how to get in touch. The last is " "that there is no warranty, so if this software ruins your life don't " "come crying to me."}, {butText_just, 0, " If you want to do anything else with this software, " "you should read the license below for details."}, {butText_just, 0, ""}, {butText_center, 0, "GNU GENERAL PUBLIC LICENSE"}, {butText_center, 0, "TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND " "MODIFICATION"}, {butText_just, 0, ""}, {butText_just, 0, " 0. This License applies to any program or other work " "which contains a notice placed by the copyright holder saying it may be " "distributed under the terms of this General Public License. The " "\"Program\", below, refers to any such program or work, and a \"work " "based on the Program\" means either the Program or any derivative work " "under copyright law: that is to say, a work containing the Program or a " "portion of it, either verbatim or with modifications and/or translated " "into another language. (Hereinafter, translation is included without " "limitation in the term \"modification\".) Each licensee is addressed " "as \"you\"."}, {butText_just, 0, ""}, {butText_just, 0, "Activities other than copying, distribution and " "modification are not covered by this License; they are outside its " "scope. The act of running the Program is not restricted, and the " "output from the Program is covered only if its contents constitute a " "work based on the Program (independent of having been made by running " "the Program). Whether that is true depends on what the Program does."}, {butText_just, 0, ""}, {butText_just, 0, " 1. You may copy and distribute verbatim copies of the " "Program's source code as you receive it, in any medium, provided that " "you conspicuously and appropriately publish on each copy an appropriate " "copyright notice and disclaimer of warranty; keep intact all the " "notices that refer to this License and to the absence of any warranty; " "and give any other recipients of the Program a copy of this License " "along with the Program."}, {butText_just, 0, ""}, {butText_just, 0, "You may charge a fee for the physical act of " "transferring a copy, and you may at your option offer warranty " "protection in exchange for a fee."}, {butText_just, 0, ""}, {butText_just, 0, " 2. You may modify your copy or copies of the Program " "or any portion of it, thus forming a work based on the Program, and " "copy and distribute such modifications or work under the terms of " "Section 1 above, provided that you also meet all of these " "conditions:"}, {butText_just, 0, ""}, {butText_just, 0, " a) You must cause the modified files to carry " "prominent notices stating that you changed the files and the date of " "any change."}, {butText_just, 0, ""}, {butText_just, 0, " b) You must cause any work that you distribute or " "publish, that in whole or in part contains or is derived from the " "Program or any part thereof, to be licensed as a whole at no charge to " "all third parties under the terms of this License."}, {butText_just, 0, ""}, {butText_just, 0, " c) If the modified program normally reads commands " "interactively when run, you must cause it, when started running for " "such interactive use in the most ordinary way, to print or display an " "announcement including an appropriate copyright notice and a notice " "that there is no warranty (or else, saying that you provide a warranty) " "and that users may redistribute the program under these conditions, and " "telling the user how to view a copy of this License. (Exception: if " "the Program itself is interactive but does not normally print such an " "announcement, your work based on the Program is not required to print " "an announcement.)"}, {butText_just, 0, ""}, {butText_just, 0, "These requirements apply to the modified work as a " "whole. If identifiable sections of that work are not derived from the " "Program, and can be reasonably considered independent and separate " "works in themselves, then this License, and its terms, do not apply to " "those sections when you distribute them as separate works. But when " "you distribute the same sections as part of a whole which is a work " "based on the Program, the distribution of the whole must be on the " "terms of this License, whose permissions for other licensees extend to " "the entire whole, and thus to each and every part regardless of who " "wrote it."}, {butText_just, 0, ""}, {butText_just, 0, "Thus, it is not the intent of this section to claim " "rights or contest your rights to work written entirely by you; rather, " "the intent is to exercise the right to control the distribution of " "derivative or collective works based on the Program."}, {butText_just, 0, ""}, {butText_just, 0, "In addition, mere aggregation of another work not based " "on the Program with the Program (or with a work based on the Program) " "on a volume of a storage or distribution medium does not bring the " "other work under the scope of this License."}, {butText_just, 0, ""}, {butText_just, 0, " 3. You may copy and distribute the Program (or a work " "based on it, under Section 2) in object code or executable form under " "the terms of Sections 1 and 2 above provided that you also do one of " "the following:"}, {butText_just, 0, ""}, {butText_just, 0, " a) Accompany it with the complete corresponding " "machine-readable source code, which must be distributed under the terms " "of Sections 1 and 2 above on a medium customarily used for software " "interchange; or,"}, {butText_just, 0, ""}, {butText_just, 0, " b) Accompany it with a written offer, valid for at " "least three years, to give any third party, for a charge no more than " "your cost of physically performing source distribution, a complete " "machine-readable copy of the corresponding source code, to be " "distributed under the terms of Sections 1 and 2 above on a medium " "customarily used for software interchange; or,"}, {butText_just, 0, ""}, {butText_just, 0, " c) Accompany it with the information you received " "as to the offer to distribute corresponding source code. (This " "alternative is allowed only for noncommercial distribution and only if " "you received the program in object code or executable form with such an " "offer, in accord with Subsection b above.)"}, {butText_just, 0, ""}, {butText_just, 0, "The source code for a work means the preferred form of " "the work for making modifications to it. For an executable work, " "complete source code means all the source code for all modules it " "contains, plus any associated interface definition files, plus the " "scripts used to control compilation and installation of the executable. " " However, as a special exception, the source code distributed need not " "include anything that is normally distributed (in either source or " "binary form) with the major components (compiler, kernel, and so on) of " "the operating system on which the executable runs, unless that " "component itself accompanies the executable."}, {butText_just, 0, ""}, {butText_just, 0, "If distribution of executable or object code is made by " "offering access to copy from a designated place, then offering " "equivalent access to copy the source code from the same place counts as " "distribution of the source code, even though third parties are not " "compelled to copy the source along with the object code."}, {butText_just, 0, ""}, {butText_just, 0, " 4. You may not copy, modify, sublicense, or " "distribute the Program except as expressly provided under this License. " " Any attempt otherwise to copy, modify, sublicense or distribute the " "Program is void, and will automatically terminate your rights under " "this License. However, parties who have received copies, or rights, " "from you under this License will not have their licenses terminated so " "long as such parties remain in full compliance."}, {butText_just, 0, ""}, {butText_just, 0, " 5. You are not required to accept this License, since " "you have not signed it. However, nothing else grants you permission to " "modify or distribute the Program or its derivative works. These " "actions are prohibited by law if you do not accept this License. " "Therefore, by modifying or distributing the Program (or any work based " "on the Program), you indicate your acceptance of this License to do so, " "and all its terms and conditions for copying, distributing or modifying " "the Program or works based on it."}, {butText_just, 0, ""}, {butText_just, 0, " 6. Each time you redistribute the Program (or any " "work based on the Program), the recipient automatically receives a " "license from the original licensor to copy, distribute or modify the " "Program subject to these terms and conditions. You may not impose any " "further restrictions on the recipients' exercise of the rights granted " "herein. You are not responsible for enforcing compliance by third " "parties to this License."}, {butText_just, 0, ""}, {butText_just, 0, " 7. If, as a consequence of a court judgment or " "allegation of patent infringement or for any other reason (not limited " "to patent issues), conditions are imposed on you (whether by court " "order, agreement or otherwise) that contradict the conditions of this " "License, they do not excuse you from the conditions of this License. " "If you cannot distribute so as to satisfy simultaneously your " "obligations under this License and any other pertinent obligations, " "then as a consequence you may not distribute the Program at all. For " "example, if a patent license would not permit royalty-free " "redistribution of the Program by all those who receive copies directly " "or indirectly through you, then the only way you could satisfy both it " "and this License would be to refrain entirely from distribution of the " "Program."}, {butText_just, 0, ""}, {butText_just, 0, "If any portion of this section is held invalid or " "unenforceable under any particular circumstance, the balance of the " "section is intended to apply and the section as a whole is intended to " "apply in other circumstances."}, {butText_just, 0, ""}, {butText_just, 0, "It is not the purpose of this section to induce you to " "infringe any patents or other property right claims or to contest " "validity of any such claims; this section has the sole purpose of " "protecting the integrity of the free software distribution system, " "which is implemented by public license practices. Many people have " "made generous contributions to the wide range of software distributed " "through that system in reliance on consistent application of that " "system; it is up to the author/donor to decide if he or she is willing " "to distribute software through any other system and a licensee cannot " "impose that choice."}, {butText_just, 0, ""}, {butText_just, 0, "This section is intended to make thoroughly clear what " "is believed to be a consequence of the rest of this License."}, {butText_just, 0, ""}, {butText_just, 0, " 8. If the distribution and/or use of the Program is " "restricted in certain countries either by patents or by copyrighted " "interfaces, the original copyright holder who places the Program under " "this License may add an explicit geographical distribution limitation " "excluding those countries, so that distribution is permitted only in or " "among countries not thus excluded. In such case, this License " "incorporates the limitation as if written in the body of this License."}, {butText_just, 0, ""}, {butText_just, 0, " 9. The Free Software Foundation may publish revised " "and/or new versions of the General Public License from time to time. " "Such new versions will be similar in spirit to the present version, but " "may differ in detail to address new problems or concerns."}, {butText_just, 0, ""}, {butText_just, 0, "Each version is given a distinguishing version number. " "If the Program specifies a version number of this License which applies " "to it and \"any later version\", you have the option of following the " "terms and conditions either of that version or of any later version " "published by the Free Software Foundation. If the Program does not " "specify a version number of this License, you may choose any version " "ever published by the Free Software Foundation."}, {butText_just, 0, ""}, {butText_just, 0, " 10. If you wish to incorporate parts of the Program " "into other free programs whose distribution conditions are different, " "write to the author to ask for permission. For software which is " "copyrighted by the Free Software Foundation, write to the Free Software " "Foundation; we sometimes make exceptions for this. Our decision will " "be guided by the two goals of preserving the free status of all " "derivatives of our free software and of promoting the sharing and reuse " "of software generally."}, {butText_just, 0, ""}, {butText_center, 0, "NO WARRANTY"}, {butText_just, 0, ""}, {butText_just, 0, " 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, " "THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY " "APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT " "HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM \"AS IS\" WITHOUT " "WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT " "LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A " "PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE " "OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU " "ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION."}, {butText_just, 0, ""}, {butText_just, 0, " 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR " "AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO " "MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE " "LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL " "OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE " "PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING " "RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A " "FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF " "SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH " "DAMAGES."}, {butText_just, 0, ""}, {butText_center, 0, "END OF TERMS AND CONDITIONS"}, {butText_just, 0, ""}, {butText_center, 0, XIO_PL1CHAR XIO_PL2CHAR XIO_PL1MARKCHAR XIO_PL2CHAR XIO_PL1CHAR}, {butText_just, 0, ""}, {0,0,NULL}}; static xio_tb_t copying_french[] = { {butText_center, 1, "Pente " VERSION}, {butText_center, 0, "Par Bill Shubert"}, {butText_center, 0, DATE_FRENCH}, {butText_just, 0, ""}, {butText_just, 1, "Distribution"}, {butText_just, 0, " This program is distributed under the Gnu General " "Public License, version 2. This should have been included with your " "copy of the source code in a file called \"COPYING\". In any case, the " "license is also included below."}, {butText_just, 0, " Basically, there are three things that most of you " "will care about in this license. One is that you can give away free " "copies to all your friends. Another is that you have to be told where " "you can get the source code from. You can get it from me; see the " "\"About the Author\" help page for how to get in touch. The last is " "that there is no warranty, so if this software ruins your life don't " "come crying to me."}, {butText_just, 0, " If you want to do anything else with this software, " "you should read the license below for details."}, {butText_just, 0, ""}, {butText_center, 0, "GNU GENERAL PUBLIC LICENSE"}, {butText_center, 0, "TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND " "MODIFICATION"}, {butText_just, 0, ""}, {butText_just, 0, " 0. This License applies to any program or other work " "which contains a notice placed by the copyright holder saying it may be " "distributed under the terms of this General Public License. The " "\"Program\", below, refers to any such program or work, and a \"work " "based on the Program\" means either the Program or any derivative work " "under copyright law: that is to say, a work containing the Program or a " "portion of it, either verbatim or with modifications and/or translated " "into another language. (Hereinafter, translation is included without " "limitation in the term \"modification\".) Each licensee is addressed " "as \"you\"."}, {butText_just, 0, ""}, {butText_just, 0, "Activities other than copying, distribution and " "modification are not covered by this License; they are outside its " "scope. The act of running the Program is not restricted, and the " "output from the Program is covered only if its contents constitute a " "work based on the Program (independent of having been made by running " "the Program). Whether that is true depends on what the Program does."}, {butText_just, 0, ""}, {butText_just, 0, " 1. You may copy and distribute verbatim copies of the " "Program's source code as you receive it, in any medium, provided that " "you conspicuously and appropriately publish on each copy an appropriate " "copyright notice and disclaimer of warranty; keep intact all the " "notices that refer to this License and to the absence of any warranty; " "and give any other recipients of the Program a copy of this License " "along with the Program."}, {butText_just, 0, ""}, {butText_just, 0, "You may charge a fee for the physical act of " "transferring a copy, and you may at your option offer warranty " "protection in exchange for a fee."}, {butText_just, 0, ""}, {butText_just, 0, " 2. You may modify your copy or copies of the Program " "or any portion of it, thus forming a work based on the Program, and " "copy and distribute such modifications or work under the terms of " "Section 1 above, provided that you also meet all of these " "conditions:"}, {butText_just, 0, ""}, {butText_just, 0, " a) You must cause the modified files to carry " "prominent notices stating that you changed the files and the date of " "any change."}, {butText_just, 0, ""}, {butText_just, 0, " b) You must cause any work that you distribute or " "publish, that in whole or in part contains or is derived from the " "Program or any part thereof, to be licensed as a whole at no charge to " "all third parties under the terms of this License."}, {butText_just, 0, ""}, {butText_just, 0, " c) If the modified program normally reads commands " "interactively when run, you must cause it, when started running for " "such interactive use in the most ordinary way, to print or display an " "announcement including an appropriate copyright notice and a notice " "that there is no warranty (or else, saying that you provide a warranty) " "and that users may redistribute the program under these conditions, and " "telling the user how to view a copy of this License. (Exception: if " "the Program itself is interactive but does not normally print such an " "announcement, your work based on the Program is not required to print " "an announcement.)"}, {butText_just, 0, ""}, {butText_just, 0, "These requirements apply to the modified work as a " "whole. If identifiable sections of that work are not derived from the " "Program, and can be reasonably considered independent and separate " "works in themselves, then this License, and its terms, do not apply to " "those sections when you distribute them as separate works. But when " "you distribute the same sections as part of a whole which is a work " "based on the Program, the distribution of the whole must be on the " "terms of this License, whose permissions for other licensees extend to " "the entire whole, and thus to each and every part regardless of who " "wrote it."}, {butText_just, 0, ""}, {butText_just, 0, "Thus, it is not the intent of this section to claim " "rights or contest your rights to work written entirely by you; rather, " "the intent is to exercise the right to control the distribution of " "derivative or collective works based on the Program."}, {butText_just, 0, ""}, {butText_just, 0, "In addition, mere aggregation of another work not based " "on the Program with the Program (or with a work based on the Program) " "on a volume of a storage or distribution medium does not bring the " "other work under the scope of this License."}, {butText_just, 0, ""}, {butText_just, 0, " 3. You may copy and distribute the Program (or a work " "based on it, under Section 2) in object code or executable form under " "the terms of Sections 1 and 2 above provided that you also do one of " "the following:"}, {butText_just, 0, ""}, {butText_just, 0, " a) Accompany it with the complete corresponding " "machine-readable source code, which must be distributed under the terms " "of Sections 1 and 2 above on a medium customarily used for software " "interchange; or,"}, {butText_just, 0, ""}, {butText_just, 0, " b) Accompany it with a written offer, valid for at " "least three years, to give any third party, for a charge no more than " "your cost of physically performing source distribution, a complete " "machine-readable copy of the corresponding source code, to be " "distributed under the terms of Sections 1 and 2 above on a medium " "customarily used for software interchange; or,"}, {butText_just, 0, ""}, {butText_just, 0, " c) Accompany it with the information you received " "as to the offer to distribute corresponding source code. (This " "alternative is allowed only for noncommercial distribution and only if " "you received the program in object code or executable form with such an " "offer, in accord with Subsection b above.)"}, {butText_just, 0, ""}, {butText_just, 0, "The source code for a work means the preferred form of " "the work for making modifications to it. For an executable work, " "complete source code means all the source code for all modules it " "contains, plus any associated interface definition files, plus the " "scripts used to control compilation and installation of the executable. " " However, as a special exception, the source code distributed need not " "include anything that is normally distributed (in either source or " "binary form) with the major components (compiler, kernel, and so on) of " "the operating system on which the executable runs, unless that " "component itself accompanies the executable."}, {butText_just, 0, ""}, {butText_just, 0, "If distribution of executable or object code is made by " "offering access to copy from a designated place, then offering " "equivalent access to copy the source code from the same place counts as " "distribution of the source code, even though third parties are not " "compelled to copy the source along with the object code."}, {butText_just, 0, ""}, {butText_just, 0, " 4. You may not copy, modify, sublicense, or " "distribute the Program except as expressly provided under this License. " " Any attempt otherwise to copy, modify, sublicense or distribute the " "Program is void, and will automatically terminate your rights under " "this License. However, parties who have received copies, or rights, " "from you under this License will not have their licenses terminated so " "long as such parties remain in full compliance."}, {butText_just, 0, ""}, {butText_just, 0, " 5. You are not required to accept this License, since " "you have not signed it. However, nothing else grants you permission to " "modify or distribute the Program or its derivative works. These " "actions are prohibited by law if you do not accept this License. " "Therefore, by modifying or distributing the Program (or any work based " "on the Program), you indicate your acceptance of this License to do so, " "and all its terms and conditions for copying, distributing or modifying " "the Program or works based on it."}, {butText_just, 0, ""}, {butText_just, 0, " 6. Each time you redistribute the Program (or any " "work based on the Program), the recipient automatically receives a " "license from the original licensor to copy, distribute or modify the " "Program subject to these terms and conditions. You may not impose any " "further restrictions on the recipients' exercise of the rights granted " "herein. You are not responsible for enforcing compliance by third " "parties to this License."}, {butText_just, 0, ""}, {butText_just, 0, " 7. If, as a consequence of a court judgment or " "allegation of patent infringement or for any other reason (not limited " "to patent issues), conditions are imposed on you (whether by court " "order, agreement or otherwise) that contradict the conditions of this " "License, they do not excuse you from the conditions of this License. " "If you cannot distribute so as to satisfy simultaneously your " "obligations under this License and any other pertinent obligations, " "then as a consequence you may not distribute the Program at all. For " "example, if a patent license would not permit royalty-free " "redistribution of the Program by all those who receive copies directly " "or indirectly through you, then the only way you could satisfy both it " "and this License would be to refrain entirely from distribution of the " "Program."}, {butText_just, 0, ""}, {butText_just, 0, "If any portion of this section is held invalid or " "unenforceable under any particular circumstance, the balance of the " "section is intended to apply and the section as a whole is intended to " "apply in other circumstances."}, {butText_just, 0, ""}, {butText_just, 0, "It is not the purpose of this section to induce you to " "infringe any patents or other property right claims or to contest " "validity of any such claims; this section has the sole purpose of " "protecting the integrity of the free software distribution system, " "which is implemented by public license practices. Many people have " "made generous contributions to the wide range of software distributed " "through that system in reliance on consistent application of that " "system; it is up to the author/donor to decide if he or she is willing " "to distribute software through any other system and a licensee cannot " "impose that choice."}, {butText_just, 0, ""}, {butText_just, 0, "This section is intended to make thoroughly clear what " "is believed to be a consequence of the rest of this License."}, {butText_just, 0, ""}, {butText_just, 0, " 8. If the distribution and/or use of the Program is " "restricted in certain countries either by patents or by copyrighted " "interfaces, the original copyright holder who places the Program under " "this License may add an explicit geographical distribution limitation " "excluding those countries, so that distribution is permitted only in or " "among countries not thus excluded. In such case, this License " "incorporates the limitation as if written in the body of this License."}, {butText_just, 0, ""}, {butText_just, 0, " 9. The Free Software Foundation may publish revised " "and/or new versions of the General Public License from time to time. " "Such new versions will be similar in spirit to the present version, but " "may differ in detail to address new problems or concerns."}, {butText_just, 0, ""}, {butText_just, 0, "Each version is given a distinguishing version number. " "If the Program specifies a version number of this License which applies " "to it and \"any later version\", you have the option of following the " "terms and conditions either of that version or of any later version " "published by the Free Software Foundation. If the Program does not " "specify a version number of this License, you may choose any version " "ever published by the Free Software Foundation."}, {butText_just, 0, ""}, {butText_just, 0, " 10. If you wish to incorporate parts of the Program " "into other free programs whose distribution conditions are different, " "write to the author to ask for permission. For software which is " "copyrighted by the Free Software Foundation, write to the Free Software " "Foundation; we sometimes make exceptions for this. Our decision will " "be guided by the two goals of preserving the free status of all " "derivatives of our free software and of promoting the sharing and reuse " "of software generally."}, {butText_just, 0, ""}, {butText_center, 0, "NO WARRANTY"}, {butText_just, 0, ""}, {butText_just, 0, " 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, " "THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY " "APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT " "HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM \"AS IS\" WITHOUT " "WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT " "LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A " "PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE " "OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU " "ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION."}, {butText_just, 0, ""}, {butText_just, 0, " 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR " "AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO " "MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE " "LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL " "OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE " "PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING " "RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A " "FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF " "SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH " "DAMAGES."}, {butText_just, 0, ""}, {butText_center, 0, "END OF TERMS AND CONDITIONS"}, {butText_just, 0, ""}, {butText_center, 0, XIO_PL1CHAR XIO_PL2CHAR XIO_PL1MARKCHAR XIO_PL2CHAR XIO_PL1CHAR}, {butText_just, 0, ""}, {0,0,NULL}}; static xio_tb_t copying_italian[] = { {butText_center, 1, "Pente " VERSION}, {butText_center, 0, "di Bill Shubert"}, {butText_center, 0, DATE_ITALIAN}, {butText_just, 0, ""}, {butText_just, 1, "Distribuzione"}, {butText_just, 0, " Questo programma è distribuito con la Gnu General " "Public License, versione 2. Questa dovrebbe essere inclusa nella vostra " "copia del codice sorgente in un file chiamato \"COPYING\". Ad ogni modo, " "la licenza è riportata anche qui di seguito."}, {butText_just, 0, " In sostanza, sono tre i punti di questa licenza che " "interesseranno la maggior parte di voi. Una è che potete distribuire " "delle copie ai vostri amici. Un'altra è che vi deve essere detto dove " "potete trovare il codice sorgente. Lo potete avere da me; leggete la " "pagina di aiuto \"A proposito dell'autore\" per sapere come contattarmi. " "L'ultima è che non c'è garanzia, quindi se questo programma vi rovina la " "vita, non venite a lamentarvi da me."}, {butText_just, 0, " Se volete fare qualcos'altro di questo programma, " "dovreste leggere la licenza che segue per i dettagli."}, {butText_just, 0, ""}, {butText_center, 0, "GNU GENERAL PUBLIC LICENSE"}, {butText_center, 0, "TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND " "MODIFICATION"}, {butText_just, 0, ""}, {butText_just, 0, " 0. This License applies to any program or other work " "which contains a notice placed by the copyright holder saying it may be " "distributed under the terms of this General Public License. The " "\"Program\", below, refers to any such program or work, and a \"work " "based on the Program\" means either the Program or any derivative work " "under copyright law: that is to say, a work containing the Program or a " "portion of it, either verbatim or with modifications and/or translated " "into another language. (Hereinafter, translation is included without " "limitation in the term \"modification\".) Each licensee is addressed " "as \"you\"."}, {butText_just, 0, ""}, {butText_just, 0, "Activities other than copying, distribution and " "modification are not covered by this License; they are outside its " "scope. The act of running the Program is not restricted, and the " "output from the Program is covered only if its contents constitute a " "work based on the Program (independent of having been made by running " "the Program). Whether that is true depends on what the Program does."}, {butText_just, 0, ""}, {butText_just, 0, " 1. You may copy and distribute verbatim copies of the " "Program's source code as you receive it, in any medium, provided that " "you conspicuously and appropriately publish on each copy an appropriate " "copyright notice and disclaimer of warranty; keep intact all the " "notices that refer to this License and to the absence of any warranty; " "and give any other recipients of the Program a copy of this License " "along with the Program."}, {butText_just, 0, ""}, {butText_just, 0, "You may charge a fee for the physical act of " "transferring a copy, and you may at your option offer warranty " "protection in exchange for a fee."}, {butText_just, 0, ""}, {butText_just, 0, " 2. You may modify your copy or copies of the Program " "or any portion of it, thus forming a work based on the Program, and " "copy and distribute such modifications or work under the terms of " "Section 1 above, provided that you also meet all of these " "conditions:"}, {butText_just, 0, ""}, {butText_just, 0, " a) You must cause the modified files to carry " "prominent notices stating that you changed the files and the date of " "any change."}, {butText_just, 0, ""}, {butText_just, 0, " b) You must cause any work that you distribute or " "publish, that in whole or in part contains or is derived from the " "Program or any part thereof, to be licensed as a whole at no charge to " "all third parties under the terms of this License."}, {butText_just, 0, ""}, {butText_just, 0, " c) If the modified program normally reads commands " "interactively when run, you must cause it, when started running for " "such interactive use in the most ordinary way, to print or display an " "announcement including an appropriate copyright notice and a notice " "that there is no warranty (or else, saying that you provide a warranty) " "and that users may redistribute the program under these conditions, and " "telling the user how to view a copy of this License. (Exception: if " "the Program itself is interactive but does not normally print such an " "announcement, your work based on the Program is not required to print " "an announcement.)"}, {butText_just, 0, ""}, {butText_just, 0, "These requirements apply to the modified work as a " "whole. If identifiable sections of that work are not derived from the " "Program, and can be reasonably considered independent and separate " "works in themselves, then this License, and its terms, do not apply to " "those sections when you distribute them as separate works. But when " "you distribute the same sections as part of a whole which is a work " "based on the Program, the distribution of the whole must be on the " "terms of this License, whose permissions for other licensees extend to " "the entire whole, and thus to each and every part regardless of who " "wrote it."}, {butText_just, 0, ""}, {butText_just, 0, "Thus, it is not the intent of this section to claim " "rights or contest your rights to work written entirely by you; rather, " "the intent is to exercise the right to control the distribution of " "derivative or collective works based on the Program."}, {butText_just, 0, ""}, {butText_just, 0, "In addition, mere aggregation of another work not based " "on the Program with the Program (or with a work based on the Program) " "on a volume of a storage or distribution medium does not bring the " "other work under the scope of this License."}, {butText_just, 0, ""}, {butText_just, 0, " 3. You may copy and distribute the Program (or a work " "based on it, under Section 2) in object code or executable form under " "the terms of Sections 1 and 2 above provided that you also do one of " "the following:"}, {butText_just, 0, ""}, {butText_just, 0, " a) Accompany it with the complete corresponding " "machine-readable source code, which must be distributed under the terms " "of Sections 1 and 2 above on a medium customarily used for software " "interchange; or,"}, {butText_just, 0, ""}, {butText_just, 0, " b) Accompany it with a written offer, valid for at " "least three years, to give any third party, for a charge no more than " "your cost of physically performing source distribution, a complete " "machine-readable copy of the corresponding source code, to be " "distributed under the terms of Sections 1 and 2 above on a medium " "customarily used for software interchange; or,"}, {butText_just, 0, ""}, {butText_just, 0, " c) Accompany it with the information you received " "as to the offer to distribute corresponding source code. (This " "alternative is allowed only for noncommercial distribution and only if " "you received the program in object code or executable form with such an " "offer, in accord with Subsection b above.)"}, {butText_just, 0, ""}, {butText_just, 0, "The source code for a work means the preferred form of " "the work for making modifications to it. For an executable work, " "complete source code means all the source code for all modules it " "contains, plus any associated interface definition files, plus the " "scripts used to control compilation and installation of the executable. " " However, as a special exception, the source code distributed need not " "include anything that is normally distributed (in either source or " "binary form) with the major components (compiler, kernel, and so on) of " "the operating system on which the executable runs, unless that " "component itself accompanies the executable."}, {butText_just, 0, ""}, {butText_just, 0, "If distribution of executable or object code is made by " "offering access to copy from a designated place, then offering " "equivalent access to copy the source code from the same place counts as " "distribution of the source code, even though third parties are not " "compelled to copy the source along with the object code."}, {butText_just, 0, ""}, {butText_just, 0, " 4. You may not copy, modify, sublicense, or " "distribute the Program except as expressly provided under this License. " " Any attempt otherwise to copy, modify, sublicense or distribute the " "Program is void, and will automatically terminate your rights under " "this License. However, parties who have received copies, or rights, " "from you under this License will not have their licenses terminated so " "long as such parties remain in full compliance."}, {butText_just, 0, ""}, {butText_just, 0, " 5. You are not required to accept this License, since " "you have not signed it. However, nothing else grants you permission to " "modify or distribute the Program or its derivative works. These " "actions are prohibited by law if you do not accept this License. " "Therefore, by modifying or distributing the Program (or any work based " "on the Program), you indicate your acceptance of this License to do so, " "and all its terms and conditions for copying, distributing or modifying " "the Program or works based on it."}, {butText_just, 0, ""}, {butText_just, 0, " 6. Each time you redistribute the Program (or any " "work based on the Program), the recipient automatically receives a " "license from the original licensor to copy, distribute or modify the " "Program subject to these terms and conditions. You may not impose any " "further restrictions on the recipients' exercise of the rights granted " "herein. You are not responsible for enforcing compliance by third " "parties to this License."}, {butText_just, 0, ""}, {butText_just, 0, " 7. If, as a consequence of a court judgment or " "allegation of patent infringement or for any other reason (not limited " "to patent issues), conditions are imposed on you (whether by court " "order, agreement or otherwise) that contradict the conditions of this " "License, they do not excuse you from the conditions of this License. " "If you cannot distribute so as to satisfy simultaneously your " "obligations under this License and any other pertinent obligations, " "then as a consequence you may not distribute the Program at all. For " "example, if a patent license would not permit royalty-free " "redistribution of the Program by all those who receive copies directly " "or indirectly through you, then the only way you could satisfy both it " "and this License would be to refrain entirely from distribution of the " "Program."}, {butText_just, 0, ""}, {butText_just, 0, "If any portion of this section is held invalid or " "unenforceable under any particular circumstance, the balance of the " "section is intended to apply and the section as a whole is intended to " "apply in other circumstances."}, {butText_just, 0, ""}, {butText_just, 0, "It is not the purpose of this section to induce you to " "infringe any patents or other property right claims or to contest " "validity of any such claims; this section has the sole purpose of " "protecting the integrity of the free software distribution system, " "which is implemented by public license practices. Many people have " "made generous contributions to the wide range of software distributed " "through that system in reliance on consistent application of that " "system; it is up to the author/donor to decide if he or she is willing " "to distribute software through any other system and a licensee cannot " "impose that choice."}, {butText_just, 0, ""}, {butText_just, 0, "This section is intended to make thoroughly clear what " "is believed to be a consequence of the rest of this License."}, {butText_just, 0, ""}, {butText_just, 0, " 8. If the distribution and/or use of the Program is " "restricted in certain countries either by patents or by copyrighted " "interfaces, the original copyright holder who places the Program under " "this License may add an explicit geographical distribution limitation " "excluding those countries, so that distribution is permitted only in or " "among countries not thus excluded. In such case, this License " "incorporates the limitation as if written in the body of this License."}, {butText_just, 0, ""}, {butText_just, 0, " 9. The Free Software Foundation may publish revised " "and/or new versions of the General Public License from time to time. " "Such new versions will be similar in spirit to the present version, but " "may differ in detail to address new problems or concerns."}, {butText_just, 0, ""}, {butText_just, 0, "Each version is given a distinguishing version number. " "If the Program specifies a version number of this License which applies " "to it and \"any later version\", you have the option of following the " "terms and conditions either of that version or of any later version " "published by the Free Software Foundation. If the Program does not " "specify a version number of this License, you may choose any version " "ever published by the Free Software Foundation."}, {butText_just, 0, ""}, {butText_just, 0, " 10. If you wish to incorporate parts of the Program " "into other free programs whose distribution conditions are different, " "write to the author to ask for permission. For software which is " "copyrighted by the Free Software Foundation, write to the Free Software " "Foundation; we sometimes make exceptions for this. Our decision will " "be guided by the two goals of preserving the free status of all " "derivatives of our free software and of promoting the sharing and reuse " "of software generally."}, {butText_just, 0, ""}, {butText_center, 0, "NO WARRANTY"}, {butText_just, 0, ""}, {butText_just, 0, " 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, " "THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY " "APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT " "HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM \"AS IS\" WITHOUT " "WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT " "LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A " "PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE " "OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU " "ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION."}, {butText_just, 0, ""}, {butText_just, 0, " 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR " "AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO " "MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE " "LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL " "OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE " "PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING " "RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A " "FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF " "SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH " "DAMAGES."}, {butText_just, 0, ""}, {butText_center, 0, "END OF TERMS AND CONDITIONS"}, {butText_just, 0, ""}, {butText_center, 0, XIO_PL1CHAR XIO_PL2CHAR XIO_PL1MARKCHAR XIO_PL2CHAR XIO_PL1CHAR}, {butText_just, 0, ""}, {0,0,NULL}}; xio_tb_t *xioStr_proghelp[] = {proghelp_eng, proghelp_french, proghelp_italian}; xio_tb_t *xioStr_gamehelp[] = {gamehelp_eng, gamehelp_french, gamehelp_italian}; xio_tb_t *xioStr_setuphelp[] = {setuphelp_eng, setuphelp_french, setuphelp_italian}; xio_tb_t *xioStr_networkhelp[] = {network_eng, network_french, network_italian}; xio_tb_t *xioStr_comphelp[] = {computer_eng, computer_french, computer_italian}; xio_tb_t *xioStr_abouthelp[] = {author_eng, author_french, author_italian}; xio_tb_t *xioStr_copyinghelp[] = {copying_eng, copying_french, copying_italian}; #endif /* X11_DISP */ pente-2.2.5/src/xio/pentebuts.c0100664000076400007640000002441707331147374014630 0ustar wmswms/* * src/xio/pentebuts.c, part of Pente (game program) * Copyright (C) 1994 William Shubert. * See "configure.h.in" for more copyright information. * * This code extends the wmslib/but library to add special buttons needed * for pente. */ #include #if X11_DISP #include #include #include #include #include "../pente.h" #include "xio.h" static ButOut grid_mmove(But *but, int x, int y); static ButOut grid_mleave(But *but); static ButOut grid_mpress(But *but, int butnum, int x, int y); static ButOut grid_mrelease(But *but, int butnum, int x, int y); static void grid_draw(But *but, int x,int y,int w,int h); static ButOut grid_destroy(But *but); static void grid_newflags(But *but, uint fl); static void cap_draw(But *but, int x,int y,int w,int h); static void drawp(ButWin *win, uint piece, int x, int y, int size, bool black_border); static void mark_piece(ButWin *win, uint piece, int x, int y, uint size); static ButOut cap_destroy(But *but); static ButOut gridNetPress(But *but, void *buf, int bufLen); typedef struct grid_t { bd_loc_t pos; uint ptype; /* The piece at this point on the board. */ bool marked; ButOut (*callback)(But *but); } grid_t; static ButAction grid_action = { grid_mmove, grid_mleave, grid_mpress, grid_mrelease, NULL, NULL, grid_draw, grid_destroy, grid_newflags, gridNetPress}; typedef struct cap_t { int threshold; uint caps; int player; } cap_t; static ButAction cap_action = { NULL, NULL, NULL, NULL, NULL, NULL, cap_draw, cap_destroy, but_flags, NULL}; But *but_grid_create(ButOut (*func)(But *but), ButWin *win, int layer, int flags, bd_loc_t pos) { grid_t *grid; But *but; grid = (grid_t *)wms_malloc(sizeof(grid_t)); but = but_create(win, grid, &grid_action); but->uPacket = &(grid->pos); but->layer = layer; but->flags = flags; grid->callback = func; grid->pos = pos; grid->ptype = BD_EMPTYA; but_init(but); return(but); } void but_grid_change(But *but, uint piece, bool marked) { grid_t *grid = but->iPacket; assert(but->action == &grid_action); grid->ptype = piece; grid->marked = marked; but_draw(but); } bd_loc_t but_grid_loc(But *but) { grid_t *grid = but->iPacket; assert(but->action == &grid_action); return(grid->pos); } static ButOut grid_destroy(But *but) { grid_t *grid = but->iPacket; wms_free(grid); return(0); } static void grid_newflags(But *but, uint fl) { uint ofl = but->flags; but->flags = fl; if ((ofl & (BUT_TWITCHED|BUT_PRESSED|BUT_NETTWITCH|BUT_NETPRESS)) != (fl & (BUT_TWITCHED|BUT_PRESSED|BUT_NETTWITCH|BUT_NETPRESS))) but_draw(but); } static ButOut grid_mmove(But *but, int x, int y) { uint newflags = but->flags, retval = BUTOUT_CAUGHT; if (!(but->flags & BUT_PRESSABLE)) return(BUTOUT_CAUGHT); if ((x < but->x) || (y < but->y) || (x >= but->x + but->w) || (y >= but->y + but->h)) { newflags &= ~BUT_TWITCHED; if (newflags != but->flags) { butEnv_setCursor(but->win->env, but, butCur_idle); but_newFlags(but, newflags); } if (!(newflags & BUT_LOCKED)) retval = 0; } else { newflags |= BUT_TWITCHED; if (newflags != but->flags) { butEnv_setCursor(but->win->env, but, butCur_twitch); but_newFlags(but, newflags); } } return(retval); } static ButOut grid_mleave(But *but) { int newflags = but->flags; newflags &= ~BUT_TWITCHED; if (newflags != but->flags) { butEnv_setCursor(but->win->env, but, butCur_idle); but_newFlags(but, newflags); } return(BUTOUT_CAUGHT); } static ButOut grid_mpress(But *but, int butnum, int x, int y) { int newflags = but->flags, retval = BUTOUT_CAUGHT; if (butnum == 1) newflags |= BUT_PRESSED|BUT_LOCKED; else retval |= BUTOUT_ERR; if (!(but->flags & BUT_PRESSED) && (newflags & BUT_PRESSED)) snd_play(&pe_move_snd); if (newflags != but->flags) but_newFlags(but, newflags); return(retval); } static ButOut grid_mrelease(But *but, int butnum, int x, int y) { int newflags = but->flags, retval = BUTOUT_CAUGHT; grid_t *grid = but->iPacket; if (butnum != 1) return(retval); if (but->flags & BUT_TWITCHED) { if (but->flags & BUT_PRESSED) { if (but->id) butRnet_butSpecSend(but, NULL, 0); retval |= grid->callback(but); } } else retval |= BUTOUT_ERR; newflags &= ~(BUT_PRESSED|BUT_LOCKED); if (newflags != but->flags) but_newFlags(but, newflags); return(retval); } static void grid_draw(But *but, int x,int y,int w,int h) { grid_t *grid = but->iPacket; uint piece = grid->ptype; uint inside, flags = but->flags; Display *dpy; if (BD_EMPTYP(piece) && !(flags & (BUT_TWITCHED|BUT_NETTWITCH))) return; dpy = but->win->env->dpy; inside = (but->w + 10) / 20; if (inside == 0) inside = 1; if (BD_PLAYERP(piece)) { drawp(but->win, piece, but->x, but->y, but->w, FALSE); if (grid->marked) { mark_piece(but->win, piece, but->x, but->y, but->w); } } else if ((flags & (BUT_PRESSED |BUT_NETPRESS)) && (flags & (BUT_TWITCHED|BUT_NETTWITCH))) { drawp(but->win, BD_PLAYER(xio_turn), but->x, but->y, but->w, FALSE); } else if (flags & (BUT_TWITCHED|BUT_NETTWITCH)) { drawp(but->win, BD_WINNER(xio_turn), but->x, but->y, but->w, FALSE); } } static ButOut gridNetPress(But *but, void *buf, int bufLen) { grid_t *grid = but->iPacket; assert(bufLen == 0); snd_play(&pe_move_snd); return(grid->callback(but)); } But *but_cap_create(ButWin *win, int layer, int flags, int capnum, int player) { But *but; cap_t *cnstore; cnstore = (cap_t *)wms_malloc(sizeof(cap_t)); but = but_create(win, cnstore, &cap_action); but->layer = layer; but->flags = flags; cnstore->threshold = capnum; cnstore->caps = 0; cnstore->player = player; but_init(but); return(but); } void but_cap_change(But *but, uint newcap) { cap_t *cap = but->iPacket; assert(but->action == &cap_action); cap->caps = newcap; but_draw(but); } static ButOut cap_destroy(But *but) { cap_t *cap = but->iPacket; wms_free(cap); return(0); } static void cap_draw(But *but, int x,int y,int w,int h) { cap_t *cap = but->iPacket; uint piece; if (cap->threshold > cap->caps) return; if (xio_gameover && (cap->caps < 5)) piece = BD_WINNER(cap->player); else piece = BD_PLAYER(cap->player); drawp(but->win, piece, but->x, but->y, but->w, FALSE); drawp(but->win, piece, but->x, but->y+but->w, but->w, FALSE); } void xio_draw_pl1char(void *packet, ButWin *win, int x, int y, int w, int h) { ButEnv *env = butWin_env(win); drawp(win, BD_PLAYER(0), x,y,w, TRUE); butEnv_setXFg(env, BUT_FG); } void xio_draw_pl2char(void *packet, ButWin *win, int x, int y, int w, int h) { ButEnv *env = butWin_env(win); drawp(win, BD_PLAYER(1), x,y,w, TRUE); butEnv_setXFg(env, BUT_FG); } void xio_draw_pl1markchar(void *packet, ButWin *win, int x, int y, int w, int h) { ButEnv *env = butWin_env(win); drawp(win, BD_PLAYER(0), x,y,w, TRUE); mark_piece(win, BD_PLAYER(0), x,y,w); butEnv_setXFg(env, BUT_FG); } void xio_draw_pl2markchar(void *packet, ButWin *win, int x, int y, int w, int h) { ButEnv *env = butWin_env(win); drawp(win, BD_PLAYER(1), x,y,w, TRUE); mark_piece(win, BD_PLAYER(1), x,y,w); butEnv_setXFg(env, BUT_FG); } static void drawp(ButWin *win, uint piece, int x, int y, int size, bool black_border) { int lwidth; ButEnv *env = win->env; Display *dpy = env->dpy; GC gc = env->gc; Xio *xio; lwidth = (size + 12) / 25; if (lwidth > 0) { xio = butEnv_packet(env); if (black_border && (xio->color == GrayScale)) butEnv_setXFg(env, XIO_PIC_BLACK); else if ((piece == BD_WINNER(0)) || (piece == BD_WINNER(1))) butEnv_setXFg(env, XIO_PIC_DIMOUTLINE); else butEnv_setXFg(env, XIO_PIC_OUTLINE); XFillArc(dpy, win->win, gc, x,y, size,size, 0, 360*64); } switch(piece) { case BD_PLAYER(0): butEnv_setXFg(env, XIO_PIC_PL1); break; case BD_PLAYER(1): butEnv_setXFg(env, XIO_PIC_PL2); break; case BD_WINNER(0): butEnv_setXFg(env, XIO_PIC_DIMPL1); break; case BD_WINNER(1): butEnv_setXFg(env, XIO_PIC_DIMPL2); break; } XFillArc(dpy, win->win, gc, x+lwidth,y+lwidth, size-2*lwidth,size-2*lwidth, 0, 360*64); } static void mark_piece(ButWin *win, uint piece, int x, int y, uint size) { int lwidth; uint point, dent, center; XPoint pset[9]; if (piece == BD_PLAYER(0)) butEnv_setXFg(win->env, XIO_PIC_MARK1); else if (piece == BD_PLAYER(1)) butEnv_setXFg(win->env, XIO_PIC_MARK2); else return; lwidth = (size + 12) / 25; if (lwidth < 1) return; XSetLineAttributes(win->env->dpy, win->env->gc, lwidth, LineSolid, CapProjecting, JoinMiter); /* point = (1*size+1)/3; * dent = (4*size+4)/9; */ point = (size+4)/9; dent = (size+13)/27; center = size / 2; x += center; y += center; pset[0].x = x - point; pset[0].y = y - point; pset[1].x = x; pset[1].y = y - dent; pset[2].x = x + point; pset[2].y = pset[0].y; pset[3].x = x + dent; pset[3].y = y; pset[4].x = pset[2].x; pset[4].y = y + point; pset[5].x = x; pset[5].y = y + dent; pset[6].x = pset[0].x; pset[6].y = pset[4].y; pset[7].x = x - dent; pset[7].y = y; pset[8] = pset[0]; XDrawLines(win->env->dpy, win->win, win->env->gc, pset, 9, CoordModeOrigin); } void xio_draw_comp(void *packet, ButWin *win, int x, int y, int w, int h) { XPoint points[4]; Display *dpy = butEnv_dpy(butWin_env(win)); Window xwin = butWin_xwin(win); GC gc = butEnv_gc(butWin_env(win)); int h2 = h/2, h3 = h/3, h12 = h/12; int w6 = w/6, w9 = w/9; y += (h - (h12+h2+h12+h3)) / 2; points[0].x = x; points[0].y = y+h12+h2+h3; points[1].x = x+w6; points[1].y = y+h12+h2+h12; points[2].x = x+w-w6; points[2].y = y+h12+h2+h12; points[3].x = x+w; points[3].y = y+h12+h2+h3; XFillPolygon(dpy, xwin, gc, points, 4, Nonconvex, CoordModeOrigin); XFillRectangle(dpy, xwin, gc, x+w6,y+h12, w-2*w6,h2); butEnv_setXFg(butWin_env(win), BUT_PBG); XFillRectangle(dpy, xwin, gc, x+w6+w9,y+h12*2, w-2*w6-2*w9,h2-h12*2); butEnv_setXFg(butWin_env(win), BUT_FG); } #endif pente-2.2.5/src/xio/cm2pm.c0100664000076400007640000000464707045637747013652 0ustar wmswms/* * src/xio/cm2pm.c, part of Pente (game program) * Copyright (C) 1994 William Shubert. * See "configure.h.in" for more copyright information. */ #include #ifdef X11_DISP #include #include #include #include "../pente.h" #include "xio.h" Pixmap cm2pm_chop(Xio *xio, uchar *cmap, uint cmapw,uint cmaph, uint w,uint h, int pic0, int npic, int gridw, int buth) { ButEnv *env = xio->env; int depth; Visual *v; Display *dpy; Window root; Pixmap p; int i, x, y, div, cmx, cmy; unsigned long clist[256*3]; XImage *im; int xaddmin, addstd, subextra, current, cadd; const int bevel_start = 55, avg = 0, hi = 256, lo = 512; int bevw = w / bevel_start; int caph, capw; if (gridw > 0) { caph = h - 2*buth; capw = (w - caph) / 2; } else { caph = h; capw = 0; } div = (256*1024) / npic; for (i = 0; i < 256; ++i) { clist[i] = butEnv_color(xio->env, pic0 + (i*1024)/div); clist[i+hi] = butEnv_color(xio->env, pic0 + (i*1024)/div + npic); clist[i+lo] = butEnv_color(xio->env, pic0 + (i*1024)/div + npic*2); } dpy = butEnv_dpy(env); v = DefaultVisual(dpy, DefaultScreen(dpy)); depth = DefaultDepth(dpy, DefaultScreen(dpy)); root = RootWindow(dpy, DefaultScreen(dpy)); im = butEnv_imageCreate(env, w, h); xaddmin = cmapw / w; addstd = cmapw - (xaddmin * w); subextra = w; current = 0; for (y = 0; y < h; ++y) { cmy = ((y * cmaph) / h) * cmapw; cmx = 0; for (x = 0; x < w; ++x) { if (y < bevw) { if (x < capw) cadd = avg; else if (x < capw-y) cadd = lo; else if (x < w-capw-y) cadd = hi; else if (x < w-capw) cadd = lo; else cadd = avg; } else if (y < caph-bevw) { if (x < capw) cadd = avg; else if (x < capw+bevw) cadd = hi; else if (x < w-capw-bevw) cadd = avg; else if (x < w-capw) cadd = lo; else cadd = avg; } else if (y < caph) { if (x < capw) cadd = avg; else if (x < caph-y) cadd = lo; else if (x < capw+caph-y) cadd = hi; else if (x < w-capw) cadd = lo; else cadd = avg; } else cadd = avg; XPutPixel(im, x, y, clist[cmap[cmx+cmy]+cadd]); cmx += xaddmin; current += addstd; if (current > 0) { ++cmx; current -= subextra; } } } p = XCreatePixmap(dpy, root, w,h, depth); XPutImage(dpy, p, env->gc, im, 0,0,0,0,w,h); butEnv_imageDestroy(im); return(p); } #endif pente-2.2.5/src/xio/setup.c0100664000076400007640000003435407045637747013772 0ustar wmswms/* * src/xio/setup.c, part of Pente (game program) * Copyright (C) 1994-1995 William Shubert. * See "configure.h.in" for more copyright information. * * Routines to manage the setup window. */ #include #if X11_DISP #include #include #include #include #include #include #include #include #include #include #include #include #include "../pente.h" #include "xio.h" #include "setup.h" #include "sound.h" #include "helpwin.h" #include "remAcc.h" #define MAX_PORTNAME_LEN 50 static char portName[MAX_PORTNAME_LEN+1]; static bool wait_for_open = FALSE; static ButOut unmap(ButWin *win); static ButOut resize(ButWin *win); static ButOut destroy(ButWin *win); static ButOut ok_pressed(But *but); static ButOut connPressed(But *but); static ButOut lang_pressed(But *but, int value); static ButOut help_pressed(But *but); static ButOut color_pressed(But *but, int value); static ButOut remote_toggle(But *but, int value); static ButOut volset(But *but, int val, bool newPress); static ButOut newSocket(But *but, const char *value); static ButOut showThinkPressed(But *but, bool val); XioSetup *xioSetup_create(Xio *xio) { XioSetup *swin; static ButKey ka_ok[] = {{XK_Return, 0,0}, {XK_KP_Enter, 0,0}, {0,0,0}}; static ButKey helpkeys[] = {{XK_H, 0,0}, {XK_h, 0,0}, {XK_Help, 0,0}, {XK_question, 0,0}, {0,0,0}}; static ButKey soundkeys[] = {{XK_S, 0,0}, {XK_s, 0,0}, {0,0,0}}; ButWin *win; char geometry[100]; int w, h, minh; if (xio->swin && !wait_for_open) { XRaiseWindow(butEnv_dpy(xio->env), butWin_xwin(xio->swin->win)); return(xio->swin); } w = butWin_w(xio->mainwin); h = (int)(butWin_h(xio->mainwin)*0.61803399+0.5); swin = malloc(sizeof(XioSetup)); if (w == 0) { /* Main window hasn't been opened! */ wait_for_open = TRUE; return(swin); } else wait_for_open = FALSE; swin->xio = xio; ++xio->openWindows; clp_setBool(pe_clp, "x.setup", TRUE); minh = (but_h(xio->helpbut)*4+butEnv_stdBw(xio->env)*9) * 2; if (h < minh) h = minh; sprintf(geometry, "%dx%d%s", w, h, clp_getStr(pe_clp, "x.setup.geom")); win = swin->win = butWin_create(swin, xio->env, "Pente Setup", w, h, unmap, NULL, resize, destroy); butWin_activate(win); swin->xio = xio; swin->mainbox = butBoxFilled_create(win, 0, BUT_DRAWABLE); butBoxFilled_setColors(swin->mainbox, xio->litColor, xio->shadColor, xio->bgColor); swin->title = butText_create(win, 1, BUT_DRAWABLE, xioStr_pentesetup[xio->lang], butText_center); butText_setFont(swin->title, 1); /* Bold. */ swin->box1 = butBox_create(win, 1, BUT_DRAWABLE); butBox_setColors(swin->box1, xio->litColor, xio->shadColor); swin->langs = butMenu_downCreate(lang_pressed, xio, win, 1, 2, BUT_DRAWABLE|BUT_PRESSABLE, xioStr_language[xio->lang], xioStr_langlist[xio->lang], xio->lang); swin->colorb = butCb_create(color_pressed, xio, win, 1, BUT_PRESSABLE|BUT_DRAWABLE, (xio->color != GrayScale)); swin->colorl = butText_create(win, 1, BUT_DRAWABLE, xioStr_color[xio->lang], butText_left); swin->showThinkBox = butCb_create(showThinkPressed, xio, win, 1, BUT_PRESSABLE|BUT_DRAWABLE, clp_getBool(pe_clp, "showthink")); swin->showThinkTxt = butText_create(win, 1, BUT_DRAWABLE, xioStr_showThink[xio->lang], butText_right); swin->box2 = butBox_create(win, 1, BUT_DRAWABLE); butBox_setColors(swin->box2, xio->litColor, xio->shadColor); swin->svt1 = butText_create(win, 1, BUT_DRAWABLE, xioStr_soundvol[xio->lang], butText_center); swin->svoff = butText_create(win, 1, BUT_DRAWABLE, xioStr_off[xio->lang], butText_left); swin->svmax = butText_create(win, 1, BUT_DRAWABLE, xioStr_max[xio->lang], butText_right); swin->svbar = butSlide_hCreate(volset, xio, win, 1, BUT_DRAWABLE|BUT_PRESSABLE, SND_MAXVOL, xio->sound.volume, (SND_MAXVOL+9)/10); swin->svout = butText_create(win, 1, BUT_DRAWABLE, "---%", butText_center); swin->svtoggle = butKeytrap_create(xioSound_toggle, xio, win, BUT_DRAWABLE|BUT_PRESSABLE); but_setKeys(swin->svtoggle, soundkeys); xioSetup_newVol(swin, butSlide_get(swin->svbar)); swin->box3 = butBox_create(win, 1, BUT_DRAWABLE); butBox_setColors(swin->box3, xio->litColor, xio->shadColor); swin->ttlab = butText_create(win, 1, BUT_DRAWABLE, xioStr_transtab[xio->lang], butText_center); butText_setColor(swin->ttlab, BUT_FG, TRUE); swin->ttsize = butText_create(win, 1, BUT_DRAWABLE, xioStr_size[xio->lang], butText_left); butText_setColor(swin->ttsize, BUT_FG, TRUE); swin->ttsizedown = butAct_create(NULL, xio, win, 1, BUT_DRAWABLE, "-", BUT_ALEFT|BUT_SRIGHT); swin->ttsizebox = butBox_create(win, 1, BUT_DRAWABLE); butBox_setColors(swin->ttsizebox, BUT_SHAD, BUT_LIT); swin->ttsizeout = butText_create(win, 2, BUT_DRAWABLE, xioStr_disabled[xio->lang], butText_right); butText_setColor(swin->ttsizeout, BUT_FG, TRUE); swin->ttsizebg = butPlain_create(win, 1, BUT_DRAWABLE, BUT_ENTERBG); swin->ttsizeup = butAct_create(NULL, xio, win, 1, BUT_DRAWABLE, "+", BUT_SLEFT|BUT_ARIGHT); swin->ttauto = butCt_create(NULL, xio, win, 1, BUT_DRAWABLE, xioStr_autosize[xio->lang]); swin->box4 = butBox_create(win, 1, BUT_DRAWABLE); butBox_setColors(swin->box4, xio->litColor, xio->shadColor); swin->remote = butText_create(win, 1, BUT_DRAWABLE, xioStr_netplay[xio->lang], butText_center); swin->rmchk = butCb_create(remote_toggle, xio, win, 1, BUT_DRAWABLE | BUT_PRESSABLE, clp_getBool(pe_clp, "x.remote.enabled")); swin->rmchklab = butText_create(win, 1, BUT_DRAWABLE, xioStr_enabled[xio->lang], butText_left); swin->rmsock = butText_create(win, 1, BUT_DRAWABLE, xioStr_socket[xio->lang], butText_left); swin->rmConn = butCt_create(connPressed, xio, win, 1, BUT_DRAWABLE|BUT_PRESSABLE, ""); xioSetup_remoteRelabel(swin); swin->rmsockin = butTextin_create(newSocket, xio, win, 1, BUT_DRAWABLE|BUT_PRESSABLE, clp_getStr(pe_clp, "x.remote.lsock"), MAX_PORTNAME_LEN); swin->ok = butCt_create(ok_pressed, xio, win, 1, BUT_DRAWABLE|BUT_PRESSABLE, xioStr_ok[xio->lang]); but_setKeys(swin->ok, ka_ok); swin->help = butCt_create(help_pressed, NULL, win, 1, BUT_DRAWABLE|BUT_PRESSABLE, xioStr_help[xio->lang]); but_setKeys(swin->help, helpkeys); return(swin); } void xioSetup_resize(XioSetup *swin) { Xio *xio; int winw; int w, h, minh; if (swin) { xio = swin->xio; if (wait_for_open) xioSetup_create(xio); winw = butWin_w(xio->mainwin); w = winw; h = (int)(winw * 0.61803399 + 0.5); minh = (but_h(xio->helpbut)*4+butEnv_stdBw(xio->env)*9) * 2; if (h < minh) h = minh; butWin_resize(swin->win, winw, h); } } static ButOut unmap(ButWin *win) { clp_setBool(pe_clp, "x.setup", FALSE); butWin_destroy(win); return(0); } static ButOut resize(ButWin *win) { int w, h, ax, ay, aw, ah, buth, i, j; XioSetup *swin; Xio *xio; int bw; ButEnv *env; swin = butWin_packet(win); env = butWin_env(win); bw = butEnv_stdBw(env); xio = butEnv_packet(env); buth = but_h(xio->helpbut); w = butWin_w(win); h = butWin_h(win); but_resize(swin->mainbox, 0,0, w,h); but_resize(swin->title, bw,bw, w-bw*2,buth+bw*2); ax = bw; ay = bw*3+buth; aw = w/2-bw, ah = h/2-(bw*3+buth); but_resize(swin->box1, ax, ay, aw, ah); but_resize(swin->langs, ax+bw*2, ay+bw*2, aw-bw*4, buth*2); but_resize(swin->colorb, ax+bw*2, ay+buth*2+bw*3, buth, buth); butText_resize(swin->colorl, ax+bw*3+buth, ay+buth*2+bw*3, buth); but_resize(swin->showThinkBox, ax+aw-bw*2-buth, ay+buth*2+bw*3, buth, buth); butText_resize(swin->showThinkTxt, ax+aw-bw*3-buth, ay+buth*2+bw*3, buth); ax = bw; ay = h/2; aw = w/2-bw, ah = h-(h/2)-(bw*3+buth); but_resize(swin->box2, ax,ay, aw,ah); but_resize(swin->svt1, ax+bw*2, ay+bw*2, aw-bw*4, buth); i = butText_resize(swin->svoff, ax+bw*2, ay+bw*3+buth, buth); j = butText_resize(swin->svmax, ax+aw-bw*2, ay+bw*3+buth, buth); but_resize(swin->svbar, ax+bw*3+i, ay+bw*3+buth, aw-bw*6-i-j, buth); but_resize(swin->svout, ax+bw*3, ay+bw*4+buth*2, aw-bw*6, buth); ax = w/2; ay = bw*3+buth; aw = w-w/2-bw, ah = h/2-(bw*3+buth); but_resize(swin->box3, ax,ay, aw,ah); but_resize(swin->ttlab, ax+bw*2, ay+bw*2, aw-bw*4, buth); i = butText_resize(swin->ttsize, ax+bw*2, ay+bw*3+buth, buth); i += bw * 3; but_resize(swin->ttsizedown, ax+i, ay+bw*3+buth, buth,buth); but_resize(swin->ttsizebox, ax+i+buth, ay+bw*3+buth, aw-i-buth*2-bw*2, buth); but_resize(swin->ttsizeout, ax+i+buth+bw*2, ay+bw*3+buth+bw, aw-i-buth*2-bw*6, buth-bw*2); but_resize(swin->ttsizebg, ax+i+buth+bw, ay+bw*3+buth+bw, aw-i-buth*2-bw*4, buth-bw*2); but_resize(swin->ttsizeup, ax+aw-buth-bw*2, ay+bw*3+buth, buth,buth); but_resize(swin->ttauto, ax+bw*2,ay+bw*4+buth*2, aw-bw*4,buth); ax = w/2; ay = h/2; aw = w-w/2-bw, ah = h-h/2-(bw*3+buth); but_resize(swin->box4, ax,ay, aw,ah); but_resize(swin->remote, ax+bw*2, ay+bw*2, aw-bw*4, buth); but_resize(swin->rmchk, ax+bw*2, ay+bw*3+buth, buth, buth); but_resize(swin->rmchklab, ax+bw*3+buth, ay+bw*3+buth, aw/2-bw*3-buth, buth); but_resize(swin->rmConn, ax+(aw+bw)/2, ay+bw*3+buth, aw-(aw+bw)/2-bw*2, buth); i = butText_resize(swin->rmsock, ax+bw*2, ay+bw*4+buth*2, buth); but_resize(swin->rmsockin, ax+bw*3+i, ay+bw*4+buth*2, aw-bw*5-i, buth); but_resize(swin->ok, bw*2, h-buth-bw*2, (w-bw*5)/2, buth); but_resize(swin->help, (w-bw*5)/2+bw*3, h-buth-bw*2, w-(w-bw*5)/2-bw*5, buth); return(0); } static ButOut ok_pressed(But *but) { Xio *xio = butEnv_packet(butWin_env(but_win(but))); ButOut retVal = 0; clp_setBool(pe_clp, "x.setup", FALSE); /* * If listening is enabled AND the user has typed in a new socket, * then try opening it. */ if (strcmp(clp_getStr(pe_clp, "x.remote.lsock"), butTextin_get(xio->swin->rmsockin))) { strcpy(portName, butTextin_get(xio->swin->rmsockin)); clp_setStr(pe_clp, "x.remote.lsock", portName); clp_setBool(pe_clp, "x.remote.wanted", TRUE); clp_setBool(pe_clp, "x.remote.enabled", TRUE); if (!xio_r_init(xio)) { retVal = BUTOUT_ERR; } } butWin_destroy(but_win(but)); return(retVal); } static ButOut help_pressed(But *but) { Xio *xio = butEnv_packet(butWin_env(but_win(but))); xio->hwin = xioHelp_create(xio, 2); return(0); } static ButOut color_pressed(But *but, int value) { Xio *xio = butEnv_packet(butWin_env(but_win(but))); clp_setBool(pe_clp, "wasColor", xio_color = value); clp_setBool(pe_clp, "color", value); xio->restart_x = TRUE; return(BUTOUT_STOPWAIT); } static ButOut lang_pressed(But *but, int value) { Xio *xio = butEnv_packet(butWin_env(but_win(but))); if (xio->lang != value) { xio->lang = value; clp_setStr(pe_clp, "language", xioStr_langlist[0][value]); xio->restart_x = TRUE; } return(BUTOUT_STOPWAIT); } static ButOut destroy(ButWin *win) { Xio *xio = butEnv_packet(butWin_env(win)); static char geom[30]; --xio->openWindows; xio->swin = NULL; xioSound_check(xio); sprintf(geom, "+%d+%d", butWin_x(win), butWin_y(win)); clp_setStr(pe_clp, "x.setup.geom", geom); xioSound_check(xio); return(0); } static ButOut volset(But *but, int newvol, bool newPress) { int percent; XioSetup *swin = butWin_packet(but_win(but)); char text[5]; if (newPress) xioSound_showErr(swin->xio); /* Round percent up so that it only says 0% if it's REALLY at zero. */ percent = (newvol*100+SND_MAXVOL-1)/SND_MAXVOL; sprintf(text, "%d%%", (newvol*100+SND_MAXVOL/2)/SND_MAXVOL); butText_set(swin->svout, text); xioSound_setVol(swin->xio, newvol, newPress); return(0); } static ButOut remote_toggle(But *but, int value) { Xio *xio = butEnv_packet(butWin_env(but_win(but))); clp_setBool(pe_clp, "x.remote.wanted", value); clp_setBool(pe_clp, "x.remote.enabled", value); but_setFlags(xio->swin->rmsockin, BUT_NOKEY); if (value) { if (xio_r_init(xio)) return(0); butCb_set(but, FALSE, FALSE); return(BUTOUT_ERR); } else xio_r_disable(xio); return(0); } static ButOut newSocket(But *but, const char *value) { Xio *xio = butEnv_packet(butWin_env(but_win(but))); but_setFlags(but, BUT_NOKEY); clp_setBool(pe_clp, "x.remote.enabled", TRUE); clp_setBool(pe_clp, "x.remote.wanted", TRUE); if (xio_r_init(xio)) { butCb_set(xio->swin->rmchk, TRUE, FALSE); return(0); } else { butCb_set(xio->swin->rmchk, FALSE, FALSE); return(BUTOUT_ERR); } } ButOut connPressed(But *but) { Xio *xio = butEnv_packet(butWin_env(but_win(but))); if (xio->rnet || xio->remAcc || xio->waitWindow) { /* We already have a connection open, so we'll press disconnect! */ if (xio->rnet) { butRnet_destroy(xio->rnet, xioStr_netClosed[xio->lang]); xio->rnet = NULL; } if (xio->remAcc) { xioRemAcc_destroy(xio->remAcc); xio->remAcc = NULL; } if (xio->waitWindow) { abutMsg_destroy(xio->waitWindow, TRUE); xio->waitWindow = NULL; } } else xio_r_create(butEnv_packet(butWin_env(but_win(but)))); xioSetup_remoteRelabel(xio->swin); return(0); } void xioSetup_freshPortName(XioSetup *swin) { if (swin && !wait_for_open) { strcpy(portName, butTextin_get(swin->rmsockin)); clp_setStr(pe_clp, "x.remote.lsock", portName); } } void xioSetup_newVol(struct XioSetup_struct *swin, int vol) { char text[5]; if (swin) { butSlide_set(swin->svbar, BUT_NOCHANGE, vol, BUT_NOCHANGE); sprintf(text, "%d%%", (vol*100+SND_MAXVOL/2)/SND_MAXVOL); butText_set(swin->svout, text); } } static ButOut showThinkPressed(But *but, bool val) { clp_setBool(pe_clp, "showthink", val); xio_think(PE_REDO, -1); return(0); } void xioSetup_remoteRelabel(XioSetup *swin) { Xio *xio; if (swin) { xio = swin->xio; if (xio->rnet || xio->remAcc || xio->waitWindow) butCt_setText(swin->rmConn, xioStr_disconnect[xio->lang]); else butCt_setText(swin->rmConn, xioStr_connect[xio->lang]); } } #endif /* X11_DISP */ pente-2.2.5/src/xio/remote.c0100664000076400007640000003472007045637747014122 0ustar wmswms/* * src/xio/remote.c, part of Pente (game program) * Copyright (C) 1994-1995 William Shubert. * See "configure.h.in" for more copyright information. * * Routines to manage remote connections. */ #include #if X11_DISP #include #include #include "../pente.h" #include #include #include #include #include #include #include #include #include #include #include #include "xio.h" #include "setup.h" #include "remAcc.h" #include "helpwin.h" #include "sound.h" typedef struct xioRemote_struct { int name; Xio *xio; ButWin *win; But *box, *title; But *mlab, *mtxtin; But *plab, *ptxtin; But *ok, *help, *cancel; MAGIC_STRUCT } xioRemote; static int xio_r_connect(Xio *xio); static ButOut newRemote(ButRnet *net); static ButOut remoteAccepted(ButRnet *net); static ButOut unmap(ButWin *win); static ButOut resize(ButWin *win); static ButOut destroy(ButWin *win); static int parsePort(Xio *xio, const char *portStr, bool reportErrors); static ButOut okPressed(But *but); static ButOut helpPressed(But *but); static ButOut cancelPressed(But *but); static ButOut newm(But *but, const char *value); static ButOut newp(But *but, const char *value); static ButOut newMenu(ButRnet *net, void *msg, int msgLen); static ButOut forceClose(ButRnet *net, const char *reason); static ButOut waitClosed(void *packet); static ButOut stopWaiting(But *but); static void createWaitingWindow(Xio *xio); static ButOut netInfo(ButRnet *net, void *msg, int msgLen); static ButOut remoteComp(ButRnet *net, void *msg, int msgLen); static ButKey soundkeys[] = {{XK_S, 0,0}, {XK_s, 0,0}, {0,0,0}}; #define MAX_MACHNAME_SIZE 100 #define MAX_PORTNAME_SIZE 50 static char mName[MAX_MACHNAME_SIZE+1]; static char pName[MAX_PORTNAME_SIZE+1]; bool xio_r_init(Xio *xio) { char errmsg[500]; const char *sock; int portNum; ClpEntry *eWant, *eHas; #if !HAVE_SOCKETS return(FALSE); /* NOTREACHED */ #endif xio_r_disable(xio); xioSetup_freshPortName(xio->swin); eWant = clp_lookup(pe_clp, "x.remote.wanted"); eHas = clp_lookup(pe_clp, "x.remote.enabled"); if (!clpEntry_getBool(eWant)) return(FALSE); portNum = parsePort(xio, sock = clp_getStr(pe_clp, "x.remote.lsock"), clpEntry_getBool(eHas)); if (portNum < 0) return(FALSE); xio->lnet = butLnet_create(xio->env, portNum, xio, newRemote, netInfo, forceClose); if (butLnet_error(xio->lnet)) { if ((butLnet_errNum(xio->lnet) == EACCES) && (portNum < IPPORT_RESERVED)) { sprintf(errmsg, xioStr_errProtSocket[xio->lang], sock, IPPORT_RESERVED); } else if (butLnet_errNum(xio->lnet) == EADDRINUSE) { sprintf(errmsg, xioStr_errSockInUse[xio->lang], sock); } else { sprintf(errmsg, xioStr_errLSockGeneric[xio->lang], sock, strerror(butLnet_errNum(xio->lnet))); } if (clpEntry_getBool(eHas)) { clpEntry_setBool(eHas, FALSE); abutMsg_winCreate(xio->abut, "Pente Error", errmsg); XBell(butEnv_dpy(xio->env), 0); } butLnet_destroy(xio->lnet); xio->lnet = NULL; xioSetup_newRemoteEnable(xio->swin, FALSE); return(FALSE); } else { clpEntry_setBool(eHas, TRUE); xioSetup_newRemoteEnable(xio->swin, TRUE); return(TRUE); } } void xio_r_disable(Xio *xio) { if (xio->lnet) { butLnet_destroy(xio->lnet); xio->lnet = NULL; } } static bool xio_r_connect(Xio *xio) { char errmsg[500]; const char *sock, *mach; int port; port = parsePort(xio, sock = clp_getStr(pe_clp, "x.remote.rsock"), TRUE); if (port < 0) { return(FALSE); } xio->rnet = butRnet_create(xio->env, mach = clp_getStr(pe_clp, "x.remote.rname"), port, xio, remoteAccepted, netInfo, forceClose); if (butRnet_error(xio->rnet)) { if (butRnet_errNum(xio->rnet) == ECONNREFUSED) { sprintf(errmsg, xioStr_errRSockRefused[xio->lang], mach, sock); } else { sprintf(errmsg, xioStr_errRSockGeneric[xio->lang], strerror(butRnet_errNum(xio->rnet)), sock, mach); } abutMsg_winCreate(xio->abut, "Pente Error", errmsg); butRnet_destroy(xio->rnet, NULL); xio->rnet = NULL; return(FALSE); } else if (butRnet_lookupError(xio->rnet)) { if (butRnet_errNum(xio->rnet) == TRY_AGAIN) { sprintf(errmsg, xioStr_errHostTemp[xio->lang], mach); } else { sprintf(errmsg, xioStr_errHostPerm[xio->lang], mach); } abutMsg_winCreate(xio->abut, "Pente Error", errmsg); butRnet_destroy(xio->rnet, NULL); xio->rnet = NULL; return(FALSE); } else { createWaitingWindow(xio); return(TRUE); } } static void createWaitingWindow(Xio *xio) { AbutMsgOpt buts[1]; buts[0].name = xioStr_cancel[xio->lang]; buts[0].callback = stopWaiting; buts[0].packet = xio; buts[0].keyEq = NULL; xio->waitWindow = abutMsg_winOptCreate(xio->abut, "Pente: Waiting for Accept", xioStr_netWait[xio->lang], waitClosed, xio, 1, buts); } static ButOut waitClosed(void *packet) { Xio *xio = packet; if (xio->rnet != NULL) { if (!butRnet_valid(xio->rnet)) { butRnet_destroy(xio->rnet, xioStr_netClosed[xio->lang]); xio->rnet = NULL; } } xio->waitWindow = NULL; xioSetup_remoteRelabel(xio->swin); return(0); } static ButOut stopWaiting(But *but) { Xio *xio = but_packet(but); abutMsg_destroy(xio->waitWindow, TRUE); return(0); } void xio_r_create(Xio *xio) { int w, h; static ButKey ka_ok[] = {{XK_Return, 0,0}, {XK_KP_Enter, 0,0}, {0,0,0}}; static ButKey helpkeys[] = {{XK_H, 0,0}, {XK_h, 0,0}, {XK_Help, 0,0}, {XK_question, 0,0}, {0,0,0}}; static ButKey cancelkeys[] = {{XK_Escape, 0,0}, {XK_Break, 0,0}, {0,0,0}}; xioRemote *rwin; ButWin *win; char geometry[100]; But *svTog; #if !HAVE_SOCKETS abutMsg_winCreate(xio->abut, "Pente Error", xioStr_noSockets[xio->lang]); return; /* NOTREACHED */ #endif if (xio->rwin != NULL) { assert(MAGIC(xio->rwin)); XRaiseWindow(butEnv_dpy(xio->env), butWin_xwin(xio->rwin->win)); return; } xio->rwin = rwin = (xioRemote *)wms_malloc(sizeof(xioRemote)); MAGIC_SET(rwin); rwin->xio = xio; xioSetup_remoteRelabel(xio->swin); w = (butWin_w(xio->mainwin)*2)/3; h = w/2; if (w == 0) return; /* How did I get here? */ sprintf(geometry, "%dx%d", w, h); rwin->win = win = butWin_create(rwin, xio->env, "Pente Networking", w, h, unmap, NULL, resize, destroy); butWin_activate(win); rwin->box = butBoxFilled_create(rwin->win, 0, BUT_DRAWABLE); rwin->title = butText_create(win, 1, BUT_DRAWABLE, xioStr_netConn[xio->lang], butText_center); butText_setFont(rwin->title, 1); rwin->mlab = butText_create(win, 1, BUT_DRAWABLE, xioStr_machine[xio->lang], butText_left); rwin->mtxtin = butTextin_create(newm, xio, win, 1, BUT_DRAWABLE|BUT_PRESSABLE, clp_getStr(pe_clp, "x.remote.rname"), MAX_MACHNAME_SIZE); rwin->plab = butText_create(win, 1, BUT_DRAWABLE, xioStr_socket[xio->lang], butText_left); rwin->ptxtin = butTextin_create(newp, xio, win, 1, BUT_DRAWABLE|BUT_PRESSABLE, clp_getStr(pe_clp, "x.remote.rsock"), MAX_PORTNAME_SIZE); rwin->help = butCt_create(helpPressed, xio, win, 1, BUT_DRAWABLE | BUT_PRESSABLE, xioStr_help[xio->lang]); but_setKeys(rwin->help, helpkeys); rwin->ok = butCt_create(okPressed, xio, win, 1, BUT_DRAWABLE|BUT_PRESSABLE, xioStr_ok[xio->lang]); but_setKeys(rwin->ok, ka_ok); rwin->cancel = butCt_create(cancelPressed, xio, win, 1, BUT_DRAWABLE | BUT_PRESSABLE, xioStr_cancel[xio->lang]); but_setKeys(rwin->cancel, cancelkeys); butBoxFilled_setColors(rwin->box, xio->litColor, xio->shadColor, xio->bgColor); svTog = butKeytrap_create(xioSound_toggle, xio, win, BUT_DRAWABLE|BUT_PRESSABLE); but_setKeys(svTog, soundkeys); } static ButOut unmap(ButWin *win) { butWin_destroy(win); return(0); } static ButOut newm(But *but, const char *value) { Xio *xio = but_packet(but); but_setFlags(xio->rwin->ptxtin, BUT_KEYED); return(0); } static ButOut newp(But *but, const char *value) { Xio *xio = but_packet(but); but_setFlags(but, BUT_NOKEY); return(okPressed(xio->rwin->ok)); } static ButOut resize(ButWin *win) { int w, h; xioRemote *rwin = butWin_packet(win); Xio *xio = rwin->xio; int butbw = butEnv_stdBw(xio->env); int buth = but_h(xio->helpbut); int rowh, border, mY, pY; int mW, pW, maxW, butw; assert(MAGIC(rwin)); w = butWin_w(win); h = butWin_h(win); rowh = h - 4*butbw - 2*buth; border = (rowh - 2*buth) / 3; mY = 2*butbw + buth + border; pY = mY + border + buth; but_resize(rwin->box, 0,0, w,h); butText_resize(rwin->title, w/2,butbw*2, buth); mW = butText_resize(rwin->mlab, butbw*2,mY, buth); pW = butText_resize(rwin->plab, butbw*2,pY, buth); if (mW > pW) maxW = mW; else maxW = pW; but_resize(rwin->mtxtin, butbw*3+maxW,mY, w-butbw*5-maxW,buth); but_resize(rwin->ptxtin, butbw*3+maxW,pY, w-butbw*5-maxW,buth); butw = (w - butbw*6)/3; but_resize(rwin->ok, butbw*2,h-buth-2*butbw, butw,buth); but_resize(rwin->help, butbw*3+butw,h-buth-2*butbw, (w-butbw*6-butw*2),buth); but_resize(rwin->cancel, butbw*4+butw*2,h-buth-2*butbw, butw,buth); return(0); } static ButOut destroy(ButWin *win) { Xio *xio = butEnv_packet(butWin_env(win)); xioRemote *rwin = butWin_packet(win); assert(MAGIC(rwin)); MAGIC_UNSET(rwin); wms_free(rwin); xio->rwin = NULL; xioSetup_remoteRelabel(xio->swin); return(0); } static ButOut newRemote(ButRnet *net) { Xio *xio = butRnet_packet(net); if (strncmp(butRnet_protocol(net), "pente", 5)) butRnet_destroy(net, "Wrong protocol; expecting pente"); else if (xio->rnet) butRnet_destroy(net, "Remote user is already playing network pente " "against another player"); else { xio->rnet = net; xioRemAcc_create(net); } return(0); } static ButOut remoteAccepted(ButRnet *net) { Xio *xio = butRnet_packet(net); char msg[2]; if (strncmp(butRnet_protocol(net), "pente", 5)) { butRnet_destroy(net, "Wrong protocol; expecting pente"); xio->rnet = NULL; } abutMsg_destroy(xio->waitWindow, TRUE); xio->waitWindow = NULL; msg[0] = '0' + butMenu_get(xio->menu1); msg[1] = '0' + butMenu_get(xio->menu2); butRnet_send(net, msg, 2); xio_stopped = FALSE; xio_paused = FALSE; xio_moveSelected = PE_RESTART; xioRemote_newState(xio); return(BUTOUT_STOPWAIT); } /* * Returns -1 if it's a bogus socket. */ static int parsePort(Xio *xio, const char *portStr, bool reportErrors) { int port; bool err; port = wms_atoi(portStr, &err); if (err || (port > 65535) || (port < 1)) { char msg[300]; if (reportErrors) { sprintf(msg, xioStr_errSockNumInvalid[xio->lang], portStr, 65535); abutMsg_winCreate(xio->abut, "Pente Error", msg); } return(-1); } else { return(port); } } static ButOut okPressed(But *but) { Xio *xio = butEnv_packet(butWin_env(but_win(but))); xioRemote *rwin = xio->rwin; but_setFlags(rwin->mtxtin, BUT_NOKEY); but_setFlags(rwin->ptxtin, BUT_NOKEY); strcpy(mName, butTextin_get(rwin->mtxtin)); clp_setStr(pe_clp, "x.remote.rname", mName); strcpy(pName, butTextin_get(rwin->ptxtin)); clp_setStr(pe_clp, "x.remote.rsock", pName);; butWin_destroy(but_win(but)); if (xio_r_connect(xio)) return(0); else return(BUTOUT_ERR); } static ButOut helpPressed(But *but) { Xio *xio = butEnv_packet(butWin_env(but_win(but))); xio->hwin = xioHelp_create(xio, 3); return(0); } static ButOut cancelPressed(But *but) { butWin_destroy(but_win(but)); return(0); } static ButOut forceClose(ButRnet *net, const char *reason) { Xio *xio; char msgstr[1000]; xio = butRnet_packet(net); sprintf(msgstr, xioStr_netDisconnect[xio->lang], butRnet_who(net), reason); abutMsg_winCreate(xio->abut, "Pente: Network closed", msgstr); if (xio->waitWindow != NULL) { abutMsg_destroy(xio->waitWindow, TRUE); xio->waitWindow = NULL; } if (xio->remAcc != NULL) { xioRemAcc_destroy(xio->remAcc); xio->remAcc = NULL; } xio->rnet = NULL; if (xio->waitWindow != NULL) abutMsg_destroy(xio->waitWindow, TRUE); xio->remoteEnd = FALSE; xioRemote_newState(xio); xioSetup_remoteRelabel(xio->swin); return(0); } void xioRemote_newState(Xio *xio) { const char *optlist[10]; if (xio->remoteEnd) { optlist[0] = xioStr_remote[xio->lang]; optlist[1] = xioStr_human[xio->lang]; } else { optlist[0] = xioStr_human[xio->lang]; optlist[1] = xioStr_remote[xio->lang]; } optlist[2] = BUTMENU_OLBREAK; optlist[3] = xioStr_comp1[xio->lang]; optlist[4] = xioStr_comp2[xio->lang]; optlist[5] = xioStr_comp3[xio->lang]; optlist[6] = xioStr_comp4[xio->lang]; optlist[7] = xioStr_comp5[xio->lang]; optlist[8] = xioStr_comp6[xio->lang]; optlist[9] = BUTMENU_OLEND; butMenu_setText(xio->menu1, NULL, optlist, BUT_NOCHANGE); butMenu_setText(xio->menu2, NULL, optlist, BUT_NOCHANGE); } void xioRemote_destroy(Xio *xio) { butWin_destroy(xio->rwin->win); } static ButOut netInfo(ButRnet *net, void *msg, int msgLen) { if (msgLen == 2) return(newMenu(net, msg, msgLen)); else { assert(msgLen == sizeof(XioCompBroadcast)); return(remoteComp(net, msg, msgLen)); } } static ButOut newMenu(ButRnet *net, void *msg, int msgLen) { Xio *xio = butRnet_packet(net); char *cMsg = msg; xio->remoteEnd = TRUE; butMenu_set(xio->menu1, cMsg[0] - '0'); butMenu_set(xio->menu2, cMsg[1] - '0'); xio_change_menu(xio->menu1, cMsg[0] - '0'); xio_change_menu(xio->menu2, cMsg[1] - '0'); xio_stopped = FALSE; xio_paused = FALSE; xio_moveSelected = PE_RESTART; xioRemote_newState(xio); return(BUTOUT_STOPWAIT); } static ButOut remoteComp(ButRnet *net, void *msg, int msgLen) { XioCompBroadcast *cm = msg; bd_loc_t pm; Xio *xio = butRnet_packet(net); pm = (bd_loc_t)stdInt32_int(cm->pos); if (stdInt32_int(cm->think)) { xio_think(pm, stdInt32_int(cm->player)); return(0); } else { if (xio->markpos != pm) { xio_moveSelected = pm; return(BUTOUT_STOPWAIT); } else return(0); } } void xioRemote_comp(Xio *xio, bool think, bd_loc_t loc, int player) { XioCompBroadcast cb; cb.think = int_stdInt32((int)think); cb.pos = int_stdInt32((int)loc); cb.player = int_stdInt32((int)player); butRnet_send(xio->rnet, &cb, sizeof(cb)); } #endif pente-2.2.5/src/xio/sound.c0100664000076400007640000001052507045637747013754 0ustar wmswms/* * src/xio/sound.c, part of Pente (game program) * Copyright (C) 1994-1995 William Shubert. * See "configure.h.in" for more copyright information. * * Routines to manage the sounds */ #include #if X11_DISP #include #include #include #include "../pente.h" #include "xio.h" #include "setup.h" #include "sound.h" static void show_snd_error(Xio *xio); void xioSound_create(Xio *xio) { static int newSound = TRUE; xio->sound.ceVol = clp_lookup(pe_clp, "volume"); xio->sound.ceOldVol = clp_lookup(pe_clp, "volumeLast"); xio->sound.ceSilent = clp_lookup(pe_clp, "silent"); xio->sound.ceErr = clp_lookup(pe_clp, "soundErr"); xio->sound.volume = clpEntry_getInt(xio->sound.ceVol); if (newSound) { newSound = FALSE; if (clp_where(pe_clp, "volume") == clpWhere_cmdline) { xio->sound.volume = xio->sound.volume * SND_MAXVOL / 100; } else if ((xio->rcMajor == 2) && (xio->rcMinor == 0) && (xio->rcBugFix < 3)) { xio->sound.volume = xio->sound.volume * SND_MAXVOL / 261; } } if (xio->sound.volume > SND_MAXVOL) xio->sound.volume = SND_MAXVOL; if (xio->sound.volume < 0) xio->sound.volume = 0; xio->sound.silent = clpEntry_getBool(xio->sound.ceSilent); xio->sound.oldVolume = clpEntry_getInt(xio->sound.ceOldVol); if (!xio->sound.volume && xio->sound.oldVolume) xio->sound.volume = xio->sound.oldVolume; if (xio->sound.silent) xio->sound.volume = 0; xio->sound.err = clpEntry_getBool(xio->sound.ceErr); snd_init(sndState_off, xio->sound.volume); xioSound_check(xio); } void xioSound_check(Xio *xio) { static SndState oldState = sndState_off; SndState newState; SndInit err; if (xio->openWindows) { newState = sndState_fullOpen; } else newState = sndState_partOpen; if (newState != oldState) { if (!xio->sound.volume && !xio->sound.silent && xio->sound.oldVolume) { clpEntry_setInt(xio->sound.ceVol, xio->sound.volume = xio->sound.oldVolume); xio->sound.err = TRUE; } oldState = newState; err = snd_init(newState, -1); if (err) { show_snd_error(xio); } else { if (xio->sound.err) clpEntry_setBool(xio->sound.ceErr, xio->sound.err = FALSE); if (xio->sound.volume) clpEntry_setInt(xio->sound.ceOldVol, xio->sound.oldVolume = xio->sound.volume); } } } ButOut xioSound_toggle(But *but, bool press) { Xio *xio = but_packet(but); if (!press) return(0); xioSound_showErr(xio); clpEntry_setBool(xio->sound.ceSilent, xio->sound.silent = xio->sound.volume); if (xio->sound.silent) { if (xio->sound.volume > 0) clpEntry_setInt(xio->sound.ceOldVol, xio->sound.oldVolume = xio->sound.volume); clpEntry_setInt(xio->sound.ceVol, xio->sound.volume = 0); snd_init(sndState_oldState, 0); xioSetup_newVol(xio->swin, 0); } else { xio->sound.volume = xio->sound.oldVolume; if (snd_init(sndState_oldState, xio->sound.volume) != sndInit_ok) { show_snd_error(xio); } else { if (xio->sound.err) clpEntry_setBool(xio->sound.ceErr, xio->sound.err = FALSE); clpEntry_setInt(xio->sound.ceOldVol, xio->sound.oldVolume = xio->sound.volume); xioSetup_newVol(xio->swin, xio->sound.volume); clpEntry_setInt(xio->sound.ceVol, xio->sound.volume); } } return(0); } void xioSound_setVol(Xio *xio, int newVol, bool setLast) { SndInit err; err = snd_init(sndState_oldState, newVol); if (err) show_snd_error(xio); else { if (xio->sound.err) clpEntry_setBool(xio->sound.ceErr, xio->sound.err = FALSE); if (setLast && (xio->sound.volume > 0)) clpEntry_setInt(xio->sound.ceOldVol, xio->sound.oldVolume = xio->sound.volume); clpEntry_setInt(xio->sound.ceVol, xio->sound.volume = newVol); if (xio->sound.silent && (newVol > 0)) clpEntry_setBool(xio->sound.ceSilent, xio->sound.silent = FALSE); } } static void show_snd_error(Xio *xio) { clpEntry_setInt(xio->sound.ceVol, xio->sound.volume = 0); xioSetup_newVol(xio->swin, 0); /* * If we had an error LAST time, too, then just skip it and don't * show it again. */ if (!xio->sound.err) { clpEntry_setBool(xio->sound.ceErr, xio->sound.err = TRUE); abutMsg_winCreate(xio->abut, "Pente Error", snd_error); XBell(butEnv_dpy(xio->env), 0); } } #endif /* X11_DISP */ pente-2.2.5/src/xio/remAcc.c0100664000076400007640000000403407045637747014014 0ustar wmswms#include #if X11_DISP #include #include #include #include #include "../pente.h" #include "xio.h" #include "remAcc.h" #include "sound.h" #include "setup.h" static ButOut winClosed(void *packet); static ButOut okPressed(But *but); static ButOut rejectPressed(But *but); XioRemAcc *xioRemAcc_create(ButRnet *net) { XioRemAcc *ra; Xio *xio; static ButKey ka_ok[] = {{XK_Return, 0,0}, {XK_KP_Enter, 0,0}, {0,0,0}}; char msg[1000]; AbutMsgOpt buts[2]; xio = butRnet_packet(net); ra = wms_malloc(sizeof(XioRemAcc)); MAGIC_SET(ra); xio->remAcc = ra; xioSetup_remoteRelabel(xio->swin); sprintf(msg, xioStr_netOffer[xio->lang], butRnet_who(net)); ra->xio = xio; buts[0].name = xioStr_ok[xio->lang]; buts[0].callback = okPressed; buts[0].packet = xio; buts[0].keyEq = ka_ok; buts[1].name = xioStr_reject[xio->lang]; buts[1].callback = rejectPressed; buts[1].packet = xio; buts[1].keyEq = NULL; ra->mwin = abutMsg_winOptCreate(xio->abut, "Pente: Incoming Connection", msg, winClosed, xio, 2, buts); ra->net = net; return(ra); } static ButOut winClosed(void *packet) { Xio *xio = packet; XioRemAcc *ra = xio->remAcc; if (ra != NULL) { assert(MAGIC(ra)); butRnet_destroy(xio->rnet, "Connection rejected by remote player"); xio->remAcc = NULL; xio->rnet = NULL; MAGIC_UNSET(ra); wms_free(ra); xioSetup_remoteRelabel(xio->swin); } return(0); } static ButOut okPressed(But *but) { Xio *xio = but_packet(but); XioRemAcc *ra = xio->remAcc; assert(MAGIC(ra)); xio->remAcc = NULL; abutMsg_destroy(ra->mwin, TRUE); butRnet_accept(ra->net); MAGIC_UNSET(ra); wms_free(ra); return(0); } static ButOut rejectPressed(But *but) { Xio *xio = but_packet(but); abutMsg_destroy(xio->remAcc->mwin, TRUE); return(BUTOUT_STOPWAIT); } void xioRemAcc_destroy(XioRemAcc *ra) { assert(MAGIC(ra)); abutMsg_destroy(ra->mwin, TRUE); MAGIC_UNSET(ra); wms_free(ra); } #endif /* XIO_DISP */ pente-2.2.5/wmslib/src/wms.c0100664000076400007640000001331407045637750014121 0ustar wmswms/* * wmslib/src/wms.c, part of wmslib (Library functions) * Copyright (C) 1995 William Shubert. * See "configure.h.in" for more copyright information. */ #include #if !HAVE_GETDTABLESIZE #include #endif #if DEBUG typedef struct alloc_struct { int magic; int size; const char *file; int line; struct alloc_struct *next, *prev; } alloc_t; static int alloc_count=0, total_bytes=0, check=FALSE; static alloc_t *ring_head = NULL; void *wms_malloc_debug(uint bufsize, const char *file, int line) { void *ret; alloc_t *alloc; if (bufsize == 0) return(NULL); ++alloc_count; total_bytes += bufsize; bufsize += sizeof(alloc_t); alloc = malloc(bufsize); assert(alloc != NULL); if (alloc == NULL) { fprintf(stderr, "%s: FATAL ERROR: Failed to allocate %d bytes.\n", wms_progname, bufsize); exit(1); } ret = (void *)((int)alloc + sizeof(alloc_t)); alloc->magic = 0x91325832; alloc->size = bufsize - sizeof(alloc_t); alloc->file = file; alloc->line = line; if (ring_head == NULL) { ring_head = alloc; alloc->next = alloc->prev = alloc; } else { alloc->next = ring_head; alloc->prev = ring_head->prev; alloc->next->prev = alloc; alloc->prev->next = alloc; } return(ret); } void wms_free(void *deadbuf) { alloc_t *alloc; assert(deadbuf != NULL); alloc = (alloc_t *)((int)deadbuf - sizeof(alloc_t)); --alloc_count; if (alloc->magic != 0x91325832) { fprintf(stderr, "WARNING: BAD FREE!\n"); for (;;); } total_bytes -= alloc->size; alloc->magic = 0; if (ring_head == alloc) { if (alloc->next == alloc) ring_head = NULL; else { ring_head = alloc->next; alloc->next->prev = alloc->prev; alloc->prev->next = alloc->next; } } else if (alloc->next != alloc) { alloc->next->prev = alloc->prev; alloc->prev->next = alloc->next; } free(alloc); } void wms_alloc_ring_reset(void) { ring_head = NULL; } void wms_alloc_ring_show(void) { alloc_t *alloc; if (ring_head == NULL) { printf("*** wms_alloc: Empty ring\n"); } else { alloc = ring_head; do { printf("*** wms_alloc: %4d bytes; file \"%s\", line %d.\n", alloc->size, alloc->file, alloc->line); alloc = alloc->next; } while (alloc != ring_head); printf("\n"); } } void wms_alloc_stat(void) { fprintf(stderr, "Count of allocated buffers: %d\n", alloc_count); fprintf(stderr, " Total bytes allocated: %d\n", total_bytes); check = TRUE; } #else /* !DEBUG */ void *wms_malloc(uint bufsize) { void *ret; if (bufsize == 0) return(NULL); ret = malloc(bufsize); assert(ret != NULL); if (ret == NULL) { fprintf(stderr, "%s: FATAL ERROR: Failed to allocate %d bytes.\n", wms_progname, bufsize); exit(1); } return(ret); } #endif /* DEBUG */ #if !HAVE_STRERROR /* * Do a fake, really bad strerror() function. */ const char *strerror(int error) { static char out[20]; sprintf(out, "System error %d", error); return(out); } #endif /* !HAVE_STRERROR */ #if !HAVE_GETDTABLESIZE int getdtablesize(void) { struct rlimit tmp_rlim; getrlimit(RLIMIT_NOFILE, &tmp_rlim); return(tmp_rlim.rlim_cur); } #endif /* !HAVE_GETDTABLESIZE */ int wms_atoi(const char *str, bool *err) { bool dummy; bool negative = FALSE, inNum = FALSE, gotNum = FALSE, doneNum = FALSE; int i, v = 0, newV; if (err == NULL) err = &dummy; *err = FALSE; for (i = 0; str[i]; ++i) { if (isspace(str[i])) { if (inNum) doneNum = TRUE; } else if (str[i] == '-') { if (inNum) { *err = TRUE; return(0); } else { inNum = TRUE; negative = TRUE; } } else if (isdigit(str[i])) { if (doneNum) { *err = TRUE; return(0); } else { inNum = TRUE; gotNum = TRUE; newV = v*10 + (int)(str[i] - '0'); if (newV / 10 != v) { *err = TRUE; return(0); } v = newV; } } else { *err = TRUE; return(0); } } if (!gotNum) { *err = TRUE; return(0); } if (negative) return(-v); else return(v); } double wms_atof(const char *str, bool *err) { int i; bool decimal = FALSE; i = 0; if (str[0] == '-') ++i; while (str[i]) { if (str[i] == '.') { if (decimal) { if (err) *err = TRUE; return(0.0); } decimal = TRUE; } else if (!isdigit(str[i])) { if (err) *err = TRUE; return(0.0); } ++i; } if (err) *err = FALSE; return(atof(str)); } #if WORDS_BIGENDIAN int stdInt32_int(StdInt32 i) { return(((i >> 24) & 0x000000ff) | ((i >> 8) & 0x0000ff00) | ((i << 8) & 0x00ff0000) | ((i << 24) & 0xff000000)); } StdInt32 int_stdInt32(int i) { return(((i >> 24) & 0x000000ff) | ((i >> 8) & 0x0000ff00) | ((i << 8) & 0x00ff0000) | ((i << 24) & 0xff000000)); } #endif /* WORDS_BIGENDIAN */ #if !HAVE_MEMMOVE void *memmove(void *dest, const void *src, size_t n) { char *dc; const char *sc; int i; dc = dest; sc = src; if ((dc + n < sc) || (sc + n < dc)) return(memcpy(dest, src, n)); else { if (dc < sc) { for (i = 0; i < n; ++i) { dc[i] = sc[i]; } } else if (sc < dc) { for (i = n - 1; i >= 0; --i) { dc[i] = sc[i]; } } } return(dest); } #endif /* !HAVE_MEMMOVE */ #if !HAVE_STRCASECMP int strcasecmp(const char *s1, const char *s2) { int i; char c1, c2; for (i = 0; s1[i]; ++i) { c1 = s1[i]; c2 = s2[i]; if ((c1 >= 'a') && (c1 <= 'z')) c1 += 'A' - 'a'; if ((c2 >= 'a') && (c2 <= 'z')) c2 += 'A' - 'a'; if (c1 != c2) return((int)c1 - (int)c2); } if (s2[i]) return(-1); return(0); } #endif /* !HAVE_STRCASECMP */ pente-2.2.5/wmslib/src/wms/clp.c0100664000076400007640000003553307045640231014672 0ustar wmswms/* * wmslib/src/wms/clp.c, part of wmslib (Library functions) * Copyright (C) 1995-1997 William Shubert. * See "configure.h.in" for more copyright information. * * Command Line Parse. */ #include #include #include #include /* To get umask()...I hope this is portable! */ #include #if STDC_HEADERS #include #endif /* STDC_HEADERS */ #ifdef _WMS_CLP_H_ #error Levelization Error. #endif #include "clp.h" /********************************************************************** * Globals **********************************************************************/ const char *wms_progname = "UNKNOWN"; static bool showErrs = TRUE; /********************************************************************** * Forward Declarations **********************************************************************/ static ClpEntry *clp_iLookup(Clp *clp, const char *key, bool *bval); static void clpEntry_free(ClpEntry *ci); static void strip(char *argv[]); static void clp_help(Clp *clp); static void setStrList(ClpEntry *entry, const char *vals); static void moreStrs(ClpEntry *ce, int newNumStrs); /********************************************************************** * Functions **********************************************************************/ Clp *clp_create(const ClpSetup vars[]) { int numVars, i; Clp *newClp; newClp = wms_malloc(sizeof(Clp)); MAGIC_SET(newClp); for (numVars = 0; !(vars[numVars].flags & CLPSETUP_ENDFLAG); ++numVars); newClp->numInfos = numVars + 2; newClp->infos = wms_malloc((numVars + 2) * sizeof(ClpEntry)); for (i = 0; i < numVars; ++i) { MAGIC_SET(&newClp->infos[i]); newClp->infos[i].name = vars[i].name; newClp->infos[i].desc = vars[i].desc; newClp->infos[i].flags = vars[i].flags; newClp->infos[i].test = vars[i].test; if (vars[i].name == NULL) newClp->infos[i].flags |= CLPSETUP_NOSAVE; newClp->infos[i].where = clpWhere_unset; newClp->infos[i].type = clpDtype_string; newClp->infos[i].numStrs = 0; newClp->infos[i].maxStrs = 0; newClp->infos[i].storage.strList = NULL; if (vars[i].defVal) { setStrList(&newClp->infos[i], vars[i].defVal); } else { setStrList(&newClp->infos[i], ""); } assert(newClp->infos[i].numStrs > 0); } MAGIC_SET(&newClp->infos[i]); newClp->infos[i].name = NULL; newClp->infos[i].desc = ""; newClp->infos[i].flags = CLPSETUP_BOOL|CLPSETUP_NOSAVE; newClp->infos[i].where = clpWhere_unset; newClp->infos[i].type = clpDtype_bool; newClp->infos[i].test = NULL; ++i; MAGIC_SET(&newClp->infos[i]); newClp->infos[i].name = "help,-help"; newClp->infos[i].desc = "Show this message"; newClp->infos[i].flags = CLPSETUP_BOOL|CLPSETUP_NOSAVE|CLPSETUP_HELP; newClp->infos[i].where = clpWhere_unset; newClp->infos[i].type = clpDtype_bool; newClp->infos[i].test = NULL; return(newClp); } void clp_destroy(Clp *clp) { int i; assert(MAGIC(clp)); for (i = 0; i < clp->numInfos; ++i) clpEntry_free(&clp->infos[i]); wms_free(clp->infos); wms_free(clp); } int clp_rCmdline(Clp *clp, char *argv[]) { int numArgs; ClpEntry *ce; bool bval; assert(MAGIC(clp)); wms_progname = argv[0]; strip(argv); for (numArgs = 0; argv[numArgs];) { if (argv[numArgs][0] == '-') { /* It's a switch. */ ce = clp_iLookup(clp, argv[numArgs]+1, &bval); ce->where = clpWhere_cmdline; if (ce->flags & CLPSETUP_BOOL) { if (bval && (ce->flags & CLPSETUP_HELP)) { clp_help(clp); exit(1); } clpEntry_setBool(ce, bval); } else { if (argv[numArgs+1]) clpEntry_setStr(ce, argv[numArgs+1]); else { fprintf(stderr, "%s: Switch \"%s\" requires an argument.\n", wms_progname, argv[numArgs]); exit(1); } strip(argv + numArgs); } strip(argv + numArgs); } else ++numArgs; } return(numArgs); } /* * clp_rFile returns FALSE if it can't find the file at all. */ bool clp_rFile(Clp *clp, const char *fname) { FILE *ifile; char line_in[1024], *arg; Str full_fn; char *home, *key_start; int i, ch_in; bool retval = FALSE; ClpEntry *ci; assert(MAGIC(clp)); str_initChars(&full_fn, fname); showErrs = FALSE; if (fname[0] == '~') { /* Prepend "$HOME" */ home = getenv("HOME"); if (home == NULL) { fprintf(stderr, "%s: Error: Could not find environment variable \"HOME\".\n", wms_progname); showErrs = TRUE; str_deinit(&full_fn); return(FALSE); } str_print(&full_fn, "%s/%s", home, fname+1); } ifile = fopen(str_chars(&full_fn), "r"); if (ifile != NULL) { retval = TRUE; do { ch_in = getc(ifile); for (i = 0; (i < 1023) && (ch_in != '\n') && (ch_in != EOF); ++i) { line_in[i] = ch_in; ch_in = getc(ifile); } while ((ch_in != '\n') && (ch_in != EOF)) ch_in = getc(ifile); line_in[i] = '\0'; if ((line_in[0] == '#') || (line_in[0] == '\0')) continue; key_start = strchr(line_in, '.') + 1; if (key_start != NULL) { arg = strchr(line_in, ':'); *arg = '\0'; arg += 2; ci = clp_iLookup(clp, key_start, NULL); if (ci != NULL) { if ((ci->where == clpWhere_unset) || (ci->where == clpWhere_xdefs)) { ci->where = clpWhere_rcfile; setStrList(ci, arg); } } } } while (ch_in != EOF); fclose(ifile); } str_deinit(&full_fn); showErrs = TRUE; return(retval); } void clp_wFile(Clp *clp, const char *fname, const char *pname) { FILE *ofile; Str full_fn; char *home; const char *strOut; int i, prevMask, strNum, charNum; ClpEntry *ci; str_initChars(&full_fn, fname); if (fname[0] == '~') { /* Prepend "$HOME" */ home = getenv("HOME"); if (home == NULL) { fprintf(stderr, "%s: Error: Could not find environment variable \"HOME\".\n", wms_progname); str_deinit(&full_fn); return; } str_print(&full_fn, "%s/%s", home, fname+1); } prevMask = umask(0177); ofile = fopen(str_chars(&full_fn), "w"); umask(prevMask); if (ofile == NULL) { fprintf(stderr, "%s: Error: Could not open file \"%s\" for writing.\n", wms_progname, fname); perror(wms_progname); exit(1); } fprintf(ofile, "# NOTICE: Please do not edit this file.\n" "# It was automatically generated by \"%s\". If you want to\n" "# change one of these values, please use command line switches,\n" "# X defaults, or a setup window.\n" "# As a last resort you may simply delete this file.\n\n", wms_progname); for (i = 0; i < clp->numInfos; ++i) { ci = &clp->infos[i]; if (!(ci->flags & CLPSETUP_NOSAVE)) { switch(ci->type) { case clpDtype_int: fprintf(ofile, "%s.%s: %d\n", pname, ci->name, ci->storage.ival); break; case clpDtype_double: fprintf(ofile, "%s.%s: %f\n", pname, ci->name, ci->storage.dval); break; case clpDtype_bool: if (ci->storage.bval) fprintf(ofile, "%s.%s: y\n", pname, ci->name); else fprintf(ofile, "%s.%s: n\n", pname, ci->name); break; case clpDtype_string: fprintf(ofile, "%s.%s: ", pname, ci->name); for (strNum = 0; strNum < ci->numStrs; ++strNum) { if (strNum != 0) putc('|', ofile); strOut = str_chars(&ci->storage.strList[strNum]); for (charNum = 0; strOut[charNum]; ++charNum) { if ((strOut[charNum] == '|') || (strOut[charNum] == '\\')) putc('\\', ofile); putc(strOut[charNum], ofile); } } putc('\n', ofile); break; default: /* Should never reach here. */ assert(0); break; } } } fclose(ofile); str_deinit(&full_fn); } int clpEntry_iGetInt(ClpEntry *ce, bool *err) { switch(ce->type) { case clpDtype_int: if (err) *err = FALSE; return(ce->storage.ival); break; case clpDtype_string: return(wms_atoi(str_chars(&ce->storage.strList[0]), err)); break; default: if (err) *err = TRUE; return(0); } } double clpEntry_iGetDouble(ClpEntry *ce, bool *err) { switch(ce->type) { case clpDtype_double: if (err) *err = FALSE; return(ce->storage.dval); break; case clpDtype_string: return(wms_atof(str_chars(&ce->storage.strList[0]), err)); break; default: if (err) *err = TRUE; return(0.0); } } const char *clpEntry_iGetStrNum(ClpEntry *ce, int num, bool *err) { if (ce->type == clpDtype_string) { if (err) *err = FALSE; assert(num < ce->numStrs); return(str_chars(&ce->storage.strList[num])); } else { if (err) *err = TRUE; return(NULL); } } bool clpEntry_iGetBool(ClpEntry *ce, bool *err) { const char *str; switch(ce->type) { case clpDtype_bool: if (err) *err = FALSE; return(ce->storage.bval); break; case clpDtype_string: str = str_chars(&ce->storage.strList[0]); if ((!strcmp(str, "1")) || (!strcmp(str, "t")) || (!strcmp(str, "T")) || (!strcmp(str, "y")) || (!strcmp(str, "Y")) || (!strcmp(str, "true")) || (!strcmp(str, "True")) || (!strcmp(str, "TRUE")) || (!strcmp(str, "yes")) || (!strcmp(str, "Yes")) || (!strcmp(str, "YES"))) return(TRUE); if ((!strcmp(str, "0")) || (!strcmp(str, "f")) || (!strcmp(str, "F")) || (!strcmp(str, "n")) || (!strcmp(str, "N")) || (!strcmp(str, "false")) || (!strcmp(str, "False")) || (!strcmp(str, "FALSE")) || (!strcmp(str, "no")) || (!strcmp(str, "No")) || (!strcmp(str, "NO"))) return(FALSE); if (err) *err = TRUE; return(FALSE); break; default: if (err) *err = TRUE; return(FALSE); } } bool clpEntry_setInt(ClpEntry *ce, int val) { ClpEntry newCe; MAGIC_SET(&newCe); if (ce->test) { newCe.type = clpDtype_int; newCe.storage.ival = val; if (!ce->test(&newCe)) return(FALSE); } clpEntry_free(ce); ce->type = clpDtype_int; ce->storage.ival = val; MAGIC_UNSET(&newCe); return(TRUE); } bool clpEntry_setDouble(ClpEntry *ce, double val) { ClpEntry newCe; MAGIC_SET(&newCe); if (ce->test) { newCe.type = clpDtype_double; newCe.storage.dval = val; if (!ce->test(&newCe)) return(FALSE); } clpEntry_free(ce); ce->type = clpDtype_double; ce->storage.dval = val; MAGIC_UNSET(&newCe); return(TRUE); } bool clpEntry_setStrNum(ClpEntry *ce, const char *val, int num) { ClpEntry newCe; bool testResult; if (ce->test) { assert(num == 0); MAGIC_SET(&newCe); newCe.type = clpDtype_string; newCe.storage.strList = str_createChars(val); newCe.numStrs = 1; testResult = ce->test(&newCe); str_destroy(newCe.storage.strList); MAGIC_UNSET(&newCe); if (!testResult) return(FALSE); } if (ce->type == clpDtype_string) { if (num >= ce->numStrs) { moreStrs(ce, num+1); } str_copyChars(&ce->storage.strList[num], val); } else { assert(num == 0); clpEntry_free(ce); ce->type = clpDtype_string; ce->numStrs = 1; ce->maxStrs = 1; ce->storage.strList = str_createChars(val); } return(TRUE); } static void moreStrs(ClpEntry *ce, int newNumStrs) { Str *newStrs; int i; assert(newNumStrs > ce->numStrs); newStrs = wms_malloc(newNumStrs * sizeof(Str)); for (i = 0; i < ce->numStrs; ++i) { newStrs[i] = ce->storage.strList[i]; } for (; i < newNumStrs; ++i) { str_init(&newStrs[i]); } wms_free(ce->storage.strList); ce->storage.strList = newStrs; } bool clpEntry_setBool(ClpEntry *ce, bool val) { ClpEntry newCe; MAGIC_SET(&newCe); if (ce->test) { newCe.type = clpDtype_bool; newCe.storage.bval = val; if (!ce->test(&newCe)) return(FALSE); } clpEntry_free(ce); ce->type = clpDtype_bool; ce->storage.bval = val; MAGIC_UNSET(&newCe); return(TRUE); } ClpEntry *clp_lookup(Clp *clp, const char *key) { assert(MAGIC(clp)); return(clp_iLookup(clp, key, NULL)); } static ClpEntry *clp_iLookup(Clp *clp, const char *key, bool *bval) { ClpEntry *ci; int i, j, keyLen; bool reversed; assert(MAGIC(clp)); keyLen = strlen(key); reversed = !strncmp(key, "no", 2); if (bval) *bval = TRUE; for (i = 0; i < clp->numInfos; ++i) { ci = &clp->infos[i]; if (ci->name) { for (j = 0; ci->name[j];) { if (!strncmp(ci->name+j, key, keyLen)) { if ((ci->name[j + keyLen] == '\0') || (ci->name[j + keyLen] == ',')) return(ci); } if (reversed && (ci->flags & CLPSETUP_BOOL) && !strncmp(ci->name, key+2, keyLen - 2)) { if (bval) *bval = FALSE; return(ci); } while (ci->name[j] && (ci->name[j] != ',')) ++j; if (ci->name[j]) ++j; } } } if (showErrs) { fprintf(stderr, "%s: \"-%s\" is not a valid flag.\n" " Use \"%s -help\" for a list of valid flags.\n", wms_progname, key, wms_progname); exit(1); } else return(NULL); } static void strip(char *argv[]) { do { argv[0] = argv[1]; ++argv; } while (argv[0] != NULL); } static void clpEntry_free(ClpEntry *ci) { int i; assert(MAGIC(ci)); if (ci->type == clpDtype_string) { for (i = 0; i < ci->maxStrs; ++i) str_deinit(&ci->storage.strList[i]); wms_free(ci->storage.strList); } } static void clp_help(Clp *clp) { int i, j; char name[40]; const char *prestr; assert(MAGIC(clp)); for (i = 0; i < clp->numInfos; ++i) { if (clp->infos[i].desc) { if (clp->infos[i].name) { name[0] = '\0'; if (clp->infos[i].flags & CLPSETUP_SHOWBOOL) prestr = "-[no]"; else prestr = "-"; strcpy(name, prestr); for (j = 0; clp->infos[i].name[j]; ++j) { strncat(name, clp->infos[i].name+j, 1); if (clp->infos[i].name[j] == ',') strcat(name, prestr); } if (clp->infos[i].flags & CLPSETUP_SHOWARG) { fprintf(stderr, " %14s <...> %s\n", name, clp->infos[i].desc); } else { fprintf(stderr, " %20s %s\n", name, clp->infos[i].desc); } } else fprintf(stderr, " %s\n", clp->infos[i].desc); } } } static void setStrList(ClpEntry *entry, const char *vals) { int numVals = 1; int i; Str *newStrs; bool escaped; for (i = 0, escaped = FALSE; vals[i]; ++i) { if (!escaped && (vals[i] == '|')) ++numVals; escaped = (!escaped && (vals[i] == '\\')); } if (numVals > entry->maxStrs) { newStrs = wms_malloc(numVals * sizeof(Str)); for (i = 0; i < numVals; ++i) { str_init(&newStrs[i]); } if (entry->storage.strList != NULL) wms_free(entry->storage.strList); entry->maxStrs = numVals; entry->storage.strList = newStrs; } else newStrs = entry->storage.strList; entry->numStrs = numVals; numVals = 0; str_clip(&newStrs[0], 0); for (i = 0, escaped = FALSE; vals[i]; ++i) { if (escaped) { str_catChar(&newStrs[numVals], vals[i]); escaped = FALSE; } else { if (vals[i] == '\\') escaped = TRUE; else if (vals[i] == '|') { ++numVals; assert(numVals < entry->numStrs); str_clip(&newStrs[numVals], 0); } else { str_catChar(&newStrs[numVals], vals[i]); } } } } pente-2.2.5/wmslib/src/wms/clp-x.c0100664000076400007640000000205707045640231015132 0ustar wmswms/* * wmslib/src/wms/clp-x.c, part of wmslib (Library functions) * Copyright (C) 1995-1996 William Shubert. * See "configure.h.in" for more copyright information. * * Command Line Parser. */ #include #if X11_DISP #include #include #include "clp.h" /********************************************************************** * Functions **********************************************************************/ void clp_rXDefaults(Clp *clp, Display *dpy, char *name) { int i, j; ClpEntry *ci; char *xdef, wname[80]; for (i = 0; i < clp->numInfos; ++i) { ci = &clp->infos[i]; if (!ci->name || (ci->where == clpWhere_cmdline)) continue; strncpy(wname, ci->name, sizeof(wname) - 1); wname[sizeof(wname) - 1] = '\0'; for (j = 0; wname[j]; ++j) if (wname[j] == ',') wname[j] = '\0'; xdef = XGetDefault(dpy, name, wname); if (xdef != NULL) { ci->where = clpWhere_xdefs; ci->type = clpDtype_string; clpEntry_setStr(ci, xdef); } } } #endif /* X11_DISP */ pente-2.2.5/wmslib/src/wms/rnd.c0100664000076400007640000000440207045640231014666 0ustar wmswms/* * wmslib/src/wms/rnd.c, part of wmslib (Library functions) * Copyright (C) 1995 William Shubert. * See "configure.h.in" for more copyright information. */ #include #include int rnd_int(Rnd *state) { uint result; int destIndent; assert(MAGIC(state)); destIndent = state->indent + RND_INDENT; if (destIndent >= RND_DATASIZE) destIndent -= RND_DATASIZE; result = (state->data[destIndent] += state->data[state->indent]); if (++state->indent >= RND_DATASIZE) state->indent = 0; return((int)(result >> 1)); } uint rnd_uint(Rnd *state) { uint result; int destIndent; assert(MAGIC(state)); destIndent = state->indent + RND_INDENT; if (destIndent >= RND_DATASIZE) destIndent -= RND_DATASIZE; result = (state->data[destIndent] += state->data[state->indent]); if (++state->indent >= RND_DATASIZE) state->indent = 0; return(result); } int32 rnd_int32(Rnd *state) { uint32 result; int destIndent; assert(MAGIC(state)); destIndent = state->indent + RND_INDENT; if (destIndent >= RND_DATASIZE) destIndent -= RND_DATASIZE; result = (state->data[destIndent] += state->data[state->indent]); if (++state->indent >= RND_DATASIZE) state->indent = 0; return((int32)(result >> 1)); } uint32 rnd_uint32(Rnd *state) { uint32 result; int destIndent; assert(MAGIC(state)); destIndent = state->indent + RND_INDENT; if (destIndent >= RND_DATASIZE) destIndent -= RND_DATASIZE; result = (state->data[destIndent] += state->data[state->indent]); if (++state->indent >= RND_DATASIZE) state->indent = 0; return(result); } Rnd *rnd_create(uint seed) { int i; Rnd *state; state = wms_malloc(sizeof(Rnd)); MAGIC_SET(state); state->indent = 0; for (i = 0; i < RND_DATASIZE; ++i) { state->data[i] = seed; seed = seed * 13 + 3; } for (i = 0; i < 100; ++i) rnd_uint32(state); return(state); } void rnd_destroy(Rnd *state) { assert(MAGIC(state)); MAGIC_UNSET(state); wms_free(state); } float rnd_float(Rnd *state) { int result; float out; #if SIZEOF_INT > 2 result = rnd_int(state) & 0xffffff; out = result / 16777216.0; return(out); #else result = rnd_int(state) & 0x7fff; out = result / 32768.0; return(out); #endif } pente-2.2.5/wmslib/src/wms/snd.c0100664000076400007640000001615307331147374014705 0ustar wmswms/* * wmslib/src/wms/snd.c, part of wmslib (Library functions) * Copyright (C) 1995 William Shubert. * See "configure.h.in" for more copyright information. */ #include #include #include #include #if SUN_SOUND #include #elif LINUX_SOUND #if !HAVE_GETDTABLESIZE #include #endif #include #include #endif #if SUN_SOUND #define sound_dev_name "/dev/audio" #elif LINUX_SOUND #define sound_dev_name "/dev/dsp" #endif #if SUN_SOUND #define SND_PHYSMAXVOL 255 #elif LINUX_SOUND #define SND_PHYSMAXVOL 261 #endif #ifndef SUN_SOUND #define SUN_SOUND 0 #endif #ifndef LINUX_SOUND #define LINUX_SOUND 0 #endif const bool sndAvail = (SUN_SOUND || LINUX_SOUND); static int sound_dev = -1, volume = 0; static SndState state = sndState_off; #if SUN_SOUND static audio_info_t old_ai; #elif LINUX_SOUND static Snd *cvtlist = NULL; static pid_t child; static int ulaw_to_16bit(uchar ulawbyte); static void audio_child(int in, int out); #endif void (*snd_errHandler)(SndInit errType, char *errStr) = NULL; char snd_error[1000] = "Sound functioning properly."; static void snd_deinitChild(void); #if SUN_SOUND || LINUX_SOUND SndInit snd_init(SndState newState, int newVolume) { #if SUN_SOUND audio_info_t ai; #endif /* SUN_SOUND */ SndInit result = sndInit_ok; assert((newVolume >= -1) && (newVolume <= SND_MAXVOL)); if (newVolume >= 0) newVolume = ((newVolume * SND_PHYSMAXVOL + SND_MAXVOL/2) / SND_MAXVOL); if (state == sndState_iOff) return(sndInit_broken); if (state == sndState_iWantOpen) { if (newState == sndState_oldState) newState = sndState_fullOpen; state = sndState_off; } if (newVolume == -1) newVolume = volume; if (volume != newVolume) { if (volume == 0) { if (newState == sndState_oldState) newState = state; state = sndState_off; } #if LINUX_SOUND /* Free up all old converted sound buffers. */ while (cvtlist != NULL) { cvtlist->converted = FALSE; wms_free(cvtlist->cvtdata.dsp); cvtlist = cvtlist->next; } #endif /* LINUX_SOUND */ volume = newVolume; } if (volume == 0) snd_deinit(); if ((newState != sndState_oldState) && (newState != state)) { snd_deinit(); state = newState; if ((volume == 0) || (state < sndState_fullOpen)) { /* * Try to open it, just to make sure that we can. */ sound_dev = open(sound_dev_name, O_WRONLY|O_NDELAY); if (sound_dev != -1) { close(sound_dev); sound_dev = -1; return(result); } } else sound_dev = open(sound_dev_name, O_WRONLY|O_NDELAY); if (sound_dev == -1) { /* Can't open the sound device. Drag. */ if (errno == EBUSY) { result = sndInit_busy; if (state == sndState_fullOpen) state = sndState_iWantOpen; /* Somebody else has it open! Print an error and try again. */ sprintf(snd_error, "Sound device \"%s\" is busy.", sound_dev_name); } else { /* Some other reason...give up forever. */ result = sndInit_broken; volume = 0; state = sndState_iOff; sprintf(snd_error, "Couldn't open sound device \"%s\". " "Error code: \"%s\".", sound_dev_name, strerror(errno)); } return(result); } if (state == sndState_fullOpen) { #if LINUX_SOUND /* Sound device opened successfully. Spawn the audio child. */ int pipes[2], i; pipe(pipes); child = fork(); if (child == 0) { int maxFiles = getdtablesize(); /* * Close off all file descriptors that the audio child doesn't need. */ for (i = 2; i < maxFiles; ++i) { if ((i != pipes[0]) && (i != sound_dev)) close(i); } audio_child(pipes[0], sound_dev); } else { close(pipes[0]); close(sound_dev); sound_dev = pipes[1]; } #endif /* LINUX_SOUND */ } } #if SUN_SOUND /* Cofigure the device for us. */ ioctl(sound_dev, AUDIO_GETINFO, &ai); old_ai = ai; AUDIO_INITINFO(&ai); ai.play.sample_rate = 8000; ai.play.channels = 1; ai.play.precision = 8; ai.play.encoding = AUDIO_ENCODING_ULAW; if (volume != -1) ai.play.gain = (volume * AUDIO_MAX_GAIN + SND_MAXVOL/2) / SND_MAXVOL; if (ioctl(sound_dev, AUDIO_SETINFO, &ai) == -1) { sprintf(snd_error, "Sound device \"%s\" cannot use desired " "data format.", sound_dev_name); result = sndInit_broken; volume = 0; close(sound_dev); state = sndState_iOff; } #endif /* SUN_SOUND */ return(result); } void snd_play(Snd *sound) { if ((volume == 0) || (state <= sndState_off)) return; #if LINUX_SOUND if (!sound->converted) { int i; sound->cvtdata.dsp = wms_malloc(sound->len); sound->cvtlen = sound->len; for (i = 0; i < sound->len; ++i) sound->cvtdata.dsp[i] = ((ulaw_to_16bit(sound->data[i]) * volume) >> 16) + 128; sound->converted = TRUE; sound->next = cvtlist; cvtlist = sound; } #endif /* LINUX_SOUND */ if (state == sndState_partOpen) snd_init(sndState_iTempOpen, -1); if (sound_dev != -1) write(sound_dev, #if SUN_SOUND sound->data, sound->len #elif LINUX_SOUND sound->cvtdata.dsp, sound->cvtlen #endif ); if (state == sndState_iTempOpen) { #if LINUX_SOUND if (sound_dev != -1) ioctl(sound_dev, SNDCTL_DSP_SYNC, NULL); #endif snd_deinitChild(); state = sndState_partOpen; } } void snd_deinit(void) { #if LINUX_SOUND int status; #endif /* LINUX_SOUND */ if ((sound_dev != -1) && (state == sndState_fullOpen)) { #if SUN_SOUND ioctl(sound_dev, AUDIO_SETINFO, &old_ai); #endif /* SUN_SOUND */ close(sound_dev); #if LINUX_SOUND kill(child, SIGKILL); wait(&status); #endif /* LINUX_SOUND */ } sound_dev = -1; } static void snd_deinitChild(void) { if (sound_dev != -1) { #if SUN_SOUND ioctl(sound_dev, AUDIO_SETINFO, &old_ai); #endif /* SUN_SOUND */ close(sound_dev); } sound_dev = -1; } #if LINUX_SOUND static void audio_child(int in, int out) { size_t size_in; char buf[1024*8]; /* 1 second...should be enough! */ /* Make sure that we don't save OUR state! */ signal(SIGTERM, SIG_DFL); signal(SIGINT, SIG_DFL); signal(SIGPIPE, SIG_DFL); signal(SIGHUP, SIG_DFL); for (;;) { size_in = read(in, buf, 1024*8); if (size_in == 0) exit(0); if (size_in == -1) { perror("Pente sound demon: Error "); exit(1); } write(out, buf, size_in); ioctl(out, SNDCTL_DSP_SYNC, NULL); } } static int ulaw_to_16bit(uchar ulawbyte) { static int exp_lut[8] = { 0, 132, 396, 924, 1980, 4092, 8316, 16764 }; int sign, exponent, mantissa, sample; ulawbyte = ~ ulawbyte; sign = ( ulawbyte & 0x80 ); exponent = ( ulawbyte >> 4 ) & 0x07; mantissa = ulawbyte & 0x0F; sample = exp_lut[exponent] + ( mantissa << ( exponent + 3 ) ); if ( sign != 0 ) sample = -sample; return sample; } #endif /* LINUX_SOUND */ #else /* No audio. */ SndInit snd_init(SndState newstate, int vol) { sprintf(snd_error, "%s was compiled with sound turned off.", wms_progname); return(sndInit_broken); } void snd_play(Snd *sound) {} void snd_deinit(void) {} #endif /* SUN_SOUND || LINUX_SOUND */ pente-2.2.5/wmslib/src/wms/str.c0100664000076400007640000001721707045640231014723 0ustar wmswms/* * wmslib/src/wms/str.c, part of wmslib (Library functions) * Copyright (C) 1995-1996 William Shubert. * See "configure.h.in" for more copyright information. */ #include #include #include /********************************************************************** * Global variables **********************************************************************/ static char empty = '\0'; /********************************************************************** * Functions **********************************************************************/ Str *str_create(void) { Str *ret; ret = wms_malloc(sizeof(Str)); MAGIC_SET(ret); ret->len = ret->maxLen = 0; ret->chars = ∅ return(ret); } Str *str_createStr(const Str *s) { Str *ret; ret = wms_malloc(sizeof(Str)); MAGIC_SET(ret); ret->len = ret->maxLen = s->len; ret->chars = wms_malloc(ret->len + 1); strcpy(ret->chars, s->chars); assert(strlen(ret->chars) == ret->len); return(ret); } Str *str_createChars(const char *chars) { Str *ret; ret = wms_malloc(sizeof(Str)); MAGIC_SET(ret); ret->len = ret->maxLen = strlen(chars); ret->chars = wms_malloc(ret->len + 1); strcpy(ret->chars, chars); assert(strlen(ret->chars) == ret->len); return(ret); } Str *str_createChar(char c) { Str *ret; ret = wms_malloc(sizeof(Str)); MAGIC_SET(ret); ret->len = ret->maxLen = 1; ret->chars = wms_malloc(ret->len + 1); ret->chars[0] = c; ret->chars[1] = '\0'; assert(strlen(ret->chars) == ret->len); return(ret); } void str_destroy(Str *s) { assert(MAGIC(s)); if (s->chars != &empty) wms_free(s->chars); MAGIC_UNSET(s); wms_free(s); } void str_init(Str *s) { MAGIC_SET(s); s->len = s->maxLen = 0; s->chars = ∅ } void str_initStr(Str *s, const Str *src) { MAGIC_SET(s); s->len = s->maxLen = src->len; s->chars = wms_malloc(s->len + 1); strcpy(s->chars, src->chars); assert(strlen(s->chars) == s->len); } void str_initChars(Str *s, const char *src) { MAGIC_SET(s); s->len = s->maxLen = strlen(src); s->chars = wms_malloc(s->len + 1); strcpy(s->chars, src); assert(strlen(s->chars) == s->len); } void str_initCharsLen(Str *s, const char *src, int len) { assert(strlen(src) >= len); MAGIC_SET(s); s->len = s->maxLen = len; s->chars = wms_malloc(s->len + 1); strncpy(s->chars, src, len); s->chars[len] = '\0'; assert(strlen(s->chars) == s->len); } void str_deinit(Str *s) { assert(MAGIC(s)); if (s->chars != &empty) wms_free(s->chars); MAGIC_UNSET(s); } void str_copy(Str *dest, const Str *src) { char *newChars; assert(MAGIC(dest)); assert(MAGIC(src)); assert(strlen(src->chars) == src->len); if (src->len > dest->maxLen) { dest->maxLen = src->len * 2; newChars = wms_malloc(dest->maxLen + 1); if (dest->chars != &empty) wms_free(dest->chars); dest->chars = newChars; } strcpy(dest->chars, src->chars); dest->len = src->len; assert(strlen(dest->chars) == dest->len); } void str_copyChars(Str *dest, const char *src) { int srcLen = strlen(src); char *newChars; assert(MAGIC(dest)); if (srcLen > dest->maxLen) { dest->maxLen = srcLen * 2; newChars = wms_malloc(dest->maxLen + 1); if (dest->chars != &empty) wms_free(dest->chars); dest->chars = newChars; } strcpy(dest->chars, src); dest->len = srcLen; assert(strlen(dest->chars) == dest->len); } void str_copyCharsLen(Str *dest, const char *src, int srcLen) { char *newChars; assert(MAGIC(dest)); assert(strlen(src) >= srcLen); if (srcLen > dest->maxLen) { dest->maxLen = srcLen * 2; newChars = wms_malloc(dest->maxLen + 1); if (dest->chars != &empty) wms_free(dest->chars); dest->chars = newChars; } strncpy(dest->chars, src, srcLen); dest->chars[dest->len = srcLen] = '\0'; assert(strlen(dest->chars) == dest->len); } void str_copyChar(Str *dest, char src) { char *newChars; assert(MAGIC(dest)); if (1 > dest->maxLen) { dest->maxLen = 32; newChars = wms_malloc(dest->maxLen + 1); if (dest->chars != &empty) wms_free(dest->chars); dest->chars = newChars; } dest->chars[0] = src; dest->chars[1] = '\0'; dest->len = 1; assert(src != '\0'); } void str_cat(Str *dest, const Str *src) { char *newChars; assert(MAGIC(dest)); assert(MAGIC(src)); assert(strlen(dest->chars) == dest->len); assert(strlen(src->chars) == src->len); if (dest->len + src->len > dest->maxLen) { dest->maxLen = (dest->len + src->len) * 2; newChars = wms_malloc(dest->maxLen + 1); strcpy(newChars, dest->chars); if (dest->chars != &empty) wms_free(dest->chars); dest->chars = newChars; } strcpy(dest->chars + dest->len, src->chars); dest->len += src->len; assert(strlen(dest->chars) == dest->len); } void str_catChars(Str *dest, const char *src) { int srcLen = strlen(src); char *newChars; assert(MAGIC(dest)); assert(strlen(dest->chars) == dest->len); if (dest->len + srcLen > dest->maxLen) { dest->maxLen = (dest->len + srcLen) * 2; newChars = wms_malloc(dest->maxLen + 1); strcpy(newChars, dest->chars); if (dest->chars != &empty) wms_free(dest->chars); dest->chars = newChars; } strcpy(dest->chars + dest->len, src); dest->len += srcLen; } void str_catCharsLen(Str *dest, const char *src, int srcLen) { char *newChars; assert(MAGIC(dest)); assert(strlen(dest->chars) == dest->len); assert(strlen(src) >= srcLen); if (dest->len + srcLen > dest->maxLen) { dest->maxLen = (dest->len + srcLen) * 2; newChars = wms_malloc(dest->maxLen + 1); strcpy(newChars, dest->chars); if (dest->chars != &empty) wms_free(dest->chars); dest->chars = newChars; } strncpy(dest->chars + dest->len, src, srcLen); dest->len += srcLen; dest->chars[dest->len] = '\0'; } void str_catChar(Str *dest, char src) { char *newChars; assert(MAGIC(dest)); assert(strlen(dest->chars) == dest->len); if (dest->len + 1 > dest->maxLen) { dest->maxLen = (dest->len + 1) * 2; newChars = wms_malloc(dest->maxLen + 1); strcpy(newChars, dest->chars); if (dest->chars != &empty) wms_free(dest->chars); dest->chars = newChars; assert(strlen(dest->chars) == dest->len); } dest->chars[dest->len++] = src; dest->chars[dest->len] = '\0'; assert(strlen(dest->chars) == dest->len); } void str_catInt(Str *dest, int src) { char srcChars[SIZEOF_INT * 3 + 1]; assert(MAGIC(dest)); sprintf(srcChars, "%d", src); str_catChars(dest, srcChars); } void str_print(Str *dest, const char *fmt, ...) { va_list ap; char tmp[40]; static char tmpFmt[] = "%0xd"; double dval; const char *sVal; assert(MAGIC(dest)); str_copyChars(dest, ""); va_start(ap, fmt); while (*fmt) { if (*fmt != '%') str_catChar(dest, *fmt); else { ++fmt; switch(*fmt) { case '0': assert(fmt[2] == 'd'); tmpFmt[2] = fmt[1]; sprintf(tmp, tmpFmt, va_arg(ap, int)); str_catChars(dest, tmp); fmt += 2; break; case 'c': str_catChar(dest, (char)va_arg(ap, int)); break; case 'd': str_catInt(dest, va_arg(ap, int)); break; case 'g': dval = va_arg(ap, double); if ((int)dval == dval) { sprintf(tmp, "%d", (int)dval); } else { sprintf(tmp, "%.1f", dval); } str_catChars(dest, tmp); break; case 's': sVal = va_arg(ap, char *); assert(sVal != NULL); str_catChars(dest, sVal); break; default: str_catChar(dest, *fmt); break; } } ++fmt; } va_end(ap); } int str_alphaCmp(const void *a, const void *b) { const Str *sa = a, *sb = b; assert(MAGIC(sa)); assert(MAGIC(sb)); return(strcmp(sa->chars, sb->chars)); } pente-2.2.5/wmslib/src/but/net.c0100664000076400007640000005206407045637750014700 0ustar wmswms/* * wmslib/src/but/net.c, part of wmslib (Library functions) * Copyright (C) 1995-1997 William Shubert. * See "configure.h.in" for more copyright information. */ #include #if X11_DISP #ifdef STDC_HEADERS #include #include #endif /* STDC_HEADERS */ #include #include #include #include #include #include #include #include #ifdef HAVE_SYS_SELECT_H #include #endif #include #if HAVE_SOCKETS #include #if HAVE_NETINET_IN_H #include #endif #if HAVE_SYS_IN_H #include #endif #if HAVE_SYS_INET_H #include #endif #include #if HAVE_ARPA_NAMESER_H #include #endif #if HAVE_RESOLV_H #include #endif #if HAVE_SYS_UTSNAME_H #include #endif #include #endif /* HAVE_SOCKETS */ #include #include #include #include #if HAVE_SOCKETS /********************************************************************** * Forward Declarations **********************************************************************/ static ButOut newConn(void *packet, int fd); static ButRnet *newRnet(ButEnv *env); static ButOut getNetData(void *packet, int fd); static ButOut finishWrite(void *packet, int fd); static void putProtoWho(ButRnet *net); static void butRnet_close(ButRnet *net, const char *reason, bool forced); static bool butRnet_write(ButRnet *net, ButNetMsg *msg); static void butRnet_sendMMove(ButRnet *net, int winId, int lx, int ly, int lw, int lh, ButCur type); static void newFlags(ButRnet *net, int id, uint newFlags); static ButOut butSpec(ButEnv *env, int butId, void *buf, int bufLen); /********************************************************************** * Functions **********************************************************************/ ButLnet *butLnet_create(ButEnv *env, int port, void *packet, ButOut ocallback(ButRnet *net), ButOut callback(ButRnet *net, void *cmd, int cmdLen), ButOut ccallback(ButRnet *net, const char *reason)) { ButLnet *net = wms_malloc(sizeof(ButLnet)); struct sockaddr_in sa; MAGIC_SET(net); net->env = env; net->packet = packet; net->valid = net->error = FALSE; net->fd = socket(AF_INET, SOCK_STREAM, 0); net->ocallback = ocallback; net->callback = callback; net->ccallback = ccallback; if (net->fd == -1) { net->error = TRUE; net->errNum = errno; return(net); } sa.sin_family = AF_INET; sa.sin_addr.s_addr = INADDR_ANY; sa.sin_port = htons(port); if (bind(net->fd, (struct sockaddr *)&sa, sizeof(sa)) != 0) { net->error = TRUE; net->errNum = errno; close(net->fd); return(net); } if (listen(net->fd, 2) != 0) { net->error = TRUE; net->errNum = errno; close(net->fd); return(net); } butEnv_addFile(env, BUT_READFILE, net->fd, net, newConn); net->valid = TRUE; return(net); } ButRnet *butRnet_create(ButEnv *env, const char *address, int port, void *packet, ButOut ocallback(ButRnet *net), ButOut callback(ButRnet *net, void *cmd, int cmdLen), ButOut ccallback(ButRnet *net, const char *reason)) { ButRnet *net; struct sockaddr_in sa; struct hostent *hp; net = newRnet(env); net->packet = packet; net->state = butRnetState_closed; net->error = net->lookupError = net->butNetError = FALSE; net->ocallback = ocallback; net->callback = callback; net->ccallback = ccallback; if ((net->fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) { net->error = TRUE; net->errNum = errno; return(net); } sa.sin_family = AF_INET; if ((hp = gethostbyname(address)) == NULL) { net->lookupError = TRUE; #if HAVE_H_ERRNO net->errNum = h_errno; #else net->errNum = HOST_NOT_FOUND; #endif return(net); } memcpy(&sa.sin_addr, hp->h_addr, hp->h_length); sa.sin_port = htons(port); if (connect(net->fd, (struct sockaddr *)&sa, sizeof(sa)) < 0) { net->error = TRUE; net->errNum = errno; return(net); } net->state = butRnetState_pwWait; fcntl(net->fd, F_SETFL, O_NONBLOCK); putProtoWho(net); butEnv_addFile(net->env, BUT_READFILE, net->fd, net, getNetData); return(net); } void butRnet_accept(ButRnet *net) { assert(net->state == butRnetState_accWait); net->state = butRnetState_open; net->lType = net->env->curlast; net->env->curlast = butCur_bogus; /* Force the cursor type to be sent. */ putProtoWho(net); } void butLnet_destroy(ButLnet *net) { assert(MAGIC(net)); if (net->valid) { close(net->fd); butEnv_rmFile(net->env, BUT_READFILE, net->fd); } MAGIC_UNSET(net); wms_free(net); } void butRnet_destroy(ButRnet *net, const char *reason) { ButNetMsg msgOut; assert(MAGIC(net)); if (net->state < butRnetState_closing) { msgOut.type = int_stdInt32(BUTNET_CLOSE); msgOut.length = int_stdInt32(2*4+strlen(reason)+1); strcpy(msgOut.perType.close, reason); butRnet_write(net, &msgOut); butRnet_close(net, NULL, FALSE); } } static ButOut newConn(void *packet, int fd) { ButLnet *lnet = packet; ButRnet *rnet; struct sockaddr_in addr; int addrlen = sizeof(addr); assert(MAGIC(lnet)); rnet = newRnet(lnet->env); rnet->fd = accept(lnet->fd, (struct sockaddr *)&addr, &addrlen); if (rnet->fd < 0) { rnet->env->partners[rnet->partner] = NULL; MAGIC_UNSET(rnet); wms_free(rnet); return(0); } rnet->packet = lnet->packet; rnet->ocallback = lnet->ocallback; rnet->callback = lnet->callback; rnet->ccallback = lnet->ccallback; fcntl(rnet->fd, F_SETFL, O_NONBLOCK); rnet->state = butRnetState_pwAccWait; butEnv_addFile(rnet->env, BUT_READFILE, rnet->fd, rnet, getNetData); return(0); } static ButRnet *newRnet(ButEnv *env) { ButRnet *net = wms_malloc(sizeof(ButRnet)); int newNumPartners, i, partner; ButRnet **newPartners; MAGIC_SET(net); for (partner = 0; partner < env->numPartners; ++partner) { if (!env->partners[partner]) break; } if (partner == env->numPartners) { newNumPartners = (env->numPartners + 1) * 2; newPartners = wms_malloc(newNumPartners * sizeof(ButRnet *)); for (i = 0; i < env->numPartners; ++i) { newPartners[i] = env->partners[i]; } for (; i < newNumPartners; ++i) newPartners[i] = NULL; if (env->partners) wms_free(env->partners); env->numPartners = newNumPartners; env->partners = newPartners; } env->partners[partner] = net; net->partner = partner; net->env = env; net->error = FALSE; net->wBufSize = net->wBufStart = net->wBufLen = 0; net->wBuffer = NULL; net->rBufAmt = 0; net->rBufLen = BUTNET_MAXCMD * 2 + 2; net->fd = -1; net->ackNeeded = net->mouseMove = FALSE; net->who = "Unknown"; net->protocol = "Unknown"; if ((env->last_mwin) && (env->last_mx >= 0)) { assert(MAGIC(env->last_mwin)); net->lWinId = env->last_mwin->id; net->lx = env->last_mx; net->ly = env->last_my; net->lw = env->last_mwin->w; net->lh = env->last_mwin->h; net->lType = env->curnum; } else net->lWinId = -2; net->lPress = net->lTwitch = -1; butRcur_create(&net->rc, net->env); return(net); } /* Returns TRUE if success. */ static bool butRnet_write(ButRnet *net, ButNetMsg *msg) { int len = stdInt32_int(msg->length) + 8; int amtWritten; char *remainder = (char *)msg; assert(MAGIC(net)); if (net->wBufLen == 0) { /* Nothing queued up. Try to write directly! */ amtWritten = write(net->fd, msg, len); if (amtWritten == len) return(TRUE); if (amtWritten < 0) { butRnet_close(net, strerror(errno), TRUE); return(FALSE); } remainder += amtWritten; len -= amtWritten; } /* Not all got written. Put some into the wBuffer. */ if (len + net->wBufStart + net->wBufLen > net->wBufSize) { char *newBuf; newBuf = wms_malloc(net->wBufSize = len + net->wBufStart + net->wBufLen); if (net->wBufLen) memcpy(newBuf, net->wBuffer+net->wBufStart, net->wBufLen); net->wBufStart = 0; if (net->wBuffer) wms_free(net->wBuffer); net->wBuffer = newBuf; } memcpy(remainder, net->wBuffer + net->wBufStart + net->wBufLen, len); net->wBufLen += len; butEnv_addFile(net->env, BUT_WRITEFILE, net->fd, net, finishWrite); return(TRUE); } static ButOut finishWrite(void *packet, int fd) { ButRnet *net = packet; int amtWritten; assert(MAGIC(net)); amtWritten = write(net->fd, net->wBuffer + net->wBufStart, net->wBufLen); if (amtWritten == net->wBufLen) { butEnv_rmFile(net->env, BUT_WRITEFILE, net->fd); net->wBufLen = 0; net->wBufStart = 0; if (net->state == butRnetState_closing) { close(net->fd); net->fd = -1; MAGIC_UNSET(net); wms_free(net); } } else if (amtWritten < 0) { butRnet_close(net, strerror(errno), TRUE); return(0); } else { net->wBufStart += amtWritten; net->wBufLen -= amtWritten; } return(0); } static ButOut getNetData(void *packet, int fd) { ButRnet *net = packet; int readLen, i, msgType; ButOut res = 0; char *temp; assert(MAGIC(net)); if (net->rBufAmt < 4) { /* Waiting for the length count. */ readLen = read(fd, (char *)&net->rBuffer + net->rBufAmt, 4 - net->rBufAmt); if (readLen <= 0) { if (readLen == 0) butRnet_close(net, "Connection closed", TRUE); else if ((readLen < 0) && (errno != EAGAIN)) butRnet_close(net, strerror(errno), TRUE); return(res); } if ((net->rBufAmt += readLen) < 4) return(0); net->rBufMsgLen = stdInt32_int(net->rBuffer.length); if (net->rBufMsgLen > BUTNET_MAXCMD) { fprintf(stderr, "Bogus command\n"); for (;;); } net->rBufMsgLen += 8; return(0); } if ((net->rBufMsgLen > BUTNET_MAXCMD+8) || (net->rBufMsgLen < 8)) { butRnet_close(net, "Invalid data on connection", TRUE); return(res); } readLen = read(fd, (char *)&net->rBuffer + net->rBufAmt, net->rBufMsgLen - net->rBufAmt); if (readLen <= 0) { if (readLen == 0) butRnet_close(net, "Connection closed", TRUE); else if ((readLen < 0) && (errno != EAGAIN)) butRnet_close(net, strerror(errno), TRUE); return(res); } net->rBufAmt += readLen; if (net->rBufAmt == net->rBufMsgLen) { msgType = stdInt32_int(net->rBuffer.type); net->rBufAmt = 0; switch(msgType) { case BUTNET_PROTOWHO: if (net->state == butRnetState_pwWait) { net->state = butRnetState_open; /* Force the cursor type to be sent. */ net->lType = net->env->curlast; net->env->curlast = butCur_bogus; } else if (net->state == butRnetState_pwAccWait) { net->state = butRnetState_accWait; } else { butRnet_close(net, "Invalid data on connection", TRUE); break; } if (net->rBufMsgLen != sizeof(net->rBuffer.perType.protoWho) + 8) { butRnet_close(net, "Invalid data on connection", TRUE); break; } net->rmtPartner = stdInt32_int(net->rBuffer.perType.protoWho.context); temp = wms_malloc(i = (strlen(net->rBuffer.perType.protoWho.proto) + 1)); strcpy(temp, net->rBuffer.perType.protoWho.proto); net->protocol = temp; temp = wms_malloc(strlen(net->rBuffer.perType.protoWho.who) + 1); strcpy(temp, net->rBuffer.perType.protoWho.who); net->who = temp; return(net->ocallback(net)); break; case BUTNET_CLOSE: butRnet_close(net, net->rBuffer.perType.close, FALSE); break; case BUTNET_USERDATA: if (net->callback) return(net->callback(net, net->rBuffer.perType.userData, stdInt32_int(net->rBuffer.length))); break; case BUTNET_MOUSE: if (net->rBufMsgLen != sizeof(net->rBuffer.perType.mouse) + 8) { butRnet_close(net, "Invalid data on connection", TRUE); break; } butRcur_move(&net->rc, stdInt32_int(net->rBuffer.perType.mouse.win), stdInt32_int(net->rBuffer.perType.mouse.x), stdInt32_int(net->rBuffer.perType.mouse.y), stdInt32_int(net->rBuffer.perType.mouse.w), stdInt32_int(net->rBuffer.perType.mouse.h), stdInt32_int(net->rBuffer.perType.mouse.type)); net->rBuffer.length = int_stdInt32(0); net->rBuffer.type = int_stdInt32(BUTNET_MOUSEACK); butRnet_write(net, &net->rBuffer); break; case BUTNET_MOUSEACK: if (net->rBufMsgLen != 8) { butRnet_close(net, "Invalid data on connection", TRUE); break; } net->ackNeeded = FALSE; if (net->mouseMove) { net->mouseMove = FALSE; butRnet_sendMMove(net, -1, -1,-1, -1,-1, -1); } break; case BUTNET_NEWFLAGS: if (net->rBufMsgLen != sizeof(net->rBuffer.perType.newFlags) + 8) { butRnet_close(net, "Invalid data on connection", TRUE); break; } newFlags(net, stdInt32_int(net->rBuffer.perType.newFlags.butId), stdInt32_int(net->rBuffer.perType.newFlags.newFlags)); break; case BUTNET_BUTSPEC: res |= butSpec(net->env, stdInt32_int(net->rBuffer.perType.butSpec.butId), net->rBuffer.perType.butSpec.butData, stdInt32_int(net->rBuffer.length) - sizeof(StdInt32)); break; default: butRnet_close(net, "Invalid data on connection", TRUE); break; } } return(res); } static void newFlags(ButRnet *net, int id, uint newFlags) { ButEnv *env = net->env; But *but; if (id < env->maxButIds) { but = env->id2But[id]; if (but) { if (newFlags & BUT_PRESSED) net->lPress = id; else if (net->lPress == id) net->lPress = -1; if (newFlags & BUT_TWITCHED) net->lTwitch = id; else if (net->lTwitch == id) net->lTwitch = -1; but_newFlags(but, (newFlags & (BUT_NETMASK<flags & ~(BUT_NETMASK<env; ButNetMsg protoOut; assert(MAGIC(net)); protoOut.length = int_stdInt32(sizeof(protoOut.perType.protoWho)); protoOut.type = int_stdInt32(BUTNET_PROTOWHO); #if HAVE_SYS_UTSNAME_H uname(&unameOut); #endif if ((loginName = getlogin()) == NULL) { pw = getpwuid(getuid()); loginName = pw->pw_name; } strcpy(protoOut.perType.protoWho.proto, env->protocol); protoOut.perType.protoWho.proto[sizeof(protoOut.perType.protoWho.proto) - 1] = '\0'; sprintf(protoOut.perType.protoWho.who, "%s@%s", loginName, #if HAVE_SYS_UTSNAME_H unameOut.nodename #else "unknown" #endif ); butRnet_write(net, &protoOut); } static void butRnet_close(ButRnet *net, const char *reason, bool force) { ButEnv *env = net->env; assert(MAGIC(net)); if (net->lPress != -1) { if (env->id2But[net->lPress]) { but_newFlags(env->id2But[net->lPress], env->id2But[net->lPress]->flags & ~BUT_NETPRESS); } } if (net->lTwitch != -1) { if (env->id2But[net->lTwitch]) { but_newFlags(env->id2But[net->lTwitch], env->id2But[net->lTwitch]->flags & ~BUT_NETTWITCH); } } if (net->state < butRnetState_closing) { if (reason && net->ccallback) net->ccallback(net, reason); net->state = butRnetState_closing; butEnv_rmFile(net->env, BUT_READFILE, net->fd); if (force || (net->wBufLen == 0)) { close(net->fd); net->fd = -1; if (net->wBufLen != 0) butEnv_rmFile(net->env, BUT_WRITEFILE, net->fd); } } net->env->partners[net->partner] = NULL; MAGIC_UNSET(net); wms_free(net); } void butRnet_send(ButRnet *net, void *buffer, int len) { ButNetMsg msg; assert(len <= BUTNET_MAXCMD); msg.length = int_stdInt32(len); msg.type = int_stdInt32(BUTNET_USERDATA); memcpy(msg.perType.userData, buffer, len); butRnet_write(net, &msg); } void butRnet_mMove(ButEnv *env, int winId, int lx,int ly, int lw,int lh, ButCur curnum) { int i; for (i = 0; i < env->numPartners; ++i) { if (env->partners[i]) { if (butRnet_valid(env->partners[i]) && ((winId != -2) || (env->partners[i]->lWinId != -2))) butRnet_sendMMove(env->partners[i], winId, lx,ly, lw,lh, curnum); } } } static void butRnet_sendMMove(ButRnet *net, int winId, int lx, int ly, int lw, int lh, ButCur curnum) { ButNetMsg msg; if (winId == -1) winId = net->lWinId; if (lx == -1) lx = net->lx; if (ly == -1) ly = net->ly; if (lw == -1) lw = net->lw; if (lh == -1) lh = net->lh; if (curnum == -1) curnum = net->lType; net->lWinId = winId; net->lx = lx; net->ly = ly; net->lw = lw; net->lh = lh; net->lType = curnum; if (net->ackNeeded) net->mouseMove = TRUE; else { msg.length = int_stdInt32(sizeof(msg.perType.mouse)); msg.type = int_stdInt32(BUTNET_MOUSE); msg.perType.mouse.context = int_stdInt32(0); msg.perType.mouse.win = int_stdInt32(winId); msg.perType.mouse.x = int_stdInt32(lx); msg.perType.mouse.y = int_stdInt32(ly); msg.perType.mouse.w = int_stdInt32(lw); msg.perType.mouse.h = int_stdInt32(lh); msg.perType.mouse.type = int_stdInt32(curnum); assert((curnum == -1) || (curnum < butCur_bogus)); butRnet_write(net, &msg); } } void butRnet_newFlags(ButEnv *env, int butId, uint newFlags) { int i; ButNetMsg msg; if ((butId != -2) && (env->numPartners > 0)) { assert(butId >= 0); assert(butId < env->maxButIds); newFlags = (newFlags & ~(BUT_NETTWITCH|BUT_NETPRESS|BUT_NETKEY)) | ((newFlags & BUT_NETMASK) << BUT_NETSHIFT); msg.length = int_stdInt32(sizeof(msg.perType.newFlags)); msg.type = int_stdInt32(BUTNET_NEWFLAGS); msg.perType.newFlags.butId = int_stdInt32(butId); msg.perType.newFlags.newFlags = int_stdInt32(newFlags); for (i = 0; i < env->numPartners; ++i) { if (env->partners[i]) if (butRnet_valid(env->partners[i])) butRnet_write(env->partners[i], &msg); } } } static ButOut butSpec(ButEnv *env, int butId, void *buf, int bufLen) { But *but; but = env->id2But[butId]; assert(but->action->netMessage); return(but->action->netMessage(but, buf, bufLen)); } #else /* !HAVE_SOCKETS */ ButLnet *butLnet_create(ButEnv *env, int port, void *packet, ButOut ocallback(ButRnet *net), ButOut callback(ButRnet *net, void *cmd, int cmdLen), ButOut ccallback(ButRnet *net, const char *reason)) { ButLnet *net = wms_malloc(sizeof(ButLnet)); net->error = TRUE; net->valid = FALSE; net->errNum = EPERM; return(net); } ButRnet *butRnet_create(ButEnv *env, char *address, int port, void *packet, ButOut ocallback(ButRnet *net), ButOut callback(ButRnet *net, void *cmd, int cmdLen), ButOut ccallback(ButRnet *net, const char *reason)) { ButRnet *net = wms_malloc(sizeof(ButRnet)); net->error = TRUE; net->errNum = EPERM; net->state = butRnetState_closed; return(net); } void butLnet_destroy(ButLnet *net) { wms_free(net); } void butRnet_destroy(ButRnet *net, char *reason) { wms_free(net); } bool butRnet_write(ButRnet *net, ButNetMsg *msg) { return(FALSE); } void butRnet_send(ButRnet *net, void *buffer, int len) {} void butRnet_mMove(ButEnv *env, int winId, int lx,int ly, int lw,int lh, ButCur curnum) {} void butRnet_newFlags(ButEnv *env, int butId, uint newFlags) {} void butRnet_accept(ButRnet *net) {} #endif /* HAVE_SOCKETS */ void but_setId(But *but, int id) { ButEnv *env = but->win->env; int i; assert(MAGIC(but)); if (id >= env->maxButIds) { But **newId2But; int newMaxButIds = (id + 1)*2; newId2But = wms_malloc(newMaxButIds * sizeof(But *)); for (i = 0; i < env->maxButIds; ++i) newId2But[i] = env->id2But[i]; for (; i < newMaxButIds; ++i) newId2But[i] = NULL; env->maxButIds = newMaxButIds; if (env->id2But) wms_free(env->id2But); env->id2But = newId2But; } if (but->id != -1) { assert(but->id < env->maxButIds); env->id2But[id] = NULL; } env->id2But[id] = but; but->id = id; } void butWin_setId(ButWin *win, int id) { ButEnv *env = win->env; int i; assert(MAGIC(win)); if (id >= env->maxWinIds) { ButWin **newId2Win; int newMaxWinIds = (id + 1)*2; newId2Win = wms_malloc(newMaxWinIds * sizeof(ButWin *)); for (i = 0; i < env->maxWinIds; ++i) newId2Win[i] = env->id2Win[i]; for (; i < newMaxWinIds; ++i) newId2Win[i] = NULL; env->maxWinIds = newMaxWinIds; if (env->id2Win) wms_free(env->id2Win); env->id2Win = newId2Win; } if (win->id != -1) { assert(win->id < env->maxWinIds); env->id2Win[id] = NULL; } env->id2Win[id] = win; win->id = id; } void butRnet_butSpecSend(But *but, void *buffer, int len) { ButEnv *env; ButNetMsg msg; int i; assert(len < BUTNET_MAXCMD - sizeof(StdInt32)); if (but->id >= 0) { env = but->win->env; if (env->numPartners > 0) { msg.length = int_stdInt32(len + 4); msg.type = int_stdInt32(BUTNET_BUTSPEC); msg.perType.butSpec.butId = int_stdInt32(but->id); if (len > 0) memcpy(msg.perType.butSpec.butData, buffer, len); for (i = 0; i < env->numPartners; ++i) { if (env->partners[i]) { if (butRnet_valid(env->partners[i])) butRnet_write(env->partners[i], &msg); } } } } } #endif /* X11_DISP */ pente-2.2.5/wmslib/src/but/box.c0100664000076400007640000004266207045637750014705 0ustar wmswms/* * wmslib/src/but/box.c, part of wmslib (Library functions) * Copyright (C) 1994-1997 William Shubert. * See "configure.h.in" for more copyright information. */ #include #ifdef X11_DISP #ifdef STDC_HEADERS #include #include #endif /* STDC_HEADERS */ #include #include #include #include #include #include #include #ifdef HAVE_SYS_SELECT_H #include #endif #include #include #include /********************************************************************** * Data Types **********************************************************************/ typedef struct Box_struct { Pixmap ulmap, lrmap; int ulcolor, lrcolor; } Box; typedef struct BoxFilled_struct { Pixmap ulmap, lrmap, cmap; int ulcolor, lrcolor, ccolor; } BoxFilled; /********************************************************************** * Foward Declarations **********************************************************************/ static void box_draw(But *but, int x, int y, int w, int h); static void boxFilled_draw(But *but, int x, int y, int w, int h); static ButOut curve(int x, int y, int radius, int start, int sweep, XPoint *pts); static ButOut box_destroy(But *but); static ButOut boxFilled_destroy(But *but); static bool boxFilled_resize(But *but, int oldX, int oldY, int oldW, int oldH); static ButOut box_mmove(But *but, int x, int y); #define CIRCLE 64 /* Points to make a full circle. */ /********************************************************************** * Globals **********************************************************************/ static ButAction box_action = { box_mmove, NULL, NULL, NULL, NULL, NULL, box_draw, box_destroy, but_flags, NULL, NULL}; static ButAction boxFilled_action = { NULL, NULL, NULL, NULL, NULL, NULL, boxFilled_draw, boxFilled_destroy, but_flags, NULL, boxFilled_resize}; /********************************************************************** * Functions **********************************************************************/ But *butBox_create(ButWin *win, int layer, int flags) { But *but; Box *box; box = (Box *)wms_malloc(sizeof(Box)); but = but_create(win, box, &box_action); but->layer = layer; but->flags = flags; box->ulcolor = BUT_LIT; box->lrcolor = BUT_SHAD; box->ulmap = None; box->lrmap = None; but_init(but); return(but); } void butBox_setColors(But *but, int ul, int lr) { Box *box = but->iPacket; assert(but->action == &box_action); if (ul >= 0) { box->ulcolor = ul; box->ulmap = None; } if (lr >= 0) { box->lrcolor = lr; box->lrmap = None; } but_draw(but); } void butBox_setPixmaps(But *but, Pixmap ul, Pixmap lr) { Box *box = but->iPacket; assert(but->action == &box_action); if (ul != None) box->ulmap = ul; if (lr != None) box->lrmap = lr; but_draw(but); } static void box_draw(But *but, int x, int y, int w, int h) { ButEnv *env = but->win->env; int butbw = env->stdButBw; Box *box = but->iPacket; if ((x < but->x + butbw) || (x+w > but->x + but->w - butbw) || (y < but->y + butbw) || (y+h > but->y + but->h - butbw)) { but_drawBox(but->win, but->x, but->y, but->w, but->h,0, butbw, 0, box->ulcolor, box->lrcolor, box->ulmap, box->lrmap); } } static ButOut box_destroy(But *but) { wms_free(but->iPacket); return(0); } void but_drawBox(ButWin *win, int x, int y, int w, int h, int bstate, int bw, int angles, int ulcolor, int lrcolor, Pixmap ulmap, Pixmap lrmap) { ButEnv *env = win->env; Display *dpy = env->dpy; XPoint points[(CIRCLE/8+1)*4 + (CIRCLE/4+1)*2 + 1]; int abw = (bw * 1448 + 511) / 1024, h2 = h/2; int rounding = env->font0h / 2; int pnum = 0; int xOff = win->xOff, yOff = win->yOff; bool forceTiled; /* For arrows: * a----- h2 = c.y - a.y * / b____ abw = d.x - c.x * / / * c_d * \ \ */ if (angles & BUT_ALEFT) { points[pnum ].x = x + abw + h2 - bw - xOff; points[pnum++].y = y + bw - yOff; points[pnum ].x = x + abw - xOff; points[pnum++].y = y + h2 - yOff; points[pnum ].x = x - xOff; points[pnum++].y = y + h2 - yOff; points[pnum ].x = x + h2 - xOff; points[pnum++].y = y - yOff; } else if (angles & BUT_RLEFT) { pnum += curve(x+rounding-xOff, y+ rounding-yOff, rounding-bw, 90,90, points+pnum); pnum += curve(x+rounding-xOff, y+h-rounding-yOff, rounding-bw, 180,45, points+pnum); pnum += curve(x+rounding-xOff, y+h-rounding-yOff, rounding, 225,-45, points+pnum); pnum += curve(x+rounding-xOff, y+ rounding-yOff, rounding, 180,-90, points+pnum); } else { /* Square left edge. */ points[pnum ].x = x + bw - xOff; points[pnum++].y = y + bw - yOff; points[pnum ].x = x + bw - xOff; points[pnum++].y = y + h - bw - yOff; points[pnum ].x = x - xOff; points[pnum++].y = y + h - yOff; points[pnum ].x = x - xOff; points[pnum++].y = y - yOff; } if (angles & BUT_ARIGHT) { points[pnum ].x = x + w - h2 - xOff; points[pnum++].y = y - yOff; points[pnum ].x = x + w - xOff; points[pnum++].y = y + h2 - yOff; points[pnum ].x = x + w - abw - xOff; points[pnum++].y = y + h2 - yOff; points[pnum ].x = x + w - (abw + h2) + (abw-bw) - xOff; points[pnum++].y = y + bw - yOff; } else if (angles & BUT_RRIGHT) { pnum += curve(x+w-rounding-xOff, y+rounding-yOff, rounding, 90,-45, points+pnum); pnum += curve(x+w-rounding-xOff, y+rounding-yOff, rounding-bw, 0,45, points+pnum); } else { /* Square right edge. */ points[pnum ].x = x + w - xOff; points[pnum++].y = y - yOff; points[pnum ].x = x + w - bw - xOff; points[pnum++].y = y + bw - yOff; } points[pnum] = points[0]; assert(pnum < sizeof(points) / sizeof(points[0])); forceTiled = FALSE; if (bstate == 0) { if (ulmap == None) { butEnv_setXFg(env, ulcolor); } else { forceTiled = TRUE; XSetFillStyle(env->dpy, env->gc, FillTiled); XSetTile(env->dpy, env->gc, ulmap); } } else { if (lrmap == None) { butEnv_setXFg(env, lrcolor); } else { forceTiled = TRUE; XSetFillStyle(env->dpy, env->gc, FillTiled); XSetTile(env->dpy, env->gc, lrmap); } } XFillPolygon(dpy, win->win, env->gc, points, pnum, Nonconvex, CoordModeOrigin); h2 = (h + 1) / 2; pnum = 0; if (angles & BUT_ALEFT) { points[pnum ].x = x + abw + h2 - bw - xOff; points[pnum++].y = y + h - bw - yOff; points[pnum ].x = x + abw - xOff; points[pnum++].y = y + h - h2 - yOff; points[pnum ].x = x - xOff; points[pnum++].y = y + h - h2 - yOff; points[pnum ].x = x + h2 - xOff; points[pnum++].y = y + h - yOff; } else if (angles & BUT_RLEFT) { pnum += curve(x+rounding-xOff, y+h-rounding-yOff, rounding-bw, 270,-45, points+pnum); pnum += curve(x+rounding-xOff, y+h-rounding-yOff, rounding, 225,45, points+pnum); } else { /* Square left edge. */ points[pnum ].x = x + bw - xOff; points[pnum++].y = y + h - bw - yOff; points[pnum ].x = x - xOff; points[pnum++].y = y + h - yOff; } if (angles & BUT_ARIGHT) { points[pnum ].x = x + w - h2 - xOff; points[pnum++].y = y + h - yOff; points[pnum ].x = x + w - xOff; points[pnum++].y = y + h - h2 - yOff; points[pnum ].x = x + w - abw - xOff; points[pnum++].y = y + h - h2 - yOff; points[pnum ].x = x + w - (abw + h2) + (abw-bw) - xOff; points[pnum++].y = y + h - bw - yOff; } else if (angles & BUT_RRIGHT) { pnum += curve(x+w-rounding-xOff, y+h-rounding-yOff, rounding, 270,90, points+pnum); pnum += curve(x+w-rounding-xOff, y+rounding-yOff, rounding, 0,45, points+pnum); pnum += curve(x+w-rounding-xOff, y+rounding-yOff, rounding-bw, 45,-45, points+pnum); pnum += curve(x+w-rounding-xOff, y+h-rounding-yOff, rounding-bw, 0,-90, points+pnum); } else { /* Square right edge. */ points[pnum ].x = x + w - xOff; points[pnum++].y = y + h - yOff; points[pnum ].x = x + w - xOff; points[pnum++].y = y - yOff; points[pnum ].x = x + w - bw - xOff; points[pnum++].y = y + bw - yOff; points[pnum ].x = x + w - bw - xOff; points[pnum++].y = y + h - bw - yOff; } points[pnum] = points[0]; assert(pnum < sizeof(points) / sizeof(points[0])); if (bstate == 0) { if (lrmap == None) { if (forceTiled) { XSetFillStyle(env->dpy, env->gc, FillSolid); forceTiled = FALSE; } butEnv_setXFg(env, lrcolor); } else { forceTiled = TRUE; XSetFillStyle(env->dpy, env->gc, FillTiled); XSetTile(env->dpy, env->gc, lrmap); } } else { if (ulmap == None) { if (forceTiled) { XSetFillStyle(env->dpy, env->gc, FillSolid); forceTiled = FALSE; } butEnv_setXFg(env, ulcolor); } else { if (!forceTiled) { XSetFillStyle(env->dpy, env->gc, FillTiled); forceTiled = TRUE; } XSetTile(env->dpy, env->gc, ulmap); } } XFillPolygon(dpy, win->win, env->gc, points, pnum, Nonconvex, CoordModeOrigin); if (forceTiled) butEnv_stdFill(env); } static ButOut curve(int x, int y, int radius, int start, int sweep, XPoint *pts) { const int circRadius = 2048; static const int cosine[CIRCLE] = { 2048, 2038, 2009, 1960, 1892, 1806, 1703, 1583, 1448, 1299, 1138, 965, 784, 595, 400, 201, 0, -201, -400, -595, -784, -965,-1138,-1299, -1448,-1583,-1703,-1806, -1892,-1960,-2009,-2038, -2048,-2038,-2009,-1960, -1892,-1806,-1703,-1583, -1448,-1299,-1138, -965, -784, -595, -400, -201, 0, 201, 400, 595, 784, 965, 1138, 1299, 1448, 1583, 1703, 1806, 1892, 1960, 2009, 2038}; int i, step, count = 0, limit, round, cv; start = (start * CIRCLE) / 360; sweep = (sweep * CIRCLE) / 360; if (sweep > 0) step = 1; else step = -1; limit = step*sweep; for (i = start, count = 0; count <= limit; i += step, ++count) { cv = cosine[i & (CIRCLE-1)]; if (cv < 0) round = -circRadius/2; else round = circRadius/2; pts[count].x = x + (cv * radius + round) / circRadius; cv = cosine[(CIRCLE/4 + i) & (CIRCLE-1)]; if (cv < 0) round = -circRadius/2; else round = circRadius/2; pts[count].y = y + (cv * radius + round) / circRadius; } return(count); } void but_drawCt(ButWin *win, int flags, int fgpic, int bgpic, int pbgpic, int x, int y, int w, int h, int bw, const char *text, int angles, int fontnum) { ButEnv *env = win->env; but_drawCtb(win, flags, fgpic, bgpic, pbgpic, x, y, w, h, bw, angles); if (!(flags & BUT_PRESSABLE)) { XSetFillStyle(env->dpy, env->gc, FillStippled); XSetForeground(env->dpy, env->gc, env->colors[fgpic]); } else butEnv_setXFg(env, fgpic); if ((flags & BUT_PRESSED) && (flags & BUT_TWITCHED)) { x += bw/2; y += bw/2; } butWin_write(win, x + (w - butEnv_textWidth(env, text, fontnum))/2, y + (h - butEnv_fontH(env, fontnum)) / 2, text, fontnum); if (!(flags & BUT_PRESSABLE)) { butEnv_stdFill(env); } } void but_drawCtb(ButWin *win, int flags, int fgpic, int bgpic, int pbgpic, int x, int y, int w, int h, int bw, int angles) { ButEnv *env = win->env; but_drawBox(win, x, y, w, h, flags & (BUT_PRESSED|BUT_NETPRESS), bw, angles, BUT_LIT, BUT_SHAD, None, None); if ((flags & (BUT_PRESSED|BUT_NETPRESS)) && (flags & (BUT_TWITCHED|BUT_NETTWITCH|BUT_KEYPRESSED|BUT_NETKEY))) bgpic = pbgpic; butEnv_setXFg(env, bgpic); x -= win->xOff; y -= win->yOff; if (angles) { XPoint points[CIRCLE + 5]; int npoints = 0, abw = (bw * 1448 + 511) / 1024, rnd = env->font0h / 2; if (angles & BUT_ALEFT) { points[npoints ].x = x + abw + h/2 - bw; points[npoints++].y = y + bw; points[npoints ].x = x + abw; points[npoints++].y = y + h/2; points[npoints ].x = x + abw + (h+1)/2 - bw; points[npoints++].y = y + h - bw; } else if (angles & BUT_RLEFT) { npoints += curve(x+rnd,y+rnd, rnd-bw, 90,90, points+npoints); npoints += curve(x+rnd,y+h-rnd, rnd-bw, 180,90, points+npoints); } else { points[npoints ].x = x + bw; points[npoints++].y = y + bw; points[npoints ].x = x + bw; points[npoints++].y = y + h - bw; } if (angles & BUT_ARIGHT) { points[npoints ].x = x + w - abw - (h+1)/2 + bw; points[npoints++].y = y + h - bw; points[npoints ].x = x + w - abw; points[npoints++].y = y + h/2; points[npoints ].x = x + w - abw - h/2 + bw; points[npoints++].y = y + bw; } else if (angles & BUT_RRIGHT) { npoints += curve(x+w-rnd,y+h-rnd, rnd-bw, 270,90, points+npoints); npoints += curve(x+w-rnd,y+rnd, rnd-bw, 0,90, points+npoints); } else { points[npoints ].x = x + w - bw; points[npoints++].y = y + h - bw; points[npoints ].x = x + w - bw; points[npoints++].y = y + bw; } points[npoints] = points[0]; assert(npoints < CIRCLE+5); XFillPolygon(env->dpy, win->win, env->gc, points, npoints, Convex, CoordModeOrigin); } else XFillRectangle(env->dpy, win->win, env->gc, x+bw, y+bw, w-2*bw, h-2*bw); } But *butBoxFilled_create(ButWin *win, int layer, int flags) { But *but; BoxFilled *box; box = (BoxFilled *)wms_malloc(sizeof(BoxFilled)); but = but_create(win, box, &boxFilled_action); but->layer = layer; but->flags = flags | BUT_OPAQUE; box->ulcolor = BUT_LIT; box->lrcolor = BUT_SHAD; box->ccolor = BUT_BG; box->ulmap = None; box->lrmap = None; box->cmap = None; but_init(but); return(but); } void butBoxFilled_setColors(But *but, int ul, int lr, int c) { BoxFilled *box = but->iPacket; assert(but->action == &boxFilled_action); if (ul >= 0) { box->ulcolor = ul; box->ulmap = None; } if (lr >= 0) { box->lrcolor = lr; box->lrmap = None; } if (c >= 0) { box->ccolor = c; box->cmap = None; } but_draw(but); } void butBoxFilled_setPixmaps(But *but, Pixmap ul, Pixmap lr, Pixmap c) { BoxFilled *box = but->iPacket; assert(but->action == &boxFilled_action); if (ul != None) box->ulmap = ul; if (lr != None) box->lrmap = lr; if (c != None) box->cmap = c; but_draw(but); } static void boxFilled_draw(But *but, int x, int y, int w, int h) { ButWin *win = but->win; ButEnv *env = win->env; int butbw = env->stdButBw; BoxFilled *box = but->iPacket; if ((x < but->x + butbw) || (x+w > but->x + but->w - butbw) || (y < but->y + butbw) || (y+h > but->y + but->h - butbw)) { but_drawBox(but->win, but->x, but->y, but->w, but->h,0, butbw, 0, box->ulcolor, box->lrcolor, box->ulmap, box->lrmap); } if ((x >= but->x + but->w - butbw) || (y >= but->y + but->h - butbw) || (x + w <= but->x + butbw) || (y+h <= but->y + butbw)) return; if (x < but->x + butbw) { w -= but->x + butbw - x; x = but->x + butbw; } if (y < but->y + butbw) { h -= but->y + butbw - y; y = but->y + butbw; } if (x+w > but->x + but->w - butbw) w = but->x + but->w - butbw - x; if (y+h > but->y + but->h - butbw) h = but->y + but->h - butbw - y; if (box->cmap == None) { butEnv_setXFg(env, box->ccolor); XFillRectangle(env->dpy, win->win, env->gc, x-win->xOff, y-win->yOff, w,h); } else { if (env->colorp) XSetFillStyle(env->dpy, env->gc, FillTiled); XSetTile(env->dpy, env->gc, box->cmap); XFillRectangle(env->dpy, but->win->win, env->gc, x-win->xOff, y-win->yOff, w,h); if (env->colorp) XSetFillStyle(env->dpy, env->gc, FillSolid); } } static ButOut boxFilled_destroy(But *but) { wms_free(but->iPacket); return(0); } /* * This resize redraws only the needed parts of the screen. */ static bool boxFilled_resize(But *but, int oldX, int oldY, int oldW, int oldH) { int x, y, w, h, bw; bw = but->win->env->stdButBw; x = but->x; y = but->y; w = but->w; h = but->h; if ((oldW < 1) || (oldH < 1)) { butWin_redraw(but->win, x, y, w, h); } else if ((x + w < oldX) || (y + h < oldY) || (oldX + oldW < x) || (oldY + oldH < y)) { butWin_redraw(but->win, oldX, oldY, oldW, oldH); butWin_redraw(but->win, x, y, w, h); } else { if (x < oldX) butWin_redraw(but->win, x, y, oldX + bw - x, h); else if (oldX < x) butWin_redraw(but->win, oldX, oldY, x + bw - oldX, oldH); if (y < oldY) butWin_redraw(but->win, x, y, w, oldY + bw - y); else if (oldY < y) butWin_redraw(but->win, oldX, oldY, oldW, y + bw - oldY); if (x + w < oldX + oldW) butWin_redraw(but->win, x + w - bw, oldY, oldX + oldW + bw - x - w, oldH); else if (oldX + oldW < x + w) butWin_redraw(but->win, oldX + oldW - bw, y, x + w + bw - oldX - oldW, h); if (y + h < oldY + oldH) butWin_redraw(but->win, oldX, y + h - bw, oldW, oldY + oldH + bw - y - h); else if (oldY + oldH < y + h) butWin_redraw(but->win, x, oldY + oldH - bw, w, y + h + bw - oldY - oldH); } return(FALSE); } static ButOut box_mmove(But *but, int x, int y) { int bw = butEnv_stdBw(but->win->env); if (((x >= but->x) && (x < but->x + bw)) || ((y >= but->y) && (y < but->y + bw)) || ((x >= but->x + but->w - bw) && (x < but->x + but->w)) || ((y >= but->y + but->h - bw) && (y < but->y + but->h))) return(BUTOUT_CAUGHT); else return(0); } #endif pente-2.2.5/wmslib/src/but/but.c0100664000076400007640000007035707331147374014705 0ustar wmswms/* * wmslib/src/but/but.c, part of wmslib (Library functions) * Copyright (C) 1994-1996 William Shubert. * See "configure.h.in" for more copyright information. */ #include #ifdef X11_DISP #ifdef STDC_HEADERS #include #include #endif /* STDC_HEADERS */ #include #include #include #include #include #include #include #include #include #include #include #include /********************************************************************** * Types **********************************************************************/ typedef struct MouseEventFinder_struct { bool found; Window win; } MouseEventFinder; #if XlibSpecificationRelease < 5 /* * Older (X11R4 and earlier) releases of X11 used a char * where now an * XPointer is used. */ typedef char *XPointer; #endif /********************************************************************** * Forward declarations **********************************************************************/ static ButOut keyPress(ButEnv *env, XKeyPressedEvent *evt); static ButOut keyRelease(ButEnv *env, XKeyReleasedEvent *evt); static ButOut handleEvent(ButEnv *env); static int activateEvent(ButEnv *env); static bool butEnv_stdColors(ButEnv *env); static void getWinXY(Display *dpy, ButWin *win); static ButOut serviceXData(void *packet, int fd); static bool performQueuedWinStuff(ButEnv *env); static Bool anotherMouseEvent(Display *dpy, XEvent *ev, XPointer arg); #if DEBUG static int butErrors(Display *dpy, XErrorEvent *err); #endif /********************************************************************** * Globals **********************************************************************/ ButTimer *but_timerList; Atom but_wmDeleteWindow, but_wmProtocols; static fd_set emptyfds; static struct timeval long_timeout; static void makeStripes(ButEnv *env, int ssize); /* * This array really should be const, but an error in my Xlib.h forces me * to leave it non-const. :-( */ static char greymaps[17][4] = { {0x00, 0x00, 0x00, 0x00}, {0x01, 0x00, 0x00, 0x00}, {0x01, 0x00, 0x04, 0x00}, {0x05, 0x00, 0x04, 0x00}, {0x05, 0x00, 0x05, 0x00}, {0x05, 0x02, 0x05, 0x00}, {0x05, 0x02, 0x05, 0x08}, {0x05, 0x0a, 0x05, 0x08}, {0x05, 0x0a, 0x05, 0x0a}, {0x07, 0x0a, 0x05, 0x0a}, {0x07, 0x0a, 0x0d, 0x0a}, {0x0f, 0x0a, 0x0d, 0x0a}, {0x0f, 0x0a, 0x0f, 0x0a}, {0x0f, 0x0b, 0x0f, 0x0a}, {0x0f, 0x0b, 0x0f, 0x0e}, {0x0f, 0x0f, 0x0f, 0x0e}, {0x0f, 0x0f, 0x0f, 0x0f}}; /********************************************************************** * Functions **********************************************************************/ /* Returns false if the display can't be opened. */ ButEnv *butEnv_create(const char *protocol, const char *dpyname, int shutdown(Display *dpy)) { Display *dpy; ButEnv *env; env = (ButEnv *)wms_malloc(sizeof(ButEnv)); MAGIC_SET(env); if ((dpy = env->dpy = XOpenDisplay(dpyname)) == NULL) { MAGIC_UNSET(env); wms_free(env); return(NULL); } #if DEBUG XSynchronize(dpy, True); XSetErrorHandler(butErrors); #endif env->protocol = (char *)wms_malloc(strlen(protocol)+1); /* Probably not a good idea to silently truncate the protocol like this. */ if (strlen(protocol) > BUTNET_MAXCMD) env->protocol[BUTNET_MAXCMD] = '\0'; strcpy(env->protocol, protocol); if (shutdown != NULL) XSetIOErrorHandler(shutdown); env->shutdown = shutdown; return(env); } ButEnv *butEnv_createNoDpy(const char *protocol) { ButEnv *env; env = (ButEnv *)wms_malloc(sizeof(ButEnv)); MAGIC_SET(env); env->dpy = NULL; return(env); } /* * Returns: * 0 - Black and white display or color=FALSE. * 1 - Couldn't allocate standard colors. Failed. * 2 - Color successful. * 3 - Truecolor display. Color will always be successful. */ int butEnv_init(ButEnv *env, void *packet, const char *atomname, bool color) { Display *dpy; static int firstInit = TRUE; int i; XGCValues defGc; unsigned long gcVals; int retval; XVisualInfo xvi, *vlr; int depth; Window dummyRoot; unsigned int tempW, tempH, dummyBWRet, dummyDepth; int dummyX, dummyY; dpy = env->dpy; env->fonts = NULL; env->colors = NULL; env->colorPmaps = NULL; env->winlist = NULL; if (dpy) { but_wmDeleteWindow = XInternAtom(dpy, "WM_DELETE_WINDOW", 0); but_wmProtocols = XInternAtom(dpy, "WM_PROTOCOLS", 0); depth = DefaultDepth(dpy, DefaultScreen(dpy)); env->depth = depth; } if (firstInit) { firstInit = FALSE; but_timerList = NULL; FD_ZERO(&emptyfds); long_timeout.tv_sec = 60 * 60 * 24 * 365; /* 1 year. */ long_timeout.tv_usec = 0; } if (dpy && color) { xvi.visual = DefaultVisual(dpy, DefaultScreen(dpy)); xvi.visualid = XVisualIDFromVisual(xvi.visual); vlr = XGetVisualInfo(dpy, VisualIDMask, &xvi, &i); if (vlr[0].class == TrueColor) retval = 3; else if (vlr[0].class >= 2) { /* A color class */ retval = 2; } else { /* B&W */ retval = 0; color = FALSE; } XFree(vlr); } else retval = 0; env->packet = packet; if (dpy) { env->prop = XInternAtom(dpy, atomname, False); XGetGeometry(dpy, DefaultRootWindow(dpy), &dummyRoot, &dummyX, &dummyY, &tempW, &tempH, &dummyBWRet, &dummyDepth); env->rootW = tempW; env->rootH = tempH; } env->sReq = NULL; env->sClear = NULL; env->sNotify = NULL; env->winlist = NULL; env->wllen = env->wlmax = 0; env->minWindows = 1; env->butIn = NULL; env->lockBut = NULL; env->last_mwin = NULL; env->stipDisable = None; for (i = 0; i < BUTWRITE_MAXCHARS; ++i) env->write[i].draw = NULL; env->keyModifiers = 0; env->eventNum = 0; env->maxFd = 0; for (i = 0; i < 3; ++i) { env->maxGFds[i] = 0; FD_ZERO(&env->fMasks[i]); env->fCallbacks[i] = NULL; } if (dpy) butEnv_addFile(env, BUT_READFILE, ConnectionNumber(dpy), env, serviceXData); else return(retval); defGc.function = GXcopy; defGc.plane_mask = AllPlanes; defGc.line_style = LineSolid; defGc.cap_style = CapButt; defGc.join_style = JoinMiter; if (color) defGc.fill_style = FillSolid; else defGc.fill_style = FillTiled; defGc.fill_rule = EvenOddRule; defGc.graphics_exposures = False; gcVals = GCFunction | GCPlaneMask | GCLineStyle | GCCapStyle | GCJoinStyle | GCFillStyle | GCFillRule | GCGraphicsExposures; env->gc = XCreateGC(dpy, RootWindow(dpy, DefaultScreen(dpy)), gcVals, &defGc); env->gc2 = XCreateGC(dpy, RootWindow(dpy, DefaultScreen(dpy)), gcVals, &defGc); env->numFonts = 1; env->fonts = (XFontStruct **)wms_malloc(env->numFonts * sizeof(XFontStruct *)); for (i = 0; i < env->numFonts; ++i) { env->fonts[i] = NULL; butEnv_setFont(env, 0, "fixed", 0); } env->colorp = color; env->numColors = BUT_DCOLORS; env->colors = (ulong *)wms_malloc(env->numColors * sizeof(ulong)); env->colorPmaps = (Pixmap *)wms_malloc(env->numColors * sizeof(Pixmap)); if (!butEnv_stdColors(env)) { retval = 1; env->colorp = FALSE; XSetFillStyle(dpy, env->gc, FillTiled); XSetFillStyle(dpy, env->gc2, FillTiled); butEnv_stdColors(env); } env->partner = 0; env->numPartners = 0; env->partners = NULL; env->maxButIds = env->maxWinIds = 0; env->id2But = NULL; env->id2Win = NULL; butEnv_rcInit(env); return(retval); } void butEnv_destroy(ButEnv *env) { int i; assert(MAGIC(env)); while (env->wllen != 0) { but_inEvent = TRUE; for (i = 0; i < env->wllen; ++i) butWin_destroy(env->winlist[i]); but_inEvent = FALSE; while (but_dList(NULL) || butWin_dList(NULL)); } for (i = 0; i < env->numPartners; ++i) { if (env->partners[i] != NULL) { butRnet_destroy(env->partners[i], "Remote user has quit the program."); } } if (env->fonts != NULL) wms_free(env->fonts); if (env->colors != NULL) wms_free(env->colors); if (env->colorPmaps != NULL) wms_free(env->colorPmaps); if (env->winlist != NULL) wms_free(env->winlist); if (env->protocol != NULL) wms_free(env->protocol); MAGIC_UNSET(env); wms_free(env); XCloseDisplay(env->dpy); } void butEnv_events(ButEnv *env) { int i, selected_fds, fdGroup; fd_set fdSets[3]; struct timeval next_timer; ButOut result, temp; if (env->dpy) butEnv_rcActivate(env); for (;;) { result = 0; if (env->dpy) { do { XFlush(env->dpy); while (XPending(env->dpy)) { result |= handleEvent(env); if (result & BUTOUT_STOPWAIT) return; } result |= butEnv_checkTimers(env, &next_timer); if (result & BUTOUT_STOPWAIT) { return; } } while(performQueuedWinStuff(env)); if (result & BUTOUT_ERR) { XBell(env->dpy, 0); result = 0; } } for (fdGroup = 0; fdGroup < 3; ++fdGroup) { fdSets[fdGroup] = env->fMasks[fdGroup]; } if (env->dpy && (env->wllen <= env->minWindows)) return; selected_fds = select(env->maxFd, &fdSets[BUT_READFILE], &fdSets[BUT_WRITEFILE], &fdSets[BUT_XFILE], &next_timer); assert(selected_fds >= 0); if (selected_fds > 0) { for (fdGroup = 0; fdGroup < 3; ++fdGroup) { for (i = 0; i < env->maxGFds[fdGroup]; ++i) { if (FD_ISSET(i, &fdSets[fdGroup])) { assert(env->fCallbacks[fdGroup][i].callback != NULL); but_inEvent = TRUE; result |= env->fCallbacks[fdGroup][i]. callback(env->fCallbacks[fdGroup][i].packet, i); but_inEvent = FALSE; do { temp = but_dList(NULL) | butWin_dList(NULL); result |= temp; } while (temp != 0); if (env->dpy) { butEnv_rcActivate(env); if (result & BUTOUT_ERR) XBell(env->dpy, 0); } if (result & BUTOUT_STOPWAIT) { return; } } } } } } } /* * Do all the resizes and redraws that have been queued up now. * TRUE is returned if there was anything to do. */ static bool performQueuedWinStuff(ButEnv *env) { bool anythingDone = FALSE; ButWin *win, *winToDo, *ancestor; int i; for (i = 0; i < env->wllen; ++i) { win = env->winlist[i]; if (win->resizeNeeded) { anythingDone = TRUE; win->resize(win); win->resizeNeeded = FALSE; win->resized = TRUE; } } do { winToDo = NULL; for (i = 0; i < env->wllen; ++i) { win = env->winlist[i]; if (win->redrawReady && win->numRedraws && win->resized) { if (winToDo == NULL) { winToDo = win; } else { for (ancestor = win->parent; ancestor; ancestor = ancestor->parent) { if (ancestor == winToDo) winToDo = win; } } } } if (winToDo) { anythingDone = TRUE; butWin_performDraws(winToDo); } } while (winToDo); return(anythingDone); } static ButOut handleEvent(ButEnv *env) { ButOut result, temp; but_inEvent = TRUE; result = activateEvent(env); but_inEvent = FALSE; do { temp = but_dList(NULL) | butWin_dList(NULL); result |= temp; } while (temp != 0); butEnv_rcActivate(env); return(result); } static int activateEvent(ButEnv *env) { Display *dpy; XEvent event, ev2; ButWin *win = NULL; int old_w, old_h; ButOut result = 0; MouseEventFinder mef; dpy = env->dpy; XNextEvent(dpy, &event); switch(event.type) { case Expose: win = butEnv_findWin(env, event.xexpose.window); if (win != NULL) { assert(win->mapped); butWin_redraw(win, event.xexpose.x, event.xexpose.y, event.xexpose.width, event.xexpose.height); /* Don't do any of the redraws until the expose count hits zero. */ win->redrawReady = (event.xexpose.count == 0); } break; case MapNotify: win = butEnv_findWin(env, event.xmap.window); assert(MAGICNULL(win)); if (win == NULL) return(result); butWin_turnOnTimers(win); win->mapped = TRUE; if (win->map != NULL) win->map(win); if (!win->resized) { /* * If you have no window manager, you won't get your ConfigureNotify * when you start up, so we have to fake that first resize when * we get mapped. Yeah, it's ugly, but deal with it. */ win->resizeNeeded = TRUE; } break; case UnmapNotify: win = butEnv_findWin(env, event.xunmap.window); if (win == NULL) return(result); butWin_turnOffTimers(win); win->mapped = FALSE; if (win->unmap != NULL) { result |= win->unmap(win); } if (!win->isIcon && (win->iconWin == NULL)) { butWin_dList(win); } break; case ConfigureNotify: win = butEnv_findWin(env, event.xunmap.window); if (win == NULL) return(result); old_w = win->w; old_h = win->h; win->w = win->logicalW = event.xconfigure.width; win->h = win->logicalH = event.xconfigure.height; butWin_checkDims(win); if ((win->w != old_w) || (win->h != old_h) || !win->resized) win->resizeNeeded = TRUE; getWinXY(dpy, win); break; case MappingNotify: case ReparentNotify: case DestroyNotify: /* I should handle this correctly. */ break; case ClientMessage: if ((event.xclient.message_type == but_wmProtocols) && (event.xclient.data.l[0] == but_wmDeleteWindow)) { /* The WM asked this window to go away. Bye! */ win = butEnv_findWin(env, event.xclient.window); if (win == NULL) return(result); if (win->quit) win->quit(win); else butWin_dList(win); } break; case ButtonPress: env->eventTime = event.xbutton.time; env->keyModifiers = event.xbutton.state; ++env->eventNum; win = butEnv_findWin(env, event.xbutton.window); if (win) result |= butWin_mPress(win, event.xbutton.x, event.xbutton.y, event.xbutton.button); return(result); break; case KeyRelease: env->eventTime = event.xbutton.time; env->keyModifiers = event.xbutton.state; return(result | keyRelease(env, &(event.xkey))); break; case ButtonRelease: env->eventTime = event.xbutton.time; env->keyModifiers = event.xbutton.state; win = butEnv_findWin(env, event.xbutton.window); if (win) result |= butWin_mRelease(win, event.xbutton.x, event.xbutton.y, event.xbutton.button); return(result); break; case KeyPress: env->eventTime = event.xbutton.time; env->keyModifiers = event.xbutton.state; ++env->eventNum; return(result | keyPress(env, &(event.xkey))); break; case MotionNotify: mef.found = FALSE; mef.win = event.xmotion.window; XCheckIfEvent(dpy, &ev2, anotherMouseEvent, (XPointer)&mef); if (!mef.found) { win = butEnv_findWin(env, event.xmotion.window); if (win) { env->eventTime = event.xmotion.time; butWin_mMove(win, event.xmotion.x, event.xmotion.y); butRnet_mMove(env, win->id, event.xmotion.x,event.xmotion.y, win->w,win->h, -1); } } break; case LeaveNotify: win = butEnv_findWin(env, event.xcrossing.window); if (win) { butWin_mMove(win, BUT_NOCHANGE,BUT_NOCHANGE); butRnet_mMove(env, -2, -1,-1,-1,-1,-1); } break; case FocusIn: break; case FocusOut: if (env->lockBut) { if (env->lockBut->flags & BUT_KEYPRESSED) { return(result | env->lockBut->action->kRelease(env->lockBut, "", 0)); } } break; case SelectionRequest: ev2.type = SelectionNotify; ev2.xselection.type = SelectionNotify; ev2.xselection.send_event = True; ev2.xselection.display = event.xselectionrequest.display; ev2.xselection.requestor = event.xselectionrequest.requestor; ev2.xselection.selection = event.xselectionrequest.selection; ev2.xselection.target = event.xselectionrequest.target; if ((env->sReq == NULL) || !env->sReq(env, &(event.xselectionrequest))) ev2.xselection.property = None; else ev2.xselection.property = event.xselectionrequest.property; ev2.xselection.time = event.xselectionrequest.time; XSendEvent(env->dpy, event.xselectionrequest.requestor, False, 0, &ev2); break; case SelectionNotify: if (env->sNotify != NULL) env->sNotify(env, &(event.xselection)); break; case SelectionClear: if (env->sClear != NULL) env->sClear(env); break; default: #if DEBUG printf("UNKNOWN EVENT! #%d\n", event.type); #endif break; } return(result); } static Bool anotherMouseEvent(Display *dpy, XEvent *ev, XPointer arg) { MouseEventFinder *mef = (MouseEventFinder *)arg; if (ev->type == MotionNotify) { if (ev->xmotion.window == mef->win) mef->found = TRUE; } else if ((ev->type == ButtonPress) || (ev->type == ButtonRelease)) { if (ev->xbutton.window == mef->win) mef->found = TRUE; } return(False); } #ifndef STR_MAXLEN #define STR_MAXLEN 100 #endif static ButOut keyPress(ButEnv *env, XKeyPressedEvent *evt) { int slen; char kbuf[STR_MAXLEN]; KeySym keysym; ButWin *win = butEnv_findWin(env, evt->window); if (!win) return(0); assert(MAGIC(win)); slen = XLookupString(evt, kbuf, STR_MAXLEN-1, &keysym, NULL); kbuf[slen] = '\0'; if (kbuf[0] == '\r') kbuf[0] = '\n'; return(butWin_kPress(win, kbuf, keysym)); } static ButOut keyRelease(ButEnv *env, XKeyReleasedEvent *evt) { int slen; char kbuf[STR_MAXLEN]; KeySym keysym; ButWin *win = butEnv_findWin(env, evt->window); if (win == NULL) return(0); slen = XLookupString(evt, kbuf, STR_MAXLEN-1, &keysym, NULL); kbuf[slen] = '\0'; if (kbuf[0] == '\r') kbuf[0] = '\n'; if (XPending(env->dpy)) { XEvent nextev; XPeekEvent(env->dpy, &nextev); if (nextev.type == KeyPress) { if ((nextev.xkey.keycode == evt->keycode) && (evt->time == nextev.xkey.time)) { XNextEvent(env->dpy, &nextev); return(butWin_kPress(win, kbuf, keysym)); } } } return(butWin_kRelease(win, kbuf, keysym)); } /* Disable all timers used in a particular window. Useful mostly so that * when you iconify a window, the timers shut off. Even though the timers * don't take much CPU time, shutting them off makes it possible to * swap the entire application out of memory and this COULD have a * noticeable effect on system performance if other applicaitons need * lots of memory. * The timers will stay in the timer queue, but they will not go off. */ void butWin_turnOffTimers(ButWin *win) { ButTimer *timer; for (timer = but_timerList; timer != NULL; timer = timer->next) { if ((timer->win == win) && (timer->state == butTimer_on) && timer->winOnly) timer->state = butTimer_off; } } /* Re-enable all timers for a particular window. This will undo the work * of but_turnoff_timers. */ void butWin_turnOnTimers(ButWin *win) { ButTimer *timer; for (timer = but_timerList; timer != NULL; timer = timer->next) { if ((timer->win == win) && (timer->state == butTimer_off) && timer->winOnly) timer->state = butTimer_on; } } static bool butEnv_stdColors(ButEnv *env) { ButColor colorset[BUT_DCOLORS]; int i, xblack, xwhite; ButColor black, white; Display *dpy = env->dpy; Window rootwin = DefaultRootWindow(dpy); xblack = BlackPixel(dpy, DefaultScreen(dpy)); xwhite = WhitePixel(dpy, DefaultScreen(dpy)); for (i = 0; i < 17; ++i) { env->greyMaps[i] = XCreatePixmapFromBitmapData(dpy, rootwin, greymaps[i], 4,4, xwhite, xblack, env->depth); } black = butColor_create(0,0,0,0); white = butColor_create(255,255,255,16); colorset[BUT_FG] = black; colorset[BUT_BG] = butColor_mix(white,3, black,1); colorset[BUT_PBG] = butColor_mix(colorset[BUT_BG],7, black,1); colorset[BUT_PBG].greyLevel = 14; colorset[BUT_HIBG] = butColor_mix(colorset[BUT_BG],1, white,1); colorset[BUT_LIT] = butColor_create(255,255,255, 8); colorset[BUT_SHAD] = butColor_create(128,128,128, 0); colorset[BUT_ENTERBG] = colorset[BUT_HIBG]; colorset[BUT_SELBG] = butColor_create(255,255,0,12); /* Yellow. */ colorset[BUT_CHOICE] = butColor_create(0,255,0, 16); colorset[BUT_WHITE] = white; colorset[BUT_BLACK] = black; for (i = 0; i < BUT_DCOLORS; ++i) { env->colorPmaps[i] = None; if (butEnv_setColor(env, i, colorset[i]) == 0) return(FALSE); } return(TRUE); } bool butEnv_setColor(ButEnv *env, int colornum, ButColor color) { int i; Display *dpy = env->dpy; Colormap cmap; XColor temp; static uchar bm1616[] = {1}; Window rootwin = DefaultRootWindow(dpy); if (colornum >= env->numColors) { ulong *newcolors; Pixmap *newpixmaps; newcolors = (ulong *)wms_malloc((colornum+1)*sizeof(ulong)); newpixmaps = (Pixmap *)wms_malloc((colornum+1)*sizeof(Pixmap)); for (i = 0; i < env->numColors; ++i) { newcolors[i] = env->colors[i]; newpixmaps[i] = env->colorPmaps[i]; } if (env->colors) wms_free(env->colors); env->colors = newcolors; if (env->colorPmaps) wms_free(env->colorPmaps); env->colorPmaps = newpixmaps; env->numColors = colornum + 1; for (; i < env->numColors; ++i) env->colorPmaps[i] = None; } cmap = DefaultColormap(dpy, DefaultScreen(dpy)); if (env->colorPmaps[colornum] != None) { if (env->colorp) { XFreePixmap(env->dpy, env->colorPmaps[colornum]); XFreeColors(env->dpy, cmap, &env->colors[colornum], 1, 0); } } if (env->colorp) { temp.red = color.red; temp.green = color.green; temp.blue = color.blue; temp.flags = DoRed | DoGreen | DoBlue; if (XAllocColor(dpy, cmap, &temp) == 0) return(FALSE); env->colors[colornum] = temp.pixel; env->colorPmaps[colornum] = XCreatePixmapFromBitmapData(dpy, rootwin, bm1616, 1,1, temp.pixel,temp.pixel, env->depth); } else { env->colorPmaps[colornum] = env->greyMaps[color.greyLevel]; if (color.greyLevel < 16) env->colors[colornum] = BlackPixel(dpy, DefaultScreen(dpy)); else env->colors[colornum] = WhitePixel(dpy, DefaultScreen(dpy)); } return(TRUE); } int butEnv_setFont(ButEnv *env, int fontnum, const char *fontname, int fparam) { XFontStruct *flist; char **fnames; int i, f_avail, minChar; Str fname, temp; int cstart, fontloaded = 0; str_init(&fname); str_init(&temp); if (fontnum >= env->numFonts) { XFontStruct **newflist; newflist = (XFontStruct **)wms_malloc((fontnum+1) * sizeof(XFontStruct *)); for (i = 0; i < env->numFonts; ++i) newflist[i] = env->fonts[i]; wms_free(env->fonts); env->fonts = newflist; env->numFonts = fontnum + 1; for (; i < env->numFonts; ++i) env->fonts[i] = NULL; } if (env->fonts[fontnum] != NULL) { XFreeFont(env->dpy, env->fonts[fontnum]); env->fonts[fontnum] = NULL; } for (;;) { ++fontloaded; if (*fontname == '/') ++fontname; if (*fontname == '\0') { fontloaded = 0; fontname = "fixed"; } for (cstart = 0; (fontname[cstart] != '\0') && (fontname[cstart] != '/'); ++cstart); str_copyCharsLen(&temp, fontname, cstart); str_print(&fname, str_chars(&temp), fparam); fontname += cstart; fnames = XListFontsWithInfo(env->dpy, str_chars(&fname), 1, &f_avail, &flist); if (f_avail > 0) { env->fonts[fontnum] = XLoadQueryFont(env->dpy, fnames[0]); minChar = env->fonts[fontnum]->min_char_or_byte2; if ((minChar > ' ') || (env->fonts[fontnum]->max_char_or_byte2 < 'z')) { printf("Char range: %d..%d, should be %d..%d\n", env->fonts[fontnum]->min_char_or_byte2, env->fonts[fontnum]->max_char_or_byte2, ' ', 'z'); XFreeFontInfo(fnames, flist, f_avail); continue; } if (env->fonts[fontnum]->per_char == NULL) { if (env->fonts[fontnum]->min_bounds.width < 1) { XFreeFontInfo(fnames, flist, f_avail); continue; } } else { if (env->fonts[fontnum]->per_char['a' - minChar].width < 1) { printf("Width of a is %d\n", env->fonts[fontnum]->per_char['a'].width); XFreeFontInfo(fnames, flist, f_avail); continue; } } if (fontnum == 0) { env->font0h = env->fonts[0]->ascent + env->fonts[0]->descent; env->stdButBw = (env->font0h + 3) / 6; makeStripes(env, (env->font0h / 15) * 2); } XFreeFontInfo(fnames, flist, f_avail); str_deinit(&temp); str_deinit(&fname); return(fontloaded); } } } void butEnv_drawAll(ButEnv *env) { int i; ButWin *win; for (i = 0; i < env->wllen; ++i) { win = env->winlist[i]; butWin_redraw(win, 0,0, win->w,win->h); } } void butEnv_resizeAll(ButEnv *env) { int i; ButWin *win; for (i = 0; i < env->wllen; ++i) { win = env->winlist[i]; win->resize(win); } } static void makeStripes(ButEnv *env, int ssize) { uint j; int x, y; uchar *stripes; if (ssize == 0) ssize = 2; /* "ssize" is the width of a stripe pattern used to grey out text. */ j = (ssize + 7) / 8; stripes = (uchar *)wms_malloc(ssize * j); for (x = 0; x < ssize*j; ++x) stripes[x] = 0; for (y = 0; y < ssize; ++y) { for (x = 0; x < ssize; ++x) { if ((((ssize-x-1) >= y) && ((ssize-x-1) < y+(ssize/2))) || ((ssize-x-1) < y-(ssize/2))) stripes[(x>>3) + (y*j)] |= 1<<(x&7); } } if (env->stipDisable != None) XFreePixmap(env->dpy, env->stipDisable); env->stipDisable = XCreateBitmapFromData(env->dpy, RootWindow(env->dpy, DefaultScreen(env->dpy)), stripes, ssize,ssize); wms_free(stripes); XSetStipple(env->dpy, env->gc, env->stipDisable); XSetStipple(env->dpy, env->gc2, env->stipDisable); } #if DEBUG static int butErrors(Display *dpy, XErrorEvent *err) { char ebuf[1024]; XGetErrorText(dpy, err->error_code, ebuf, sizeof(ebuf)); fprintf(stderr, "Error: %s\n", ebuf); assert(0); } #endif /* DEBUG */ /* * You know, it's really unbelievable to me that this is the only way in * X to find the location on the display of a window. *sigh*. * This code was blatantly stolen from "xwininfo.c". */ static void getWinXY(Display *dpy, ButWin *win) { static bool errorPrinted = FALSE; Status status; Window wmframe = win->win; XWindowAttributes frame_attr; while (True) { Window root, parent; Window *childlist; unsigned int ujunk; status = XQueryTree(dpy, wmframe, &root, &parent, &childlist, &ujunk); if (parent == root || !parent || !status) break; wmframe = parent; if (status && childlist) XFree((void *)childlist); } /* WM may be reparented, so find edges of the frame. */ /* Only works for ICCCM-compliant WMs, and then only if the window has corner gravity. We would need to know the original width of the window to correctly handle the other gravities. */ if (!XGetWindowAttributes(dpy, wmframe, &frame_attr) && !errorPrinted) { fprintf(stderr, "wmslib: Can't get frame attributes."); errorPrinted = TRUE; } win->x = frame_attr.x; win->y = frame_attr.y; } void butEnv_addFile(ButEnv *env, int group, int fd, void *packet, ButOut (*callback)(void *packet, int fd)) { int i; assert((group >= 0) && (group < 3)); if (fd >= env->maxFd) env->maxFd = fd + 1; if (fd >= env->maxGFds[group]) { ButFdCallback *newFc = wms_malloc((fd+1)*sizeof(ButFdCallback)); for (i = 0; i < env->maxGFds[group]; ++i) newFc[i] = env->fCallbacks[group][i]; for (; i < fd; ++i) newFc[i].callback = NULL; if (env->fCallbacks[group] != NULL) wms_free(env->fCallbacks[group]); env->maxGFds[group] = fd + 1; env->fCallbacks[group] = newFc; } env->fCallbacks[group][fd].callback = callback; env->fCallbacks[group][fd].packet = packet; FD_SET(fd, &env->fMasks[group]); } void butEnv_rmFile(ButEnv *env, int group, int fd) { assert((group >= 0) && (group < 3)); assert(MAGIC(env)); assert(fd < env->maxGFds[group]); env->fCallbacks[group][fd].callback = NULL; FD_CLR(fd, &env->fMasks[group]); } static ButOut serviceXData(void *packet, int fd) { ButEnv *env = packet; if (XPending(env->dpy)) return(handleEvent(env)); else return(0); } XImage *butEnv_imageCreate(ButEnv *env, int w, int h) { Display *dpy = env->dpy; XImage *image; image = XCreateImage(dpy, DefaultVisual(dpy, DefaultScreen(dpy)), DefaultDepth(dpy, DefaultScreen(dpy)), ZPixmap, 0, NULL, w, h, 32, 0); image->data = wms_malloc(image->bytes_per_line * h); return(image); } void butEnv_imageDestroy(XImage *img) { wms_free(img->data); img->data = NULL; XDestroyImage(img); } #endif /* X11_DISP */ pente-2.2.5/wmslib/src/but/canvas.c0100664000076400007640000003274407045637750015370 0ustar wmswms/* * wmslib/src/but/canvas.c, part of wmslib (Library functions) * Copyright (C) 1994-1996 William Shubert. * See "configure.h.in" for more copyright information. */ #include #ifdef X11_DISP #ifdef STDC_HEADERS #include #include #endif /* STDC_HEADERS */ #include #include #include #include #include #include #include #ifdef HAVE_SYS_SELECT_H #include #endif #include #include #ifdef _BUT_CANVAS_H_ Levelization Error. #endif #include "canvas.h" /********************************************************************** * Data Types **********************************************************************/ typedef struct Can_struct { bool grabbed; int grab_mx,grab_my, grab_ox,grab_oy; ButWin *parent, *win; But *but; Pixmap pmap; void (*change)(void *packet, int xOff, int yOff, int w, int h, int viewW, int viewH); MAGIC_STRUCT } Can; /********************************************************************** * Forward Declarations **********************************************************************/ static ButOut mmove(But *but, int x, int y); static ButOut mleave(But *but); static ButOut mpress(But *but, int butnum, int x, int y); static ButOut mrelease(But *but, int butnum, int x, int y); static ButOut kpress(But *but, const char *keystr, KeySym sym); static ButOut krelease(But *but, const char *keystr, KeySym sym); static void draw(But *but, int x, int y, int w, int h); static ButOut destroy(But *but); static bool reviseDims(Can *can); /********************************************************************** * Globals **********************************************************************/ static const ButAction action = { mmove, mleave, mpress, mrelease, kpress, krelease, draw, destroy, but_flags, NULL}; /********************************************************************** * Functions **********************************************************************/ ButWin *butCan_create(void *packet, ButWin *parent, int layer, ButWinFunc *resize, ButWinFunc *destroy, void (*change)(void *packet, int xOff, int yOff, int w, int h, int viewW, int viewH)) { ButEnv *env; ButWin *win; But *but; Can *can; assert(MAGIC(parent)); env = parent->env; assert(MAGIC(env)); win = wms_malloc(sizeof(ButWin)); can = wms_malloc(sizeof(Can)); but = but_create(parent, can, &action); MAGIC_SET(win); MAGIC_SET(can); MAGIC_SET(&win->butsNoDraw); win->parent = parent; win->parentBut = but; win->packet = packet; win->iPacket = can; win->win = None; win->physWin = butCan_xWin(parent); win->iconWin = NULL; win->name = NULL; win->iconic = FALSE; win->isIcon = FALSE; win->x = 0; win->y = 0; win->w = win->minW = win->maxW = win->logicalW = 0; win->h = win->minH = win->maxH = win->logicalH = 0; win->wStep = 1; win->hStep = 1; win->xOff = 0; win->yOff = 0; win->minWRatio = win->minHRatio = win->maxWRatio = win->maxHRatio = 0; win->resized = FALSE; win->resizeNeeded = FALSE; win->redrawReady = TRUE; win->redraws = NULL; win->numRedraws = win->maxRedraws = 0; win->id = 0; win->mapped = TRUE; win->unmap = NULL; win->map = NULL; win->resize = resize; win->destroy = destroy; win->quit = NULL; win->env = env; win->minLayer = 1; win->maxLayer = 0; win->butsNoDraw.buts = NULL; win->butsNoDraw.numButs = 0; win->butsNoDraw.maxButs = 0; win->butsNoDraw.dynamic = TRUE; win->lock = NULL; win->butIn = NULL; win->keyBut = NULL; win->numCols = 0; win->maxCols = 0; win->cols = NULL; butWin_addToTable(win); but->uPacket = packet; but->layer = layer; but->flags = BUT_DRAWABLE|BUT_PRESSABLE|BUT_OPAQUE; can->grabbed = FALSE; can->parent = parent; can->win = win; can->but = but; can->pmap = None; can->change = change; but_init(but); return(win); } void butCan_resizeView(ButWin *win, int x, int y, int w, int h, bool propagate) { int oldh, oldw, oldx, oldy; Can *can = win->iPacket; But *but = can->but; assert(MAGIC(win)); assert(MAGIC(can)); win->resized = TRUE; oldx = but->x; oldy = but->y; oldw = but->w; oldh = but->h; if (x == BUT_NOCHANGE) x = oldx; if (y == BUT_NOCHANGE) y = oldy; if (w == BUT_NOCHANGE) w = oldw; if (h == BUT_NOCHANGE) h = oldh; /* * Check to see if the porthole size has changed. If it has, hit it * with a redraw. Not real necessary for these, but what the heck. */ if ((w != oldw) || (h != oldh)) { win->w = w; win->h = h; reviseDims(can); if (win->resize != NULL) { win->resize(win); } if (can->pmap != None) { butWin_rmFromTable(win); XFreePixmap(win->env->dpy, can->pmap); } can->pmap = XCreatePixmap(win->env->dpy, win->physWin, w, h, win->env->depth); win->win = can->pmap; butWin_addToTable(win); but_resize(but, x,y, w,h); butWin_redraw(win, win->xOff,win->yOff, w,h); if (propagate && can->change) { can->change(can->but->uPacket, win->xOff, win->yOff, win->logicalW, win->logicalH, win->w, win->h); } } else if ((x != oldx) || (y != oldy)) { /* Check if the porthole geometry has changed, necessitating a redraw. */ but_resize(but, x,y, w,h); } } void butCan_slide(ButWin *win, int xOff, int yOff, bool propagate) { int oldox, oldoy; Can *can = win->iPacket; int csx, csy, cdx, cdy, cw, ch; int rdx, rdw; assert(MAGIC(win)); assert(MAGIC(can)); oldox = win->xOff; oldoy = win->yOff; if (xOff != BUT_NOCHANGE) win->xOff = xOff; if (yOff != BUT_NOCHANGE) win->yOff = yOff; reviseDims(can); if (((oldox == win->xOff) && (oldoy == win->yOff)) || (win->win == None)) return; if (win->xOff > oldox) { csx = win->xOff - oldox; cdx = 0; cw = win->w - csx; } else if (win->xOff == oldox) { csx = 0; cdx = 0; cw = win->w; } else { /* win->xOff < oldox */ csx = 0; cdx = oldox - win->xOff; cw = win->w - csx; } if (win->yOff > oldoy) { csy = win->yOff - oldoy; cdy = 0; ch = win->h - csy; } else if (win->yOff == oldoy) { csy = 0; cdy = 0; ch = win->h; } else { /* win->yOff < oldoy */ csy = 0; cdy = oldoy - win->yOff; ch = win->h - csy; } if ((cw < 0) || (ch < 0)) { /* Must redraw entire pixmap. */ butWin_redraw(win, win->xOff, win->yOff, win->w, win->h); } else { XCopyArea(win->env->dpy, can->pmap, can->pmap, win->env->gc, csx,csy, cw,ch, cdx,cdy); if (cdx > csx) { butWin_redraw(win, win->xOff, win->yOff, cdx-csx, win->h); rdx = win->xOff+cdx-csx; rdw = win->w - (cdx-csx); if (rdw < 0) rdw = 0; } else if (cdx == csx) { rdx = win->xOff; rdw = win->w; } else { /* cdx < csx */ butWin_redraw(win, win->xOff+win->w-(csx-cdx), win->yOff, csx-cdx, win->h); rdx = win->xOff; rdw = win->w - (csx - cdx); if (rdw < 0) rdw = 0; } if (cdy > csy) { butWin_redraw(win, rdx, win->yOff, rdw, cdy-csy); } else if (cdy < csy) { butWin_redraw(win, rdx, win->yOff+win->h-(csy-cdy), rdw, csy-cdy); } } but_draw(can->but); if (propagate) { can->change(can->but->uPacket, win->xOff, win->yOff, win->logicalW, win->logicalH, win->w, win->h); } if (can->parent->butIn == can->but) { butWin_mMove(win->env->last_mwin, win->env->last_mx, win->env->last_my); } } void butCan_destroy(ButWin *win) { } static ButOut mmove(But *but, int x, int y) { Can *can = but->iPacket; ButWin *win = can->win; ButEnv *env = but->win->env; ButOut result; int new_ox, new_oy; assert(MAGIC(but)); assert(MAGIC(can)); if (can->grabbed) { if (env->last_mwin != but->win) { return(0); } new_ox = can->grab_ox + 10*(can->grab_mx - x); new_oy = can->grab_oy + 10*(can->grab_my - y); if ((new_ox != win->xOff) || (new_oy != win->yOff)) { butCan_slide(can->win, new_ox, new_oy, TRUE); } env->last_mwin = but->win; env->last_mx = x - but->x + win->xOff; env->last_my = y - but->y + win->yOff; return(BUTOUT_CAUGHT); } else { result = butWin_mMove(can->win, x-but->x+win->xOff, y-but->y+win->yOff); return(result | BUTOUT_CAUGHT | BUTOUT_IGNORE); } } static ButOut mleave(But *but) { /* * This isn't quite right...not sure how to handle this. * I don't want to get a "leave" when I propogate a mouse move down * to the area below, but I get one anyway! * can_t *can = but->iPacket; * int result; * * assert(MAGIC(can)); * result = but_mmove(but->win->env, can->win, 1,-1); * return(result); */ return(0); } static ButOut mpress(But *but, int butnum, int x, int y) { Can *can = but->iPacket; ButWin *win = can->win; int result; assert(MAGIC(can)); if (butnum == 3) { can->grabbed = TRUE; can->grab_mx = x; can->grab_my = y; can->grab_ox = win->xOff; can->grab_oy = win->yOff; butEnv_setCursor(but->win->env, but, butCur_grab); but_newFlags(but, but->flags | BUT_LOCKED); return(BUTOUT_CAUGHT); } else { result = butWin_mPress(can->win, x - but->x + win->xOff, y - but->y + win->yOff, butnum); return(result); } } static ButOut mrelease(But *but, int butnum, int x, int y) { Can *can = but->iPacket; ButWin *win = can->win; ButOut result; assert(MAGIC(can)); if (butnum == 3) { can->grabbed = FALSE; but_newFlags(but, but->flags & ~BUT_LOCKED); butEnv_setCursor(but->win->env, but, butCur_idle); return(BUTOUT_CAUGHT); } else { result = butWin_mRelease(can->win, x - but->x + win->xOff, y - but->y + win->yOff, butnum); return(result); } } static ButOut kpress(But *but, const char *keystr, KeySym sym) { Can *can = but->iPacket; ButOut result; assert(MAGIC(can)); result = butWin_kPress(can->win, keystr, sym); return(result); } static ButOut krelease(But *but, const char *keystr, KeySym sym) { Can *can = but->iPacket; ButOut result; assert(MAGIC(can)); result = butWin_kRelease(can->win, keystr, sym); return(result); } static void draw(But *but, int x, int y, int w, int h) { Can *can = but->iPacket; ButWin *win = but->win; ButEnv *env = win->env; int csx,csy, cdx,cdy, cw,ch; assert(MAGIC(can)); assert(MAGIC(win)); csx = 0; csy = 0; cdx = but->x; cdy = but->y; cw = but->w; ch = but->h; if (x > cdx) { csx += x - cdx; cw -= x - cdx; cdx = x; } if (y > cdy) { csy += y - cdy; ch -= y - cdy; cdy = y; } if (x+w < cdx+cw) cw = x+w-cdx; if (y+h < cdy+ch) ch = y+h-cdy; if ((cw > 0) && (ch > 0)) XCopyArea(env->dpy, can->pmap, win->win, env->gc, csx,csy, cw,ch, cdx,cdy); } void butCan_redrawn(ButWin *win, int x,int y, int w,int h) { Can *can = win->iPacket; assert(MAGIC(win)); if (can == NULL) return; assert(MAGIC(can)); if (can->but == NULL) return; assert(MAGIC(can->but)); assert(MAGIC(can->parent)); if (x < win->xOff) { w -= win->xOff - x; x = win->xOff; } if (y < win->yOff) { h -= win->yOff - y; y = win->yOff; } if (x + w > win->xOff + win->w) w = win->xOff + win->w - x; if (y + h > win->yOff + win->h) h = win->yOff + win->h - y; butWin_redraw(can->parent, can->but->x + x - win->xOff, can->but->y + y - win->yOff, w, h); } static ButOut destroy(But *but) { Can *can = but->iPacket; assert(MAGIC(but)); assert(MAGIC(can)); assert((can->win == NULL) || MAGIC(can->win)); can->but = NULL; but->iPacket = NULL; if (can->win == NULL) { MAGIC_UNSET(can); wms_free(can); } else butWin_destroy(can->win); return(0); } void butCan_winDead(ButWin *win) { Can *can = win->iPacket; assert(MAGIC(win)); assert(MAGIC(can)); assert((can->but == NULL) || MAGIC(can->but)); can->win = NULL; win->iPacket = NULL; if (can->but == NULL) { MAGIC_UNSET(can); wms_free(can); } else but_destroy(can->but); } void butCan_resizeWin(ButWin *win, int w, int h, bool propagate) { Can *can = win->iPacket; int oldW, oldH; assert(MAGIC(win)); assert(MAGIC(can)); oldW = win->logicalW; oldH = win->logicalH; if (w < win->w) w = win->w; if (h < win->h) h = win->h; win->logicalW = w; win->logicalH = h; reviseDims(can); if ((win->logicalW <= 0) || (win->logicalH <= 0)) return; if ((win->logicalW != oldW) || (win->logicalH != oldH)) { win->resize(win); if (propagate && can->change) { can->change(can->but->uPacket, win->xOff, win->yOff, win->logicalW, win->logicalH, win->w, win->h); } } } Window butCan_xWin(ButWin *win) { assert(MAGIC(win)); while (win->parent) { win = win->parent; assert(MAGIC(win)); } return(win->win); } static bool reviseDims(Can *can) { ButWin *win = can->win; bool change = FALSE; if (win->logicalW < win->w) { change = TRUE; win->logicalW = win->w; } if (win->logicalH < win->h) { change = TRUE; win->logicalH = win->h; } if (win->xOff < 0) { change = TRUE; win->xOff = 0; } else if (win->xOff + win->w > win->logicalW) { change = TRUE; win->xOff = win->logicalW - win->w; } if (win->yOff < 0) { change = TRUE; win->yOff = 0; } else if (win->yOff + win->h > win->logicalH) { change = TRUE; win->yOff = win->logicalH - win->h; } return(change); } #endif /* X11_DISP */ pente-2.2.5/wmslib/src/but/checkbox.c0100664000076400007640000001640707045637750015701 0ustar wmswms/* * wmslib/src/but/checkbox.c, part of wmslib (Library functions) * Copyright (C) 1994-1996 William Shubert. * See "configure.h.in" for more copyright information. */ #include #ifdef X11_DISP #ifdef STDC_HEADERS #include #include #endif /* STDC_HEADERS */ #include #include #include #include #include #include #include #ifdef HAVE_SYS_SELECT_H #include #endif #include #include #include #include #include typedef struct Cb_struct { bool on; ButOut (*press)(But *but, bool value); } Cb; static ButOut mmove(But *but, int x, int y); static ButOut mleave(But *but); static ButOut mpress(But *but, int butnum, int x, int y); static ButOut mrelease(But *but, int butnum, int x, int y); static ButOut kpress(But *but, const char *keystr, KeySym sym); static ButOut krelease(But *but, const char *keystr, KeySym sym); static void draw(But *but, int x, int y, int w, int h); static ButOut destroy(But *but); static void flags(But *but, uint flags); static const ButAction action = { mmove, mleave, mpress, mrelease, kpress, krelease, draw, destroy, flags, NULL}; /********************************************************************** * Functions **********************************************************************/ But *butCb_create(ButOut (*func)(But *but, bool value), void *packet, ButWin *win, int layer, int flags, bool on) { But *but; Cb *cb; cb = wms_malloc(sizeof(Cb)); but = but_create(win, cb, &action); MAGIC_SET(but); but->uPacket = packet; but->layer = layer; but->flags = flags | BUT_OPAQUE; cb->on = on; cb->press = func; but_init(but); return(but); } bool butCb_get(But *but) { Cb *cb = but->iPacket; assert(but->action == &action); assert(MAGIC(but)); return(cb->on); } void butCb_set(But *but, bool on, bool makeCallback) { Cb *cb = but->iPacket; assert(but->action == &action); assert(MAGIC(but)); if (cb->on != on) { cb->on = on; but_draw(but); if (makeCallback && (cb->press != NULL)) cb->press(but, on); } } static ButOut destroy(But *but) { Cb *cb = but->iPacket; assert(but->action == &action); assert(MAGIC(but)); wms_free(cb); return(0); } static void draw(But *but, int x, int y, int w, int h) { ButWin *win = but->win; Cb *cb = but->iPacket; uint flags = but->flags; ButEnv *env = win->env; XPoint check[6]; int i, ix, iy, iw, ih, delta; assert(but->action == &action); assert(MAGIC(but)); ix = but->x + env->stdButBw - win->xOff; iy = but->y + env->stdButBw - win->yOff; iw = but->w - 2*env->stdButBw; ih = but->h - 2*env->stdButBw; but_drawBox(win, but->x,but->y, but->w,but->h, flags & BUT_PRESSED, env->stdButBw, BUT_SLEFT|BUT_SRIGHT, BUT_LIT, BUT_SHAD, None, None); if (flags & BUT_PRESSED) butEnv_setXFg(env, BUT_PBG); else { if (cb->on && (but->flags & BUT_PRESSABLE)) { butEnv_setXFg(env, BUT_CHOICE); } else butEnv_setXFg(env, BUT_BG); } XFillRectangle(env->dpy, win->win, env->gc, ix,iy, iw,ih); if (((flags & BUT_PRESSED) && !cb->on) || (!(flags & BUT_PRESSED) && cb->on)) { check[0].x = ix + (iw + 1) / 3; check[0].y = iy + ih; check[1].x = ix; check[1].y = iy + (2*ih + 1) / 3; check[2].x = ix + (iw + 3) / 6; check[2].y = iy + (3*ih + 3) / 6; check[3].x = check[0].x; check[3].y = check[1].y; check[4].x = ix + iw; check[4].y = iy + (ih + 1) / 3; check[5] = check[0]; if (flags & BUT_PRESSED) { delta = (env->stdButBw + 1) / 2; for (i = 1; i < 5; ++i) check[i].y += delta; check[0].x -= delta; check[5].x += delta; } butEnv_setXFg(env, BUT_FG); XFillPolygon(env->dpy, win->win, env->gc, check, 6, Nonconvex, CoordModeOrigin); } } static void flags(But *but, uint flags) { uint ofl = but->flags; but->flags = flags; if (((flags & (BUT_PRESSABLE|BUT_DRAWABLE|BUT_PRESSED)) != (ofl & (BUT_PRESSABLE|BUT_DRAWABLE|BUT_PRESSED))) || (((flags & BUT_TWITCHED) != (ofl & BUT_TWITCHED)) && (flags & BUT_PRESSED))) but_draw(but); } static ButOut mmove(But *but, int x, int y) { ButOut retval = BUTOUT_CAUGHT; int newflags = but->flags; ButEnv *env = but->win->env; if (!(but->flags & BUT_PRESSABLE)) return(BUTOUT_CAUGHT); if ((x >= but->x + env->stdButBw) && (y >= but->y + env->stdButBw) && (x < but->x + but->w - env->stdButBw) && (y < but->y + but->h - env->stdButBw)) newflags |= BUT_TWITCHED; else { newflags &= ~BUT_TWITCHED; if (!(newflags & BUT_LOCKED)) retval &= ~BUTOUT_CAUGHT; } if (!(but->flags & BUT_TWITCHED) && (newflags & BUT_TWITCHED)) butEnv_setCursor(but->win->env, but, butCur_twitch); else if ((but->flags & BUT_TWITCHED) && !(newflags & BUT_TWITCHED)) butEnv_setCursor(but->win->env, but, butCur_idle); if (newflags != but->flags) { but_newFlags(but, newflags); } return(retval); } static ButOut mleave(But *but) { int newflags = but->flags; newflags &= ~BUT_TWITCHED; if ((but->flags & BUT_TWITCHED) && !(newflags & BUT_TWITCHED)) butEnv_setCursor(but->win->env, but, butCur_idle); if (newflags != but->flags) { but_newFlags(but, newflags); } return(BUTOUT_CAUGHT); } static ButOut mpress(But *but, int butnum, int x, int y) { ButOut retval = BUTOUT_CAUGHT; int newflags = but->flags; if (!newflags & BUT_TWITCHED) retval &= ~BUTOUT_CAUGHT; else { if (butnum == 1) newflags |= BUT_PRESSED | BUT_LOCKED; else return(BUTOUT_CAUGHT | BUTOUT_ERR); } if (!(but->flags & BUT_PRESSED) && (newflags & BUT_PRESSED)) snd_play(&but_downSnd); if (newflags != but->flags) but_newFlags(but, newflags); return(retval); } static ButOut mrelease(But *but, int butnum, int x, int y) { ButOut retval = BUTOUT_CAUGHT; int newflags = but->flags; Cb *cb; if (butnum != 1) { if (but->flags & BUT_TWITCHED) return(BUTOUT_CAUGHT); else return(0); } if (!(but->flags & BUT_PRESSED)) return(0); if (but->flags & BUT_TWITCHED) { cb = but->iPacket; cb->on = !cb->on; if (cb->press != NULL) retval |= cb->press(but, cb->on); } else retval |= BUTOUT_ERR; newflags &= ~(BUT_PRESSED|BUT_LOCKED); if ((but->flags & BUT_PRESSED) && !(newflags & BUT_PRESSED) && !(retval & BUTOUT_ERR)) snd_play(&but_upSnd); if (newflags != but->flags) but_newFlags(but, newflags); return(retval); } static ButOut kpress(But *but, const char *keystr, KeySym sym) { ButOut retval = BUTOUT_CAUGHT; int newflags = but->flags; newflags |= BUT_KEYPRESSED; if (!(but->flags & BUT_KEYPRESSED)) { snd_play(&but_downSnd); but_newFlags(but, newflags); } return(retval); } static ButOut krelease(But *but, const char *keystr, KeySym sym) { ButOut retval = BUTOUT_CAUGHT; int newflags = but->flags; Cb *cb = but->iPacket; newflags &= ~(BUT_KEYPRESSED); cb->on = !cb->on; if (cb->press != NULL) retval |= cb->press(but, cb->on); snd_play(&but_upSnd); if (newflags != but->flags) but_newFlags(but, newflags); return(retval); } #endif pente-2.2.5/wmslib/src/but/ctext.c0100664000076400007640000002616007045637750015237 0ustar wmswms/* * wmslib/src/but/ctext.c, part of wmslib (Library functions) * Copyright (C) 1994-1996 William Shubert. * See "configure.h.in" for more copyright information. */ #include #ifdef X11_DISP #ifdef STDC_HEADERS #include #include #endif /* STDC_HEADERS */ #include #include #include #include #include #include #include #ifdef HAVE_SYS_SELECT_H #include #endif #include #include #include #include #include #include /********************************************************************** * Data Types **********************************************************************/ typedef struct Ct_struct { char *str; int maxlen; int angles; ButOut (*pfunc)(But *but), (*rfunc)(But *but); bool netAction; int textX, textY, textW, textH; } Ct; /********************************************************************** * Forward Declarations **********************************************************************/ static ButOut mmove(But *but, int x, int y); static ButOut mleave(But *but); static ButOut mpress(But *but, int butnum, int x, int y); static ButOut mrelease(But *but, int butnum, int x, int y); static ButOut kpress(But *but, const char *keystr, KeySym sym); static ButOut krelease(But *but, const char *keystr, KeySym sym); static void draw(But *but, int x, int y, int w, int h); static ButOut destroy(But *but); static bool mouse_over_but(But *but, int x, int y); static void flags(But *but, uint flags); static ButOut remPress(But *but, void *msg, int msgLen); /********************************************************************** * Globals **********************************************************************/ static ButAction action = { mmove, mleave, mpress, mrelease, kpress, krelease, draw, destroy, flags, remPress}; /********************************************************************** * Functions **********************************************************************/ But *butCt_create(ButOut (*func)(But *but), void *packet, ButWin *win, int layer, int flags, const char *text) { return(butAct_vCreate(NULL, func, packet, win, layer, flags, text, BUT_RLEFT|BUT_RRIGHT)); } But *butAct_create(ButOut (*func)(But *but), void *packet, ButWin *win, int layer, int flags, const char *text, int angleflags) { return(butAct_vCreate(NULL, func, packet, win, layer, flags, text, angleflags)); } But *butAct_vCreate(ButOut (*pfunc)(But *but), ButOut (*rfunc)(But *but), void *packet, ButWin *win, int layer, int flags, const char *text, int angleflags) { Ct *ct; But *but; ct = wms_malloc(sizeof(Ct)); but = but_create(win, ct, &action); but->uPacket = packet; but->layer = layer; but->flags = flags; if (text == NULL) text = ""; ct->rfunc = rfunc; ct->maxlen = strlen(text); ct->str = (char *)wms_malloc(sizeof(char) * (ct->maxlen + 1)); strcpy(ct->str, text); ct->angles = angleflags; ct->pfunc = pfunc; ct->netAction = TRUE; ct->textW = ct->textH = 0; but_init(but); return(but); } void butCt_setText(But *but, const char *text) { Ct *ct = but->iPacket; int newlen; assert(but->action == &action); newlen = strlen(text); if (newlen > ct->maxlen) { wms_free(ct->str); ct->maxlen = newlen; ct->str = (char *)wms_malloc((newlen + 1) * sizeof(char)); } strcpy(ct->str, text); but_draw(but); } static ButOut destroy(But *but) { Ct *ct = but->iPacket; wms_free(ct->str); wms_free(ct); return(0); } void butCt_setTextLoc(But *but, int x, int y, int w, int h) { Ct *ct = but->iPacket; ct->textX = x; ct->textY = y; ct->textW = w; ct->textH = h; } static void draw(But *but, int x, int y, int w, int h) { ButWin *win = but->win; ButEnv *env = win->env; Ct *ct = but->iPacket; uint flags = but->flags; int tx, ty, tw, th; int textWidth; but_drawCtb(win, flags, BUT_FG, BUT_BG, BUT_PBG, but->x, but->y, but->w, but->h, env->stdButBw, ct->angles); tx = but->x; ty = but->y; if (ct->textW != 0) { tx += ct->textX; ty += ct->textY; tw = ct->textW; th = ct->textH; } else { tw = but->w; th = but->h; } if (!(but->flags & BUT_PRESSABLE)) { XSetFillStyle(env->dpy, env->gc, FillStippled); XSetForeground(env->dpy, env->gc, env->colors[BUT_FG]); } else butEnv_setXFg(env, BUT_FG); if ((but->flags & BUT_PRESSED) && (but->flags & BUT_TWITCHED)) { tx += env->stdButBw/2; ty += env->stdButBw/2; } textWidth = butEnv_textWidth(win->env, ct->str, 0); butWin_write(win, tx + (tw - textWidth) / 2, ty + (th - butEnv_fontH(win->env, 0))/2, ct->str, 0); if (!(but->flags & BUT_PRESSABLE)) { butEnv_stdFill(env); } } static void flags(But *but, uint flags) { uint ofl = but->flags; but->flags = flags; if ((flags & BUT_NETPRESS) && !(ofl & BUT_NETPRESS)) { snd_play(&but_downSnd); } if (((flags & (BUT_PRESSABLE|BUT_DRAWABLE|BUT_PRESSED|BUT_NETPRESS)) != (ofl & (BUT_PRESSABLE|BUT_DRAWABLE|BUT_PRESSED|BUT_NETPRESS))) || (((flags & (BUT_TWITCHED|BUT_NETTWITCH)) != (ofl & (BUT_TWITCHED|BUT_NETTWITCH))) && (flags & (BUT_PRESSED|BUT_NETPRESS)))) but_draw(but); } static ButOut mmove(But *but, int x, int y) { ButOut retval = BUTOUT_CAUGHT; uint newflags = but->flags; if (mouse_over_but(but, x,y)) { if (!(but->flags & BUT_PRESSABLE)) return(BUTOUT_CAUGHT); newflags |= BUT_TWITCHED; } else { if (!(but->flags & BUT_PRESSABLE)) return(0); newflags &= ~BUT_TWITCHED; if (!(newflags & BUT_LOCKED)) retval &= ~BUTOUT_CAUGHT; } if (!(but->flags & BUT_TWITCHED) && (newflags & BUT_TWITCHED)) butEnv_setCursor(but->win->env, but, butCur_twitch); else if ((but->flags & BUT_TWITCHED) && !(newflags & BUT_TWITCHED)) butEnv_setCursor(but->win->env, but, butCur_idle); if (newflags != but->flags) { but_newFlags(but, newflags); } return(retval); } static ButOut mleave(But *but) { int newflags = but->flags; newflags &= ~BUT_TWITCHED; if ((but->flags & BUT_TWITCHED) && !(newflags & BUT_TWITCHED)) butEnv_setCursor(but->win->env, but, butCur_idle); if (newflags != but->flags) { but_newFlags(but, newflags); } return(BUTOUT_CAUGHT); } static ButOut mpress(But *but, int butnum, int x, int y) { ButOut retval = BUTOUT_CAUGHT; uint newflags = but->flags; Ct *ct = but->iPacket; bool pressPf = FALSE; if (!(newflags & BUT_TWITCHED)) retval &= ~BUTOUT_CAUGHT; else { if (butnum == 1) { newflags |= BUT_PRESSED | BUT_LOCKED; pressPf = TRUE; } else return(BUTOUT_CAUGHT | BUTOUT_ERR); } if (!(but->flags & BUT_PRESSED) && (newflags & BUT_PRESSED)) snd_play(&but_downSnd); if (newflags != but->flags) but_newFlags(but, newflags); if (pressPf && ct->pfunc) retval |= ct->pfunc(but); return(retval); } static ButOut mrelease(But *but, int butnum, int x, int y) { ButOut retval = BUTOUT_CAUGHT; int newflags = but->flags; Ct *ct = but->iPacket; bool pressRf = FALSE; if (butnum != 1) { if (but->flags & BUT_TWITCHED) return(BUTOUT_CAUGHT); else return(0); } if (!(but->flags & BUT_PRESSED)) return(0); if (but->flags & BUT_TWITCHED) { pressRf = TRUE; } else { if (ct->pfunc != NULL) pressRf = TRUE; retval |= BUTOUT_ERR; } newflags &= ~(BUT_PRESSED|BUT_LOCKED); if ((but->flags & BUT_PRESSED) && !(newflags & BUT_PRESSED) && !(retval & BUTOUT_ERR)) snd_play(&but_upSnd); if (newflags != but->flags) but_newFlags(but, newflags); if (but->id >= 0) butRnet_butSpecSend(but, NULL, 0); if (pressRf && ct->rfunc) retval |= ct->rfunc(but); return(retval); } static ButOut kpress(But *but, const char *keystr, KeySym sym) { ButOut retval = BUTOUT_CAUGHT; int newflags = but->flags; Ct *ct = but->iPacket; newflags |= BUT_KEYPRESSED|BUT_PRESSED|BUT_LOCKED; if (!(but->flags & BUT_KEYPRESSED)) { snd_play(&but_downSnd); but_newFlags(but, newflags); if (ct->pfunc != NULL) retval |= ct->pfunc(but); } return(retval); } static ButOut krelease(But *but, const char *keystr, KeySym sym) { ButOut retval = BUTOUT_CAUGHT; int newflags = but->flags; Ct *ct = but->iPacket; bool pressRf = FALSE; if (!(newflags & BUT_KEYPRESSED)) return(0); newflags &= ~(BUT_KEYPRESSED|BUT_PRESSED|BUT_LOCKED); if (keystr != NULL) { /* If keystr is NULL, the key wasn't released - we lost focus instead. */ pressRf = TRUE; } snd_play(&but_upSnd); if (newflags != but->flags) but_newFlags(but, newflags); if (but->id >= 0) butRnet_butSpecSend(but, NULL, 0); if (pressRf && ct->rfunc) retval |= ct->rfunc(but); return(retval); } static bool mouse_over_but(But *but, int x, int y) { int angleflags = ((Ct *)(but->iPacket))->angles; int radlimit, radius, dx, dy; if (x < but->x + but->w/2) { if (angleflags & BUT_ALEFT) { if ((y < but->y) || (y >= but->y + but->h)) return(0); if (y < but->y + but->h/2) if (x <= but->x + (but->y + but->h/2 - y)) return(0); else return(x > but->x + (y - (but->y + but->h/2))); } else if (angleflags & BUT_SLEFT) return((x >= but->x) && (y >= but->y) && (y < but->y + but->h)); } else { if (angleflags & BUT_ARIGHT) { if ((y < but->y) || (y >= but->y + but->h)) return(0); if (y < but->y + but->h/2) return(x < but->x + but->w - (but->y + but->h/2 - y)); else return(x < but->x + but->w - (y - (but->y + but->h/2))); } else if (angleflags & BUT_SRIGHT) return((x < but->x + but->w) && (y >= but->y) && (y < but->y + but->h)); } /* We're dealing with the tough case...rounded edges! */ radius = but->h / 4; radlimit = (radius + 1); radlimit *= radlimit; if (y < but->y + radius) { if (x < but->x + radius) { dx = but->x + radius - x; dy = but->y + radius - y; return(dx*dx + dy*dy < radlimit); } else if (x < but->x + but->w - radius) return(y >= but->y); else { dx = x - (but->x + but->w - radius - 1); dy = but->y + radius - y; return(dx*dx + dy*dy < radlimit); } } else if (y < but->y + but->h - radius) return((x >= but->x) && (x < but->x + but->w)); else { if (x < but->x + radius) { dx = but->x + radius - x; dy = y - (but->y + but->h - radius - 1); return(dx*dx + dy*dy < radlimit); } else if (x < but->x + but->w - radius) return(y < but->y + but->h); else { dx = x - (but->x + but->w - radius - 1); dy = y - (but->y + but->h - radius - 1); return(dx*dx + dy*dy < radlimit); } } } static ButOut remPress(But *but, void *msg, int msgLen) { Ct *ct = but->iPacket; ButOut res = 0; assert(msgLen == 0); snd_play(&but_upSnd); if ((ct->rfunc != NULL) && ct->netAction) res = ct->rfunc(but); return(res); } void butCt_setNetAction(But *but, bool netAction) { Ct *ct = but->iPacket; ct->netAction = netAction; } #endif pente-2.2.5/wmslib/src/but/i_finder.c0100664000076400007640000004050207045637750015663 0ustar wmswms/* * wmslib/src/but/i_finder.c, part of wmslib (Library functions) * Copyright (C) 1994 William Shubert. * See "configure.h.in" for more copyright information. */ #include #ifdef X11_DISP #ifdef STDC_HEADERS #include #include #endif /* STDC_HEADERS */ #include #include #include #include #include #include #include #ifdef HAVE_SYS_SELECT_H #include #endif #include #include static void addButToCol(ButCol *col, But *but, int y1, int y2); static void addButToRow(ButRow *row, But *but); static void copyCol(ButCol *dest, ButCol *src); static void copyRow(ButRow *dest, ButRow *src); static void findButSetInCol(ButCol *col, int x, int y, ButSet *butset); static void butDelFromCol(ButCol *col, But *but); static void butDelFromRow(ButRow *row, But *but); static bool colEq(ButCol *c1, ButCol *c2); static bool rowEq(ButRow *r1, ButRow *r2); static void colDel(ButWin *win, int col_num); static void rowDel(ButCol *col, int row_num); static int markForTable(But *but, void *packet); static int addToTable(But *but, void *packet); static int butcomp(const void *a, const void *b); #if 0 /* Useful sometimes for debugging. */ void printf_table(but_win_t *win); void printf_env(but_env_t *win); #endif void butWin_addToTable(ButWin *win) { ButEnv *env = win->env; ButWin **new_winlist; int i, j, new_pos; assert(MAGIC(win)); if (win->win != None) { /* * If win->win is None, then it is a canvas, which does not have to * be entered into the window table yet. */ if (env->wlmax == env->wllen) { new_winlist = wms_malloc(sizeof(ButWin *) * (env->wllen + 1) * 2); for (i = 0; i < env->wllen; ++i) new_winlist[i] = env->winlist[i]; if (env->winlist != NULL) wms_free(env->winlist); env->winlist = new_winlist; env->wlmax = (env->wllen + 1) * 2; } for (i = 0; (i < env->wllen) && (win->win > env->winlist[i]->win); ++i); new_pos = i; for (i = env->wllen; i > new_pos; --i) env->winlist[i] = env->winlist[i-1]; env->winlist[new_pos] = win; ++env->wllen; } if (win->numCols == 0) { /* * A canvas may call this function every time the pixmap changes, so * we have to make sure that we don't re-allocate all this stuff! */ win->numCols = 2; win->maxCols = 2; win->cols = wms_malloc(2 * sizeof(ButCol)); win->cols[0].startX = int_min; win->cols[1].startX = int_max; for (i = 0; i < 2; ++i) { MAGIC_SET(&win->cols[i]); win->cols[i].numRows = 2; win->cols[i].maxRows = 2; win->cols[i].rows = wms_malloc(2 * sizeof(ButRow)); win->cols[i].rows[0].startY = int_min; win->cols[i].rows[1].startY = int_max; for (j = 0; j < 2; ++j) { MAGIC_SET(&win->cols[i].rows[j]); win->cols[i].rows[j].numButs = 0; win->cols[i].rows[j].maxButs = 0; win->cols[i].rows[j].buts = NULL; } } } #if DEBUG for (i = 1; i < env->wllen; ++i) { assert(env->winlist[i]->win > env->winlist[i - 1]->win); } #endif /* DEBUG */ } void butWin_rmFromTable(ButWin *win) { ButEnv *env = win->env; int i; assert(MAGIC(win)); assert(MAGIC(env)); for (i = 0; (env->winlist[i] != win) && (i < env->wllen); ++i); if (i < env->wllen) { --env->wllen; while (i < env->wllen) { env->winlist[i] = env->winlist[i+1]; ++i; } } #if DEBUG for (i = 1; i < env->wllen; ++i) { assert(env->winlist[i]->win > env->winlist[i - 1]->win); } #endif /* DEBUG */ } void but_addToTable(But *but) { ButWin *win = but->win; int x1 = but->x, y1 = but->y, x2 = but->x + but->w, y2 = but->y + but->h; int i, src, dest; ButCol *new_cl = win->cols; int new_cll = win->numCols, new_clmax = win->maxCols; int x1done = 0, x2done = 0; assert(MAGIC(but)); assert(but->flags & BUT_DRAWABLE); butSet_delBut(&win->butsNoDraw, but); for (i = 0; i < new_cll; ++i) { assert(MAGIC(&new_cl[i])); if (new_cl[i].startX == x1) x1done = 1; else if (new_cl[i].startX == x2) x2done = 1; } new_cll += 2 - (x1done + x2done); if (new_cll > win->maxCols) { new_cl = wms_malloc(sizeof(ButCol) * (new_clmax = new_cll * 2)); for (i = 0; i < new_clmax; ++i) { MAGIC_SET(&new_cl[i]); new_cl[i].rows = NULL; } } for (src = win->numCols, dest = new_cll; src > 0;) { --src; --dest; assert(MAGIC(&win->cols[src])); if (!x2done && (win->cols[src].startX < x2)) { assert(MAGIC(&new_cl[dest])); copyCol(&new_cl[dest], &win->cols[src]); new_cl[dest--].startX = x2; x2done = 1; } if (!x1done && (win->cols[src].startX < x1)) { assert(MAGIC(&new_cl[dest])); copyCol(&new_cl[dest], &win->cols[src]); new_cl[dest].startX = x1; addButToCol(&new_cl[dest--], but, y1, y2); x1done = 1; } assert(MAGIC(&new_cl[dest])); new_cl[dest] = win->cols[src]; if ((new_cl[dest].startX < x2) && (new_cl[dest].startX >= x1)) addButToCol(&new_cl[dest], but, y1, y2); } if (win->cols != new_cl) { for (i = 0; i < win->maxCols; ++i) MAGIC_UNSET(&win->cols[i]); wms_free(win->cols); win->cols = new_cl; } win->maxCols = new_clmax; win->numCols = new_cll; } static void addButToCol(ButCol *col, But *but, int y1, int y2) { ButRow *new_rl = col->rows; int i, src, dest, new_rll = col->numRows, new_rlmax = col->maxRows; int y1done=0, y2done=0; assert(MAGIC(col)); assert(MAGIC(but)); for (i = 0; i < col->numRows; ++i) { assert(MAGIC(&col->rows[i])); if (col->rows[i].startY == y1) y1done = 1; if (col->rows[i].startY == y2) y2done = 1; } new_rll += 2 - (y1done + y2done); if (new_rll > col->maxRows) { new_rl = wms_malloc(sizeof(ButRow) * (new_rlmax = new_rll * 2)); for (i = 0; i < new_rlmax; ++i) { MAGIC_SET(&new_rl[i]); new_rl[i].buts = NULL; } } for (src = col->numRows, dest = new_rll; src > 0;) { --src; --dest; assert(MAGIC(&col->rows[src])); if (!y2done && (col->rows[src].startY < y2)) { assert(MAGIC(&new_rl[dest])); copyRow(&new_rl[dest], &col->rows[src]); new_rl[dest--].startY = y2; y2done = 1; } if (!y1done && (col->rows[src].startY < y1)) { assert(MAGIC(&new_rl[dest])); copyRow(&new_rl[dest], &col->rows[src]); new_rl[dest].startY = y1; addButToRow(&new_rl[dest--], but); y1done = 1; } assert(MAGIC(&new_rl[dest])); new_rl[dest] = col->rows[src]; if ((new_rl[dest].startY < y2) && (new_rl[dest].startY >= y1)) addButToRow(&new_rl[dest], but); } if (col->rows != new_rl) { if (col->rows != NULL) { wms_free(col->rows); for (i = 0; i < col->maxRows; ++i) MAGIC_UNSET(&col->rows[i]); } col->rows = new_rl; } col->maxRows = new_rlmax; col->numRows = new_rll; } static void addButToRow(ButRow *row, But *but) { int i, new_maxButs = row->maxButs, new_numButs = row->numButs + 1; But **new_bl = row->buts; assert(MAGIC(row)); assert(MAGIC(but)); if (new_numButs >= row->maxButs) { new_bl = wms_malloc(sizeof(But *) * (new_maxButs = new_numButs * 2)); for (i = 0; i < row->numButs; ++i) new_bl[i] = row->buts[i]; } for (i = row->numButs - 1; (i >= 0) && (but->layer < row->buts[i]->layer); --i) { assert(MAGIC(new_bl[i])); assert(new_bl[i] != but); new_bl[i+1] = new_bl[i]; } new_bl[i+1] = but; #if DEBUG for (; i >= 0; --i) assert(new_bl[i] != but); #endif if ((row->buts != NULL) && (row->buts != new_bl)) wms_free(row->buts); row->buts = new_bl; row->numButs = new_numButs; row->maxButs = new_maxButs; } static void copyCol(ButCol *dest, ButCol *src) { int i; assert(MAGIC(dest)); assert(MAGIC(src)); *dest = *src; dest->rows = wms_malloc(dest->maxRows * sizeof(ButRow)); for (i = 0; i < dest->maxRows; ++i) MAGIC_SET(&dest->rows[i]); for (i = 0; i < dest->numRows; ++i) copyRow(&dest->rows[i], &src->rows[i]); } static void copyRow(ButRow *dest, ButRow *src) { int i; assert(MAGIC(dest)); assert(MAGIC(src)); *dest = *src; dest->buts = wms_malloc(dest->maxButs * sizeof(But *)); for (i = 0; i < dest->numButs; ++i) dest->buts[i] = src->buts[i]; } void butWin_findButSet(ButWin *win, int x, int y, ButSet *butset) { unsigned hlen, result = 0, cllen = win->numCols; assert(MAGIC(win)); butset->dynamic = FALSE; while ((hlen = (cllen >> 1))) { assert(MAGIC(&win->cols[result+hlen])); if (win->cols[result+hlen].startX > x) { cllen = hlen; } else { cllen -= hlen; result += hlen; } } findButSetInCol(&win->cols[result], x, y, butset); } static void findButSetInCol(ButCol *col, int x, int y, ButSet *butset) { unsigned hlen, result = 0, rllen = col->numRows; assert(MAGIC(col)); while ((hlen = (rllen >> 1))) { assert(MAGIC(&col->rows[result+hlen])); if (col->rows[result+hlen].startY > y) { rllen = hlen; } else { rllen -= hlen; result += hlen; } } butset->numButs = col->rows[result].numButs; butset->buts = col->rows[result].buts; butset->dynamic = FALSE; } void but_delFromTable(But *but) { ButWin *win = but->win; int i; ButCol *cl = win->cols; assert(MAGIC(but)); assert(MAGIC(win)); for (i = 1; i < win->numCols - 1; ++i) { assert(MAGIC(&cl[i])); if ((cl[i].startX >= but->x) && (cl[i].startX < but->x + but->w)) { butDelFromCol(&cl[i], but); if (colEq(&cl[i-1], &cl[i])) { colDel(win, i); --i; } if ((i+1 < win->numCols - 1) && colEq(&cl[i], &cl[i+1])) colDel(win, i+1); } } } static bool colEq(ButCol *c1, ButCol *c2) { int i; assert(MAGIC(c1)); assert(MAGIC(c2)); if (c1->numRows != c2->numRows) return(FALSE); for (i = 0; i < c1->numRows; ++i) { if (!rowEq(&c1->rows[i], &c2->rows[i])) return(FALSE); } return(TRUE); } static bool rowEq(ButRow *r1, ButRow *r2) { int i; assert(MAGIC(r1)); assert(MAGIC(r2)); if (r1->numButs != r2->numButs) return(FALSE); for (i = 0; i < r1->numButs; ++i) { if (r1->buts[i] != r2->buts[i]) return(FALSE); } return(TRUE); } static void butDelFromCol(ButCol *col, But *but) { int i; ButRow *rl = col->rows; assert(MAGIC(col)); for (i = 1; i < col->numRows - 1; ++i) { assert(MAGIC(&rl[i])); if ((rl[i].startY >= but->y) && (rl[i].startY < but->y + but->h)) { butDelFromRow(&rl[i], but); if (rowEq(&rl[i-1], &rl[i])) { rowDel(col, i); --i; } if ((i+1 < col->numRows - 1) && rowEq(&rl[i], &rl[i+1])) rowDel(col, i+1); } } } static void butDelFromRow(ButRow *row, But *but) { int dest, src; assert(MAGIC(row)); for (dest = 0, src = 0; src < row->numButs; ++src) { assert(MAGIC(row->buts[src])); row->buts[dest] = row->buts[src]; if (row->buts[dest] != but) { ++dest; } else { assert(src == dest); } } assert(src == dest + 1); --row->numButs; assert(dest == row->numButs); } static void colDel(ButWin *win, int col_num) { int i; assert(MAGIC(win)); assert(MAGIC(&win->cols[col_num])); for (i = 0; i < win->cols[col_num].numRows; ++i) { assert(MAGIC(&win->cols[col_num].rows[i])); if (win->cols[col_num].rows[i].buts != NULL) wms_free(win->cols[col_num].rows[i].buts); } wms_free(win->cols[col_num].rows); --win->numCols; for (i = col_num; i < win->numCols; ++i) win->cols[i] = win->cols[i+1]; } static void rowDel(ButCol *col, int row_num) { int i; assert(MAGIC(col)); assert(MAGIC(&col->rows[row_num])); if (col->rows[row_num].buts != NULL) wms_free(col->rows[row_num].buts); --col->numRows; for (i = row_num; i < col->numRows; ++i) col->rows[i] = col->rows[i+1]; } void butWin_findButSetInRegion(ButWin *win, int x, int y, int w, int h, ButSet *butset) { assert(MAGIC(win)); butset->numButs = 0; butset->dynamic = TRUE; butWin_findButsInRegion(win, x,y, w,h, markForTable, butset); if (butset->numButs > 0) { butset->buts = wms_malloc(butset->numButs * sizeof(But *)); butset->maxButs = butset->numButs; butset->numButs = 0; butWin_findButsInRegion(win, x,y, w,h, addToTable, butset); qsort(butset->buts, butset->numButs, sizeof(But *), butcomp); } else { butset->dynamic = FALSE; butset->buts = NULL; } } static int markForTable(But *but, void *packet) { ButSet *butset = packet; assert(MAGIC(but)); if ((but->flags & (BUT_TABLED|BUT_DEAD|BUT_DRAWABLE)) == BUT_DRAWABLE) { ++butset->numButs; but->flags |= BUT_TABLED; } return(0); } static int addToTable(But *but, void *packet) { ButSet *butset = packet; assert(MAGIC(but)); if (but->flags & BUT_TABLED) { butset->buts[butset->numButs++] = but; assert(butset->numButs <= butset->maxButs); but->flags &= ~BUT_TABLED; } return(0); } static int butcomp(const void *a, const void *b) { const But *but_a = *(But **)a; const But *but_b = *(But **)b; assert(MAGIC(but_a)); assert(MAGIC(but_b)); if (but_a->layer != but_b->layer) return(but_a->layer - but_b->layer); else if (but_a > but_b) return(-1); else return(1); } ButWin *butEnv_findWin(ButEnv *env, Window win) { int wmin = 0, wmax = env->wllen, wnum; #if DEBUG for (wnum = 1; wnum < env->wllen; ++wnum) { assert(env->winlist[wnum]->win > env->winlist[wnum - 1]->win); } #endif /* DEBUG */ while (wmin < wmax) { wnum = (wmax + wmin) >> 1; assert(MAGIC(env->winlist[wnum])); if (env->winlist[wnum]->win == win) { return(env->winlist[wnum]); } if (env->winlist[wnum]->win > win) { wmax = wnum; } else { wmin = wnum + 1; } } return(NULL); } But *butWin_findButsInRegion(ButWin *win, int x,int y, int w,int h, bool (*action)(But *but, void *packet), void *packet) { int r, c, b; ButCol *col; ButRow *row; But *but; assert(MAGIC(win)); for (c = 1; c < win->numCols - 1; ++c) { col = &win->cols[c]; assert(MAGIC(col)); if ((col->startX < x+w) && (win->cols[c+1].startX > x)) { for (r = 1; r < col->numRows - 1; ++r) { row = &col->rows[r]; assert(MAGIC(row)); if ((row->startY < y+h) && (col->rows[r+1].startY > y)) { for (b = 0; b < row->numButs; ++b) { but = row->buts[b]; assert(MAGIC(but)); if (action(but, packet)) return(but); } } } } } return(NULL); } #if 0 /* Sometimes useful for debugging. */ void printf_env(but_env_t *env) { int i; printf("Env has %d (max %d) windows:\n", env->wllen, env->wlmax); for (i = 0; i < env->wllen; ++i) printf(" 0x%x (x win %d)\n", (int)env->winlist[i], (int)(env->winlist[i]->win)); } void printf_table(but_win_t *win) { int i, j, k; for (i = 0; i < win->numCols - 1; ++i) { printf("Col %d of %d: %d..%d\n", i+1, win->numCols - 1, win->cols[i].startX, win->cols[i+1].startX - 1); for (j = 0; j < win->cols[i].numRows - 1; ++j) { printf(" Row %d of %d: %d..%d\n", j+1, win->cols[i].numRows - 1, win->cols[i].rows[j].startY, win->cols[i].rows[j+1].startY - 1); if (win->cols[i].rows[j].numButs == 0) printf(" No buttons.\n"); else { for (k = 0; k < win->cols[i].rows[j].numButs; ++k) printf(" But 0x%x\n", (int)win->cols[i].rows[j].buts[k]); } } } printf("---\n"); } #endif void butSet_addBut(ButSet *butset, But *but) { int i, new_maxButs; But **newbuts; assert(MAGIC(butset)); assert(butset->dynamic); for (i = 0; i < butset->numButs; ++i) { if (butset->buts[i] == but) return; } if (butset->numButs == butset->maxButs) { new_maxButs = (butset->maxButs + 1) * 2; newbuts = wms_malloc(new_maxButs * sizeof(But *)); if (butset->buts != NULL) { memcpy(newbuts, butset->buts, butset->maxButs * sizeof(But *)); wms_free(butset->buts); } butset->buts = newbuts; butset->maxButs = new_maxButs; } butset->buts[butset->numButs++] = but; } void butSet_delBut(ButSet *butset, But *but) { int i; assert(MAGIC(butset)); for (i = 0; i < butset->numButs; ++i) { if (butset->buts[i] == but) { butset->buts[i] = butset->buts[--butset->numButs]; return; } } } #endif pente-2.2.5/wmslib/src/but/i_general.c0100664000076400007640000004605607045637750016043 0ustar wmswms/* * wmslib/src/but/i_general.c, part of wmslib (Library functions) * Copyright (C) 1994,1997 William Shubert. * See "configure.h.in" for more copyright information. */ #include #ifdef X11_DISP #ifdef STDC_HEADERS #include #include #endif /* STDC_HEADERS */ #include #include #include #include #include #include #include #ifdef HAVE_SYS_SELECT_H #include #endif #include #include #include #include #include /********************************************************************** * Forward Declarations **********************************************************************/ static void mousein(ButWin *win, int x, int y, ButSet *butset); /********************************************************************** * Globals **********************************************************************/ bool but_inEvent = FALSE; /********************************************************************** * Functions **********************************************************************/ void but_init(But *but) { ButWin *win = but->win; ButEnv *env = win->env; int nfl; assert(MAGIC(win)); MAGIC_SET(but); if (!(but->flags & BUT_DRAWABLE)) return; if (win->maxLayer < win->minLayer) win->maxLayer = win->minLayer = but->layer; else { if (but->layer < win->minLayer) win->minLayer = but->layer; if (but->layer > win->maxLayer) win->maxLayer = but->layer; } butSet_addBut(&win->butsNoDraw, but); if (but->w > 0) but_addToTable(but); if (but->flags & BUT_KEYED) { if (win->keyBut != NULL) { nfl = win->keyBut->flags & ~BUT_KEYED; if (env->last_mwin == win) nfl &= ~BUT_KEYACTIVE; but_newFlags(win->keyBut, nfl); } win->keyBut = but; if (env->last_mwin == win) but->flags |= BUT_KEYACTIVE; } nfl = but->flags; but->flags = BUT_DRAWABLE; /* Force a new flags type redraw. */ but_newFlags(but, nfl); butWin_mMove(env->last_mwin, env->last_mx, env->last_my); } void but_resize(But *but, int x, int y, int w, int h) { int oldx = but->x, oldy = but->y, oldw = but->w, oldh = but->h; assert(MAGIC(but)); if ((oldx == x) && (oldy == y) && (oldw == w) && (oldh == h)) return; if ((w <= 0) || (h <= 0)) w = h = 0; if ((oldw > 0) && (but->flags & BUT_DRAWABLE)) but_delFromTable(but); but->x = x; but->y = y; but->w = w; but->h = h; if ((w > 0) && (but->flags & BUT_DRAWABLE)) but_addToTable(but); if (but->action->resize) { if (but->action->resize(but, oldx, oldy, oldw, oldh) && (but->flags & BUT_DRAWABLE)) { butWin_redraw(but->win, oldx,oldy, oldw,oldh); butWin_redraw(but->win, x,y, w,h); } } else if (but->flags & BUT_DRAWABLE) { if ((oldw > 0) && (oldh > 0)) butWin_redraw(but->win, oldx,oldy, oldw,oldh); butWin_redraw(but->win, x,y, w,h); } if (but->flags & BUT_DRAWABLE) butWin_mMove(but->win->env->last_mwin, but->win->env->last_mx, but->win->env->last_my); } void but_destroy(But *but) { ButTimer *timer; if (but != NULL) { assert(MAGIC(but)); but_newFlags(but, 0); for (timer = but_timerList; timer != NULL; timer = timer->next) { if (timer->but == but) { butTimer_destroy(timer); break; } } } if (but_inEvent) but_dList(but); else but_delete(but); } But *but_create(ButWin *win, void *iPacket, const ButAction *action) { But *but; but = (But *)wms_malloc(sizeof(But)); MAGIC_SET(but); assert(win->parent || (win->win != None)); but->uPacket = NULL; but->iPacket = iPacket; but->win = win; but->layer = 0; but->x = 0; but->y = 0; but->w = 0; but->h = 0; but->id = -2; but->flags = 0; but->keys = NULL; but->action = action; but->destroyCallback = NULL; return(but); } ButOut but_delete(But *but) { ButOut result = 0; ButWin *win = but->win; int x = but->x, y = but->y, w = but->w, h = but->h; assert(but != NULL); assert(MAGIC(win)); assert(MAGIC(but)); if (but->flags) but_newFlags(but, 0); if (but->destroyCallback) but->destroyCallback(but); if (but->action->destroy != NULL) result = but->action->destroy(but); MAGIC_UNSET(but); wms_free(but); butWin_redraw(win, x,y,w,h); return(result); } void but_setFlags(But *but, uint fch) { uint fl; assert(MAGIC(but)); fl = but->flags | fch; fl &= ~(fch >> BUT_MAXBITS); but_newFlags(but, fl); } void but_setKeys(But *but, const ButKey *keys) { assert(MAGIC(but)); assert((but->action->kPress) || (but->action->kRelease)); but->keys = keys; } void but_newFlags(But *but, uint nfl) { static bool inNewFlags = FALSE; ButWin *win = but->win, *tmpWin, *ancestor; ButEnv *env = win->env; uint oldflags = but->flags; assert(MAGIC(win)); assert(MAGIC(but)); for (ancestor = win; ancestor->parent; ancestor = ancestor->parent) assert(MAGIC(ancestor)); if (!(nfl & BUT_PRESSABLE)) { nfl &= ~(BUT_PRESSED|BUT_TWITCHED|BUT_LOCKED); if (env->curhold == but) butEnv_setCursor(env, but, butCur_idle); } if (!(oldflags & BUT_DRAWABLE) && (nfl & BUT_DRAWABLE)) { but->flags = nfl; but_init(but); return; } if (!(nfl & BUT_DRAWABLE) && (env->butIn == but)) { env->butIn = NULL; for (tmpWin = win; tmpWin; tmpWin = tmpWin->parent) { assert(MAGIC(tmpWin)); tmpWin->butIn = NULL; } } if ((oldflags & BUT_KEYED) && !(nfl & BUT_KEYED)) { nfl &= ~BUT_KEYACTIVE; ancestor->keyBut = NULL; } if (!(oldflags & BUT_KEYED) && (nfl & BUT_KEYED)) { if (ancestor->keyBut != NULL) { but_newFlags(ancestor->keyBut, ancestor->keyBut->flags & ~BUT_KEYED); } ancestor->keyBut = but; if (env->last_mwin == but->win) { nfl |= BUT_KEYACTIVE; } } if ((but->id != -2) && !inNewFlags && ((nfl & BUT_NETMASK) != (but->flags & BUT_NETMASK))) { inNewFlags = TRUE; butRnet_newFlags(env, but->id, nfl); inNewFlags = FALSE; } if (!(oldflags & BUT_LOCKED) && (nfl & BUT_LOCKED)) { if (env->lockBut != NULL) but_newFlags(env->lockBut, env->lockBut->flags & ~BUT_LOCKED); env->lockBut = but; win->lock = but; for (tmpWin = env->lockBut->win; tmpWin->parent; tmpWin = tmpWin->parent) { assert(MAGIC(tmpWin)); tmpWin->parent->lock = tmpWin->parentBut; } } else if ((oldflags & BUT_LOCKED) && !(nfl & BUT_LOCKED)) { for (tmpWin = but->win; tmpWin; tmpWin = tmpWin->parent) { assert(MAGIC(tmpWin)); tmpWin->lock = NULL; } env->lockBut = NULL; } if (nfl != oldflags) { if (but->action->newFlags) but->action->newFlags(but, nfl); } if ((oldflags & BUT_DRAWABLE) && !(nfl & BUT_DRAWABLE)) { if (but->w > 0) { but_delFromTable(but); } } butWin_mMove(env->last_mwin, env->last_mx, env->last_my); } void but_draw(But *but) { assert(MAGIC(but)); if ((but->flags & (BUT_DRAWABLE|BUT_DEAD)) == BUT_DRAWABLE) butWin_redraw(but->win, but->x,but->y, but->w,but->h); } ButOut butWin_mMove(ButWin *win, int x, int y) { ButEnv *env; ButOut result = 0; int i; But *but, *oldbut; ButSet butset; ButWin *tmpWin; assert(MAGICNULL(win)); if (win == NULL) return(0); env = win->env; if ((env->last_mwin != win) && (!env->last_mwin || (env->last_mwin->physWin != win->physWin))) { env->curwin = win->physWin; env->curlast = butCur_bogus; } if (win->parent == NULL) { /* Only do this if you're on a real window, that is, not in a canvas. */ env->last_mwin = win; env->last_mx = x; env->last_my = y; } mousein(win, x, y, &butset); for (i = butset.numButs - 1; i >= 0; --i) { but = butset.buts[i]; assert(MAGIC(but)); if ((but->flags & BUT_DRAWABLE) && !(but->flags & BUT_PRESSTHRU)) { if (but->action->mMove == NULL) result |= BUTOUT_CAUGHT; else result |= but->action->mMove(but, x,y); if (result & BUTOUT_CAUGHT) { if (result & BUTOUT_IGNORE) return(result); if (env->butIn != but) { if (env->butIn != NULL) { for (tmpWin = env->butIn->win; tmpWin; tmpWin = tmpWin->parent) { tmpWin->butIn = NULL; } if ((env->butIn->flags & BUT_PRESSABLE) && (env->butIn->action->mLeave != NULL)) result |= env->butIn->action->mLeave(env->butIn); } env->butIn = but; but->win->butIn = but; for (tmpWin = but->win; tmpWin->parent; tmpWin = tmpWin->parent) { tmpWin->parent->butIn = tmpWin->parentBut; } } return(result); } } } if (env->butIn != NULL) { oldbut = env->butIn; for (tmpWin = env->butIn->win; tmpWin; tmpWin = tmpWin->parent) { tmpWin->butIn = NULL; } env->butIn = NULL; if ((oldbut->flags & BUT_PRESSABLE) && (oldbut->action->mLeave != NULL)) result |= oldbut->action->mLeave(oldbut); } return(result); } ButOut butWin_mPress(ButWin *win, int x, int y, int butnum) { ButOut result; But *but; assert(MAGIC(win)); result = butWin_mMove(win, x, y); but = win->butIn; if (but != NULL) { assert(MAGIC(but)); if ((but->flags & BUT_PRESSABLE) && (but->action->mPress != NULL)) { return(result | but->action->mPress(but, butnum, x, y)); } } return(result | BUTOUT_ERR); } ButOut butWin_mRelease(ButWin *win, int x, int y, int butnum) { ButOut result; But *but; assert(MAGIC(win)); result = butWin_mMove(win, x, y); but = win->butIn; if (but != NULL) { assert(MAGIC(but)); if ((but->flags & BUT_PRESSABLE) && (but->action->mRelease != NULL)) return(result | but->action->mRelease(but, butnum, x, y)); } return(result); } static int keycheck(But *but, void *packet) { int keycount; KeySym sym = *(KeySym *)packet; assert(MAGIC(but)); if (but->keys != NULL) { for (keycount = 0; but->keys[keycount].key != 0; ++keycount) { if ((but->keys[keycount].key == sym) && ((but->win->env->keyModifiers & but->keys[keycount].modMask) == but->keys[keycount].modifiers)) return(1); } } return(0); } ButOut butWin_kPress(ButWin *win, const char *keystr, KeySym sym) { ButOut retVal = 0; But *but; assert(MAGIC(win)); /* * The keybut _always_ get a shot at the key when it is pressed. */ if (win->keyBut) { assert(win->keyBut->flags & BUT_PRESSABLE); retVal |= win->keyBut->action->kPress(win->keyBut, keystr, sym); } if (!(retVal & BUTOUT_CAUGHT)) { but = butWin_findButsInRegion(win, 0,0, win->w,win->h, keycheck, &sym); if ((but != NULL) && (but->flags & BUT_PRESSABLE) && (but->action->kPress != NULL)) { assert(MAGIC(but)); retVal |= but->action->kPress(but, keystr, sym); } else { /* * A key was pressed that nobody wanted. * But only signal an error if it was a "real" key...don't beep when * some poor guy presses shift! */ if (!IsModifierKey(sym)) retVal |= BUTOUT_ERR; } } return(retVal); } ButOut butWin_kRelease(ButWin *win, const char *keystr, KeySym sym) { ButOut retval = 0; But *but; assert(MAGIC(win)); but = butWin_findButsInRegion(win, 0,0, win->w,win->h, keycheck, &sym); if (but != NULL) { assert(MAGIC(but)); if ((but->flags & BUT_PRESSABLE) && (but->action->kRelease != NULL)) retval |= but->action->kRelease(but, keystr, sym); } return(retval); } /* mousein(win, x, y, reason) will return the button number that the mouse is * presently inside of. If the mouse is not in any button NULL will * be returned. * The checkfunc will be called only if the mouse is already inside the * (x,y,w,h) boundaries of the button. "reason" is one of BUT_RE_PRESS, * BUT_RE_RELEASE, or BUT_RE_MOVE, depending on the reason for the button * to be checked. * Non-pressable buttons will never be returned. * * NOTE: This does a linear search through the buttons. YUCK! SLOW! I'd * like to recode this to do a three-dimensional binary search (the * dimensions being window, x, and y) but that would take some seriously * heavy-duty coding and I have a million other things to do first. * * NOTE to note: I finally did the 3d binary search. Works great! */ static void mousein(ButWin *win, int x, int y, ButSet *butset) { static But *but; assert(MAGIC(win)); if (win->lock) { butset->dynamic = FALSE; butset->numButs = 1; butset->buts = &but; but = win->lock; } else butWin_findButSet(win, x, y, butset); } static int but_compare(const void *a, const void *b) { But **but_a = (But **)a, **but_b = (But **)b; assert(MAGIC(*but_a)); assert(MAGIC(*but_b)); return((*but_a)->layer - (*but_b)->layer); } void butWin_redraw(ButWin *win, int x, int y, int w, int h) { ButWinArea *newAreas; int newMaxRedraws, i; bool change; assert((x > -1000) && (y > -1000)); if (!w || !h) return; assert(w > 0); assert(h > 0); if (win->numRedraws + 1 >= win->maxRedraws) { newMaxRedraws = (win->maxRedraws + 1) * 2; newAreas = wms_malloc(newMaxRedraws * sizeof(ButWinArea)); for (i = 0; i < win->numRedraws; ++i) { newAreas[i] = win->redraws[i]; } if (win->redraws) wms_free(win->redraws); win->redraws = newAreas; win->maxRedraws = newMaxRedraws; } assert(win->numRedraws < win->maxRedraws); do { assert(w > 0); assert(h > 0); change = FALSE; for (i = 0; i < win->numRedraws; ++i) { if ((x <= win->redraws[i].x + win->redraws[i].w) && (y <= win->redraws[i].y + win->redraws[i].h) && (x + w >= win->redraws[i].x) && (y + h >= win->redraws[i].y)) { change = TRUE; if (win->redraws[i].x < x) { w += x - win->redraws[i].x; x = win->redraws[i].x; } if (win->redraws[i].y < y) { h += y - win->redraws[i].y; y = win->redraws[i].y; } if (x + w < win->redraws[i].x + win->redraws[i].w) w = win->redraws[i].x + win->redraws[i].w - x; if (y + h < win->redraws[i].y + win->redraws[i].h) h = win->redraws[i].y + win->redraws[i].h - y; win->redraws[i] = win->redraws[--win->numRedraws]; } } } while (change); win->redraws[win->numRedraws].x = x; win->redraws[win->numRedraws].y = y; win->redraws[win->numRedraws].w = w; win->redraws[win->numRedraws].h = h; assert(w > 0); assert(h > 0); ++win->numRedraws; assert(win->numRedraws < win->maxRedraws); } void butWin_performDraws(ButWin *win) { int drawNum; int i, drx,dry, drw,drh, x, y, w, h; ButEnv *env = win->env; XRectangle cliprect; ButSet butset; But *but; assert(MAGIC(win)); if (!win->mapped) { win->numRedraws = 0; return; } for (drawNum = 0; drawNum < win->numRedraws; ++drawNum) { x = win->redraws[drawNum].x; y = win->redraws[drawNum].y; w = win->redraws[drawNum].w; h = win->redraws[drawNum].h; assert(w > 0); assert(h > 0); if (x < win->xOff) { w -= win->xOff - x; x = win->xOff; } if (x + w > win->xOff + win->w) w = win->xOff + win->w - x; if (y < win->yOff) { h -= win->yOff - y; y = win->yOff; } if (y + h > win->yOff + win->h) h = win->yOff + win->h - y; if ((w <= 0) || (h <= 0)) continue; if (win->id != -2) butRcur_redraw(env, win->id, x,y,w,h); butWin_findButSetInRegion(win, x,y, w,h, &butset); if (butset.numButs > 0) { cliprect.x = x - win->xOff; cliprect.y = y - win->yOff; cliprect.width = w; cliprect.height = h; XSetClipRectangles(env->dpy, env->gc, 0,0, &cliprect, 1, YXSorted); qsort(butset.buts, butset.numButs, sizeof(But *), but_compare); assert(MAGIC(win)); for (i = butset.numButs - 1; i > 0; --i) { but = butset.buts[i]; assert(MAGIC(but)); if ((but->flags & BUT_OPAQUE) && (but->x <= x) && (but->y <= y) && (but->x + but->w >= x + w) && (but->y + but->h >= y + h)) break; } for (; i < butset.numButs; ++i) { but = butset.buts[i]; assert(MAGIC(but)); if (!(but->flags & BUT_DEAD)) { if (but->x < x) drx = x; else drx = but->x; if (but->y < y) dry = y; else dry = but->y; if (but->x + but->w < x+w) drw = but->x + but->w - drx; else drw = x + w - drx; if (but->y + but->h < y+h) drh = but->y + but->h - dry; else drh = y+h - dry; but->action->draw(but, x,y, w,h); } } XSetClipMask(env->dpy, env->gc, None); butSet_destroy(&butset); if (win->parent) { /* * It's a canvas. Fire off a redraw request so that the changes to * the canvas pixmap will be seen on the screen. */ butCan_redrawn(win, x, y, w, h); } } } win->numRedraws = 0; } void butSet_destroy(ButSet *butset) { if (butset->dynamic && (butset->buts != NULL)) wms_free(butset->buts); } /* If win is NULL it will execute all destroy commands built up. */ ButOut butWin_dList(ButWin *win) { static ButWin **dlist = NULL; static int dlist_len = 0, max_dlist_len = 0; ButWin **new_dlist; int i; ButOut result = 0; assert(MAGICNULL(win)); if (win == NULL) { /* * It is really important that we start at the end here. Since our * child windows are added to the _end_ of the dlist, and they _must_ * be destroyed first, we have to go backwards. */ while (dlist_len) { i = dlist_len - 1; if (dlist[i] != NULL) { assert(MAGIC(dlist[i])); result |= butWin_delete(dlist[i]) | BUTOUT_CAUGHT; if (result & BUTOUT_STILLBUTS) { /* Window still has buttons...can't kill it yet! */ return(result & ~BUTOUT_STILLBUTS); } dlist[i] = NULL; } --dlist_len; } } else { if (win->iconWin != NULL) { butWin_dList(win->iconWin); win->iconWin = NULL; } if (dlist_len+1 > max_dlist_len) { new_dlist = wms_malloc(sizeof(ButWin *) * (dlist_len * 2 + 2)); for (i = 0; i < dlist_len; ++i) new_dlist[i] = dlist[i]; if (dlist != NULL) wms_free(dlist); dlist = new_dlist; max_dlist_len = (dlist_len * 2 + 2); } for (i = 0; i < dlist_len; ++i) if (dlist[i] == win) return(result); dlist[dlist_len++] = win; } return(result); } /* If but is NULL it will execute all destroy commands built up. */ ButOut but_dList(But *but) { static But **dlist = NULL; static int dlist_len = 0, max_dlist_len = 0; But **new_dlist; int i; ButOut result = 0; if (but == NULL) { if (dlist_len == 0) return(0); for (i = 0; i < dlist_len; ++i) { result |= but_delete(dlist[i]) | BUTOUT_CAUGHT; } dlist_len = 0; } else { if (dlist_len+1 > max_dlist_len) { new_dlist = wms_malloc(sizeof(But *) * (dlist_len * 2 + 2)); for (i = 0; i < dlist_len; ++i) new_dlist[i] = dlist[i]; if (dlist != NULL) wms_free(dlist); dlist = new_dlist; max_dlist_len = (dlist_len * 2 + 2); } for (i = 0; i < dlist_len; ++i) if (dlist[i] == but) return(result); but_newFlags(but, 0); dlist[dlist_len++] = but; but->flags |= BUT_DEAD; } return(result); } void but_flags(But *but, uint flags) { but->flags = flags; but_draw(but); } #endif /* X11_DISP */ pente-2.2.5/wmslib/src/but/i_snd.c0100664000076400007640000000235407045637750015203 0ustar wmswms/* * wmslib/src/but/i_snd.c, part of wmslib (Library functions) * Copyright (C) 1994 William Shubert. * See "configure.h.in" for more copyright information. */ #include #if X11_DISP #include #include static uchar butdown[] = { /* * Actual noise: The final click as you slam a pair of scissors * shut. */ 88,93,188,250,62,199,229,69,77,197,111,68,206,217,77,59,198,62, 79,203,216,95,207,188,167,199,35,78,89,159,163,45,155,177,106,47, 159,169,31,170,58,90,45,73,45,216,42,75,58,186,55,120,175,61,69, 191,121,44,181,122,86,64,189,93,74,187,189,100,185,183,239,196}; static uchar butup[] = { /* * Actual noise: The final click as you slam a pair of scissors * shut. * This is a slightly different sample than butdown; more echoish. */ 171,71,87,89,55,224,211,203,66,91,90,53,175,188,70,72,76,76,230, 190,174,56,55,213,79,91,193,216,77,87,202,199,220,95,79,70,58, 187,175,61,172,86,48,189,198,92,96,205,67,78,198,179,56,55,191, 44,207,180,54,186,206,69,180,185,43,187,184,67,195,93,164,208,71, 156,229,163,44,24,156,168,71,23,235,166,144,173,207,149,221,237, 30,49,26}; Snd but_downSnd = snd_define(butdown); Snd but_upSnd = snd_define(butup); #endif /* X11_DISP */ pente-2.2.5/wmslib/src/but/i_win.c0100664000076400007640000003326607331147374015216 0ustar wmswms/* * wmslib/src/but/i_win.c, part of wmslib (Library functions) * Copyright (C) 1994-1997 William Shubert. * See "configure.h.in" for more copyright information. */ #include #ifdef X11_DISP #ifdef STDC_HEADERS #include #include #endif /* STDC_HEADERS */ #include #include #include #include #include #include #include #ifdef HAVE_SYS_SELECT_H #include #endif #include #include #include /********************************************************************** * Forward declarations **********************************************************************/ static ButWin *create(void *packet, ButEnv *env, const char *name, int w, int h, ButWinFunc *resize); /********************************************************************** * Functions **********************************************************************/ ButWin *butWin_iCreate(void *packet, ButEnv *env, const char *name, int w, int h, ButWin **iWin, bool iconic, int iW, int iH, ButWinFunc *unmap, ButWinFunc *map, ButWinFunc *resize, ButWinFunc *iResize, ButWinFunc *destroy) { ButWin *result; result = create(packet, env, name, w, h, resize); result->unmap = unmap; result->map = map; result->destroy = destroy; result->quit = NULL; if (iWin) { *iWin = create(packet, env, name, iW, iH, iResize); (*iWin)->isIcon = TRUE; result->iconWin = *iWin; result->iconic = iconic; butWin_activate(*iWin); } return(result); } ButWin *butWin_rootCreate(void *packet, ButEnv *env) { ButWin *result; int scrn = DefaultScreen(env->dpy); result = create(packet, env, "No Name", DisplayWidth(env->dpy, scrn), DisplayHeight(env->dpy, scrn), NULL); result->unmap = NULL; result->map = NULL; result->destroy = NULL; result->quit = NULL; result->win = RootWindow(env->dpy, scrn); /* VirtualRootWindowOfScreen(DefaultScreenOfDisplay(env->dpy)); */ result->physWin = result->win; result->resized = TRUE; result->mapped = TRUE; XSelectInput(env->dpy, result->win, ExposureMask); butWin_addToTable(result); return(result); } static ButWin *create(void *packet, ButEnv *env, const char *name, int w, int h, ButWinFunc *resize) { ButWin *win; win = wms_malloc(sizeof(ButWin)); MAGIC_SET(win); MAGIC_SET(&win->butsNoDraw); win->parent = NULL; win->parentBut = NULL; win->packet = packet; win->iPacket = NULL; win->win = None; win->physWin = None; win->iconWin = NULL; win->name = name; win->iconic = FALSE; win->isIcon = FALSE; win->x = int_max; win->y = int_max; win->w = win->minW = win->maxW = win->logicalW = w; win->h = win->minH = win->maxH = win->logicalH = h; win->wStep = 1; win->hStep = 1; win->xOff = 0; win->yOff = 0; win->minWRatio = win->minHRatio = win->maxWRatio = win->maxHRatio = 0; win->resized = FALSE; win->resizeNeeded = FALSE; win->redrawReady = TRUE; win->redraws = NULL; win->numRedraws = win->maxRedraws = 0; win->id = 0; win->mapped = FALSE; win->unmap = NULL; win->map = NULL; win->resize = resize; win->destroy = NULL; win->quit = NULL; win->env = env; win->minLayer = 1; win->maxLayer = 0; win->butsNoDraw.buts = NULL; win->butsNoDraw.numButs = 0; win->butsNoDraw.maxButs = 0; win->butsNoDraw.dynamic = TRUE; win->lock = NULL; win->butIn = NULL; win->keyBut = NULL; win->numCols = 0; win->maxCols = 0; win->cols = NULL; return(win); } void butWin_setGeom(ButWin *win, const char *geometry) { char xdir = '+', ydir = '+'; int pcount; int defscr = DefaultScreen(win->env->dpy); assert(MAGIC(win)); if (geometry[0] == '=') ++geometry; if ((geometry[0] == '+') || (geometry[0] == '-')) { pcount = sscanf(geometry, "%c%d%c%d", &xdir, &win->x, &ydir, &win->y); if ((pcount != 4) || ((xdir != '-') && (xdir != '+')) || ((ydir != '-') && (ydir != '+'))) { fprintf(stderr, "Error: Cannot understand geometry \"%s\".\n", geometry); assert(FALSE); exit(1); } } else { pcount = sscanf(geometry, "%dx%d%c%d%c%d", &win->w, &win->h, &xdir, &win->x, &ydir, &win->y); if (((pcount != 2) && (pcount != 6)) || ((xdir != '-') && (xdir != '+')) || ((ydir != '-') && (ydir != '+'))) { fprintf(stderr, "Error: Cannot understand geometry \"%s\".\n", geometry); assert(FALSE); exit(1); } } if (xdir == '-') win->x = DisplayWidth(win->env->dpy, defscr) - win->x - win->w; if (ydir == '-') win->y = DisplayHeight(win->env->dpy, defscr) - win->y - win->h; butWin_checkDims(win); } void butWin_setX(ButWin *win, int x) { assert(MAGIC(win)); win->x = x; butWin_checkDims(win); } void butWin_setY(ButWin *win, int y) { assert(MAGIC(win)); win->y = y; butWin_checkDims(win); } void butWin_setMinW(ButWin *win, int minW) { assert(MAGIC(win)); win->minW = minW; butWin_checkDims(win); } void butWin_setMinH(ButWin *win, int minH) { assert(MAGIC(win)); win->minH = minH; butWin_checkDims(win); } void butWin_setMaxW(ButWin *win, int maxW) { assert(MAGIC(win)); if (maxW == 0) maxW = int_max / 2; win->maxW = maxW; butWin_checkDims(win); } void butWin_setMaxH(ButWin *win, int maxH) { assert(MAGIC(win)); if (maxH == 0) maxH = int_max / 2; win->maxH = maxH; butWin_checkDims(win); } void butWin_setWHRatio(ButWin *win, int w, int h) { assert(MAGIC(win)); win->minWRatio = w; win->maxWRatio = w; win->minHRatio = h; win->maxHRatio = h; butWin_checkDims(win); } void butWin_setWHRatios(ButWin *win, int minW, int minH, int maxW, int maxH) { assert(MAGIC(win)); assert(minW / minH <= maxW / maxH); assert(minH / minW >= maxH / maxW); win->minWRatio = minW; win->minHRatio = minH; win->maxWRatio = maxW; win->maxHRatio = maxH; butWin_checkDims(win); } void butWin_setWStep(ButWin *win, int wStep) { assert(MAGIC(win)); win->wStep = wStep; butWin_checkDims(win); } void butWin_setHStep(ButWin *win, int hStep) { assert(MAGIC(win)); win->hStep = hStep; butWin_checkDims(win); } void butWin_activate(ButWin *win) { ButEnv *env = win->env; Display *dpy = env->dpy; uint hintmask = USSize; int defscr = DefaultScreen(dpy); XSizeHints *sizeHints; XSetWindowAttributes winattr; XWMHints wm_hints; XClassHint class_hints; XTextProperty windowName, iconName; static char *dumb_argv[] = {NULL}; static Atom protocols[1]; /* Stupid X doesn't call their strings const always. */ char *annoyance; char annoy2[] = "Basicwin"; sizeHints = XAllocSizeHints(); if (win->x != int_max) { hintmask |= USPosition; if (win->x + win->w / 2 < 0) win->x = -win->w / 2; if (win->x + win->w / 2 > env->rootW) win->x = env->rootW - win->w/2; if (win->y + win->h / 2 < 0) win->y = -win->h/2; if (win->y + win->h / 2 > env->rootH) win->y = env->rootH - win->h / 2; } winattr.background_pixel = env->colors[BUT_BG]; winattr.event_mask = ExposureMask | StructureNotifyMask; winattr.bit_gravity = NorthWestGravity; if (win->isIcon) { win->win = XCreateWindow(dpy, DefaultRootWindow(dpy), win->x,win->y, win->w, win->h, 0, env->depth, InputOutput, CopyFromParent, CWBackPixel|CWEventMask|CWBitGravity, &winattr); win->physWin = win->win; XSelectInput(dpy, win->win, ExposureMask|StructureNotifyMask); } else { winattr.event_mask |= PointerMotionMask | ButtonPressMask | KeyPressMask | ButtonReleaseMask | KeyReleaseMask | LeaveWindowMask | FocusChangeMask; win->win = XCreateWindow(dpy, RootWindow(dpy, defscr), win->x,win->y, win->w,win->h, 0, env->depth, InputOutput, CopyFromParent, CWBackPixel|CWEventMask|CWBitGravity, &winattr); win->physWin = win->win; sizeHints->flags = PSize | PMinSize | PMaxSize | hintmask; sizeHints->max_width = win->maxW; sizeHints->max_height = win->maxH; sizeHints->min_width = win->minW; sizeHints->min_height = win->minH; if (win->minWRatio != 0) { sizeHints->flags |= PAspect; sizeHints->min_aspect.x = win->minWRatio; sizeHints->min_aspect.y = win->minHRatio; sizeHints->max_aspect.x = win->maxWRatio; sizeHints->max_aspect.y = win->maxHRatio; } if ((win->wStep != 1) || (win->hStep != 1)) { sizeHints->flags |= PResizeInc; sizeHints->width_inc = win->wStep; sizeHints->height_inc = win->hStep; } wm_hints.flags = StateHint | InputHint; if (win->iconWin != None) { wm_hints.flags |= IconWindowHint; wm_hints.icon_window = win->iconWin->win; } annoyance = wms_malloc(strlen(win->name) + 1); strcpy(annoyance, win->name); if (XStringListToTextProperty(&annoyance, 1, &iconName) == 0) { fprintf(stderr, "Cannot allocate icon name.\n"); assert(FALSE); exit(1); } if (XStringListToTextProperty(&annoyance, 1, &windowName) == 0) { fprintf(stderr, "Cannot allocate window name.\n"); exit(1); } wms_free(annoyance); if (win->iconic) wm_hints.initial_state = IconicState; else wm_hints.initial_state = NormalState; wm_hints.input = True; class_hints.res_name = annoyance; class_hints.res_class = annoy2; XSetWMProperties(dpy, win->win, &windowName, &iconName, dumb_argv, 0, sizeHints, &wm_hints, &class_hints); protocols[0] = but_wmDeleteWindow; XSetWMProtocols(dpy, win->win, protocols, 1); XMapWindow(dpy, win->win); } XFree(sizeHints); butWin_addToTable(win); } void butWin_destroy(ButWin *win) { if (but_inEvent) { butWin_dList(win); } else { while (butWin_delete(win) == BUTOUT_STILLBUTS); } } ButOut butWin_delete(ButWin *win) { ButEnv *env = win->env; ButOut result = 0; int i, j; ButSet bset; assert(MAGIC(win)); if (win->destroy != NULL) { /* * This must be done before killing the buttons in case the user wants * to read some buttons before they go away. */ result |= win->destroy(win); win->destroy = NULL; } butWin_findButSetInRegion(win, int_min/2,int_min/2, int_max,int_max, &bset); but_inEvent = TRUE; if ((bset.numButs != 0) || (win->butsNoDraw.numButs != 0)) { for (i = 0; i < bset.numButs; ++i) { but_destroy(bset.buts[i]); } for (i = 0; i < win->butsNoDraw.numButs; ++i) { but_destroy(win->butsNoDraw.buts[i]); } butSet_destroy(&bset); win->butsNoDraw.numButs = 0; return(BUTOUT_STILLBUTS); } if (win->parent) butCan_winDead(win); but_inEvent = FALSE; butSet_destroy(&bset); butSet_destroy(&win->butsNoDraw); /* Remove all timers from the timer list. */ /* Clear out the table. */ /* Since there can be no buttons left, you can easily wms_free the table. */ for (i = 0; i < win->numCols; ++i) { assert(MAGIC(&win->cols[i])); MAGIC_UNSET(&win->cols[i]); for (j = 0; j < win->cols[i].numRows; ++j) { assert(MAGIC(&win->cols[i].rows[j])); MAGIC_UNSET(&win->cols[i].rows[j]); if (win->cols[i].rows[j].buts != NULL) wms_free(win->cols[i].rows[j].buts); } wms_free(win->cols[i].rows); } wms_free(win->cols); if (env->curwin == win->win) env->curwin = None; if (win->parent) XFreePixmap(env->dpy, win->win); else XDestroyWindow(env->dpy, win->win); if (env->last_mwin == win) env->last_mwin = NULL; butWin_rmFromTable(win); MAGIC_UNSET(&win->butsNoDraw); MAGIC_UNSET(win); wms_free(win); return(result); } /* * Should only be called by a fixed size window. */ void butWin_resize(ButWin *win, int newW, int newH) { XSizeHints *sizeHints; win->minW = win->maxW = newW; win->minH = win->maxH = newH; sizeHints = XAllocSizeHints(); sizeHints->flags = PMaxSize | PMinSize | PSize; sizeHints->max_width = sizeHints->min_width = sizeHints->width = newW; sizeHints->max_height = sizeHints->min_height = sizeHints->height = newH; XSetWMNormalHints(win->env->dpy, win->win, sizeHints); XFree(sizeHints); XResizeWindow(win->env->dpy, win->win, newW, newH); } /* * Some window managers (like eXceed/NT) ignore the ratio parts of * a window. This could break some programs, so here we just ignore * parts of a window if that's the case. It's ugly, but hey, get * a real window manager. */ void butWin_checkDims(ButWin *win) { if (win->w > win->env->rootW) win->w = win->env->rootW; if (win->h > win->env->rootH) win->h = win->env->rootH; if (win->w < win->minW) win->w = win->minW; if (win->w > win->maxW) win->w = win->maxW; if (win->h < win->minH) win->h = win->minH; if (win->h > win->maxH) win->h = win->maxH; win->w -= ((win->w - win->minW) % win->wStep); win->h -= ((win->h - win->minH) % win->hStep); if (win->minWRatio) { if ((win->w + 1) * win->minHRatio - 1 < win->h * win->minWRatio) win->w = (win->h * win->minWRatio) / win->minHRatio; if ((win->h + 1) * win->maxWRatio - 1 < win->w * win->maxHRatio) win->h = (win->w * win->maxHRatio) / win->maxWRatio; } } ButColor butColor_create(int r, int g, int b, int grey) { ButColor result; result.red = (65535L * r + 127) / 255; result.green = (65535L * g + 127) / 255; result.blue = (65535L * b + 127) / 255; result.greyLevel = grey; return(result); } ButColor butColor_mix(ButColor c1, int r1, ButColor c2, int r2) { ButColor res; res.red = ((c1.red * r1) + (c2.red * r2) + (r1 + r2) / 2) / (r1 + r2); res.green = ((c1.green * r1) + (c2.green * r2) + (r1 + r2) / 2) / (r1 + r2); res.blue = ((c1.blue * r1) + (c2.blue * r2) + (r1 + r2) / 2) / (r1 + r2); res.greyLevel = c1.greyLevel; return(res); } #endif /* X11_DISP */ pente-2.2.5/wmslib/src/but/menu.c0100664000076400007640000004615107045637750015056 0ustar wmswms/* * wmslib/src/but/menu.c, part of wmslib (Library functions) * Copyright (C) 1994-1997 William Shubert. * See "configure.h.in" for more copyright information. * * Known problems: * The first and last options MUST be text, not a divider. */ #include #ifdef X11_DISP #ifdef STDC_HEADERS #include #include #endif /* STDC_HEADERS */ #include #include #include #include #include #include #include #ifdef HAVE_SYS_SELECT_H #include #endif #include #include #include #include #include #include #include #include /********************************************************************** * Data structures **********************************************************************/ typedef struct Ol_struct { /* Option List */ Str text; int x,y,w,h; uint flags; } Ol; typedef struct menu_struct { int fgpic, bgpic; int cval, nvals, nbreaks, tval, xoff; int last_w, llayer; bool active, up, skip_clicks; bool menu_was_twitched; bool clickOpen; /* TRUE if it's open because of a click. */ Time pressTime; const char *title; Ol *options; But *child, *parent; ButOut (*callback)(But *but, int value); } Menu; /********************************************************************** * Forward Declarations **********************************************************************/ static int menu_width(But *but); static ButOut smmove(But *but, int x, int y); static ButOut smleave(But *but); static ButOut smpress(But *but, int butnum, int x, int y); static void sdraw(But *but, int x,int y, int w,int h); static ButOut sdestroy(But *but); static void snewflags(But *but, uint flags); static But *lcreate(But *smenu, bool local); static ButOut lmmove(But *but, int x, int y); static ButOut lmleave(But *but); static ButOut lmpress(But *but, int butnum, int x, int y); static ButOut lmrelease(But *but, int butnum, int x, int y); static void ldraw(But *but, int x,int y, int w,int h); static ButOut ldestroy(But *but); static void lnewflags(But *but, uint flags); static ButOut netMsg(But *but, void *msg, int msgLen); static But *create(ButOut (*func)(But *but, int value), void *packet, ButWin *win, int layer, int toplayer, int flags, const char *title, const char *optlist[], int cur_opt, bool up); /********************************************************************** * Globals **********************************************************************/ static const ButAction saction = { smmove, smleave, smpress, NULL, NULL, NULL, sdraw, sdestroy, snewflags, netMsg}; static const ButAction laction = { lmmove, lmleave, lmpress, lmrelease, NULL, NULL, ldraw, ldestroy, lnewflags, NULL}; char butMenu_dummy = '\0'; /********************************************************************** * Functions **********************************************************************/ But *butMenu_upCreate(ButOut (*func)(But *but, int value), void *packet, ButWin *win, int layer, int toplayer, int flags, const char *title, const char *optlist[], int cur_opt) { return(create(func, packet, win, layer, toplayer, flags, title, optlist, cur_opt, TRUE)); } But *butMenu_downCreate(ButOut (*func)(But *but, int value), void *packet, ButWin *win, int layer, int toplayer, int flags, const char *title, const char *optlist[], int cur_opt) { return(create(func, packet, win, layer, toplayer, flags, title, optlist, cur_opt, FALSE)); } static But *create(ButOut (*callback)(But *but, int value), void *packet, ButWin *win, int layer, int toplayer, int flags, const char *title, const char *optlist[], int cur_opt, bool up) { Menu *m; But *but; int i; m = wms_malloc(sizeof(Menu)); but = but_create(win, m, &saction); but->uPacket = packet; but->layer = layer; but->flags = flags | BUT_OPAQUE; m->callback = callback; m->fgpic = BUT_FG; m->bgpic = BUT_BG; m->cval = cur_opt; m->nbreaks = 0; for (i = 0; optlist[i] != BUTMENU_OLEND; ++i) if (optlist[i] == BUTMENU_OLBREAK) ++m->nbreaks; m->nvals = i; m->options = wms_malloc((i+1) * sizeof(Ol)); i = 0; do { if (optlist[i] == BUTMENU_OLBREAK) { str_init(&m->options[i].text); m->options[i].flags = BUTMENU_BREAK; } else if (optlist[i] == BUTMENU_OLEND) { str_init(&m->options[i].text); m->options[i].flags = BUTMENU_END; } else { str_initChars(&m->options[i].text, optlist[i]); m->options[i].flags = 0; } } while (optlist[i++] != BUTMENU_OLEND); m->llayer = toplayer; m->tval = 0; m->active = FALSE; m->up = up; m->menu_was_twitched = FALSE; m->title = title; m->last_w = 0; m->child = NULL; m->parent = but; but_init(but); return(but); } void butMenu_setText(But *but, const char *title, const char *optlist[], int newopt) { Menu *m = but->iPacket; int i; if (title == NULL) title = m->title; m->title = title; m->nbreaks = 0; for (i = 0; optlist[i] != BUTMENU_OLEND; ++i) if (optlist[i] == BUTMENU_OLBREAK) ++m->nbreaks; m->nvals = i; wms_free(m->options); m->options = wms_malloc((i+1) * sizeof(Ol)); i = 0; do { if (optlist[i] == BUTMENU_OLBREAK) { str_init(&m->options[i].text); m->options[i].flags = BUTMENU_BREAK; } else if (optlist[i] == BUTMENU_OLEND) { str_init(&m->options[i].text); m->options[i].flags = BUTMENU_END; } else { str_initChars(&m->options[i].text, optlist[i]); m->options[i].flags = 0; } } while (optlist[i++] != BUTMENU_OLEND); if (newopt != BUT_NOCHANGE) m->cval = newopt; but_draw(but); } void butMenu_setFlags(But *but, int optnum, uint flags) { Menu *m = but->iPacket; m->options[optnum].flags = flags; but_draw(but); } /* Cannot be called when the menu is open. */ void butMenu_set(But *but, int new_opt) { Menu *m = but->iPacket; assert(but->action == &saction); m->cval = new_opt; but_draw(but); } int butMenu_get(But *but) { Menu *m = but->iPacket; return(m->cval); } void butMenu_setColor(But *but, int fg, int bg) { Menu *m = but->iPacket; assert(but->action == &saction); m->fgpic = fg; m->bgpic = bg; but_draw(but); } static ButOut smmove(But *but, int x, int y) { ButOut retval = BUTOUT_CAUGHT; int newflags = but->flags; int butbw = but->win->env->stdButBw; if ((x >= but->x + butbw) && (x < but->x + but->w - butbw) && (y >= but->y + butbw) && (y < but->y + but->h - butbw)) { newflags |= BUT_TWITCHED; } else { newflags &= ~BUT_TWITCHED; if (!newflags & BUT_LOCKED) retval &= ~BUTOUT_CAUGHT; } if (!(but->flags & BUT_TWITCHED) && (newflags & BUT_TWITCHED)) butEnv_setCursor(but->win->env, but, butCur_twitch); else if ((but->flags & BUT_TWITCHED) && !(newflags & BUT_TWITCHED)) butEnv_setCursor(but->win->env, but, butCur_idle); if (newflags != but->flags) but_newFlags(but, newflags); return(retval); } static ButOut smleave(But *but) { int newflags = but->flags; newflags &= ~BUT_TWITCHED; if ((but->flags & BUT_TWITCHED) && !(newflags & BUT_TWITCHED)) butEnv_setCursor(but->win->env, but, butCur_idle); if (newflags != but->flags) but_newFlags(but, newflags); return(BUTOUT_CAUGHT); } static ButOut smpress(But *but, int butnum, int x, int y) { ButOut retval = BUTOUT_CAUGHT; int newflags = but->flags; Menu *m = but->iPacket; if (!(newflags & BUT_TWITCHED)) retval &= ~BUTOUT_CAUGHT; else { if (butnum == 1) { newflags |= BUT_PRESSED; m->pressTime = but->win->env->eventTime; } else retval |= BUTOUT_ERR; } if (newflags != but->flags) but_newFlags(but, newflags); return(retval); } static void sdraw(But *but, int x,int y, int w,int h) { ButWin *win = but->win; Menu *m = but->iPacket; uint flags = but->flags; int bwdiff, sbw, bbw; if (m->child == NULL) { bbw = win->env->stdButBw; if (bbw == 0) bbw = 1; sbw = (bbw + 1) / 2; bwdiff = bbw - sbw; but_drawBox(win, but->x, but->y, but->w, but->h, 0, bwdiff, BUT_SLEFT|BUT_SRIGHT, BUT_LIT, BUT_SHAD, None, None); but_drawCt(win, flags, m->fgpic, m->bgpic, BUT_PBG, but->x+bwdiff, but->y+bwdiff, but->w-2*bwdiff, but->h/2 - bwdiff, sbw, m->title, BUT_SLEFT|BUT_SRIGHT, 0); but_drawCt(win, flags, BUT_FG,BUT_BG,BUT_PBG, but->x+bwdiff, but->y + but->h/2, but->w-2*bwdiff, but->h - but->h/2 - bwdiff, sbw, str_chars(&m->options[m->cval].text), BUT_SLEFT|BUT_SRIGHT, 0); } } static ButOut sdestroy(But *but) { Menu *m = but->iPacket; int i; if (m->child != NULL) but_destroy(m->child); for (i = 0; i <= m->nvals; ++i) { str_deinit(&m->options[i].text); } wms_free(m->options); wms_free(but->iPacket); return(0); } static void snewflags(But *but, uint flags) { Menu *m = but->iPacket; bool local; if (flags & (BUT_PRESSED|BUT_NETPRESS)) { if (m->child == NULL) { local = flags & BUT_PRESSED; but->flags = flags & ~(BUT_PRESSED|BUT_NETPRESS); m->child = lcreate(but, local); } } else { but->flags = flags; } } /* * If local is TRUE, then make the popup unpressable. */ static But *lcreate(But *smenu, bool local) { But *but; Menu *m = smenu->iPacket; int sh, i, x,y, w,h; ButWin *win = smenu->win; ButEnv *env = win->env; int butbw = env->stdButBw; h = (m->nvals - m->nbreaks) * (sh = (env->font0h + butbw * 2)) + butbw * 3 + smenu->h / 2 + m->nbreaks * ((butbw & ~1) + butbw); but = but_create(win, m, &laction); but->uPacket = smenu->uPacket; but->layer = m->llayer; but->x = smenu->x; but->y = smenu->y; if (m->up) but->y += smenu->h - h; but->w = smenu->w; but->h = h; but->flags = BUT_DRAWABLE | BUT_OPAQUE; if (local) but->flags |= BUT_PRESSABLE | BUT_PRESSED | BUT_LOCKED | BUT_TWITCHED; but->keys = NULL; x = but->x + env->stdButBw; y = but->y + m->parent->h/2 + 2*butbw; w = but->w - 2*env->stdButBw; h = env->font0h + env->stdButBw; for (i = 0; i < m->nvals; ++i) { if (m->options[i].flags & BUTMENU_BREAK) { y += (env->stdButBw & ~1) + env->stdButBw; } else { m->options[i].x = x; m->options[i].y = y; m->options[i].w = w; m->options[i].h = h; y += env->font0h + env->stdButBw * 2; } } m->tval = m->cval; m->last_w = 0; m->clickOpen = FALSE; if (local) { x = but->x + but->w/2; y = m->options[m->cval].y - butbw + sh/2; while (win->parent != NULL) { x += win->xOff; y += win->yOff; win = win->parent; } XWarpPointer(env->dpy, None, win->win, 0,0,0,0, x, y); } m->skip_clicks = TRUE; but_init(but); snd_play(&butMenu_openSnd); return(but); } static ButOut lmmove(But *but, int x, int y) { ButOut result = 0; int msel, m_y, newflags = but->flags, otval; Menu *m = but->iPacket; ButEnv *env = but->win->env; int butbw = env->stdButBw; bool click = TRUE; StdInt32 netNewVal; if (m->skip_clicks) { click = FALSE; } if (but->flags & BUT_PRESSED) result |= BUTOUT_CAUGHT; for (msel = 0; msel < m->nvals; ++msel) { if (!(m->options[msel].flags & BUTMENU_BREAK)) { m_y = m->options[msel].y - butbw; if ((y > m_y + butbw / 2) && (y <= m_y + butbw / 2 + 2*butbw + env->font0h)) break; } } if (msel < m->nvals) { if (msel == m->cval) m->skip_clicks = FALSE; if (m->options[msel].flags & BUTMENU_DISABLED) msel = m->nvals; } if (msel == m->nvals) newflags &= ~BUT_TWITCHED; else newflags |= BUT_TWITCHED; if (msel != m->tval) { if (m->parent->id >= 0) { netNewVal = int_stdInt32(msel); butRnet_butSpecSend(m->parent, &netNewVal, sizeof(netNewVal)); } otval = m->tval; m->tval = msel; if (((newflags ^ but->flags) & ~BUT_TWITCHED) == 0) { /* Otherwise, it will be drawn by the setflags call. */ if (otval != m->nvals) { butWin_redraw(but->win, m->options[otval].x,m->options[otval].y-butbw, m->options[otval].w,m->options[otval].h+butbw*2); } if (msel != m->nvals) { butWin_redraw(but->win, m->options[msel].x,m->options[msel].y-butbw, m->options[msel].w,m->options[msel].h+butbw*2); } } if (click) snd_play(&but_downSnd); } if (newflags != but->flags) but_newFlags(but, newflags); return(result); } static ButOut lmleave(But *but) { Menu *m = but->iPacket; StdInt32 msg; if (m->parent->id >= 0) { msg = int_stdInt32(-1); butRnet_butSpecSend(m->parent, &msg, sizeof(msg)); } but_destroy(but); snd_play(&butMenu_closeSnd); return(BUTOUT_CAUGHT); } static ButOut lmpress(But *but, int butnum, int x, int y) { Menu *m = but->iPacket; if (m->clickOpen) { m->clickOpen = FALSE; snd_play(&but_upSnd); return(BUTOUT_CAUGHT); } else return(BUTOUT_CAUGHT | BUTOUT_ERR); } static ButOut lmrelease(But *but, int butnum, int x, int y) { int result = BUTOUT_CAUGHT; Menu *m = but->iPacket; StdInt32 msg; if (but->flags & BUT_PRESSABLE) { if (m->pressTime + BUT_DCLICK > but->win->env->eventTime) { /* Open this with a click. */ m->clickOpen = TRUE; return(BUTOUT_CAUGHT); } if (m->parent->id >= 0) { msg = int_stdInt32(-1); butRnet_butSpecSend(m->parent, &msg, sizeof(msg)); } } but_destroy(but); if (m->tval == m->nvals) { result |= BUTOUT_ERR; } else { m->cval = m->tval; if (m->callback != NULL) result |= m->callback(m->parent, m->cval); } snd_play(&butMenu_closeSnd); return(result); } static void ldraw(But *but, int x,int y, int w,int h) { Menu *m = but->iPacket; ButWin *win = but->win; ButEnv *env = win->env; But *sbut = m->parent; int tx, ty, tw, th, i; uint butbw = env->stdButBw; int new_y, old_y; if (butbw == 0) butbw = 1; /* If it resizes, you must recalculate how far into the button you should * start drawing the options. Start with last_w set to 0 to force * this to happen on the first redraw. */ if (m->last_w != but->w) { m->last_w = but->w; m->xoff = (but->w - menu_width(but)) / 2; } /* Draw the title. */ tw = sbut->w; th = sbut->h / 2; /* Don't forget: sbut is two boxes high! */ if (y < m->options[0].y) { but_drawCt(but->win, BUT_PRESSABLE, m->fgpic, m->bgpic, 0, but->x, but->y, tw, th, butbw, m->title, BUT_SLEFT|BUT_SRIGHT, 0); } /* The box around the options. */ if ((y < m->options[0].y-butbw) || (y+h > m->options[m->nvals-1].y + m->options[m->nvals-1].h+butbw) || (x < m->options[0].x-butbw) || (x > m->options[0].x + m->options[0].w+butbw)) { but_drawBox(win, but->x, but->y + th, but->w, but->h - th, 0, (butbw+1)/2, BUT_SLEFT|BUT_SRIGHT, BUT_LIT, BUT_SHAD, None, None); } new_y = but->y + th + butbw; /* Top of the current selection. */ old_y = but->y + th + (butbw+1) / 2; /* Fill in the background for the options. */ butEnv_setXFg(env, BUT_BG); XFillRectangle(env->dpy, win->win, env->gc, but->x + butbw - win->xOff, new_y - win->yOff, but->w - butbw * 2, but->y + but->h - new_y - butbw); for (i = 0; i <= m->nvals; ++i) { if (m->options[i].flags & (BUTMENU_BREAK | BUTMENU_END)) { /* Draw the inner box around a group of options. */ tx = but->x + (butbw+1)/2; ty = old_y; tw = but->w - ((butbw+1) & ~1); th = new_y - old_y + butbw + (butbw / 2); if ((ty < y+h) && (ty+th >= y) && ((ty+butbw/2 > y) || (ty+th-butbw/2 < y+h) || (tx+butbw/2 > x) || (tx+tw-butbw/2 < x+w))) but_drawBox(win, tx,ty, tw,th, 0, butbw / 2, BUT_SLEFT|BUT_SRIGHT, BUT_LIT, BUT_SHAD, None, None); old_y = new_y + butbw + butbw/2; new_y += (butbw & ~1) + butbw; } else { /* Draw the text for this option. */ /* If it's selected, highlight behind it. */ if (i == m->tval) { if ((m->options[i].y-butbw <= y+h) && (m->options[i].y+m->options[i].h+butbw > y)) { but_drawBox(win, but->x + butbw, new_y, but->w - 2*butbw, env->font0h + 3*butbw, 0, butbw, BUT_SLEFT|BUT_SRIGHT, BUT_LIT, BUT_SHAD, None, None); butEnv_setXFg(env, BUT_HIBG); XFillRectangle(env->dpy, win->win, env->gc, but->x + 2*butbw - win->xOff, new_y + butbw - win->yOff, but->w - 4*butbw, env->font0h + butbw); } } if ((m->options[i].y <= y+h) && (m->options[i].y+m->options[i].h > y)) { if (m->options[i].flags & BUTMENU_DISABLED) { XSetFillStyle(env->dpy, env->gc, FillStippled); XSetForeground(env->dpy, env->gc, env->colors[BUT_FG]); } else butEnv_setXFg(env, BUT_FG); butWin_write(win, but->x + m->xoff, m->options[i].y + butbw/2, str_chars(&m->options[i].text), 0); if (m->options[i].flags & BUTMENU_DISABLED) { butEnv_stdFill(env); } } new_y += env->font0h + butbw*2; } } } static ButOut ldestroy(But *but) { ButWin *win = but->win; ButEnv *env = win->env; Menu *m = but->iPacket; But *sbut = m->parent; int x, y; int minX, minY; minX = but->x; minY = but->y; x = sbut->x + sbut->w/2; y = sbut->y + sbut->h/2; while (win->parent != NULL) { minX += win->xOff; x += win->xOff; minY += win->yOff; y += win->yOff; win = win->parent; } XWarpPointer(env->dpy, win->win, win->win, minX, minY, but->w, but->h, x, y); m->child = NULL; return(0); } static void lnewflags(But *but, uint flags) { uint ofl = but->flags; but->flags = flags; if (((flags ^ ofl) & ~BUT_TWITCHED) != 0) but_draw(but); } static int menu_width(But *but) { Menu *m = but->iPacket; ButEnv *env = but->win->env; int i, maxw, tw; maxw = butEnv_textWidth(env, m->title, 0); for (i = 0; !(m->options[i].flags & BUTMENU_END); ++i) { if (!(m->options[i].flags & BUTMENU_BREAK)) { tw = butEnv_textWidth(env, str_chars(&m->options[i].text), 0); if (tw > maxw) maxw = tw; } } return(maxw); } static ButOut netMsg(But *but, void *msg, int msgLen) { StdInt32 *i = msg; int msgVal = stdInt32_int(*i); int ctval, butbw = butEnv_stdBw(but->win->env); Menu *m = but->iPacket; ButOut result = 0; assert(msgLen == sizeof(StdInt32)); if (msgVal < 0) result |= lmrelease(m->child, 0,0,0); else { snd_play(&but_downSnd); ctval = m->tval; m->tval = msgVal; if (ctval != m->nvals) { butWin_redraw(but->win, m->options[ctval].x, m->options[ctval].y-butbw, m->options[ctval].w,m->options[ctval].h+butbw*2); } if (msgVal != m->nvals) { butWin_redraw(but->win, m->options[msgVal].x, m->options[msgVal].y-butbw, m->options[msgVal].w, m->options[msgVal].h+butbw*2); } } return(result); } void butMenu_setOptionName(But *but, const char *new, int entryNum) { Menu *m; assert(but->action == &saction); m = but->iPacket; assert(entryNum < m->nvals); str_copyChars(&m->options[entryNum].text, new); if (entryNum == m->cval) but_draw(but); } #endif pente-2.2.5/wmslib/src/but/menu_snd.c0100664000076400007640000002126107045637750015715 0ustar wmswms/* * wmslib/src/but/menu_snd.c, part of wmslib (Library functions) * Copyright (C) 1994 William Shubert. * See "configure.h.in" for more copyright information. */ #include #if X11_DISP #include #include #include static uchar openmenu[] = { /* * Actual noise: "Twanging" a rubber band stretched across my * hole puncher. */ 101,97,104,92,79,70,53,55,89,32,21,35,32,44,47,57,72,83,229,196, 146,136,150,140,139,145,150,158,164,175,190,235,74,59,51,47,45, 44,43,43,43,44,45,47,49,53,56,36,31,180,101,222,193,211,210,45, 29,14,19,12,22,31,35,109,191,200,220,175,176,169,169,167,166,166, 166,167,168,167,142,128,133,139,142,151,156,167,177,206,80,58,47, 43,40,31,12,3,5,6,10,14,21,25,30,41,50,73,238,195,185,178,174, 163,137,128,133,137,141,146,152,159,168,180,197,102,68,57,50,42, 34,47,46,43,47,44,48,48,52,55,59,47,24,16,18,15,14,17,25,32,44, 62,125,191,180,173,169,166,160,140,129,137,159,178,159,147,140, 142,151,161,34,21,44,168,162,184,185,223,95,70,60,56,52,51,49,50, 50,51,53,52,31,17,15,13,15,25,60,161,146,143,149,150,154,156,159, 163,167,171,174,179,184,189,195,201,207,214,221,227,233,235,235, 233,229,227,45,12,7,11,15,24,30,41,54,84,203,185,167,143,137,146, 175,67,225,207,166,144,141,139,139,142,158,43,17,13,17,20,32,169, 149,143,151,156,161,172,178,197,219,82,68,60,56,45,24,16,16,15, 21,29,58,176,158,154,158,159,163,167,170,174,184,202,223,79,81, 240,185,176,186,186,189,191,194,202,33,7,8,14,18,27,32,45,204, 149,141,142,167,36,59,64,79,220,213,193,175,156,157,165,176,88, 68,69,74,75,77,78,105,165,147,142,138,142,150,155,166,175,198,97, 57,24,10,10,10,13,22,39,174,157,159,165,169,173,178,185,190,198, 206,217,232,93,51,45,49,46,52,55,62,82,193,172,169,172,173,175, 194,21,6,13,17,24,31,40,56,231,155,143,149,172,53,222,215,203, 189,183,157,153,157,162,188,75,53,56,59,60,64,213,173,172,161, 154,151,148,147,150,158,167,179,202,91,53,26,14,12,11,15,20,28, 48,190,162,158,167,172,176,188,208,91,78,67,57,49,51,59,76,234, 204,194,187,175,168,163,161,166,179,73,27,10,12,17,22,29,36,47, 206,157,156,157,179,69,78,96,208,174,155,155,156,160,175,218,50, 43,45,49,86,172,166,159,156,157,158,165,168,170,170,171,175,187, 236,60,45,34,27,23,21,22,24,28,36,55,207,185,179,177,179,180,186, 196,205,218,237,110,107,222,196,186,185,179,174,173,173,174,179, 189,210,56,34,22,12,13,20,25,31,46,176,163,165,164,183,201,187, 179,174,170,167,166,168,173,185,209,89,76,77,110,200,182,175,172, 170,170,170,171,174,174,177,183,186,191,207,91,58,45,40,36,32,29, 29,33,41,47,55,66,95,208,201,204,206,207,205,202,200,196,194,191, 189,187,182,178,176,180,187,206,94,71,53,40,30,24,21,22,30,44,87, 184,173,170,171,172,175,181,181,180,183,181,178,179,184,191,208, 244,107,121,225,203,193,187,184,185,184,183,182,181,182,184,189, 196,205,231,77,56,45,41,38,37,38,41,47,58,69,78,90,239,216,211, 208,207,206,206,203,202,203,199,195,193,191,188,188,192,205,124, 78,67,53,39,33,30,30,34,41,56,101,189,177,173,173,174,176,179, 184,189,191,196,199,198,195,192,193,197,203,210,222,234,232,230, 220,214,211,203,196,191,188,187,188,191,199,214,106,73,58,49,45, 43,44,46,52,61,74,94,237,218,212,206,204,205,206,206,206,208,210, 209,206,204,201,196,192,191,191,198,218,88,61,50,39,30,30,32,40, 51,79,201,183,176,176,179,184,189,196,203,206,207,207,207,202, 194,191,190,193,198,201,203,206,208,212,214,218,221,221,218,208, 205,200,193,192,197,207,124,76,61,53,47,46,47,54,61,73,91,242, 218,209,206,206,205,205,208,211,214,214,215,218,217,219,216,212, 207,203,204,205,219,96,72,57,44,35,30,31,38,48,72,206,185,178, 176,178,184,189,197,205,208,211,207,205,199,192,191,191,193,196, 200,204,209,212,217,222,222,231,228,220,214,205,200,195,191,191, 198,213,99,72,60,55,53,53,57,64,75,83,90,97,102,109,254,254,249, 242,234,229,223,219,215,212,208,206,204,203,203,205,213,223,114, 79,65,56,45,37,34,38,45,59,101,197,184,179,179,182,186,191,199, 205,207,206,205,202,198,197,195,196,197,199,202,205,215,230,111, 93,86,85,90,105,235,211,199,191,186,186,190,203,250,76,62,57,56, 59,64,75,83,89,95,95,90,85,85,87,91,99,120,237,228,226,225,221, 215,209,208,206,205,209,220,110,78,65,58,49,42,40,42,46,59,79, 207,189,182,179,180,183,188,194,202,206,209,212,211,206,204,201, 199,198,198,200,203,210,224,254,97,91,87,83,83,87,101,236,213, 202,195,194,201,217,109,77,65,61,61,64,73,84,96,105,103,103,96, 95,97,105,120,244,231,223,222,220,219,216,213,212,208,211,220, 235,92,73,62,56,50,44,44,46,53,65,91,213,194,187,184,183,185,188, 191,199,204,207,213,215,215,214,211,207,206,207,210,216,223,236, 121,101,91,86,87,94,125,220,205,195,190,188,189,192,204,242,85, 72,64,62,63,67,72,78,88,95,104,117,109,106,114,123,117,123,255, 120,109,106,108,110,119,237,227,233,246,97,77,66,59,54,48,49,55, 62,78,245,206,194,187,185,186,188,191,195,200,204,206,215,231, 242,236,225,218,213,212,214,218,222,231,252,104,92,87,90,95,114, 225,206,198,191,190,190,195,206,247,84,72,66,66,69,74,79,89,95, 101,100,95,94,96,101,108,113,109,105,99,94,92,92,95,103,116,122, 116,101,86,75,67,61,58,56,58,63,75,95,223,207,199,193,190,189, 189,190,193,197,200,203,207,217,226,237,251,247,243,236,232,230, 227,230,245,110,95,92,94,109,234,214,204,200,198,197,201,210,235, 94,78,71,68,69,72,76,83,90,103,122,242,238,237,236,238,239,238, 238,237,247,115,104,96,94,99,103,104,100,90,82,75,69,63,61,62,66, 74,89,252,223,215,208,203,199,196,196,198,200,201,204,211,219, 224,229,234,235,231,233,234,231,227,223,224,229,245,102,94,94, 102,248}; static uchar closemenu[] = { /* * Actual sound: Me clicking my tongue. I don't really like this * noise but I can't find a better one within my wage slave * cubicle and if I leave to record a good noise my boss might * see me. */ 214,102,73,59,51,47,44,42,42,43,44,47,52,61,81,218,191,182,176, 175,174,175,177,181,187,194,202,215,224,231,223,209,200,193,190, 188,188,186,181,180,181,185,195,219,90,65,55,47,45,44,43,43,43, 46,52,68,243,192,177,172,170,169,172,182,205,77,52,41,34,30,29, 30,34,41,54,103,188,173,167,164,162,162,162,164,166,170,172,175, 175,179,189,217,76,59,52,49,49,47,44,38,32,30,30,32,40,49,67,110, 199,185,176,171,167,166,168,173,184,205,94,72,66,62,60,57,54,54, 58,70,117,201,188,186,188,192,195,193,189,185,184,184,185,187, 190,188,187,184,180,177,175,175,174,175,176,183,204,72,44,31,25, 21,18,18,19,21,25,29,36,47,76,197,178,172,169,167,168,168,168, 168,169,170,171,174,175,178,177,175,175,175,177,183,188,198,211, 225,122,99,87,73,63,60,58,60,62,62,61,60,57,55,55,57,61,68,78,79, 76,71,70,77,105,206,191,186,183,183,184,186,190,199,204,215,249, 94,90,120,212,199,190,189,191,196,203,208,208,206,207,218,118,86, 73,66,59,55,52,47,45,43,41,40,40,39,39,40,41,44,49,60,91,203,184, 174,167,160,157,156,159,168,179,192,197,189,177,174,179,221,56, 44,44,55,73,62,43,31,41,175,144,144,144,152,144,153,18,18,18,145, 144,144,151,31,18,18,18,72,153,193,32,144,144,174,18,18,39,151, 195,172,144,144,160,18,18,163,158,34,150,144,144,178,18,18,41,37, 18,36,144,144,144,18,18,18,18,21,235,144,144,144,18,18,22,18,22, 168,144,144,144,95,25,18,18,18,42,144,144,163,152,59,18,18,18,25, 147,153,144,144,167,18,18,19,23,29,148,144,144,186,27,26,18,18, 18,152,144,158,145,155,22,18,18,35,41,175,144,144,159,47,43,18, 18,25,158,151,153,144,148,42,20,29,34,45,157,144,146,163,195,26, 18,18,20,32,182,144,144,145,153,172,48,43,74,201,170,157,168,62, 29,18,18,18,18,26,126,167,172,164,189,62,76,237,166,150,144,144, 144,149,172,73,43,34,47,68,214,189,102,46,28,22,17,21,30,43,217, 188,192,220,49,41,38,43,79,181,162,158,160,170,189,84,60,78,194, 172,164,162,168,188,62,31,18,192,154,29,144,22,144,31,41,175,18, 156,18,144,29,145,197,177,174,41,162,31,151,52,147,194,157,206, 67,57,36,104,34,187,35,186,26,32,47,60,68,29,203,105,189,87,88, 78,38,47,43,97,73,169,171,161,173,171,193,239,103,80,195,203,177, 189,189,76,63,45,47,46,58,87,217,191,206,222,63,58,48,57,69,209, 187,178,180,189,216,77,66,59,68,86,210,196,186,185,185,188,189, 184,176,172,169,167,169,175,194,106,63,56,55,62,78,119,116,75,56, 44,36,31,30,31,36,42,51,60,79,107,223,200,187,176,172,166,162, 159,160,163,167,173,177,186,191,204,242,78,59,47,40,33,30,30,31, 35,41,47,57,69,90,221,202,191,184,178,175,174,175,178,183,191, 206,243,107,255,222,213,205,202,202,205,212,213,217,213,205,198, 194,192,193,198,207,220,232,225,211,203,198,200,209,121,78,63,57, 54,52,51,52,56,60,65,74,76,78,81,88,116,219,205,202,201,202,207, 219,239,105,87,78,78,82,84,88,88,80,77,76,76,79,93,234,209,201, 194,189,186,184,185,188,190,190,190,190,191,191,193,197,204,219, 229,241,123,95,79,72,68,64,60,56}; Snd butMenu_openSnd = snd_define(openmenu); Snd butMenu_closeSnd = snd_define(closemenu); #endif /* X11_DISP */ pente-2.2.5/wmslib/src/but/plain.c0100664000076400007640000001475007045637750015215 0ustar wmswms/* * wmslib/src/but/plain.c, part of wmslib (Library functions) * Copyright (C) 1994-1995 William Shubert. * See "configure.h.in" for more copyright information. * * File for "plain" buttons...pixmaps, solid colors, etc. */ #include #ifdef X11_DISP #ifdef STDC_HEADERS #include #include #endif /* STDC_HEADERS */ #include #include #include #include #include #include #include #ifdef HAVE_SYS_SELECT_H #include #endif #include #include #include static void pix_draw(But *but, int x, int y, int w, int h); static void plain_draw(But *but, int x, int y, int w, int h); static void dummy_draw(But *but, int x, int y, int w, int h); static void keytrap_draw(But *but, int x, int y, int w, int h); static ButOut pixmap_destroy(But *but); static ButOut plain_destroy(But *but); static ButOut dummy_destroy(But *but); static ButOut keytrap_destroy(But *but); static ButOut plain_mmove(But *but, int x, int y); static ButOut keytrap_kpress(But *but, const char *keystr, KeySym sym); static ButOut keytrap_krelease(But *but, const char *keystr, KeySym sym); static ButAction pix_action = { NULL, NULL, NULL, NULL, NULL, NULL, pix_draw, pixmap_destroy, but_flags, NULL}; static ButAction plain_action = { plain_mmove, NULL, NULL, NULL, NULL, NULL, plain_draw, plain_destroy, but_flags, NULL}; static ButAction dummy_action = { NULL, NULL, NULL, NULL, NULL, NULL, dummy_draw, dummy_destroy, but_flags, NULL}; static ButAction keytrap_action = { NULL, NULL, NULL, NULL, keytrap_kpress, keytrap_krelease, keytrap_draw, keytrap_destroy, but_flags, NULL}; typedef struct Pix_struct { Pixmap pic; int x,y; } Pix; typedef struct Plain_struct { int color; } Plain; typedef struct Keytrap_struct { ButOut (*callback)(But *but, int press); bool holdKey; } Keytrap; But *butPixmap_create(ButWin *win, int layer, int flags, Pixmap pic) { Pix *pix; But *but; pix = wms_malloc(sizeof(Pix)); but = but_create(win, pix, &pix_action); but->win = win; but->layer = layer; but->flags = flags | BUT_OPAQUE; pix->pic = pic; pix->x = 0; pix->y = 0; but_init(but); return(but); } void butPixmap_setPic(But *but, Pixmap pic, int x,int y) { Pix *pix = but->iPacket; assert(but->action == &pix_action); pix->pic = pic; pix->x = x; pix->y = y; but_draw(but); } static ButOut pixmap_destroy(But *but) { wms_free(but->iPacket); return(0); } static void pix_draw(But *but, int x, int y, int w, int h) { ButWin *win = but->win; ButEnv *env = win->env; Pix *pix = but->iPacket; if (pix->pic == None) { return; } XSetFillStyle(env->dpy, env->gc, FillTiled); XSetTile(env->dpy, env->gc, pix->pic); if ((but->x != pix->x + win->xOff) || (but->y != pix->y + win->yOff)) XSetTSOrigin(env->dpy, env->gc, but->x - pix->x - win->xOff, but->y - pix->y - win->yOff); if (but->x > x) { w -= but->x - x; x = but->x; } if (but->y > y) { h -= but->y - y; y = but->y; } if (but->x + but->w < x + w) w = but->x + but->w - x; if (but->y + but->h < y + h) h = but->y + but->h - y; XFillRectangle(env->dpy, win->win, env->gc, x - win->xOff, y - win->yOff, w, h); butEnv_stdFill(env); if ((but->x != pix->x) || (but->y != pix->y)) XSetTSOrigin(env->dpy, env->gc, 0,0); } But *butPlain_create(ButWin *win, int layer, int flags, int cnum) { Plain *plain; But *but; plain = wms_malloc(sizeof(Plain)); but = but_create(win, plain, &plain_action); but->layer = layer; but->flags = flags | BUT_OPAQUE; plain->color = cnum; but_init(but); return(but); } void butPlain_setColor(But *but, int cnum) { Plain *plain = but->iPacket; plain->color = cnum; but_draw(but); } static ButOut plain_destroy(But *but) { wms_free(but->iPacket); return(0); } static void plain_draw(But *but, int x, int y, int w, int h) { ButWin *win = but->win; ButEnv *env = win->env; Plain *color = but->iPacket; if (but->x > x) { w -= (but->x - x); x = but->x; } if (but->y > y) { h -= (but->y - y); y = but->y; } if (but->x+but->w < x+w) w = but->x+but->w - x; if (but->y+but->h < y+h) h = but->y+but->h - y; butEnv_setXFg(env, color->color); XFillRectangle(env->dpy, win->win, env->gc, x-win->xOff, y-win->yOff, w,h); } static ButOut plain_mmove(But *but, int x, int y) { return(BUTOUT_CAUGHT); } But *butDummy_create(ButWin *win, int layer, int flags) { But *but; but = but_create(win, NULL, &dummy_action); but->layer = layer; but->flags = flags | BUT_OPAQUE; but_init(but); return(but); } static ButOut dummy_destroy(But *but) { return(0); } static void dummy_draw(But *but, int x, int y, int w, int h) { } But *butKeytrap_create(ButOut (*func)(But *but, int press), void *uPacket, ButWin *win, int flags) { Keytrap *ktrap; But *but; but = but_create(win, NULL, &keytrap_action); ktrap = wms_malloc(sizeof(Keytrap)); but->uPacket = uPacket; but->iPacket = ktrap; ktrap->callback = func; ktrap->holdKey = TRUE; but->flags = flags; but->w = 1; but->h = 1; but_init(but); return(but); } static ButOut keytrap_destroy(But *but) { return(0); } void butKeytrap_setHold(But *but, bool hold) { Keytrap *k; assert(but->action == &keytrap_action); k = but->iPacket; k->holdKey = hold; } static ButOut keytrap_kpress(But *but, const char *keystr, KeySym sym) { ButOut retval = BUTOUT_CAUGHT; Keytrap *k = but->iPacket; if (!(but->flags & BUT_KEYPRESSED)) { snd_play(&but_downSnd); if (k->holdKey) but_newFlags(but, but->flags | BUT_KEYPRESSED|BUT_PRESSED|BUT_LOCKED); retval |= k->callback(but, TRUE); } return(retval); } static ButOut keytrap_krelease(But *but, const char *keystr, KeySym sym) { ButOut retval = BUTOUT_CAUGHT; int newflags = but->flags; Keytrap *k = but->iPacket; if (!(newflags & BUT_KEYPRESSED) && k->holdKey) return(0); if (k->holdKey) { newflags &= ~(BUT_KEYPRESSED|BUT_PRESSED|BUT_LOCKED); if (newflags != but->flags) but_newFlags(but, newflags); } snd_play(&but_upSnd); if (keystr != NULL) { /* If keystr is NULL, the key wasn't released - we lost focus instead. */ retval |= k->callback(but, FALSE); } return(retval); } static void keytrap_draw(But *but, int x, int y, int w, int h) { } #endif /* X11_DISP */ pente-2.2.5/wmslib/src/but/rcur.c0100664000076400007640000002427207045637750015065 0ustar wmswms/* * wmslib/src/but/rcur.c, part of wmslib (Library functions) * Copyright (C) 1994 William Shubert. * See "configure.h.in" for more copyright information. */ #include #ifdef X11_DISP #ifdef STDC_HEADERS #include #include #endif /* STDC_HEADERS */ #include #include #include #include #include #include #include #ifdef HAVE_SYS_SELECT_H #include #endif #include #include #include #include typedef struct Curs_struct { int fontcurnum; int hotX, hotY, w, h; char *pic, *mask; } Curs; #define ntm_width 16 #define ntm_height 16 #define ntm_bits ((char *)ntm_ubits) static uchar ntm_ubits[] = { 0x03, 0x00, 0x07, 0x00, 0x0f, 0x00, 0x1f, 0x00, 0x3f, 0x00, 0x7f, 0x00, 0xff, 0x00, 0xff, 0x01, 0xff, 0x03, 0xff, 0x03, 0x7f, 0x00, 0xf7, 0x00, 0xf3, 0x00, 0xe0, 0x01, 0xe0, 0x01, 0xc0, 0x01}; #define ntp_width 16 #define ntp_height 16 #define ntp_bits ((char *)ntp_ubits) static uchar ntp_ubits[] = { 0x00, 0x00, 0x02, 0x00, 0x06, 0x00, 0x0e, 0x00, 0x1e, 0x00, 0x3e, 0x00, 0x7e, 0x00, 0xfe, 0x00, 0xfe, 0x01, 0x3e, 0x00, 0x36, 0x00, 0x62, 0x00, 0x60, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0x00, 0x00}; #define tm_width 16 #define tm_height 16 #define tm_bits ((char *)tm_ubits) static uchar tm_ubits[] = { 0x00, 0xe0, 0x00, 0xf8, 0x00, 0xfe, 0x80, 0x7f, 0xe0, 0x7f, 0xf8, 0x3f, 0xfc, 0x3f, 0xf8, 0x1f, 0xe0, 0x1f, 0xf0, 0x0f, 0xf8, 0x0f, 0x7c, 0x07, 0x3e, 0x07, 0x1f, 0x02, 0x0e, 0x00, 0x04, 0x00}; #define tp_width 16 #define tp_height 16 #define tp_bits ((char *)tp_ubits) static uchar tp_ubits[] = { 0x00, 0x00, 0x00, 0x60, 0x00, 0x78, 0x00, 0x3e, 0x80, 0x3f, 0xe0, 0x1f, 0xf8, 0x1f, 0x80, 0x0f, 0xc0, 0x0f, 0xe0, 0x06, 0x70, 0x06, 0x38, 0x02, 0x1c, 0x02, 0x0e, 0x00, 0x04, 0x00, 0x00, 0x00}; #define txtp_width 16 #define txtp_height 16 #define txtp_bits ((char *)txtp_ubits) static uchar txtp_ubits[] = { 0x00, 0x00, 0xee, 0x00, 0x38, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x38, 0x00, 0xee, 0x00, 0x00, 0x00}; #define txtm_width 16 #define txtm_height 16 #define txtm_bits ((char *)txtm_ubits) static uchar txtm_ubits[] = { 0xef, 0x01, 0xff, 0x01, 0xff, 0x01, 0x7c, 0x00, 0x38, 0x00, 0x38, 0x00, 0x38, 0x00, 0x38, 0x00, 0x38, 0x00, 0x38, 0x00, 0x38, 0x00, 0x38, 0x00, 0x7c, 0x00, 0xff, 0x01, 0xff, 0x01, 0xef, 0x01}; static Curs cursors[BUTCUR_NUM]; static void draw(ButRcur *rc); static void erase(ButRcur *rc); static void butRcur_hideForRedraw(ButRcur *rc, int winId, int x,int y, int w,int h); void butEnv_rcInit(ButEnv *env) { Drawable d = RootWindow(env->dpy, DefaultScreen(env->dpy)); static bool first_time = TRUE; ButCur i; int dataWidth, j, k; if (first_time) { first_time = FALSE; for (i = butCur_idle; i < butCur_bogus; ++i) cursors[i].pic = NULL; cursors[butCur_idle].fontcurnum = XC_left_ptr; cursors[butCur_idle].hotX = 1; cursors[butCur_idle].hotY = 1; cursors[butCur_idle].w = 16; cursors[butCur_idle].h = 16; cursors[butCur_idle].pic = ntp_bits; cursors[butCur_idle].mask = ntm_bits; cursors[butCur_twitch].fontcurnum = XC_arrow; cursors[butCur_twitch].hotX = 14; cursors[butCur_twitch].hotY = 1; cursors[butCur_twitch].w = 16; cursors[butCur_twitch].h = 16; cursors[butCur_twitch].pic = tp_bits; cursors[butCur_twitch].mask = tm_bits; cursors[butCur_text].fontcurnum = XC_xterm; cursors[butCur_text].hotX = 4; cursors[butCur_text].hotY = 8; cursors[butCur_text].w = 16; cursors[butCur_text].h = 16; cursors[butCur_text].pic = txtp_bits; cursors[butCur_text].mask = txtm_bits; cursors[butCur_up].fontcurnum = XC_sb_up_arrow; cursors[butCur_up].hotX = 14; cursors[butCur_up].hotY = 14; cursors[butCur_up].w = 16; cursors[butCur_up].h = 16; cursors[butCur_up].pic = ntp_bits; cursors[butCur_up].mask = ntm_bits; cursors[butCur_down].fontcurnum = XC_sb_down_arrow; cursors[butCur_down].hotX = 14; cursors[butCur_down].hotY = 14; cursors[butCur_down].w = 16; cursors[butCur_down].h = 16; cursors[butCur_down].pic = ntp_bits; cursors[butCur_down].mask = ntm_bits; cursors[butCur_left].fontcurnum = XC_sb_left_arrow; cursors[butCur_left].hotX = 14; cursors[butCur_left].hotY = 14; cursors[butCur_left].w = 16; cursors[butCur_left].h = 16; cursors[butCur_left].pic = ntp_bits; cursors[butCur_left].mask = ntm_bits; cursors[butCur_right].fontcurnum = XC_sb_right_arrow; cursors[butCur_right].hotX = 14; cursors[butCur_right].hotY = 14; cursors[butCur_right].w = 16; cursors[butCur_right].h = 16; cursors[butCur_right].pic = ntp_bits; cursors[butCur_right].mask = ntm_bits; cursors[butCur_lr].fontcurnum = XC_sb_h_double_arrow; cursors[butCur_lr].hotX = 14; cursors[butCur_lr].hotY = 14; cursors[butCur_lr].w = 16; cursors[butCur_lr].h = 16; cursors[butCur_lr].pic = ntp_bits; cursors[butCur_lr].mask = ntm_bits; cursors[butCur_ud].fontcurnum = XC_sb_v_double_arrow; cursors[butCur_ud].hotX = 14; cursors[butCur_ud].hotY = 14; cursors[butCur_ud].w = 16; cursors[butCur_ud].h = 16; cursors[butCur_ud].pic = ntp_bits; cursors[butCur_ud].mask = ntm_bits; cursors[butCur_grab].fontcurnum = XC_fleur; cursors[butCur_grab].hotX = 14; cursors[butCur_grab].hotY = 14; cursors[butCur_grab].w = 16; cursors[butCur_grab].h = 16; cursors[butCur_grab].pic = ntp_bits; cursors[butCur_grab].mask = ntm_bits; } for (i = butCur_idle; i < butCur_bogus; ++i) { /* "Grey out" the remote cursors. */ dataWidth = (cursors[i].w + 7) / 8; for (j = 0; j < cursors[i].h; j += 2) { for (k = 0; k < dataWidth; ++k) { cursors[i].mask[j*dataWidth + k] &= 0x55; if (j+1 < cursors[i].h) { cursors[i].mask[(j+1)*dataWidth + k] &= 0xaa; } } } env->cursors[i] = XCreateFontCursor(env->dpy, cursors[i].fontcurnum); env->cpic[i] = XCreateBitmapFromData(env->dpy, d, cursors[i].pic, cursors[i].w, cursors[i].h); env->cmask[i] = XCreateBitmapFromData(env->dpy, d, cursors[i].mask, cursors[i].w, cursors[i].h); } env->curnum = butCur_idle; env->curwin = None; env->curhold = NULL; env->curlast = butCur_bogus; } /* Erase the cursor if it is in the area specified. */ void butRcur_create(ButRcur *rc, ButEnv *env) { MAGIC_SET(rc); rc->env = env; rc->winId = -2; rc->drawn = FALSE; rc->under = XCreatePixmap(env->dpy, DefaultRootWindow(env->dpy), 16,16, env->depth); } void butRcur_move(ButRcur *rc, int winId, int rx,int ry, int rw,int rh, ButCur type) { ButEnv *env = rc->env; assert(MAGIC(rc)); if ((winId < 0) || (winId >= env->maxWinIds)) winId = -2; else if (env->id2Win[winId] == NULL) winId = -2; if ((winId == rc->winId) && (rx == rc->rx) && (ry == rc->ry) && (rw == rc->rw) && (rh == rc->rh) && (type == rc->type)) return; if (rc->drawn) erase(rc); rc->winId = winId; rc->rx = rx; rc->ry = ry; rc->rw = rw; rc->rh = rh; rc->type = type; if (winId != -2) { rc->lx = (rx * env->id2Win[winId]->w + rw/2) / rw - cursors[type].hotX; rc->ly = (ry * env->id2Win[winId]->h + rh/2) / rh - cursors[type].hotY; draw(rc); } } void butRcur_redraw(ButEnv *env, int winId, int x,int y, int w,int h) { int i; if (winId == -2) return; for (i = 0; i < env->numPartners; ++i) { if (env->partners[i]) { if (butRnet_valid(env->partners[i]) && (winId == env->partners[i]->rc.winId)) butRcur_hideForRedraw(&env->partners[i]->rc, winId, x,y, w,h); } } } static void butRcur_hideForRedraw(ButRcur *rc, int winId, int x,int y, int w,int h) { assert(MAGIC(rc)); if (rc->drawn && (rc->winId == winId) && (x < rc->lx+16) && (y < rc->ly+16) && (x+w > rc->lx) && (y+h > rc->ly)) { /* We need to erase it. Will the redraw erase it for us? */ if ((x <= rc->lx) && (y <= rc->ly) && (x+w >= rc->lx+16) && (y+h >= rc->ly+16)) { rc->drawn = FALSE; } else erase(rc); } } /* xio is the I/O context that the move got reported in. */ static void draw(ButRcur *rc) { ButEnv *env = rc->env; assert(!rc->drawn); assert(MAGIC(rc)); XCopyArea(env->dpy, env->id2Win[rc->winId]->win, rc->under, env->gc2, rc->lx,rc->ly, 16,16, 0,0); if (!env->colorp) XSetFillStyle(env->dpy, env->gc2, FillSolid); XSetClipMask(env->dpy, env->gc2, env->cmask[rc->type]); XSetClipOrigin(env->dpy, env->gc2, rc->lx,rc->ly); XSetForeground(env->dpy, env->gc2, env->colors[BUT_FG]); XSetBackground(env->dpy, env->gc2, env->colors[BUT_LIT]); XCopyPlane(env->dpy, env->cpic[rc->type],env->id2Win[rc->winId]->win, env->gc2, 0,0, 16,16, rc->lx,rc->ly, 1L); XSetClipMask(env->dpy, env->gc2, None); if (!env->colorp) XSetFillStyle(env->dpy, env->gc2, FillTiled); rc->drawn = TRUE; } static void erase(ButRcur *rc) { ButEnv *env = rc->env; assert(MAGIC(rc)); assert(rc->drawn); XCopyArea(env->dpy, rc->under, env->id2Win[rc->winId]->win, env->gc2, 0,0, 16,16, rc->lx,rc->ly); rc->drawn = FALSE; } /* Change the cursor to make it twitched or not twitched. */ void butEnv_setCursor(ButEnv *env, But *but, ButCur newcursor) { if (newcursor == butCur_idle) { if (but == env->curhold) { env->curnum = newcursor; env->curhold = NULL; } } else { env->curnum = newcursor; env->curhold = but; } env->curwin = but->win->physWin; } /* Set up any cursor changes that may have occurred. */ void butEnv_rcActivate(ButEnv *env) { int i; if ((env->curlast != env->curnum) && (env->curwin != None)) { assert(env->curnum < butCur_bogus); env->curlast = env->curnum; XDefineCursor(env->dpy, env->curwin, env->cursors[env->curlast]); butRnet_mMove(env, -1, -1,-1, -1,-1, env->curnum); } for (i = 0; i < env->numPartners; ++i) { if (env->partners[i]) { if (butRnet_valid(env->partners[i]) && (env->partners[i]->rc.winId >= 0) && !env->partners[i]->rc.drawn) draw(&env->partners[i]->rc); } } } #endif pente-2.2.5/wmslib/src/but/slide.c0100664000076400007640000003615307045637750015213 0ustar wmswms/* * wmslib/src/but/slide.c, part of wmslib (Library functions) * Copyright (C) 1994-1997 William Shubert. * See "configure.h.in" for more copyright information. */ #include #ifdef X11_DISP #ifdef STDC_HEADERS #include #include #endif /* STDC_HEADERS */ #include #include #include #include #include #include #include #ifdef HAVE_SYS_SELECT_H #include #endif #include #include #include #include #include #include /********************************************************************** * Data Types **********************************************************************/ typedef struct Slide_struct { int maxval; int cval; int size; bool horiz; bool grip; int start_mloc, start_val, start_loc; ButTimer *timer; int timer_jump; int oldcur; /* * Stuff calculated from dimensions. * w and h are for a horizontal slider. Reverse for vertical! */ int boxW, boxH, boxLoc; int lastW, lastH; ButOut (*callback)(But *but, int setting, bool newPress); } Slide; /********************************************************************** * Forward Declarations **********************************************************************/ static ButOut mmove(But *but, int x, int y); static ButOut mleave(But *but); static ButOut mpress(But *but, int butnum, int x, int y); static ButOut mrelease(But *but, int butnum, int x, int y); static void draw(But *but, int x, int y, int w, int h); static ButOut destroy(But *but); static void flags(But *but, uint flags); static ButOut slide_now(ButTimer *bt); static void specialDraw(But *but, Slide *slide, int x, int y, int w, int h); static void drawNewLoc(But *but); static void calcBoxLoc(But *but); /********************************************************************** * Globals **********************************************************************/ static const ButAction action = { mmove, mleave, mpress, mrelease, NULL, NULL, draw, destroy, flags, NULL}; /********************************************************************** * Functions **********************************************************************/ But *butSlide_hCreate(ButOut (*func)(But *but, int setting, bool newPress), void *packet, ButWin *win, int layer, int flags, int maxval, int cval, int size) { Slide *slide; But *but; slide = wms_malloc(sizeof(Slide)); but = but_create(win, slide, &action); but->uPacket = packet; but->layer = layer; but->flags = flags | BUT_OPAQUE; slide->maxval = maxval; slide->cval = cval; slide->size = size; slide->horiz = TRUE; slide->grip = FALSE; slide->start_mloc = 0; slide->start_val = 0; slide->start_loc = 0; slide->timer = NULL; slide->timer_jump = 0; slide->oldcur = butCur_idle; slide->boxW = slide->boxH = slide->boxLoc = 0; slide->lastW = 0; slide->lastH = 0; slide->callback = func; but_init(but); return(but); } But *butSlide_vCreate(ButOut (*func)(But *but, int setting, bool newPress), void *packet, ButWin *win, int layer, int flags, int maxval, int cval, int size) { Slide *slide; But *but; slide = wms_malloc(sizeof(Slide)); but = but_create(win, slide, &action); but->uPacket = packet; but->layer = layer; but->flags = flags | BUT_OPAQUE; slide->maxval = maxval; slide->cval = cval; slide->size = size; slide->horiz = FALSE; slide->grip = FALSE; slide->start_mloc = 0; slide->start_val = 0; slide->start_loc = 0; slide->timer = NULL; slide->timer_jump = 0; slide->oldcur = butCur_idle; slide->boxW = slide->boxH = slide->boxLoc = 0; slide->lastW = 0; slide->lastH = 0; slide->callback = func; but_init(but); return(but); } void butSlide_set(But *but, int maxval, int cval, int size) { Slide *slide = but->iPacket; assert(but->action == &action); if (maxval == BUT_NOCHANGE) maxval = slide->maxval; if (cval == BUT_NOCHANGE) cval = slide->cval; if (size == BUT_NOCHANGE) size = slide->size; if ((maxval != slide->maxval) || (cval != slide->cval) || (size != slide->size)) { slide->maxval = maxval; slide->cval = cval; slide->size = size; drawNewLoc(but); } } int butSlide_get(But *but) { Slide *slide = but->iPacket; return(slide->cval); } static ButOut destroy(But *but) { Slide *slide = but->iPacket; if (slide->timer != NULL) butTimer_destroy(slide->timer); wms_free(slide); return(0); } static void draw(But *but, int x, int y, int w, int h) { ButWin *win = but->win; ButEnv *env = win->env; Slide *slide = but->iPacket; int bw = env->stdButBw; if ((w != slide->lastW) || (h != slide->lastH)) calcBoxLoc(but); but_drawBox(win, but->x,but->y, but->w,but->h, 1, bw, BUT_SLEFT|BUT_SRIGHT, BUT_LIT, BUT_SHAD, None, None); butEnv_setXFg(env, BUT_PBG); XFillRectangle(env->dpy, win->win, env->gc, but->x+bw,but->y+bw, but->w-2*bw, but->h-2*bw); if (slide->horiz) { but_drawBox(win, but->x+bw+slide->boxLoc, but->y+bw, slide->boxW, slide->boxH, but->flags & BUT_LOCKED, bw, BUT_SLEFT|BUT_SRIGHT, BUT_LIT, BUT_SHAD, None, None); butEnv_setXFg(env, BUT_BG); XFillRectangle(env->dpy, win->win, env->gc, but->x + bw*2 + slide->boxLoc, but->y + bw * 2, slide->boxW - bw * 2, slide->boxH - bw * 2); } else /* !but->horiz */ { but_drawBox(win, but->x+bw, but->y+bw+slide->boxLoc, slide->boxH, slide->boxW, but->flags & BUT_LOCKED, bw, BUT_SLEFT|BUT_SRIGHT, BUT_LIT, BUT_SHAD, None, None); butEnv_setXFg(env, BUT_BG); XFillRectangle(env->dpy, win->win, env->gc, but->x + bw * 2, but->y + bw*2 + slide->boxLoc, slide->boxH - bw * 2, slide->boxW - bw * 2); } } static void calcBoxLoc(But *but) { Slide *slide = but->iPacket; ButEnv *env = but->win->env; int allW, allH; int bw; bw = butEnv_stdBw(env); if (slide->horiz) { allW = but->w - 2*bw; allH = but->h - 2*bw; } else { allW = but->h - 2*bw; allH = but->w - 2*bw; } if (allW <= allH) { slide->boxW = allW; slide->boxH = allH; slide->boxLoc = 0; } else { slide->boxW = (slide->size * allW + (slide->size + slide->maxval) / 2) / (slide->size + slide->maxval); slide->boxH = allH; if (slide->boxW < slide->boxH) slide->boxW = slide->boxH; if (slide->maxval == 0) slide->boxLoc = 0; else slide->boxLoc = ((allW - slide->boxW) * slide->cval + slide->maxval / 2) / slide->maxval; } slide->lastW = but->w; slide->lastH = but->h; } static void drawNewLoc(But *but) { ButEnv *env = but->win->env; Slide *slide = but->iPacket; int bw = env->stdButBw; int boxW, boxH, boxLoc; int oldW, oldLoc; if ((but->w < 1) || (but->h < 1)) return; oldW = slide->boxW; oldLoc = slide->boxLoc; calcBoxLoc(but); boxW = slide->boxW; boxH = slide->boxH; boxLoc = slide->boxLoc; if (boxLoc < oldLoc) { specialDraw(but, slide, boxLoc + bw, bw, oldLoc + bw - boxLoc, boxH); } else if (boxLoc > oldLoc) { specialDraw(but, slide, oldLoc + bw, bw, boxLoc + bw - oldLoc, boxH); } if (boxLoc + boxW < oldLoc + oldW) { specialDraw(but, slide, boxLoc + boxW, bw, oldLoc + oldW + bw - boxLoc - boxW, boxH); } else if (boxLoc + boxW > oldLoc + oldW) { specialDraw(but, slide, oldLoc + oldW, bw, boxLoc + boxW + bw - oldLoc - oldW, boxH); } } static void specialDraw(But *but, Slide *slide, int x, int y, int w, int h) { if (slide->horiz) { butWin_redraw(but->win, but->x + x, but->y + y, w, h); } else { butWin_redraw(but->win, but->x + y, but->y + x, h, w); } } static void flags(But *but, uint flags) { uint ofl = but->flags; but->flags = flags; if ((flags & (BUT_PRESSABLE|BUT_DRAWABLE|BUT_PRESSED|BUT_LOCKED)) != (ofl & (BUT_PRESSABLE|BUT_DRAWABLE|BUT_PRESSED|BUT_LOCKED))) but_draw(but); } static ButOut mmove(But *but, int x, int y) { ButOut retval = BUTOUT_CAUGHT; int newflags = but->flags; ButEnv *env = butWin_env(but_win(but)); Slide *slide = but->iPacket; int newval, newloc, pitmax; int newcur = butCur_idle; if (slide->horiz) { if ((newflags & BUT_LOCKED) && slide->grip) { /* Slide it around! */ if (x == BUT_NOCHANGE) return(retval); newloc = x - slide->start_mloc + slide->start_loc; if (newloc < 0) newloc = 0; pitmax = but->w - slide->boxW - env->stdButBw*2; if (newloc > pitmax) newloc = pitmax; if (pitmax == 0) newval = 0; else newval = (newloc * slide->maxval + pitmax/2) / pitmax; if (newval != slide->cval) { slide->cval = newval; drawNewLoc(but); if (slide->callback != NULL) return(retval | slide->callback(but, slide->cval, FALSE)); } return(retval); } if ((x >= but->x+env->stdButBw) && (x < but->x+but->w-env->stdButBw) && (y >= but->y+env->stdButBw) && (y < but->y+but->h-env->stdButBw)) { newflags |= BUT_TWITCHED; if (x < but->x + env->stdButBw + slide->boxLoc) newcur = butCur_left; else if (x < but->x + env->stdButBw + slide->boxLoc + slide->boxW) newcur = butCur_lr; else newcur = butCur_right; } else { newflags &= ~BUT_TWITCHED; if (!(newflags & BUT_LOCKED)) retval &= ~BUTOUT_CAUGHT; } if (!(newflags & BUT_LOCKED) && (newcur != slide->oldcur)) { butEnv_setCursor(env, but, newcur); slide->oldcur = newcur; } if (newflags != but->flags) { but_newFlags(but, newflags); } return(retval); } else /* !slide->horiz */ { if ((newflags & BUT_LOCKED) && slide->grip) { /* Slide it around! */ if (y == BUT_NOCHANGE) return(retval); newloc = y - slide->start_mloc + slide->start_loc; if (newloc < 0) newloc = 0; pitmax = but->h - slide->boxW - env->stdButBw*2; if (newloc > pitmax) newloc = pitmax; if (pitmax == 0) newval = 0; else newval = (newloc * slide->maxval + pitmax/2) / pitmax; if (newval != slide->cval) { slide->cval = newval; drawNewLoc(but); if (slide->callback != NULL) return(retval | slide->callback(but, slide->cval, FALSE)); } return(retval); } if ((x >= but->x+env->stdButBw) && (x < but->x+but->w-env->stdButBw) && (y >= but->y+env->stdButBw) && (y < but->y+but->h-env->stdButBw)) { newflags |= BUT_TWITCHED; if (y < but->y + env->stdButBw + slide->boxLoc) newcur = butCur_up; else if (y < but->y + env->stdButBw + slide->boxLoc + slide->boxW) newcur = butCur_ud; else newcur = butCur_down; } else { newflags &= ~BUT_TWITCHED; if (!(newflags & BUT_LOCKED)) retval &= ~BUTOUT_CAUGHT; } if (!(newflags & BUT_LOCKED) && (newcur != slide->oldcur)) { butEnv_setCursor(env, but, newcur); slide->oldcur = newcur; } if (newflags != but->flags) { but_newFlags(but, newflags); } return(retval); } } static ButOut mleave(But *but) { int newflags = but->flags; Slide *slide = but->iPacket; newflags &= ~BUT_TWITCHED; butEnv_setCursor(but->win->env, but, butCur_idle); slide->oldcur = butCur_idle; if (newflags != but->flags) { but_newFlags(but, newflags); } return(BUTOUT_CAUGHT); } static ButOut mpress(But *but, int butnum, int x, int y) { int retval = BUTOUT_CAUGHT, newflags = but->flags; Slide *slide = but->iPacket; ButEnv *env = but->win->env; if (!newflags & BUT_TWITCHED) retval &= ~BUTOUT_CAUGHT; else { if (slide->horiz) { if (but->w <= but->h) return(BUTOUT_CAUGHT | BUTOUT_ERR); if (butnum == 1) { newflags |= BUT_LOCKED; if (x < but->x + env->stdButBw + slide->boxLoc) { butSlide_startSlide(but, TRUE, -slide->size*2, FALSE); } else if (x >= but->x + env->stdButBw + slide->boxLoc + slide->boxW) { butSlide_startSlide(but, TRUE, slide->size*2, FALSE); } else { /* The box has been "gripped." */ slide->grip = TRUE; slide->start_mloc = x; slide->start_loc = slide->boxLoc; slide->start_val = slide->cval; } } else return(BUTOUT_CAUGHT | BUTOUT_ERR); } else /* !slide->horiz */ { if (but->h <= but->w) return(BUTOUT_CAUGHT | BUTOUT_ERR); if (butnum == 1) { newflags |= BUT_LOCKED; if (y < but->y + env->stdButBw + slide->boxLoc) { butSlide_startSlide(but, TRUE, -slide->size*2, FALSE); } else if (y >= but->y + env->stdButBw + slide->boxLoc + slide->boxW) { butSlide_startSlide(but, TRUE, slide->size*2, FALSE); } else { /* The box has been "gripped." */ slide->grip = TRUE; slide->start_mloc = y; slide->start_loc = slide->boxLoc; slide->start_val = slide->cval; } } else return(BUTOUT_CAUGHT | BUTOUT_ERR); } snd_play(&but_downSnd); if (newflags != but->flags) but_newFlags(but, newflags); if (slide->callback != NULL) return(retval | slide->callback(but, slide->cval, TRUE)); } return(retval); } void butSlide_startSlide(But *but, bool pause, int ssize, bool propagate) { Slide *slide = but->iPacket; struct timeval delay; int atj; bool skipTimer = FALSE; if (slide->timer != NULL) butTimer_destroy(slide->timer); if (pause) { slide->cval += ssize/2; if (slide->cval <= 0) { slide->cval = 0; skipTimer = TRUE; } else if (slide->cval >= slide->maxval - 1) { slide->cval = slide->maxval - 1; skipTimer = TRUE; } drawNewLoc(but); if (propagate && slide->callback) slide->callback(but, slide->cval, TRUE); } if (!skipTimer) { slide->timer_jump = ssize; if (pause) { delay.tv_sec = 0; delay.tv_usec = 500000; } else { delay.tv_sec = 0; delay.tv_usec = 0; } if (slide->timer_jump > 0) atj = slide->timer_jump; else atj = -slide->timer_jump; slide->timer = butTimer_fCreate(NULL, but, delay, atj*2, FALSE, slide_now); } } static ButOut slide_now(ButTimer *bt) { But *but = bt->but; Slide *slide = but->iPacket; if (slide->timer_jump > 0) { slide->cval += bt->eventNum; if (slide->cval > slide->maxval) { slide->cval = slide->maxval; butTimer_destroy(bt); slide->timer = NULL; } } else { slide->cval -= bt->eventNum; if (slide->cval < 0) { slide->cval = 0; butTimer_destroy(bt); slide->timer = NULL; } } bt->eventNum = 0; drawNewLoc(but); if (slide->callback != NULL) return(slide->callback(but, slide->cval, FALSE)); return(0); } static ButOut mrelease(But *but, int butnum, int x, int y) { ButOut retval = BUTOUT_CAUGHT; uint newflags = but->flags; Slide *slide = but->iPacket; if (!newflags & BUT_TWITCHED) butEnv_setCursor(but->win->env, but, slide->oldcur = butCur_idle); if (slide->timer != NULL) { butTimer_destroy(slide->timer); slide->timer = NULL; } slide->grip = FALSE; newflags &= ~BUT_LOCKED; if (newflags != but->flags) but_newFlags(but, newflags); snd_play(&but_upSnd); return(retval); } void butSlide_stopSlide(But *but) { Slide *slide = but->iPacket; if (slide->timer) { butTimer_destroy(slide->timer); slide->timer = NULL; } } #endif pente-2.2.5/wmslib/src/but/tblock.c0100664000076400007640000002430607045637750015366 0ustar wmswms/* * wmslib/src/but/tblock.c, part of wmslib (Library functions) * Copyright (C) 1994-1996 William Shubert. * See "configure.h.in" for more copyright information. */ #include #ifdef X11_DISP #ifdef STDC_HEADERS #include #include #endif /* STDC_HEADERS */ #include #include #include #include #include #include #include #ifdef HAVE_SYS_SELECT_H #include #endif #include #include #include #include #include #include /********************************************************************** * Data Types **********************************************************************/ typedef struct Word_struct { int start, len, xoff, yoff, w; } Word; typedef struct { char *str; int nwords; Word *words; ButTextAlign align; int font; int setup_w; } Tb; /********************************************************************** * Forward Declarations **********************************************************************/ static void draw(But *but, int x,int y, int w,int h); static ButOut destroy(But *but); /********************************************************************** * Globals **********************************************************************/ static const ButAction action = { NULL,NULL,NULL,NULL, NULL,NULL, draw, destroy, but_flags, NULL}; /********************************************************************** * Functions **********************************************************************/ But *butTblock_create(ButWin *win, int layer, int flags, const char *text, ButTextAlign align) { But *but; Tb *tb; assert(MAGIC(win)); assert(MAGIC(&win->butsNoDraw)); tb = wms_malloc(sizeof(Tb)); but = but_create(win, tb, &action); but->layer = layer; but->flags = flags; tb->str = NULL; tb->nwords = 0; tb->words = NULL; tb->align = align; tb->font = 0; tb->setup_w = 0; but_init(but); if (text != NULL) butTblock_setText(but, text); return(but); } void butTblock_setFont(But *but, int fontnum) { Tb *tb = but->iPacket; assert(but->action == &action); tb->font = fontnum; but_draw(but); } int butTblock_getH(But *but) { Tb *tb = but->iPacket; int fonth; assert(but->action == &action); fonth = but->win->env->fonts[tb->font]->ascent + but->win->env->fonts[tb->font]->descent; if (tb->nwords == 0) return(fonth); else return(tb->words[tb->nwords - 1].yoff + fonth); } const char *butTblock_getText(But *but) { Tb *tb; assert(but->action == &action); tb = but->iPacket; return(tb->str); } void butTblock_setText(But *but, const char *text) { Tb *tb = but->iPacket; ButEnv *env = but->win->env; int w = tb->setup_w = but->w, txtH; int len, numLines, wordNum, totalWidth, i, j; int lastSpaceSeen, spacesAtLastSpace, spacesThisLine; int widthAtLastSpace, widthNonSpace, widthOfCurrentChar; int widthNonSpaceAtLastSpace; bool nonSpaceSeen, prevCharWasSpace; Word *words; int *widths; int wordWMax, wordWMin; assert(but->action == &action); txtH = env->fonts[tb->font]->ascent + env->fonts[tb->font]->descent; if (text != NULL) { len = strlen(text); if (tb->str != NULL) wms_free(tb->str); tb->str = wms_malloc((len + 1) * sizeof(char)); strcpy(tb->str, text); } if (w == 0) return; text = tb->str; len = strlen(text); if (tb->words != NULL) wms_free(tb->words); if (text == NULL) { tb->words = NULL; return; } tb->nwords = strlen(tb->str); if (tb->nwords == 0) return; tb->words = words = wms_malloc(tb->nwords * sizeof(Word)); widths = wms_malloc(len * sizeof(int)); words[0].start = 0; words[0].xoff = 0; words[0].yoff = 0; words[0].w = 0; wordNum = totalWidth = widthNonSpace = 0; widthAtLastSpace = 0; spacesAtLastSpace = 0; widthNonSpaceAtLastSpace = 0; wordWMax = wordWMin = 0; numLines = 1; spacesThisLine = lastSpaceSeen = 0; nonSpaceSeen = prevCharWasSpace = FALSE; for (i = 0; i < len; ++i) { widthOfCurrentChar = butEnv_charWidth(env, tb->str+i, tb->font); assert(widthOfCurrentChar > 0); widths[i] = widthOfCurrentChar; if (tb->str[i] == ' ') { if (!prevCharWasSpace) { lastSpaceSeen = i; widthAtLastSpace = totalWidth; widthNonSpaceAtLastSpace = widthNonSpace; spacesAtLastSpace = spacesThisLine; } if (nonSpaceSeen) ++spacesThisLine; else widthNonSpace += widthOfCurrentChar; prevCharWasSpace = TRUE; } else { if ((uchar)tb->str[i] < BUTWRITE_MINPRINT) { ++i; widths[i] = 0; } nonSpaceSeen = TRUE; prevCharWasSpace = FALSE; widthNonSpace += widthOfCurrentChar; } totalWidth += widthOfCurrentChar; if (totalWidth > w) { if (lastSpaceSeen != words[wordNum].start) i = lastSpaceSeen; words[wordNum].len = i - words[wordNum].start; switch(tb->align) { case butText_center: words[wordNum].xoff += (w - widthAtLastSpace) / 2; words[wordNum].w = widthAtLastSpace; break; case butText_right: words[wordNum].xoff += (w - widthAtLastSpace); words[wordNum].w = widthAtLastSpace; break; case butText_just: widthNonSpace = widthNonSpaceAtLastSpace; totalWidth = 0; j = words[wordNum].start; nonSpaceSeen = FALSE; while (spacesAtLastSpace > 0) { assert(j <= i); if ((tb->str[j] == ' ') && nonSpaceSeen) { widthOfCurrentChar = (w - widthNonSpace + spacesAtLastSpace/2) / spacesAtLastSpace; --spacesAtLastSpace; widthNonSpace += widthOfCurrentChar; totalWidth += widthOfCurrentChar; if (tb->str[j - 1] != ' ') { words[wordNum].len = j - words[wordNum].start; assert(words[wordNum].w > 0); assert(words[wordNum].w < w); ++wordNum; } if (tb->str[j + 1] != ' ') { assert(totalWidth < w); words[wordNum].start = j + 1; words[wordNum].xoff = totalWidth; words[wordNum].yoff = txtH * (numLines - 1); words[wordNum].w = 0; } } else { if (tb->str[j] != ' ') nonSpaceSeen = TRUE; totalWidth += widths[j]; words[wordNum].w += widths[j]; if ((uchar)tb->str[j] < BUTWRITE_MINPRINT) ++j; } ++j; } words[wordNum].len = i - tb->words[wordNum].start; while ((tb->str[j] != ' ') && (tb->str[j] != '\0')) words[wordNum].w += widths[j++]; break; case butText_left: words[wordNum].w = widthAtLastSpace; break; } ++wordNum; while (tb->str[i] == ' ') { ++i; widths[i] = butEnv_charWidth(env, tb->str+i, tb->font); } lastSpaceSeen = i; widthNonSpace = totalWidth = widths[i]; spacesThisLine = 0; nonSpaceSeen = TRUE; prevCharWasSpace = FALSE; words[wordNum].start = i; words[wordNum].xoff = 0; words[wordNum].yoff = txtH * numLines; words[wordNum].w = 0; ++numLines; /* * If this was a special character then step over it's second byte. */ if ((uchar)tb->str[i] < BUTWRITE_MINPRINT) { ++i; widths[i] = 0; } } } words[wordNum].len = i - words[wordNum].start; if (tb->align == butText_center) words[wordNum].xoff += (w - totalWidth) / 2; else if (tb->align == butText_right) words[wordNum].xoff += (w - totalWidth); words[wordNum].w = totalWidth; tb->nwords = wordNum + 1; /* We probably allocated way too many words, so allocate a new block * of exactly the right size and move to it. */ words = wms_malloc(tb->nwords * sizeof(Word)); memcpy(words, tb->words, tb->nwords * sizeof(Word)); for (i = 0; i < tb->nwords; ++i) { words[i].w = 0; for (j = words[i].start; j < words[i].start+words[i].len; ++j) words[i].w += widths[j]; } wms_free(widths); wms_free(tb->words); tb->words = words; } /* Returns the height of the text block after being resized. */ int butTblock_resize(But *but, int x, int y, int w) { int old_w = but->w, h; assert(MAGIC(but)); assert(but->action == &action); but->w = w; butTblock_setText(but, NULL); but->w = old_w; but_resize(but, x, y, w, h = butTblock_getH(but)); return(h); } static ButOut destroy(But *but) { Tb *tb = but->iPacket; if (tb->str != NULL) wms_free(tb->str); if (tb->words != NULL) wms_free(tb->words); wms_free(tb); return(0); } static void draw(But *but, int dx, int dy, int dw, int dh) { Tb *tb = but->iPacket; ButEnv *env = but->win->env; int i, x, y; char temp; int fonth; if (but->w != tb->setup_w) butTblock_setText(but, NULL); fonth = env->fonts[tb->font]->ascent + env->fonts[tb->font]->descent; butEnv_setXFg(env, BUT_FG); x = but->x; y = but->y; for (i = 0; i < tb->nwords; ++i) { assert((tb->words[i].xoff >= 0) && (tb->words[i].xoff < but->w) && (tb->words[i].yoff >= 0) && (tb->words[i].yoff < but->h)); assert((tb->words[i].w > 0) && (tb->words[i].w <= but->w)); if ((x+tb->words[i].xoff < dx+dw) && (y+tb->words[i].yoff < dy+dh) && (x+tb->words[i].xoff + tb->words[i].w >= dx) && (y+tb->words[i].yoff + fonth >= dy)) { temp = tb->str[tb->words[i].start + tb->words[i].len]; tb->str[tb->words[i].start + tb->words[i].len] = '\0'; butWin_write(but->win, x+tb->words[i].xoff, y+tb->words[i].yoff, tb->str+tb->words[i].start, tb->font); tb->str[tb->words[i].start + tb->words[i].len] = temp; } } } int butTblock_guessH(ButEnv *env, const char *text, int w, int fontNum) { int curW = 0, curH; int wLastSpace = 0; int fontH; int i; fontH = butEnv_fontH(env, fontNum); curH = fontH; for (i = 0; text[i]; ++i) { if (text[i] == ' ') { curW += butEnv_charWidth(env, text+i, fontNum); wLastSpace = curW; if (curW >= w) { while (i+1 == ' ') ++i; curH += fontH; wLastSpace = curW = 0; } } else { curW += butEnv_charWidth(env, text+i, fontNum); if (text[i] <= '\2') ++i; if (curW > w) { curH += fontH; if (wLastSpace) { curW -= wLastSpace; wLastSpace = 0; } else { /* No spaces, break the word in half. */ curW = butEnv_charWidth(env, text+i, fontNum); } } } } return(curH); } #endif pente-2.2.5/wmslib/src/but/text.c0100664000076400007640000000771007045637750015074 0ustar wmswms/* * wmslib/src/but/text.c, part of wmslib (Library functions) * Copyright (C) 1994-1996 William Shubert. * See "configure.h.in" for more copyright information. */ #include #ifdef X11_DISP #ifdef STDC_HEADERS #include #include #endif /* STDC_HEADERS */ #include #include #include #include #include #include #include #ifdef HAVE_SYS_SELECT_H #include #endif #include #include #include #include /********************************************************************** * Data Structures **********************************************************************/ typedef struct Txt_struct { Str text; ButTextAlign align; int font; int color; bool stipple; } Txt; /********************************************************************** * Forward Declarations **********************************************************************/ static void draw(But *but, int x,int y, int w,int h); static ButOut destroy(But *but); /********************************************************************** * Globals **********************************************************************/ static const ButAction action = { NULL,NULL,NULL,NULL, NULL,NULL, draw, destroy, but_flags, NULL}; /********************************************************************** * Functions **********************************************************************/ But *butText_create(ButWin *win, int layer, int flags, const char *text, ButTextAlign align) { But *but; Txt *t; t = wms_malloc(sizeof(Txt)); but = but_create(win, t, &action); but->layer = layer; but->flags = flags; str_init(&t->text); t->align = align; t->font = 0; t->color = BUT_FG; t->stipple = FALSE; but_init(but); if (text != NULL) butText_set(but, text); return(but); } void butText_set(But *but, const char *text) { Txt *t = but->iPacket; assert(but->action == &action); if (text == NULL) text = ""; str_copyChars(&t->text, text); but_draw(but); } void butText_setFont(But *but, int fontnum) { Txt *t = but->iPacket; assert(but->action == &action); t->font = fontnum; but_draw(but); } void butText_setColor(But *but, int color, bool stipple) { Txt *t = but->iPacket; if (color == BUT_NOCHANGE) color = t->color; if ((color != t->color) || (stipple != t->stipple)) { t->color = color; t->stipple = stipple; but_draw(but); } } static ButOut destroy(But *but) { Txt *t = but->iPacket; str_deinit(&t->text); return(0); } static void draw(But *but, int x,int y, int w,int h) { Txt *t = but->iPacket; ButEnv *env = but->win->env; XFontStruct *fs = env->fonts[t->font]; int th; const char *text = str_chars(&t->text); if (t->stipple) { XSetFillStyle(env->dpy, env->gc, FillStippled); XSetForeground(env->dpy, env->gc, env->colors[t->color]); } else { butEnv_setXFg(env, t->color); } x = but->x; if (t->align == butText_center) x += (but->w - butEnv_textWidth(env, text, t->font)) / 2; else if (t->align == butText_right) x += (but->w - butEnv_textWidth(env, text, t->font)); th = fs->ascent + fs->descent; butWin_write(but->win, x, but->y + (but->h - th) / 2, text, t->font); if (t->stipple) { butEnv_stdFill(env); } } int butText_resize(But *but, int x, int y, int h) { Txt *txt = but->iPacket; int w = butEnv_textWidth(but->win->env, str_chars(&txt->text), txt->font); switch (txt->align) { case butText_left: break; case butText_center: x -= w/2; break; case butText_right: x -= w; break; default: break; } but_resize(but, x, y, w, h); return(w); } const char *butText_get(But *but) { Txt *t; assert(MAGIC(but)); assert(but->action == &action); t = but->iPacket; return(str_chars(&t->text)); } #endif pente-2.2.5/wmslib/src/but/textin.c0100664000076400007640000007255507045637750015434 0ustar wmswms/* * wmslib/src/but/textin.c, part of wmslib (Library functions) * Copyright (C) 1994-1997 William Shubert. * See "configure.h.in" for more copyright information. */ /* * I don't really like this button. * It is slower than it has to be (this may or may not matter). */ #include #ifdef X11_DISP #ifdef STDC_HEADERS #include #include #endif /* STDC_HEADERS */ #include #include #include #include #include #include #include #include #ifdef HAVE_SYS_SELECT_H #include #endif #include #include #include #include #include /********************************************************************** * Data Types **********************************************************************/ typedef struct SpecKey_struct { struct SpecKey_struct *next; KeySym keysym; uint keyModifiers, modMask; ButOut (*callback)(But *but, KeySym keysym, uint keyModifiers, void *context); void *context; MAGIC_STRUCT } SpecKey; typedef struct Txtin_struct { ButOut (*callback)(But *but, const char *value); bool hidden; char *str, *dispStr; /* dispStr is only used if hidden is TRUE. */ int maxlen, len, loc, cutend; int mousePress, origMousePress, clicks; int xoffset; Pixmap pm; int pm_w, pm_h, slideDir, slideFreq; int but3StartMouse, but3StartXoff; bool mouseInBut, cursorVisible; ButTimer *cTimer, *sTimer; SpecKey *specKeys; MAGIC_STRUCT } Txtin; /********************************************************************** * Forward Declarations **********************************************************************/ static int locateMouse(XFontStruct *fs, char *text, int len, int x, bool *rightSide); static void ti_cursor(But *but); static void ti_redrawCursor(But *but); static ButOut mmove(But *but, int x, int y); static ButOut mleave(But *but); static ButOut mpress(But *but, int butnum, int x, int y); static ButOut mrelease(But *but, int butnum, int x, int y); static ButOut kpress(But *but, const char *keystr, KeySym sym); static void draw(But *but, int x,int y, int w,int h); static ButOut destroy(But *but); static bool insert(ButEnv *env, const char *src, Txtin *but); static void cut(ButEnv *env, char *cutstr, int cutlen, But *but); static void paste(ButEnv *env, But *but); static void enableCTimer(But *but); static void disableCTimer(But *but); static void curInView(But *but); static void textInView(But *but, bool maxInView); static bool sreq(ButEnv *env, XSelectionRequestEvent *xsre); static int sclear(ButEnv *env); static int snotify(ButEnv *env, XSelectionEvent *xsre); static void flags(But *but, uint flags); static void wordsel_adjust(Txtin *but); static void startSlide(But *but, int dir, bool fast); static ButOut slide(ButTimer *timer); /********************************************************************** * Globals **********************************************************************/ static int cutstr_maxlen = 0, cutstr_len; static char *cutdata = NULL; static But *cut_butnum = NULL; static But *paste_butnum = NULL; static const ButAction action = { mmove, mleave, mpress, mrelease, kpress, NULL, draw, destroy, flags, NULL}; /********************************************************************** * Functions **********************************************************************/ But *butTextin_create(ButOut (*callback)(But *but, const char *value), void *packet, ButWin *win, int layer, int flags, const char *text, int maxlen) { But *but; Txtin *ti; ti = wms_malloc(sizeof(Txtin)); MAGIC_SET(ti); but = but_create(win, ti, &action); but->uPacket = packet; but->layer = layer; but->flags = flags | BUT_OPAQUE; if (text == NULL) text = ""; ti->callback = callback; ti->hidden = FALSE; ti->maxlen = maxlen; ti->str = (char *)wms_malloc(ti->maxlen + 1); ti->dispStr = ti->str; ti->xoffset = 0; ti->pm_w = ti->pm_h = 0; ti->pm = None; ti->mousePress = -1; ti->mouseInBut = FALSE; strcpy(ti->str, text); ti->len = ti->loc = ti->cutend = strlen(text); ti->cTimer = NULL; if (flags & BUT_KEYED) { ti->cursorVisible = TRUE; } else ti->cursorVisible = FALSE; ti->sTimer = NULL; ti->but3StartXoff = -1; ti->specKeys = NULL; but_init(but); return(but); } const char *butTextin_get(But *but) { Txtin *ti = but->iPacket; assert(but->action == &action); assert(MAGIC(ti)); return(ti->str); } static ButOut destroy(But *but) { Txtin *ti = but->iPacket; ButEnv *env = but->win->env; SpecKey *spec, *nextSpec; assert(but->action == &action); assert(MAGIC(ti)); spec = ti->specKeys; while (spec != NULL) { assert(MAGIC(spec)); nextSpec = spec->next; MAGIC_UNSET(spec); wms_free(spec); spec = nextSpec; } if (cut_butnum == but) { if (env->sClear == sclear) env->sClear = NULL; if (env->sReq == sreq) env->sReq = NULL; cut_butnum = NULL; } if (paste_butnum == but) { if (env->sNotify == snotify) env->sNotify = NULL; paste_butnum = NULL; } if (ti->pm != None) XFreePixmap(but->win->env->dpy, ti->pm); wms_free(ti->str); if (ti->hidden) wms_free(ti->dispStr); else { assert(ti->dispStr == ti->str); } MAGIC_UNSET(ti); wms_free(ti); return(0); } static void draw(But *but, int x,int y, int w,int h) { ButWin *win = but->win; ButEnv *env = win->env; Txtin *ti = but->iPacket; int txtw; int butbw = env->stdButBw; XFontStruct *fs = env->fonts[0]; assert(but->action == &action); assert(MAGIC(ti)); XSetFont(env->dpy, env->gc2, env->fonts[0]->fid); if ((ti->pm_w != but->w - 2*butbw) || (ti->pm_h != but->h - 2*butbw)) { if (ti->pm != None) XFreePixmap(env->dpy, ti->pm); ti->pm = XCreatePixmap(env->dpy, win->win, ti->pm_w = but->w - 2*butbw, ti->pm_h = but->h - 2*butbw, DefaultDepth(env->dpy, DefaultScreen(env->dpy))); } but_drawBox(win, but->x,but->y, but->w,but->h, 1, butbw, BUT_SRIGHT|BUT_SLEFT, BUT_LIT, BUT_SHAD, None, None); txtw = XTextWidth(fs, ti->dispStr, ti->loc); butEnv_setXFg2(env, BUT_HIBG); XFillRectangle(env->dpy, ti->pm, env->gc2, 0,0, ti->pm_w,ti->pm_h); if (but->flags & BUT_PRESSABLE) butEnv_setXFg2(env, BUT_FG); else { XSetFillStyle(env->dpy, env->gc2, FillStippled); XSetForeground(env->dpy, env->gc2, env->colors[BUT_FG]); } if (ti->loc == ti->cutend) { XDrawString(env->dpy, ti->pm, env->gc2, x = butbw - ti->xoffset, y = (fs->ascent + ti->pm_h - fs->descent) / 2, ti->dispStr, ti->len); } else { int tw1, tw2; int cl1, cl2; if (ti->cutend >= ti->loc) { cl1 = ti->loc; cl2 = ti->cutend; } else { cl1 = ti->cutend; cl2 = ti->loc; } XDrawString(env->dpy, ti->pm, env->gc2, x = butbw - ti->xoffset, y = (fs->ascent + ti->pm_h - fs->descent) / 2, ti->dispStr, cl1); tw1 = XTextWidth(fs, ti->dispStr, cl1); tw2 = XTextWidth(fs, ti->dispStr + cl1, cl2 - cl1); x += tw1 + tw2; XDrawString(env->dpy, ti->pm, env->gc2, x,y, ti->dispStr + cl2, ti->len - cl2); x -= tw2; XSetBackground(env->dpy, env->gc2, env->colors[BUT_SELBG]); if (!env->colorp) { XSetTile(env->dpy, env->gc2, env->colorPmaps[BUT_WHITE]); XSetForeground(env->dpy, env->gc2, env->colors[BUT_WHITE]); } XDrawImageString(env->dpy, ti->pm, env->gc2, x,y, ti->dispStr + cl1, cl2 - cl1); } if (!(but->flags & BUT_PRESSABLE)) { butEnv_stdFill2(env); } XCopyArea(env->dpy, ti->pm, win->win, env->gc, 0,0, ti->pm_w,ti->pm_h, but->x + butbw - win->xOff, but->y + butbw - win->yOff); if ((ti->loc == ti->cutend) && ti->cursorVisible && (but->flags & BUT_PRESSABLE)) ti_cursor(but); } static ButOut mmove(But *but, int x, int y) { Txtin *ti = but->iPacket; ButWin *win = but->win; ButEnv *env = win->env; int newMousePress; bool rightSide; if (!(but->flags & BUT_PRESSABLE)) return(BUTOUT_CAUGHT); if (!ti->mouseInBut) { ti->mouseInBut = TRUE; butEnv_setCursor(env, but, butCur_text); } if (ti->mousePress != -1) { if (ti->clicks < 2) { if (x < but->x) { startSlide(but, -1, (x < but->x - but->h + env->stdButBw*2)); newMousePress = 0; } else if (x > but->x + but->w) { startSlide(but, 1, (x > but->x + but->w + but->h - env->stdButBw*2)); newMousePress = ti->len; } else { if (ti->sTimer != NULL) { butTimer_destroy(ti->sTimer); ti->sTimer = NULL; } if (y < but->y + env->stdButBw*2) newMousePress = 0; else if (y > but->y+but->h - env->stdButBw*2) newMousePress = ti->len; else newMousePress = locateMouse(env->fonts[0], ti->dispStr, ti->len, x - (but->x + 2*env->stdButBw - ti->xoffset), &rightSide); } if (ti->clicks == 1) { if (rightSide && (newMousePress >= ti->origMousePress) && (newMousePress < ti->len)) ++newMousePress; else if (!rightSide && (newMousePress <= ti->origMousePress) && (newMousePress > 0)) --newMousePress; } if (newMousePress != ti->mousePress) { ti->mousePress = ti->loc = newMousePress; if (ti->clicks == 1) { ti->cutend = ti->origMousePress; wordsel_adjust(ti); } but_draw(but); } } } if (ti->but3StartXoff != -1) { int oldXoff = ti->xoffset; ti->xoffset = ti->but3StartXoff - 10*(x - ti->but3StartMouse); textInView(but, FALSE); if (oldXoff != ti->xoffset) but_draw(but); } return(BUTOUT_CAUGHT); } static ButOut mleave(But *but) { Txtin *ti = but->iPacket; if (ti->mouseInBut) { ti->mouseInBut = FALSE; butEnv_setCursor(but->win->env, but, butCur_idle); } return(BUTOUT_CAUGHT); } static ButOut mpress(But *but, int butnum, int x, int y) { Txtin *ti = but->iPacket; ButEnv *env = but->win->env; static Time lastPressTime = -1; static int lastPressNum = -2; int rightSide; if (ti->cTimer) { butTimer_reset(ti->cTimer); ti->cursorVisible = TRUE; } switch (butnum) { case 1: /* Button 1 selects, drags, etc. */ if (ti->but3StartXoff != -1) return(BUTOUT_ERR); if (!(but->flags & BUT_KEYED)) but_newFlags(but, but->flags | BUT_KEYED); but_newFlags(but, but->flags | BUT_LOCKED); ti->mousePress = locateMouse(env->fonts[0], ti->dispStr, ti->len, x - (but->x + 2*env->stdButBw - ti->xoffset), &rightSide); ti->loc = ti->cutend = ti->origMousePress = ti->mousePress; if ((lastPressTime + BUT_DCLICK > env->eventTime) && (lastPressNum + 1 == env->eventNum)) { if (ti->clicks == 0) { /* It's a double click! */ ++ti->clicks; if (rightSide) ++ti->loc; else --ti->loc; wordsel_adjust(ti); } else if (ti->clicks == 1) { /* It's a triple click! */ ++ti->clicks; ti->loc = 0; ti->cutend = ti->len; } else { /* Quadruple click! Restart! */ ti->clicks = 0; } } else ti->clicks = 0; lastPressTime = env->eventTime; lastPressNum = env->eventNum; but_draw(but); break; case 2: /* Paste! */ ti->cutend = ti->loc = locateMouse(env->fonts[0], ti->dispStr, ti->len, x - (but->x + 2*env->stdButBw - ti->xoffset), NULL); paste(env, but); break; case 3: /* * Button 3 scrolls as if this input window was a mini-canvas. I'm not * sure how useful this is but I'm doing it anyway just to make my * interface more consistent. */ if (ti->mousePress != -1) return(BUTOUT_ERR); but_newFlags(but, but->flags | BUT_LOCKED); butEnv_setCursor(env, but, butCur_lr); ti->but3StartMouse = x; ti->but3StartXoff = ti->xoffset; break; default: /* * Weird. I don't know what to do with mice with more than 3 buttons * so I guess I might as well beep. I like beeping. */ return(BUTOUT_ERR); break; } return(BUTOUT_CAUGHT); } static ButOut mrelease(But *but, int butnum, int x, int y) { Txtin *ti = but->iPacket; char *cutstr; int cutlen; if (ti->cTimer) { butTimer_reset(ti->cTimer); ti->cursorVisible = TRUE; } if ((butnum == 1) && (ti->mousePress != -1)) { if (ti->sTimer != NULL) { butTimer_destroy(ti->sTimer); ti->sTimer = NULL; } if (ti->loc != ti->cutend) { if (ti->loc < ti->cutend) { cutstr = ti->str + ti->loc; cutlen = ti->cutend - ti->loc; } else { cutstr = ti->str + ti->cutend; cutlen = ti->loc - ti->cutend; } cut(but->win->env, cutstr, cutlen, but); } ti->mousePress = -1; but_newFlags(but, but->flags & ~BUT_LOCKED); } else if ((butnum == 3) && (ti->but3StartXoff != -1)) { butEnv_setCursor(but->win->env, but, butCur_text); ti->but3StartXoff = -1; but_newFlags(but, but->flags & ~BUT_LOCKED); } return(BUTOUT_CAUGHT); } static ButOut kpress(But *but, const char *newtext, KeySym keysym) { Txtin *ti = but->iPacket; ButEnv *env = but->win->env; bool need_draw = FALSE, needCallback = FALSE; int i; ButOut result = 0; SpecKey *spec; butTimer_reset(ti->cTimer); ti->cursorVisible = TRUE; for (spec = ti->specKeys; spec != NULL; spec = spec->next) { if ((keysym == spec->keysym) && ((env->keyModifiers & spec->modMask) == spec->keyModifiers)) { return(spec->callback(but, keysym, env->keyModifiers, spec->context) | BUTOUT_CAUGHT); } } if (((keysym >= XK_KP_Space) && (keysym <= XK_KP_9)) || ((keysym >= XK_space) && (keysym <= XK_ydiaeresis))) { need_draw = TRUE; switch(newtext[0]) { case '\001': /* Ctrl-A: Beginning of line. */ case '\020': /* Ctrl-P: Up a line. */ ti->loc = ti->cutend = 0; break; case '\002': /* Ctrl-B: Back a character. */ if (ti->loc != ti->cutend) { ti->cutend = ti->loc; } else if (ti->loc) { ti->cutend = --ti->loc; } else { need_draw = FALSE; result |= BUTOUT_ERR | BUTOUT_CAUGHT; } break; case '\004': /* Ctrl-D: Delete right. */ if (ti->loc != ti->cutend) need_draw = insert(env, "", ti); else if (ti->loc < ti->len) { for (i = ti->loc; ti->str[i]; ++i) ti->str[i] = ti->str[i+1]; --ti->len; need_draw = TRUE; } else result |= BUTOUT_ERR | BUTOUT_CAUGHT; break; case '\005': /* Ctrl-E: End of line. */ case '\016': /* Ctrl-N: Down a line. */ ti->loc = ti->cutend = ti->len; break; case '\006': /* Ctrl-F: Forward a character. */ if (ti->loc != ti->cutend) { ti->loc = ti->cutend; } else if (ti->loc < ti->len) { ti->cutend = ++ti->loc; } else { result |= BUTOUT_ERR | BUTOUT_CAUGHT; need_draw = FALSE; } break; case '\013': /* Ctrl-K: Kill to end of line. */ ti->str[ti->len = ti->loc = ti->cutend] = '\0'; break; case '\025': /* Ctrl-U: Kill from beginning of line. */ for (i = ti->loc; i < ti->len; ++i) ti->str[i - ti->loc] = ti->str[i]; ti->str[ti->len -= ti->loc] = '\0'; ti->loc = ti->cutend = 0; break; default: if (!(need_draw = insert(env, newtext, ti))) result |= BUTOUT_ERR | BUTOUT_CAUGHT; break; } } else if ((keysym >= XK_Shift_L) && (keysym <= XK_Hyper_R)) { } else if ((keysym >= XK_F1) && (keysym <= XK_F35)) { if (!(need_draw = insert(env, newtext, ti))) result |= BUTOUT_ERR | BUTOUT_CAUGHT; } else if ((keysym == XK_BackSpace) || (keysym == XK_Delete)) { if (ti->loc != ti->cutend) need_draw = insert(env, "", ti); else if (ti->loc > 0) { for (i = ti->cutend = --ti->loc; ti->str[i]; ++i) ti->str[i] = ti->str[i+1]; --ti->len; need_draw = TRUE; } else result |= BUTOUT_ERR | BUTOUT_CAUGHT; #if 0 /* People don't like it when delete works the way I like it. :-( */ } else if (keysym == XK_Delete) { if (ti->loc != ti->cutend) need_draw = insert(env, "", ti); else if (ti->loc < ti->len) { for (i = ti->loc; ti->str[i]; ++i) ti->str[i] = ti->str[i+1]; --ti->len; need_draw = TRUE; } else result |= BUTOUT_ERR | BUTOUT_CAUGHT; #endif } else if (keysym == XK_Left) { if (ti->loc != ti->cutend) { if (ti->loc < ti->cutend) ti->cutend = ti->loc; else ti->loc = ti->cutend; need_draw = TRUE; } else if (ti->loc) { ti->cutend = --ti->loc; need_draw = TRUE; } else result |= BUTOUT_ERR | BUTOUT_CAUGHT; } else if (keysym == XK_Right) { if (ti->loc != ti->cutend) { if (ti->loc > ti->cutend) ti->cutend = ti->loc; else ti->loc = ti->cutend; need_draw = TRUE; } else if (ti->loc < ti->len) { ti->cutend = ++ti->loc; need_draw = TRUE; } else result |= BUTOUT_ERR | BUTOUT_CAUGHT; } else if (keysym == XK_Up) { ti->loc = ti->cutend = 0; need_draw = TRUE; } else if (keysym == XK_Down) { ti->loc = ti->cutend = ti->len; need_draw = TRUE; } else if ((keysym == XK_Return) || (keysym == XK_Linefeed) || (keysym == XK_KP_Enter)) { result |= BUTOUT_CAUGHT; if (ti->callback == NULL) { but_setFlags(but, BUT_NOKEY); } else { needCallback = TRUE; } } /* Void all mouse movement until it is pressed again. */ if (ti->mousePress != -1) { ti->mousePress = -1; if (but->flags & BUT_LOCKED) but_newFlags(but, but->flags & ~BUT_LOCKED); } if (need_draw) { result |= BUTOUT_CAUGHT; curInView(but); but_draw(but); } if (needCallback) result |= ti->callback(but, ti->str); return(result); } static bool insert(ButEnv *env, const char *src, Txtin *ti) { int i, j, ntLen, cl1, cl2; XFontStruct *fs = env->fonts[0]; if (src == NULL) { return(FALSE); } if (ti->loc <= ti->cutend) { cl1 = ti->loc; cl2 = ti->cutend; } else { cl1 = ti->cutend; cl2 = ti->loc; } for (i = 0, ntLen = 0; src[i]; ++i) { if ((((uchar)src[i] >= fs->min_char_or_byte2) && ((uchar)src[i] <= fs->max_char_or_byte2)) || (fs->all_chars_exist && fs->per_char[(uchar)src[i] - fs->min_char_or_byte2].width)) ++ntLen; } if ((ntLen == 0) && src[0]) return(FALSE); if (ntLen + ti->len + cl1 - cl2 > ti->maxlen) { return(FALSE); } if (cl1 != cl2) { for (i = cl1; i < ti->len; ++i) ti->str[i] = ti->str[i + cl2 - cl1]; } for (i = ti->len + ntLen; i >= cl1 + ntLen; --i) ti->str[i] = ti->str[i - ntLen]; for (i = 0, j = cl1; src[i]; ++i) { if ((((uchar)src[i] >= fs->min_char_or_byte2) && ((uchar)src[i] <= fs->max_char_or_byte2)) || (fs->all_chars_exist && fs->per_char[(uchar)src[i] - fs->min_char_or_byte2].width)) { ti->str[j++] = src[i]; } } ti->len += cl1 - cl2 + ntLen; ti->loc = ti->cutend = cl1 + ntLen; return(TRUE); } static void ti_cursor(But *but) { Txtin *ti = but->iPacket; ButWin *win = but->win; ButEnv *env = win->env; XFontStruct *fs = env->fonts[0]; int x, y; int rw; if (ti->loc != ti->cutend) return; x = but->x - ti->xoffset + env->stdButBw*2 + XTextWidth(fs, ti->dispStr, ti->loc); y = but->y + env->stdButBw*2; if ((rw = (fs->ascent + fs->descent + 10) / 20) < 1) rw = 1; x -= rw/2; if (x < but->x + env->stdButBw) { rw -= (but->x + env->stdButBw - x); x = but->x + env->stdButBw; } else if (x+rw > but->x + but->w - env->stdButBw) { rw = but->x + but->w - env->stdButBw - x; } if (rw <= 0) return; if (ti->cursorVisible) butEnv_setXFg2(env, BUT_FG); else butEnv_setXFg2(env, BUT_HIBG); XFillRectangle(env->dpy, win->win, env->gc2, x - win->xOff, y - win->yOff, rw, ti->pm_h - env->stdButBw*2); } static void ti_redrawCursor(But *but) { Txtin *ti = but->iPacket; ButWin *win = but->win; ButEnv *env = win->env; XFontStruct *fs = env->fonts[0]; int x, y; int rw; if (ti->loc != ti->cutend) return; x = but->x - ti->xoffset + env->stdButBw*2 + XTextWidth(fs, ti->dispStr, ti->loc); y = but->y + env->stdButBw*2; if ((rw = (fs->ascent + fs->descent + 10) / 20) < 1) rw = 1; x -= rw/2; if (x < but->x + env->stdButBw) { rw -= (but->x + env->stdButBw - x); x = but->x + env->stdButBw; } else if (x+rw > but->x + but->w - env->stdButBw) { rw = but->x + but->w - env->stdButBw - x; } if (rw <= 0) return; butWin_redraw(win, x, y, rw, ti->pm_h - env->stdButBw*2); } static void cut(ButEnv *env, char *cutstr, int cutlen, But *but) { ButWin *realWin; if (cutstr_maxlen < cutlen) { if (cutdata != NULL) wms_free(cutdata); cutdata = (char *)wms_malloc(cutlen); cutstr_maxlen = cutlen; } XStoreBytes(env->dpy, cutstr, cutlen); memcpy(cutdata, cutstr, cutlen); cutstr_len = cutlen; realWin = but->win; while (realWin->parent != NULL) realWin = realWin->parent; if ((env->sReq == NULL) || ((env->sReq == sreq) && (cut_butnum == but))) XSetSelectionOwner(env->dpy, XA_PRIMARY, realWin->win, 0); else env->sClear(env); if (XGetSelectionOwner(env->dpy, XA_PRIMARY) == realWin->win) { env->sReq = sreq; env->sClear = sclear; cut_butnum = but; } } static bool sreq(ButEnv *env, XSelectionRequestEvent *xsre) { if (xsre->target != XA_STRING) return(FALSE); XChangeProperty(env->dpy, xsre->requestor, xsre->property, xsre->target, 8, PropModeReplace, cutdata, cutstr_len); return(TRUE); } static int sclear(ButEnv *env) { Txtin *ti; assert(MAGIC(cut_butnum)); ti = cut_butnum->iPacket; assert(MAGIC(ti)); ti->loc = ti->cutend; but_draw(cut_butnum); env->sReq = NULL; env->sClear = NULL; return(0); } static void paste(ButEnv *env, But *but) { ButWin *topWin; paste_butnum = but; env->sNotify = snotify; topWin = but->win; while (topWin->parent != NULL) topWin = topWin->parent; XConvertSelection(env->dpy, XA_PRIMARY, XA_STRING, env->prop, topWin->win, 0); } static int snotify(ButEnv *env, XSelectionEvent *xsnot) { unsigned char *propbuf; unsigned long proplen, propleft; int blen; int pformat; Atom ptype; Txtin *ti; char *pb2; ti = paste_butnum->iPacket; if (xsnot->property != None) { XGetWindowProperty(env->dpy, xsnot->requestor, xsnot->property, 0, ti->maxlen, True, AnyPropertyType, &ptype, &pformat, &proplen, &propleft, &propbuf); pb2 = (char *)wms_malloc(proplen * pformat + 1); pb2[proplen * pformat] = '\0'; memcpy(pb2, propbuf, proplen * pformat); XFree(propbuf); if (insert(env, pb2, ti)) { textInView(paste_butnum, FALSE); but_draw(paste_butnum); } else XBell(env->dpy, 0); wms_free(pb2); } else { propbuf = (unsigned char *)XFetchBytes(env->dpy, &blen); if (blen > 0) { pb2 = (char *)wms_malloc(blen + 1); pb2[blen] = '\0'; memcpy(pb2, propbuf, blen); XFree(propbuf); if (insert(env, pb2, ti)) { textInView(paste_butnum, FALSE); but_draw(paste_butnum); } else XBell(env->dpy, 0); wms_free(pb2); } else XBell(env->dpy, 0); } env->sNotify = NULL; return(0); } /* * This adjusts your loc and your cutend for when you're in word select mode. */ static void wordsel_adjust(Txtin *but) { int a, b; if (but->loc < but->cutend) { a = but->loc; b = but->cutend; } else { a = but->cutend; b = but->loc; } for (;;) { if (a <= 0) { a = 0; break; } if (((isalnum(but->str[a]) || (but->str[a] == '_')) && (isalnum(but->str[a-1]) || (but->str[a-1] == '_'))) || (but->str[a] == but->str[a-1]) || (isdigit(but->str[a]) && (but->str[a-1] == '.') && (a >= 2) && isdigit(but->str[a-2])) || (isdigit(but->str[a+1]) && (but->str[a] == '.') && isdigit(but->str[a-1]))) --a; else break; } if (b <= 0) b = 1; for (;;) { if (b >= but->len) { b = but->len; break; } if (((isalnum(but->str[b-1]) || (but->str[b-1] == '_')) && (isalnum(but->str[b]) || (but->str[b] == '_'))) || (but->str[b-1] == but->str[b]) || (isdigit(but->str[b-1]) && (but->str[b] == '.') && isdigit(but->str[b+1])) || ((b >= 2) && isdigit(but->str[b-2]) && (but->str[b-1] == '.') && isdigit(but->str[b]))) ++b; else break; } but->loc = a; but->cutend = b; } /* Returns the index of the character just to the right of the cursor. */ static int locateMouse(XFontStruct *fs, char *text, int len, int x, bool *rightSide) { int i; int prev_x = x; bool dummy; if (rightSide == NULL) rightSide = &dummy; for (i = 0; (x > 0) && (i < len); ++i) { prev_x = x; if (fs->per_char == NULL) /* Monospace font. */ x -= fs->min_bounds.width; else x -= fs->per_char[text[i] - fs->min_char_or_byte2].width; } if ((*rightSide = ((i > 0) && (x < 0) && (prev_x < -x)))) --i; if (i == len) *rightSide = FALSE; return(i); } /* Set up xoffset so that the cursor will be in view. */ static void curInView(But *but) { Txtin *ti = but->iPacket; ButEnv *env = but->win->env; int curIn; curIn = XTextWidth(env->fonts[0], ti->dispStr, ti->loc); if (curIn < ti->xoffset) ti->xoffset = curIn; if (curIn - ti->xoffset > ti->pm_w - env->stdButBw * 2) ti->xoffset = curIn - ti->pm_w + env->stdButBw * 2; } /* * Set up xoffset so that the text will be in view. If maxInView is set, * then make sure that as much text is in the window as possible (that is, * there is no unnecessary empty space to the right of the text). */ static void textInView(But *but, bool maxInView) { Txtin *ti = but->iPacket; ButEnv *env = but->win->env; int curIn; curIn = XTextWidth(env->fonts[0], ti->dispStr, ti->len); if (maxInView) { if (ti->xoffset > curIn - (but->w - env->stdButBw*4)) ti->xoffset = curIn - (but->w - env->stdButBw * 4); } if (ti->xoffset < 0) ti->xoffset = 0; if (ti->xoffset > curIn) ti->xoffset = curIn; } static void flags(But *but, uint flags) { Txtin *ti = but->iPacket; if ((but->flags & BUT_KEYED) != (flags & BUT_KEYED)) { if (flags & BUT_KEYED) { enableCTimer(but); ti->cursorVisible = TRUE; } else { ti->cursorVisible = FALSE; disableCTimer(but); } } but->flags = flags; assert((but->flags & BUT_PRESSABLE) || !(but->flags & BUT_KEYED)); but_draw(but); } static ButOut blinkCursor(ButTimer *timer) { But *but = butTimer_packet(timer); Txtin *ti = but->iPacket; ti->cursorVisible = !(butTimer_ticks(timer) & 1); ti_redrawCursor(but); return(0); } static ButOut slide(ButTimer *timer) { But *but = butTimer_packet(timer); Txtin *ti = but->iPacket; int newXoff, oldXoff; if (ti->slideDir > 0) { oldXoff = ti->xoffset; textInView(but, TRUE); if (oldXoff != ti->xoffset) { ti->xoffset = oldXoff; butTimer_destroy(ti->sTimer); ti->sTimer = NULL; return(0); } } newXoff = ti->xoffset + ti->slideDir * butTimer_ticks(timer); ti->xoffset = newXoff; textInView(but, ti->slideDir > 0); if (ti->xoffset != newXoff) { butTimer_destroy(ti->sTimer); ti->sTimer = NULL; } butTimer_setTicks(timer, 0); but_draw(but); return(0); } static void startSlide(But *but, int dir, bool fast) { struct timeval zero; Txtin *ti = but->iPacket; int freq; zero.tv_sec = 0; zero.tv_usec = 0; freq = but->h; if (fast) freq *= 10; if (ti->sTimer != NULL) { if ((ti->slideFreq == freq) && (ti->slideDir == dir)) return; butTimer_destroy(ti->sTimer); } ti->slideDir = dir; ti->slideFreq = freq; ti->sTimer = butTimer_fCreate(but, but, zero, freq, FALSE, slide); } static void enableCTimer(But *but) { Txtin *ti = but->iPacket; struct timeval halfSec; assert(ti->cTimer == NULL); halfSec.tv_sec = 0; halfSec.tv_usec = 500000; ti->cTimer = butTimer_create(but, but, halfSec, halfSec, TRUE, blinkCursor); } static void disableCTimer(But *but) { Txtin *ti = but->iPacket; if (ti->cTimer != NULL) { butTimer_destroy(ti->cTimer); ti->cTimer = NULL; } } void butTextin_set(But *but, const char *newStr, bool propagate) { Txtin *ti; assert(MAGIC(but)); assert(but->action == &action); ti = but->iPacket; assert(MAGIC(ti)); assert(strlen(newStr) <= ti->maxlen); strcpy(ti->str, newStr); ti->len = ti->loc = ti->cutend = strlen(newStr); textInView(but, TRUE); but_draw(but); if (propagate) ti->callback(but, ti->str); } void butTextin_setHidden(But *but, bool hidden) { Txtin *ti; int i; assert(MAGIC(but)); assert(but->action == &action); ti = but->iPacket; assert(MAGIC(ti)); if (hidden == ti->hidden) return; ti->hidden = hidden; if (hidden) { ti->dispStr = wms_malloc(ti->maxlen); for (i = 0; i < ti->maxlen; ++i) { ti->dispStr[i] = '*'; } } else { wms_free(ti->dispStr); ti->dispStr = ti->str; } } void butTextin_setSpecialKey(But *but, KeySym keysym, uint keyModifiers, uint modMask, ButOut callback(But *but, KeySym keysym, uint keyModifiers, void *context), void *context) { Txtin *ti; SpecKey *newSpec; assert(MAGIC(but)); assert(but->action == &action); ti = but->iPacket; assert(MAGIC(ti)); assert((keyModifiers & modMask) == keyModifiers); newSpec = wms_malloc(sizeof(SpecKey)); MAGIC_SET(newSpec); newSpec->next = ti->specKeys; ti->specKeys = newSpec; newSpec->keysym = keysym; newSpec->keyModifiers = keyModifiers; newSpec->modMask = modMask; newSpec->callback = callback; newSpec->context = context; } #endif /* X11_DISP */ pente-2.2.5/wmslib/src/but/timer.c0100664000076400007640000001243007045637750015223 0ustar wmswms/* * wmslib/src/but/timer.c, part of wmslib (Library functions) * Copyright (C) 1994 William Shubert. * See "configure.h.in" for more copyright information. */ #include #ifdef X11_DISP #include #include #include #include #include #include #include #include #include ButTimer *butTimer_create(void *packet, But *but, struct timeval delay, struct timeval period, bool winOnly, ButOut (*timerFunc)(ButTimer *timer)) { ButTimer *bt; struct timeval now; struct timezone tzone; bt = wms_malloc(sizeof(ButTimer)); MAGIC_SET(bt); bt->packet = packet; bt->eventNum = 0; bt->period = period; bt->state = butTimer_on; gettimeofday(&now, &tzone); bt->nextFiring = but_timerAdd(now, delay); if (but) bt->win = but->win; else bt->win = NULL; bt->but = but; bt->timerFunc = timerFunc; bt->winOnly = winOnly; bt->next = but_timerList; bt->freqCounter = FALSE; but_timerList = bt; return(bt); } ButTimer *butTimer_fCreate(void *packet, But *but, struct timeval delay, int frequency, bool winOnly, ButOut (*timerFunc)(ButTimer *timer)) { ButTimer *bt; struct timeval now; struct timezone tzone; int i; bt = wms_malloc(sizeof(ButTimer)); MAGIC_SET(bt); bt->packet = packet; bt->eventNum = 0; bt->period.tv_sec = 0; bt->winOnly = winOnly; if (frequency < BUTTIMER_MAXFREQ) { bt->period.tv_usec = 1000000 / frequency; bt->ticksPerPeriod = 1; } else { bt->period.tv_usec = 1000000 / BUTTIMER_STDFREQ; bt->ticksPerPeriod = (frequency + BUTTIMER_STDFREQ/2) / BUTTIMER_STDFREQ; } bt->state = butTimer_on; gettimeofday(&now, &tzone); bt->nextFiring = but_timerAdd(now, delay); if (but) bt->win = but->win; else bt->win = NULL; bt->but = but; bt->timerFunc = timerFunc; bt->next = but_timerList; bt->freqCounter = TRUE; for (i = 0; i < BUTTIMER_HIST; ++i) bt->lastRes[i] = 1; bt->resnum = 0; bt->ticksLeft = 0; but_timerList = bt; return(bt); } void butTimer_destroy(ButTimer *timer) { assert(MAGIC(timer)); timer->state = butTimer_dead; } void butTimer_reset(ButTimer *timer) { struct timeval now; struct timezone tzone; assert(MAGIC(timer)); timer->eventNum = 0; gettimeofday(&now, &tzone); timer->nextFiring = but_timerAdd(now, timer->period); } struct timeval but_timerAdd(struct timeval t1, struct timeval t2) { struct timeval r; r.tv_sec = t1.tv_sec + t2.tv_sec; if ((r.tv_usec = t1.tv_usec + t2.tv_usec) > 1000000) { r.tv_usec -= 1000000; ++r.tv_sec; } return(r); } struct timeval but_timerSub(struct timeval t1, struct timeval t2) { struct timeval r; r.tv_sec = t1.tv_sec - t2.tv_sec; if ((r.tv_usec = t1.tv_usec - t2.tv_usec) < 0) { r.tv_usec += 1000000; --r.tv_sec; } if (r.tv_sec < 0) r.tv_sec += 60*60*24; return(r); } int but_timerDiv(struct timeval t1, struct timeval t2, struct timeval *remainder) { int result; long it1, it2, irem; it1 = (t1.tv_sec*1000000L) + t1.tv_usec; it2 = (t2.tv_sec*1000000L) + t2.tv_usec; result = it1 / it2; if (remainder != NULL) { irem = it1 % it2; remainder->tv_usec = irem % 1000000; remainder->tv_sec = irem / 1000000; } return(result); } int butEnv_checkTimers(ButEnv *env, struct timeval *timeout) { struct timeval current_time, next_timer, timerem; struct timezone tzone; bool take_timer, timer_set = FALSE; ButTimer *bt, *bt2; int ticks, i, orig_ticks; int result = 0; /* First, kill off all the dead timers. */ for (bt = but_timerList; bt != NULL;) { if (bt->state == butTimer_dead) { if (bt == but_timerList) but_timerList = bt->next; else { for (bt2 = but_timerList; bt2->next != bt; bt2 = bt2->next); bt2->next = bt->next; } bt2 = bt->next; MAGIC_UNSET(bt); wms_free(bt); bt = bt2; } else { bt = bt->next; } } gettimeofday(¤t_time, &tzone); for (bt = but_timerList; bt != NULL; bt = bt->next) { if (bt->state == butTimer_on) { if (timercmp(&bt->nextFiring, ¤t_time, <)) { take_timer = TRUE; ticks = but_timerDiv(but_timerSub(current_time, bt->nextFiring), bt->period, &timerem) + 1 + bt->ticksLeft; take_timer = TRUE; orig_ticks = ticks; if (bt->freqCounter) { for (i = 0; i < BUTTIMER_HIST; ++i) { if (bt->lastRes[i] > ticks) { take_timer = FALSE; } } if (!bt->ticksLeft) { bt->lastRes[bt->resnum] = ticks; bt->resnum = (bt->resnum + 1) & (BUTTIMER_HIST - 1); } ticks *= bt->ticksPerPeriod; } bt->nextFiring = but_timerSub(but_timerAdd(current_time, bt->period), timerem); if (take_timer) { bt->eventNum += ticks; result |= bt->timerFunc(bt); XSync(env->dpy, False); bt->ticksLeft = 0; } else bt->ticksLeft += orig_ticks; } if (!timer_set || timercmp(&bt->nextFiring, &next_timer, <)) { timer_set = TRUE; next_timer = bt->nextFiring; } } } if (timer_set) *timeout = but_timerSub(next_timer, current_time); else { timeout->tv_usec = 0; timeout->tv_sec = 365*24*60*60; /* 1 spurious interrupt per year. */ } return(result); } #endif /* X11_DISP */ pente-2.2.5/wmslib/src/but/write.c0100664000076400007640000001227207045637750015241 0ustar wmswms/* * wmslib/src/but/write.c, part of wmslib (Library functions) * Copyright (C) 1994 William Shubert. * See "configure.h.in" for more copyright information. */ #include #ifdef X11_DISP #ifdef STDC_HEADERS #include #include #endif /* STDC_HEADERS */ #include #include #include #include #include #include #include #ifdef HAVE_SYS_SELECT_H #include #endif #include #include #include void butEnv_setChar(ButEnv *env, double width, const char *id, void (*draw)(void *packet, ButWin *win, int x, int y, int w, int h), void *packet) { int idval; idval = ((int)(uchar)id[0] << 8) + (uchar)id[1] - 256; env->write[idval].width = width; env->write[idval].packet = packet; env->write[idval].draw = draw; } int butEnv_textWidth(ButEnv *env, const char *text, int fnum) { uchar c; int special; int total = 0, min_char, std_width; XCharStruct *charlist; if (env->fonts[fnum]->per_char != NULL) { charlist = env->fonts[fnum]->per_char; min_char = env->fonts[fnum]->min_char_or_byte2; for (;;) { c = text[0]; ++text; switch(c) { case '\0': return(total); break; case '\1': case '\2': special = 256 * (c - 1) + text[0]; ++text; assert(env->write[special].draw != NULL); total += (env->fonts[fnum]->ascent + env->fonts[fnum]->descent) * env->write[special].width + 0.5; break; default: assert((c >= min_char) && (c <= env->fonts[fnum]->max_char_or_byte2)); total += charlist[c - min_char].width; break; } } } else { /* All chars are the same width. */ std_width = env->fonts[fnum]->min_bounds.width; for (;;) { c = text[0]; ++text; switch(c) { case '\0': return(total); break; case '\1': case '\2': special = 256 * (c - 1) + text[0]; ++text; assert(env->write[special].draw != NULL); total += (env->fonts[fnum]->ascent + env->fonts[fnum]->descent) * env->write[special].width + 0.5; break; default: total += std_width; break; } } } } int butEnv_charWidth(ButEnv *env, const char *text, int fnum) { uchar c, special; int width; c = text[0]; assert(c != '\0'); switch(c) { case '\1': case '\2': special = 256 * (c - 1) + text[1]; assert(env->write[special].draw != NULL); width = (env->fonts[fnum]->ascent + env->fonts[fnum]->descent) * env->write[special].width + 0.5; break; default: if (env->fonts[fnum]->per_char != NULL) width = env->fonts[fnum]->per_char[c - env->fonts[fnum]->min_char_or_byte2]. width; else width = env->fonts[fnum]->min_bounds.width; break; } return(width); } void butWin_write(ButWin *win, int x, int y, const char *text, int font) { int wlen; ButEnv *env = win->env; int ascent = env->fonts[font]->ascent, special; int w, h = ascent + env->fonts[font]->descent; uchar c; XSetFont(env->dpy, env->gc, env->fonts[font]->fid); for (;;) { for (wlen = 0; (uchar)(text[wlen]) > BUTWRITE_MINPRINT; ++wlen); if (wlen > 0) { XDrawString(env->dpy, win->win, env->gc, x-win->xOff, y+ascent-win->yOff, text, wlen); x += XTextWidth(env->fonts[font], text, wlen); text += wlen; } switch(c = text[0]) { case '\0': return; break; case '\1': case '\2': special = 256 * (c-1) + text[1]; text += 2; assert(env->write[special].draw != NULL); w = h * env->write[special].width + 0.5; env->write[special].draw(env->write[special].packet, win, x-win->xOff,y-win->yOff, w,h); x += w; break; } } } void butWin_writeTabs(ButWin *win, int startX, int y, const char *text, int font, const int *tabList, const ButTextAlign *aligns) { int wlen; ButEnv *env = win->env; int ascent = env->fonts[font]->ascent, special; int w, h = ascent + env->fonts[font]->descent; int x = startX; uchar c; int tabNum = 0; ButTextAlign align = butText_left; XSetFont(env->dpy, env->gc, env->fonts[font]->fid); for (;;) { for (wlen = 0; (uchar)(text[wlen]) > BUTWRITE_MINPRINT; ++wlen); if (wlen > 0) { w = XTextWidth(env->fonts[font], text, wlen); switch(align) { case butText_left: break; case butText_center: x -= w / 2; break; case butText_right: x -= w; break; case butText_just: assert(0); break; } XDrawString(env->dpy, win->win, env->gc, x - win->xOff, y+ascent-win->yOff, text, wlen); x += w; text += wlen; } switch(c = text[0]) { case '\0': return; break; case '\1': case '\2': special = 256 * (c-1) + text[1]; text += 2; assert(env->write[special].draw != NULL); w = h * env->write[special].width + 0.5; env->write[special].draw(env->write[special].packet, win, x-win->xOff,y-win->yOff, w,h); x += w; break; case '\t': x = startX + tabList[tabNum]; align = aligns[tabNum]; ++tabNum; ++text; break; } } } #endif /* X11_DISP */ pente-2.2.5/wmslib/src/abut/abut.c0100664000076400007640000000263107331147374015175 0ustar wmswms/* * src/abut.c, part of wmslib library * Copyright (C) 1995-1996 William Shubert. * See "configure.h.in" for more copyright information. */ #include #include #ifdef _ABUT_ABUT_H_ Levelization Error. #endif #include /********************************************************************** * Functions **********************************************************************/ Abut *abut_create(ButEnv *env, const char *ok, const char *cancel) { Abut *a; a = wms_malloc(sizeof(Abut)); MAGIC_SET(a); a->env = env; a->ok = ok; a->cancel = cancel; a->butH = 0; a->ulColor = BUT_LIT; a->lrColor = BUT_SHAD; a->bgColor = BUT_BG; a->ulPixmap = None; a->lrPixmap = None; a->bgPixmap = None; a->clp = NULL; return(a); } void abut_destroy(Abut *a) { assert(MAGIC(a)); MAGIC_UNSET(a); wms_free(a); } void abut_setColors(Abut *a, int ul, int lr, int bg) { assert(MAGIC(a)); if (ul >= 0) { a->ulColor = ul; a->ulPixmap = None; } if (lr >= 0) { a->lrColor = lr; a->lrPixmap = None; } if (bg >= 0) { a->bgColor = bg; a->bgPixmap = None; } } void abut_setPixmaps(Abut *a, Pixmap ul, Pixmap lr, Pixmap bg) { if (ul != None) { a->ulColor = -1; a->ulPixmap = ul; } if (lr != None) { a->lrColor = -1; a->lrPixmap = lr; } if (bg != None) { a->bgColor = -1; a->bgPixmap = bg; } } pente-2.2.5/wmslib/src/abut/swin.c0100664000076400007640000002752207045637750015234 0ustar wmswms/* * wmslib/src/abut/swin.c, part of wmslib (Library functions) * Copyright (C) 1994-1996 William Shubert. * See "configure.h.in" for more copyright information. */ #include #if X11_DISP #include #include #include #include #include #include #ifdef _ABUT_SWIN_H_ Levelization Error. #endif #include "swin.h" /********************************************************************** * Forward Declarations **********************************************************************/ static void draw_uparrow(void *packet, ButWin *win, int x, int y, int w, int h); static void draw_downarrow(void *packet, ButWin *win, int x, int y, int w, int h); static void draw_leftarrow(void *packet, ButWin *win, int x, int y, int w, int h); static void draw_rightarrow(void *packet, ButWin *win, int x, int y, int w, int h); static ButOut pressUp(But *but), pressDown(But *but); static ButOut pressLeft(But *but), pressRight(But *but); static ButOut releaseVArrow(But *but), releaseHArrow(But *but); static ButOut v_moved(But *but, int new_yoff, bool newPress); static ButOut hMoved(But *but, int new_xOff, bool newPress); static void redo_slider(void *packet, int xoff, int yoff, int w, int h, int viewW, int viewH); /********************************************************************** * Functions **********************************************************************/ AbutSwin *abutSwin_create(void *packet, ButWin *parent, int layer, uint flags, ButWinFunc resize) { AbutSwin *swin; ButEnv *env = butWin_env(parent); static ButKey upKeys[] = {{XK_Prior, 0, ShiftMask}, {0,0,0}}; static ButKey downKeys[] = {{XK_Next, 0, ShiftMask}, {0,0,0}}; static ButKey leftKeys[] = {{XK_Left, 0, ShiftMask}, {0,0,0}}; static ButKey rightKeys[] = {{XK_Right, 0, ShiftMask}, {0,0,0}}; butEnv_setChar(env, 1.0, ABUT_UPPIC, draw_uparrow, NULL); butEnv_setChar(env, 1.0, ABUT_DOWNPIC, draw_downarrow, NULL); butEnv_setChar(env, 1.0, ABUT_LEFTPIC, draw_leftarrow, NULL); butEnv_setChar(env, 1.0, ABUT_RIGHTPIC, draw_rightarrow, NULL); swin = wms_malloc(sizeof(AbutSwin)); MAGIC_SET(swin); if (flags & (ABUTSWIN_LSLIDE | ABUTSWIN_RSLIDE)) { swin->up = butAct_vCreate(pressUp, releaseVArrow, swin, parent, layer, BUT_DRAWABLE|BUT_PRESSABLE, ABUT_UPPIC, BUT_SRIGHT|BUT_SLEFT); but_setKeys(swin->up, upKeys); swin->down = butAct_vCreate(pressDown, releaseVArrow, swin, parent, layer, BUT_DRAWABLE|BUT_PRESSABLE, ABUT_DOWNPIC, BUT_SRIGHT|BUT_SLEFT); but_setKeys(swin->down, downKeys); swin->vSlide = butSlide_vCreate(v_moved, swin, parent, layer, BUT_DRAWABLE|BUT_PRESSABLE, 100,10,10); } if (flags & (ABUTSWIN_TSLIDE | ABUTSWIN_BSLIDE)) { swin->left = butAct_vCreate(pressLeft, releaseHArrow, swin, parent, layer, BUT_DRAWABLE|BUT_PRESSABLE, ABUT_LEFTPIC, BUT_SRIGHT|BUT_SLEFT); but_setKeys(swin->left, leftKeys); swin->right = butAct_vCreate(pressRight, releaseHArrow, swin, parent, layer, BUT_DRAWABLE|BUT_PRESSABLE, ABUT_RIGHTPIC, BUT_SRIGHT|BUT_SLEFT); but_setKeys(swin->right, rightKeys); swin->hSlide = butSlide_hCreate(hMoved, swin, parent, layer, BUT_DRAWABLE|BUT_PRESSABLE, 100,10,10); } swin->box = butBox_create(parent, layer, BUT_DRAWABLE); butBox_setColors(swin->box, BUT_SHAD, BUT_LIT); swin->win = butCan_create(swin, parent, layer, resize, NULL, redo_slider); swin->flags = flags; swin->timer = NULL; swin->xCenter = swin->yCenter = 0.0; swin->packet = packet; return(swin); } void abutSwin_resize(AbutSwin *swin, int x, int y, int w, int h, int slideW, int lineH) { int bx, by, bw, bh; int canWinW, canWinH, canViewW, canViewH; int butbw = butEnv_stdBw(butWin_env(swin->win)); int new_yoff = 0, new_xoff = 0; float yratio = swin->yCenter, xratio = swin->xCenter; assert(MAGIC(swin)); if (x == BUT_NOCHANGE) x = swin->x; if (y == BUT_NOCHANGE) y = swin->y; if (w == BUT_NOCHANGE) w = swin->w; if (h == BUT_NOCHANGE) h = swin->h; if (slideW == BUT_NOCHANGE) slideW = swin->slideW; if (lineH == BUT_NOCHANGE) lineH = swin->lineH; swin->x = x; swin->y = y; swin->w = w; swin->h = h; swin->slideW = slideW; swin->lineH = lineH; bx = x; by = y; bw = w; bh = h; if (swin->flags & ABUTSWIN_LSLIDE) { bx += slideW; bw -= slideW; } else if (swin->flags & ABUTSWIN_RSLIDE) { bw -= slideW; } if (swin->flags & ABUTSWIN_TSLIDE) { by += slideW; bh -= slideW; } else if (swin->flags & ABUTSWIN_BSLIDE) { bh -= slideW; } butCan_resizeView(swin->win, bx+butbw,by+butbw, bw-2*butbw,bh-2*butbw, FALSE); canViewW = bw - butbw*2; canViewH = bh - butbw*2; canWinW = butWin_w(swin->win); canWinH = butWin_h(swin->win); if (swin->flags & (ABUTSWIN_TSLIDE|ABUTSWIN_BSLIDE)) { new_xoff = xratio * (canWinW - canViewW) + 0.5; } if (swin->flags & (ABUTSWIN_LSLIDE|ABUTSWIN_RSLIDE)) { new_yoff = yratio * (canWinH - canViewH) + 0.5; } if (new_xoff > canWinW - canViewW) new_xoff = canWinW - canViewW; if (new_yoff > canWinH - canViewH) new_yoff = canWinH - canViewH; if (new_xoff < 0) new_xoff = 0; if (new_yoff < 0) new_yoff = 0; if (swin->flags & ABUTSWIN_LSLIDE) { if (bh - 2*slideW < butbw * 5) { but_resize(swin->up, x, by, slideW, bh/2); but_resize(swin->down, x, by + bh/2, slideW, (bh + 1) / 2); but_resize(swin->vSlide, 0, 0, 0, 0); butSlide_set(swin->vSlide, canWinH - canViewH, new_yoff, canViewH); v_moved(swin->vSlide, new_yoff, FALSE); } else { but_resize(swin->up, x,by,slideW,slideW); but_resize(swin->down, x,by+bh-slideW,slideW,slideW); but_resize(swin->vSlide, x,by+slideW,slideW,bh-2*slideW); butSlide_set(swin->vSlide, canWinH - canViewH, new_yoff, canViewH); v_moved(swin->vSlide, new_yoff, FALSE); } } else if (swin->flags & ABUTSWIN_RSLIDE) { but_resize(swin->up, x+w-slideW,by,slideW,slideW); but_resize(swin->down, x+w-slideW,by+h-slideW,slideW,slideW); but_resize(swin->vSlide, x+w-slideW,by+slideW,slideW,bh-2*slideW); butSlide_set(swin->vSlide, canWinH - canViewH, new_yoff, canViewH); v_moved(swin->vSlide, new_yoff, FALSE); } if (swin->flags & ABUTSWIN_TSLIDE) { but_resize(swin->left, bx, y, slideW, slideW); but_resize(swin->right, bx + bw - slideW, y, slideW, slideW); but_resize(swin->hSlide, bx + slideW, y, bw - 2 * slideW, slideW); butSlide_set(swin->hSlide, canWinW - canViewW, new_xoff, canViewW); v_moved(swin->hSlide, new_xoff, FALSE); } else if (swin->flags & ABUTSWIN_BSLIDE) { but_resize(swin->left, bx, y + h - slideW, slideW, slideW); but_resize(swin->right, bx + bw - slideW, y + h - slideW, slideW, slideW); but_resize(swin->hSlide, bx + slideW, y + h - slideW, bw - 2 * slideW, slideW); butSlide_set(swin->hSlide, canWinW - canViewW, new_xoff, canViewW); v_moved(swin->hSlide, new_xoff, FALSE); } but_resize(swin->box, bx,by,bw,bh); swin->canButW = bw - butbw*2; swin->canButH = bh - butbw*2; } static void draw_uparrow(void *packet, ButWin *win, int x, int y, int w, int h) { XPoint points[3]; Display *dpy = butEnv_dpy(butWin_env(win)); Window xwin = butWin_xwin(win); GC gc = butEnv_gc(butWin_env(win)); h &= ~1; w &= ~1; points[0].x = x; points[0].y = y+h/2; points[1].x = x+w/2; points[1].y = y; points[2].x = x+w; points[2].y = y+h/2; XFillPolygon(dpy, xwin, gc, points, 3, Nonconvex, CoordModeOrigin); } static void draw_downarrow(void *packet, ButWin *win, int x, int y, int w, int h) { XPoint points[3]; Display *dpy = butEnv_dpy(butWin_env(win)); Window xwin = butWin_xwin(win); GC gc = butEnv_gc(butWin_env(win)); h &= ~1; w &= ~1; points[0].x = x; points[0].y = y+h/2; points[1].x = x+w/2; points[1].y = y+h; points[2].x = x+w; points[2].y = y+h/2; XFillPolygon(dpy, xwin, gc, points, 3, Nonconvex, CoordModeOrigin); } static void draw_leftarrow(void *packet, ButWin *win, int x, int y, int w, int h) { XPoint points[3]; Display *dpy = butEnv_dpy(butWin_env(win)); Window xwin = butWin_xwin(win); GC gc = butEnv_gc(butWin_env(win)); h &= ~1; w &= ~1; points[0].x = x; points[0].y = y+h/2; points[1].x = x+w/2; points[1].y = y; points[2].x = x+w/2; points[2].y = y+h; XFillPolygon(dpy, xwin, gc, points, 3, Nonconvex, CoordModeOrigin); } static void draw_rightarrow(void *packet, ButWin *win, int x, int y, int w, int h) { XPoint points[3]; Display *dpy = butEnv_dpy(butWin_env(win)); Window xwin = butWin_xwin(win); GC gc = butEnv_gc(butWin_env(win)); h &= ~1; w &= ~1; points[0].x = x+w; points[0].y = y+h/2; points[1].x = x+w/2; points[1].y = y; points[2].x = x+w/2; points[2].y = y+h; XFillPolygon(dpy, xwin, gc, points, 3, Nonconvex, CoordModeOrigin); } static ButOut pressUp(But *but) { AbutSwin *swin; swin = but_packet(but); assert(MAGIC(swin)); butSlide_startSlide(swin->vSlide, TRUE, -2*swin->lineH, TRUE); return(0); } static ButOut pressDown(But *but) { AbutSwin *swin; swin = but_packet(but); assert(MAGIC(swin)); butSlide_startSlide(swin->vSlide, TRUE, 2*swin->lineH, TRUE); return(0); } static ButOut pressLeft(But *but) { AbutSwin *swin; swin = but_packet(but); assert(MAGIC(swin)); butSlide_startSlide(swin->hSlide, TRUE, -2*swin->lineH, TRUE); return(0); } static ButOut pressRight(But *but) { AbutSwin *swin; swin = but_packet(but); assert(MAGIC(swin)); butSlide_startSlide(swin->hSlide, TRUE, 2*swin->lineH, TRUE); return(0); } static ButOut releaseVArrow(But *but) { AbutSwin *swin = but_packet(but); assert(MAGIC(swin)); butSlide_stopSlide(swin->vSlide); return(0); } static ButOut releaseHArrow(But *but) { AbutSwin *swin = but_packet(but); assert(MAGIC(swin)); butSlide_stopSlide(swin->hSlide); return(0); } void abutSwin_vMove(AbutSwin *swin, int newLoc) { butSlide_set(swin->vSlide, BUT_NOCHANGE, newLoc, BUT_NOCHANGE); v_moved(swin->vSlide, newLoc, FALSE); } static ButOut v_moved(But *but, int new_yoff, bool newPress) { AbutSwin *swin = but_packet(but); assert(MAGIC(swin)); if (butWin_viewH(swin->win) == butWin_h(swin->win)) swin->yCenter = 0.0; else swin->yCenter = (float)new_yoff / (float)(butWin_h(swin->win) - butWin_viewH(swin->win)); if (swin->yCenter > 1.0) swin->yCenter = 1.0; if (swin->yCenter < 0.0) swin->yCenter = 0.0; butCan_slide(swin->win, BUT_NOCHANGE, new_yoff, FALSE); return(0); } static ButOut hMoved(But *but, int newXOff, bool newPress) { AbutSwin *swin = but_packet(but); assert(MAGIC(swin)); if (butWin_viewW(swin->win) == butWin_w(swin->win)) swin->xCenter = 0.0; else swin->xCenter = (float)newXOff / (float)(butWin_w(swin->win) - butWin_viewW(swin->win)); if (swin->xCenter > 1.0) swin->xCenter = 1.0; if (swin->xCenter < 0.0) swin->xCenter = 0.0; butCan_slide(swin->win, newXOff, BUT_NOCHANGE, FALSE); return(0); } void abutSwin_destroy(AbutSwin *swin) { assert(MAGIC(swin)); MAGIC_UNSET(swin); wms_free(swin); } static void redo_slider(void *packet, int xoff, int yoff, int w, int h, int viewW, int viewH) { AbutSwin *swin = packet; assert(MAGIC(swin)); if (swin->flags & (ABUTSWIN_TSLIDE|ABUTSWIN_BSLIDE)) { butSlide_set(swin->hSlide, w-viewW, xoff, viewW); if (viewW == w) swin->xCenter = 0.0; else swin->xCenter = (float)xoff / (float)(w - viewW); } if (swin->flags & (ABUTSWIN_LSLIDE|ABUTSWIN_RSLIDE)) { butSlide_set(swin->vSlide, h-viewH, yoff, viewH); if (viewH == h) swin->yCenter = 0.0; else swin->yCenter = (float)yoff / (float)(h - viewH); } } #endif /* X11_DISP */ pente-2.2.5/wmslib/src/abut/msg.c0100664000076400007640000002611207045637750015034 0ustar wmswms/* * src/msg.c, part of wmslib library * Copyright (C) 1994-1995 William Shubert. * See "configure.h.in" for more copyright information. */ #include #include #include #include #include #include #include #include #include #include static ButOut unmap(ButWin *win); static ButOut wDestroy(ButWin *win); static ButOut resize(ButWin *win); static ButOut ok_pressed(But *but); static void checkNewSize(AbutMsg *mwin, ButWin *win); static void calcDims(Abut *abut, int fontNum, const char *text, int *w, int *h, int *textH, int numTins); static ButOut msg_resize(ButWin *win, AbutMsg *mwin); static void fillboxDead(But *but); /* * UseMsg is never accessed. We just need a void * guaranteed to be * different from any the user could pass us. */ static int useMsg = 0; AbutMsg *abutMsg_inCreate(Abut *a, ButWin *win, int layer, const char *text, void *packet, int numTins, const AbutMsgTin *tinList) { static AbutMsgOpt ok[1]; static ButKey ka_ok[] = {{XK_Return, 0, ShiftMask}, {XK_KP_Enter, 0, ShiftMask}, {0,0,0}}; ok[0].name = a->ok; ok[0].callback = ok_pressed; ok[0].keyEq = ka_ok; ok[0].packet = &useMsg; return(abutMsg_optInCreate(a, win, layer, text, NULL, NULL, 1, ok, numTins, tinList)); } AbutMsg *abutMsg_optInCreate(Abut *a, ButWin *win, int layer, const char *text, ButOut (*destroy)(void *packet), void *packet, int numButs, const AbutMsgOpt *optList, int numTins, const AbutMsgTin *tinList) { ButEnv *env; AbutMsg *mwin; int winW, winH; int i; void *butPacket; assert(MAGIC(a)); assert(a->env == butWin_env(win)); env = a->env; mwin = wms_malloc(sizeof(AbutMsg)); MAGIC_SET(mwin); mwin->abut = a; mwin->win = win; mwin->numButs = numButs; mwin->buts = wms_malloc(numButs * sizeof(But *)); mwin->numTins = numTins; mwin->tins = wms_malloc(numTins * sizeof(But *)); mwin->tinTitles = wms_malloc(numTins * sizeof(But *)); mwin->butDesc = optList; mwin->destroy = destroy; mwin->packet = packet; mwin->layer = layer; calcDims(a, 0, text, &winW, &winH, &mwin->textH, numTins); mwin->w = winW; mwin->h = winH; mwin->box = butBoxFilled_create(win, layer, BUT_DRAWABLE); but_setPacket(mwin->box, mwin); but_setDestroyCallback(mwin->box, fillboxDead); butBoxFilled_setColors(mwin->box, a->ulColor, a->lrColor, a->bgColor); butBoxFilled_setPixmaps(mwin->box, a->ulPixmap, a->lrPixmap, a->bgPixmap); mwin->text = butTblock_create(win, layer+1, BUT_DRAWABLE, text, butText_just); for (i = 0; i < numButs; ++i) { butPacket = optList[i].packet; if (butPacket == &useMsg) butPacket = mwin; mwin->buts[i] = butCt_create(optList[i].callback, butPacket, win, layer+1, BUT_DRAWABLE|BUT_PRESSABLE, optList[i].name); if (optList[i].keyEq) but_setKeys(mwin->buts[i], optList[i].keyEq); } for (i = 0; i < numTins; ++i) { if (tinList[i].name) mwin->tinTitles[i] = butText_create(win, layer+1, BUT_DRAWABLE, tinList[i].name, butText_left); else mwin->tinTitles[i] = NULL; mwin->tins[i] = butTextin_create(tinList[i].callback, packet, win, layer+1, BUT_DRAWABLE|BUT_PRESSABLE, tinList[i].def, 500); } if (butWin_w(win)) msg_resize(win, mwin); return(mwin); } AbutMsg *abutMsg_winInCreate(Abut *a, const char *title, const char *text, void *packet, int numTins, const AbutMsgTin *tinList) { static AbutMsgOpt ok[1]; static ButKey ka_ok[] = {{XK_Return, 0, ShiftMask|ControlMask}, {XK_KP_Enter, 0, ShiftMask|ControlMask}, {0, 0, 0}}; ok[0].name = a->ok; ok[0].callback = ok_pressed; ok[0].keyEq = ka_ok; ok[0].packet = &useMsg; return(abutMsg_winOptInCreate(a, title, text, NULL, NULL, 1, ok, numTins, tinList)); } AbutMsg *abutMsg_winOptInCreate(Abut *a, const char *title, const char *text, ButOut (*destroy)(void *packet), void *packet, int numButs, const AbutMsgOpt *optList, int numTins, const AbutMsgTin *tinList) { ButEnv *env; AbutMsg *mwin; ButWin *win; int winW, winH; int i; void *butPacket; assert(MAGIC(a)); env = a->env; mwin = wms_malloc(sizeof(AbutMsg)); MAGIC_SET(mwin); mwin->abut = a; mwin->numButs = numButs; mwin->buts = wms_malloc(numButs * sizeof(But *)); mwin->numTins = numTins; mwin->tins = wms_malloc(numTins * sizeof(But *)); mwin->tinTitles = wms_malloc(numTins * sizeof(But *)); mwin->butDesc = optList; mwin->destroy = destroy; mwin->packet = packet; mwin->layer = 0; calcDims(a, 0, text, &winW, &winH, &mwin->textH, numTins); mwin->w = winW; mwin->h = winH; mwin->win = win = butWin_create(mwin, env, title, winW, winH, unmap, NULL, resize, wDestroy); butWin_activate(win); mwin->box = butBoxFilled_create(win, 0, BUT_DRAWABLE); butBoxFilled_setColors(mwin->box, a->ulColor, a->lrColor, a->bgColor); butBoxFilled_setPixmaps(mwin->box, a->ulPixmap, a->lrPixmap, a->bgPixmap); mwin->text = butTblock_create(win, 1, BUT_DRAWABLE, text, butText_just); for (i = 0; i < numButs; ++i) { butPacket = optList[i].packet; if (butPacket == &useMsg) butPacket = mwin; mwin->buts[i] = butCt_create(optList[i].callback, butPacket, win, 1, BUT_DRAWABLE|BUT_PRESSABLE, optList[i].name); if (optList[i].keyEq) but_setKeys(mwin->buts[i], optList[i].keyEq); } for (i = 0; i < numTins; ++i) { mwin->tinTitles[i] = butText_create(win, 1, BUT_DRAWABLE, tinList[i].name, butText_left); mwin->tins[i] = butTextin_create(tinList[i].callback, packet, win, 1, BUT_DRAWABLE|BUT_PRESSABLE, tinList[i].def, 150); if (tinList[i].flags & abutMsgTinFlags_secret) { butTextin_setHidden(mwin->tins[i], TRUE); } } if (butWin_w(win)) msg_resize(win, mwin); return(mwin); } static ButOut unmap(ButWin *win) { butWin_destroy(win); return(0); } static ButOut wDestroy(ButWin *win) { AbutMsg *mwin = butWin_packet(win); ButOut result = 0; assert(MAGIC(mwin)); mwin->win = NULL; if (mwin->buts) { wms_free(mwin->buts); mwin->buts = NULL; } if (mwin->tins) { wms_free(mwin->tins); wms_free(mwin->tinTitles); mwin->tins = NULL; mwin->tinTitles = NULL; } if (mwin->destroy) result = mwin->destroy(mwin->packet); MAGIC_UNSET(mwin); wms_free(mwin); return(result); } static ButOut resize(ButWin *win) { return(msg_resize(win, butWin_packet(win))); } static ButOut msg_resize(ButWin *win, AbutMsg *mwin) { int x, y, w, h, buth; ButEnv *env = butWin_env(win); int bw = butEnv_stdBw(env); int butX, butW, i; int maxTinNameLen = 0, newLen; assert(MAGIC(mwin)); checkNewSize(mwin, win); x = (butWin_w(win) - mwin->w) / 2; y = (butWin_h(win) - mwin->h) / 2; w = mwin->w; h = mwin->h; buth = mwin->abut->butH; but_resize(mwin->box, x,y, w,h); butTblock_resize(mwin->text, x+bw*2, y+bw*2, w - bw*4); for (butX = bw*2, i = 0; i < mwin->numButs; ++i) { butW = (w-bw-butX + (mwin->numButs - i) / 2) / (mwin->numButs - i) - bw; but_resize(mwin->buts[i], x+butX, y+h-bw*2-buth, butW, buth); butX += butW + bw; } for (i = 0; i < mwin->numTins; ++i) { if (mwin->tinTitles[i]) { newLen = butText_resize(mwin->tinTitles[i], x + bw*2, y + h - (buth + bw)*(mwin->numTins - i + 1) - bw*2, buth) + bw; if (newLen > maxTinNameLen) maxTinNameLen = newLen; } } for (i = 0; i < mwin->numTins; ++i) { but_resize(mwin->tins[i], x + bw*2 + maxTinNameLen, y + h - (buth + bw)*(mwin->numTins - i + 1) - bw*2, w - bw*4 - maxTinNameLen, buth); } return(0); } static void checkNewSize(AbutMsg *mwin, ButWin *win) { ButEnv *env = butWin_env(win); int textH, butH; textH = butEnv_fontH(env, 0); butH = mwin->abut->butH; if (textH != mwin->textH) { calcDims(mwin->abut, 0, butTblock_getText(mwin->text), &mwin->w, &mwin->h, &mwin->textH, mwin->numTins); if (mwin->layer == 0) butWin_resize(win, mwin->w, mwin->h); } } static ButOut ok_pressed(But *but) { AbutMsg *msg; msg = but_packet(but); assert(MAGIC(msg)); if (msg->layer == 0) butWin_destroy(msg->win); else abutMsg_destroy(but_packet(but), TRUE); return(0); } void abutMsg_destroy(AbutMsg *msg, bool propagate) { int i; int x = 0, y = 0, w = 0, h = 0; assert(MAGIC(msg)); if (propagate == FALSE) { msg->destroy = NULL; } if (msg->box) { x = but_x(msg->box); y = but_y(msg->box); w = but_w(msg->box); h = but_h(msg->box); } if (msg->buts) { but_setPacket(msg->box, NULL); but_destroy(msg->box); but_destroy(msg->text); for (i = 0; i < msg->numButs; ++i) but_destroy(msg->buts[i]); for (i = 0; i < msg->numTins; ++i) { but_destroy(msg->tins[i]); but_destroy(msg->tinTitles[i]); } } if ((msg->layer == 0) && msg->win) butWin_destroy(msg->win); else { butWin_redraw(msg->win, x, y, w, h); MAGIC_UNSET(msg); wms_free(msg); } } static void calcDims(Abut *abut, int fontNum, const char *text, int *w, int *h, int *textHOut, int numTins) { ButEnv *env = abut->env; int textW, textH, butH, butSpc; int winW, winH, actualH, bw; double b, c; textW = butEnv_textWidth(env, text, fontNum); *textHOut = textH = butEnv_fontH(env, fontNum); butH = abut->butH; bw = butEnv_stdBw(env); butSpc = butH + bw; /* * This is based on the calculations: * winW = 2*winH * (winW - 4*bw) * (winH - (4*bw + butSpc*(numTins + 1))) = textW*textH * Solve for winW... * (winW - 4*bw) * (0.5*winW - 4*bw - butSpc*numTins - butSpc) = * textW*textH * 0.5*winW^2 - winW*(-4*bw-butSpc*numTins-butSpc-2*bw) + * 16*bw*bw+4*bw*butSpc*numTins+4*bw*butSpc - textW*textH = 0 * winW^2 - winW*(-12*bw-2*butSpc*numTins-2*butSpc) + * 32*bw*bw+8*bw*butSpc*numTins+8*bw*butSpc - 2*textW*textH = 0 * Using the quadratic equation, notice a is 1.0, and solve * winW = (-b+sqrt(b*b-4*a*c))/2*a */ b = (double)(-12 * bw - 2 * butSpc * numTins - 2 * butSpc); c = (double)(32*bw*bw + 8*bw*butSpc*numTins + 8*bw*butSpc - 2 * textW*textH); winW = (int)((-b + sqrt(b*b-4*c)) * 0.5 + 0.5); winH = winW / 2; if (winH < 2*textH + butSpc*(numTins + 1) + 4*butEnv_stdBw(env)) winH = 2*textH + butSpc*(numTins + 1) + 4*butEnv_stdBw(env); winW = winH * 2; actualH = butTblock_guessH(env, text, winW - 4*butEnv_stdBw(env), fontNum) + butSpc*(numTins + 1) + 4*butEnv_stdBw(env); if (actualH > winH) { winH = actualH; winW = 2*winH; } *w = winW; *h = winH; } static void fillboxDead(But *but) { AbutMsg *mwin; assert(MAGIC(but)); mwin = but_packet(but); if (mwin) { assert(MAGIC(mwin)); if (mwin->buts) { wms_free(mwin->buts); mwin->buts = NULL; } if (mwin->tins) { wms_free(mwin->tins); wms_free(mwin->tinTitles); mwin->tins = NULL; mwin->tinTitles = NULL; } mwin->box = mwin->text = NULL; mwin->win = NULL; } } pente-2.2.5/wmslib/src/wms.h0100664000076400007640000001536607045637750014137 0ustar wmswms/* * wmslib/include/wms.h, part of wmslib (Library functions) * Copyright (C) 1994 William Shubert. * See "configure.h.in" for more copyright information. * * This contains a bunch of definitions I always like to have. * This should ALWAYS be AFTER the last system include, BEFORE the first * local include. */ #ifndef _WMS_H_ #define _WMS_H_ 1 #include #ifdef STDC_HEADERS # include # include #endif /* STDC_HEADERS */ #include #include #include #include #if TIME_WITH_SYS_TIME # include # include #else /* !AC_TIME_WITH_SYS_TIME */ # if HAVE_SYS_TIME_H # include # else /* !HAVE_SYS_TIME_H */ # include # endif /* HAVE_SYS_TIME_H */ #endif /* AC_TIME_WITH_SYS_TIME */ #if X11_DISP # include # include # include #endif /* X11_DISP */ #if SUN_SOUND # include # include # include #endif /* SUN_SOUND */ /* Get all these headers out of the way here. */ #include #include #if HAVE_STDLIB_H # include #endif #if HAVE_UNISTD_H # include #endif /* HAVE_UNISTD_H */ #if HAVE_ASSERT_H && DEBUG /* * In my version of gdb, if the program takes an assertion, most of the time * the stack backtrace DOESN'T WORK! Grrr...but pressing ctrl-c always * seems to work, so my asserts print the assertion then wait patiently for * the ctrl-c. */ #define BROKEN_STUPID_ASSERT_WITH_GDB 0 #if BROKEN_STUPID_ASSERT_WITH_GDB || !HAVE_ASSERT_H #define assert(exp) do{if(!(exp)){fprintf(stderr,__FILE__":%d: Failed assertion %s\n",__LINE__,#exp);for(;;);}}while(0) #else /* assert works fine */ #include #endif #else #define assert(ignore) #endif /* HAVE_ASSERT_H && DEBUG */ #if STDC_HEADERS || HAVE_STRING_H #include /* An ANSI string.h and pre-ANSI memory.h might conflict. */ #if !STDC_HEADERS && HAVE_MEMORY_H #include #endif /* not STDC_HEADERS and HAVE_MEMORY_H */ #else /* not STDC_HEADERS and not HAVE_STRING_H */ #include #define memcpy(d,s,n) bcopy((s),(d),(n)) #define strchr index #define strrchr rindex #endif /* Not STDC_HEADERS and not HAVE_STRING_H */ #ifdef bool #undef bool #endif /* bool */ #define bool int #ifndef TRUE #define FALSE 0 #define TRUE 1 #endif /* int32 must be AT LEAT 32 bits. More is OK. */ #ifdef int32 #undef int32 #endif /* int32 */ #if (SIZEOF_INT >= 4) #define int32 int #else /* SIZEOF_INT < 4 */ #define int32 long #endif #ifdef uint32 #undef uint32 #endif /* uint32 */ #define uint32 unsigned int32 #ifdef uchar #undef uchar #endif /* uchar */ #define uchar unsigned char #ifdef ushort #undef ushort #endif /* ushort */ #define ushort unsigned short #ifdef uint #undef uint #endif /* uint */ #define uint unsigned int #ifdef ulong #undef ulong #endif #define ulong unsigned long #define int32_max 0x7fffffff #define int32_min (-int32_max-1) #define int_max ((int)((((1 << (8*(sizeof(int)-2)))-1)<<1)+1)) #define int_min (-int_max-1) #define uint_max ((((1U << (8*(sizeof(uint)-1)))-1)<<1)+1) #define long_max ((long)((((1L << (8*(sizeof(long)-2)))-1)<<1)+1)) #define long_min (-long_max-1) #define ulong_max ((((1UL << (8*(sizeof(ulong)-1)))-1)<<1)+1) /* * This atoi sets err to TRUE if there's an overflow or a non-digit * character around. If err is NULL it is just like regular atoi(). */ extern int wms_atoi(const char *str, bool *err); extern double wms_atof(const char *str, bool *err); /* * Debugging aide 1 - The MAGIC macros. * * In every dynamically allocated structure, add this: * #if DEBUG * int magic; * #endif / * DEBUG * / * Then, every time you alloc a structure, _immediately_ do a MAGIC_SET(foo) * on the newly freed buffer. Last thing before you free a structure, do * a MAGIC_UNSET(foo). Then, before you access a structure, always first * say "assert(MAGIC(foo))". This way, if you touch a structure after you * free it, an assertion will trip! And if debug is set to zero, the * checks all disappear and leave you with an efficient program. */ #if DEBUG #define MAGIC_NUM 31415927 /* Any random number will do. */ #define MAGIC_SET(x) ((x)->magic = MAGIC_NUM) #define MAGIC_UNSET(x) ((x)->magic = 0) #define MAGIC(x) ((x)->magic == MAGIC_NUM) #define MAGICNULL(x) (((x) == NULL) || ((x)->magic == MAGIC_NUM)) #define MAGIC_STRUCT int magic; #else #define MAGIC_SET(x) #define MAGIC_UNSET(x) #define MAGIC(x) 1 #define MAGIC_STRUCT #endif /* magic */ /* * Debugging aide 2 - The wms_malloc routines * * This makes it much easier to spot memory leaks and objects freed multiple * times. Basically, every time you call wms_alloc_stat(), you will see * how much memory is allocated. If this grows indefinitely, you know * that you have a memory leak. Doing wms_alloc_ring_show() will list * EVERY wms_malloc that hasn't yet been freed. Ugh. Probably way * more than you need to see. So when you call wms_alloc_ring_reset(), * the list gets cleared, so call wms_alloc_ring_reset(), do the stuff * that shouldn't leave buffers allocated but does, then call * wms_alloc_ring_show() and voila! The files and lines where your * memory leak is coming from! * As in the MAGIC macros, when DEBUG is set to zero this stuff all * disappears. Good thing, too, because it consumes bunches of memory and * a significant amount of CPU cycles. */ #if DEBUG extern void wms_free(void *deadbuf); extern void wms_alloc_stat(void); #define wms_malloc(x) wms_malloc_debug(x, __FILE__, __LINE__) extern void *wms_malloc_debug(uint bufsize, const char *file, int line); void wms_alloc_ring_reset(void); void wms_alloc_ring_show(void); #else #define wms_free free extern void *wms_malloc(uint bufsize); #endif extern const char *wms_progname; /* * A StdInt32 is an int that is exactly 4 bytes long and in little endian * format. */ #if SIZEOF_INT == 4 typedef int StdInt32; #elif SIZEOF_SHORT == 4 typedef short StdInt32; #elif SIZEOF_LONG == 4 typedef long StdInt32; #else #error You must have a 4 byte data type to compile this program! #endif #if !WORDS_BIGENDIAN #define stdInt32_int(i) (i) #define int_stdInt32(i) (i) #else /* Big endian machine. */ extern int stdInt32_int(StdInt32 i); extern StdInt32 int_stdInt32(int i); #endif #if !HAVE_STRERROR extern const char *strerror(int error); #endif #if !HAVE_STRCASECMP extern int strcasecmp(const char *s1, const char *s2); #endif #if !HAVE_MEMMOVE extern void *memmove(void *dest, const void *src, size_t n); #endif #if !HAVE_GETDTABLESIZE extern int getdtablesize(void); #endif #endif /* _WMS_H_ */ pente-2.2.5/wmslib/src/wms/clp.h0100664000076400007640000001120007045640231014660 0ustar wmswms/* * wmslib/src/wms/clp.h, part of wmslib (Library functions) * Copyright (C) 1994-1996 William Shubert. * See "configure.h.in" for more copyright information. * * Command Line Parse. */ #ifndef _WMS_CLP_H_ #ifndef _WMS_STR_H_ #include #endif #ifdef _WMS_CLP_H_ Levelization Error. #endif #define _WMS_CLP_H_ 1 /********************************************************************** * Data types. These are all visible to the application. **********************************************************************/ struct ClpEntry_struct; /* Public. */ #define CLPSETUP_BOOL 0x01 /* Is it "-[no]" or "- "? */ #define CLPSETUP_SHOWBOOL 0x02 /* Show "[no]" in the help. */ #define CLPSETUP_NOSAVE 0x04 #define CLPSETUP_ENDFLAG 0x08 #define CLPSETUP_HELP 0x10 /* This switch gives you help. */ #define CLPSETUP_SHOWARG 0x20 typedef struct ClpSetup_struct { const char *name; /* NULL for just a label. */ const char *defVal; const char *desc; /* NULL if it doesn't show up in the help. */ uint flags; bool (*test)(struct ClpEntry_struct *entry); } ClpSetup; typedef enum { clpWhere_unset, clpWhere_rcfile, clpWhere_xdefs, clpWhere_cmdline, clpWhere_dup } ClpWhere; /* Private. */ typedef enum { clpDtype_int, clpDtype_double, clpDtype_bool, clpDtype_string, clpDtype_end } ClpDtype; typedef struct ClpEntry_struct { const char *name; const char *desc; uint flags; bool (*test)(struct ClpEntry_struct *entry); ClpWhere where; ClpDtype type; int numStrs, maxStrs; union { int ival; double dval; Str *strList; bool bval; } storage; MAGIC_STRUCT } ClpEntry; typedef struct Clp_struct { ClpEntry *infos; int numInfos; MAGIC_STRUCT } Clp; /********************************************************************** * Routines available **********************************************************************/ extern Clp *clp_create(const ClpSetup vars[]); extern void clp_destroy(Clp *clp); /* * clp_rCmdline returns the number of arguments left on the command * line, or CLP_ARGS_NOGOOD if there was an error. */ extern int clp_rCmdline(Clp *cltab, char *argv[]); /* * clp_rFile returns FALSE if it can't find the file at all. */ extern bool clp_rFile(Clp *cltab, const char *fname); extern void clp_wFile(Clp *cltab, const char *fname, const char *pname); extern ClpEntry *clp_lookup(Clp *clp, const char *varName); #define clp_where(clp, str) (clp_lookup(clp, str)->where) #define clpEntry_where(ce) ((ce)->where) extern int clpEntry_iGetInt(ClpEntry *ce, bool *err); #define clp_iGetInt(clp, str, e) clpEntry_iGetInt(clp_lookup(clp, str), e) #define clpEntry_getInt(ce) clpEntry_iGetInt(ce, NULL) #define clp_getInt(clp, str) clpEntry_getInt(clp_lookup(clp, str)) extern double clpEntry_iGetDouble(ClpEntry *ce, bool *err); #define clpEntry_getDouble(ce) clpEntry_iGetDouble(ce, NULL) #define clp_getDouble(clp, str) clpEntry_getDouble(clp_lookup(clp,str)) #define clpEntry_numStrs(ce) ((ce)->numStrs) extern const char *clpEntry_iGetStrNum(ClpEntry *ce, int num, bool *err); #define clpEntry_getStrNum(ce, n) clpEntry_iGetStrNum(ce, n, NULL) #define clp_getStrNum(clp, s, n) clpEntry_getStrNum(clp_lookup(clp, s), n) #define clpEntry_iGetStr(ce, e) clpEntry_iGetStrNum(ce, 0, e) #define clpEntry_getStr(ce) clpEntry_iGetStr(ce, NULL) #define clp_getStr(clp, str) clpEntry_getStr(clp_lookup(clp, str)) extern bool clpEntry_iGetBool(ClpEntry *ce, bool *err); #define clpEntry_getBool(ce) clpEntry_iGetBool(ce, NULL) #define clp_getBool(clp, str) clpEntry_getBool(clp_lookup(clp, str)) extern bool clpEntry_setInt(ClpEntry *ce, int val); #define clp_setInt(c, s, v) clpEntry_setInt(clp_lookup(c, s), v) extern bool clpEntry_setDouble(ClpEntry *ce, double val); #define clp_setDouble(c, s, v) clpEntry_setDouble(clp_lookup(c, s), v) extern bool clpEntry_setStrNum(ClpEntry *ce, const char *val, int num); #define clp_setStrNum(c, s, v, n) clpEntry_setStrNum(clp_lookup(c, s), v, n) #define clpEntry_setStr(ce, v) clpEntry_setStrNum(ce, v, 0) #define clp_setStr(c, s, v) clpEntry_setStr(clp_lookup(c, s), v) extern bool clpEntry_setBool(ClpEntry *ce, bool val); #define clp_setBool(c, s, v) clpEntry_setBool(clp_lookup(c, s), v) /********************************************************************** * Handy macros and constants. **********************************************************************/ #define CLPSETUP_MSG(message) {NULL, NULL, message, 0, NULL} #define CLPSETUP_END {NULL,NULL,NULL,CLPSETUP_ENDFLAG, NULL} #define CLP_ARGS_NOGOOD -1 #endif /* _WMS_CLP_H_ */ pente-2.2.5/wmslib/src/wms/clp-x.h0100664000076400007640000000105407045640231015133 0ustar wmswms/* * wmslib/src/wms/clp.h, part of wmslib (Library functions) * Copyright (C) 1994-1996 William Shubert. * See "configure.h.in" for more copyright information. * * Command Line Parse. */ #ifndef _WMS_CLP_X_H_ #define _WMS_CLP_X_H_ 1 #ifndef _WMS_CLP_H_ #include #endif /********************************************************************** * Functions **********************************************************************/ extern void clp_rXDefaults(Clp *cltab, Display *dpy, const char *name); #endif /* _WMS_CLP_X_H_ */ pente-2.2.5/wmslib/src/wms/rnd.h0100664000076400007640000000133607045640231014676 0ustar wmswms/* * wmslib/src/wms/rnd.h, part of wmslib (Library functions) * Copyright (C) 1994-1995 William Shubert. * See "configure.h.in" for more copyright information. */ #ifndef _WMS_RND_H_ #define _WMS_RND_H_ 1 #ifndef _WMS_H_ #include #endif #define RND_DATASIZE 31 #define RND_INDENT 3 typedef struct Rnd_struct { int indent; uint32 data[RND_DATASIZE]; MAGIC_STRUCT } Rnd; extern int rnd_int(Rnd *state); /* No negative numbers. */ extern uint rnd_uint(Rnd *state); /* Random bit field. */ extern int rnd_int32(Rnd *state); extern uint rnd_uint32(Rnd *state); extern Rnd *rnd_create(uint seed); extern void rnd_destroy(Rnd *state); extern float rnd_float(Rnd *state); #endif /* _WMS_RND_H_ */ pente-2.2.5/wmslib/src/wms/snd.h0100664000076400007640000000431007045640231014672 0ustar wmswms/* * wmslib/include/snd.h, part of wmslib (Library functions) * Copyright (C) 1994 William Shubert. * See "configure.h.in" for more copyright information. */ #ifndef _WMS_SND_H_ #define _WMS_SND_H_ 1 /********************************************************************** * Data types **********************************************************************/ /* Public. */ typedef enum { sndInit_ok, sndInit_busy, sndInit_broken } SndInit; /* * This is a public type, but the "sndState_i*" values should never be used * by the application - they are for internal use only. */ typedef enum { sndState_iOff, sndState_off, sndState_partOpen, sndState_iWantOpen, sndState_fullOpen, sndState_oldState, sndState_iTempOpen } SndState; /* Opaque. */ typedef struct Snd_struct { int len; uchar *data; bool converted; int cvtlen; union { uchar *dsp; ushort *dsp1; } cvtdata; struct Snd_struct *next; } Snd; /********************************************************************** * Global variables **********************************************************************/ /* * Feel free to set this pointer to point to any old handler. By default * it points to a routine that dumps errStr to stderr for the first * error then ignores the rest. * It gets called ONLY by snd_play; snd_init returns an error code that you * should check for. * errStr is always the same as snd_error. */ extern void (*snd_errHandler)(SndInit errType, char *errStr); extern char snd_error[]; /********************************************************************** * Functions **********************************************************************/ extern SndInit snd_init(SndState newState, int newVolume); extern void snd_play(Snd *sound); extern void snd_deinit(void); /********************************************************************** * Macros, constants, etc. **********************************************************************/ #define snd_define(data) {sizeof(data), data, FALSE,0,{NULL},NULL} #define SND_MAXVOL 10000 /* Just for kicks, you know? */ #if SUN_SOUND || LINUX_SOUND #define SND_AVAILABLE 1 #else #define SND_AVAILABLE 0 #endif #endif /* _WMS_SND_H_ */ pente-2.2.5/wmslib/src/wms/str.h0100664000076400007640000000400207045640231014714 0ustar wmswms/* * wmslib/src/wms/str.h, part of wmslib (Library functions) * Copyright (C) 1994-1995 William Shubert. * See "configure.h.in" for more copyright information. */ #ifndef _WMS_STR_H_ #define _WMS_STR_H_ 1 #ifndef _WMS_H_ #include #endif /********************************************************************** * Data Types **********************************************************************/ typedef struct Str_struct { char *chars; int len; int maxLen; MAGIC_STRUCT } Str; /********************************************************************** * Functions **********************************************************************/ extern Str *str_create(void); extern Str *str_createStr(const Str *s); extern Str *str_createChars(const char *chars); extern Str *str_createChar(char c); extern void str_destroy(Str *s); extern void str_init(Str *s); extern void str_initStr(Str *s, const Str *src); extern void str_initChars(Str *s, const char *src); extern void str_initCharsLen(Str *s, const char *src, int len); extern void str_deinit(Str *s); #define str_len(s) ((s)->len) #define str_chars(s) ((const char *)((s)->chars)) extern void str_copy(Str *dest, const Str *src); extern void str_copyChars(Str *dest, const char *src); extern void str_copyCharsLen(Str *dest, const char *src, int len); extern void str_copyChar(Str *dest, char src); extern void str_print(Str *dest, const char *fmt, ...); extern void str_cat(Str *dest, const Str *src); extern void str_catChars(Str *dest, const char *src); extern void str_catCharsLen(Str *dest, const char *src, int len); extern void str_catChar(Str *dest, char src); extern void str_catInt(Str *dest, int src); /* str_alphaCmd is useful in qsort and bsearch. */ extern int str_alphaCmp(const void *a, const void *b); #define str_clip(s, l) \ do { \ if ((l) < (s)->len) \ (s)->chars[(s)->len = (l)] = '\0'; \ } while(0) #endif /* _WMS_STR_H_ */ pente-2.2.5/wmslib/src/but/net.h0100664000076400007640000001142507045637750014701 0ustar wmswms/* * wmslib/include/but/net.h, part of wmslib (Library functions) * Copyright (C) 1994-1995 William Shubert. * See "configure.h.in" for more copyright information. * * Includes for button networking. */ #ifndef _BUTNET_H_ #define _BUTNET_H_ 1 #include /********************************************************************** * Constants **********************************************************************/ /* Public. */ #define BUTNET_MAXCMD (16*1024) /* Max length of 1 net command. */ /* Private. */ /* * These really should be an enum, but then I'd be treating the enum like an * int when I do int_stdInt32() to it, so I may as well just leave it as * an int. */ #define BUTNET_PROTOWHO 0 #define BUTNET_CLOSE 1 #define BUTNET_USERDATA 2 #define BUTNET_MOUSE 3 #define BUTNET_MOUSEACK 4 #define BUTNET_NEWFLAGS 5 #define BUTNET_BUTSPEC 6 /********************************************************************** * Types **********************************************************************/ /* Private. */ struct ButLnet_struct { struct ButEnv_struct *env; void *packet; bool valid, error; int errNum; char *protocol; ButOut (*ocallback)(struct ButRnet_struct *net); ButOut (*callback)(struct ButRnet_struct *net, void *cmd, int cmdLen); ButOut (*ccallback)(struct ButRnet_struct *net, const char *reason); int fd; MAGIC_STRUCT }; /* ButLnet typedef in but.h */ typedef enum { butRnetState_pwWait, butRnetState_pwAccWait, butRnetState_accWait, butRnetState_open, butRnetState_closing, butRnetState_closed } ButRnetState; typedef struct ButNetMsg_struct { StdInt32 length; StdInt32 type; union { struct { StdInt32 context; /* This is the client's new context. */ char proto[100]; char who[100]; } protoWho; char close[BUTNET_MAXCMD]; char userData[BUTNET_MAXCMD]; struct { StdInt32 context, win, type, x,y, w,h; } mouse; /* mouseAck needs no data. */ struct { StdInt32 butId; StdInt32 newFlags; } newFlags; struct { StdInt32 butId; char butData[BUTNET_MAXCMD - sizeof(StdInt32)]; } butSpec; } perType; } ButNetMsg; struct ButRnet_struct { struct ButEnv_struct *env; int partner, rmtPartner; void *packet; ButRnetState state; bool error, lookupError, butNetError; int errNum; const char *who, *protocol; ButOut (*ocallback)(struct ButRnet_struct *net); ButOut (*callback)(struct ButRnet_struct *net, void *cmd, int cmdLen); ButOut (*ccallback)(struct ButRnet_struct *net, const char *reason); int wBufSize, wBufStart, wBufLen; char *wBuffer; int rBufAmt; /* How much stuff in the rBuffer? */ int rBufLen; int rBufMsgLen; struct ButNetMsg_struct rBuffer; int fd; int lWinId, lx,ly, lw,lh, lType; int lPress, lTwitch; ButRcur rc; bool ackNeeded, mouseMove; MAGIC_STRUCT }; /* ButLnet typedef in but.h */ /********************************************************************** * Functions **********************************************************************/ /* Public. */ #define butRnet_valid(net) ((net)->state == butRnetState_open) #define butRnet_error(net) ((net)->error) #define butRnet_lookupError(net) ((net)->lookupError) #define butRnet_specialError(net) ((net)->specialError) #define butRnet_errNum(net) ((net)->errNum) #define butRnet_packet(net) ((net)->packet) #define butRnet_who(net) ((net)->who) #define butRnet_protocol(net) ((net)->protocol) #define butLnet_valid(net) ((net)->valid) #define butLnet_error(net) ((net)->error) #define butLnet_errNum(net) ((net)->errNum) #define butLnet_packet(net) ((net)->packet) /* * butLnet_create and butRnet_create will return NULL if the system was * compiled without sockets available. */ extern ButLnet *butLnet_create(ButEnv *env, int port, void *packet, ButOut ocallback(ButRnet *net), ButOut callback(ButRnet *net, void *cmd, int cmdLen), ButOut ccallback(ButRnet *net, const char *reason)); extern void butLnet_destroy(ButLnet *net); extern ButRnet *butRnet_create(ButEnv *env, const char *address, int port, void *packet, ButOut ocallback(ButRnet *net), ButOut callback(ButRnet *net, void *cmd, int cmdLen), ButOut ccallback(ButRnet *net, const char *reason)); extern void butRnet_accept(ButRnet *net); extern void butRnet_send(ButRnet *net, void *buffer, int len); extern void butRnet_destroy(ButRnet *net, const char *reason); /* Private. */ extern void butRnet_mMove(ButEnv *env, int winId, int lx, int ly, int lw, int lh, ButCur type); extern void butRnet_butSpecSend(But *but, void *buffer, int len); extern void butRnet_newFlags(ButEnv *env, int butId, uint newFlags); #endif /* _BUTNET_H_ */ pente-2.2.5/wmslib/src/but/box.h0100664000076400007640000000350607045637750014704 0ustar wmswms/* * wmslib/src/but/box.h, part of wmslib (Library functions) * Copyright (C) 1994-1995 William Shubert. * See "configure.h.in" for more copyright information. * * Includes for but.c */ #ifndef _BUT_BOX_H_ #ifndef _BUT_BUT_H_ #include #endif #define _BUT_BOX_H_ 1 /********************************************************************** * Constants **********************************************************************/ #define BUT_ALEFT 0x01 /* Arrows on left/right. */ #define BUT_ARIGHT 0x02 #define BUT_RLEFT 0x04 /* Rounded edges on left/right. */ #define BUT_RRIGHT 0x08 #define BUT_SLEFT 0x10 /* Square edges on left/right. */ #define BUT_SRIGHT 0x20 /********************************************************************** * Functions **********************************************************************/ /* Public. */ extern But *butBox_create(ButWin *win, int layer, int flags); extern void butBox_setColors(But *but, int ul, int lr); extern void butBox_setPixmaps(But *but, Pixmap ul, Pixmap lr); extern But *butBoxFilled_create(ButWin *win, int layer, int flags); extern void butBoxFilled_setColors(But *but, int ul, int lr, int c); extern void butBoxFilled_setPixmaps(But *but, Pixmap ul, Pixmap lr, Pixmap c); /* Private. */ extern void but_drawCtb(ButWin *win, int flags, int fgpic, int bgpic, int pbgpic, int x, int y, int w, int h, int bw, int angles); extern void but_drawCt(ButWin *win, int flags, int fgpic, int bgpic, int pbgpic, int x, int y, int w, int h, int bw, const char *text, int angles, int fontnum); /* If bstate is nonzero, invert the ul and lr colors. */ extern void but_drawBox(ButWin *win, int x, int y, int w, int h, int bstate, int bw, int angles, int ulcolor, int lrcolor, Pixmap ulmap, Pixmap lrmap); #endif /* _BUT_BOX_H_ */ pente-2.2.5/wmslib/src/but/but.h0100664000076400007640000004203407045637750014705 0ustar wmswms/* * wmslib/include/but/but.h, part of wmslib (Library functions) * Copyright (C) 1994-1995 William Shubert. * See "configure.h.in" for more copyright information. * * Includes for auxiliary button code. */ #ifndef _BUT_BUT_H_ #define _BUT_BUT_H_ 1 #include #if HAVE_SYS_SELECT_H #include #endif /********************************************************************** * Forward declarations **********************************************************************/ typedef struct ButTimer_struct ButTimer; typedef struct ButWin_struct ButWin; typedef struct ButLnet_struct ButLnet; typedef struct ButRnet_struct ButRnet; typedef struct ButEnv_struct ButEnv; typedef struct But_struct But; #include /********************************************************************** * Constants **********************************************************************/ #define BUT_DCLICK 350 /* Time between double clicks; should probably */ /* be settable by the user. */ /********************************************************************** * Types **********************************************************************/ #define BUTOUT_STOPWAIT 0x01 #define BUTOUT_ERR 0x02 #define BUTOUT_CAUGHT 0x04 #define BUTOUT_STILLBUTS 0x08 #define BUTOUT_IGNORE 0x10 /* Used by canvases. */ typedef uint ButOut; typedef ButOut ButWinFunc(struct ButWin_struct *win); typedef struct ButAction_struct { ButOut (*mMove)(But *but, int x, int y); ButOut (*mLeave)(But *but); ButOut (*mPress)(But *but, int butnum, int x, int y); ButOut (*mRelease)(But *but, int butnum, int x, int y); ButOut (*kPress)(But *but, const char *str, KeySym sym); ButOut (*kRelease)(But *but, const char *str, KeySym sym); void (*draw)(But *but, int x, int y, int w, int h); ButOut (*destroy)(But *but); void (*newFlags)(But *but, uint nfl); ButOut (*netMessage)(But *but, void *msg, int msgLen); /* resize returns TRUE if redraws are needed for old & new position. */ bool (*resize)(But *but, int oldX, int oldY, int oldW, int oldH); } ButAction; typedef struct ButColor_struct { int red, green, blue, greyLevel; } ButColor; typedef struct ButSet_struct { int numButs; bool dynamic; /* If TRUE, then buts should be freed when you're done. */ But **buts; int maxButs; MAGIC_STRUCT } ButSet; typedef struct ButWinArea_struct { int x, y, w, h; } ButWinArea; struct ButWin_struct { struct ButWin_struct *parent; /* NULL unless you're a canvas. */ struct But_struct *parentBut; /* NULL unless you're a canvas. */ void *packet, *iPacket; Window win, physWin; struct ButWin_struct *iconWin; const char *name; bool iconic, isIcon; int x,y,w,h, xOff, yOff, minWRatio, minHRatio, maxWRatio, maxHRatio; int minW, minH, maxW, maxH, wStep, hStep; int logicalW, logicalH; /* Same as w&h except for canvases. */ bool resized, resizeNeeded, redrawReady; ButWinArea *redraws; int numRedraws, maxRedraws; int id; bool mapped; ButWinFunc *unmap, *map, *resize, *destroy, *quit; ButEnv *env; int minLayer, maxLayer; struct ButSet_struct butsNoDraw; But *lock, *butIn; But *keyBut; int numCols, maxCols; struct ButCol_struct *cols; MAGIC_STRUCT }; typedef struct ButWrite_struct { double width; void *packet; void (*draw)(void *packet, ButWin *win, int x, int y, int w, int h); } ButWrite; #define BUTWRITE_MINPRINT '\t' #define BUTWRITE_MAXCHARS (BUTWRITE_MINPRINT*256-256) typedef struct ButFdCallback_struct { ButOut (*callback)(void *packet, int fd); void *packet; } ButFdCallback; struct ButEnv_struct { char *protocol; void *packet; Display *dpy; int (*shutdown)(Display *dpy); GC gc, gc2; Pixmap stipDisable; bool colorp; /* TRUE if color, FALSE if b/w. */ int numColors; ulong *colors; Pixmap greyMaps[17]; Pixmap *colorPmaps; int numFonts; XFontStruct **fonts; int font0h, depth, rootW, rootH; int stdButBw; Atom prop; bool (*sReq)(ButEnv *env, XSelectionRequestEvent *xsre); int (*sClear)(ButEnv *env); int (*sNotify)(ButEnv *env, XSelectionEvent *xsnot); struct ButWin_struct **winlist; int minWindows, wllen, wlmax; But *butIn, *lockBut; struct ButWin_struct *last_mwin; int last_mx, last_my; ButEnv *next; struct ButWrite_struct write[BUTWRITE_MAXCHARS]; uint keyModifiers; Time eventTime; /* But & kbd PRESS or RELEASE or MOVE events. */ int eventNum; /* But & kbd PRESS events ONLY. */ int maxFd, maxGFds[3]; fd_set fMasks[3]; ButFdCallback *fCallbacks[3]; /* These are set up in the rc (remote cusor) file. */ int cur_mnum, new_mnum; Cursor cursors[BUTCUR_NUM]; Pixmap cpic[BUTCUR_NUM], cmask[BUTCUR_NUM], *cstore; struct ButRnet_struct **partners; int partner, numPartners; int maxButIds, maxWinIds; But **id2But; struct ButWin_struct **id2Win; ButCur curnum, curlast; Window curwin; But *curhold; MAGIC_STRUCT }; typedef struct ButKey_struct { KeySym key; uint modifiers; uint modMask; } ButKey; struct But_struct { void *uPacket; /* Packet of user information. */ void *iPacket; /* Packet unique to this button type. */ struct ButWin_struct *win; int layer; int x, y, w, h, id; unsigned flags; const ButKey *keys; /* A list of keys that map to this button. */ const ButAction *action; void (*destroyCallback)(struct But_struct *but); MAGIC_STRUCT }; typedef struct ButRow_struct { int startY, numButs, maxButs; But **buts; MAGIC_STRUCT } ButRow; typedef struct ButCol_struct { int startX; int numRows, maxRows; struct ButRow_struct *rows; MAGIC_STRUCT } ButCol; #define butEnv_setXFg(env, colornum) \ do { \ if (env->colorp) \ XSetForeground(env->dpy, env->gc, env->colors[colornum]); \ else \ XSetTile(env->dpy, env->gc, env->colorPmaps[colornum]); \ } while (0) #define butEnv_stdFill(env) \ do { \ if (env->colorp) \ XSetFillStyle(env->dpy, env->gc, FillSolid); \ else \ XSetFillStyle(env->dpy, env->gc, FillTiled); \ } while (0) #define butEnv_setXFg2(env, colornum) \ do { \ if (env->colorp) \ XSetForeground(env->dpy, env->gc2, env->colors[colornum]); \ else \ XSetTile(env->dpy, env->gc2, env->colorPmaps[colornum]); \ } while (0) #define butEnv_stdFill2(env) \ do { \ if (env->colorp) \ XSetFillStyle(env->dpy, env->gc2, FillSolid); \ else \ XSetFillStyle(env->dpy, env->gc2, FillTiled); \ } while (0) extern Atom but_myProp, but_wmDeleteWindow, but_wmProtocols; extern struct ButTimer_struct *but_timerList; extern bool but_inEvent; extern void butWin_turnOnTimers(ButWin *win); extern void butWin_turnOffTimers(ButWin *win); extern ButOut butWin_delete(ButWin *win); extern ButOut but_dList(But *but); extern ButOut butWin_dList(ButWin *win); /* From "write.c" */ extern void butWin_write(ButWin *win, int x, int y, const char *text, int font); /* Functions available to the buttons. */ extern void butEnv_deinit(ButEnv *env); extern But *but_create(ButWin *win, void *iPacket, const ButAction *action); extern void but_init(But *but); extern ButOut but_delete(But *but); #define but_getFlags(b) ((b)->flags) extern void but_newFlags(But *but, uint newflags); extern void but_flags(But *but, uint newflags); /* Private. */ extern void but_draw(But *but); extern void butWin_redraw(ButWin *win, int x, int y, int w, int h); extern void butWin_performDraws(ButWin *win); extern void but_resize(But *but, int x, int y, int w, int h); extern ButOut butWin_mMove(ButWin *win, int x, int y); extern ButOut butWin_mPress(ButWin *win, int x, int y, int butnum); extern ButOut butWin_mRelease(ButWin *win, int x, int y, int butnum); extern ButOut butWin_kPress(ButWin *win, const char *kstring, KeySym sym); extern ButOut butWin_kRelease(ButWin *env, const char *kstring, KeySym sym); /* Functions for internal use only. */ /* In but_finder.c */ void butSet_destroy(ButSet *butset); extern ButWin *butEnv_findWin(ButEnv *env, Window win); extern void butWin_addToTable(ButWin *win); extern void butWin_rmFromTable(ButWin *win); extern void but_addToTable(But *but); extern void but_delFromTable(But *but); extern void butWin_findButSet(ButWin *win, int x, int y, ButSet *butset); extern void butWin_findButSetInRegion(ButWin *win, int x,int y, int w,int h, ButSet *butset); extern But *butWin_findButsInRegion(ButWin *win, int x,int y, int w,int h, bool (*action)(But *but, void *packet), void *packet); void butSet_addBut(ButSet *butset, But *but); void butSet_delBut(ButSet *butset, But *but); /* From "ctext.c" */ #ifdef _WMS_SND_H_ extern Snd but_downSnd, but_upSnd; #endif /* _WMS_SND_H_ */ /********************************************************************** * Forward declarations **********************************************************************/ /* These are all bits for the flags arguments to button functions. */ #define BUT_DRAWABLE 0x0001 /* Can be drawn. */ #define BUT_PRESSABLE 0x0002 /* Can be pressed. */ #define BUT_TWITCHABLE 0x0004 /* Changes when mouse goes over it. */ #define BUT_KEYED 0x0008 /* Keys pressed land in this button. */ #define BUT_PRESSTHRU 0x0010 #define BUT_PRESSED 0x0020 #define BUT_TWITCHED 0x0040 #define BUT_KEYPRESSED 0x0080 #define BUT_KEYACTIVE 0x0100 /* Read only; set if recvs keypresses. */ #define BUT_TABLED 0x0200 /* Private. Don't touch. */ #define BUT_LOCKED 0x0400 #define BUT_OPAQUE 0x0800 /* Solidly fills rectangle. */ #define BUT_DEAD 0x1000 /* Marked for death! */ #define BUT_NETPRESS 0x2000 #define BUT_NETTWITCH 0x4000 #define BUT_NETKEY 0x8000 #define BUT_MAXBITS 16 #define BUT_NODRAW (BUT_DRAWABLE<packet) #define butEnv_dpy(env) ((env)->dpy) #define butEnv_gc(env) ((env)->gc) #define butEnv_color(env, cnum) ((env)->colors[cnum]) #define butEnv_isColor(env) ((env)->colorp) #define butEnv_pixmap(env, cnum) ((env)->colorPmaps[cnum]) #define butEnv_fontStr(env, fnum) ((env)->fonts[fnum]) #define butEnv_stdBw(env) ((env)->stdButBw) #define butEnv_keyModifiers(env) ((env)->keyModifiers) #define butWin_packet(win) ((win)->packet) #define butWin_env(win) ((win)->env) #define butWin_xwin(bwin) ((bwin)->win) #define butWin_w(win) ((win)->logicalW) #define butWin_h(win) ((win)->logicalH) #define butWin_viewW(win) ((win)->w) #define butWin_viewH(win) ((win)->h) #define butWin_x(win) ((win)->x) #define butWin_y(win) ((win)->y) #define butWin_xoff(win) ((win)->xOff) #define butWin_yoff(win) ((win)->yOff) #define butWin_setPacket(win, p) ((win)->packet = (p)) #define butWin_setQuit(win, q) ((win)->quit = (q)) #define butWin_setDestroy(win, d) ((win)->destroy = (d)) #define but_win(but) ((but)->win) #define but_packet(but) ((but)->uPacket) #define but_setPacket(but, val) ((but)->uPacket = (val)) #define but_x(but) ((but)->x) #define but_y(but) ((but)->y) #define but_w(but) ((but)->w) #define but_h(but) ((but)->h) #define but_setDestroyCallback(but, v) ((but)->destroyCallback = (v)) /* * but_events keeps servicing events until one returns BUT_OUT_STOPWAIT. */ extern void butEnv_events(ButEnv *env); extern ButEnv *butEnv_create(const char *protocol, const char *dpyname, int shutdown(Display *dpy)); extern ButEnv *butEnv_createNoDpy(const char *protocol); /* * but_env_init() returns: * 0 - Black and white display or color=FALSE. * 1 - Couldn't allocate standard colors. Failed. * 2 - Color successful. * 3 - Truecolor display. Color will always be successful. */ extern int butEnv_init(ButEnv *env, void *packet, const char *atomname, bool color); extern void butEnv_destroy(ButEnv *env); extern bool butEnv_setFont(ButEnv *env, int fontnum, const char *fontname, int fparam); #define butEnv_fontH(env, fnum) \ ((env)->fonts[fnum]->ascent + (env)->fonts[fnum]->descent) /* drawall is typically used after changing fonts, etc. */ extern void butEnv_drawAll(ButEnv *env); extern void butEnv_resizeAll(ButEnv *env); extern void but_draw(But *but); extern void but_destroy(But *but); extern void but_resize(But *but, int x, int y, int w, int h); #define butEnv_localContext(env) ((env)->localContext) #define butEnv_context(env) ((env)->context) extern void but_setId(But *but, int id); extern void butWin_setId(ButWin *win, int id); #define BUT_READFILE 0 #define BUT_WRITEFILE 1 #define BUT_XFILE 2 extern void butEnv_addFile(ButEnv *env, int group, int fd, void *packet, ButOut (*callback)(void *packet, int fd)); extern void butEnv_rmFile(ButEnv *env, int group, int fd); extern ButWin *butWin_iCreate(void *packet, ButEnv *env, const char *name, int w, int h, ButWin **iWin, bool iconic, int iW, int iH, ButWinFunc *unmap, ButWinFunc *map, ButWinFunc *resize, ButWinFunc *iResize, ButWinFunc *destroy); /* * DO NOT ACTIVATE a root window. */ extern ButWin *butWin_rootCreate(void *packet, ButEnv *env); #define butWin_create(p,e,n,w,h,un,ma,re,de) \ butWin_iCreate(p,e,n,w,h,NULL,FALSE,0,0,un,ma,re,NULL,de) extern void butWin_setGeom(ButWin *win, const char *geometry); extern void butWin_setX(ButWin *win, int x); extern void butWin_setY(ButWin *win, int y); extern void butWin_setMinW(ButWin *win, int minW); extern void butWin_setMinH(ButWin *win, int minH); extern void butWin_setMaxW(ButWin *win, int maxW); extern void butWin_setMaxH(ButWin *win, int maxH); extern void butWin_setWHRatio(ButWin *win, int w, int h); extern void butWin_setWHRatios(ButWin *win, int minW, int minH, int maxW, int maxH); extern void butWin_setWStep(ButWin *win, int wStep); extern void butWin_setHStep(ButWin *win, int hStep); #define butWin_getMinW(w) ((w)->minW) #define butWin_getMinH(w) ((w)->minH) #define butWin_getMaxW(w) ((w)->maxW) #define butWin_getMaxH(w) ((w)->maxH) #define butWin_getWStep(w) ((w)->wStep) #define butWin_getHStep(w) ((w)->hStep) extern void butWin_activate(ButWin *win); extern void butWin_checkDims(ButWin *win); /* Private. */ extern void butWin_resize(ButWin *win, int newW, int newH); extern void butWin_destroy(ButWin *xw); /* grey is 0..16 */ extern ButColor butColor_create(int r, int g, int b, int grey); /* The output color will have bw_greyscale same as c1's. */ extern ButColor butColor_mix(ButColor c1, int r1, ButColor c2, int r2); extern bool butEnv_setColor(ButEnv *env, int colornum, ButColor color); XImage *butEnv_imageCreate(ButEnv *env, int w, int h); void butEnv_imageDestroy(XImage *image); /* From "i_general.c" */ extern void but_setFlags(But *but, uint fch); extern void but_setKeys(But *but, const ButKey *keys); /* From "but_write.c" */ extern void butEnv_setChar(ButEnv *env, double wratio, const char *id, void (*draw)(void *packet, ButWin *win, int x, int y, int w, int h), void *packet); extern int butEnv_textWidth(ButEnv *env, const char *text, int fnum); extern int butEnv_charWidth(ButEnv *env, const char *text, int fnum); /* From "but_textin.c" */ #define BUT_NOCHANGE (1 << (sizeof(int)*8-2)) #endif /* _BUT_BUT_H_ */ pente-2.2.5/wmslib/src/but/canvas.h0100664000076400007640000000242007045637750015361 0ustar wmswms/* * wmslib/include/but/canvas.h, part of wmslib (Library functions) * Copyright (C) 1994-1995 William Shubert. * See "configure.h.in" for more copyright information. * * Includes for canvas.c */ #ifndef _BUT_CANVAS_H_ #define _BUT_CANVAS_H_ 1 /********************************************************************** * Functions. **********************************************************************/ extern ButWin *butCan_create(void *packet, ButWin *parent, int layer, ButWinFunc *resize, ButWinFunc *destroy, void (*change)(void *packet, int xOff, int yOff, int w, int h, int viewW, int viewH)); /* Any values of BUT_NOCHANGE in this function will be left unchanged. */ extern void butCan_resizeView(ButWin *win, int x, int y, int w, int h, bool propagate); extern void butCan_slide(ButWin *win, int xOff, int yOff, bool propagate); extern void butCan_resizeWin(ButWin *win, int w, int h, bool propagate); #define butCan_xOff(win) ((win)->xOff) #define butCan_yOff(win) ((win)->yOff) extern void butCan_destroy(ButWin *can); /* Private. */ extern Window butCan_xWin(ButWin *win); extern void butCan_redrawn(ButWin *win, int x,int y, int w,int h); extern void butCan_winDead(ButWin *win); #endif /* _BUT_CANVAS_H_ */ pente-2.2.5/wmslib/src/but/checkbox.h0100664000076400007640000000124607045637750015701 0ustar wmswms/* * wmslib/src/but/checkbox.h, part of wmslib (Library functions) * Copyright (C) 1994-1995 William Shubert. * See "configure.h.in" for more copyright information. * * Includes for checkbox.c */ #ifndef _BUT_CHECKBOX_H_ #define _BUT_CHECKBOX_H_ 1 /********************************************************************** * Functions **********************************************************************/ extern But *butCb_create(ButOut (*func)(But *but, bool value), void *packet, ButWin *win, int layer, int flags, bool on); extern bool butCb_get(But *but); extern void butCb_set(But *but, bool on, bool makeCallback); #endif /* _BUT_CHECKBOX_H_ */ pente-2.2.5/wmslib/src/but/ctext.h0100664000076400007640000000224607045637750015243 0ustar wmswms/* * wmslib/src/but/ctext.h, part of wmslib (Library functions) * Copyright (C) 1995 William Shubert. * See "configure.h.in" for more copyright information. * * Includes for ctext.c */ #ifndef _BUT_CTEXT_H_ #define _BUT_CTEXT_H_ 1 #include /********************************************************************** * Functions **********************************************************************/ extern But *butCt_create(ButOut (*func)(But *but), void *packet, ButWin *win, int layer, int flags, const char *text); extern void butCt_setText(But *info, const char *text); extern But *butAct_create(ButOut (*func)(But *but), void *packet, ButWin *win, int layer, int flags, const char *text, int angleflags); extern But *butAct_vCreate(ButOut (*pfunc)(But *but), ButOut (*rfunc)(But *but), void *packet, ButWin *win, int layer, int flags, const char *text, int angleflags); #define butAct_setText butCt_setText extern void butCt_setNetAction(But *but, bool netAction); #define butAct_setNetAction butCt_setNetAction extern void butCt_setTextLoc(But *but, int x, int y, int w, int h); #endif /* _BUT_CTEXT_H_ */ pente-2.2.5/wmslib/src/but/i_finder.h0100664000076400007640000000043607045637750015672 0ustar wmswms/* * wmslib/src/but/i_finder.h, part of wmslib (Library functions) * Copyright (C) 1995 William Shubert. * See "configure.h.in" for more copyright information. * * Includes for i_finder.c */ #ifndef _BUT_I_FINDER_H_ #define _BUT_I_FINDER_H_ 1 #endif /* _BUT_I_FINDER_H_ */ pente-2.2.5/wmslib/src/but/i_general.h0100664000076400007640000000045607045637750016042 0ustar wmswms/* * wmslib/src/but/i_general.h, part of wmslib (Library functions) * Copyright (C) 1995 William Shubert. * See "configure.h.in" for more copyright information. * * Includes for auxiliary button code. */ #ifndef _BUT_I_GENERAL_H_ #define _BUT_I_GENERAL_H_ 1 #endif /* _BUT_I_GENERAL_H_ */ pente-2.2.5/wmslib/src/but/i_snd.h0100664000076400007640000000041707045637750015206 0ustar wmswms/* * wmslib/src/but/i_snd.h, part of wmslib (Library functions) * Copyright (C) 1995 William Shubert. * See "configure.h.in" for more copyright information. * * Includes for i_snd.c */ #ifndef _BUT_I_SND_H_ #define _BUT_I_SND_H_ 1 #endif /* _BUT_I_SND_H_ */ pente-2.2.5/wmslib/src/but/i_win.h0100664000076400007640000000041707045637750015217 0ustar wmswms/* * wmslib/src/but/i_win.h, part of wmslib (Library functions) * Copyright (C) 1995 William Shubert. * See "configure.h.in" for more copyright information. * * Includes for i_win.c */ #ifndef _BUT_I_WIN_H_ #define _BUT_I_WIN_H_ 1 #endif /* _BUT_I_WIN_H_ */ pente-2.2.5/wmslib/src/but/menu.h0100664000076400007640000000361207045637750015056 0ustar wmswms/* * wmslib/src/but/menu.h, part of wmslib (Library functions) * Copyright (C) 1995-1996 William Shubert. * See "configure.h.in" for more copyright information. * * Includes for menu.c */ #ifndef _BUT_MENU_H_ #define _BUT_MENU_H_ 1 /********************************************************************** * Constants **********************************************************************/ #define BUTMENU_OLEND NULL #define BUTMENU_OLBREAK (&butMenu_dummy) #define BUTMENU_DISABLED 1 /* Flags. */ #define BUTMENU_END 2 /* Private. */ #define BUTMENU_BREAK 4 /* Private. */ /********************************************************************** * Global variables **********************************************************************/ /* Private. */ extern char butMenu_dummy; /********************************************************************** * Functions **********************************************************************/ extern But *butMenu_upCreate(ButOut (*func)(But *but, int value), void *packet, ButWin *win, int layer, int toplayer, int flags, const char *title, const char *optlist[], int cur_opt); extern But *butMenu_downCreate(ButOut (*func)(But *but, int value), void *packet, ButWin *win, int layer, int toplayer, int flags, const char *title, const char *optlist[], int cur_opt); extern void butMenu_set(But *but, int new_opt); extern int butMenu_get(But *but); extern void butMenu_setColor(But *but, int fg, int bg); /* If newcval is -1, then it will be left unchanged. */ extern void butMenu_setText(But *but, const char *title, const char *optlist[], int newcval); extern void butMenu_setOptionName(But *but, const char *new, int entryNum); /* * flags should be from the BUTMENU_DISABLED list above. */ extern void butMenu_setFlags(But *but, int optnum, uint flags); #endif /* _BUT_MENU_H_ */ pente-2.2.5/wmslib/src/but/menu_snd.h0100664000076400007640000000101007045637750015710 0ustar wmswms/* * wmslib/src/but/menu_snd.h, part of wmslib (Library functions) * Copyright (C) 1995 William Shubert. * See "configure.h.in" for more copyright information. * * Includes for menu_snd.c */ #ifndef _BUT_MENU_SND_H_ #include #define _BUT_MENU_SND_H_ 1 /********************************************************************** * Global variables **********************************************************************/ extern Snd butMenu_openSnd, butMenu_closeSnd; #endif /* _BUT_MENU_SND_H_ */ pente-2.2.5/wmslib/src/but/plain.h0100664000076400007640000000240307045637750015212 0ustar wmswms/* * wmslib/src/but/plain.h, part of wmslib (Library functions) * Copyright (C) 1995 William Shubert. * See "configure.h.in" for more copyright information. * * Includes for plain.c */ #ifndef _BUT_PLAIN_H_ #define _BUT_PLAIN_H_ 1 /********************************************************************** * Functions. **********************************************************************/ extern But *butPlain_create(ButWin *win, int layer, int flags, int cnum); extern void butPlain_setColor(But *but, int cnum); extern But *butPixmap_create(ButWin *win, int layer, int flags, Pixmap pic); extern void butPixmap_setPic(But *but, Pixmap pic, int x,int y); /* * dummy is a button that isn't drawn, but is opaque. It is sometimes * useful to create one of these to prevent the button library from * doing tons of extra redraws, then erase the dummy to force one * final redraw. */ extern But *butDummy_create(ButWin *win, int layer, int flags); /* * A keytrap does nothing but call your func when the key you specify * is pressed or released. */ extern But *butKeytrap_create(ButOut (*func)(But *but, bool press), void *packet, ButWin *win, int flags); extern void butKeytrap_setHold(But *but, bool hold); #endif /* _BUT_PLAIN_H_ */ pente-2.2.5/wmslib/src/but/rcur.h0100664000076400007640000000335007045637750015064 0ustar wmswms/* * wmslib/include/but/rcur.h, part of wmslib (Library functions) * Copyright (C) 1994-1995 William Shubert. * See "configure.h.in" for more copyright information. * * Includes for remote cursors. */ #ifndef _BUTRCUR_H_ #define _BUTRCUR_H_ 1 /********************************************************************** * Constants **********************************************************************/ #define BUTCUR_NUM 10 /********************************************************************** * Types **********************************************************************/ /* * Do not use butCur_bogus. It is a bogus cursor, _NOT_ a bogus-looking * cursor. */ typedef enum { butCur_idle, butCur_text, butCur_twitch, butCur_right, butCur_left, butCur_up, butCur_down, butCur_lr, butCur_ud, butCur_grab, butCur_bogus} ButCur; typedef struct ButRcur_struct { ButEnv *env; int winId, rx,ry, rw,rh; int lx,ly; ButCur type; bool drawn; Pixmap under; MAGIC_STRUCT } ButRcur; /********************************************************************** * Functions **********************************************************************/ /* Public. */ extern void butEnv_rcInit(ButEnv *env); extern void butRcur_create(ButRcur *rc, ButEnv *env); #define butRcur_destroy(rc) butRcur_move(-2, 0,0, 0,0); extern void butRcur_move(ButRcur *rc, int winId, int rx,int ry, int rw,int rh, ButCur type); extern void butRcur_redraw(ButEnv *env, int winId, int x,int y, int w,int h); /* The type of cursor has changed. */ extern void butEnv_setCursor(ButEnv *env, But *but, ButCur newCursor); /* Set up any cursor changes that may have occurred. */ extern void butEnv_rcActivate(ButEnv *env); #endif /* _BUTRCUR_H_ */ pente-2.2.5/wmslib/src/but/slide.h0100664000076400007640000000205207045637750015207 0ustar wmswms/* * wmslib/src/but/slide.h, part of wmslib (Library functions) * Copyright (C) 1995 William Shubert. * See "configure.h.in" for more copyright information. * * Includes for slide.c */ #ifndef _BUT_SLIDE_H_ #define _BUT_SLIDE_H_ 1 /********************************************************************** * Functions **********************************************************************/ extern But *butSlide_hCreate(ButOut (*func)(But *but, int setting, bool newPress), void *packet, ButWin *win, int layer, int flags, int maxval, int cval, int size); extern But *butSlide_vCreate(ButOut (*func)(But *but, int setting, bool newPress), void *packet, ButWin *win, int layer, int flags, int maxval, int cval, int size); extern int butSlide_get(But *but); extern void butSlide_set(But *but, int maxval, int cval, int size); extern void butSlide_startSlide(But *but, bool pauseStart, int valsPerSecond, bool propagate); extern void butSlide_stopSlide(But *but); #endif /* _BUT_SLIDE_H_ */ pente-2.2.5/wmslib/src/but/tblock.h0100664000076400007640000000174207045637750015372 0ustar wmswms/* * wmslib/src/but/tblock.h, part of wmslib (Library functions) * Copyright (C) 1995 William Shubert. * See "configure.h.in" for more copyright information. * * Includes for tblock.c */ #ifndef _BUT_TBLOCK_H_ #define _BUT_TBLOCK_H_ 1 #include /********************************************************************** * Functions **********************************************************************/ extern But *butTblock_create(ButWin *win, int layer, int flags, const char *text, ButTextAlign align); /* resize returns the height of the text block after being resized. */ extern int butTblock_resize(But *but, int x, int y, int w); extern void butTblock_setText(But *but, const char *text); extern const char *butTblock_getText(But *but); extern void butTblock_setFont(But *but, int fontnum); extern int butTblock_getH(But *but); extern int butTblock_guessH(ButEnv *env, const char *text, int w, int fontNum); #endif /* _BUT_TBLOCK_H_ */ pente-2.2.5/wmslib/src/but/text.h0100664000076400007640000000204407045637750015074 0ustar wmswms/* * wmslib/src/but/text.h, part of wmslib (Library functions) * Copyright (C) 1995 William Shubert. * See "configure.h.in" for more copyright information. * * Includes for text.c */ #ifndef _BUT_TEXT_H_ #define _BUT_TEXT_H_ 1 /********************************************************************** * Data types **********************************************************************/ typedef enum { butText_left, butText_right, butText_center, butText_just } ButTextAlign; /********************************************************************** * Functions **********************************************************************/ extern But *butText_create(ButWin *win, int layer, int flags, const char *text, ButTextAlign align); extern int butText_resize(But *but, int x, int y, int h); extern const char *butText_get(But *but); extern void butText_set(But *but, const char *text); extern void butText_setFont(But *but, int fontnum); extern void butText_setColor(But *but, int color, bool stipple); #endif /* _BUT_TEXT_H_ */ pente-2.2.5/wmslib/src/but/textin.h0100664000076400007640000000240207045637750015421 0ustar wmswms/* * wmslib/src/but/textin.h, part of wmslib (Library functions) * Copyright (C) 1995-1997 William Shubert. * See "configure.h.in" for more copyright information. * * Includes for textin.c */ #ifndef _BUT_TEXTIN_H_ #define _BUT_TEXTIN_H_ 1 /********************************************************************** * Functions **********************************************************************/ extern But *butTextin_create(ButOut (*func)(But *but, const char *value), void *packet, ButWin *win, int layer, int flags, const char *text, int maxlen); extern void butTextin_setCallback(But *but, ButOut (*func)(But *but, const char *value), void *packet); extern void butTextin_set(But *but, const char *str, bool propagate); extern const char *butTextin_get(But *but); /* * If you set hidden to TRUE, then all characters appear as only "*"s. This * is nice if you are asking for a password. */ extern void butTextin_setHidden(But *but, bool hidden); extern void butTextin_setSpecialKey(But *but, KeySym keysym, uint keyModifiers, uint modMask, ButOut callback(But *but, KeySym keysym, uint keyModifiers, void *context), void *context); #endif /* _BUT_TEXTIN_H_ */ pente-2.2.5/wmslib/src/but/timer.h0100664000076400007640000000457507045637750015243 0ustar wmswms/* * wmslib/src/but/timer.h, part of wmslib (Library functions) * Copyright (C) 1995 William Shubert. * See "configure.h.in" for more copyright information. * * Includes for timer.c */ #ifndef _BUT_TIMER_H_ #define _BUT_TIMER_H_ 1 /********************************************************************** * Constants **********************************************************************/ #define BUTTIMER_HIST 4 #define BUTTIMER_MAXFREQ 400 /* Hz...the most we'll ever allow. */ #define BUTTIMER_STDFREQ 100 /* Hz...the "standard" value. */ /********************************************************************** * Data types **********************************************************************/ typedef enum { butTimer_on, butTimer_off, butTimer_dead } ButTimerState; /* Private. */ struct ButTimer_struct { void *packet; int eventNum; struct timeval nextFiring, period; bool winOnly; /* False=shut off when iconified. */ ButTimerState state; struct ButWin_struct *win; But *but; ButOut (*timerFunc)(struct ButTimer_struct *timer); struct ButTimer_struct *next; int ticksPerPeriod; bool freqCounter; int lastRes[BUTTIMER_HIST]; int resnum, ticksLeft; MAGIC_STRUCT }; /********************************************************************** * Functions **********************************************************************/ /* Public. */ extern ButTimer *butTimer_create(void *packet, But *but, struct timeval delay, struct timeval period, bool win_only, ButOut (*timerfunc)(struct ButTimer_struct *timer)); extern ButTimer *butTimer_fCreate(void *packet, But *but, struct timeval delay, int frequency, bool win_only, ButOut (*timerfunc)(struct ButTimer_struct *timer)); extern void butTimer_destroy(ButTimer *timer); extern void butTimer_reset(ButTimer *timer); #define butTimer_ticks(bt) ((bt)->eventNum) #define butTimer_setTicks(bt, v) ((bt)->eventNum = (v)) #define butTimer_packet(bt) ((bt)->packet) /* Private. */ extern struct timeval but_timerAdd(struct timeval t1, struct timeval t2); extern struct timeval but_timerSub(struct timeval t1, struct timeval t2); extern int but_timerDiv(struct timeval t1, struct timeval t2, struct timeval *remainder); extern int butEnv_checkTimers(ButEnv *env, struct timeval *timeout); #endif /* _BUT_TIMER_H_ */ pente-2.2.5/wmslib/src/but/write.h0100664000076400007640000000120007045637750015233 0ustar wmswms/* * wmslib/src/but/write.h, part of wmslib (Library functions) * Copyright (C) 1995 William Shubert. * See "configure.h.in" for more copyright information. * * Includes for write.c */ #ifndef _BUT_WRITE_H_ #define _BUT_WRITE_H_ 1 #ifndef _BUT_TEXT_H_ #include #endif /********************************************************************** * Functions **********************************************************************/ extern void butWin_writeTabs(ButWin *win, int startX, int y, const char *text, int font, const int *tabList, const ButTextAlign *aligns); #endif /* _BUT_WRITE_H_ */ pente-2.2.5/wmslib/src/abut/abut.h0100664000076400007640000000226207045637750015206 0ustar wmswms/* * src/abut.h, part of wmslib library * Copyright (C) 1995-1996 William Shubert. * See "configure.h.in" for more copyright information. */ #ifndef _ABUT_ABUT_H_ #ifndef _WMS_CLP_H_ #include #endif #ifdef _ABUT_ABUT_H_ Levelization Error. #endif #define _ABUT_ABUT_H_ 1 /********************************************************************** * Types **********************************************************************/ /* Private. */ typedef struct Abut_struct { ButEnv *env; const char *ok, *cancel; int butH; int ulColor, lrColor, bgColor; Pixmap ulPixmap, lrPixmap, bgPixmap; Clp *clp; MAGIC_STRUCT } Abut; /********************************************************************** * Functions available **********************************************************************/ extern Abut *abut_create(ButEnv *env, const char *ok, const char *cancel); extern void abut_destroy(Abut *a); extern void abut_setColors(Abut *a, int ul, int lr, int bg); extern void abut_setPixmaps(Abut *a, Pixmap ul, Pixmap lr, Pixmap bg); #define abut_setClp(a, c) ((a)->clp = (c)) #define abut_setButH(a, h) ((a)->butH = (h)) #endif /* _ABUT_ABUT_H_ */ pente-2.2.5/wmslib/src/abut/swin.h0100664000076400007640000000331107045637750015227 0ustar wmswms/* * wmslib/src/abut/swin.h, part of wmslib (Library functions) * Copyright (C) 1994-1995 William Shubert. * See "configure.h.in" for more copyright information. * * Includes for auxiliary button code. */ #ifndef _ABUT_SWIN_H_ #define _ABUT_SWIN_H_ 1 #ifndef _WMS_H_ #include #endif #ifndef _BUT_BUT_H_ #include #endif /********************************************************************** * Constants **********************************************************************/ #define ABUT_UPPIC "\2\1" #define ABUT_DOWNPIC "\2\2" #define ABUT_LEFTPIC "\2\3" #define ABUT_RIGHTPIC "\2\4" /********************************************************************** * Data types **********************************************************************/ typedef struct AbutSwin_struct { ButWin *win; void *packet; But *up, *down, *left, *right, *hSlide, *vSlide, *box; float xCenter, yCenter; uint flags; ButTimer *timer; int x, y, w, h, slideW, lineH; /* Backups for resizing. */ int canButW, canButH; MAGIC_STRUCT } AbutSwin; #define ABUTSWIN_LSLIDE 0x1 #define ABUTSWIN_RSLIDE 0x2 #define ABUTSWIN_TSLIDE 0x4 #define ABUTSWIN_BSLIDE 0x8 /********************************************************************** * Functions **********************************************************************/ extern AbutSwin *abutSwin_create(void *packet, ButWin *parent, int layer, uint flags, ButWinFunc resize); extern void abutSwin_resize(AbutSwin *swin, int x, int y, int w, int h, int slidew, int lineh); extern void abutSwin_destroy(AbutSwin *swin); extern void abutSwin_vMove(AbutSwin *swin, int newLoc); #endif /* _ABUT_SWIN_H_ */ pente-2.2.5/wmslib/src/abut/msg.h0100664000076400007640000000557107045637750015047 0ustar wmswms/* * src/help.h, part of wmslib library * Copyright (C) 1995 William Shubert. * See "configure.h.in" for more copyright information. */ #ifndef _ABUT_MSG_H_ #define _ABUT_MSG_H_ 1 #ifndef _WMS_H_ #include #endif #ifndef _BUT_BUT_H_ #include #endif #ifndef _BUT_BOX_H_ #include #endif #ifndef _ABUT_ABUT_H_ #include #endif /********************************************************************** * Types **********************************************************************/ /* Public. */ typedef struct AbutMsgOpt_struct { const char *name; ButOut (*callback)(But *but); void *packet; const ButKey *keyEq; } AbutMsgOpt; typedef struct AbutMsgTin_struct { const char *name; const char *def; ButOut (*callback)(But *but, const char *value); uint flags; } AbutMsgTin; #define abutMsgTinFlags_secret 0x1 /* Private. */ typedef struct AbutMsg_struct { Abut *abut; ButWin *win; int numButs, numTins; But **buts, **tins, **tinTitles; const AbutMsgOpt *butDesc; ButOut (*destroy)(void *packet); void *packet; int layer; int w, h, textH; But *box, *text; MAGIC_STRUCT } AbutMsg; /********************************************************************** * Functions available **********************************************************************/ extern AbutMsg *abutMsg_inCreate(Abut *a, ButWin *win, int layer, const char *text, void *packet, int numTins, const AbutMsgTin *tinList); extern AbutMsg *abutMsg_optInCreate(Abut *a, ButWin *win, int layer, const char *text, ButOut (*destroy)(void *packet), void *packet, int numButs, const AbutMsgOpt *optList, int numTins, const AbutMsgTin *tinList); extern AbutMsg *abutMsg_winInCreate(Abut *a, const char *title, const char *text, void *packet, int numTins, const AbutMsgTin *tinList); extern AbutMsg *abutMsg_winOptInCreate(Abut *a, const char *title, const char *text, ButOut (*destroy)(void *packet), void *packet, int numButs, const AbutMsgOpt *optList, int numTins, const AbutMsgTin *tinList); #define abutMsg_create(a, w, l, t) abutMsg_inCreate(a, w, l, t, NULL,0,NULL) #define abutMsg_optCreate(a, w, l, t, d, p, nb, b) \ abutMsg_optInCreate(a, w, l, t, d, p, nb, b, 0,NULL) #define abutMsg_winCreate(a, ti, t) \ abutMsg_winInCreate(a, ti, t, NULL,0,NULL) #define abutMsg_winOptCreate(a, ti, t, d, p, nb, b) \ abutMsg_winOptInCreate(a, ti, t, d, p, nb, b, 0,NULL) extern void abutMsg_destroy(AbutMsg *msg, bool propagate); #define abutMsg_setColors(m, ul, lr, f) \ butBoxFilled_setColors((m)->box, (ul), (lr), (f)) #define abutMsg_setPixmaps(m, ul, lr, f) \ butBoxFilled_setPixmaps((m)->box, (ul), (lr), (f)) #define abutMsg_tin(m, t) ((m)->tins[t]) #endif /* _ABUT_MSG_H_ */ pente-2.2.5/configure.in0100644000076400007640000003005307331643351013361 0ustar wmswmsAC_INIT # # $Source: /home/wms/cvs/pente/configure.in,v $ # $Revision: 1.6 $ # $Date: 2001/08/01 00:01:45 $ # # Remember to change these in "README", and "pente.6" too. # DATE must be in DAY MONTH YEAR format. date="31 7 2001" VERSION=\"2.2.5\" ###################################################################### # My own, personal functions. # ###################################################################### AC_DEFUN(WMS_GET_SYSTEM, [AC_MSG_CHECKING([for machine type]) if test ${target} = NONE ; then SYSTEM_TYPE=`uname -m | sed sx/xxg` if test $? '!=' 0 ; then SYSTEM_TYPE=unknown ; fi os=`uname -s | sed sx/xxg` if test $? '=' 0 ; then SYSTEM_TYPE=${SYSTEM_TYPE}-${os} ; fi if test ${os} '=' SunOS ; then SYSTEM_TYPE=${SYSTEM_TYPE}`uname -r | sed -e 's/\.//g' -e 's/_.*//'` fi AC_MSG_RESULT($SYSTEM_TYPE) else SYSTEM_TYPE=${target} AC_MSG_RESULT($SYSTEM_TYPE (set by user)) fi]) AC_DEFUN(WMS_GET_CFLAGS, [AC_MSG_CHECKING([for best CFLAGS argument]) if test $ac_cv_prog_gcc = yes ; then CFLAGS='-O2 -fomit-frame-pointer' else CFLAGS='-O' fi AC_MSG_RESULT($CFLAGS) AC_SUBST(CFLAGS)]) AC_DEFUN(WMS_CHECK_H_ERRNO, [AC_MSG_CHECKING([for h_errno]) AC_TRY_LINK([#include #include #if HAVE_NETINET_IN_H #include #endif #if HAVE_SYS_IN_H #include #endif #if HAVE_SYS_INET_H #include #endif #include #if HAVE_ARPA_NAMESER_H #include #endif #if HAVE_RESOLV_H #include #endif], [h_errno = 0;], [AC_MSG_RESULT(yes); AC_DEFINE(HAVE_H_ERRNO)], [AC_MSG_RESULT(no)])]) # I don't really know what will clearly tell whether you have sockets or not, # so I just took a bunch of socket-related functions and stuck them in # a routine. If it builds and links, I assume I can build sockets code; # otherwise I assume I can't. AC_DEFUN(WMS_CHECK_SOCKETS, [AC_MSG_CHECKING([for sockets]) AC_TRY_LINK([#include #include #if HAVE_NETINET_IN_H #include #endif #if HAVE_SYS_IN_H #include #endif #if HAVE_SYS_INET_H #include #endif #include #if HAVE_ARPA_NAMESER_H #include #endif #if HAVE_RESOLV_H #include #endif #include #include #include ], [ struct sockaddr_in sa; bind(0,(struct sockaddr *)&sa, sizeof(sa)); listen(0,2); socket(AF_INET,SOCK_STREAM,0); gethostbyname("foo");], [AC_MSG_RESULT(yes); AC_DEFINE(HAVE_SOCKETS)], [AC_MSG_RESULT(no)])]) ###################################################################### # Done with my own functions. On to the real configure file. # ###################################################################### export VERSION AC_DEFINE_UNQUOTED(VERSION,$VERSION) dayNum=`echo $date | awk '{ print $1 }'` monthNum=`echo $date | awk '{ print $2 }'` yearNum=`echo $date | awk '{ print $3 }'` monthEnglish=`echo January February March April May June July August September October November December | awk '{ print $'$monthNum' }'` monthFrench=`echo Janvier Fevrier Mars Avril Mai Juin Juillet Août Septembre Octobre Novembre Décembre | awk '{ print $'$monthNum' }'` monthItalian=`echo Gennaio Febbraio Marzo Aprile Maggie Guigno Luglio Agosto Settembre Ottobre Novembre Dicembre | awk '{ print $'$monthNum' }'` DATE="\"$dayNum $monthEnglish $yearNum\"" DATE_FRENCH="\"$dayNum $monthFrench $yearNum\"" DATE_ITALIAN="\"$dayNum $monthItalian $yearNum\"" export DATE export DATE_FRENCH export DATE_ITALIAN AC_DEFINE_UNQUOTED(DATE,$DATE) AC_DEFINE_UNQUOTED(DATE_FRENCH,$DATE_FRENCH) AC_DEFINE_UNQUOTED(DATE_ITALIAN,$DATE_ITALIAN) AC_PROG_INSTALL AC_PROG_CC AC_PROG_CPP WMS_GET_CFLAGS PROGS="pente" AC_SUBST(PROGS)dnl BUILD_DIR=`pwd` AC_SUBST(BUILD_DIR)dnl LIBDIR="-L\$(BUILD_DIR)/wmslib" INCDIR="-I\$(BUILD_DIR)/wmslib/src -I\$(BUILD_DIR)/obj-\$(SYSTEM_TYPE)" WMS_GET_SYSTEM export SYSTEM_TYPE AC_SUBST(SYSTEM_TYPE)dnl rm -rf obj-${SYSTEM_TYPE} obj-d${SYSTEM_TYPE} pente-${SYSTEM_TYPE} mkdir obj-${SYSTEM_TYPE} if test x"$HOME" = x/home/wms ; then mkdir obj-d${SYSTEM_TYPE} fi cp configure.h.in obj-${SYSTEM_TYPE}/configure.h.in AC_CONFIG_HEADER(obj-${SYSTEM_TYPE}/configure.h) AC_SUBST(LIBS)dnl AC_SUBST(LIBDIR)dnl AC_SUBST(INCDIR)dnl AC_SUBST(VERSION)dnl AC_SUBST(DATE)dnl AC_PROG_RANLIB AC_ISC_POSIX AC_MINIX AC_AIX AC_CHECK_LIB(m,main) AC_CHECK_LIB(seq,main) AC_CHECK_LIB(nsl,main) AC_CHECK_LIB(socket,main) AC_CHECK_HEADER(curses.h, AC_CHECK_LIB(curses, main, AC_DEFINE(CURSES_DISP) AC_CHECK_LIB(termcap, main) LIBS="-lcurses $LIBS")) AC_STDC_HEADERS AC_CHECK_HEADERS(memory.h sys/select.h unistd.h assert.h stdlib.h string.h netinet/in.h sys/in.h sys/inet.h arpa/nameser.h resolv.h sys/time.h) AC_TIME_WITH_SYS_TIME AC_CHECK_HEADER( sun/audioio.h, AC_DEFINE(SUN_SOUND), AC_CHECK_HEADER( machine/soundcard.h, AC_DEFINE(LINUX_SOUND))) WMS_CHECK_H_ERRNO WMS_CHECK_SOCKETS if test "$cross_compiling" = "yes" ; then echo "********* IMPORTANT *************************************************" echo "*** It looks like either you are cross compiling, or configure cannot" echo "*** figure out how to run your C compiler." echo "*** If you are cross compiling, then configure cannot detect the " echo "*** size of various types and the endian style of your machine. " echo "*** You will have to edit the file obj-${SYSTEM_TYPE}/configure.h " echo "*** by hand." echo "*** If you are NOT cross compiling, then please see the README file" echo "*** for instructions on how to tell ./configure how to run your" echo "*** C compiler." echo "*********************************************************************" else AC_CHECK_SIZEOF(short) if test "x$ac_cv_sizeof_short" '=' x0 ; then echo "********* IMPORTANT *************************************************" echo "*** configure cannot figure out how to run your C compiler." echo "*** figure out how to run your C compiler." echo "*** If you are cross compiling, then configure cannot detect the " echo "*** size of various types and the endian style of your machine. " echo "*** You will have to edit the file obj-${SYSTEM_TYPE}/configure.h " echo "*** by hand." echo "*** If you are NOT cross compiling, then please see the README file" echo "*** for instructions on how to tell ./configure how to run your" echo "*** C compiler." echo "*********************************************************************" exit 1 fi AC_CHECK_SIZEOF(int) AC_CHECK_SIZEOF(long) AC_CHECK_SIZEOF(long long) AC_C_BIGENDIAN fi AC_CHECK_FUNCS(strerror getdtablesize memmove strcasecmp) AC_RETSIGTYPE AC_FIND_X if test '!' "$no_x" ; then AC_DEFINE(X11_DISP) if test "$x_includes" ; then INCDIR="$INCDIR -I$x_includes" fi LIBS="-lX11 $LIBS" if test "$x_libraries" ; then LIBDIR="$LIBDIR -L$x_libraries" fi fi subdirs='comp xio' for dname in ${subdirs}; do mkdir obj-${SYSTEM_TYPE}/$dname if test x"$HOME" = x/home/wms ; then mkdir obj-d${SYSTEM_TYPE}/$dname fi done TOP_FILES='pente pe_snd play board cio textio' PENTE_INCS='src/pente.h src/play.h src/board.h src/comp/comp.h src/comp/eval.h src/xio/xio.h src/xio/setup.h src/xio/helpwin.h src/xio/sound.h src/xio/remAcc.h' COMP_FILES='comp spawn eval move lmove deeptree' XIO_FILES='plasma xio mainwin helpwin strings pentebuts cm2pm setup remote sound remAcc' ofiles=' ' sfiles="README COPYING man6/pente.6 configure Makefile.in configure.h.in install-sh $PENTE_INCS" for ofile in ${TOP_FILES}; do ofiles="${ofiles} obj-\$(SYSTEM_TYPE)/${ofile}.o" sfiles="${sfiles} src/${ofile}.c" done for ofile in ${COMP_FILES}; do ofiles="${ofiles} obj-\$(SYSTEM_TYPE)/comp/${ofile}.o" sfiles="${sfiles} src/comp/${ofile}.c" done for ofile in ${XIO_FILES}; do ofiles="${ofiles} obj-\$(SYSTEM_TYPE)/xio/${ofile}.o" sfiles="${sfiles} src/xio/${ofile}.c" done OBJS=${ofiles} AC_SUBST(OBJS)dnl AC_OUTPUT(Makefile) for ofile in ${TOP_FILES}; do cat <>Makefile obj-\$(SYSTEM_TYPE)/${ofile}.o: src/${ofile}.c cd src; \$(CC) \$(CFLAGS) -c ${ofile}.c mv src/${ofile}.o obj-\$(SYSTEM_TYPE)/${ofile}.o EOF done for ofile in ${COMP_FILES}; do cat <>Makefile obj-\$(SYSTEM_TYPE)/comp/${ofile}.o: src/comp/${ofile}.c cd src/comp; \$(CC) \$(CFLAGS) -c ${ofile}.c mv src/comp/${ofile}.o obj-\$(SYSTEM_TYPE)/comp/${ofile}.o EOF done for ofile in ${XIO_FILES}; do cat <>Makefile obj-\$(SYSTEM_TYPE)/xio/${ofile}.o: src/xio/${ofile}.c cd src/xio; \$(CC) \$(CFLAGS) -c ${ofile}.c mv src/xio/${ofile}.o obj-\$(SYSTEM_TYPE)/xio/${ofile}.o EOF done # I blow away the cache every time. Why? Here's why: # A) You hopefully only ever run configure once per machine type, so # it won't buy most users any time. # B) If you have several machine types sharing a file system, the cache will # make configure break! There's NO CHECK to make sure that the cache is # for the appropriate machine! # These two reasons - especially B - lead me to conclude that autoconf's # caching is not useful in it's current implementation. If code is added # to make it check to ensure that it's on the right machine, great, otherwise # forget it. echo Destroying config.cache rm -f config.cache # Add in wmslib's Makefile TOP_FILES='wms' WMS_FILES='clp clp-x rnd snd str' BUT_FILES='net box but canvas checkbox ctext i_finder i_general i_snd i_win menu menu_snd plain rcur slide tblock text textin timer write' ABUT_FILES='abut swin msg' cfiles=' ' hfiles=' ' ofiles=' ' for tfile in ${TOP_FILES}; do cfiles="${cfiles} wmslib/src/${tfile}.c" hfiles="${hfiles} wmslib/src/${tfile}.h" ofiles="${ofiles} wmslib/obj-\$(SYSTEM_TYPE)/${tfile}.o" done for tfile in ${WMS_FILES}; do cfiles="${cfiles} wmslib/src/wms/${tfile}.c" hfiles="${hfiles} wmslib/src/wms/${tfile}.h" ofiles="${ofiles} wmslib/obj-\$(SYSTEM_TYPE)/wms_${tfile}.o" done for tfile in ${BUT_FILES}; do cfiles="${cfiles} wmslib/src/but/${tfile}.c" hfiles="${hfiles} wmslib/src/but/${tfile}.h" ofiles="${ofiles} wmslib/obj-\$(SYSTEM_TYPE)/but_${tfile}.o" done for tfile in ${ABUT_FILES}; do cfiles="${cfiles} wmslib/src/abut/${tfile}.c" hfiles="${hfiles} wmslib/src/abut/${tfile}.h" ofiles="${ofiles} wmslib/obj-\$(SYSTEM_TYPE)/abut_${tfile}.o" done sfiles="${sfiles} ${cfiles} ${hfiles}" rm -rf wmslib/obj-${SYSTEM_TYPE} wmslib/obj-d${SYSTEM_TYPE} mkdir wmslib/obj-${SYSTEM_TYPE} if test x"$HOME" = x/home/wms ; then mkdir wmslib/obj-d${SYSTEM_TYPE} fi arofiles=`echo ${ofiles} | sed 's&wmslib/obj-$(SYSTEM_TYPE)/&&g'` cat <>Makefile wmslib/libwms-\$(SYSTEM_TYPE).a: ${ofiles} cd wmslib/obj-\$(SYSTEM_TYPE); ar -r libwms-\$(SYSTEM_TYPE).a ${arofiles} mv wmslib/obj-\$(SYSTEM_TYPE)/libwms-\$(SYSTEM_TYPE).a wmslib/libwms-\$(SYSTEM_TYPE).a EOF if test "$RANLIB" '!=' : ; then echo " cd wmslib; ${RANLIB} libwms-\$(SYSTEM_TYPE).a" >>Makefile fi cat <>Makefile EOF for cfile in ${cfiles}; do scfile=`echo $cfile | sed 'sx.*/xx'` sofile=`echo $scfile | sed 's/c$/o/'` dname=`echo $cfile | sed 's&/'${scfile}'$&&'` ofile=`echo $cfile | sed -e 's/src/obj-$(SYSTEM_TYPE)/' -e 'sxbut/xbut_x' -e 'sxabut/xabut_x' -e 'sxwms/xwms_x' -e 's/c$/o/'` cat <>Makefile ${ofile}: ${cfile} cd ${dname}; \$(CC) \$(CFLAGS) -c ${scfile} mv ${dname}/${sofile} ${ofile} EOF done # I only make tar for myself. Why? Because nobody else really needs it # and the line ends up so long it breaks some editors. if test x"$HOME" = x/home/wms ; then tsfiles=' ' for sfile in ${sfiles}; do tsfiles="${tsfiles} pente-\$(VERSION)/${sfile}" done cat <>Makefile tar: cd ..; tar cvf pente-\$(VERSION).tar ${tsfiles} pente-\$(VERSION)/configure.in; gzip -f -9v pente-\$(VERSION).tar EOF fi echo '# DO NOT DELETE' >>Makefile mv Makefile Makefile-${SYSTEM_TYPE} ln -s Makefile-${SYSTEM_TYPE} Makefile if test x"$HOME" = x/home/wms ; then sed Makefile-d${SYSTEM_TYPE} -e 's/SYSTEM_TYPE = /SYSTEM_TYPE = d/' -e 's/^CFLAGS/# Old CFLAGS/' -e 's/# CFLAGS/CFLAGS/' -e 's/^LFLAGS/# Old LFLAGS/' -e 's/# LFLAGS/LFLAGS/' rm -f Makefile-d ln -s Makefile-d${SYSTEM_TYPE} Makefile-d cd obj-d${SYSTEM_TYPE} ln -s ../obj-${SYSTEM_TYPE}/configure.h . fi