10 std::ostream &operator << (std::ostream &ostr, Indent &ind)
12 for (int i = 0; i < ind.indent_level; i++)
15 for (int i = 0; i < ind.align_spaces; i++)
21 static bool check_empty(const char *dirname)
23 struct dirent ent, *entp;
25 DIR *dir = opendir(dirname);
27 fprintf(stderr, "Cannot open directory \"%s\".\n",
34 // readdir_r is buggy on osx 10.2, and will fail if errno is
38 if (readdir_r(dir, &ent, &entp) && errno != EEXIST) {
39 fprintf(stderr, "2 Cannot readdir on \"%s\": %s.\n",
40 dirname, strerror(errno));
45 } while (entp && (!strcmp(ent.d_name, ".") ||
46 !strcmp(ent.d_name, "..")));
56 void makepath(const char *_path, bool require_empty)
59 string::size_type pos = 0, last = 0;
61 while (pos != string::npos) {
62 pos = path.find('/', pos + 1);
63 string component(path, 0, pos);
65 if (component.length() - last == 1) {
72 if (mkdir(component.c_str(), 0777) && errno != EEXIST) {
73 fprintf(stderr, "Cannot create directory \"%s\": %s.\n",
74 component.c_str(), strerror(errno));
80 if (require_empty && !check_empty(_path)) {
81 fprintf(stderr, "Directory \"%s\" is not empty.\n", _path);
86 static inline int hex_to_bin(int hex)
89 return hex - 'a' + 10;
92 return hex - 'A' + 10;
97 void parse_guid(const char *guid_str, char *guid_bin)
99 bool second_hex_digit = false;
102 for (i = 0; i < 36; i++) {
103 if (i == 8 || i == 13 || i == 18 || i == 23) {
104 if (guid_str[i] != '-')
107 if (!isxdigit(guid_str[i]))
110 if (second_hex_digit) {
111 *guid_bin++ |= hex_to_bin(guid_str[i]);
112 second_hex_digit = false;
114 *guid_bin = hex_to_bin(guid_str[i]) << 4;
115 second_hex_digit = true;
120 if (guid_str[i] == 0)
124 yyerrorf("\"%s\" is not a valid GUID.", guid_str);