void Trick::AttributesMap::print_xml(std::ofstream & sie_out ) { std::map<std::string, ATTRIBUTES *>::iterator it ; int jj ; for ( it = name_to_attr_map.begin() ; it != name_to_attr_map.end() ; it++ ) { ATTRIBUTES * attr = (*it).second ; std::string class_name = (*it).first; std::replace(class_name.begin(), class_name.end(), ':', '_'); sie_out << " <class name=\"" << class_name << "\">" << std::endl ; while ( attr->name[0] != '\0' and (attr->type_name != NULL)) { sie_out << " <member" ; sie_out << std::endl << " name=\"" << attr->name << "\"" ; std::string type_name = attr->type_name; std::replace(type_name.begin(), type_name.end(), ':', '_'); sie_out << std::endl << " type=\"" << type_remove_dims(type_name) << "\"" ; sie_out << std::endl << " io_attributes=\"" << attr->io << "\"" ; sie_out << std::endl << " units=\"" << attr->units << "\"" ; std::string description = attr->des; if ( ! description.empty() ) { sie_out << std::endl << " description=\"" << replace_special_chars(description) << "\"" ; } sie_out << ">" << std::endl ; if ( attr->num_index > 0 ) { for (jj = 0; jj < attr->num_index; jj++) { sie_out << " <dimension>" << attr->index[jj].size << "</dimension>" << std::endl ; } } sie_out << " </member>" << std::endl ; attr++ ; } sie_out << " </class>" << std::endl << std::endl ; } }
std::string & Trick::AttributesMap::type_remove_dims( std::string & type ) { size_t index = type.find_first_of("*["); if (index != std::string::npos) { type.erase(index); } index = type.find_last_not_of(" "); if (index != std::string::npos) { type.erase(index + 1); } return replace_special_chars(type) ; }
int main (int argc, char **argv) { int ret = 0; char *line = NULL; size_t line_len = 0; ssize_t len; FILE *f; static int test_utf8 = 0; static const struct option options[] = { {"utf8", no_argument, &test_utf8, 1}, {NULL, 0, NULL, 0 } }; #ifdef HAVE_MCHECK_H mtrace (); #endif while (getopt_long (argc, argv, "", options, NULL) >= 0); if (optind + 1 != argc) { fprintf (stderr, "Missing test filename\n"); return 1; } f = fopen (argv[optind], "r"); if (f == NULL) { fprintf (stderr, "Couldn't open %s\n", argv[optind]); return 1; } while ((len = getline (&line, &line_len, f)) > 0) { char *pattern, *flagstr, *string, *expect, *matches, *p; int cflags = REG_EXTENDED, eflags = 0, try_bre_ere = 0; if (line[len - 1] == '\n') line[len - 1] = '\0'; /* Skip comments and empty lines. */ if (*line == '#' || *line == '\0') continue; puts (line); fflush (stdout); pattern = strtok (line, "\t"); if (pattern == NULL) continue; if (strcmp (pattern, "\"\"") == 0) pattern += 2; flagstr = strtok (NULL, "\t"); if (flagstr == NULL) continue; string = strtok (NULL, "\t"); if (string == NULL) continue; if (strcmp (string, "\"\"") == 0) string += 2; for (p = flagstr; *p; ++p) switch (*p) { case '-': break; case 'b': cflags &= ~REG_EXTENDED; break; case '&': try_bre_ere = 1; break; case 'C': eflags = -1; break; case 'i': cflags |= REG_ICASE; break; case 's': cflags |= REG_NOSUB; break; case 'n': cflags |= REG_NEWLINE; break; case '^': eflags |= REG_NOTBOL; break; case '$': eflags |= REG_NOTEOL; break; case 'm': case 'p': case '#': /* Not supported. */ flagstr = NULL; break; } if (flagstr == NULL) continue; replace_special_chars (pattern); glibc_re_syntax (pattern); if (eflags != -1) replace_special_chars (string); expect = strtok (NULL, "\t"); matches = NULL; if (expect != NULL) { replace_special_chars (expect); matches = strtok (NULL, "\t"); if (matches != NULL) replace_special_chars (matches); } if (setlocale (LC_ALL, "C") == NULL) { puts ("setlocale C failed"); ret = 1; } if (test (pattern, cflags, string, eflags, expect, matches, "FAIL") || (try_bre_ere && test (pattern, cflags & ~REG_EXTENDED, string, eflags, expect, matches, "FAIL"))) ret = 1; else if (test_utf8) { if (setlocale (LC_ALL, "cs_CZ.UTF-8") == NULL) { puts ("setlocale cs_CZ.UTF-8 failed"); ret = 1; } else if (test (pattern, cflags, string, eflags, expect, matches, "UTF-8 FAIL") || (try_bre_ere && test (pattern, cflags & ~REG_EXTENDED, string, eflags, expect, matches, "UTF-8 FAIL"))) ret = 1; else if (mb_tests (pattern, cflags, string, eflags, expect, matches) || (try_bre_ere && mb_tests (pattern, cflags & ~REG_EXTENDED, string, eflags, expect, matches))) ret = 1; } } free (line); fclose (f); return ret; }
// Helper used to create an absolute filename using the passed // directory and xdebug-specific format string static String format_filename(folly::StringPiece dir, folly::StringPiece formatFile, bool addSuffix) { // Create a string buffer and append the directory name auto const formatlen = formatFile.size(); StringBuffer buf(formatlen * 2); // Slightly larger than formatlen if (!dir.empty()) { buf.append(dir); buf.append('/'); } // Append the filename auto globals = get_global_variables()->asArrayData(); for (int pos = 0; pos < formatlen; pos++) { auto c = formatFile[pos]; if (c != '%' || pos + 1 == formatlen) { buf.append(c); continue; } c = formatFile[++pos]; switch (c) { // crc32 of current working directory case 'c': { auto const crc32 = HHVM_FN(crc32)(g_context->getCwd()); buf.append(crc32); break; } // process id case 'p': buf.append(getpid()); break; // Random number case 'r': buf.printf("%lx", (long)HHVM_FN(rand)()); break; // Script name case 's': { auto server = globals->get(s_SERVER).toArray(); if (server.exists(s_SCRIPT_NAME) && server[s_SCRIPT_NAME].isString()) { const String scriptname(server[s_SCRIPT_NAME].toString(), CopyString); replace_special_chars(scriptname.get()); buf.append(scriptname); } break; } // Timestamp (seconds) case 't': { auto const sec = (int64_t)time(nullptr); if (sec != -1) { buf.append(sec); } break; } // Timestamp (microseconds) case 'u': { struct timeval tv; if (gettimeofday(&tv, 0) != -1) { buf.printf("%ld_%ld", long(tv.tv_sec), long(tv.tv_usec)); } break; } // $_SERVER['HTTP_HOST'] case 'H': { Array server = globals->get(s_SERVER).toArray(); if (server.exists(s_HTTP_HOST) && server[s_HTTP_HOST].isString()) { const String hostname(server[s_HTTP_HOST].toString(), CopyString); replace_special_chars(hostname.get()); buf.append(hostname); } break; } // $_SERVER['REQUEST_URI'] case 'R': { auto server = globals->get(s_SERVER).toArray(); if (globals->exists(s_REQUEST_URI)) { const String requri(server[s_REQUEST_URI].toString(), CopyString); replace_special_chars(requri.get()); buf.append(requri); } break; } // $_SERVER['UNIQUE_ID'] case 'U': { auto server = globals->get(s_SERVER).toArray(); if (server.exists(s_UNIQUE_ID) && server[s_UNIQUE_ID].isString()) { const String uniqueid(server[s_UNIQUE_ID].toString(), CopyString); replace_special_chars(uniqueid.get()); buf.append(uniqueid); } break; } // session id case 'S': { // First we grab the session name from the ini settings, then the id // from the cookies String session_name; if (IniSetting::Get(s_SESSION_NAME, session_name)) { auto cookies = globals->get(s_COOKIE).toArray(); if (cookies.exists(session_name) && cookies[session_name].isString()) { const String sessionstr(cookies[session_name].toString(), CopyString); replace_special_chars(sessionstr.get()); buf.append(sessionstr); } break; } } // Literal case '%': buf.append('%'); break; default: buf.append('%'); buf.append(c); break; } } // Optionally add .xt file extension if (addSuffix) { buf.append(".xt"); } return buf.copy(); }