コード例 #1
0
/* fs_flist_putter:
  *  Callback routine for for_each_file() to fill the file selector listbox.
  */
static int fs_flist_putter(AL_CONST char *str, int attrib, void *check_attrib)
{
    char *s, *ext, *name;
    int c, c2;
    
    s = get_filename(str);
    fix_filename_case(s);
    
    if(!(attrib & FA_DIREC))
    {
        /* Check if file extension matches. */
        if(fext_p)
        {
            ext = get_extension(s);
            
            for(c=0; c<fext_size; c++)
            {
                if(ustricmp(ext, fext_p[c]) == 0)
                    goto Next;
            }
            
            return 0;
        }
        
Next:

        /* Check if file attributes match. */
        if(check_attrib)
        {
            for(c=0; c<ATTRB_MAX; c++)
            {
                if((attrb_state[c] == ATTRB_SET) && (!(attrib & attrb_flag[c])))
                    return 0;
                    
                if((attrb_state[c] == ATTRB_UNSET) && (attrib & attrb_flag[c]))
                    return 0;
            }
        }
    }
    
    if((flist->size < FLIST_SIZE) && ((ugetc(s) != '.') || (ugetat(s, 1))))
    {
        int size = ustrsizez(s) + ((attrib & FA_DIREC) ? ucwidth(OTHER_PATH_SEPARATOR) : 0);
        name = (char *) zc_malloc(size);
        
        if(!name)
            return -1;
            
        ustrzcpy(name, size, s);
        
        if(attrib & FA_DIREC)
            put_backslash(name);
            
        /* Sort alphabetically with directories first. */
        for(c=0; c<flist->size; c++)
        {
            if(ugetat(flist->name[c], -1) == OTHER_PATH_SEPARATOR)
            {
                if(attrib & FA_DIREC)
                    if(ustrfilecmp(name, flist->name[c]) < 0)
                        break;
            }
            else
            {
                if(attrib & FA_DIREC)
                    break;
                    
                if(ustrfilecmp(name, flist->name[c]) < 0)
                    break;
            }
        }
        
        /* Shift in preparation for inserting the new entry. */
        for(c2=flist->size; c2>c; c2--)
            flist->name[c2] = flist->name[c2-1];
            
        /* Insert the new entry. */
        flist->name[c] = name;
        flist->size++;
    }
    
    return 0;
}
コード例 #2
0
ファイル: rfsel.c プロジェクト: albinoz/raine
/* fs_flist_putter:
 *  Callback routine for for_each_file() to fill the file selector listbox.
 */
static void fs_flist_putter(AL_CONST char *str, int attrib, int param)
{
   char ext_tokens[32];
   char *s, *ext, *tok, *name;
   char tmp[512], tmp2[32];
   int c, c2, i, k, sign;

   /* attribute flags (rhsda order)
    * 0 = not required, 1 = must be set, -1 = must be unset
    */
   int attr_flag[5+5] = {
      0, -1, -1, 0, 0,
      FA_RDONLY, FA_HIDDEN, FA_SYSTEM, FA_DIREC, FA_ARCH
   };

   c = usetc(ext_tokens, ' ');
   c += usetc(ext_tokens+c, ',');
   c += usetc(ext_tokens+c, ';');
   usetc(ext_tokens+c, 0);

   s = get_filename(str);
   fix_filename_case(s);

   if (fext) {
      ustrcpy(tmp, fext);
      ustrtok(tmp, ext_tokens);
      c = (ustrtok(NULL, ext_tokens) ? 1 : 0);
      if (!c) {
	 if (!ustrchr(fext, '/'))
	    c = 1;
      }

      if (c && (!(attrib & FA_DIREC))) {
	 ustrcpy(tmp, fext);
	 ext = get_extension(s);
	 tok = ustrtok(tmp, ext_tokens);

	 while (tok) {
	    if (ustricmp(ext, tok) == 0)
	       break;

	    tok = ustrtok(NULL, ext_tokens);
	 }

	 if (!tok)
	    return;
      }

      c = usetc(ext_tokens, ' ');
      c += usetc(ext_tokens+c, ',');
      c += usetc(ext_tokens+c, ';');
      c += usetc(ext_tokens+c, '/');
      usetc(ext_tokens+c, 0);

      ustrcpy(tmp, fext);
      tok = ustrchr(tmp, '/');

      if (tok)
	 tok = ustrtok(tok, ext_tokens);

      if (tok) {
	 sign = 1;
	 c = usetc(tmp2, 'r');
	 c += usetc(tmp2+c, 'h');
	 c += usetc(tmp2+c, 's');
	 c += usetc(tmp2+c, 'd');
	 c += usetc(tmp2+c, 'a');
	 c += usetc(tmp2+c, '+');
	 c += usetc(tmp2+c, '-');
	 usetc(tmp2+c, 0);

	 /* scan the string */
	 i = 0;
	 while ((c = utolower(ugetat(tok, i)))) {
	    k = 0;
	    while ((c2 = ugetat(tmp2, k))!=0) {
	       if (c == c2) {
		  if (k<5) {
		     attr_flag[k] = sign;
		     break;
		  }
		  else
		     sign = (k==5) ? 1 : -1;
	       }
	       k++;
	    }
	    i++;
	 }
      }
   }

   /* check if file attributes match */
   if (!(attr_flag[3+5] & attrib)) {
      /* if not a directory, we check all attributes except FA_DIREC */
      for (c=0; c<5; c++) {
	 if (c == 3)
	    continue;
	 if ((attr_flag[c] == 1) && (!(attrib & attr_flag[c+5])))
	    return;
	 if ((attr_flag[c] == -1) && (attrib & attr_flag[c+5]))
	    return;
      }
   }
   else {
      /* if a directory, we check only FA_DIREC */
      if (attr_flag[3] == -1)
	 return;
   }

   if ((flist->size < FLIST_SIZE) && ((ugetc(s) != '.') || (ugetat(s, 1)))) {
      name = malloc(ustrsizez(s) + ((attrib & FA_DIREC) ? ucwidth(OTHER_PATH_SEPARATOR) : 0));
      if (!name)
	 return;

      for (c=0; c<flist->size; c++) {
	 if (ugetat(flist->name[c], -1) == OTHER_PATH_SEPARATOR) {
	    if (attrib & FA_DIREC)
	       if (ustrfilecmp(s, flist->name[c]) < 0)
		  break;
	 }
	 else {
	    if (attrib & FA_DIREC)
	       break;
	    if (ustrfilecmp(s, flist->name[c]) < 0)
	       break;
	 }
      }

      for (c2=flist->size; c2>c; c2--)
	 flist->name[c2] = flist->name[c2-1];

      flist->name[c] = name;
      ustrcpy(flist->name[c], s);

      if (attrib & FA_DIREC)
	 put_backslash(flist->name[c]);

      flist->size++;
   }
}