⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 registry.c

📁 解压在c盘
💻 C
📖 第 1 页 / 共 2 页
字号:
      }    }    else if (ch == '\'') {      for (ch = buf_read(is);           ch >= 0 && ch != '\'';           ch = buf_read(is)) {      }    }  }  cse_error(is->config, "%s:%d: expected doctype end at end of file\n",	    is->path, is->line);}/* * skips to the end of the cdata declaration */static voidskip_cdata(rstream_t *is){  int ch;  while ((ch = buf_read(is)) >= 0) {    if (ch != ']')      continue;    else if ((ch = buf_read(is)) != ']')      continue;    else if ((ch = buf_read(is)) == '>')      return;  }  cse_error(is->config, "%s:%d: expected CDATA end at end of file\n",	    is->path, is->line);}/* * skips to the end of the processing instruction */static voidskip_pi(rstream_t *is){  int ch;  while ((ch = buf_read(is)) >= 0) {    while (ch == '?') {      if ((ch = buf_read(is)) == '>')        return;    }  }  cse_error(is->config, "%s:%d: expected pi end at end of file\n",	    is->path, is->line);}static char *calculate_subpath(char *dest, char *path, char *value){  int p;    if (! value)    return 0;      for (p = strlen(path); p >= 0; p--) {    if (path[p] == '/' || path[p] == '\\')      break;  }  if (p < 0)    p = 0;    strcpy(dest, path);  dest[p] = 0;  if (value[0] == '/' || value[0] == '\\' ||      (value[1] == ':' &&       ((value[0] >= 'a' && value[0] <= 'z') ||        (value[0] >= 'A' && value[0] <= 'Z')))) {    strcpy(dest, value);  }  else {    strcat(dest, "/");    strcat(dest, value);  }  return dest;}static registry_t *handle_include(config_t *config, registry_t *node, char *path, char *value){  char buf[4096];  char *subpath;  registry_t *subnode;  registry_t *next;  FILE *is;  LOG(("resin:include href=%s pwd=%s\n", value ? value : "null", path));  if (! value || ! value[0])    return node;  subpath = calculate_subpath(buf, path, value);  LOG(("subpath %s\n", subpath));    cse_add_depend(config, subpath);  is = fopen(subpath, "r");  if (! is)    return node;  subnode = cse_parse(is, config, subpath);  fclose(is);  if (! subnode)    return node;  /* Now append the included configuration after the resin:include */  for (subnode = subnode->first; subnode; subnode = next) {    next = subnode->next;    subnode->parent = node->parent;    if (node->next)      node->next->prev = subnode;    else      node->parent->last = subnode;    subnode->next = node->next;    node->next = subnode;    subnode->prev = node;    node = subnode;  }  return node;}static registry_t *parse_include(config_t *config, registry_t *node, char *path){  char *href = cse_find_value(node->first, "href");  return handle_include(config, node, path, href);}static registry_t *parse_include_directory(config_t *config, registry_t *node, char *path){#ifdef WIN32  return node;#else  char buf[4096];  char *href = cse_find_value(node->first, "href");  char *ext = cse_find_value(node->first, "extension");  char *subpath;  DIR *dir;  struct dirent *dirent;  LOG(("resin:include-directory href=%s\n", href ? href : "null"));        if (! href || ! href[0])    return node;  subpath = calculate_subpath(buf, path, href);  LOG(("resin:include-directory %s\n", subpath));  dir = opendir(subpath);  if (! dir)    return node;    cse_add_depend(config, subpath);    while ((dirent = readdir(dir))) {    char *name = dirent->d_name;    if (! ext || (strlen(ext) <= strlen(name) &&                  ! strcmp(name + strlen(name) - strlen(ext), ext))) {      char inc_path[4096];      sprintf(inc_path, "%s/%s", subpath, name);      node = handle_include(config, node, inc_path, name);    }  }  closedir(dir);  return node;#endif}/* * Parses the configuration file. */registry_t *cse_parse(FILE *file, config_t *config, char *path){  int ch;  rstream_t is;  int spaceOnly = 1;  registry_t *root;  registry_t *node;  is.file = file;  is.path = path;  is.line = 1;  is.config = config;  is.length = 0;  is.capacity = 1024;  is.pool = config->p;  is.buf = cse_alloc(config->p, is.capacity);  root = (registry_t *) cse_alloc(config->p, sizeof(registry_t));  memset(root, 0, sizeof(registry_t));  root->key = "";  node = root;  while ((ch = buf_read(&is)) >= 0 && node) {    switch (ch) {    case ' ': case '\t': case '\n': case '\f':      buf_append(&is, ch);      break;    case '<':      if (! node->value && ! node->first) {        char *buf = is.buf;        int length = is.length;        for (; length > 0 && isspace(*buf); buf++, length--) {        }        for (; length > 0 && isspace(buf[length - 1]); length--) {        }                is.length = 0;        if (length > 0) {          buf[length] = 0;          node->value = cse_strdup(is.pool, buf);        }      }      ch = buf_read(&is);      if (ch == '!') {        if ((ch = buf_read(&is)) == 'D') {          skip_doctype(&is);          break;        }        else if (ch == '[') {          skip_cdata(&is);          break;        }	else if (ch != '-')	  cse_error(config, "%s:%d: expected comment start at '%c'\n", is.path, is.line, ch);	if ((ch = buf_read(&is)) != '-')	  cse_error(config, "%s:%d: expected comment start at '%c'\n", is.path, is.line, ch);	skip_comment(&is);      }      else if (ch == '?') {        skip_pi(&is);      }      else if (ch != '/') {	if (parse_tag(&is, &node, ch) < 0)	  return 0;        if (node && node->last && ! strcmp(node->last->key, "resin:include"))          parse_include(config, node->last, path);        else if (node && node->last && ! strcmp(node->last->key, "resin:include-directory"))          parse_include_directory(config, node->last, path);      }      else {	if (parse_end_tag(&is, &node) < 0)	  return 0;        if (node && node->last && ! strcmp(node->last->key, "resin:include"))          parse_include(config, node->last, path);        else if (node && node->last && ! strcmp(node->last->key, "resin:include-directory"))          parse_include_directory(config, node->last, path);      }      break;    default:      spaceOnly = 0;      buf_append(&is, ch);      break;    }  }  return root;}/* * Returns the next matching node. * * e.g. to iterate through all foo *   for (node = cse_next_link(root->first, "foo"); *        node; *        node = cse_next_line(node->next, "foo")) { *   } * */registry_t *cse_next_link(registry_t *node, char *key){  for (; node; node = node->next) {    if (! strcmp(node->key, key))      return node;  }  return 0;}char *cse_find_value(registry_t *node, char *key){  for (; node; node = node->next) {    if (! strcmp(node->key, key))      return node->value;  }  return 0;}char *cse_find_inherited_value(registry_t *node, char *key, char *deflt){  for (; node; node = node->parent) {    char *value = cse_find_value(node, key);    if (value)      return value;  }  return deflt;}voidcse_print_registry(registry_t *registry){  if (! registry)    return;  for (; registry; registry = registry->next) {    if (registry->first) {      cse_log("<%s id=%s>\n", registry->key,	      registry->value ? registry->value : "");      cse_print_registry(registry->first);      cse_log("</%s>\n", registry->key);    }    else      cse_log("%s=%s\n", registry->key, registry->value ? registry->value : "");  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -