UNIVERS  15.3
UNIVERS base processing software API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
misc.h
1 /* $Id: misc.h,v 1.35 2007/09/11 08:48:31 vlad Exp $ */
2 
3 #ifndef __misc_h
4 
5 #define __misc_h
6 
7 
8 #ifdef __cplusplus
9 extern "C"
10 {
11 #endif
12 
13 /*===========================================================*
14  *
15  * Functions that useful in many situations and circumstances,
16  * but they don't have common specialization.
17  *
18  *===========================================================*/
19 
20 #include <string.h> /* for size_t */
21 
22 #include <mix/Types.h>
23 #include <mix/PortableDirs.h>
24 #include <mix/char2ops.h>
25 
26 
39 char* ltoa (char* s, long n);
40 
53 char* lltoa (char* s, long long n);
54 
60 void* mem_copy (void* dst, const void* src, size_t sz);
61 
62 
68 Logic isspacechar (char c);
69 
70 
82  char* strmalloc (int n);
83 
93  char* stralloc (const char* s);
94 
100  void strfree (char* s);
101 
107  /* STRLIST is equal to char** for *NIX and may be SAFEARRAY* on
108  Win32 (see mix/portability.h) */
109 
110 
116  STRLIST strlistalloc (int n);
117 
123  STRLIST strlistdup (STRLIST slist, int n);
124 
130  void strlistfree (STRLIST slist, int n);
131 
137  char* strlistgetitem (STRLIST slist, int i);
138 
144  void strlistputitem (STRLIST slist, int i, const char* s);
145 
156 char* strword (char* str);
157 
162 char* strstripspaces (char* s);
163 
169 const char* strlword (const char* s);
170 
176 int strrcmp (const char* s1, const char* s2);
177 
178 
187 int strrmatch (const char* s1, const char* s2);
188 
189 
194 Logic stronlyspaces (const char* s);
195 
202 Logic strcaseeq (const char* s1, const char* s2);
203 
204 
210 char* strreplacebadch (char* s, char c);
211 
212 
217 char* strtoupper (char* s);
218 
223 char* strtolower (char* s);
224 
230 char* strnsepcpy (char* dst, const char* src, size_t n, char sep);
231 
232 
233 #define CHCL_EOS (1<<0)
234 #define CHCL_EOL (1<<1)
235 #define CHCL_SPACE (1<<2)
236 #define CHCL_PUNCT (1<<3)
237 #define CHCL_ALPHA (1<<4)
238 #define CHCL_DIGIT (1<<5)
244 char* chcl_skip (const char* s, int char_classes);
245 
250 int chcl_class (const char* s);
251 
256 double Round (double x);
257 
258 
259 /*************************************************************
260  * Timer support: stop_timer() returns time in microseconds.
261  * MT-Safe
262  *************************************************************/
263 
265 void start_timer ();
266 
269 unsigned long stop_timer ();
270 
275 void sleep_awhile (unsigned long usec);
276 
277 
285 int DebugLevel ();
286 
287 
288 /*************************************************************
289  * Tunable versatile quick sort procedure.
290  *************************************************************/
291 
293 typedef void (*QsExchangeProc)(void* base, unsigned i1, unsigned i2);
295 typedef Compar (*QsCompareProc)(void* base, unsigned i1, unsigned i2);
296 
298 void QuickSort (void *base, unsigned num,
299  QsExchangeProc pExchangeProc,
300  QsCompareProc pCompareProc);
301 
302 
304 void qs_strlist_exchange (void* base, unsigned i1, unsigned i2);
305 
307 Compar qs_strlist_compare (void* base, unsigned i1, unsigned i2);
308 
309 
310 /*************************************************************
311  * Floating point formatting procedures and functions.
312  *************************************************************/
313 
316 int FracDigits (double h1, double h2);
317 
318 /***********************************************************************
319  * Packed format of number list.
320  ***********************************************************************/
321 
327 int parse_int_list (const char* s, int** list);
328 
334 char* produce_int_list (int n, int* list);
335 
336 
337 /*************************************************************
338  *
339  * Options buffer support.
340  *
341  * Options are represented in separate lines of text buffer
342  * in format name=value with "\n" or "\r\n". Name is
343  * interpreted as the first word (spaces are skipped). The
344  * next token after the name must be '='. The next
345  * character is interpreted as value starting. Value is
346  * prolongated until the end of line except the case the
347  * last character of the line is '\' and previous one is not
348  * '\'. In the last case value is prolongated to the next
349  * line. End-of-line characters are not included in the
350  * value. Between name=value lines the full line comments
351  * started with '#' are accepted.
352  *************************************************************/
353 
356  typedef struct
357  {
358  char *name;
359  char *value;
360  } OptionItem;
361 
363  typedef struct
364  {
365  int items_num;
367  } OptionBase;
368 
373  int* parse_options (const char* buf, OptionBase* base);
374 
379  int* add_options (const char* buf, OptionBase* base);
380 
382  void add_option_item (OptionBase* base,
383  const char* name, const char* value);
384 
388  char* serialize_options (const OptionBase* base,
389  const char* start_line, const char* end_line);
390 
393  OptionItem* find_option (const OptionBase* base,
394  const char* name);
395 
399  OptionItem** find_options (const OptionBase* base,
400  const char* startname);
401 
404  void free_options (OptionBase* base);
405 
406 
410  Logic parse_ini_section (const char* buf, char** word1, char** word2);
411 
412 
413 /*************************************************************
414  *
415  * Support for enumerating labels.
416  * (very slow for large klars)
417  *
418  *************************************************************/
419 
423  typedef struct
424  {
425  int key;
426  char *label;
427  } KeyLabelItem;
428 
431  unsigned find_index_by_label (const KeyLabelItem* klar,
432  unsigned klar_n,
433  const char* label);
434 
437  unsigned find_index_by_key (const KeyLabelItem* klar,
438  unsigned klar_n,
439  int key);
440 
441 
442 
443 /*************************************************************
444  *
445  * Bad floaing point numbers.
446  *
447  *************************************************************/
448 
450 Logic isNaNQ (float num);
451 
453 Logic isInf (float num);
454 
456 Logic isNaNQorInf (float num);
457 
459 float getNaNQ ();
460 
461 
462 /***********************************************************************
463  Compute minimum and maximum value of the vector.
464  Input parameters:
465  a(n) - input vector of samples;
466  n - sample count;
467  Output parameters:
468  mm[0] - minimum value
469  mm[1] - maximum value
470  ***********************************************************************/
471 void vminmax (const float a[], int n, float mm[2]);
472 
473 
474 
475 #ifdef __cplusplus
476 };
477 #endif
478 
479 #endif /* misc.h */
char * value
Definition: misc.h:359
int key
Definition: misc.h:425
int items_num
Definition: misc.h:365
Definition: misc.h:363
Definition: misc.h:423
char * label
Definition: misc.h:426
char * name
Definition: misc.h:358
Definition: misc.h:356
OptionItem * items
Definition: misc.h:366