Revert r14786 which resulted in a substantial reduction in accuracy to save a 7.6KB...
[kugel-rb.git] / apps / misc.h
blob6c216f4e381dfc9e3f2d51012dfcd4d6303c94ee
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 by Daniel Stenberg
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
19 #ifndef MISC_H
20 #define MISC_H
22 #include <stdbool.h>
23 #include <inttypes.h>
24 /* Format a large-range value for output, using the appropriate unit so that
25 * the displayed value is in the range 1 <= display < 1000 (1024 for "binary"
26 * units) if possible, and 3 significant digits are shown. If a buffer is
27 * given, the result is snprintf()'d into that buffer, otherwise the result is
28 * voiced.*/
29 char *output_dyn_value(char *buf, int buf_size, int value,
30 const unsigned char **units, bool bin_scale);
32 /* Create a filename with a number part in a way that the number is 1
33 * higher than the highest numbered file matching the same pattern.
34 * It is allowed that buffer and path point to the same memory location,
35 * saving a strcpy(). Path must always be given without trailing slash.
37 * "num" can point to an int specifying the number to use or NULL or a value
38 * less than zero to number automatically. The final number used will also
39 * be returned in *num. If *num is >= 0 then *num will be incremented by
40 * one. */
41 #if defined(HAVE_RECORDING) && (CONFIG_RTC == 0)
42 /* this feature is needed by recording without a RTC to prevent disk access
43 when changing files */
44 #define IF_CNFN_NUM_(...) __VA_ARGS__
45 #define IF_CNFN_NUM
46 #else
47 #define IF_CNFN_NUM_(...)
48 #endif
49 char *create_numbered_filename(char *buffer, const char *path,
50 const char *prefix, const char *suffix,
51 int numberlen IF_CNFN_NUM_(, int *num));
53 /* Format time into buf.
55 * buf - buffer to format to.
56 * buf_size - size of buffer.
57 * t - time to format, in milliseconds.
59 void format_time(char* buf, int buf_size, long t);
61 #if CONFIG_RTC
62 /* Create a filename with a date+time part.
63 It is allowed that buffer and path point to the same memory location,
64 saving a strcpy(). Path must always be given without trailing slash.
65 unique_time as true makes the function wait until the current time has
66 changed. */
67 char *create_datetime_filename(char *buffer, const char *path,
68 const char *prefix, const char *suffix,
69 bool unique_time);
70 #endif /* CONFIG_RTC */
72 /* Ask the user if they really want to erase the current dynamic playlist
73 * returns true if the playlist should be replaced */
74 bool warn_on_pl_erase(void);
76 /* Read (up to) a line of text from fd into buffer and return number of bytes
77 * read (which may be larger than the number of bytes stored in buffer). If
78 * an error occurs, -1 is returned (and buffer contains whatever could be
79 * read). A line is terminated by a LF char. Neither LF nor CR chars are
80 * stored in buffer.
82 int read_line(int fd, char* buffer, int buffer_size);
83 int fast_readline(int fd, char *buf, int buf_size, void *parameters,
84 int (*callback)(int n, const char *buf, void *parameters));
86 #ifdef HAVE_LCD_BITMAP
87 /* Save a .BMP file containing the current screen contents. */
88 void screen_dump(void);
89 void screen_dump_set_hook(void (*hook)(int fh));
90 #endif
92 bool settings_parseline(char* line, char** name, char** value);
93 long default_event_handler_ex(long event, void (*callback)(void *), void *parameter);
94 long default_event_handler(long event);
95 bool list_stop_handler(void);
96 void car_adapter_mode_init(void);
97 extern int show_logo(void);
99 #if CONFIG_CODEC == SWCODEC
100 /* Return current ReplayGain mode a file should have (REPLAYGAIN_TRACK or
101 * REPLAYGAIN_ALBUM) if ReplayGain processing is enabled, or -1 if no
102 * information present.
104 int get_replaygain_mode(bool have_track_gain, bool have_album_gain);
105 #endif
107 #ifdef BOOTFILE
108 #if !defined(USB_NONE) && !defined(USB_IPODSTYLE)
109 void check_bootfile(bool do_rolo);
110 #endif
111 #endif
113 /* check range, set volume and save settings */
114 void setvol(void);
116 #ifdef HAVE_LCD_COLOR
117 int hex_to_rgb(const char* hex, int* color);
118 #endif
120 char* strrsplt(char* str, int c);
122 bool file_exists(const char *file);
123 bool dir_exists(const char *path);
126 * removes the extension of filename (if it doesn't start with a .)
127 * puts the result in buffer
129 char *strip_extension(char* buffer, int buffer_size, const char *filename);
131 /* A simplified scanf */
133 * Checks whether the value at position 'position' was really read
134 * during a call to 'parse_list'
135 * - position: 0-based number of the value
136 * - valid_vals: value after the call to 'parse_list'
138 #define LIST_VALUE_PARSED(setvals, position) ((setvals)&(1<<(position)))
139 const char* parse_list(const char *fmt, uint32_t *set_vals,
140 const char sep, const char* str, ...);
142 #endif /* MISC_H */