示例#1
0
LVal directory(char* path) {
  LVal ret=0;
#ifndef HAVE_WINDOWS_H
  DIR* dir=opendir(path);
  struct dirent *dirent;

  if(dir==NULL)
    return 0;
  while((dirent=readdir(dir))!=0) {
    char* str=q(dirent->d_name);
    if(dirent->d_type&DT_DIR)
      str=s_cat2(str,q("/"));
    ret=conss(str,ret);
  }
  closedir(dir);
#else
  WIN32_FIND_DATA fd;
  char *p=cat(path,"*.*",NULL);
  HANDLE dir=FindFirstFile(p,&fd);
  if(dir==INVALID_HANDLE_VALUE)
    return 0;
  do {
    if(!(strcmp(fd.cFileName,".")==0 ||
         strcmp(fd.cFileName,"..")==0)) {
      char* str=q(fd.cFileName);
      if(fd.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
        str=s_cat2(str,q(SLASH));
      ret=conss(str,ret);
    }
  }while(FindNextFile(dir,&fd)!=0);
  s(p);
  FindClose(dir);
#endif
  return ret;
}
示例#2
0
LVal remove_if_not1(Function1 f,LVal v) {
  LVal ret;
  for(ret=0;v;v=Next(v)) {
    LVal fret=f(v);
    if(fret) {
      if(NumberP(first(v))) {
        ret=consi(firsti(v),ret);
      }else if(StringP(first(v))) {
        ret=conss(q(firsts(v)),ret);
      }
    }
    sL(fret);
  }
  return nreverse(ret);
}
示例#3
0
LVal filter_href(LVal t) {
  LVal tags=t;
  LVal ret=(LVal)NULL;
  for(;tags!=(LVal)NULL;tags=Next(tags)) {
    char* href=NULL;
    LVal a=(LVal)((struct tag*)firstp(tags))->attr;
    for(;a;a=Next(a)) {
      struct opts* v=(struct opts*)firstp(a);
      if(strcmp(v->name,"href")==0) {
        href=q(v->value);
        break;
      }
    }
    if(href)
      ret=(LVal)toPointer(conss(href,ret));
  }
  return ret;
}
示例#4
0
Node *conslabel(Loc *loc, char *v)
{
	return conss(loc, nLABEL, v, strlen(v));
}
示例#5
0
Node *consnam(Loc *loc, char *v)
{
	return conss(loc, nNAM, v, strlen(v));
}
示例#6
0
Node *consstr(Loc *loc, char *v, int len)
{
	return conss(loc, nSTR, v, len);
}