Appendix D. The basecalc Application
This appendix lists the complete source code for the basecalc application described in Chapter 12. Source code for all examples in this book is available as described in the Preface.
The X Programmer’s Calculator (basecalc) was described in Chapter 14.
This appendix presents the complete code for basecalc, including the following files and routines that were not shown in Chapter 14.
basecalc.hInclude file for this application.
convButtonChanges the current base and converts a value, if any.
digitButtonGets a digit and assigns it to the variable
Value.displayValCalculates appropriate format string for base.
initTtyPerforms system calls to get user’s current erase, delete, and interrupt characters.
keyToWinTranslates a keycode as if a
padhad been selected.makePixmapMakes a pixmap from bitmap data, shown and described in Chapter 6.
operButtonAn operation, either does it or waits for next value and =.
printInBaseComposes the string that should be displayed. Called from
Sprintf.specButtonClears a digit, an entry, or all, or toggles unsigned mode.
SprintfA modified version of the standard C utility
sprintf, which does not print in binary.SprintfcallsprintInBase.winPressedDetermines whether
padpressed was a digit, an operator, a conversion, or a specialpad.
Example D-1 shows the basecalc.h include file. This include file sets up the structures and global variables used in the calculator application.
Example D-1. The complete basecalc.h file
/* Window flags ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access