1 // This file is part of Golly.
2 // See docs/License.html for the copyright notice.
3 
4 #ifndef _UTILS_H_
5 #define _UTILS_H_
6 
7 #include <string>       // for std::string
8 
9 class lifepoll;
10 
11 // Various types and utility routines:
12 
13 typedef struct {
14     unsigned char r;
15     unsigned char g;
16     unsigned char b;
17 } gColor;               // a color in RGB space
18 
19 typedef struct {
20     int x;
21     int y;
22     int width;
23     int height;
24 } gRect;                // a rectangle
25 
26 void SetColor(gColor& color, unsigned char red, unsigned char green, unsigned char blue);
27 // Set given gColor to given RGB values.
28 
29 void SetRect(gRect& rect, int x, int y, int width, int height);
30 // Set given gRect to given location and size.
31 
32 void Warning(const char* msg);
33 // Beep and display message in a modal dialog.
34 
35 bool YesNo(const char* msg);
36 // Similar to Warning, but there are 2 buttons: Yes and No.
37 // Returns true if Yes button is hit.
38 
39 void Fatal(const char* msg);
40 // Beep, display message in a modal dialog, then exit app.
41 
42 void Beep();
43 // Play beep sound, depending on user setting.
44 
45 double TimeInSeconds();
46 // Get time of day, in seconds (accuracy in microsecs).
47 
48 std::string CreateTempFileName(const char* prefix);
49 // Return path to a unique temporary file.
50 
51 bool FileExists(const std::string& filepath);
52 // Does given file exist?
53 
54 void RemoveFile(const std::string& filepath);
55 // Delete given file.
56 
57 bool CopyFile(const std::string& inpath, const std::string& outpath);
58 // Return true if input file is successfully copied to output file.
59 // If the output file existed it is replaced.
60 
61 bool MoveFile(const std::string& inpath, const std::string& outpath);
62 // Return true if input file is successfully moved to output file.
63 // If the output file existed it is replaced.
64 
65 void FixURLPath(std::string& path);
66 // Replace "%..." with suitable chars for a file path (eg. %20 is changed to space).
67 
68 bool IsHTMLFile(const std::string& filename);
69 // Return true if the given file's extension is .htm or .html
70 // (ignoring case).
71 
72 bool IsTextFile(const std::string& filename);
73 // Return true if the given file's extension is .txt or .doc,
74 // or if it's not a HTML file and its name contains "readme"
75 // (ignoring case).
76 
77 bool IsZipFile(const std::string& filename);
78 // Return true if the given file's extension is .zip or .gar
79 // (ignoring case).
80 
81 bool IsRuleFile(const std::string& filename);
82 // Return true if the given file is a rule-related file with
83 // an extension of .rule or .table or .tree or .colors or .icons
84 // (ignoring case).
85 
86 bool IsScriptFile(const std::string& filename);
87 // Return true if the given file is a Lua or Perl or Python script.
88 // It simply checks if the file's extension is .lua or .pl or .py
89 // (ignoring case).
90 
91 bool EndsWith(const std::string& str, const std::string& suffix);
92 // Return true if given string ends with given suffix.
93 
94 lifepoll* Poller();
95 void PollerReset();
96 void PollerInterrupt();
97 extern int event_checker;
98 // Poller is used by gollybase modules to process events.
99 // If event_checker > 0 then we've been called from the event checking code.
100 
101 #endif
102