| 1 | /* Copyright (c) 2006 by Arkkra Enterprises */ |
| 2 | /* All rights reserved */ |
| 3 | |
| 4 | #ifndef _UTILS_H_ |
| 5 | #define _UTILS_H_ |
| 6 | |
| 7 | // This file defines miscellaneous things that don't seem to really |
| 8 | // belong with any particular menu. |
| 9 | |
| 10 | #include <FL/Fl.H> |
| 11 | #include <FL/Fl_Int_Input.H> |
| 12 | |
| 13 | #ifdef OS_LIKE_WIN32 |
| 14 | // For some reason mingw doesn't seem to properly define va_list anywhere. |
| 15 | // I guess it needs a compiler-specific header file. |
| 16 | // We don't actually use any functions that use va_list, |
| 17 | // so just need to try to keep the compiler happy. |
| 18 | #ifndef va_list |
| 19 | #define va_list __VALIST |
| 20 | #endif |
| 21 | #endif |
| 22 | |
| 23 | // The FLTK Fl_Int_Input is almost what we want, but it allows |
| 24 | // octal and hex input via leading 0 and 0x respectively. |
| 25 | // So the Int_Input derived class intercepts the input and throws away |
| 26 | // characters from the set [xX] and leading zeros. |
| 27 | // Sometimes we also want to restrict to positive numbers, |
| 28 | // so the Positive_Int_Input class discards the - character as well. |
| 29 | |
| 30 | class Int_Input : public Fl_Int_Input { |
| 31 | public: |
| 32 | Int_Input(int x, int y, int w, int h, const char * label); |
| 33 | int handle(int event); |
| 34 | protected: |
| 35 | bool allow_negative; |
| 36 | }; |
| 37 | |
| 38 | class Positive_Int_Input : public Int_Input { |
| 39 | public: |
| 40 | Positive_Int_Input(int x, int y, int w, int h, const char * label); |
| 41 | }; |
| 42 | |
| 43 | |
| 44 | // Return the native OS's directory separator character |
| 45 | char dir_separator(void); |
| 46 | // Return the native OS's path separator character |
| 47 | char path_separator(void); |
| 48 | |
| 49 | // Set the $MUPPATH value |
| 50 | extern void set_muppath(const char * new_muppath); |
| 51 | |
| 52 | // Get value of PATH from third argument to main(), or failing that, |
| 53 | // from getenv(), and save it. |
| 54 | extern void get_path(const char ** const env_p); |
| 55 | |
| 56 | // Return true if given path is an absoluate path |
| 57 | extern bool is_absolute(const char * const path); |
| 58 | |
| 59 | // Find full path to an executable. |
| 60 | // If found, true is returned and full path is filled into location, |
| 61 | // which must be at least FL_PATH_MAX bytes long. |
| 62 | // If executable is not found, false is returned, and the contents of |
| 63 | // location is not defined. |
| 64 | extern bool find_executable(const char * const pgm_name, char * location); |
| 65 | |
| 66 | // Returns path to magic file saying user agrees to license |
| 67 | extern const char * magic_file(const char * pname = 0, const char ** env_p = 0); |
| 68 | |
| 69 | #ifdef OS_LIKE_WIN32 |
| 70 | // On Windows, we read the registry to try to determine the proper |
| 71 | // program to use for a given file type, like .mid or .ps files. |
| 72 | // This function will return the path to the appropriate file, |
| 73 | // if found, in a static area that may get overwritten on next call, |
| 74 | // so caller needs to make its own copy. If program is not found, |
| 75 | // returns null. |
| 76 | extern char * lookup_pgm_for_file_suffix(const char * file_suffix); |
| 77 | |
| 78 | // Look for likely default directory for Mup files. |
| 79 | // Use the current user's "My Music" place if there is one, |
| 80 | // otherwise try their "My Documents" folder. |
| 81 | // Returns path in static area or null on failure. |
| 82 | extern char * find_music_folder(void); |
| 83 | |
| 84 | #endif |
| 85 | |
| 86 | #endif |