Category : Recently Uploaded Files
Archive   : SNIP9503.ZIP
Filename : LSARY.C

 
Output of file : LSARY.C contained in archive : SNIP9503.ZIP
/*
** LSARY - A simple directory lister using a filename array
** A public domain C demo program by Bob Stout
*/

#include
#include
#include
#include
#include

/* For portability, make everything look like MSC 6 */

#if defined(__TURBOC__)
#include
#define _dos_findfirst(f,a,b) findfirst(f,b,a)
#define _dos_findnext(b) findnext(b)
#define find_t ffblk
#ifndef _A_SUBDIR
#define _A_SUBDIR FA_DIREC
#endif
#define attrib ff_attrib
#define name ff_name
#define size ff_fsize
#define wr_time ff_ftime
#define wr_date ff_fdate
#define _dos_getdiskfree getdfree
#define diskfree_t dfree
#define avail_clusters df_avail
#define sectors_per_cluster df_sclus
#define bytes_per_sector df_bsec
#else /* assume MSC/QC */
#include
#endif

#ifdef TRUE
#undef TRUE
#endif
#ifdef FALSE
#undef FALSE
#endif
#ifdef ERROR
#undef ERROR
#endif

enum LOGICAL {ERROR = -1, SUCCESS, FALSE = 0, TRUE};

#ifndef CAST
#define CAST(new_type,old_object) (*((new_type *)&(old_object)))
#endif

#define LAST_CHAR(s) (((char *)s)[strlen(s) - 1])

struct DirEntry {
char fname[FILENAME_MAX];
struct DirEntry *next;
} DirRoot = {"", NULL};

/*
** Read a directory into an array
*/

int ReaDirArray(char *path)
{
struct find_t ff;
char pattern[67];
struct DirEntry *base = &DirRoot;

strcpy(pattern, path);
if ('/' != LAST_CHAR(pattern) && '\\' != LAST_CHAR(pattern))
strcat(pattern, "\\");
strcat(pattern, "*.*");
if (SUCCESS == _dos_findfirst(pattern, 0xff, &ff)) do
{
struct DirEntry *node;

if (NULL == (node = malloc(sizeof(struct DirEntry))))
return ERROR;
base->next = node;
strcpy(base->fname, ff.name);
node->next = NULL;
*node->fname = '\0';
base = node;

} while (SUCCESS == _dos_findnext(&ff));
return SUCCESS;
}

/*
** Simple directory lister
*/

main(int argc, char *argv[])
{
char *path;

if (2 > argc)
path = ".";
else path = argv[1];
if (ERROR == ReaDirArray(path))
printf("*** Could not read %s\n", path);
else
{
struct DirEntry *node = &DirRoot;
printf("Directory of %s\n\n", path);
while (node)
{
puts(node->fname);
node = node->next;
}
}
return 0;
}


  3 Responses to “Category : Recently Uploaded Files
Archive   : SNIP9503.ZIP
Filename : LSARY.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/