The LevAWC Project
 All Data Structures Files Functions Variables Typedefs Enumerations Macros Pages
utils.h
Go to the documentation of this file.
1 /*
2  * _____
3  * ANSI / ___/
4  * / /__
5  * \___/
6  *
7  * Filename: utils.h
8  * Author : Dan Levin
9  * Date : Sun Feb 08 18:41:33 2015
10  * Version : 0.51
11  * ---
12  * Description: Description: Miscellanenous utility functions
13  *
14  * Date Revision message
15  * 150331 This code ready for version 0.51
16  *
17  */
22 #ifndef _UTILS_H_
23 #define _UTILS_H_
24 
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <ctype.h>
29 
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35  /* SOME USEFUL MACROS */
36  /* Check if memory allocation failed - Usage: MALCHK(string); */
43 #define MALCHK(x) if(!x){fprintf(stderr, "Out of memory, file: %s, line: %d", __FILE__, __LINE__); exit(EXIT_FAILURE);}
44 
51 #define FILCHK(x) if(!x){fprintf(stderr, "File opening failure - in file: %s, line: %d", __FILE__, __LINE__); exit(EXIT_FAILURE);}
52 
53  /* FUNCTION-DECLARATIONS */
58  int rand_int(int low, int high);
59 
64  int dn_up_lim(int minval, int maxval, int val);
65 
70  int dn_lim(int minval, int val);
71 
76  int up_lim(int maxval, int val);
77 
82  int maxval(int val1, int val2);
83 
88  int minval(int val1, int val2);
89 
94  int isfloat2(char *c);
95 
100  int isfloat(char *str);
101 
106  int isunsigned(char *str);
107 
112  int isunsignedfloat(char *str);
113 
118  char *strmove (char *to, char *from);
119 
120 
125  char *strins (char *dest, const char *ins);
126 
131  char *strtrim (char *str, int (*left) (int), int (*right) (int));
132 
137  char *strtriml (char *str);
138 
143  char *strtrimr (char *str);
144 
149  int read_int(const char *prompt, const int lo_val, const int hi_val);
150 
155  int read_char(const char *prompt, const int lo_val, const int hi_val, int (*char_ok)(int ch));
156 
161  int menu(const char *menurow, const int lo_sel, const int hi_sel);
162 
167  int is_val_ok(const int val, const int lo_val, const int hi_val);
168 
173  void my_clearscrn(void);
174 
179  void prompt_and_pause(char *message);
180 
185  void myflush(FILE *in);
186 
187 
188  /* END-OF-FUNCTION-DECLARATIONS */
189 
190 #ifdef __cplusplus
191 }
192 #endif
193 
194 #endif /* _UTILS_H_ */