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.h
Include file for this application.
convButton
Changes the current base and converts a value, if any.
digitButton
Gets a digit and assigns it to the variable
Value
.displayVal
Calculates appropriate format string for base.
initTty
Performs system calls to get user’s current erase, delete, and interrupt characters.
keyToWin
Translates a keycode as if a
pad
had been selected.makePixmap
Makes a pixmap from bitmap data, shown and described in Chapter 6.
operButton
An operation, either does it or waits for next value and =.
printInBase
Composes the string that should be displayed. Called from
Sprintf
.specButton
Clears a digit, an entry, or all, or toggles unsigned mode.
Sprintf
A modified version of the standard C utility
sprintf
, which does not print in binary.Sprintf
callsprintInBase
.winPressed
Determines whether
pad
pressed 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 ...
Get XLIB Programming Manual, Rel. 5, Third Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.