Debian Codegraph @

common/core_helpers.h

raw
1 /*****************************************************************************
2 * Free42 -- an HP-42S calculator simulator
3 * Copyright (C) 2004-2026 Thomas Okken
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License, version 2,
7 * as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, see http://www.gnu.org/licenses/.
16 *****************************************************************************/
17
18 #ifndef CORE_HELPERS_H
19 #define CORE_HELPERS_H 1
20
21
22 #include "free42.h"
23 #include "core_phloat.h"
24 #include "core_globals.h"
25
26
27 /*********************/
28 /* Utility functions */
29 /*********************/
30
31 int resolve_ind_arg(arg_struct *arg, char *buf = NULL, int *len = NULL);
32 int arg_to_num(arg_struct *arg, int4 *num);
33 bool dim_to_int4(vartype *dim, int4 *res);
34 int recall_result_silently(vartype *v);
35 int recall_result(vartype *v);
36 int recall_two_results(vartype *x, vartype *y);
37 void unary_result(vartype *x);
38 int unary_two_results(vartype *x, vartype *y);
39 int unary_no_result();
40 int binary_result(vartype *x);
41 void binary_two_results(vartype *x, vartype *y);
42 int ternary_result(vartype *x);
43 bool ensure_stack_capacity(int n);
44 void shrink_stack();
45 phloat rad_to_angle(phloat x);
46 phloat rad_to_deg(phloat x);
47 phloat deg_to_rad(phloat x);
48 void append_alpha_char(char c);
49 void append_alpha_string(const char *buf, int buflen, int reverse);
50
51 void string_copy(char *dst, int *dstlen, const char *src, int srclen);
52 bool string_equals(const char *s1, int s1len, const char *s2, int s2len);
53 int string_pos(const char *ntext, int nlen, const vartype *hs, int startpos);
54 bool vartype_equals(const vartype *v1, const vartype *v2);
55 int anum(const char *text, int len, phloat *res);
56 void fix_thousands_separators(char *buf, int *bufptr);
57 void fix_base_separators(char *buf, int *bufptr);
58
59 #define undefined_char(c) ((c) >= 139)
60
61 #define FLAGOP_SF 0
62 #define FLAGOP_CF 1
63 #define FLAGOP_FS_T 2
64 #define FLAGOP_FC_T 3
65 #define FLAGOP_FSC_T 4
66 #define FLAGOP_FCC_T 5
67
68 int virtual_flag_handler(int flagop, int flagnum);
69
70 int get_base();
71 void set_base(int base, bool a_thru_f = false);
72 int get_base_param(const vartype *v, int8 *n);
73 int base_range_check(int8 *n, bool force_wrap);
74 int effective_wsize();
75 phloat base2phloat(int8 n);
76 bool phloat2base(phloat p, int8 *n);
77
78 void print_text(const char *text, int length, bool left_justified);
79 void print_lines(const char *text, int length, bool left_justified);
80 void print_right(const char *left, int leftlen,
81 const char *right, int rightlen);
82 void print_wide(const char *left, int leftlen,
83 const char *right, int rightlen);
84 void print_command(int cmd, const arg_struct *arg);
85 void print_menu_trace(const char *name, int len);
86 void print_menu_trace_always(const char *name, int len);
87 void print_trace();
88 void print_stack_trace();
89
90 void generic_r2p(phloat re, phloat im, phloat *r, phloat *phi);
91 void generic_p2r(phloat r, phloat phi, phloat *re, phloat *im);
92
93 phloat sin_deg(phloat x);
94 phloat sin_grad(phloat x);
95 phloat cos_deg(phloat x);
96 phloat cos_grad(phloat x);
97
98 /***********************/
99 /* Miscellaneous stuff */
100 /***********************/
101
102 int dimension_array(const char *name, int namelen, int4 rows, int4 columns, bool check_matedit);
103 int dimension_array_ref(vartype *matrix, int4 rows, int4 columns);
104
105 phloat fix_hms(phloat x);
106
107 void char2buf(char *buf, int buflen, int *bufptr, char c);
108 void string2buf(char *buf, int buflen, int *bufptr, const char *s, int slen);
109 int uint2string(uint4 n, char *buf, int buflen);
110 int int2string(int4 n, char *buf, int buflen);
111 int ulong2string(uint8 n, char *buf, int buflen);
112 int vartype2string(const vartype *v, char *buf, int buflen, int max_mant_digits = 12);
113 const char *phloat2program(phloat d);
114 int easy_phloat2string(phloat d, char *buf, int buflen, int base_mode);
115 int ip2revstring(phloat d, char *buf, int buflen);
116
117 int matedit_get(vartype **res);
118 void leave_matrix_editor();
119
120
121 #endif