1 /*******************************************************************************
2 * Reverse Polish Notation calculator. *
3 * Copyright (c) 2007-2008, Samuel Fredrickson <kinghajj@gmail.com> *
4 * All rights reserved. *
6 * Redistribution and use in source and binary forms, with or without *
7 * modification, are permitted provided that the following conditions are met: *
8 * * Redistributions of source code must retain the above copyright *
9 * notice, this list of conditions and the following disclaimer. *
10 * * Redistributions in binary form must reproduce the above copyright *
11 * notice, this list of conditions and the following disclaimer in the *
12 * documentation and/or other materials provided with the distribution. *
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER ``AS IS'' AND ANY EXPRESS *
15 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED *
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
17 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY *
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR *
20 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER *
21 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT *
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY *
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *
25 ******************************************************************************/
27 /*******************************************************************************
28 * error.c - an error-handling function; it just prints the error and exits. *
29 * there's also some output code. *
30 ******************************************************************************/
38 //! Prints an error to the screen, then exits. This is much simpler than the
39 //! normal RPN_error function.
41 * @param msg The message to print.
43 void RPN_error(char *msg
)
45 kprintf("\nerror: %s\n\nauto-exiting in 10 seconds...", msg
);
51 #define RPNPSP_OUTBUF_SIZE 1024
52 char RPNPSP_output_buffer
[RPNPSP_OUTBUF_SIZE
];
54 static void clearOutputBuffer()
58 for(i
= 0; i
< RPNPSP_OUTBUF_SIZE
; i
++)
60 RPNPSP_output_buffer
[i
] = 0;
63 #endif // DOXYGEN_SKIP
65 //! Prints to the screen.
67 * The PSP, as far as I can tell, cannot use normal printf()-family functions.
68 * So, this uses vsprintf to print to a buffer first. This could potentially be
69 * dangerous, so the buffer is fairly large (1024 bytes) to prevent errors. As
70 * long as you don't print anything longer than 1024 characters long, everything
73 * @param fmt The formatting string.
75 int RPN_printf(char *fmt
, ...)
79 // Always make sure to clear the buffer!
83 vsprintf(RPNPSP_output_buffer
, fmt
, args
);
84 kprintf("%s", RPNPSP_output_buffer
);
90 int RPN_dprintff(char *func
, char *fmt
, ...)
94 // Always make sure to clear the buffer!
95 RPNPSP_clearOutputBuffer();
98 vsprintf(RPNPSP_output_buffer
, fmt
, args
);
99 kprintf("%s: %s\n", func
, RPNPSP_output_buffer
);
103 #endif // DOXYGEN_SKIP