./grpn-1.1.2/0040755000175000017500000000000007453220311011333 5ustar wartwart./grpn-1.1.2/CHANGES0100644000175000017500000000131307452745172012341 0ustar wartwart v1.0 Initial Release. v1.0.1: Compile with GTK versions 1.0.x. v1.0.2: Added undo. Up to 10 commands can be undone. Trap the Ctrl-c keypress and quit. v1.0.3: Map the ^ key to the x^y function. v1.0.4 Handle keys in number pad correctly. Fix memory leak in asin and atan of complex numbers. Fix malloc/ free errors introduced with the undo feature. v1.1.0 Add hex, dec, oct, and bin commands. Add rip command. Command line args to set font and window size. Fix possible memory corruption bug when displaying matrices. v1.1.1 Force keyboard entry to be interpreted as a command when prefixed with a single or double quote. v1.1.2 Add db10 and db20 commands. ./grpn-1.1.2/LICENSE0100644000175000017500000004307606723014110012344 0ustar wartwart 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. ./grpn-1.1.2/Makefile0100644000175000017500000000255207453220125012777 0ustar wartwart# Makefile by Paul Wilkins # this will compile the program 'grpn' # Please read the next few lines and enter the correct values. # where to install GRPN PREFIX = /usr/local/ # What compiler should be used CC = gcc # Where to find the gtk-config script GTK_DIR = #GTK_DIR = /loc/libs/gtk+-1.0.6/bin/ # NOTE: # # add -DGTK_VER_1_1 to the CFLAGS if you are using GTK version 1.1.0 or higher # # add -DUSE_GNOME if you want to make grpn GNOME compliant. CFLAGS = -g -O2 -I/usr/X11/include `$(GTK_DIR)gtk-config --cflags` -DGTK_VER_1_1 DFLAGS = -L/usr/X11/lib # end of user configurable section OBJS = test_gtk_ver.o real.o complex.o matrix.o number.o \ funcs.o constant.o button_def.o run_cmd.o \ main.o stack.o lcd.o setup_menu.o callback_menu.o \ process_input.o options.o \ setup_buttons.o callback_buttons.o editor.o \ error.o help.o mode.o undo.o LIBS = `$(GTK_DIR)gtk-config --libs` -lX11 -lm grpn: $(OBJS) $(CC) $(DFLAGS) -o $@ $(OBJS) $(LIBS) pure: $(OBJS) $(PURIFY) $(CC) $(DFLAGS) -o $@ $(OBJS) $(LIBS) install: grpn mkdirhier $(PREFIX)/bin cp grpn $(PREFIX)/bin chmod 755 $(PREFIX)/bin/grpn mkdirhier $(PREFIX)/man/man1 cp grpn.1 $(PREFIX)/man/man1 chmod 644 $(PREFIX)/man/man1/grpn.1 .c.o: $(CC) -c -o $@ $(CFLAGS) $*.c depend: rm -f .depend $(CC) -MM $(CFLAGS) *.c >> .depend clean: rm -f core grpn *.o include .depend ./grpn-1.1.2/README0100644000175000017500000000165307452746421012233 0ustar wartwart GRPN Version 1.1.2 By Paul Wilkins GRPN is a RPN calculator for the X Window system built using the GIMP Toolkit (GTK). GRPN works with real numbers, complex numbers, matrices, and complex matrices. Numbers can be displayed in 4 different radix modes, and complex numbers can be displayed in either Cartesian or polar form. GRPN is copyrighted under the terms of the GNU General Public License. See the file LICENSE for more details. To build GRPN: 1) Edit the Makefile to tell the compiler where to find the X and GTK headers and libraries if you do not have the gtk-config script properly installed. Most systems will not need this. 2) Run make. 3) Copy the executable, grpn, to it's final installation directory, for example /usr/local/bin. GRPN can be found (ftp) at the following locations: ibiblio.org /pub/Linux/apps/math/calc lashwhip.com /pub That's it. Good Luck. Paul paul.wilkins@analog.com ./grpn-1.1.2/button_def.c0100644000175000017500000001237007452746202013643 0ustar wartwart/* Copyright (C) 2002 Paul Wilkins 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /*button_def.c by Paul Wilkins 3/30/97 */ #include #include #include #include "buttons.h" #include "editor.h" #include "lcd.h" #include "funcs.h" #include "mode.h" #include "undo.h" extern void baseCmdCB(GtkWidget *, gpointer); FuncInfo invisible1[] = { { "Hex", "hex", "Hexidecimal display mode.", baseCmdCB, (void *)HEXIDECIMAL }, { "Dec", "dec", "Decimal display mode.", baseCmdCB, (void *)DECIMAL }, { "Oct", "oct", "Octal display mode.", baseCmdCB, (void *)OCTAL }, { "Bin", "bin", "Binary display mode.", baseCmdCB, (void *)BINARY }, { "Db10", "db10", "Convert to dB (Power).", genericButtonCB, (void *)Db10Stack }, { "Db20", "db20", "Convert to dB (Voltage).", genericButtonCB, (void *)Db20Stack }, { "Rip", "rip", "Resistors in parallel.", genericButtonCB, (void *)RipStack }, { "Cplx", "cplx", "Create a complex number.", genericButtonCB, (void *)CplxStack }, { "Cplx", "complex", "Create a complex number.", genericButtonCB, (void *)CplxStack }, { "Mtrx", "mtrx", "Create or decompose a matrix.", genericButtonCB, (void *)MtrxStack }, { "Mtrx", "matrix", "Create or decompose a matrix.", genericButtonCB, (void *)MtrxStack }, { "Undo", "undo", "Undo last command. Up to 10 commands can be undone.", genericButtonCB, (void *)UndoStack }, { "Clear", "clear", "Clears and removes all numbers on the stack.", genericButtonCB, (void *)clearLCD }, { "Quit", "quit", "Quit GRPN.", genericButtonCB, (void *)exit } }; FuncInfo row2[] = { { "Enter", "dup", "Copy the number on the top of the stack.", genericButtonCB, (void *)PushStack }, { "+/-", "neg", "Change sign.", plusMinusCB, NULL }, { "EEX", NULL, "Mouse input: enter an exponent.", enterNumCB, (void *)'e' }, { "DEL", NULL, "Mouse input: backspace.", genericButtonCB, (void *)deleteEditor }, { "Drop", "drop", "Delete the number on the top of the stack.", genericButtonCB, (void *)PopStack }, { "Swap", "swap", "Swap 2 numbers on the top of the stack.", genericButtonCB, (void *)SwapStack } }; FuncInfo num789[] = { { "7", NULL, NULL, enterNumCB, (void *)'7' }, { "8", NULL, NULL, enterNumCB, (void *)'8' }, { "9", NULL, NULL, enterNumCB, (void *)'9' }, { "/", NULL, NULL, genericButtonCB, (void *)DivStack }, { "Pi", "pi", "The constant PI.", genericButtonCB, (void *)PiStack }, { "Sin", "sin", "Trigonometric function Sin.", genericButtonCB, (void *)SinStack }, { "Cos", "cos", "Trigonometric function Cos.", genericButtonCB, (void *)CosStack }, { "Tan", "tan", "Trigonometric function Tan.", genericButtonCB, (void *)TanStack } }; FuncInfo num456[] = { { "4", NULL, NULL, enterNumCB, (void *)'4' }, { "5", NULL, NULL, enterNumCB, (void *)'5' }, { "6", NULL, NULL, enterNumCB, (void *)'6' }, { "x", NULL, NULL, genericButtonCB, (void *)MulStack }, { "1/x", "inv", "Inverse.", genericButtonCB, (void *)InvStack }, { "Asin", "asin", "Trigonometric function Arc-sin.", genericButtonCB, (void *)AsinStack }, { "Acos", "acos", "Trigonometric function Arc-cos.", genericButtonCB, (void *)AcosStack }, { "Atan", "atan", "Trigonometric function Arc-tan.", genericButtonCB, (void *)AtanStack } }; FuncInfo num123[] = { { "1", NULL, NULL, enterNumCB, (void *)'1' }, { "2", NULL, NULL, enterNumCB, (void *)'2' }, { "3", NULL, NULL, enterNumCB, (void *)'3' }, { "-", NULL, NULL, genericButtonCB, (void *)SubStack }, { "Sqrt", "sqrt", "Square root.", genericButtonCB, (void *)SqrtStack }, { "Nroot", "nroot", "N-th root.", genericButtonCB, (void *)NrootStack }, { "Log", "log", "Log base 10.", genericButtonCB, (void *)LogStack }, { "ln", "ln", "Natural log (log base e).", genericButtonCB, (void *)LnStack } }; FuncInfo num0[] = { { "0", NULL, NULL, enterNumCB, (void *)'0' }, { ".", NULL, NULL, enterNumCB, (void *)'.' }, { NULL, NULL, NULL, NULL, NULL }, { "+", NULL, NULL, genericButtonCB, (void *)AddStack }, { " 2\nx ", "sqr", "Square.", genericButtonCB, (void *)SqrStack }, { " x\ny ", "pow", "Power.", genericButtonCB, (void *)PowStack }, { " x\n10 ", "tenx", "Ten to the power.", genericButtonCB, (void *)TenxStack }, { " x\ne ", "exp", "e to the power.", genericButtonCB, (void *)ExpStack } }; int NumButtonRows = 5; int NumFunctionRows = 6; struct RowInfo rowinf[] = { { 6, 6, row2 }, { 8, 8, num789 }, { 8, 8, num456 }, { 8, 8, num123 }, { 8, 8, num0 }, { 14, 0, invisible1 } }; ./grpn-1.1.2/.depend0100664000175000017500000000341107452747000012601 0ustar wartwartbutton_def.o: button_def.c buttons.h funcs.h editor.h lcd.h mode.h \ undo.h callback_buttons.o: callback_buttons.c buttons.h funcs.h editor.h \ error.h lcd.h callback_menu.o: callback_menu.c menu.h lcd.h mode.h funcs.h help.h \ complex.h typedefs.h number.h real.h matrix.h options.h circle.o: circle.c complex.o: complex.c complex.h typedefs.h real.h number.h matrix.h \ constant.h mode.h lcd.h constant.o: constant.c real.h typedefs.h complex.h editor.o: editor.c editor.h funcs.h mode.h error.o: error.c error.h stack.h typedefs.h funcs.o: funcs.c stack.h typedefs.h number.h real.h complex.h matrix.h \ funcs.h undo.h constant.h editor.h run_cmd.h error.h mode.h help.o: help.c help.h funcs.h buttons.h license.h lcd.o: lcd.c lcd.h mode.h number.h typedefs.h real.h complex.h \ matrix.h stack.h process_input.h editor.h error.h undo.h main.o: main.c icon_bitmap stack.h typedefs.h menu.h mode.h lcd.h \ undo.h buttons.h funcs.h constant.h matrix.o: matrix.c matrix.h typedefs.h number.h real.h complex.h \ error.h constant.h mode.o: mode.c mode.h number.h typedefs.h real.h complex.h matrix.h number.o: number.c number.h typedefs.h real.h complex.h matrix.h \ mode.h constant.h error.h options.o: options.c options.h mode.h lcd.h process_input.o: process_input.c process_input.h funcs.h lcd.h \ editor.h error.h real.o: real.c real.h typedefs.h mode.h constant.h run_cmd.o: run_cmd.c buttons.h funcs.h editor.h error.h setup_buttons.o: setup_buttons.c buttons.h funcs.h editor.h setup_menu.o: setup_menu.c menu.h mode.h options.h stack.o: stack.c stack.h typedefs.h number.h real.h complex.h matrix.h test.o: test.c test.h number.h typedefs.h real.h complex.h matrix.h test_gtk_ver.o: test_gtk_ver.c undo.o: undo.c undo.h error.h stack.h typedefs.h number.h real.h \ complex.h matrix.h ./grpn-1.1.2/buttons.h0100644000175000017500000000240207452746202013210 0ustar wartwart/* Copyright (C) 2002 Paul Wilkins 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* buttons.h by Paul Wilkins */ #ifndef __BUTTONS_H #define __BUTTONS_H #include "funcs.h" /* size of a button in pixels */ #define BUTTON_SIZE 30 struct RowInfo { int numBtns; int sizeBtns; FuncInfo *fi; }; extern struct RowInfo rowinf[]; extern int NumButtonRows; extern int NumFunctionRows; GtkWidget *setupButtons(GtkWidget *parent); extern void genericButtonCB(GtkWidget *, gpointer); extern void nullButtonCB(GtkWidget *, gpointer); extern void enterNumCB(GtkWidget *, gpointer); extern void plusMinusCB(GtkWidget *, gpointer); #endif ./grpn-1.1.2/callback_buttons.c0100644000175000017500000000660207452746202015025 0ustar wartwart/* Copyright (C) 2002 Paul Wilkins 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* callback_buttons.c by Paul Wilkins */ #include #include #include "buttons.h" #include "funcs.h" #include "editor.h" #include "error.h" #include "lcd.h" /* the generic button callback function */ void genericButtonCB(GtkWidget *w, gpointer clientData){ FuncInfo *fi = (FuncInfo *)clientData; void (*func)(); /* reset any error string */ resetError(); /* call the real work function */ if(fi->data){ func = fi->data; func(); redrawLCD(); } } /* the null button callback function */ void nullButtonCB(GtkWidget *w, gpointer clientData){ printf("Sorry: Unimpilmented feature\n"); } /* inserts a char into the edit buffer */ void enterNumCB(GtkWidget *w, gpointer clientData){ int tmp; FuncInfo *fi = (FuncInfo *)clientData; /* reset any error string */ resetError(); tmp = (int)fi->data; insertEditor(tmp); redrawLCD(); } /* the +/- key needs a special callback */ /* this is unnessisarily complicated */ void plusMinusCB(GtkWidget *w, gpointer clientData){ char *p, *line; int i, pos, foundE; /* reset any error string */ resetError(); if(isEditingEditor()){ line = getLineEditor(); /* look for an 'e' or 'E' */ foundE = 0; for(p=line; *p!='\0'; p++){ if(*p == 'e' || *p == 'E'){ foundE = 1; break; } } pos = cursorPosEditor(); /* if we found an exponent */ if(foundE){ p++; /* put the cursor after the 'e' or 'E' */ for(i=(p-line)-pos; i>0; i--) rightEditor(); for(i=pos-(p-line); i>0; i--) leftEditor(); if(*p == '+'){ rightEditor(); deleteEditor(); insertEditor('-'); if(pos-(p-line) > 0) pos--; } else if(*p == '-'){ rightEditor(); deleteEditor(); insertEditor('+'); if(pos-(p-line) > 0) pos--; } else { insertEditor('-'); pos++; } /* restore the cursor to where it should be */ for(i=(p-line)-pos+1; i>0; i--) leftEditor(); for(i=pos-(p-line); i>0; i--) rightEditor(); } /* we didn't find an exponent */ else { homeEditor(); if(*line == '+'){ rightEditor(); deleteEditor(); insertEditor('-'); pos--; } else if(*line == '-'){ rightEditor(); deleteEditor(); insertEditor('+'); pos--; } else { insertEditor('-'); } for(i=0; i #include #include "menu.h" #include "lcd.h" #include "mode.h" #include "funcs.h" #include "help.h" #include "complex.h" #include "number.h" #include "options.h" gint delete_event(GtkWidget *w, GdkEvent *e, gpointer d){ return FALSE; /* will call our destroy function */ } void destroy(GtkWidget *widget, gpointer data){ gtk_main_quit(); } /* quit the program */ void quitCB(gpointer data){ gtk_main_quit(); } /* clear the stack */ void clearCB(gpointer data){ clearLCD(); /* refresh the display */ redrawLCD(); } void licenseCB(gpointer data){ license_popup(); } void helpCB(gpointer data){ help_popup(); } /* change the base we use to display the numbers */ void baseCB(gpointer clientData){ setBaseMode((int)clientData); /* refresh the display */ redrawLCD(); refreshModeDisplay(); } void baseCmdCB(GtkWidget *w, gpointer clientData){ FuncInfo *fi = (FuncInfo *)clientData; /* store the mode */ baseCB(fi->data); /* TODO: set the toggles in the buttons */ if(optWindow){ gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(optHexBtn), getBaseMode() == HEXIDECIMAL ? TRUE : FALSE); gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(optDecBtn), getBaseMode() == DECIMAL ? TRUE : FALSE); gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(optOctBtn), getBaseMode() == OCTAL ? TRUE : FALSE); gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(optBinBtn), getBaseMode() == BINARY ? TRUE : FALSE); } } void baseToggleCB(GtkWidget *widget, gpointer data){ if(GTK_TOGGLE_BUTTON(widget)->active){ baseCB(data); } } /* change the radix mode we use to display the numbers */ void radixCB(gpointer clientData){ setRadixMode((int)clientData); /* refresh the display */ redrawLCD(); refreshModeDisplay(); } void radixToggleCB(GtkWidget *widget, gpointer data){ if(GTK_TOGGLE_BUTTON(widget)->active){ radixCB(data); } } /* change the coordinate mode we use to display the numbers */ void cmodeCB(gpointer clientData){ switch((int)clientData){ case RECTANGULAR: setPolarMode(RECTANGULAR); break; case POLAR: setPolarMode(POLAR); break; default: fprintf(stderr, "Error: radixCB: i shouldn't get here\n"); exit(0); } /* refresh the display */ redrawLCD(); refreshModeDisplay(); } void cmodeToggleCB(GtkWidget *widget, gpointer data){ if(GTK_TOGGLE_BUTTON(widget)->active){ cmodeCB(data); } } /* change the display mode we use to display the numbers */ void dmodeCB(gpointer clientData){ setLCDDispMode((int)clientData); /* refresh the display */ redrawLCD(); } void dmodeToggleCB(GtkWidget *widget, gpointer data){ if(GTK_TOGGLE_BUTTON(widget)->active){ dmodeCB(data); } } ./grpn-1.1.2/grpn-1.1.lsm0100644000175000017500000000103307453221061013310 0ustar wartwartBegin4 Title: grpn Version: 1.1.2 Entered-date: Apr. 3, 2002 Description: A RPN calcuator for real and complex numbers with a GTK / X11 GUI. Keywords: math RPN calculator Author: paul.wilkins@analog.com (Paul Wilkins) Maintained-by: paul.wilkins@analog.com (Paul Wilkins) Primary-site: ftp://lashwhip.com/pub 45kB grpn-1.1.2.tar.gz Alternate-site: ftp://ibiblio.org/pub/Linux/apps/math/calc 45kB grpn-1.1.2.tar.gz Copying-policy: GPL End ./grpn-1.1.2/circle.c0100644000175000017500000000206607452746202012754 0ustar wartwart/* Copyright (C) 2002 Paul Wilkins 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include typedef struct _A A; typedef struct _B B; struct _A { int a; B *b; }; struct _B { int b; A *a; }; main(){ A a; B b; a.a = 5; b.b = 9; a.b = &b; b.a = &a; printf("a.a = %d\n", a.a); printf("b.b = %d\n", b.b); printf("a.b->b = %d\n", a.b->b); printf("b.a->a = %d\n", b.a->a); } ./grpn-1.1.2/complex.c0100644000175000017500000003430107452746202013157 0ustar wartwart/* Copyright (C) 2002 Paul Wilkins 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* complex.c by Paul Wilkins */ #include #include #include #include "complex.h" #include "real.h" #include "number.h" #include "constant.h" #include "mode.h" #include "lcd.h" /* we need to know the display size */ /* create a new complex number */ Cmplx * newCmplx(){ Cmplx *p; if(NULL == (p = (Cmplx *)malloc(sizeof(Cmplx)))){ perror("Malloc"); exit(0); } p->re = NULL; p->im = NULL; return p; } void freeCmplx(Cmplx *a){ if(a){ if(a->re) freeReal(a->re); if(a->im) freeReal(a->im); free((char *)a); a = NULL; /* make sure we die... */ } } /* assumes data in in rectangular form */ Cmplx * setCmplxReal(Cmplx *a, Real *rp, Real *ip){ if(a == NULL || rp == NULL || ip == NULL) { fprintf(stderr, "setCmplxReal(NULL)\n"); exit(0); } if(a->re) free((char *)a->re); if(a->im) free((char *)a->im); a->re = setRealReal(newReal(), rp); a->im = setRealReal(newReal(), ip); return a; } /* assumes data in in form defined by getRadixMode() and getPolarMode() */ Cmplx * inputCmplxReal(Cmplx *a, Real *rp, Real *ip){ Cmplx *c1, *c2; if(a == NULL || rp == NULL || ip == NULL) { fprintf(stderr, "setCmplxReal(NULL)\n"); exit(0); } if(a->re) free((char *)a->re); if(a->im) free((char *)a->im); if(getPolarMode() == POLAR){ c1 = newCmplx(); c1->re = setRealReal(newReal(), rp); if(getRadixMode() == DEGREES) c1->im = divReal(ip, real180Pi); else c1->im = setRealReal(newReal(), ip); c2 = rectCmplx(c1); setCmplxCmplx(a, c2); freeCmplx(c1); freeCmplx(c2); } else { a->re = setRealReal(newReal(), rp); a->im = setRealReal(newReal(), ip); } return a; } Cmplx * setCmplxCmplx(Cmplx *a, Cmplx *b){ if(a == NULL || b == NULL) { fprintf(stderr, "setCmplxCmplx(NULL)\n"); exit(0); } if(a->re) free((char *)a->re); if(a->im) free((char *)a->im); a->re = setRealReal(newReal(), b->re); a->im = setRealReal(newReal(), b->im); return a; } #define COMPLEX_PRINT_SIZE 90 char * printCmplxShort(Cmplx *a){ char *c; char *p1; char *p2; Cmplx *c1; if(NULL == (c=(char *)malloc(COMPLEX_PRINT_SIZE))) { perror("Malloc"); exit(0); } if(getPolarMode() == POLAR){ c1 = polarCmplx(a); p1 = printReal(c1->re); if(getRadixMode() == DEGREES){ mulEqReal(c1->im, real180Pi); p2 = printReal(c1->im); } else { p2 = printReal(c1->im); } freeCmplx(c1); } else { p1 = printReal(a->re); p2 = printReal(a->im); } sprintf(c, "(%s, %s)", p1, p2); free(p1); free(p2); return c; } char * printCmplx(Cmplx *a){ char *c; char *p1; char *p2; Cmplx *c1; if(NULL == (c=(char *)malloc(COMPLEX_PRINT_SIZE))) { perror("Malloc"); exit(0); } *c = '\0'; if(getPolarMode() == POLAR){ c1 = polarCmplx(a); p1 = printReal(c1->re); if(getRadixMode() == DEGREES){ mulEqReal(c1->im, real180Pi); p2 = printReal(c1->im); } else { p2 = printReal(c1->im); } freeCmplx(c1); } else { p1 = printReal(a->re); p2 = printReal(a->im); } sprintf(c, "(%s, %s)", p1, p2); if(strlen(p1)+strlen(p2)+4 > lcdWidth-4) *(c+strlen(p1)+2) = '\n'; free(p1); free(p2); return c; } Cmplx * negCmplx(Cmplx *a){ Cmplx *p = newCmplx(); p->re = negReal(a->re); p->im = negReal(a->im); return p; } Cmplx * negEqCmplx(Cmplx *a){ negEqReal(a->re); negEqReal(a->im); return a; } /* calculate 1/(re+im) */ Cmplx * invCmplx(Cmplx *a){ Real *r1, *r2, *r3; Cmplx *p = newCmplx(); /* r1 = re^2 + im^2 */ r1 = mulReal(a->re, a->re); r2 = mulReal(a->im, a->im); addEqReal(r1, r2); p->re = divReal(a->re, r1); r3 = divReal(a->im, r1); p->im = negEqReal(r3); freeReal(r1); freeReal(r2); return p; } /* calculate 1/(re+im) */ Cmplx * invEqCmplx(Cmplx *a){ Real *r1, *r2; /* r1 = re^2 + im^2 */ r1 = mulReal(a->re, a->re); r2 = mulReal(a->im, a->im); addEqReal(r1, r2); divEqReal(a->re, r1); divEqReal(a->im, r1); negEqReal(a->im); freeReal(r1); freeReal(r2); return a; } Cmplx * powCmplxInt(Cmplx *a, int b){ int i; Cmplx *c1, *c2; c1 = setCmplxCmplx(newCmplx(), a);; for(i=1; ire = absCmplx(a); p->im = thetaCmplx(a); return p; } Real * absCmplx(Cmplx *a){ Real *re, *ri; Real *r1, *r2; /* Implements re = re^2 + im^2 but without the range problem */ re = absReal(a->re); ri = absReal(a->im); if(1 == cmpReal(re, ri)){ r2 = re; /* bigger */ r1 = ri; /* smaller */ } else { r2 = ri; r1 = re; } divEqReal(r1, r2); mulEqReal(r1, r1); addEqReal(r1, realOne); powEqReal(r1, realHalf); mulEqReal(r1, r2); freeReal(r2); return r1; } Real * thetaCmplx(Cmplx *a){ int sign_re; Real *r1, *r2; Real *theta; r2 = atanEqReal(divReal(a->im, a->re)); sign_re = cmpReal(a->re, realZero); if(0 == sign_re){ /* -90 deg */ if(-1 == cmpReal(a->im, realZero)) theta = setRealDouble(newReal(), -M_PI/2.0); else /* 90 deg */ theta = setRealDouble(newReal(), M_PI/2.0); freeReal(r2); } /* quadrant 2 and 3 */ else if(-1 == sign_re){ /* quad 3 */ if(-1 == cmpReal(a->im, realZero)) theta = subEqReal(r2, realPi); else /* quad 2 */ theta = addEqReal(r2, realPi); } /* quadrant 1 and 4 */ else{ theta = r2; } return theta; } Cmplx * rectCmplx(Cmplx *a){ Real *r1, *r2; Cmplx *p = newCmplx(); r1 = cosReal(a->im); r2 = sinReal(a->im); p->re = mulEqReal(r1, a->re); p->im = mulEqReal(r2, a->re); return p; } Cmplx * lnCmplx(Cmplx *a){ Cmplx *p; p = polarCmplx(a); lnEqReal(p->re); return p; } /* Note: instead of doing lnCmplx(a)/lnReal(10.0) I did it * like this. Hopefully this way is a little faster??? */ Cmplx * logCmplx(Cmplx *a){ Real *r1; Cmplx *p; p = polarCmplx(a); r1 = lnReal(realTen); logEqReal(p->re); divEqReal(p->im, r1); freeReal(r1); return p; } Cmplx * expCmplx(Cmplx *a){ Real *rr, *ri, *re; Cmplx *p = newCmplx(); rr = cosReal(a->im); ri = sinReal(a->im); re = expReal(a->re); p->re = mulEqReal(rr, re); p->im = mulEqReal(ri, re); freeReal(re); return p; } Cmplx * expEqCmplx(Cmplx *a){ Real *r1, *r2; r1 = expReal(a->re); /* res.re = e^re * cos(im) */ mulEqReal(expEqReal(a->re), (r2=cosReal(a->im))); /* res.im = e^re * sin(im) */ mulEqReal(sinEqReal(a->im), r1); freeReal(r1); freeReal(r2); return a; } /***************** TRIG *************************/ Cmplx * sinCmplx(Cmplx *a){ Real *r1; Cmplx *p; Cmplx *c1, *c2, *c3, *c4, *c5; c1 = mulCmplx(cmplxI, a); c2 = expCmplx(c1); negEqCmplx(c1); c4 = expCmplx(c1); c5 = subCmplx(c2, c4); freeCmplx(c1); freeCmplx(c2); freeCmplx(c4); r1 = setRealDouble(newReal(), 2.0); c1 = setCmplxReal(newCmplx(), realZero, r1); freeReal(r1); p = divCmplx(c5, c1); freeCmplx(c1); freeCmplx(c5); return p; } Cmplx * cosCmplx(Cmplx *a){ Cmplx *p; Cmplx *c1, *c2, *c4; c1 = mulCmplx(cmplxI, a); c2 = expCmplx(c1); negEqCmplx(c1); c4 = expCmplx(c1); p = addCmplx(c2, c4); freeCmplx(c1); freeCmplx(c2); freeCmplx(c4); mulEqReal(p->re, realHalf); mulEqReal(p->im, realHalf); return p; } Cmplx * tanCmplx(Cmplx *a){ Cmplx *p; Cmplx *c1, *c2; c1 = sinCmplx(a); c2 = cosCmplx(a); p = divCmplx(c1, c2); freeCmplx(c1); freeCmplx(c2); return p; } Cmplx * asinCmplx(Cmplx *a){ Real *r1; Cmplx *z, *sqzp1, *sqzm1; Cmplx *c1, *c2, *c3, *c4, *c5, *c6, *c7; z = newCmplx(); setCmplxCmplx(z, a); if(1 == cmpReal(realZero, a->re)) negEqCmplx(z); /* sqrt(z + 1) */ c1 = addCmplxReal(z, realOne); sqzp1 = powCmplxReal(c1, realHalf); freeCmplx(c1); /* sqrt(z - 1) */ c1 = subCmplxReal(z, realOne); sqzm1 = powCmplxReal(c1, realHalf); freeCmplx(c1); /* if imag_part(sqzp1) < 0.0 then sqzp1 = -sqzp1 */ if(1 == cmpReal(realZero, sqzp1->im)) negEqCmplx(sqzp1); c2 = mulCmplx(sqzp1, sqzm1); c3 = addCmplx(c2, z); c4 = lnCmplx(c3); c5 = mulCmplx(c4, cmplxI); c6 = subRealCmplx(realPi2, c5); if(1 == cmpReal(c6->re, realPi2)){ c7 = subRealCmplx(realPi, c6); freeCmplx(c6); c6 = c7; } r1 = negReal(realPi); if(-1 == cmpReal(c6->re, r1)){ c7 = subRealCmplx(r1, c6); freeCmplx(c6); c6 = c7; } freeReal(r1); if(1 == cmpReal(realZero, a->re)) negEqCmplx(c6); freeCmplx(sqzp1); freeCmplx(sqzm1); freeCmplx(z); freeCmplx(c2); freeCmplx(c3); freeCmplx(c4); freeCmplx(c5); return c6; } Cmplx * acosCmplx(Cmplx *a){ Cmplx *p, *c1; c1 = asinCmplx(a); p = subRealCmplx(realPi2, c1); freeCmplx(c1); return p; } Cmplx * atanCmplx(Cmplx *a){ Real *r, *x, *y, *rsq; Real *r1, *r2, *r3, *r4, *r5, *r6, *r7; Cmplx *p = newCmplx(); r = absCmplx(a); x = a->re; y = a->im; rsq = mulReal(r, r); freeReal(r); r1 = mulReal(x, realTwo); r2 = subReal(realOne, rsq); r3 = atan2Real(r1, r2); p->re = mulReal(r3, realHalf); freeReal(r1); freeReal(r2); freeReal(r3); r1 = mulReal(y, realTwo); r2 = addReal(rsq, realOne); r3 = addReal(r2, r1); r4 = subReal(r2, r1); r5 = divReal(r3, r4); r6 = lnReal(r5); r7 = mulReal(realHalf, realHalf); p->im = mulReal(r6, r7); freeReal(r1); freeReal(r2); freeReal(r3); freeReal(r4); freeReal(r5); freeReal(r6); freeReal(r7); freeReal(rsq); return p; } /*************** MULTIPLY **********************/ /* multiply 2 Cmplx numbers */ Cmplx * mulCmplx(Cmplx *a, Cmplx *b){ Real *r1, *r2, *r3, *r4, *r5, *r6; Cmplx *p = newCmplx(); r1 = mulReal(a->re, b->re); r2 = mulReal(a->im, b->im); r3 = mulReal(a->re, b->im); r4 = mulReal(a->im, b->re); p->re = subEqReal(r1, r2); p->im = addEqReal(r3, r4); freeReal(r2); freeReal(r4); return p; } /* multiply a Cmplx by a Real number */ Cmplx * mulCmplxReal(Cmplx *a, Real *b){ Cmplx *p = newCmplx(); p->re = mulReal(a->re, b); p->im = mulReal(a->im, b); return p; } /***************** DIVIDE ***********************/ /* divide 2 Cmplx numbers */ Cmplx * divCmplx(Cmplx *a, Cmplx *b){ Real *r2, *r3; Real *r5, *r6; Real *r8, *r9; Cmplx *p = newCmplx(); /* r3 = bre^2 + bim^2 */ r3 = mulReal(b->re, b->re); r2 = mulReal(b->im, b->im); addEqReal(r3, r2); /* r6 = bre*are + bim*aim */ r6 = mulReal(b->re, a->re); r5 = mulReal(b->im, a->im); addEqReal(r6, r5); /* r9 = bre*aim - bim*are */ r9 = mulReal(b->re, a->im); r8 = mulReal(b->im, a->re); subEqReal(r9, r8); p->re = divEqReal(r6, r3); p->im = divEqReal(r9, r3); freeReal(r2); freeReal(r3); freeReal(r5); freeReal(r8); return p; } /* divide a Cmplx by a Real number */ Cmplx * divCmplxReal(Cmplx *a, Real *b){ Cmplx *p = newCmplx(); p->re = divReal(a->re, b); p->im = divReal(a->im, b); return p; } /* divide a Real by a Cmplx number */ Cmplx * divRealCmplx(Real *a, Cmplx *b){ Real *r2, *r3, *r4, *r5, *r6; Cmplx *p = newCmplx(); /* r3 = bre^2 + bim^2 */ r3 = mulReal(b->re, b->re); r2 = mulReal(b->im, b->im); addEqReal(r3, r2); r4 = divReal(b->re, r3); r5 = divReal(b->im, r3); r6 = negReal(a); p->re = mulEqReal(r4, a); p->im = mulEqReal(r5, r6); freeReal(r2); freeReal(r3); freeReal(r6); return p; } /***************** ADD ***************************/ /* add 2 Cmplx numbers */ Cmplx * addCmplx(Cmplx *a, Cmplx *b){ Cmplx *p = newCmplx(); p->re = addReal(a->re, b->re); p->im = addReal(a->im, b->im); return p; } /* add a Cmplx and a Real number */ Cmplx * addCmplxReal(Cmplx *a, Real *b){ Cmplx *p = newCmplx(); p->re = addReal(a->re, b); p->im = setRealReal(newReal(), a->im); return p; } /******************* SUBTRACT *******************/ /* subtract 2 Cmplx numbers */ Cmplx * subCmplx(Cmplx *a, Cmplx *b){ Cmplx *p = newCmplx(); p->re = subReal(a->re, b->re); p->im = subReal(a->im, b->im); return p; } /* subtract a Real from a Cmplx */ Cmplx * subCmplxReal(Cmplx *a, Real *b){ Cmplx *p = newCmplx(); p->re = subReal(a->re, b); p->im = setRealReal(newReal(), a->im); return p; } /* subtract a Cmplx from a Real */ Cmplx * subRealCmplx(Real *a, Cmplx *b){ Cmplx *p = newCmplx(); p->re = subReal(a, b->re); p->im = negReal(b->im); return p; } ./grpn-1.1.2/complex.h0100644000175000017500000000422607452746202013167 0ustar wartwart/* Copyright (C) 2002 Paul Wilkins 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* complex.h by Paul Wilkins */ /* Here we set up the complex numbers */ #ifndef __COMPLEX_H #define __COMPLEX_H #include "typedefs.h" struct _Cmplx { Real *re; Real *im; }; Cmplx * newCmplx(); void freeCmplx(Cmplx *); char * printCmplx(Cmplx *); char * printCmplxShort(Cmplx *); Cmplx * inputCmplxReal(Cmplx *, Real *, Real *); Cmplx * setCmplxReal(Cmplx *, Real *, Real *); Cmplx * setCmplxCmplx(Cmplx *, Cmplx *); Real * absCmplx(Cmplx *); Real * thetaCmplx(Cmplx *); Cmplx * polarCmplx(Cmplx *); Cmplx * rectCmplx(Cmplx *); Cmplx * negCmplx(Cmplx *); Cmplx * negEqCmplx(Cmplx *); Cmplx * invCmplx(Cmplx *); Cmplx * invEqCmplx(Cmplx *); Cmplx * powCmplxInt(Cmplx *, int); Cmplx * powCmplx(Cmplx *, Cmplx *); Cmplx * powCmplxReal(Cmplx *, Real *); Cmplx * powRealCmplx(Real *, Cmplx *); Cmplx * lnCmplx(Cmplx *); Cmplx * logCmplx(Cmplx *); Cmplx * expCmplx(Cmplx *); Cmplx * expEqCmplx(Cmplx *); Cmplx * sinCmplx(Cmplx *); Cmplx * cosCmplx(Cmplx *); Cmplx * tanCmplx(Cmplx *); Cmplx * asinCmplx(Cmplx *); Cmplx * acosCmplx(Cmplx *); Cmplx * atanCmplx(Cmplx *); Cmplx * mulCmplx(Cmplx *, Cmplx *); Cmplx * mulCmplxReal(Cmplx *, Real *); Cmplx * divCmplx(Cmplx *, Cmplx *); Cmplx * divCmplxReal(Cmplx *, Real *); Cmplx * divRealCmplx(Real *, Cmplx *); Cmplx * addCmplx(Cmplx *, Cmplx *); Cmplx * addCmplxReal(Cmplx *, Real *); Cmplx * subCmplx(Cmplx *, Cmplx *); Cmplx * subCmplxReal(Cmplx *, Real *); Cmplx * subRealCmplx(Real *a, Cmplx *b); #endif ./grpn-1.1.2/constant.c0100644000175000017500000000306707452746203013347 0ustar wartwart/* Copyright (C) 2002 Paul Wilkins 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* constant.c by Paul Wilkins 3/27/97 */ #include #include "real.h" #include "complex.h" Real *realPi; Real *realPi2; Real *realZero; Real *realHalf; Real *realTen; Real *realOne; Real *realTwo; Real *realMOne; Real *real180Pi; Cmplx *cmplxI; void setup_constant(){ Real *tmp; realPi = setRealDouble(newReal(), M_PI); realPi2 = setRealDouble(newReal(), M_PI/2.0); realZero = setRealDouble(newReal(), 0.0); realHalf = setRealDouble(newReal(), 0.5); realTen = setRealDouble(newReal(), 10.0); realOne = setRealDouble(newReal(), 1.0); realTwo = setRealDouble(newReal(), 2.0); realMOne = setRealDouble(newReal(), -1.0); tmp = setRealDouble(newReal(), 180.0); real180Pi = divReal(tmp, realPi); freeReal(tmp); tmp = setRealDouble(newReal(), 1.0); cmplxI = setCmplxReal(newCmplx(), realZero, tmp); freeReal(tmp); } ./grpn-1.1.2/constant.h0100644000175000017500000000205007452746203013343 0ustar wartwart/* Copyright (C) 2002 Paul Wilkins 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* constant.h by Paul Wilkins 3/29/97 */ #ifndef __CONSTANT_H #define __CONSTANT_H extern Real *realPi; extern Real *realPi2; extern Real *realZero; extern Real *realHalf; extern Real *realTen; extern Real *realOne; extern Real *realTwo; extern Real *realMOne; extern Real *real180Pi; extern Cmplx *cmplxI; void setup_constant(); #endif ./grpn-1.1.2/editor.c0100644000175000017500000000441707452746203013004 0ustar wartwart/* Copyright (C) 2002 Paul Wilkins 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* editor.c by Paul Wilkins 3/24/97 */ #include #include "editor.h" #include "funcs.h" #include "mode.h" #define EDIT_BUF_LEN 1024 char Ebuf[EDIT_BUF_LEN]; /* the edit buffer */ char * Epos = Ebuf; /* current cursor position */ char * Eend = Ebuf; /* end of the line */ int isEditingEditor(){ if(Ebuf == Eend) return 0; return 1; } int cursorPosEditor(){ return (int)(Epos-Ebuf); } void setCursorPosEditor(int pos){ if(pos < 0){ Epos = Ebuf; } else if(pos > Eend-Ebuf){ Epos = Eend; } else { Epos = Ebuf + pos; } } char getPrevEditor(){ if(Epos < Ebuf+1) return '\0'; return *(Epos-1); } char * getLineEditor(){ *Eend = '\0'; return Ebuf; } /* process anything in the edit buffer */ void finishEditor(){ if(Eend > Ebuf){ *Eend = '\0'; readLine(Ebuf); } Epos = Eend = Ebuf; } void insertEditor(char c){ char *p; for(p=Eend; p>=Epos; p--) *(p+1) = *p; *Epos = c; Epos++; Eend++; /* check for buffer overrun- leave 1 byte for '\0' */ if(Eend >= Ebuf + EDIT_BUF_LEN - 2) Eend = Ebuf + EDIT_BUF_LEN - 2; if(Epos >= Ebuf + EDIT_BUF_LEN - 2) Epos = Ebuf + EDIT_BUF_LEN - 3; } void deleteEditor(){ char *p; if(Epos == Ebuf) return; for(p=Epos; p Eend) Epos = Eend; } void leftEditor(){ Epos--; if(Epos < Ebuf) Epos = Ebuf; } void cancelEditor(){ Eend = Epos = Ebuf; *Ebuf = '\0'; } ./grpn-1.1.2/editor.h0100644000175000017500000000211607452746203013003 0ustar wartwart/* Copyright (C) 2002 Paul Wilkins 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* editor.h by Paul Wilkins 3/24/97 */ #ifndef __EDITOR_H #define __EDITOR_H int isEditingEditor(); int cursorPosEditor(); char getPrevEditor(); char *getLineEditor(); void finishEditor(); void insertEditor(char c); void deleteEditor(); void homeEditor(); void endEditor(); void rightEditor(); void leftEditor(); void cancelEditor(); void setCursorPosEditor(int pos); #endif ./grpn-1.1.2/error.c0100644000175000017500000000262207452746203012643 0ustar wartwart/* Copyright (C) 2002 Paul Wilkins 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* error.c by Paul Wilkins 3/30/97 */ #include #include #include "error.h" #include "stack.h" char ErrorString[MAX_ERROR_SIZE] = { 0 }; void resetError(){ *ErrorString = '\0'; } int isError(){ return *ErrorString == '\0' ? 0 : 1; } char *getStringError(){ return ErrorString; } void setStringError(char *error){ strncpy(ErrorString, error, MAX_ERROR_SIZE); ErrorString[MAX_ERROR_SIZE-1] = '\0'; } int checkArgs(char *name, int args){ if(stackLen() < args){ sprintf(ErrorString, "%s Error: Too few Arguments.", name); return 1; } return 0; } void invalidTyprError(char *name){ sprintf(ErrorString, "%s Error: Invalid Type.", name); } ./grpn-1.1.2/error.h0100644000175000017500000000173107452746203012650 0ustar wartwart/* Copyright (C) 2002 Paul Wilkins 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef __ERROR_H #define __ERROR_H #define MAX_ERROR_SIZE 1024 extern char ErrorString[MAX_ERROR_SIZE]; void resetError(); int isError(); char *getStringError(); void setStringError(char *); int checkArgs(char *, int); void invalidTyprError(char *); #endif ./grpn-1.1.2/funcs.c0100644000175000017500000003454207452746203012636 0ustar wartwart/* Copyright (C) 2002 Paul Wilkins 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* funcs.c by Paul Wilkins */ #include #include #include #include "stack.h" #include "number.h" #include "funcs.h" #include "undo.h" #include "constant.h" #include "editor.h" #include "run_cmd.h" #include "error.h" #include "mode.h" void decomposeMtrx(); void createMtrx(); Number * readNumber(char *line, int *nread); int isDigitBase(char c); void readLine(char *line){ int pos; /* the number of characters in the number */ Number *n1; if((*line != '"' && *line != '\'') && (isDigitBase(*line) || *line == '-' || *line == '+' || *line == '.')){ /* try to read in a number */ if(NULL == (n1 = readNumber(line, &pos))){ setStringError("Error: Cannot read number."); return; } SaveStackState(0); /* what to restore to the stack after an undo */ Push(n1); UndoStackState(1); /* what to undo from the stack after an undo */ /* what's left must be a command */ if(strlen(line) > pos) runCmd(line+pos); } else { /* this is a command */ runCmd(line); } } void DupStack(){ Number *n1; finishEditor(); if(checkArgs("Dup", 1)) return; SaveStackState(0); /* what to restore to the stack after an undo */ n1 = getStackEle(0); Push(setNumberNumber(newNumber(), n1)); UndoStackState(1); /* what to undo from the stack after an undo */ } void PopStack(){ if(checkArgs("Drop", 1)) return; SaveStackState(1); freeNumber(Pop()); UndoStackState(0); } void PushStack(){ if(isEditingEditor()) finishEditor(); else DupStack(); } void PiStack(){ Number *n1; finishEditor(); SaveStackState(0); n1 = setNumberReal(newNumber(), realPi); Push(n1); UndoStackState(1); } void NegStack(){ Number *n1, *n2; finishEditor(); if(checkArgs("+/-", 1)) return; SaveStackState(1); n2 = negNumber((n1=Pop())); if(n2){ Push(n2); freeNumber(n1); UndoStackState(1); } else { Push(n1); CancelStackState(); } } void InvStack(){ Number *n1, *n2; finishEditor(); if(checkArgs("Inv", 1)) return; SaveStackState(1); n2 = invNumber((n1=Pop())); if(n2){ Push(n2); freeNumber(n1); UndoStackState(1); } else { Push(n1); CancelStackState(); } } void LnStack(){ Number *n1, *n2; finishEditor(); if(checkArgs("ln", 1)) return; SaveStackState(1); n2 = lnNumber((n1=Pop())); if(n2){ Push(n2); freeNumber(n1); UndoStackState(1); } else { Push(n1); CancelStackState(); } } void LogStack(){ Number *n1, *n2; finishEditor(); if(checkArgs("log", 1)) return; SaveStackState(1); n2 = logNumber((n1=Pop())); if(n2){ Push(n2); freeNumber(n1); UndoStackState(1); } else { Push(n1); CancelStackState(); } } void TenxStack(){ Number *n1, *n2, *n3; finishEditor(); if(checkArgs("10^x", 1)) return; SaveStackState(1); n3 = setNumberReal(newNumber(), realTen); n2 = powNumber(n3, (n1=Pop())); freeNumber(n3); if(n2){ Push(n2); freeNumber(n1); UndoStackState(1); } else { Push(n1); CancelStackState(); } } void ExpStack(){ Number *n1, *n2; finishEditor(); if(checkArgs("exp", 1)) return; SaveStackState(1); n2 = expNumber((n1=Pop())); if(n2){ Push(n2); freeNumber(n1); UndoStackState(1); } else { Push(n1); CancelStackState(); } } void PowStack(){ Number *n1, *n2, *n3; finishEditor(); if(checkArgs("pow", 2)) return; SaveStackState(2); n1 = Pop(); n3 = powNumber((n2=Pop()), n1); if(n3){ Push(n3); freeNumber(n1); freeNumber(n2); UndoStackState(1); } else { Push(n2); Push(n1); CancelStackState(); } } void NrootStack(){ Number *n1, *n2, *n3, *n4; finishEditor(); if(checkArgs("nroot", 2)) return; SaveStackState(2); n4 = invNumber((n1=Pop())); if(NULL == n4){ Push(n1); CancelStackState(); return; } n3 = powNumber((n2=Pop()), n4); freeNumber(n4); if(n3){ Push(n3); freeNumber(n1); freeNumber(n2); UndoStackState(1); } else { Push(n2); Push(n1); CancelStackState(); } } void SqrStack(){ Real *r1; Number *n1, *n2, *n3; finishEditor(); if(checkArgs("sqr", 1)) return; SaveStackState(1); r1 = setRealDouble(newReal(), 2.0); n3 = setNumberReal(newNumber(), r1); freeReal(r1); n2 = powNumber((n1=Pop()), n3); freeNumber(n3); if(n2){ Push(n2); freeNumber(n1); UndoStackState(1); } else { Push(n1); CancelStackState(); } } void SqrtStack(){ Number *n1, *n2, *n3; finishEditor(); if(checkArgs("sqrt", 1)) return; SaveStackState(1); n3 = setNumberReal(newNumber(), realHalf); n2 = powNumber((n1=Pop()), n3); freeNumber(n3); if(n2){ Push(n2); freeNumber(n1); UndoStackState(1); } else { Push(n1); CancelStackState(); } } void Db10Stack(){ Number *n1, *n2; finishEditor(); if(checkArgs("db10", 1)) return; SaveStackState(1); n1 = Pop(); n2 = dbNumber(n1, 10.0); if(n2){ Push(n2); freeNumber(n1); UndoStackState(1); } else { Push(n1); CancelStackState(); } } void Db20Stack(){ Number *n1, *n2; finishEditor(); if(checkArgs("db20", 1)) return; SaveStackState(1); n1 = Pop(); n2 = dbNumber(n1, 20.0); if(n2){ Push(n2); freeNumber(n1); UndoStackState(1); } else { Push(n1); CancelStackState(); } } void RipStack(){ Number *n1, *n2, *n3; finishEditor(); if(checkArgs("rip", 2)) return; SaveStackState(2); n1 = Pop(); n3 = ripNumber((n2=Pop()), n1); if(n3){ Push(n3); freeNumber(n1); freeNumber(n2); UndoStackState(1); } else { Push(n2); Push(n1); CancelStackState(); } } void SinStack(){ Number *n1, *n2; finishEditor(); if(checkArgs("sin", 1)) return; SaveStackState(1); n2 = sinNumber((n1=Pop())); if(n2){ Push(n2); freeNumber(n1); UndoStackState(1); } else { Push(n1); CancelStackState(); } } void CosStack(){ Number *n1, *n2; finishEditor(); if(checkArgs("cos", 1)) return; SaveStackState(1); n2 = cosNumber((n1=Pop())); if(n2){ Push(n2); freeNumber(n1); UndoStackState(1); } else { Push(n1); CancelStackState(); } } void TanStack(){ Number *n1, *n2; finishEditor(); if(checkArgs("tan", 1)) return; SaveStackState(1); n2 = tanNumber((n1=Pop())); if(n2){ Push(n2); freeNumber(n1); UndoStackState(1); } else { Push(n1); CancelStackState(); } } void AsinStack(){ Number *n1, *n2; finishEditor(); if(checkArgs("asin", 1)) return; SaveStackState(1); n2 = asinNumber((n1=Pop())); if(n2){ Push(n2); freeNumber(n1); UndoStackState(1); } else { Push(n1); CancelStackState(); } } void AcosStack(){ Number *n1, *n2; finishEditor(); if(checkArgs("acos", 1)) return; SaveStackState(1); n2 = acosNumber((n1=Pop())); if(n2){ Push(n2); freeNumber(n1); UndoStackState(1); } else { Push(n1); CancelStackState(); } } void AtanStack(){ Number *n1, *n2; finishEditor(); if(checkArgs("atan", 1)) return; SaveStackState(1); n2 = atanNumber((n1=Pop())); if(n2){ Push(n2); freeNumber(n1); UndoStackState(1); } else { Push(n1); CancelStackState(); } } void AddStack(){ Number *n1, *n2, *n3; finishEditor(); if(checkArgs("+", 2)) return; SaveStackState(2); n1 = Pop(); n3 = addNumber((n2=Pop()), n1); if(n3){ Push(n3); freeNumber(n1); freeNumber(n2); UndoStackState(1); } else { Push(n2); Push(n1); CancelStackState(); } } void SubStack(){ Number *n1, *n2, *n3; finishEditor(); if(checkArgs("-", 2)) return; SaveStackState(2); n1 = Pop(); n3 = subNumber((n2=Pop()), n1); if(n3){ Push(n3); freeNumber(n1); freeNumber(n2); UndoStackState(1); } else { Push(n2); Push(n1); CancelStackState(); } } void MulStack(){ Number *n1, *n2, *n3; finishEditor(); if(checkArgs("*", 2)) return; SaveStackState(2); n1 = Pop(); n3 = mulNumber((n2=Pop()), n1); if(n3){ Push(n3); freeNumber(n1); freeNumber(n2); UndoStackState(1); } else { Push(n2); Push(n1); CancelStackState(); } } void DivStack(){ Number *n1, *n2, *n3; finishEditor(); if(checkArgs("/", 2)) return; SaveStackState(2); n1 = Pop(); n3 = divNumber((n2=Pop()), n1); if(n3){ Push(n3); freeNumber(n1); freeNumber(n2); UndoStackState(1); } else { Push(n2); Push(n1); CancelStackState(); } } void SwapStack(){ Number *n1, *n2; finishEditor(); if(checkArgs("swap", 2)) return; SaveStackState(2); n1 = Pop(); n2 = Pop(); Push(n1); Push(n2); UndoStackState(2); } void CplxStack(){ Number *n1, *n2; Cmplx *c1; finishEditor(); if(checkArgs("cplx", 2)) return; SaveStackState(2); n1 = Pop(); n2 = Pop(); if(n1->type != REAL || n2->type != REAL){ setStringError("-> complex Error: Bad Argument Type."); Push(n2); Push(n1); CancelStackState(); return; } c1 = inputCmplxReal(newCmplx(), n2->data, n1->data); freeNumber(n1); freeNumber(n2); Push(setNumberCmplx(newNumber(), c1)); freeCmplx(c1); UndoStackState(1); } /* either make a matrix or decompose a matrix */ void MtrxStack(){ Number *n1; finishEditor(); if(checkArgs("matrix", 1)) return; n1 = getStackEle(0); switch(n1->type){ case COMPLEX: setStringError("matrix Error: Bad Argument Type."); break; case MATRIX: decomposeMtrx(); break; case REAL: createMtrx(); break; } } void decomposeMtrx(){ int i, j, matSize; Number *n1, **ptr; Real *rs, *cs; Matrix *m1; if(checkArgs("matrix", 1)) return; SaveStackState(1); n1 = Pop(); m1 = (Matrix *)n1->data; matSize = m1->rows * m1->cols; for(i=0; irows; i++){ for(j=0; jcols; j++){ ptr = m1->data + (m1->cols * i) + j; Push(setNumberNumber(newNumber(), *ptr)); } } Push(setNumberReal(newNumber(), setRealDouble((cs=newReal()), m1->cols))); Push(setNumberReal(newNumber(), setRealDouble((rs=newReal()), m1->rows))); freeReal(cs); freeReal(rs); freeNumber(n1); UndoStackState(2 + matSize); } void createMtrx(){ int i, j; int rows, cols; Number *n1, *n2; Matrix *m1; if(checkArgs("matrix", 2)) return; SaveStackState(2); n1 = Pop(); n2 = Pop(); if(n1->type != REAL || n2->type != REAL){ setStringError("matrix Error: Bad Argument Type."); Push(n2); Push(n1); CancelStackState(); return; } rows = (int)setDoubleReal(n1->data); cols = (int)setDoubleReal(n2->data); if(rows == 0.0 || cols == 0.0){ setStringError("matrix Error: Bad Argument Type."); Push(n2); Push(n1); CancelStackState(); return; } if(checkArgs("matrix", rows * cols)){ Push(n2); Push(n1); CancelStackState(); return; } freeNumber(n1); freeNumber(n2); AddStackState(rows * cols); /* read in the matrix */ m1 = newMatrix(); for(i=rows-1; i>=0; i--){ for(j=cols-1; j>=0; j--){ setMatrix(m1, (n1=Pop()), i, j); freeNumber(n1); } } Push(setNumberMatrix(newNumber(), m1)); freeMatrix(m1); UndoStackState(1); } #define IS_HEX(c) (\ (c)=='a' || (c)=='A' || \ (c)=='b' || (c)=='B' || \ (c)=='c' || (c)=='C' || \ (c)=='d' || (c)=='D' || \ (c)=='e' || (c)=='E' || \ (c)=='f' || (c)=='F' || \ isdigit((c))) #define IS_DEC(c) isdigit((c)) #define IS_OCT(c) (\ (c)=='0' || (c)=='1' || \ (c)=='2' || (c)=='3' || \ (c)=='4' || (c)=='5' || \ (c)=='6' || (c)=='7') #define IS_BIN(c) ((c)=='0' || (c)=='1') int isDigitBase(char c){ switch(getBaseMode()){ case HEXIDECIMAL: return IS_HEX(c); break; case DECIMAL: return IS_DEC(c); break; case OCTAL: return IS_OCT(c); break; case BINARY: return IS_BIN(c); break; } } Number * readNumber(char *line, int *nread){ char *p, buf[2]; int i1; double d1, num; Real *r1; Number *n1; /* read in the number */ switch(getBaseMode()){ case HEXIDECIMAL: *nread = 0; /* look for "0x" */ if(0 == strncmp(line, "0x", 2)){ line+=2; *nread = 2; } num = 0.0; buf[1] = '\0'; for(p=line; IS_HEX(*p); p++, (*nread)++){ buf[0] = *p; sscanf(buf, "%x", &i1); num *= 16.0; num += (double)i1; } if(p-line == 0) return NULL; break; case DECIMAL: /* the line starts with a number-- read it in */ if(1 != sscanf(line, "%lg%n", &num, nread)){ return NULL; } break; case OCTAL: *nread = 0; num = 0.0; buf[1] = '\0'; for(p=line; IS_OCT(*p); p++, (*nread)++){ buf[0] = *p; sscanf(buf, "%d", &i1); num *= 8.0; num += (double)i1; } if(p-line == 0) return NULL; break; case BINARY: *nread = 0; num = 0.0; for(p=line; IS_BIN(*p); p++, (*nread)++){ num *= 2.0; if(*p == '1') num += 1.0; } if(p-line == 0) return NULL; break; } r1 = setRealDouble(newReal(), num); n1 = setNumberReal(newNumber(), r1); freeReal(r1); return n1; } ./grpn-1.1.2/funcs.h0100644000175000017500000000305507452746203012636 0ustar wartwart/* Copyright (C) 2002 Paul Wilkins 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* funcs.h by Paul Willkins 3/20/97 */ #ifndef __FUNCS_H #define __FUNCS_H #include struct _FuncInfo { char *name; char *cmd; char *help; void (*CB)(GtkWidget *, gpointer); void *data; }; typedef struct _FuncInfo FuncInfo; /* functions to manipulate the stack */ void readLine(char *); void DupStack(); void PopStack(); void PushStack(); void PiStack(); void NegStack(); void InvStack(); void LogStack(); void TenxStack(); void ExpStack(); void LnStack(); void PowStack(); void NrootStack(); void RipStack(); void Db10Stack(); void Db20Stack(); void SqrStack(); void SqrtStack(); void SinStack(); void CosStack(); void TanStack(); void AsinStack(); void AcosStack(); void AtanStack(); void AddStack(); void SubStack(); void MulStack(); void DivStack(); void SwapStack(); void CplxStack(); void MtrxStack(); #endif ./grpn-1.1.2/help.c0100644000175000017500000001375507452746203012453 0ustar wartwart/* Copyright (C) 2002 Paul Wilkins 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include #include #include #include "help.h" #include "funcs.h" #include "buttons.h" #include "license.h" #define HELP_TXT \ "\n\ GRPN v1.1.2\n\ \n\ By: Paul Wilkins\n\ paul.wilkins@analog.com\n\ \n\ GRPN is a graphical reverse polish notation (RPN) calculator.\n\ \n\ GRPN works with real numbers, complex numbers, matrices, and\n\ complex matrices. Numbers can be displayed in 4 different\n\ radix modes, and complex numbers can be displayed in either\n\ Cartesian or polar form.\n\ \n\ GRPN uses a stack and reverse polish notation to evaluate\n\ expressions. The stack in GRPN is infinite and limited only\n\ by available memory.\n\ \n\ Expressions are evaluated in reverse polish notation. Unlike\n\ conventional (prefix) notation, RPN requires that all arguments\n\ to a command are entered prior to execution of the command. For\n\ example to add 6.7 to 3.2 you would push both numbers onto the\n\ stack, then press the add (+) button:\n\ \n\ 3.2\n\ 6.7\n\ +\n\ \n\ The result is left on the stack.\n\ \n\ Note that GRPN uses a shorthand for all commands that causes\n\ an automatic before executing a command. The previous\n\ example could then be done as:\n\ \n\ 3.2\n\ 6.7+\n\ \n\ Input is accepted from both the keyboard and the mouse. When\n\ entering a command from the keyboard, the command may be\n\ abbreviated to the shortest set of letters which uniquely\n\ identifies the command.\n\ \n\ Input may be forced to be interpreted as a command by prefixing\n\ the command with double or single quotes. This is useful, for\n\ example when in Hexadecimal mode and you would like to switch to\n\ decimal mode by typing:\n\ dec\n\ \n\ Mouse input simply requires pressing the button with the desired\n\ command.\n\ \n\ Available commands:\n\ \n\ + Add.\n\ - Subtract.\n\ * Multiply.\n\ / Divide.\n\ ^ Power.\n\ Push a number onto the top of the stack.\n\ Push a number onto the top of the stack.\n\ " void popup_window(GtkWidget **dialog, char *txt, char *title){ GtkWidget *vbox; GtkWidget *scrolled_win; GtkWidget *label; GtkWidget *button; if (!*dialog) { *dialog = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(*dialog), title); gtk_signal_connect(GTK_OBJECT(*dialog), "destroy", GTK_SIGNAL_FUNC(gtk_widget_destroyed), dialog); #ifdef GTK_VER_1_1 gtk_container_set_border_width(GTK_CONTAINER(*dialog), 5); #else gtk_container_border_width(GTK_CONTAINER(*dialog), 5); #endif gtk_window_set_title(GTK_WINDOW(*dialog), title); gtk_widget_set_usize(*dialog, 470, 470); vbox = gtk_vbox_new(FALSE, 0); gtk_container_add(GTK_CONTAINER(*dialog), vbox); gtk_widget_show(vbox); scrolled_win = gtk_scrolled_window_new (NULL, NULL); #ifdef GTK_VER_1_1 gtk_container_set_border_width(GTK_CONTAINER(scrolled_win), 5); #else gtk_container_border_width(GTK_CONTAINER(scrolled_win), 5); #endif gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW (scrolled_win), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_box_pack_start(GTK_BOX(vbox), scrolled_win, TRUE, TRUE, 0); gtk_widget_show(scrolled_win); label = gtk_label_new(txt); gtk_signal_connect(GTK_OBJECT(label), "destroy", GTK_SIGNAL_FUNC(gtk_widget_destroyed), &label); gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT); #ifdef GTK_VER_1_1 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled_win), label); #else gtk_container_add(GTK_CONTAINER(scrolled_win), label); #endif gtk_widget_show(label); button = gtk_button_new_with_label("Dismiss"); gtk_signal_connect_object(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy), GTK_OBJECT(*dialog)); gtk_box_pack_end(GTK_BOX(vbox), button, FALSE, FALSE, 0); GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT); /* gtk_widget_grab_default(button); This puts an ugly box around the botton */ gtk_widget_show(button); } if (!GTK_WIDGET_VISIBLE(*dialog)) gtk_widget_show(*dialog); else gtk_widget_destroy(*dialog); } void license_popup(){ static GtkWidget *dialog = NULL; popup_window(&dialog, LICENSE_TXT, "License"); } void help_popup(){ int i, j, k; int cmds; int len; char *htxt; char *cmd; static GtkWidget *dialog = NULL; cmds = 0; for(i=0; i #include #include #include "lcd.h" #include "mode.h" #include "number.h" #include "stack.h" #include "process_input.h" #include "editor.h" #include "error.h" #include "undo.h" #define FONT1 "12x24" #define FONT2 "-*-courier-medium-r-*-*-24-*" #define FONT3 "-misc-fixed-medium-r-normal-*-20-*" #define FONT4 "10x20" #define FONT5 "-*-courier-medium-r-*-*-12-*" #define FONT6 "fixed" /* the amount of spacing we want around the display */ #define BORDER 2 GtkWidget *lcdDA = NULL; char **lcdText = NULL; GdkGC *lcdGC = 0; GdkGC *lcdHighlightGC = 0; /* the last area highlighted */ int dataSelected = 0; int hiX0, hiX1, hiY1; int hiY0, hiX2, hiY2; /* font stuff */ GdkFont *lcdFont; int fontW = 0; int fontH = 0; int fontD = 0; int lcdWidth = 0; int lcdHeight = 0; int lcdDisplayMode = LONG_DISPLAY; int lcdInitalized = 0; /* some callbacks */ static gint lcdExposeCB(GtkWidget *widget, GdkEventExpose *event); static gint lcdResizeCB(GtkWidget *widget, GdkEventConfigure *event); /* local functions */ void calcStackLCD(); void drawStackLCD(); /* this stuff for cut & paste */ #define START_SELECTING 0x1 #define NONE_SELECTED 0x2 #define DATA_SELECTED 0x4 static gint lcdButtonPressEvnt(GtkWidget *widget, GdkEventButton *event); static gint lcdButtonReleaseEvnt(GtkWidget *widget, GdkEventButton *event); static gint lcdMotionEvnt(GtkWidget *widget, GdkEventMotion *event); static gint lcdKeyPressEvnt(GtkWidget *widget, GdkEventKey *event); static gint lcdKeyReleaseEvnt(GtkWidget *widget, GdkEventKey *event); void lcdPasteCB(GtkWidget *, GtkSelectionData *, gpointer); gint loseSelection(GtkWidget *, GdkEventSelection *); #ifdef GTK_VER_1_1 void convertSelection(GtkWidget *, GtkSelectionData *, guint, guint, gpointer); #else void convertSelection(GtkWidget *, GtkSelectionData *, gpointer); #endif void lcdGetSelection(int time); void lcdStartHighlight(int x, int y, int time); void lcdStopHighlight(int x, int y, int time); void lcdContinueHighlight(int x, int y); #define TARGET_STRING 0x1 #define TARGET_TEXT 0x2 #define TARGET_COMPOUND_TEXT 0x4 GtkWidget *setupLCD(GtkWidget *parent, int rows, int cols, char *font){ int i; int width; int wid, hgt; #ifdef GTK_VER_1_1 static GtkTargetEntry targetlist[] = { /* Target Flags Info */ { "STRING", 0, TARGET_STRING }, { "TEXT", 0, TARGET_TEXT }, { "COMPOUND_TEXT", 0, TARGET_COMPOUND_TEXT } }; static gint ntargets = sizeof(targetlist) / sizeof(targetlist[0]); #endif /* store arguments */ lcdWidth = cols; lcdHeight = rows; /* get a font for the main window */ if(font != NULL){ if(NULL == (lcdFont = gdk_font_load(font))){ fprintf(stderr, "Unable to load font %s.\n", font); exit(0); } } else if(NULL == (lcdFont = gdk_font_load(FONT1)) && NULL == (lcdFont = gdk_font_load(FONT2)) && NULL == (lcdFont = gdk_font_load(FONT3)) && NULL == (lcdFont = gdk_font_load(FONT4)) && NULL == (lcdFont = gdk_font_load(FONT5)) && NULL == (lcdFont = gdk_font_load(FONT6))){ fprintf(stderr, "Unable to load a font.\n"); exit(0); } /* find max font width */ for(i=0; i<256; i++){ width = gdk_char_width(lcdFont, (gchar)i); if(width < 50 && width > fontW) fontW = width; } /* globals we use all over the place */ fontH = lcdFont->ascent + lcdFont->descent; fontD = lcdFont->descent; if(fontW == 0 || fontH == 0){ fprintf(stderr, "Error: can not determine font dimentions.\n"); exit(0); } wid = (2 * BORDER) + (lcdWidth * fontW); hgt = (2 * BORDER) + (lcdHeight * fontH); lcdDA = gtk_drawing_area_new(); gtk_drawing_area_size(GTK_DRAWING_AREA(lcdDA), wid, hgt); gtk_box_pack_start(GTK_BOX(parent), lcdDA, TRUE, TRUE, 0); gtk_widget_show(lcdDA); /* Signals used to handle window ops */ gtk_signal_connect(GTK_OBJECT(lcdDA), "expose_event", (GtkSignalFunc)lcdExposeCB, NULL); gtk_signal_connect(GTK_OBJECT(lcdDA),"configure_event", (GtkSignalFunc)lcdResizeCB, NULL); /* Event signals (Selection) */ gtk_signal_connect(GTK_OBJECT(lcdDA), "selection_received", (GtkSignalFunc)lcdPasteCB, NULL); gtk_signal_connect(GTK_OBJECT(lcdDA), "selection_clear_event", (GtkSignalFunc)loseSelection, NULL); /* gtk_signal_connect(GTK_OBJECT(lcdDA), "selection_request_event", (GtkSignalFunc)convertSelection, NULL); */ #ifdef GTK_VER_1_1 gtk_selection_add_targets(lcdDA, GDK_SELECTION_PRIMARY, targetlist, ntargets); gtk_signal_connect(GTK_OBJECT(lcdDA), "selection_get", (GtkSignalFunc)convertSelection, NULL); #else gtk_selection_add_handler(lcdDA, GDK_SELECTION_PRIMARY, GDK_SELECTION_TYPE_STRING, convertSelection, NULL); #endif /* Event signals (Input) */ gtk_signal_connect(GTK_OBJECT(lcdDA), "motion_notify_event", (GtkSignalFunc)lcdMotionEvnt, NULL); gtk_signal_connect(GTK_OBJECT(lcdDA), "button_press_event", (GtkSignalFunc)lcdButtonPressEvnt, NULL); gtk_signal_connect(GTK_OBJECT(lcdDA), "button_release_event", (GtkSignalFunc)lcdButtonReleaseEvnt, NULL); gtk_signal_connect_after(GTK_OBJECT(lcdDA), "key_press_event", (GtkSignalFunc)lcdKeyPressEvnt, NULL); gtk_signal_connect_after(GTK_OBJECT(lcdDA), "key_release_event", (GtkSignalFunc)lcdKeyReleaseEvnt, NULL); gtk_widget_set_events(lcdDA, GDK_EXPOSURE_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK); GTK_WIDGET_SET_FLAGS(lcdDA, GTK_CAN_FOCUS); gtk_widget_grab_focus(lcdDA); return lcdDA; } void clearLCD(){ /* clear the stack */ clearStack(); /* reset any error string */ resetError(); /* clear the entry buffer */ cancelEditor(); /* re-initialize (and clear) the undo system */ initUndoSystem(); /* redraw the window */ calcStackLCD(); drawStackLCD(); } void clearLCDwindow(){ gdk_window_clear(lcdDA->window); } /* Recalculate the contents of the lcd display. * note: we don't redraw the lcd here, that is done by drawStackLCD(). */ void calcStackLCD(){ int i, j; int strLen, pLen, curPos; char *c, *p; char *txt; /* the number */ char label[16]; /* the stack number label */ int height; int indx; int row; /* the row to start print the current number */ int txtPos; /* which col do we start printing in */ int lines; /* the number of lines this number has */ int top; /* which row is the top for drawing the stack */ int bottom; /* which row is the current bottom for drawing the stack */ int labelLen; /* the stack number label length */ Number *num; if(isEditingEditor()){ height = lcdHeight - 1; } else { height = lcdHeight; } if(height <= 0) return; /* clear the old display */ for(i=0; i lcdWidth) strLen = lcdWidth; strncpy(lcdText[0], c, strLen); } else { top = 0; } bottom = height; /* print all of the numbers */ for(indx=0; indx lcdWidth) labelLen = lcdWidth; strncpy(lcdText[row], label, labelLen); /* print the number */ p = txt; for(j=0, i=row; i lcdWidth) break; strncpy(&(lcdText[i][txtPos]), p, lcdWidth-txtPos); p = p + pLen + 1; } /* free the mem used to print the number */ free(txt); bottom = bottom - j; if(bottom == top) break; } /* fill in the rest of the indexes */ for(i=indx, j=bottom; j>top; i++, j--){ sprintf(label, "%d: ", i+1); labelLen = strlen(label); if(labelLen > lcdWidth) labelLen = lcdWidth; strncpy(lcdText[j-1], label, labelLen); } if(isEditingEditor()){ txt = getLineEditor(); curPos = cursorPosEditor(); if(curPos > lcdWidth){ txt += (curPos - lcdWidth); } strLen = strlen(txt); if(strLen > lcdWidth) strLen = lcdWidth; strncpy(lcdText[lcdHeight-1], txt, strLen); } } /* Redraw the contents of the lcd display. * note: start BORDER pixels down and to the right. * TODO: we could be smart and only redraw what has changed. * This does this work correctly with varriable sized fonts. */ void drawStackLCD(){ int i; int curPos; int strt, stop; GdkGC *drawgc; /* draw the stack */ for(i=0; i=hiY1 && i<=hiY2){ stop = hiX1; if(stop > lcdWidth) stop = lcdWidth; } else { stop = lcdWidth; } if(stop-strt){ gdk_window_clear_area(lcdDA->window, strt*fontW + BORDER, i*fontH + BORDER, fontW*(stop-strt), fontH); gdk_draw_text(lcdDA->window, lcdFont, lcdGC, strt*fontW + BORDER, (i+1)*fontH - fontD + BORDER, &lcdText[i][strt], stop-strt); } /* draw the highlighted section of the line */ if(dataSelected == DATA_SELECTED && i>=hiY1 && i<=hiY2){ strt = hiX1; if(strt > lcdWidth) strt = lcdWidth; stop = hiX2+1; if(stop > lcdWidth) stop = lcdWidth; if(stop-strt){ gdk_draw_rectangle(lcdDA->window, lcdGC, TRUE, strt*fontW + BORDER, i*fontH + BORDER, fontW*(stop-strt), fontH); gdk_draw_text(lcdDA->window, lcdFont, lcdHighlightGC, strt*fontW + BORDER, (i+1)*fontH - fontD + BORDER, &lcdText[i][strt], stop-strt); } } /* draw the last unhighlighted section of the line */ stop = lcdWidth; if(dataSelected == DATA_SELECTED && i>=hiY1 && i<=hiY2){ strt = hiX2+1; if(strt > lcdWidth) strt = lcdWidth; } else { strt = lcdWidth; } if(stop-strt){ gdk_window_clear_area(lcdDA->window, strt*fontW + BORDER, i*fontH + BORDER, fontW*(stop-strt), fontH); gdk_draw_text(lcdDA->window, lcdFont, lcdGC, strt*fontW + BORDER, (i+1)*fontH - fontD + BORDER, &lcdText[i][strt], stop-strt); } } /* draw the cursor */ if(isEditingEditor()){ curPos = cursorPosEditor(); if(curPos > lcdWidth){ curPos = lcdWidth; } if(dataSelected == DATA_SELECTED && curPos>=hiX1 && curPos<=hiX2 && lcdHeight-1>=hiY1 && lcdHeight-1<=hiY2) { drawgc = lcdHighlightGC; } else { drawgc = lcdGC; } /* hack: draw a white line to erase any old cursor in position 0. XDrawImageString dosen't cover this up like it does with an old cursor in any other position */ if(!(dataSelected == DATA_SELECTED && 0==hiX1 && lcdHeight-1>=hiY1 && lcdHeight-1<=hiY2)) { gdk_draw_line(lcdDA->window, lcdHighlightGC, BORDER - 1, (lcdHeight-1) * fontH + BORDER, BORDER - 1, lcdHeight * fontH - 1 + BORDER); } /* draw the cursor */ gdk_draw_line(lcdDA->window, drawgc, fontW * curPos - 1 + BORDER, (lcdHeight-1) * fontH + BORDER, fontW * curPos - 1 + BORDER, lcdHeight * fontH - 1 + BORDER); } } /* redraw what we need to */ void redrawLCD(){ calcStackLCD(); drawStackLCD(); } void lcdResize(){ int i; char *buf; int width, height; width = lcdDA->allocation.width; height = lcdDA->allocation.height; lcdWidth = (width - 2*BORDER) / fontW; if(lcdWidth < 0) lcdWidth = 0; lcdHeight = (height - 2*BORDER) / fontH; if(lcdHeight < 0) lcdHeight = 0; /* free the old mem */ if(lcdText){ free(lcdText[0]); free(lcdText); } /* get the new mem. note: add 1 bec size could otherwize be 0. */ if(NULL == (lcdText=(char**)malloc((1+lcdHeight)*sizeof(char *)))){ perror("malloc"); exit(0); } if(NULL == (buf=(char*)malloc(1+lcdHeight*lcdWidth*sizeof(char)))){ perror("malloc"); exit(0); } lcdText[0] = buf; /* in case lcdHeight == 0 */ for(i=0; ifg_gc[GTK_STATE_NORMAL]; lcdHighlightGC = style->bg_gc[GTK_STATE_NORMAL]; lcdResize(); lcdInitalized = 1; } clearLCDwindow(); drawStackLCD(); return FALSE; } static gint lcdResizeCB(GtkWidget *widget, GdkEventConfigure *event){ if(lcdInitalized != 0) lcdResize(); return TRUE; } static gint lcdKeyPressEvnt(GtkWidget *widget, GdkEventKey *event){ char c; if(event->string) c = *(event->string); else c = 'd'; /* just pick something */ processInput( event->keyval, event->state & GDK_CONTROL_MASK ? 1 : 0, c, 'd'); return TRUE; } static gint lcdKeyReleaseEvnt(GtkWidget *widget, GdkEventKey *event){ return TRUE; } static gint lcdButtonPressEvnt(GtkWidget *widget, GdkEventButton *event) { gtk_widget_grab_focus(lcdDA); if(event->button == 1){ lcdStartHighlight(event->x, event->y, event->time); } } static gint lcdButtonReleaseEvnt(GtkWidget *widget, GdkEventButton *event) { switch(event->button){ case 1: /* stop highlighting an area */ lcdStopHighlight(event->x, event->y, event->time); break; case 2: /* paste data */ lcdGetSelection(event->time); break; case 3: /* might be used to continue highlighting */ if(dataSelected == DATA_SELECTED){ lcdContinueHighlight(event->x, event->y); lcdStopHighlight(event->x, event->y, event->time); } break; } } static gint lcdMotionEvnt(GtkWidget *widget, GdkEventMotion *event) { int x, y; GdkModifierType state; if(event->is_hint){ gdk_window_get_pointer(event->window, &x, &y, &state); } else { x = event->x; y = event->y; state = event->state; } if(state & GDK_BUTTON1_MASK){ /* highlighting with button 1 */ lcdContinueHighlight(x, y); } else if(state & GDK_BUTTON3_MASK && dataSelected == DATA_SELECTED){ /* continuing a highlight with button 3 */ lcdContinueHighlight(x, y); } return TRUE; } #ifdef GTK_VER_1_1 void convertSelection( GtkWidget *widget, GtkSelectionData *selection, guint info, guint time, gpointer data) #else void convertSelection( GtkWidget *widget, GtkSelectionData *selection, gpointer data) #endif { int i; int width, height; char *str; guchar *text; gint len; gint format; GdkAtom type; /* no highlight */ if(dataSelected != DATA_SELECTED){ printf("convertSelection called, but no selection.\n"); } else { width = hiX2 - hiX1 + 1; height = hiY2 - hiY1 + 1; len = (width + 1) * height; str = (char *)malloc(len * sizeof(char)); for(i=0; itarget){ #endif case GDK_TARGET_STRING: case TARGET_STRING: gtk_selection_data_set( selection, GDK_SELECTION_TYPE_STRING, 8, str, len-1); break; case TARGET_TEXT: case TARGET_COMPOUND_TEXT: gdk_string_to_compound_text(str, &type, &format, &text, &len); gtk_selection_data_set( selection, type, format, text, len); gdk_free_compound_text(text); break; } } } gint loseSelection( GtkWidget *widget, GdkEventSelection *event) { /* if there is a current (old) selection, then clear it */ if(dataSelected == DATA_SELECTED){ dataSelected = NONE_SELECTED; drawStackLCD(); } return TRUE; } void lcdStartHighlight(int x, int y, int time){ int xx, yy; /* if there is a current (old) selection, then clear it */ if(dataSelected == DATA_SELECTED){ dataSelected = NONE_SELECTED; drawStackLCD(); /* ... and tell GDK */ if(gdk_selection_owner_get(GDK_SELECTION_PRIMARY) == lcdDA->window){ gtk_selection_owner_set(NULL, GDK_SELECTION_PRIMARY, GDK_CURRENT_TIME); } } xx = (x - BORDER) / fontW; if(xx < 0) xx = 0; if(xx >= lcdWidth) xx = lcdWidth - 1; yy = (y - BORDER) / fontH; if(yy < 0) yy = 0; if(yy >= lcdHeight) yy = lcdHeight - 1; hiX0 = hiX1 = hiX2 = xx; hiY0 = hiY1 = hiY2 = yy; dataSelected = START_SELECTING; } void lcdStopHighlight(int x, int y, int time){ int reCalc, curPos; int xx, yy; /* if the user started to select something, but didn't actually select anything, then reset stuff */ if(dataSelected == START_SELECTING){ dataSelected = NONE_SELECTED; /* user may have been positioning the edit cursor */ if(isEditingEditor()){ xx = (x - BORDER) / fontW; if(xx < 0) xx = 0; if(xx >= lcdWidth) xx = lcdWidth - 1; yy = (y - BORDER) / fontH; if(yy == lcdHeight-1){ curPos = cursorPosEditor(); if(curPos > lcdWidth){ reCalc = 1; xx += (curPos - lcdWidth); } else { reCalc = 0; } setCursorPosEditor(xx); /* need to recalc since cursor may have moved out of the visable part of the editor */ if(reCalc) calcStackLCD(); } } /* clear any old highlights */ drawStackLCD(); } /* if data is now selected */ if(dataSelected == DATA_SELECTED){ if(0 == gtk_selection_owner_set( lcdDA, GDK_SELECTION_PRIMARY, GDK_CURRENT_TIME)) { fprintf(stderr, "failed to gain selection\n"); dataSelected = NONE_SELECTED; drawStackLCD(); } } } void lcdContinueHighlight(int x, int y){ int xx, yy; int lastx1, lastx2, lasty1, lasty2; xx = (x - BORDER) / fontW; if(xx < 0) xx = 0; if(xx >= lcdWidth) xx = lcdWidth - 1; yy = (y - BORDER) / fontH; if(yy < 0) yy = 0; if(yy >= lcdHeight) yy = lcdHeight - 1; lastx1 = hiX1; lastx2 = hiX2; lasty1 = hiY1; lasty2 = hiY2; if(xx < hiX0){ hiX1 = xx; hiX2 = hiX0 + 0; } else { hiX1 = hiX0; hiX2 = xx + 0; } if(yy < hiY0){ hiY1 = yy; hiY2 = hiY0 + 0; } else { hiY1 = hiY0; hiY2 = yy + 0; } /* if the highlight area changed */ if(lastx1 != hiX1 || lastx2 != hiX2 || lasty1 != hiY1 || lasty2 != hiY2){ dataSelected = DATA_SELECTED; /* repaint the display */ drawStackLCD(); } } /* ask for data */ void lcdGetSelection(int time){ /* And request the primary selection */ gtk_selection_convert(lcdDA, GDK_SELECTION_PRIMARY, /* GdkAtom selection */ GDK_TARGET_STRING, /* GdkAtom target */ GDK_CURRENT_TIME); /* guint32 time */ } void lcdPasteCB( GtkWidget *widget, GtkSelectionData *selection, gpointer data) { int i; char *str; static GdkAtom clipboard_atom = GDK_NONE; if(selection->length <= 0 || selection->type != GDK_SELECTION_TYPE_STRING){ /* printf("length is zero or did not get a string.\n"); */ if(selection->selection != GDK_SELECTION_PRIMARY) return; /* selection failed. Try the clipboard now... */ if(clipboard_atom == GDK_NONE){ clipboard_atom = gdk_atom_intern("CLIPBOARD", FALSE); } /* ask for another selection, but this time from the clipboard */ gtk_selection_convert(lcdDA, clipboard_atom, /* GdkAtom selection */ GDK_TARGET_STRING, /* GdkAtom target */ GDK_CURRENT_TIME); /* guint32 time */ return; } str = (char*)selection->data; for(i=0; ilength; i++){ /* TODO maybe do something like isalpha() here? */ processInput(0, 0, str[i], str[i]); } } ./grpn-1.1.2/lcd.h0100644000175000017500000000201407452746203012254 0ustar wartwart/* Copyright (C) 2002 Paul Wilkins 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* lcd.h by Paul Wilkins 3/21/97 */ #ifndef __LCD_H #define __LCD_H #include /* display area in characters */ extern int lcdWidth; extern int lcdHeight; GtkWidget *setupLCD(GtkWidget *, int, int, char *); void redrawLCD(); void clearLCD(); void setLCDDispMode(int); int getLCDDispMode(); #endif ./grpn-1.1.2/license.h0100644000175000017500000000276007452746203013144 0ustar wartwart/* Copyright (C) 2002 Paul Wilkins 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #define LICENSE_TXT "\n\ \n\ Copyright (C) 2002 Paul Wilkins\n\ \n\ This program is free software; you can redistribute it and/or\n\ modify it under the terms of the GNU General Public License\n\ as published by the Free Software Foundation; either version 2\n\ of the License, or (at your option) any later version.\n\ \n\ This program is distributed in the hope that it will be useful,\n\ but WITHOUT ANY WARRANTY; without even the implied warranty of\n\ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See\n\ the GNU General Public License for more details.\n\ \n\ You should have received a copy of the GNU General Public License\n\ along with this program; if not, write to the Free Software\n\ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA \n\ 02111-1307, USA.\n\ \n\ \n\ " ./grpn-1.1.2/main.c0100644000175000017500000001352307452746203012440 0ustar wartwart/* Copyright (C) 2002 Paul Wilkins 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* main.c by Paul Wilkins. * This file contains the main program. */ #include #ifdef USE_GNOME #include #endif #include #include "icon_bitmap" #include "stack.h" #include "menu.h" #include "mode.h" #include "lcd.h" #include "undo.h" #include "buttons.h" #include "constant.h" void usage(char *str){ fprintf(stderr, "Error: %s\n", str); fprintf(stderr, "Usage: grpn [-fn font] [-btn-fn font] [-disp-fn font]\n"); fprintf(stderr, " [-rows n] [-cols n] [-b]\n"); fprintf(stderr, " -b: Don't draw the buttons.\n"); fprintf(stderr, " -rows: Display (a minimum of) \"n\" rows.\n"); fprintf(stderr, " -cols: Display (a minimum of) \"n\" columns.\n"); fprintf(stderr, " -btn-fn: Use \"font\" for the buttons and menu-bar.\n"); fprintf(stderr, " -disp-fn: Use \"font\" for the main display.\n"); fprintf(stderr, " -fn: Specifies both -btn-fn and -disp-fn.\n"); } GtkWidget *main_w; main(int argc, char *argv[]) { int n; int rows, cols; int drawButtons; char *btn_font, *disp_font; /* GtkWidget *main_w; */ GtkWidget *vbox; GtkWidget *menu; GtkWidget *mdisp; GtkWidget *lcd; GtkWidget *btns; GdkFont *new_font; GtkStyle *default_style, *new_style; GdkBitmap *icon_bitmap; #ifdef USE_GNOME GnomeAppBar *appbar; #endif #ifdef USE_GNOME gnome_init("grpn", "1.0", argc, argv); gnome_app_new("grpn", "grpn"); #else /* initialize gtk */ gtk_init(&argc, &argv); #endif /* initial values */ drawButtons = 1; rows = 8; cols = 30; btn_font = disp_font = NULL; /* process command line args */ n = 1; while(n < argc){ if(0 == strcmp("-fn", argv[n])){ n++; if(n >= argc){ usage("Missing required argument for -fn."); exit(0); } btn_font = disp_font = argv[n]; } else if(0 == strcmp("-btn-fn", argv[n])){ n++; if(n >= argc){ usage("Missing required argument for -btn-fn."); exit(0); } btn_font = argv[n]; } else if(0 == strcmp("-disp-fn", argv[n])){ n++; if(n >= argc){ usage("Missing required argument for -disp-fn."); exit(0); } disp_font = argv[n]; } else if(0 == strcmp("-rows", argv[n])){ n++; if(n >= argc){ usage("Missing required argument for -rows."); exit(0); } if(1 != sscanf(argv[n], "%d", &rows)){ usage("Unable to read number or rows."); exit(0); } } else if(0 == strcmp("-cols", argv[n])){ n++; if(n >= argc){ usage("Missing required argument for -cols."); exit(0); } if(1 != sscanf(argv[n], "%d", &cols)){ usage("Unable to read number or cols."); exit(0); } } else if(0 == strcmp("-b", argv[n])){ drawButtons = 0; } else { usage("Unknown Argument."); exit(0); } n++; } /* set up any constants we may use */ setup_constant(); /* initialize the undo system */ initUndoSystem(); /* setup the stack */ if(0 == setup_stack()){ fprintf(stderr, "Error: Could not initalize data structures.\n"); exit(0); } /* set the font if told */ if(btn_font != NULL){ default_style = gtk_widget_get_default_style(); if(NULL == (new_font = gdk_font_load(btn_font))){ fprintf(stderr, "Unable to load font %s.\n", btn_font); exit(0); } new_style = gtk_style_copy(default_style); new_style->font = new_font; gtk_widget_set_default_style(new_style); } #ifdef USE_GNOME main_w = gnome_app_new("grpn", "grpn"); setup_menu(main_w); appbar = GNOME_APPBAR(gnome_appbar_new(FALSE, FALSE, FALSE)); gnome_app_set_statusbar(GNOME_APP(main_w), GTK_WIDGET(appbar)); /*create the box that everyone goes in */ vbox = gtk_vbox_new(FALSE, 0); gnome_app_set_contents(GNOME_APP(main_w), vbox); gtk_widget_show(vbox); #else /* the main window contains the work area and the menubar */ main_w = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_widget_set_name(main_w, "grpn"); /*create the box that everyone goes in */ vbox = gtk_vbox_new(FALSE, 0); gtk_container_add(GTK_CONTAINER(main_w), vbox); gtk_widget_show(vbox); /* set up the menu bar */ menu = setup_menu(vbox); #endif /* handle window manager close */ gtk_signal_connect(GTK_OBJECT(main_w), "delete_event", GTK_SIGNAL_FUNC(delete_event), NULL); gtk_signal_connect(GTK_OBJECT(main_w), "destroy", GTK_SIGNAL_FUNC(destroy), NULL); /* create the varrious subsystems */ mdisp = setupModeDisplay(vbox); if(drawButtons) btns = setupButtons(vbox); lcd = setupLCD(vbox, rows, cols, disp_font); /* Create pixmap of depth 1 (bitmap) for icon */ gtk_widget_realize(main_w); icon_bitmap = gdk_bitmap_create_from_data(main_w->window, icon_bitmap_bits, icon_bitmap_width, icon_bitmap_height); gdk_window_set_icon(main_w->window, NULL, icon_bitmap, NULL); gtk_widget_show(main_w); gtk_main(); } ./grpn-1.1.2/matrix.c0100644000175000017500000003217607452746203013025 0ustar wartwart/* Copyright (C) 2002 Paul Wilkins 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* matrix.c by Paul Wilkins */ #include #include #include #include #include "matrix.h" #include "number.h" #include "error.h" #include "constant.h" /* get the space for the data */ Number ** mallocData(Number **d, int rows, int cols){ int i, j; int size; Number **p; if(d){ size = rows*cols*sizeof(Number *); if(NULL == (p=(Number **)realloc((char *)d, size))){ perror("realloc"); exit(0); } } else { if(NULL == (p = (Number **)malloc(rows*cols*sizeof(Number *)))){ perror("Malloc"); exit(0); } } return p; } /* create a new matrix */ Matrix * newMatrix(){ Matrix *p; if(NULL == (p = (Matrix *)malloc(sizeof(Matrix)))){ perror("Malloc"); exit(0); } p->rows = 0; p->cols = 0; p->data = NULL; return p; } void freeMatrix(Matrix *a){ int i, j; Number **ptr; if(a->data){ for(i=0; irows; i++) for(j=0; jcols; j++){ ptr = a->data + (a->cols * i) + j; freeNumber(*ptr); } free((char *)a->data); } free((char *)a); } void setMatrix(Matrix *a, Number *b, int row, int col){ int oldrows, oldcols; Number **ptr; row++; col++; if(a->data == NULL){ if(row > a->rows) a->rows = row; if(col > a->cols) a->cols = col; a->data = mallocData(NULL, a->rows, a->cols); memset(a->data, 0, a->rows*a->cols*sizeof(Number *)); } else if(row > a->rows || col > a->cols){ oldrows = a->rows; oldcols = a->cols; if(row > a->rows) a->rows = row; if(col > a->cols) a->cols = col; a->data = mallocData(a->data, a->rows, a->cols); memset(a->data+(oldrows*oldcols), 0, ((a->rows*a->cols)-(oldrows*oldcols))*sizeof(Number *)); } row--; col--; ptr = a->data + (a->cols * row) + col; *ptr = setNumberNumber(newNumber(), b); } Matrix * setMatrixMatrix(Matrix *a, Matrix *b){ int i, j; Number *n1; Number **ptr1, **ptr2; if(a == NULL || b == NULL) { fprintf(stderr, "setMatrixMatrix(NULL)\n"); exit(0); } /* initalize the stuff in p */ a->data = mallocData(NULL, b->rows, b->cols); a->rows = b->rows; a->cols = b->cols; /* p[i][j] = b + a[i][j] */ for(i=0; irows; i++) for(j=0; jcols; j++){ ptr1 = b->data + (a->cols * i) + j; ptr2 = a->data + (a->cols * i) + j; *ptr2 = setNumberNumber(newNumber(), *ptr1); } return a; } #define MATRIX_PRINT_SIZE 50 char * printMatrixShort(Matrix *a){ char *c; if(NULL == (c=(char *)malloc(MATRIX_PRINT_SIZE))) { perror("Malloc"); exit(0); } sprintf(c, "[%d x %d Matrix]", a->rows, a->cols); return c; } char * printMatrix(Matrix *a){ char *c; char *p1; int i, j; if(NULL == (c=(char *)malloc(MATRIX_PRINT_SIZE*a->rows*a->cols))) { perror("Malloc"); exit(0); } *c = '\0'; if(a->data){ strcat(c, "[ "); for(i=0; irows; i++){ for(j=0; jcols; j++){ strcat(c, (p1=printNumberShort(*(a->data+(a->cols*i)+j)))); strcat(c, " "); free(p1); } if(i < a->rows-1) strcat(c, " \n"); } strcat(c, "]"); } return c; } Matrix * negMatrix(Matrix *a){ int i, j; Number **ptr1, **ptr2; Matrix *p = newMatrix(); if(a == NULL) { fprintf(stderr, "negMatrix(NULL)\n"); exit(0); } /* initalize the stuff in p */ p->data = mallocData(NULL, a->rows, a->cols); p->rows = a->rows; p->cols = a->cols; /* p[i][j] = b + a[i][j] */ for(i=0; irows; i++) for(j=0; jcols; j++){ ptr1 = a->data + (a->cols * i) + j; ptr2 = p->data + (a->cols * i) + j; *ptr2 = negNumber(*ptr1); } return p; } Matrix * invMatrix(Matrix *a){ printf("TODO: Inv Matrix\n"); return NULL; } /***************** MULTIPLY *******************/ /* multiply 2 Matrixes */ Matrix * mulMatrix(Matrix *a, Matrix *b){ int i, j, k; Matrix *p; Number *n1, *n2, *nsum; Number **ptr1, **ptr2, **ptr3; if(a == NULL || b == NULL) { fprintf(stderr, "mulMatrix(NULL)\n"); exit(0); } if(a->cols != b->rows){ sprintf(getStringError(), "* Error: Invalid dimension."); return NULL; } /* initalize the stuff in p */ p = newMatrix(); p->data = mallocData(NULL, a->rows, b->cols); p->rows = a->rows; p->cols = b->cols; /* p[i][j] = sum t=1 to k of a[i][t]*b[t][j] */ for(i=0; irows; i++){ for(j=0; jcols; j++){ ptr3 = p->data + (p->cols * i) + j; nsum = setNumberReal(newNumber(), realZero); for(k=0; kcols; k++){ ptr1 = a->data + (a->cols * i) + k; ptr2 = b->data + (b->cols * k) + j; n1 = mulNumber(*ptr1, *ptr2); n2 = nsum; nsum = addNumber(n2, n1); freeNumber(n1); freeNumber(n2); } *ptr3 = nsum; } } return p; } /* multiply a Matrix and a Cmplx */ Matrix * mulMatrixCmplx(Matrix *a, Cmplx *b){ int i, j; Number *n1; Number **ptr1, **ptr2; Matrix *p = newMatrix(); if(a == NULL) { fprintf(stderr, "mulMatrixCmplx(NULL)\n"); exit(0); } /* initalize the stuff in p */ p->data = mallocData(NULL, a->rows, a->cols); p->rows = a->rows; p->cols = a->cols; /* p[i][j] = b + a[i][j] */ for(i=0; irows; i++) for(j=0; jcols; j++){ ptr1 = a->data + (a->cols * i) + j; ptr2 = p->data + (a->cols * i) + j; *ptr2 = mulNumber(*ptr1, (n1=setNumberCmplx(newNumber(), b))); freeNumber(n1); } return p; } /* multiply a Matrix and a Real */ Matrix * mulMatrixReal(Matrix *a, Real *b){ int i, j; Number *n1; Number **ptr1, **ptr2; Matrix *p = newMatrix(); if(a == NULL) { fprintf(stderr, "mulMatrixReal(NULL)\n"); exit(0); } /* initalize the stuff in p */ p->data = mallocData(NULL, a->rows, a->cols); p->rows = a->rows; p->cols = a->cols; /* p[i][j] = b + a[i][j] */ for(i=0; irows; i++) for(j=0; jcols; j++){ ptr1 = a->data + (a->cols * i) + j; ptr2 = p->data + (a->cols * i) + j; *ptr2 = mulNumber(*ptr1, (n1=setNumberReal(newNumber(), b))); freeNumber(n1); } return p; } /***************** DIVIDE *******************/ /* divide 2 Matrixes */ Matrix * divMatrix(Matrix *a, Matrix *b){ invalidTyprError("/"); return NULL; } /* divide a Cmplx by a Matrix */ Matrix * divCmplxMatrix(Cmplx *a, Matrix *b){ invalidTyprError("/"); return NULL; } /* divide a Cmplx by a Matrix */ Matrix * divRealMatrix(Real *a, Matrix *b){ invalidTyprError("/"); return NULL; } /* divide a Matrix by a Cmplx */ Matrix * divMatrixCmplx(Matrix *a, Cmplx *b){ int i, j; Number *n1; Number **ptr1, **ptr2; Matrix *p = newMatrix(); if(a == NULL) { fprintf(stderr, "divMatrixCmplx(NULL)\n"); exit(0); } /* initalize the stuff in p */ p->data = mallocData(NULL, a->rows, a->cols); p->rows = a->rows; p->cols = a->cols; /* p[i][j] = b + a[i][j] */ for(i=0; irows; i++) for(j=0; jcols; j++){ ptr1 = a->data + (a->cols * i) + j; ptr2 = p->data + (a->cols * i) + j; *ptr2 = divNumber(*ptr1, (n1=setNumberCmplx(newNumber(), b))); freeNumber(n1); } return p; } /* divide a Matrix by a Real */ Matrix * divMatrixReal(Matrix *a, Real *b){ int i, j; Number *n1; Number **ptr1, **ptr2; Matrix *p = newMatrix(); if(a == NULL) { fprintf(stderr, "divMatrixReal(NULL)\n"); exit(0); } /* initalize the stuff in p */ p->data = mallocData(NULL, a->rows, a->cols); p->rows = a->rows; p->cols = a->cols; /* p[i][j] = b + a[i][j] */ for(i=0; irows; i++) for(j=0; jcols; j++){ ptr1 = a->data + (a->cols * i) + j; ptr2 = p->data + (a->cols * i) + j; *ptr2 = divNumber(*ptr1, (n1=setNumberReal(newNumber(), b))); freeNumber(n1); } return p; } /***************** ADD *******************/ /* add 2 Matrixes */ Matrix * addMatrix(Matrix *a, Matrix *b){ int i, j; Number **ptr1, **ptr2, **ptr3; Matrix *p; if(a == NULL || b == NULL) { fprintf(stderr, "addMatrix(NULL)\n"); exit(0); } if(a->rows != b->rows || a->cols != b->cols){ sprintf(getStringError(), "+ Error: Invalid dimension."); return NULL; } /* initalize the stuff in p */ p = newMatrix(); p->data = mallocData(NULL, a->rows, a->cols); p->rows = a->rows; p->cols = a->cols; /* p[i][j] = b + a[i][j] */ for(i=0; irows; i++) for(j=0; jcols; j++){ ptr1 = a->data + (a->cols * i) + j; ptr2 = b->data + (a->cols * i) + j; ptr3 = p->data + (a->cols * i) + j; *ptr3 = addNumber(*ptr1, *ptr2); } return p; } /* add a Matrix and a Cmplx */ Matrix * addMatrixCmplx(Matrix *a, Cmplx *b){ int i, j; Number *n1; Number **ptr1, **ptr2; Matrix *p = newMatrix(); if(a == NULL) { fprintf(stderr, "addMatrixCmplx(NULL)\n"); exit(0); } /* initalize the stuff in p */ p->data = mallocData(NULL, a->rows, a->cols); p->rows = a->rows; p->cols = a->cols; /* p[i][j] = b + a[i][j] */ for(i=0; irows; i++) for(j=0; jcols; j++){ ptr1 = a->data + (a->cols * i) + j; ptr2 = p->data + (a->cols * i) + j; *ptr2 = addNumber(*ptr1, (n1=setNumberCmplx(newNumber(), b))); freeNumber(n1); } return p; } /* add a Matrix and a Real */ Matrix * addMatrixReal(Matrix *a, Real *b){ int i, j; Number *n1; Number **ptr1, **ptr2; Matrix *p = newMatrix(); if(a == NULL) { fprintf(stderr, "addMatrixReal(NULL)\n"); exit(0); } /* initalize the stuff in p */ p->data = mallocData(NULL, a->rows, a->cols); p->rows = a->rows; p->cols = a->cols; /* p[i][j] = b + a[i][j] */ for(i=0; irows; i++) for(j=0; jcols; j++){ ptr1 = a->data + (a->cols * i) + j; ptr2 = p->data + (a->cols * i) + j; *ptr2 = addNumber(*ptr1, (n1=setNumberReal(newNumber(), b))); freeNumber(n1); } return p; } /***************** SUBTRACT *******************/ /* subtract 2 Matrixes */ Matrix * subMatrix(Matrix *a, Matrix *b){ int i, j; Number **ptr1, **ptr2, **ptr3; Matrix *p; if(a == NULL || b == NULL) { fprintf(stderr, "subMatrix(NULL)\n"); exit(0); } if(a->rows != b->rows || a->cols != b->cols){ sprintf(getStringError(), "- Error: Invalid dimension."); return NULL; } /* initalize the stuff in p */ p = newMatrix(); p->data = mallocData(NULL, a->rows, a->cols); p->rows = a->rows; p->cols = a->cols; /* p[i][j] = b + a[i][j] */ for(i=0; irows; i++) for(j=0; jcols; j++){ ptr1 = a->data + (a->cols * i) + j; ptr2 = b->data + (a->cols * i) + j; ptr3 = p->data + (a->cols * i) + j; *ptr3 = subNumber(*ptr1, *ptr2); } return p; } /* subtract a Cmplx from a Matrix */ Matrix * subCmplxMatrix(Cmplx *a, Matrix *b){ invalidTyprError("-"); return NULL; } /* subtract a Real from a Matrix */ Matrix * subRealMatrix(Real *a, Matrix *b){ invalidTyprError("-"); return NULL; } /* subtract a Cmplx from a Matrix */ Matrix * subMatrixCmplx(Matrix *a, Cmplx *b){ int i, j; Number *n1; Number **ptr1, **ptr2; Matrix *p = newMatrix(); if(a == NULL) { fprintf(stderr, "subMatrixCmplx(NULL)\n"); exit(0); } /* initalize the stuff in p */ p->data = mallocData(NULL, a->rows, a->cols); p->rows = a->rows; p->cols = a->cols; /* p[i][j] = b + a[i][j] */ for(i=0; irows; i++) for(j=0; jcols; j++){ ptr1 = a->data + (a->cols * i) + j; ptr2 = p->data + (a->cols * i) + j; *ptr2 = subNumber(*ptr1, (n1=setNumberCmplx(newNumber(), b))); freeNumber(n1); } return p; } /* subtract a Cmplx from a Matrix */ Matrix * subMatrixReal(Matrix *a, Real *b){ int i, j; Number *n1; Number **ptr1, **ptr2; Matrix *p = newMatrix(); if(a == NULL) { fprintf(stderr, "subMatrixReal(NULL)\n"); exit(0); } /* initalize the stuff in p */ p->data = mallocData(NULL, a->rows, a->cols); p->rows = a->rows; p->cols = a->cols; /* p[i][j] = b + a[i][j] */ for(i=0; irows; i++) for(j=0; jcols; j++){ ptr1 = a->data + (a->cols * i) + j; ptr2 = p->data + (a->cols * i) + j; *ptr2 = subNumber(*ptr1, (n1=setNumberReal(newNumber(), b))); freeNumber(n1); } return p; } ./grpn-1.1.2/matrix.h0100644000175000017500000000362207452746203013024 0ustar wartwart/* Copyright (C) 2002 Paul Wilkins 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* matrix.h by Paul Wilkins */ /* Here we set up the matrix numbers */ #ifndef __MATRIX_H #define __MATRIX_H #include "typedefs.h" /* index like: ptr = (data + (row_indx * cols) + col_indx) */ struct _Matrix { int rows, cols; Number **data; }; Matrix * newMatrix(); void freeMatrix(Matrix *); char * printMatrix(Matrix *); char * printMatrixShort(Matrix *); void setMatrix(Matrix *, Number *, int, int); Matrix * setMatrixMatrix(Matrix *, Matrix *); Matrix * negMatrix(Matrix *); Matrix * invMatrix(Matrix *); Matrix * mulMatrix(Matrix *, Matrix *); Matrix * mulMatrixCmplx(Matrix *, Cmplx *); Matrix * mulMatrixReal(Matrix *, Real *); Matrix * divMatrix(Matrix *, Matrix *); Matrix * divMatrixCmplx(Matrix *, Cmplx *); Matrix * divMatrixReal(Matrix *, Real *); Matrix * divCmplxMatrix(Cmplx *, Matrix *); Matrix * divRealMatrix(Real *, Matrix *); Matrix * addMatrix(Matrix *, Matrix *); Matrix * addMatrixCmplx(Matrix *, Cmplx *); Matrix * addMatrixReal(Matrix *, Real *); Matrix * subMatrix(Matrix *, Matrix *); Matrix * subMatrixCmplx(Matrix *, Cmplx *); Matrix * subMatrixReal(Matrix *, Real *); Matrix * subCmplxMatrix(Cmplx *, Matrix *); Matrix * subRealMatrix(Real *, Matrix *); #endif ./grpn-1.1.2/menu.h0100644000175000017500000000166007452746203012464 0ustar wartwart/* Copyright (C) 2002 Paul Wilkins 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* menu.h by Paul Wilkins 3/15/97 */ #ifndef __MENU_H #define __MENU_H GtkWidget *setup_menu(GtkWidget *); extern gint delete_event(GtkWidget *, GdkEvent *, gpointer); extern void destroy(GtkWidget *, gpointer); #endif ./grpn-1.1.2/mode.c0100644000175000017500000000546407452746203012445 0ustar wartwart/* Copyright (C) 2002 Paul Wilkins 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* setup mode.c by Paul Wilkins 2/8/98 */ #include #include #include "mode.h" #include "number.h" #include "complex.h" GtkWidget *ModeDisplay = NULL; int radixMode = RADIANS; int polarMode = RECTANGULAR; int baseMode = DECIMAL; int getRadixMode(){ return radixMode; } void setRadixMode(int mode){ if(mode == RADIANS) radixMode = RADIANS; else if(mode == DEGREES) radixMode = DEGREES; else printf("setRadixMode invalid mode\n"); } void setPolarMode(int val){ polarMode = val; } int getPolarMode(){ return polarMode; } void setBaseMode(int val){ baseMode = val; } int getBaseMode(){ return baseMode; } char *getModeDisplayString(){ int rad_mode, pol_mode, base_mode; static char buf[256]; rad_mode = getRadixMode(); switch(rad_mode){ case DEGREES: strcpy(buf, " Degrees "); break; case RADIANS: strcpy(buf, " Radians "); break; default: fprintf(stderr, "invalid Radix mode\n"); break; } pol_mode = getPolarMode(); switch(pol_mode){ case RECTANGULAR: strcat(buf, "Rectangular "); break; case POLAR: strcat(buf, "Polar "); break; default: fprintf(stderr, "invalid Polar mode\n"); break; } base_mode = getBaseMode(); switch(base_mode){ case BINARY: strcat(buf, "Binary"); break; case OCTAL: strcat(buf, "Octal"); break; case DECIMAL: strcat(buf, "Decimal"); break; case HEXIDECIMAL: strcat(buf, "Hexidecimal"); break; default: fprintf(stderr, "invalid Base mode\n"); break; } return buf; } void refreshModeDisplay(){ char *str; str = getModeDisplayString(); gtk_label_set(GTK_LABEL(ModeDisplay), str); } GtkWidget *setupModeDisplay(GtkWidget *parent){ ModeDisplay = gtk_label_new(" "); gtk_box_pack_start(GTK_BOX(parent), ModeDisplay, FALSE, FALSE, 0); gtk_widget_show(ModeDisplay); /* set the string */ refreshModeDisplay(); return ModeDisplay; } ./grpn-1.1.2/mode.h0100644000175000017500000000242407452746203012443 0ustar wartwart/* Copyright (C) 2002 Paul Wilkins 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* mode.h by Paul Wilkins 2/8/98 */ #ifndef __MODE_H #define __MODE_H #include #define BINARY 0x1 #define OCTAL 0x2 #define DECIMAL 0x4 #define HEXIDECIMAL 0x8 #define DEGREES 0x10 #define RADIANS 0x20 #define RECTANGULAR 0x40 #define POLAR 0x80 #define LONG_DISPLAY 0x100 #define SHORT_DISPLAY 0x200 void setPolarMode(int); int getPolarMode(); void setRadixMode(int); int getRadixMode(); void setBaseMode(int); int getBaseMode(); /* the mode display window */ void refreshModeDisplay(); GtkWidget *setupModeDisplay(GtkWidget *); #endif ./grpn-1.1.2/nroot.xbm0100644000175000017500000000131106723014111013173 0ustar wartwart#define nroot_width 25 #define nroot_height 25 static unsigned char nroot_bits[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0x00, 0x00, 0x00, 0x88, 0x00, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, 0x20, 0xf8, 0x7f, 0x00, 0x50, 0x08, 0x00, 0x00, 0x50, 0x08, 0x00, 0x00, 0x88, 0x44, 0x10, 0x00, 0x88, 0x44, 0x10, 0x00, 0x00, 0x84, 0x08, 0x00, 0x40, 0x02, 0x05, 0x00, 0x40, 0x02, 0x02, 0x00, 0x80, 0x02, 0x02, 0x00, 0x80, 0x01, 0x02, 0x00, 0x00, 0x01, 0x02, 0x00, 0x00, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; ./grpn-1.1.2/number.c0100644000175000017500000006064407452746203013012 0ustar wartwart/* Copyright (C) 2002 Paul Wilkins 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* number.c by Paul Wilkins 3/15/97 */ #include #include #include "number.h" #include "matrix.h" #include "complex.h" #include "real.h" #include "mode.h" #include "constant.h" #include "error.h" Number * newNumber(){ Number *p; if(NULL == (p = (Number *)malloc(sizeof(Number)))){ perror("Malloc"); exit(0); } p->refCnt = 0; return p; } void freeNumber(Number *a){ if(a == NULL) return; if(a->refCnt != 0){ return; } switch(a->type){ case REAL: freeReal(a->data); break; case COMPLEX: freeCmplx(a->data); break; case MATRIX: freeMatrix(a->data); break; default: fprintf(stderr, "Error: Unknown number type\n"); exit(0); } free(a); } void clrRefcntNumber(Number *a){ if(a == NULL){ fprintf(stderr, "clrRefcntNumber(NULL)\n"); exit(0); } a->refCnt = 0; } void incRefcntNumber(Number *a){ if(a == NULL){ fprintf(stderr, "incRefcntNumber(NULL)\n"); exit(0); } a->refCnt++; } void decRefcntNumber(Number *a){ if(a == NULL){ fprintf(stderr, "decRefcntNumber(NULL)\n"); exit(0); } a->refCnt--; } char * printNumber(Number *a){ if(a == NULL){ fprintf(stderr, "printNumber(NULL)\n"); exit(0); } switch(a->type){ case REAL: return printReal(a->data); break; case COMPLEX: return printCmplx(a->data); break; case MATRIX: return printMatrix(a->data); break; default: fprintf(stderr, "Error: printNumber(): Unknown number type: 0x%x\n", a->type); exit(0); } } char * printNumberShort(Number *a){ if(a == NULL){ fprintf(stderr, "printNumber(NULL)\n"); exit(0); } switch(a->type){ case REAL: return printReal(a->data); break; case COMPLEX: return printCmplxShort(a->data); break; case MATRIX: return printMatrixShort(a->data); break; default: fprintf(stderr, "Error: printNumber(): Unknown number type\n"); exit(0); } } Number * setNumberReal(Number *a, Real *b){ a->type = REAL; a->data = setRealReal(newReal(), b); return a; } Number * setNumberCmplx(Number *a, Cmplx *b){ a->type = COMPLEX; a->data = setCmplxCmplx(newCmplx(), b); return a; } Number * setNumberMatrix(Number *a, Matrix *b){ a->type = MATRIX; a->data = setMatrixMatrix(newMatrix(), b); return a; } Number * setNumberNumber(Number *a, Number *b){ a->type = b->type; switch(b->type){ case REAL: a->data = setRealReal(newReal(), b->data); break; case COMPLEX: a->data = setCmplxCmplx(newCmplx(), b->data); break; case MATRIX: a->data = setMatrixMatrix(newMatrix(), b->data); break; default: fprintf(stderr, "Error: Unknown number type\n"); exit(0); } return a; } Number * negNumber(Number *a){ Number *c = newNumber(); if(a == NULL){ fprintf(stderr, "negNumber(NULL)\n"); exit(0); } switch(a->type){ case REAL: c->type = REAL; c->data = negReal(a->data); break; case COMPLEX: c->type = COMPLEX; c->data = negCmplx(a->data); break; case MATRIX: c->type = MATRIX; c->data = negMatrix(a->data); break; default: fprintf(stderr, "Error: Unknown number type\n"); exit(0); } if(c->data == NULL){ free(c); c = NULL; } return c; } Number * invNumber(Number *a){ Number *c = newNumber(); if(a == NULL){ fprintf(stderr, "invNumber(NULL)\n"); exit(0); } switch(a->type){ case REAL: c->type = REAL; c->data = invReal(a->data); break; case COMPLEX: c->type = COMPLEX; c->data = invCmplx(a->data); break; case MATRIX: c->type = MATRIX; c->data = invMatrix(a->data); break; default: fprintf(stderr, "Error: Unknown number type\n"); exit(0); } if(c->data == NULL){ free(c); c = NULL; } return c; } Number * lnNumber(Number *a){ Real *r1; Cmplx *c1; Number *c = newNumber(); if(a == NULL){ fprintf(stderr, "lnNumber(NULL)\n"); exit(0); } switch(a->type){ case REAL: if(-1 == cmpReal(a->data, realZero)){ /* ln(<0) is complex ! */ c1 = setCmplxReal(newCmplx(), a->data, realZero); c->type = COMPLEX; c->data = lnCmplx(c1); freeCmplx(c1); } else { c->type = REAL; c->data = lnReal(a->data); } break; case COMPLEX: c->type = COMPLEX; c->data = lnCmplx(a->data); break; case MATRIX: c->type = MATRIX; invalidTyprError("ln"); c->data = NULL; break; default: fprintf(stderr, "Error: Unknown number type\n"); exit(0); } if(c->data == NULL){ free(c); c = NULL; } return c; } Number * logNumber(Number *a){ Real *r1; Cmplx *c1; Number *c = newNumber(); if(a == NULL){ fprintf(stderr, "logNumber(NULL)\n"); exit(0); } switch(a->type){ case REAL: if(-1 == cmpReal(a->data, realZero)){ /* log(<0) is complex ! */ c1 = setCmplxReal(newCmplx(), a->data, realZero); c->type = COMPLEX; c->data = logCmplx(c1); freeCmplx(c1); } else { c->type = REAL; c->data = logReal(a->data); } break; case COMPLEX: c->type = COMPLEX; c->data = logCmplx(a->data); break; case MATRIX: c->type = MATRIX; invalidTyprError("log"); c->data = NULL; break; default: fprintf(stderr, "Error: Unknown number type\n"); exit(0); } if(c->data == NULL){ free(c); c = NULL; } return c; } Number * expNumber(Number *a){ Number *c = newNumber(); if(a == NULL){ fprintf(stderr, "expNumber(NULL)\n"); exit(0); } switch(a->type){ case REAL: c->type = REAL; c->data = expReal(a->data); break; case COMPLEX: c->type = COMPLEX; c->data = expCmplx(a->data); break; case MATRIX: c->type = MATRIX; invalidTyprError("exp"); c->data = NULL; break; default: fprintf(stderr, "Error: Unknown number type\n"); exit(0); } if(c->data == NULL){ free(c); c = NULL; } return c; } /* note that complex numbers take care of degree/radian conversions, * but we have to deal with that for real numbers here. */ Number * sinNumber(Number *a){ Real *r1; Number *c = newNumber(); if(a == NULL){ fprintf(stderr, "sin Number(NULL)\n"); exit(0); } switch(a->type){ case REAL: c->type = REAL; r1 = fromRadixReal(a->data); c->data = sinReal(r1); freeReal(r1); break; case COMPLEX: c->type = COMPLEX; c->data = sinCmplx(a->data); break; case MATRIX: c->type = MATRIX; invalidTyprError("sin"); c->data = NULL; break; default: fprintf(stderr, "Error: Unknown number type\n"); exit(0); } if(c->data == NULL){ free(c); c = NULL; } return c; } Number * cosNumber(Number *a){ Real *r1; Number *c = newNumber(); if(a == NULL){ fprintf(stderr, "cos Number(NULL)\n"); exit(0); } switch(a->type){ case REAL: c->type = REAL; r1 = fromRadixReal(a->data); c->data = cosReal(r1); freeReal(r1); break; case COMPLEX: c->type = COMPLEX; c->data = cosCmplx(a->data); break; case MATRIX: c->type = MATRIX; invalidTyprError("cos"); c->data = NULL; break; default: fprintf(stderr, "Error: Unknown number type\n"); exit(0); } if(c->data == NULL){ free(c); c = NULL; } return c; } Number * tanNumber(Number *a){ Real *r1; Number *c = newNumber(); if(a == NULL){ fprintf(stderr, "tan Number(NULL)\n"); exit(0); } switch(a->type){ case REAL: c->type = REAL; r1 = fromRadixReal(a->data); c->data = tanReal(r1); freeReal(r1); break; case COMPLEX: c->type = COMPLEX; c->data = tanCmplx(a->data); break; case MATRIX: c->type = MATRIX; invalidTyprError("tan"); c->data = NULL; break; default: fprintf(stderr, "Error: Unknown number type\n"); exit(0); } if(c->data == NULL){ free(c); c = NULL; } return c; } Number * asinNumber(Number *a){ Real *r1; Cmplx *c1; Number *c = newNumber(); if(a == NULL){ fprintf(stderr, "asin Number(NULL)\n"); exit(0); } switch(a->type){ case REAL: if(1 == cmpReal(a->data, realOne) || -1 == cmpReal(a->data, realMOne)){ /* asin(>1 or <-1) is complex ! */ c1 = setCmplxReal(newCmplx(), a->data, realZero); c->type = COMPLEX; c->data = asinCmplx(c1); freeCmplx(c1); } else { c->type = REAL; r1 = asinReal(a->data); c->data = toRadixReal(r1); freeReal(r1); } break; case COMPLEX: c->type = COMPLEX; c->data = asinCmplx(a->data); break; case MATRIX: c->type = MATRIX; invalidTyprError("asin"); c->data = NULL; break; default: fprintf(stderr, "Error: Unknown number type\n"); exit(0); } if(c->data == NULL){ free(c); c = NULL; } return c; } Number * acosNumber(Number *a){ Real *r1; Cmplx *c1; Number *c = newNumber(); if(a == NULL){ fprintf(stderr, "acos Number(NULL)\n"); exit(0); } switch(a->type){ case REAL: if(1 == cmpReal(a->data, realOne) || -1 == cmpReal(a->data, realMOne)){ /* acos(>1 or <-1) is complex ! */ c1 = setCmplxReal(newCmplx(), a->data, realZero); c->type = COMPLEX; c->data = acosCmplx(c1); freeCmplx(c1); } else { c->type = REAL; r1 = acosReal(a->data); c->data = toRadixReal(r1); freeReal(r1); } break; case COMPLEX: c->type = COMPLEX; c->data = acosCmplx(a->data); break; case MATRIX: c->type = MATRIX; invalidTyprError("acos"); c->data = NULL; break; default: fprintf(stderr, "Error: Unknown number type\n"); exit(0); } if(c->data == NULL){ free(c); c = NULL; } return c; } Number * atanNumber(Number *a){ Real *r1; Number *c = newNumber(); if(a == NULL){ fprintf(stderr, "atan Number(NULL)\n"); exit(0); } switch(a->type){ case REAL: c->type = REAL; r1 = atanReal(a->data); c->data = toRadixReal(r1); freeReal(r1); break; case COMPLEX: c->type = COMPLEX; c->data = atanCmplx(a->data); break; case MATRIX: c->type = MATRIX; invalidTyprError("atan"); c->data = NULL; break; default: fprintf(stderr, "Error: Unknown number type\n"); exit(0); } if(c->data == NULL){ free(c); c = NULL; } return c; } Number * powNumber(Number *a, Number *b){ Cmplx *c1; Number *c = newNumber(); if(a == NULL || b == NULL) { fprintf(stderr, "powNumber(NULL)\n"); exit(0); } switch(a->type){ case REAL: switch(b->type){ case REAL: if(-1 == cmpReal(a->data, realZero) && 0 == isIntReal(b->data)){ /* do complex math */ c->type = COMPLEX; c1 = setCmplxReal(newCmplx(), a->data, realZero); c->data = powCmplxReal(c1, b->data); freeCmplx(c1); } else { c->type = REAL; c->data = powReal(a->data, b->data); } break; case COMPLEX: c->type = COMPLEX; if(-1 == cmpReal(a->data, realZero)){ c1 = setCmplxReal(newCmplx(), a->data, realZero); c->data = powCmplx(c1, b->data); freeCmplx(c1); } else { c->data = powRealCmplx(a->data, b->data); } break; case MATRIX: invalidTyprError("pow"); c->data = NULL; break; default: fprintf(stderr, "Error: Unknown number type\n"); exit(0); break; } break; case COMPLEX: switch(b->type){ case REAL: c->type = COMPLEX; c->data = powCmplxReal(a->data, b->data); break; case COMPLEX: c->type = COMPLEX; c->data = powCmplx(a->data, b->data); break; case MATRIX: invalidTyprError("pow"); c->data = NULL; break; default: fprintf(stderr, "Error: Unknown number type\n"); exit(0); break; } break; case MATRIX: invalidTyprError("pow"); c->data = NULL; break; default: fprintf(stderr, "Error: Unknown number type\n"); exit(0); } if(c->data == NULL){ free(c); c = NULL; } return c; } Number * ripNumber(Number *a, Number *b){ Number *c; Number *num; Number *den; if(a == NULL || b == NULL) { fprintf(stderr, "ripNumber(NULL)\n"); exit(0); } switch(a->type){ case REAL: case COMPLEX: switch(b->type){ case REAL: case COMPLEX: num = mulNumber(a,b); den = addNumber(a,b); c = divNumber(num,den); freeNumber(num); freeNumber(den); break; case MATRIX: invalidTyprError("rip"); return NULL; break; default: fprintf(stderr, "Error: Unknown number type\n"); exit(0); break; } break; case MATRIX: invalidTyprError("rip"); return NULL; break; default: fprintf(stderr, "Error: Unknown number type\n"); exit(0); break; } return c; } Number * dbNumber(Number *a, double sf){ Real *r1; Number *c; Number *n1, *n2; if(a == NULL) { fprintf(stderr, "dbNumber(NULL)\n"); exit(0); } switch(a->type){ case REAL: case COMPLEX: n1 = logNumber(a); n2 = setNumberReal(newNumber(), setRealDouble((r1=newReal()), sf)); c = mulNumber(n1, n2); freeNumber(n1); freeNumber(n2); freeReal(r1); break; case MATRIX: invalidTyprError("db"); return NULL; break; default: fprintf(stderr, "Error: Unknown number type\n"); exit(0); break; } return c; } Number * mulNumber(Number *a, Number *b){ Number *c = newNumber(); if(a == NULL || b == NULL) { fprintf(stderr, "mulNumber(NULL)\n"); exit(0); } switch(a->type){ case REAL: switch(b->type){ case REAL: c->type = REAL; c->data = mulReal(a->data, b->data); break; case COMPLEX: c->type = COMPLEX; c->data = mulCmplxReal(b->data, a->data); break; case MATRIX: c->type = MATRIX; c->data = mulMatrixReal(b->data, a->data); break; default: fprintf(stderr, "Error: Unknown number type\n"); exit(0); break; } break; case COMPLEX: switch(b->type){ case COMPLEX: c->type = COMPLEX; c->data = mulCmplx(a->data, b->data); break; case REAL: c->type = COMPLEX; c->data = mulCmplxReal(a->data, b->data); break; case MATRIX: c->type = MATRIX; c->data = mulMatrixCmplx(b->data, a->data); break; default: fprintf(stderr, "Error: Unknown number type\n"); exit(0); break; } break; case MATRIX: switch(b->type){ case MATRIX: c->type = MATRIX; c->data = mulMatrix(a->data, b->data); c->type = MATRIX; break; case COMPLEX: c->type = MATRIX; c->data = mulMatrixCmplx(a->data, b->data); break; case REAL: c->type = MATRIX; c->data = mulMatrixReal(a->data, b->data); break; default: fprintf(stderr, "Error: Unknown number type\n"); exit(0); break; } break; default: fprintf(stderr, "Error: Unknown number type\n"); exit(0); } if(c->data == NULL){ free(c); c = NULL; } return c; } Number * divNumber(Number *a, Number *b){ Number *c = newNumber(); if(a == NULL || b == NULL) { fprintf(stderr, "mulNumber(NULL)\n"); exit(0); } switch(a->type){ case REAL: switch(b->type){ case REAL: c->type = REAL; c->data = divReal(a->data, b->data); break; case COMPLEX: c->type = COMPLEX; c->data = divRealCmplx(a->data, b->data); break; case MATRIX: c->type = MATRIX; c->data = divRealMatrix(a->data, b->data); break; default: fprintf(stderr, "Error: Unknown number type\n"); exit(0); break; } break; case COMPLEX: switch(b->type){ case COMPLEX: c->type = COMPLEX; c->data = divCmplx(a->data, b->data); break; case REAL: c->type = COMPLEX; c->data = divCmplxReal(a->data, b->data); break; case MATRIX: c->type = MATRIX; c->data = divCmplxMatrix(a->data, b->data); break; default: fprintf(stderr, "Error: Unknown number type\n"); exit(0); break; } break; case MATRIX: switch(b->type){ case MATRIX: c->type = MATRIX; c->data = divMatrix(a->data, b->data); break; case COMPLEX: c->type = MATRIX; c->data = divMatrixCmplx(a->data, b->data); break; case REAL: c->type = MATRIX; c->data = divMatrixReal(a->data, b->data); break; default: fprintf(stderr, "Error: Unknown number type\n"); exit(0); break; } break; default: fprintf(stderr, "Error: Unknown number type\n"); exit(0); } if(c->data == NULL){ free(c); c = NULL; } return c; } Number * addNumber(Number *a, Number *b){ Number *c = newNumber(); if(a == NULL || b == NULL) { fprintf(stderr, "addNumber(NULL)\n"); exit(0); } switch(a->type){ case REAL: switch(b->type){ case REAL: c->type = REAL; c->data = addReal(a->data, b->data); break; case COMPLEX: c->type = COMPLEX; c->data = addCmplxReal(b->data, a->data); break; case MATRIX: c->type = MATRIX; c->data = addMatrixReal(b->data, a->data); break; default: fprintf(stderr, "Error: Unknown number type\n"); exit(0); break; } break; case COMPLEX: switch(b->type){ case COMPLEX: c->type = COMPLEX; c->data = addCmplx(a->data, b->data); break; case REAL: c->type = COMPLEX; c->data = addCmplxReal(a->data, b->data); break; case MATRIX: c->type = MATRIX; c->data = addMatrixCmplx(b->data, a->data); break; default: fprintf(stderr, "Error: Unknown number type\n"); exit(0); break; } break; case MATRIX: switch(b->type){ case MATRIX: c->type = MATRIX; c->data = addMatrix(a->data, b->data); break; case COMPLEX: c->type = MATRIX; c->data = addMatrixCmplx(a->data, b->data); break; case REAL: c->type = MATRIX; c->data = addMatrixReal(a->data, b->data); break; default: fprintf(stderr, "Error: Unknown number type\n"); exit(0); break; } break; default: fprintf(stderr, "Error: Unknown number type\n"); exit(0); } if(c->data == NULL){ free(c); c = NULL; } return c; } Number * subNumber(Number *a, Number *b){ Number *c = newNumber(); if(a == NULL || b == NULL) { fprintf(stderr, "subNumber(NULL)\n"); exit(0); } switch(a->type){ case REAL: switch(b->type){ case REAL: c->type = REAL; c->data = subReal(a->data, b->data); break; case COMPLEX: c->type = COMPLEX; c->data = subRealCmplx(a->data, b->data); break; case MATRIX: c->type = MATRIX; c->data = subRealMatrix(a->data, b->data); break; default: fprintf(stderr, "Error: Unknown number type\n"); exit(0); break; } break; case COMPLEX: switch(b->type){ case COMPLEX: c->type = COMPLEX; c->data = subCmplx(a->data, b->data); break; case REAL: c->type = COMPLEX; c->data = subCmplxReal(a->data, b->data); break; case MATRIX: c->type = MATRIX; c->data = subCmplxMatrix(a->data, b->data); break; default: fprintf(stderr, "Error: Unknown number type\n"); exit(0); break; } break; case MATRIX: switch(b->type){ case MATRIX: c->type = MATRIX; c->data = subMatrix(a->data, b->data); break; case COMPLEX: c->type = MATRIX; c->data = subMatrixCmplx(a->data, b->data); break; case REAL: c->type = MATRIX; c->data = subMatrixReal(a->data, b->data); break; default: fprintf(stderr, "Error: Unknown number type\n"); exit(0); break; } break; default: fprintf(stderr, "Error: Unknown number type\n"); exit(0); } if(c->data == NULL){ free(c); c = NULL; } return c; } ./grpn-1.1.2/number.h0100644000175000017500000000422207452746203013005 0ustar wartwart/* Copyright (C) 2002 Paul Wilkins 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* number.h by Paul Wilkins 3/15/97 */ #ifndef __NUMBER_H #define __NUMBER_H #include "typedefs.h" /* types of numbers */ #define REAL 0x1 #define COMPLEX 0x2 #define MATRIX 0x4 /* a number */ struct _Number { int refCnt; /* refference count. used to implement undo */ int type; /* the type of number data pointe to */ void *data; /* the data (Real, complex, etc.) */ }; #include "real.h" #include "complex.h" #include "matrix.h" Number * newNumber(); void freeNumber(Number *); void clrRefcntNumber(Number *); void incRefcntNumber(Number *); void decRefcntNumber(Number *); Number * setNumberReal(Number *, Real *); Number * setNumberCmplx(Number *, Cmplx *); Number * setNumberMatrix(Number *, Matrix *); Number * setNumberNumber(Number *, Number *); char * printNumber(Number *); char * printNumberShort(Number *); Number * negNumber(Number *); Number * invNumber(Number *); Number * lnNumber(Number *); Number * logNumber(Number *); Number * expNumber(Number *); Number * powNumber(Number *, Number *); Number * dbNumber(Number *, double); Number * ripNumber(Number *, Number *); Number * sinNumber(Number *); Number * cosNumber(Number *); Number * tanNumber(Number *); Number * asinNumber(Number *); Number * acosNumber(Number *); Number * atanNumber(Number *); Number * mulNumber(Number *, Number *); Number * divNumber(Number *, Number *); Number * addNumber(Number *, Number *); Number * subNumber(Number *, Number *); #endif ./grpn-1.1.2/options.c0100644000175000017500000002123507452746203013206 0ustar wartwart/* Copyright (C) 2002 Paul Wilkins 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* options.c by Paul Wilkins 1/17/99 */ #include #include #include "options.h" #include "mode.h" #include "lcd.h" extern void baseToggleCB(GtkWidget *, gpointer); extern void radixToggleCB(gpointer); extern void cmodeToggleCB(gpointer); extern void dmodeToggleCB(gpointer); GtkWidget *optBinBtn; GtkWidget *optOctBtn; GtkWidget *optDecBtn; GtkWidget *optHexBtn; GtkWidget *optWindow = NULL; /* pops up a new window with all the options in it */ void optionsCB(gpointer data){ GSList *group; GtkWidget *button; GtkWidget *frame; GtkWidget *hbox, *vbox; if (!optWindow) { optWindow = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title (GTK_WINDOW (optWindow), "Options"); gtk_signal_connect(GTK_OBJECT(optWindow), "destroy", GTK_SIGNAL_FUNC(gtk_widget_destroyed), &optWindow); #ifdef GTK_VER_1_1 gtk_container_set_border_width(GTK_CONTAINER(optWindow), 5); #else gtk_container_border_width(GTK_CONTAINER(optWindow), 5); #endif /* all the sections go in the vbox */ vbox = gtk_vbox_new(FALSE, 0); gtk_container_add(GTK_CONTAINER(optWindow), vbox); gtk_widget_show(vbox); /************************************************************/ frame = gtk_frame_new("Base"); gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 0); #ifdef GTK_VER_1_1 gtk_container_set_border_width(GTK_CONTAINER(frame), 5); #else gtk_container_border_width(GTK_CONTAINER(frame), 5); #endif gtk_widget_show(frame); hbox = gtk_hbox_new(TRUE, 0); gtk_container_add(GTK_CONTAINER(frame), hbox); gtk_widget_show(hbox); button = gtk_radio_button_new_with_label(NULL, "Bin"); gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 0); gtk_signal_connect(GTK_OBJECT(button), "toggled", GTK_SIGNAL_FUNC(baseToggleCB), (gpointer)BINARY); gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button), getBaseMode() == BINARY ? TRUE : FALSE); gtk_widget_show(button); optBinBtn = button; group = gtk_radio_button_group(GTK_RADIO_BUTTON(button)); button = gtk_radio_button_new_with_label(group, "Oct"); gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 0); gtk_signal_connect(GTK_OBJECT(button), "toggled", GTK_SIGNAL_FUNC(baseToggleCB), (gpointer)OCTAL); gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button), getBaseMode() == OCTAL ? TRUE : FALSE); gtk_widget_show(button); optOctBtn = button; group = gtk_radio_button_group(GTK_RADIO_BUTTON(button)); button = gtk_radio_button_new_with_label(group, "Dec"); gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 0); gtk_signal_connect(GTK_OBJECT(button), "toggled", GTK_SIGNAL_FUNC(baseToggleCB), (gpointer)DECIMAL); gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button), getBaseMode() == DECIMAL ? TRUE : FALSE); gtk_widget_show(button); optDecBtn = button; group = gtk_radio_button_group(GTK_RADIO_BUTTON(button)); button = gtk_radio_button_new_with_label(group, "Hex"); gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 0); gtk_signal_connect(GTK_OBJECT(button), "toggled", GTK_SIGNAL_FUNC(baseToggleCB), (gpointer)HEXIDECIMAL); gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button), getBaseMode() == HEXIDECIMAL ? TRUE : FALSE); gtk_widget_show(button); optHexBtn = button; /************************************************************/ frame = gtk_frame_new("Radix"); gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 0); #ifdef GTK_VER_1_1 gtk_container_set_border_width(GTK_CONTAINER(frame), 5); #else gtk_container_border_width(GTK_CONTAINER(frame), 5); #endif gtk_widget_show(frame); hbox = gtk_hbox_new(TRUE, 0); gtk_container_add(GTK_CONTAINER(frame), hbox); gtk_widget_show(hbox); button = gtk_radio_button_new_with_label(NULL, "Degrees"); gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 0); gtk_signal_connect(GTK_OBJECT(button), "toggled", GTK_SIGNAL_FUNC(radixToggleCB), (gpointer)DEGREES); gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button), getRadixMode() == DEGREES ? TRUE : FALSE); gtk_widget_show(button); group = gtk_radio_button_group(GTK_RADIO_BUTTON(button)); button = gtk_radio_button_new_with_label(group, "Radians"); gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 0); gtk_signal_connect(GTK_OBJECT(button), "toggled", GTK_SIGNAL_FUNC(radixToggleCB), (gpointer)RADIANS); gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button), getRadixMode() == RADIANS ? TRUE : FALSE); gtk_widget_show(button); /************************************************************/ frame = gtk_frame_new("Coordinate Mode"); gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 0); #ifdef GTK_VER_1_1 gtk_container_set_border_width(GTK_CONTAINER(frame), 5); #else gtk_container_border_width(GTK_CONTAINER(frame), 5); #endif gtk_widget_show(frame); hbox = gtk_hbox_new(TRUE, 0); gtk_container_add(GTK_CONTAINER(frame), hbox); gtk_widget_show(hbox); button = gtk_radio_button_new_with_label(NULL, "Rectangular"); gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 0); gtk_signal_connect(GTK_OBJECT(button), "toggled", GTK_SIGNAL_FUNC(cmodeToggleCB), (gpointer)RECTANGULAR); gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button), getPolarMode() == RECTANGULAR ? TRUE : FALSE); gtk_widget_show(button); group = gtk_radio_button_group(GTK_RADIO_BUTTON(button)); button = gtk_radio_button_new_with_label(group, "Polar"); gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 0); gtk_signal_connect(GTK_OBJECT(button), "toggled", GTK_SIGNAL_FUNC(cmodeToggleCB), (gpointer)POLAR); gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button), getPolarMode() == POLAR ? TRUE : FALSE); gtk_widget_show(button); /************************************************************/ frame = gtk_frame_new("Display Mode"); gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 0); #ifdef GTK_VER_1_1 gtk_container_set_border_width(GTK_CONTAINER(frame), 5); #else gtk_container_border_width(GTK_CONTAINER(frame), 5); #endif gtk_widget_show(frame); hbox = gtk_hbox_new(TRUE, 0); gtk_container_add(GTK_CONTAINER(frame), hbox); gtk_widget_show(hbox); button = gtk_radio_button_new_with_label(NULL, "Short"); gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 0); gtk_signal_connect(GTK_OBJECT(button), "toggled", GTK_SIGNAL_FUNC(dmodeToggleCB), (gpointer)SHORT_DISPLAY); gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button), getLCDDispMode() == SHORT_DISPLAY ? TRUE : FALSE); gtk_widget_show(button); group = gtk_radio_button_group(GTK_RADIO_BUTTON(button)); button = gtk_radio_button_new_with_label(group, "Long"); gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 0); gtk_signal_connect(GTK_OBJECT(button), "toggled", GTK_SIGNAL_FUNC(dmodeToggleCB), (gpointer)LONG_DISPLAY); gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button), getLCDDispMode() == LONG_DISPLAY ? TRUE : FALSE); gtk_widget_show(button); /************************************************************/ button = gtk_button_new_with_label("Dismiss"); gtk_signal_connect_object(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy), GTK_OBJECT(optWindow)); gtk_box_pack_start(GTK_BOX(vbox), button, TRUE, TRUE, 0); GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT); gtk_widget_show(button); } if (!GTK_WIDGET_VISIBLE(optWindow)) { gtk_widget_show(optWindow); } else { gtk_widget_destroy(optWindow); } } ./grpn-1.1.2/options.h0100644000175000017500000000211007452746203013202 0ustar wartwart/* Copyright (C) 2002 Paul Wilkins 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* options.h by Paul Wilkins 1/17/99 */ #ifndef __OPTIONS_H #define __OPTIONS_H /* toggle buttons in the dialog */ extern GtkWidget *optBinBtn; extern GtkWidget *optOctBtn; extern GtkWidget *optDecBtn; extern GtkWidget *optHexBtn; /* the dialog */ extern GtkWidget *optWindow; /* pops up a new window with all the options in it */ void optionsCB(gpointer data); #endif ./grpn-1.1.2/pi.xbm0100644000175000017500000000130006723014111012440 0ustar wartwart#define pi_width 25 #define pi_height 25 static unsigned char pi_bits[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x07, 0x00, 0xc0, 0x84, 0x00, 0x00, 0x00, 0x84, 0x00, 0x00, 0x00, 0x84, 0x00, 0x00, 0x00, 0x42, 0x00, 0x00, 0x00, 0x42, 0x00, 0x00, 0x00, 0x42, 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; ./grpn-1.1.2/process_input.c0100644000175000017500000001024607452746203014410 0ustar wartwart/* Copyright (C) 2002 Paul Wilkins 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* process_input.c by Paul Wilkins 3/21/97 */ #include #include #include #include "process_input.h" #include "funcs.h" #include "lcd.h" #include "editor.h" #include "error.h" void processInput(int ksym, int isCtrl, char bb, char chr){ int keysym; char c; if(ksym == 0){ switch(chr){ case ' ': case '\n': case '\t': keysym = GDK_space; break; case '+': keysym = GDK_plus; break; case '-': keysym = GDK_minus; break; case '/': keysym = GDK_slash; break; case '*': keysym = GDK_asterisk; break; case '^': keysym = GDK_asciicircum; break; default: keysym = GDK_4; /* just pick one */ break; } } else { keysym = ksym; } if(isCtrl){ switch(keysym){ case GDK_c: /* quit */ exit(0); break; } /* ignore the ctrl key */ return; } /* this will clear any error string */ resetError(); /* process the line */ switch(keysym){ case GDK_space: /* if there is something in the buffer, then */ case GDK_KP_Space: /* push it onto the stack, else duplicate the */ case GDK_Return: /* element on the bottom of the stack */ case GDK_Tab: case GDK_KP_Tab: case GDK_KP_Enter: case GDK_KP_Insert: case GDK_Linefeed: PushStack(); break; case GDK_Begin: /* used when editing the entry buffer */ case GDK_Home: case GDK_Up: case GDK_KP_Home: case GDK_KP_Up: homeEditor(); break; case GDK_End: /* used when editing the entry buffer */ case GDK_Down: case GDK_KP_End: case GDK_KP_Down: endEditor(); break; case GDK_Right: /* used when editing the entry buffer */ case GDK_KP_Right: rightEditor(); break; case GDK_Left: /* used when editing the entry buffer */ case GDK_KP_Left: leftEditor(); break; case GDK_BackSpace: /* delete the last entry in the stack */ case GDK_Delete: /* OR backspace over the last char typed */ case GDK_KP_Delete: if(isEditingEditor()){ deleteEditor(); } else { PopStack(); } break; case GDK_Escape: /* clear the entry buffer */ cancelEditor(); break; case GDK_plus: case GDK_KP_Add: c = getPrevEditor(); if(c == 'e' || c == 'E'){ insertEditor(bb); } else { AddStack(); } break; case GDK_minus: case GDK_KP_Subtract: c = getPrevEditor(); if(c == 'e' || c == 'E'){ insertEditor(bb); } else { SubStack(); } break; case GDK_asterisk: case GDK_KP_Multiply: MulStack(); break; case GDK_slash: case GDK_KP_Divide: DivStack(); break; case GDK_asciicircum: PowStack(); break; default: /* catch everything that's left over */ /* ascii characters */ if((keysym >= GDK_KP_Space && keysym <= GDK_KP_9) || (keysym >= GDK_space && keysym <= GDK_asciitilde)){ insertEditor(bb); } break; } /* repaint the screen */ redrawLCD(); } ./grpn-1.1.2/process_input.h0100644000175000017500000000160707452746203014416 0ustar wartwart/* Copyright (C) 2002 Paul Wilkins 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* process_input.h by Paul Wilkins 3/21/97 */ #ifndef __PROCESS_INPUT_H #define __PROCESS_INPUT_H /* process keyboard input */ void processInput(int, int, char, char); #endif ./grpn-1.1.2/real.c0100644000175000017500000004131207452746203012434 0ustar wartwart/* Copyright (C) 2002 Paul Wilkins 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* real.c by Paul Wilkins */ #include #include #include #include #include "real.h" #include "mode.h" #include "constant.h" void checkFinite(Real *a){ if(isnan(a->num)){ a->ok = REAL_NAN; a->num = 0.0; } else if(!finite(a->num)){ a->ok = REAL_INF; a->num = 0.0; } } /* convert a real number from the internal radix representation (radians) the the representation of the current mode (radians or degrees) */ Real * toRadixReal(Real *a){ Real *r1; /* deal with degrees if we need to */ if(getRadixMode() == DEGREES){ r1 = mulReal(a, real180Pi); } else { r1 = setRealReal(newReal(), a); } checkFinite(r1); return r1; } Real * fromRadixReal(Real *a){ Real *r1; /* deal with degrees if we need to */ if(getRadixMode() == DEGREES){ r1 = divReal(a, real180Pi); } else { r1 = setRealReal(newReal(), a); } checkFinite(r1); return r1; } /* create a new real number */ Real * newReal(){ Real *p; if(NULL == (p = (Real *)malloc(sizeof(Real)))){ perror("Malloc"); exit(0); } p->ok = REAL_OK; p->num = 0.0; return p; } void freeReal(Real *a){ free((char *)a); } double setDoubleReal(Real *a){ if(a){ switch(a->ok){ case REAL_OK: return a->num; break; case REAL_NAN: fprintf(stderr, "setDoubleReal trying to return NAN\n"); return 0.0; break; case REAL_INF: fprintf(stderr, "setDoubleReal trying to return INF\n"); return 0.0; break; default: fprintf(stderr, "Error: setDoubleReal: invalid type\n"); exit(0); } } return 0.0; } Real * setRealDouble(Real *a, double d){ a->ok = REAL_OK; a->num = d; checkFinite(a); return a; } Real * setRealReal(Real *a, Real *b){ if(a && b){ a->ok = b->ok; if(b->ok == REAL_OK){ a->num = b->num; checkFinite(a); } else { a->num = 0.0; } } return a; } #define REAL_PRINT_SIZE 2048 char * printReal(Real *a){ char *c, *p; int i; int baseMode; double dd, nn, fm; char buf[REAL_PRINT_SIZE]; if(NULL == (c=(char *)malloc(REAL_PRINT_SIZE))){ perror("Malloc"); exit(0); } switch(a->ok){ case REAL_OK: baseMode = getBaseMode(); switch(baseMode){ case BINARY: dd = a->num; i = 1; p = buf+REAL_PRINT_SIZE-1; *p-- = '\0'; do { nn = pow(2.0, (double)i); if(fmod(dd, nn) >= nn*0.5) *p-- = '1'; else *p-- = '0'; i++; } while (dd / nn >= 0.5); *p = '\0'; if(i <= 2){ strcpy(c, "0"); } else { strncpy(c, p+2, i-1); } break; case OCTAL: dd = a->num; i = 1; p = buf+REAL_PRINT_SIZE-1; *p-- = '\0'; do { nn = pow(8.0, (double)i); fm = fmod(dd, nn); if(fm >= nn*0.875) *p-- = '7'; else if(fm >= nn*0.75) *p-- = '6'; else if(fm >= nn*0.625) *p-- = '5'; else if(fm >= nn*0.5) *p-- = '4'; else if(fm >= nn*0.375) *p-- = '3'; else if(fm >= nn*0.25) *p-- = '2'; else if(fm >= nn*0.125) *p-- = '1'; else *p-- = '0'; i++; } while (dd / nn >= 0.125); if(i <= 2){ strcpy(c, "00"); } else { strncpy(c, p+1, i-0); } break; case DECIMAL: sprintf(c, "%.15g", a->num); break; case HEXIDECIMAL: dd = a->num; i = 1; p = buf+REAL_PRINT_SIZE-1; *p-- = '\0'; do { nn = pow(16.0, (double)i); fm = fmod(dd, nn); if(fm >= nn*0.9375) *p-- = 'f'; else if(fm >= nn*0.875) *p-- = 'e'; else if(fm >= nn*0.8125) *p-- = 'd'; else if(fm >= nn*0.75) *p-- = 'c'; else if(fm >= nn*0.6875) *p-- = 'b'; else if(fm >= nn*0.625) *p-- = 'a'; else if(fm >= nn*0.5625) *p-- = '9'; else if(fm >= nn*0.5) *p-- = '8'; else if(fm >= nn*0.4375) *p-- = '7'; else if(fm >= nn*0.375) *p-- = '6'; else if(fm >= nn*0.3125) *p-- = '5'; else if(fm >= nn*0.25) *p-- = '4'; else if(fm >= nn*0.1875) *p-- = '3'; else if(fm >= nn*0.125) *p-- = '2'; else if(fm >= nn*0.0625) *p-- = '1'; else *p-- = '0'; i++; } while (dd / nn >= 0.0625); if(i <= 2){ strcpy(c, "0x0"); } else { strcpy(c, "0x"); strncat(c, p+2, i-1); } break; } break; case REAL_NAN: sprintf(c, "NaN"); break; case REAL_INF: sprintf(c, "Infinity"); break; default: fprintf(stderr, "Error: printReal: invalid type\n"); exit(0); } return c; } /* compare 2 Real numbers */ int cmpReal(Real *a, Real *b){ if(a->ok == REAL_OK && b->ok == REAL_OK){ if(a->num == b->num) return 0; if(a->num > b->num) return 1; else return -1; } else if(a->ok == REAL_INF && b->ok == REAL_INF) return 0; else return 1; } /* is the Real numbers an int ? */ int isIntReal(Real *a){ if(a->ok == REAL_OK){ if(1.0 == (double)( ((int)(a->num)) /a->num) ) return 1; } return 0; } /* absolute value of a Real number */ Real * absReal(Real *a){ Real *p = newReal(); p->ok = a->ok; p->num = fabs(a->num); checkFinite(p); return p; } /* negate a Real number */ Real * negReal(Real *a){ Real *p = newReal(); p->ok = a->ok; p->num = -(a->num); checkFinite(p); return p; } /* negate a Real number */ Real * negEqReal(Real *a){ a->num = -a->num; checkFinite(a); return a; } /* invert a Real number */ Real * invReal(Real *a){ Real *p = newReal(); p->ok = a->ok; if(a->num == 0.0){ p->ok = REAL_NAN; p->num = 0.0; } else { p->num = 1.0 / a->num; checkFinite(p); } return p; } /* invert a Real number */ Real * invEqReal(Real *a){ if(a->num == 0.0){ a->ok = REAL_NAN; a->num = 0.0; } else { a->num = 1.0 / a->num; checkFinite(a); } return a; } /* Real number to the power */ Real * powReal(Real *a, Real *b){ Real *p = newReal(); if(a->ok == REAL_OK && b->ok == REAL_OK){ p->ok = REAL_OK; p->num = pow(a->num, b->num); checkFinite(p); } else if(a->ok == REAL_NAN || b->ok == REAL_NAN){ p->ok = REAL_NAN; p->num = 0.0; } else { p->ok = REAL_INF; p->num = 0.0; } return p; } /* Real number to the power */ Real * powEqReal(Real *a, Real *b){ if(a->ok == REAL_OK && b->ok == REAL_OK){ a->num = pow(a->num, b->num); checkFinite(a); } else if(a->ok == REAL_NAN || b->ok == REAL_NAN){ a->num = 0.0; } return a; } /* Real number to the power */ Real * powRealInt(Real *a, int b){ Real *p = newReal(); p->ok = a->ok; p->num = pow(a->num, (double)b); checkFinite(p); return p; } /* natural log of as Real number */ Real * lnReal(Real *a){ Real *p = newReal(); switch(a->ok){ case REAL_OK: if(a->num > 0.0){ p->ok = a->ok; p->num = log(a->num); checkFinite(p); } else if(a->num == 0.0){ p->ok = REAL_INF; p->num = 0.0; } else { printf("lnReal(<0)\n"); exit(0); } break; case REAL_INF: p->ok = REAL_INF; p->num = 0.0; break; case REAL_NAN: p->ok = REAL_NAN; p->num = 0.0; break; default: fprintf(stderr, "lnReal unknown real type\n"); exit(0); break; } return p; } /* natural log of as Real number */ Real * lnEqReal(Real *a){ switch(a->ok){ case REAL_OK: if(a->num > 0.0){ a->num = log(a->num); checkFinite(a); } else if(a->num == 0.0){ a->ok = REAL_INF; a->num = 0.0; } else { printf("lnEqReal(<0)\n"); exit(0); } break; case REAL_INF: a->num = 0.0; break; case REAL_NAN: a->num = 0.0; break; default: fprintf(stderr, "lnReal unknown real type\n"); exit(0); break; } return a; } /* log base ten of a Real number */ Real * logReal(Real *a){ Real *p = newReal(); switch(a->ok){ case REAL_OK: if(a->num > 0.0){ p->ok = a->ok; p->num = log10(a->num); checkFinite(p); } else if(a->num == 0.0){ p->ok = REAL_INF; p->num = 0.0; } else { printf("logReal(<0)\n"); exit(0); } break; case REAL_INF: p->ok = REAL_INF; p->num = 0.0; break; case REAL_NAN: p->ok = REAL_NAN; p->num = 0.0; break; default: fprintf(stderr, "logReal unknown real type\n"); exit(0); break; } return p; } /* log base ten of a Real number */ Real * logEqReal(Real *a){ switch(a->ok){ case REAL_OK: if(a->num > 0.0){ a->num = log10(a->num); checkFinite(a); } else if(a->num == 0.0){ a->ok = REAL_INF; a->num = 0.0; } else { printf("logEqReal(<0)\n"); exit(0); } break; case REAL_INF: a->num = 0.0; break; case REAL_NAN: a->num = 0.0; break; default: fprintf(stderr, "logEqReal unknown real type\n"); exit(0); break; } return a; } /* e to a Real number */ Real * expReal(Real *a){ Real *p = newReal(); p->ok = a->ok; p->num = exp(a->num); checkFinite(p); return p; } /* e to a Real number */ Real * expEqReal(Real *a){ a->num = exp(a->num); checkFinite(a); return a; } /* trig func */ Real * asinReal(Real *a){ Real *p = newReal(); p->ok = a->ok; p->num = asin(a->num); checkFinite(p); return p; } /* trig func */ Real * asinEqReal(Real *a){ a->num = asin(a->num); checkFinite(a); return a; } /* trig func */ Real * acosReal(Real *a){ Real *p = newReal(); p->ok = a->ok; p->num = acos(a->num); checkFinite(p); return p; } /* trig func */ Real * acosEqReal(Real *a){ a->num = acos(a->num); checkFinite(a); return a; } /* trig func */ Real * atanReal(Real *a){ Real *p = newReal(); p->ok = a->ok; p->num = atan(a->num); checkFinite(p); return p; } /* trig func */ Real * atan2Real(Real *a, Real *b){ Real *p = newReal(); if(a->ok == REAL_OK && b->ok == REAL_OK){ p->ok = REAL_OK; p->num = atan2(a->num, b->num); checkFinite(p); } else if(a->ok == REAL_NAN || b->ok == REAL_NAN){ p->ok = REAL_NAN; p->num = 0.0; } else { p->ok = REAL_INF; p->num = 0.0; } return p; } /* trig func */ Real * atanEqReal(Real *a){ a->num = atan(a->num); checkFinite(a); return a; } /* trig func */ Real * sinReal(Real *a){ Real *p = newReal(); p->ok = a->ok; p->num = sin(a->num); checkFinite(p); return p; } /* trig func */ Real * sinEqReal(Real *a){ a->num = sin(a->num); checkFinite(a); return a; } /* trig func */ Real * cosReal(Real *a){ Real *p = newReal(); p->ok = a->ok; p->num = cos(a->num); checkFinite(p); return p; } /* trig func */ Real * cosEqReal(Real *a){ a->num = cos(a->num); checkFinite(a); return a; } /* trig func */ Real * tanReal(Real *a){ Real *p = newReal(); p->ok = a->ok; p->num = tan(a->num); checkFinite(p); return p; } /* trig func */ Real * tanEqReal(Real *a){ a->num = tan(a->num); checkFinite(a); return a; } /* multiply 2 Real numbers */ Real * mulReal(Real *a, Real *b){ Real *p = newReal(); if(a->ok == REAL_OK && b->ok == REAL_OK){ p->ok = REAL_OK; p->num = a->num * b->num; checkFinite(p); } else if(a->ok == REAL_NAN || b->ok == REAL_NAN) p->ok = REAL_NAN; else p->ok = REAL_INF; return p; } /* multiply 2 Real numbers */ Real * mulEqReal(Real *a, Real *b){ if(a->ok == REAL_OK && b->ok == REAL_OK){ a->num *= b->num; checkFinite(a); } else if(a->ok == REAL_NAN || b->ok == REAL_NAN) a->ok = REAL_NAN; else a->ok = REAL_INF; return a; } /* divide 2 Real numbers */ Real * divReal(Real *a, Real *b){ Real *p = newReal(); switch(a->ok){ case REAL_OK: switch(b->ok){ case REAL_OK: if(b->num == 0.0){ p->ok = REAL_NAN; p->num = 0.0; } else { p->ok = REAL_OK; p->num = a->num / b->num; checkFinite(p); } break; case REAL_INF: p->ok = REAL_NAN; p->num = 0.0; break; case REAL_NAN: p->ok = REAL_NAN; p->num = 0.0; break; default: fprintf(stderr, "divReal unknown real type\n"); exit(0); break; } break; case REAL_INF: p->ok = REAL_INF; p->num = 0.0; break; case REAL_NAN: p->ok = REAL_NAN; p->num = 0.0; break; default: fprintf(stderr, "divReal unknown real type\n"); exit(0); break; } return p; } /* divide 2 Real numbers */ Real * divEqReal(Real *a, Real *b){ switch(a->ok){ case REAL_OK: switch(b->ok){ case REAL_OK: if(b->num == 0.0){ a->ok = REAL_NAN; a->num = 0.0; } else { a->num /= b->num; checkFinite(a); } break; case REAL_INF: a->ok = REAL_NAN; a->num = 0.0; break; case REAL_NAN: a->ok = REAL_NAN; a->num = 0.0; break; default: fprintf(stderr, "divReal unknown real type\n"); exit(0); break; } break; } return a; } /* add 2 Real numbers */ Real * addReal(Real *a, Real *b){ Real *p = newReal(); if(a->ok == REAL_OK && b->ok == REAL_OK){ p->ok = REAL_OK; p->num = a->num + b->num; checkFinite(p); } else if(a->ok == REAL_NAN || b->ok == REAL_NAN) p->ok = REAL_NAN; else p->ok = REAL_INF; return p; } /* add 2 Real numbers */ Real * addEqReal(Real *a, Real *b){ if(a->ok == REAL_OK && b->ok == REAL_OK){ a->num += b->num; checkFinite(a); } else if(a->ok == REAL_NAN || b->ok == REAL_NAN) a->ok = REAL_NAN; else a->ok = REAL_INF; return a; } /* subtract 2 Real numbers */ Real * subReal(Real *a, Real *b){ Real *p = newReal(); if(a->ok == REAL_OK && b->ok == REAL_OK){ p->ok = REAL_OK; p->num = a->num - b->num; checkFinite(p); } else if(a->ok == REAL_NAN || b->ok == REAL_NAN) p->ok = REAL_NAN; else p->ok = REAL_INF; return p; } /* subtract 2 Real numbers */ Real * subEqReal(Real *a, Real *b){ if(a->ok == REAL_OK && b->ok == REAL_OK){ a->num -= b->num; checkFinite(a); } else if(a->ok == REAL_NAN || b->ok == REAL_NAN) a->ok = REAL_NAN; else a->ok = REAL_INF; return a; } ./grpn-1.1.2/real.h0100644000175000017500000000432307452746203012442 0ustar wartwart/* Copyright (C) 2002 Paul Wilkins 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* real.h by Paul Wilkins */ /* Here we set up the real numbers */ #ifndef __REAL_H #define __REAL_H #include "typedefs.h" #define REAL_INF 0x1 #define REAL_NAN 0x2 #define REAL_OK 0x4 struct _Real { char ok; double num; }; Real * newReal(); void freeReal(Real *); char * printReal(Real *); Real * setRealDouble(Real *, double); double setDoubleReal(Real *); Real * setRealReal(Real *, Real *); Real * fromRadixReal(Real *a); Real * toRadixReal(Real *a); int cmpReal(Real *, Real *); int isIntReal(Real *); Real * absReal(Real *); Real * negReal(Real *); Real * negEqReal(Real *); Real * invReal(Real *); Real * invEqReal(Real *); Real * powRealInt(Real *a, int); Real * powReal(Real *a, Real *b); Real * powEqReal(Real *a, Real *b); Real * lnReal(Real *a); Real * lnEqReal(Real *a); Real * logReal(Real *a); Real * logEqReal(Real *a); Real * expReal(Real *a); Real * expEqReal(Real *a); Real * sinReal(Real *a); Real * sinEqReal(Real *a); Real * cosReal(Real *a); Real * cosEqReal(Real *a); Real * tanReal(Real *a); Real * tanEqReal(Real *a); Real * asinReal(Real *a); Real * asinEqReal(Real *a); Real * acosReal(Real *a); Real * acosEqReal(Real *a); Real * atanReal(Real *a); Real * atan2Real(Real *a, Real *b); Real * atanEqReal(Real *a); Real * mulReal(Real *, Real *); Real * mulEqReal(Real *, Real *); Real * divReal(Real *, Real *); Real * divEqReal(Real *, Real *); Real * addReal(Real *, Real *); Real * addEqReal(Real *, Real *); Real * subReal(Real *, Real *); Real * subEqReal(Real *, Real *); #endif ./grpn-1.1.2/run_cmd.c0100644000175000017500000000440707452746203013144 0ustar wartwart/* Copyright (C) 2002 Paul Wilkins 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* run_cmd.c by Paul Wilkins */ #include #include #include "buttons.h" #include "funcs.h" #include "editor.h" #include "error.h" /* line is the name of the command to run, as stored in * the RowInfo struct */ void runCmd(char *line){ int i, j; int cmdLen; int lineLen; FuncInfo *fi; void (*CallBack)(GtkWidget *, gpointer); int found = 0; /* how many matching commands have we found */ if(*line == '"' || *line == '\'') line++; lineLen = strlen(line); /* try to find a matching command */ for(i=0; iCB; CallBack((GtkWidget *)NULL, (gpointer)fi); } else if(found > 1){ sprintf(getStringError(), "%s: Ambigious command name.", line); } else { sprintf(getStringError(), "%s: Unrecognized command.", line); } } ./grpn-1.1.2/run_cmd.h0100644000175000017500000000150107452746203013141 0ustar wartwart/* Copyright (C) 2002 Paul Wilkins 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* run_cmd.h by Paul Wilkins 3/30/97 */ #ifndef __RUN_CMD_H #define __RUN_CMD_H void runCmd(char *); #endif ./grpn-1.1.2/setup_buttons.c0100644000175000017500000000601307452746203014426 0ustar wartwart/* Copyright (C) 2002 Paul Wilkins 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* setup_buttons.c by Paul Wilkins */ #include #include #include "buttons.h" #include "funcs.h" #include "editor.h" /* create the button widgets */ GtkWidget *createButton( GtkWidget *parent, int leftPos, int rightPos, int topPos, int bottomPos, FuncInfo *fi) { GtkWidget *btn, *label; void (*callBack)(GtkWidget *, gpointer); /* btn = gtk_button_new_with_label(fi->name); */ btn = gtk_button_new(); label = gtk_label_new(fi->name); gtk_misc_set_alignment(GTK_MISC(label), 0.5, 0.5); gtk_misc_set_padding(GTK_MISC(label), 0, 0); gtk_container_add(GTK_CONTAINER(btn), label); gtk_widget_show(label); /* the space around the button gtk_container_border_width(GTK_CONTAINER(btn), 10); */ /* when the button is clicked, we call the "callback" function */ callBack = fi->CB; gtk_signal_connect(GTK_OBJECT (btn), "clicked", GTK_SIGNAL_FUNC(callBack), (gpointer)fi); gtk_table_attach_defaults(GTK_TABLE(parent), btn, leftPos, rightPos, topPos, bottomPos); gtk_widget_show(btn); GTK_WIDGET_UNSET_FLAGS(btn, GTK_CAN_FOCUS); return btn; } /* setup the buttons */ GtkWidget *setupButtons(GtkWidget *parent){ int i, j; int good; int numRows, numCols; int tWidth; GtkWidget *table; /* get the number of rows and columns */ numRows = NumButtonRows; numCols = 0; for(i=0; i numCols) numCols = rowinf[i].numBtns; } /* find the width of the table we need to fit out different sized buttons */ for(tWidth=numCols; tWidth<100; tWidth++){ good = 1; for(j=0; j #include #ifdef USE_GNOME #include #endif #include #include "menu.h" #include "mode.h" #include "options.h" extern void quitCB(gpointer); extern void clearCB(gpointer); extern void optionsCB(gpointer); extern void licenseCB(gpointer); extern void helpCB(gpointer); #ifdef OPTIONS_MENU extern void baseCB(gpointer); extern void radixCB(gpointer); extern void cmodeCB(gpointer); extern void dmodeCB(gpointer); #endif #ifdef USE_GNOME GnomeUIInfo filemenu[] = { {GNOME_APP_UI_ITEM, "Clear", "Clear and reset GRPN", clearCB, NULL, NULL, GNOME_APP_PIXMAP_NONE, NULL, 0, 0, NULL}, {GNOME_APP_UI_ITEM, "Options", "Options", optionsCB, NULL, NULL, GNOME_APP_PIXMAP_NONE, NULL, 0, 0, NULL}, GNOMEUIINFO_MENU_EXIT_ITEM(quitCB, NULL), GNOMEUIINFO_END }; GnomeUIInfo helpmenu[] = { {GNOME_APP_UI_ITEM, "License", "License", licenseCB, NULL, NULL, GNOME_APP_PIXMAP_NONE, NULL, 0, 0, NULL}, GNOMEUIINFO_HELP("grpn"), GNOMEUIINFO_END }; GnomeUIInfo mainmenu[] = { GNOMEUIINFO_MENU_FILE_TREE(filemenu), GNOMEUIINFO_MENU_HELP_TREE(helpmenu), GNOMEUIINFO_END }; /* create the menubar */ GtkWidget *setup_menu(GtkWidget *parent) { gnome_app_create_menus(GNOME_APP(parent), mainmenu); return NULL; } #else /* not USE_GNOME */ /* create the menubar */ GtkWidget *setup_menu(GtkWidget *parent) { GtkWidget *menu_bar; GtkWidget *fileM, *fileI; GtkWidget *clearI; GtkWidget *optionsI; GtkWidget *quitI; #ifdef OPTIONS_MENU GtkWidget *optM, *optI; GtkWidget *baseM, *baseI; GtkWidget *binI; GtkWidget *octI; GtkWidget *decI; GtkWidget *hexI; GtkWidget *radixM, *radixI; GtkWidget *degI; GtkWidget *radI; GtkWidget *coordM, *coordI; GtkWidget *rectI; GtkWidget *polI; GtkWidget *dispM, *dispI; GtkWidget *shrtI; GtkWidget *longI; #endif GtkWidget *helpM, *helpI; GtkWidget *hlpI; GtkWidget *licenseI; /********************************************************/ /* File */ fileM = gtk_menu_new(); /* Remember: don't gtk_widget_show the menu */ /* Clear */ clearI = gtk_menu_item_new_with_label("Clear"); gtk_menu_append(GTK_MENU(fileM), clearI); gtk_widget_show(clearI); gtk_signal_connect_object(GTK_OBJECT(clearI), "activate", GTK_SIGNAL_FUNC(clearCB), NULL); /* Options */ optionsI = gtk_menu_item_new_with_label("Options"); gtk_menu_append(GTK_MENU(fileM), optionsI); gtk_widget_show(optionsI); gtk_signal_connect_object(GTK_OBJECT(optionsI), "activate", GTK_SIGNAL_FUNC(optionsCB), NULL); /* Quit */ quitI = gtk_menu_item_new_with_label("Quit"); gtk_menu_append(GTK_MENU(fileM), quitI); gtk_widget_show(quitI); gtk_signal_connect_object(GTK_OBJECT(quitI), "activate", GTK_SIGNAL_FUNC(quitCB), NULL); /********************************************************/ #ifdef OPTIONS_MENU /* create the "Options" pulldown menu */ optM = gtk_menu_new(); /* Base */ baseM = gtk_menu_new(); /* Binary */ binI = gtk_menu_item_new_with_label("Binary"); gtk_menu_append(GTK_MENU(baseM), binI); gtk_widget_show(binI); gtk_signal_connect_object(GTK_OBJECT(binI), "activate", GTK_SIGNAL_FUNC(baseCB), (gpointer)BINARY); /* Octal */ octI = gtk_menu_item_new_with_label("Octal"); gtk_menu_append(GTK_MENU(baseM), octI); gtk_widget_show(octI); gtk_signal_connect_object(GTK_OBJECT(octI), "activate", GTK_SIGNAL_FUNC(baseCB), (gpointer)OCTAL); /* Decimal */ decI = gtk_menu_item_new_with_label("Decimal"); gtk_menu_append(GTK_MENU(baseM), decI); gtk_widget_show(decI); gtk_signal_connect_object(GTK_OBJECT(decI), "activate", GTK_SIGNAL_FUNC(baseCB), (gpointer)DECIMAL); /* Hex */ hexI = gtk_menu_item_new_with_label("Hex"); gtk_menu_append(GTK_MENU(baseM), hexI); gtk_widget_show(hexI); gtk_signal_connect_object(GTK_OBJECT(hexI), "activate", GTK_SIGNAL_FUNC(baseCB), (gpointer)HEXIDECIMAL); baseI = gtk_menu_item_new_with_label("Base"); gtk_menu_append(GTK_MENU(optM), baseI); gtk_widget_show(baseI); gtk_menu_item_set_submenu(GTK_MENU_ITEM(baseI), baseM); /* Radix */ radixM = gtk_menu_new(); /* Degrees */ degI = gtk_menu_item_new_with_label("Degrees"); gtk_menu_append(GTK_MENU(radixM), degI); gtk_widget_show(degI); gtk_signal_connect_object(GTK_OBJECT(degI), "activate", GTK_SIGNAL_FUNC(radixCB), (gpointer)DEGREES); /* Radians */ radI = gtk_menu_item_new_with_label("Radians"); gtk_menu_append(GTK_MENU(radixM), radI); gtk_widget_show(radI); gtk_signal_connect_object(GTK_OBJECT(radI), "activate", GTK_SIGNAL_FUNC(radixCB), (gpointer)RADIANS); radixI = gtk_menu_item_new_with_label("Radix"); gtk_menu_append(GTK_MENU(optM), radixI); gtk_widget_show(radixI); gtk_menu_item_set_submenu(GTK_MENU_ITEM(radixI), radixM); /* Coordinate Mode */ coordM = gtk_menu_new(); /* Rectangular */ rectI = gtk_menu_item_new_with_label("Rectangular"); gtk_menu_append(GTK_MENU(coordM), rectI); gtk_widget_show(rectI); gtk_signal_connect_object(GTK_OBJECT(rectI), "activate", GTK_SIGNAL_FUNC(cmodeCB), (gpointer)RECTANGULAR); /* Polar */ polI = gtk_menu_item_new_with_label("Polar"); gtk_menu_append(GTK_MENU(coordM), polI); gtk_widget_show(polI); gtk_signal_connect_object(GTK_OBJECT(polI), "activate", GTK_SIGNAL_FUNC(cmodeCB), (gpointer)POLAR); coordI = gtk_menu_item_new_with_label("Coordinate Mode"); gtk_menu_append(GTK_MENU(optM), coordI); gtk_widget_show(coordI); gtk_menu_item_set_submenu(GTK_MENU_ITEM(coordI), coordM); /* Display Mode */ dispM = gtk_menu_new(); /* Short */ shrtI = gtk_menu_item_new_with_label("Short"); gtk_menu_append(GTK_MENU(dispM), shrtI); gtk_widget_show(shrtI); gtk_signal_connect_object(GTK_OBJECT(shrtI), "activate", GTK_SIGNAL_FUNC(dmodeCB), (gpointer)SHORT_DISPLAY); /* Long */ longI = gtk_menu_item_new_with_label("Long"); gtk_menu_append(GTK_MENU(dispM), longI); gtk_widget_show(longI); gtk_signal_connect_object(GTK_OBJECT(longI), "activate", GTK_SIGNAL_FUNC(dmodeCB), (gpointer)LONG_DISPLAY); dispI = gtk_menu_item_new_with_label("Display Mode"); gtk_menu_append(GTK_MENU(optM), dispI); gtk_widget_show(dispI); gtk_menu_item_set_submenu(GTK_MENU_ITEM(dispI), dispM); #endif /********************************************************/ /* create the "Help" pulldown menu */ helpM = gtk_menu_new(); /* Help */ hlpI = gtk_menu_item_new_with_label("Help"); gtk_menu_append(GTK_MENU(helpM), hlpI); gtk_widget_show(hlpI); gtk_signal_connect_object(GTK_OBJECT(hlpI), "activate", GTK_SIGNAL_FUNC(helpCB), NULL); /* Help */ licenseI = gtk_menu_item_new_with_label("License"); gtk_menu_append(GTK_MENU(helpM), licenseI); gtk_widget_show(licenseI); gtk_signal_connect_object(GTK_OBJECT(licenseI), "activate", GTK_SIGNAL_FUNC(licenseCB), NULL); /********************************************************/ /* tell the menubar who is the heplp widget */ menu_bar = gtk_menu_bar_new(); gtk_box_pack_start(GTK_BOX(parent), menu_bar, FALSE, FALSE, 0); gtk_widget_show(menu_bar); fileI = gtk_menu_item_new_with_label("File"); gtk_menu_item_set_submenu(GTK_MENU_ITEM(fileI), fileM); gtk_menu_bar_append(GTK_MENU_BAR(menu_bar), fileI); gtk_widget_show(fileI); #ifdef OPTIONS_MENU optI = gtk_menu_item_new_with_label("Options"); gtk_menu_item_set_submenu(GTK_MENU_ITEM(optI), optM); gtk_menu_bar_append(GTK_MENU_BAR(menu_bar), optI); gtk_widget_show(optI); #endif helpI = gtk_menu_item_new_with_label("Help"); gtk_menu_item_right_justify(GTK_MENU_ITEM(helpI)); gtk_menu_item_set_submenu(GTK_MENU_ITEM(helpI), helpM); gtk_menu_bar_append(GTK_MENU_BAR(menu_bar), helpI); gtk_widget_show(helpI); return menu_bar; } #endif /* USE_GNOME */ ./grpn-1.1.2/sqrt.xbm0100644000175000017500000000130606723014111013027 0ustar wartwart#define sqrt_width 25 #define sqrt_height 25 static unsigned char sqrt_bits[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x1f, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x21, 0x02, 0x00, 0x00, 0x21, 0x02, 0x00, 0x00, 0x41, 0x01, 0x00, 0x90, 0x40, 0x01, 0x00, 0x90, 0x80, 0x00, 0x00, 0xa0, 0x40, 0x01, 0x00, 0x60, 0x40, 0x01, 0x00, 0x40, 0x20, 0x02, 0x00, 0x40, 0x20, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; ./grpn-1.1.2/stack.c0100644000175000017500000001206207452746203012616 0ustar wartwart/* Copyright (C) 2002 Paul Wilkins 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* stack.c by Paul Wilkins */ #include #include #include "stack.h" #include "number.h" #define STACK_CHUNK_SIZE 20 /* a stack element */ struct StackElem { struct StackElem *t; /* the node above us */ struct StackElem *b; /* the node below us */ Number *data; /* the data */ }; /* we build the stack in these arrays */ struct StackChunk { int freeIndx; struct StackElem *freeList[STACK_CHUNK_SIZE]; struct StackChunk *next; struct StackElem ary[STACK_CHUNK_SIZE]; }; /* The main stack of GRPN. This is where we store the numbers */ struct Stack stack; struct StackChunk *stackChunkHead = NULL; struct Stack *getStack(){ return &stack; } /* get the length of the stack */ int stackLen(){ return stack.length; } /* malloc a new stack chunk */ struct StackChunk * newStackChunk(){ int i; struct StackChunk *c; /* malloc a new chunk */ if(NULL == (c=(struct StackChunk *)malloc(sizeof(struct StackChunk)))){ perror("Malloc"); exit(0); } /* initalize stuff */ c->freeIndx = STACK_CHUNK_SIZE - 1; c->next = NULL; for(i=0; ifreeList[i] = &((c->ary)[i]); c->ary[i].data = NULL; } return c; } /* malloc a new stack element */ struct StackElem * newStackEle(){ struct StackElem *s; struct StackChunk *c; /* find the first stack chunk with free elements */ for(c=stackChunkHead; c->freeIndx==-1; c=c->next); /* get the StackEle */ s = c->freeList[c->freeIndx]; c->freeIndx--; /* if there are no more free elements */ if(c->freeIndx < 0){ c->freeIndx = -1; if(c->next == NULL) c->next = newStackChunk(); } return s; } void stackAddToFreeList(struct StackElem *s){ struct StackChunk *c; for(c=stackChunkHead; c!=NULL; c=c->next) if(s >= c->ary && s <= &((c->ary)[STACK_CHUNK_SIZE])) c->freeList[++(c->freeIndx)] = s; } int copyStack(struct Stack *srcStack, struct Stack *dstStack, int nelts){ int i; struct StackElem *dst, *src; for(i=0, src=srcStack->head; it){ /* set the stuff in the newly created stack element */ dst = newStackEle(); dst->data = src->data; dst->t = dstStack->head; dst->b = NULL; incRefcntNumber(dst->data); /* update the stuff in the ele above us */ if(dst->t) dst->t->b = dst; /* update the dest stack */ dstStack->head = dst; dstStack->length++; } if(i != nelts){ fprintf(stderr, "copyStack: Error copying stack.\n"); return 0; } return 1; } int setup_stack(){ stack.head = NULL; stack.length = 0; stackChunkHead = newStackChunk(); return 1; } void clearNamedStack(struct Stack *stk){ struct StackElem *s; for(s=stk->head; s; s=s->t){ decRefcntNumber(s->data); freeNumber(s->data); stackAddToFreeList(s); } stk->head = NULL; stk->length = 0; } void clearStack(){ clearNamedStack(&stack); } void printStack(){ char *c; struct StackElem *s = NULL; struct StackElem *p = NULL; /* find the top of the stack */ for(s=stack.head; s; s=s->t) p = s; /* print the numbers starting from the top */ for(s=p; p; p=p->b){ c = printNumber(p->data); printf("%s\n", c); free(c); } } Number * getStackEle(int which){ int i; struct StackElem *s = NULL; if(which < 0 || which >= stack.length) return NULL; s = stack.head; for(i=0; it; return s->data; } int Push(Number *data){ struct StackElem *s; /* set the stuff in the newly created stack element */ s = newStackEle(); s->data = data; s->t = stack.head; s->b = NULL; /* increment the ref count of the number */ incRefcntNumber(data); /* update the stuff in the ele above us */ if(s->t) s->t->b = s; /* update the head */ stack.head = s; stack.length++; return 1; /* success */ } Number * Pop(){ Number *ptr; struct StackElem *s; s = stack.head; /* nothing to pop */ if(s == NULL) return NULL; /* update the stuff in the ele above us */ if(s->t){ s->t->b = NULL; stack.head = s->t; } else stack.head = NULL; ptr = s->data; /* decrement the ref count of the number */ decRefcntNumber(ptr); stackAddToFreeList(s); stack.length--; return ptr; } ./grpn-1.1.2/stack.h0100644000175000017500000000226307452746203012625 0ustar wartwart/* Copyright (C) 2002 Paul Wilkins 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* stack.h by Paul Wilkins 3/15/97 */ #ifndef __STACK_H #define __STACK_H #include "typedefs.h" struct StackElem; struct Stack { int length; /* the head (bottom) of the stack */ struct StackElem *head; }; int setup_stack(); int stackLen(); void printStack(); void clearStack(); void clearNamedStack(struct Stack *); struct Stack *getStack(); int copyStack(struct Stack *, struct Stack *, int); Number * getStackEle(int); int Push(Number *); Number * Pop(); #endif ./grpn-1.1.2/test.c0100644000175000017500000000712307452746203012472 0ustar wartwart/* Copyright (C) 2002 Paul Wilkins 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* test.c by Paul Wilkins 3/15/97 */ #include #include #include "test.h" #include "number.h" #include "complex.h" #include "real.h" void test(){ char *c; int i, j; Number *a, *b; Real *ra, *rb; Cmplx *ca, *cb; Matrix *ma, *mb; Number *p1; printf("test()\n"); ra = setRealDouble(newReal(), 3.0); rb = setRealDouble(newReal(), 9.0); ca = setCmplxReal(newCmplx(), setRealDouble(newReal(), 3.0), setRealDouble(newReal(), 2.0)); cb = setCmplxReal(newCmplx(), setRealDouble(newReal(), 0.0), setRealDouble(newReal(), 0.0)); ma = newMatrix(); /* setMatrix(ma, setNumberCmplx(newNumber(), ca), 0, 0); setMatrix(ma, setNumberCmplx(newNumber(), cb), 0, 1); setMatrix(ma, setNumberCmplx(newNumber(), cb), 1, 0); setMatrix(ma, setNumberCmplx(newNumber(), ca), 1, 1); */ setMatrix(ma, setNumberReal(newNumber(), ra), 0, 0); setMatrix(ma, setNumberReal(newNumber(), rb), 0, 1); setMatrix(ma, setNumberReal(newNumber(), rb), 0, 2); setMatrix(ma, setNumberReal(newNumber(), rb), 1, 0); setMatrix(ma, setNumberCmplx(newNumber(), ca), 1, 1); setMatrix(ma, setNumberReal(newNumber(), ra), 1, 2); mb = newMatrix(); setMatrix(mb, setNumberReal(newNumber(), ra), 0, 0); setMatrix(mb, setNumberReal(newNumber(), ra), 0, 1); setMatrix(mb, setNumberReal(newNumber(), ra), 1, 0); setMatrix(mb, setNumberReal(newNumber(), ra), 1, 1); setMatrix(mb, setNumberReal(newNumber(), rb), 2, 0); setMatrix(mb, setNumberReal(newNumber(), rb), 2, 1); /* a = setNumberReal(newNumber(), ra); */ /* a = setNumberCmplx(newNumber(), ca); */ a = setNumberMatrix(newNumber(), ma); /* b = setNumberReal(newNumber(), ra); */ /* b = setNumberCmplx(newNumber(), cb); */ b = setNumberMatrix(newNumber(), mb); c = printNumber(a); printf("a = %s\n", c); free(c); c = printNumber(b); printf("b = %s\n", c); free(c); p1 = negNumber(a); c = printNumber(p1); printf("-a = %s\n", c); free(c); freeNumber(p1); p1 = mulNumber(a, b); if(p1){ c = printNumber(p1); printf("a * b = %s\n", c); free(c); freeNumber(p1); } p1 = addNumber(a, b); if(p1){ c = printNumber(p1); printf("a + b = %s\n", c); free(c); freeNumber(p1); } p1 = subNumber(a, b); if(p1){ c = printNumber(p1); printf("a - b = %s\n", c); free(c); freeNumber(p1); } p1 = subNumber(b, a); if(p1){ c = printNumber(p1); printf("b - a = %s\n", c); free(c); freeNumber(p1); } p1 = divNumber(a, b); if(p1){ c = printNumber(p1); printf("a / b = %s\n", c); free(c); freeNumber(p1); } p1 = divNumber(b, a); if(p1){ c = printNumber(p1); printf("b / a = %s\n", c); free(c); freeNumber(p1); } printf("done testing...\n"); } ./grpn-1.1.2/test.h0100644000175000017500000000146007452746203012475 0ustar wartwart/* Copyright (C) 2002 Paul Wilkins 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* test.h by Paul Wilkins 3/15/97 */ #ifndef __TEST_H #define __TEST_H void test(); #endif ./grpn-1.1.2/test_gtk_ver.c0100644000175000017500000000237007452746203014212 0ustar wartwart/* Copyright (C) 2000 Paul Wilkins 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 theGNU 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* test_gtk_ver.c by Paul Wilkins 1/30/99 */ #include /* * This will test to make sure you have the correct #define set * in the makefile for your version of GTK. * * if you get an error when compiling this file, then uncomment * the line #define GTK_VER_1_1 in the Makefile, and recompile. * * GTK version == 1.0 unset GTK_VER_1_1 * GTK version == 1.1 set GTK_VER_1_1 * GTK version == 1.2 set GTK_VER_1_1 */ #ifdef GTK_VER_1_1 typedef GtkTargetEntry WRONG_VERSION_OF_GTK_PLEASE_UNSET_GTK_VER_1_1_IN_MAKEFILE; #endif ./grpn-1.1.2/typedefs.h0100644000175000017500000000166507452746203013350 0ustar wartwart/* Copyright (C) 2002 Paul Wilkins 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* typedefs.h by Paul Wilkins 3/16/97 */ #ifndef __TYPEDEFS_H #define __TYPEDEFS_H #undef Cmplx typedef struct _Number Number; typedef struct _Matrix Matrix; typedef struct _Cmplx Cmplx; typedef struct _Real Real; #endif ./grpn-1.1.2/undo.c0100644000175000017500000000623607452746203012464 0ustar wartwart/* Copyright (C) 2000 Paul Wilkins 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* undo.c by Paul Wilkins */ #include #include "undo.h" #include "error.h" #include "stack.h" #include "number.h" /* must be at least 2 */ #define MAX_UNDO_LEVELS 10 int nSavedItems[MAX_UNDO_LEVELS]; int nUndoItems[MAX_UNDO_LEVELS]; struct Stack undoStacks[MAX_UNDO_LEVELS]; int ringIndx; int undoLevel; void initUndoSystem(){ int i; static int initialized = 0; if(initialized != 0){ for(i=0; i= MAX_UNDO_LEVELS){ clearNamedStack(&(undoStacks[ringIndx])); } /* save the new info */ nSavedItems[ringIndx] = args; copyStack(getStack(), &(undoStacks[ringIndx]), args); } void AddStackState(int args){ /* save the new info */ nSavedItems[ringIndx] += args; copyStack(getStack(), &(undoStacks[ringIndx]), args); } /* Called after anything that modifies the stack. * Records the number of stack elements that must be poped * from the stack to undo the last operation if UndoStack * is called. */ void UndoStackState(int args){ nUndoItems[ringIndx] = args; undoLevel++; if(undoLevel >= MAX_UNDO_LEVELS) undoLevel = MAX_UNDO_LEVELS; ringIndx++; if(ringIndx >= MAX_UNDO_LEVELS) ringIndx = 0; } ./grpn-1.1.2/undo.h0100644000175000017500000000027707452746203012470 0ustar wartwart#ifndef __UNDO_H #define __UNDO_H void initUndoSystem(); void UndoStack(); void CancelStackState(); void SaveStackState(int); void AddStackState(int); void UndoStackState(int); #endif ./grpn-1.1.2/grpn.10100644000175000017500000000354107453220246012372 0ustar wartwart.\" Hey, EMACS: -*- nroff -*- .\" First parameter, NAME, should be all caps .\" Second parameter, SECTION, should be 1-8, maybe w/ subsection .\" other parameters are allowed: see man(7), man(1) .TH GRPN 1 "April 2002" GRPN "GTK+ Reverse Polish Notation Calculator" .\" Please adjust this date whenever revising the manpage. .\" .\" Some roff macros, for reference: .\" .nh disable hyphenation .\" .hy enable hyphenation .\" .ad l left justify .\" .ad b justify to both left and right margins .\" .nf disable filling .\" .fi enable filling .\" .br insert line break .\" .sp insert n+1 empty lines .\" for manpage-specific macros, see man(7) .SH NAME grpn \- GTK+ reverse polish notation calculator .SH SYNOPSIS .B grpn .B " [-fn \fIfont\fR] [-btn-fn \fIfont\fR] [-disp-fn \fIfont\fR] " .B " [-rows \fIn\fR] [-cols \fIn\fR] [-b] " .br .SH DESCRIPTION .br GRPN is a RPN calculator for the X Window system built using the GIMP Toolkit (GTK+). GRPN works with real numbers, complex numbers, matrices, and complex matrices. Numbers can be displayed in 4 different radix modes, and complex numbers can be displayed in either Cartesian or polar form. .PP .\" TeX users may be more comfortable with the \fB\fP and .\" \fI\fP escape sequences to invode bold face and italics, .\" respectively. \fBgrpn\fP is a GTK+ reverse polish notation calculator. .SH OPTIONS .br .TP .B " -b" Don't draw the buttons. .TP .B " -rows \fIn\fR" Display (a minimum of) n rows. .TP .B " -cols \fIn\fR" Display (a minimum of) n columns. .TP .B " -btn-fn \fIfont\fR" Use font for the buttons and menu bar. .TP .B " -disp-fn \fIfont\fR" Use font for the main display. .TP .B " -fn \fIfont\fR" Specifies both -btn-fn and -disp-fn. .I .SH AUTHOR GRPN was written by Paul Wilkins .