11 std::ostream &operator << (std::ostream &ostr, Indent &ind)
13 for (int i = 0; i < ind.indent_level; i++)
16 for (int i = 0; i < ind.align_spaces; i++)
22 static bool check_empty(const char *dirname)
24 struct dirent ent, *entp;
26 DIR *dir = opendir(dirname);
28 fprintf(stderr, "Cannot open directory \"%s\".\n",
35 // readdir_r is buggy on osx 10.2, and will fail if errno is
39 if (readdir_r(dir, &ent, &entp) && errno != EEXIST) {
40 fprintf(stderr, "2 Cannot readdir on \"%s\": %s.\n",
41 dirname, strerror(errno));
46 } while (entp && (!strcmp(ent.d_name, ".") ||
47 !strcmp(ent.d_name, "..")));
57 void makepath(const char *_path, bool require_empty)
60 string::size_type pos = 0, last = 0;
62 while (pos != string::npos) {
63 pos = path.find('/', pos + 1);
64 string component(path, 0, pos);
66 if (component.length() - last == 1) {
73 if (mkdir(component.c_str(), 0777) && errno != EEXIST) {
74 fprintf(stderr, "Cannot create directory \"%s\": %s.\n",
75 component.c_str(), strerror(errno));
81 if (require_empty && !check_empty(_path)) {
82 fprintf(stderr, "Directory \"%s\" is not empty.\n", _path);
87 static inline int hex_to_bin(int hex)
90 return hex - 'a' + 10;
93 return hex - 'A' + 10;
98 void parse_guid(const char *guid_str, char *guid_bin)
100 bool second_hex_digit = false;
103 for (i = 0; i < 36; i++) {
104 if (i == 8 || i == 13 || i == 18 || i == 23) {
105 if (guid_str[i] != '-')
108 if (!isxdigit(guid_str[i]))
111 if (second_hex_digit) {
112 *guid_bin++ |= hex_to_bin(guid_str[i]);
113 second_hex_digit = false;
115 *guid_bin = hex_to_bin(guid_str[i]) << 4;
116 second_hex_digit = true;
121 if (guid_str[i] == 0)
125 yyerrorf("\"%s\" is not a valid GUID.", guid_str);