1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
/*
\funcref{fun\_makelist}{void fun\_makelist ()}
{}
{}
{newvar(), sortlist()}
{}
{funmakel.c}
{
This function converts the last pushed string into a listvariable
holding expanded filenames. The {\em reg} register is set to hold the
list. The list is alphabetically sorted.
{\bf Note that} under MSDOS, the elements of the list are converted
to lower case.
The argument at the top of the stack may be, optionally, an
attribute mask. In this case, the mask is used in a
{\em findfirst() / findnext ()} loop. By default the
attribute {\em \_A\_NORMAL} is used.
}
*/
#include "icm-exec.h"
void fun_makelist ()
{
register char
*name; /* filemask string */
register int
attrib, /* attribute to scan for */
size = 0; /* sz of created list */
char
*namefound, /* returned by findfirst()/next() */
drive [_MAX_DRIVE], /* strings to create full */
dir [_MAX_DIR], /* filename, incl. path */
fname [_MAX_FNAME],
ext [_MAX_EXT],
newname [_MAX_PATH];
reg = newvar (e_list); /* return type: list */
attrib = stack [sp].vu.intval; /* get function arguments */
name = stack [sp - 1].vu.i->ls.str;
if (*name) /* if valid name.. */
{
_splitpath (name, drive, dir, fname, ext);
/* find a first name */
namefound = findfirst (name, attrib);
while (namefound) /* as long as that succeeds */
{
/* make a new path */
_makepath (newname, drive, dir, namefound, "");
/* add entry to the list */
#ifdef MSDOS /* under DOS: lower case */
reg = addtolist (reg, _strlwr (newname));
#else /* under UNIX: case as-is */
reg = addtolist (reg, newname);
#endif
size++; /* size of the list so far */
namefound = findnext(); /* determine new name */
}
reg.vu.i->ls.list.size = size;
reg = sortlist (reg);
}
}
|