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