home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 11 Util
/
11-Util.zip
/
BIGNAME.ZIP
/
BIGNAME.C
< prev
next >
Wrap
Text File
|
1993-01-29
|
8KB
|
215 lines
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#define INCL_DOS
#include <os2.h>
typedef struct dir_node
{
char file_name [CCHMAXPATHCOMP];
ULONG attributes;
FDATE date;
struct dir_node *next;
} *dir_node_ptr;
static void get_dir(char *,dir_node_ptr *,dir_node_ptr *);
int main(int,char **);
static void report_big_names(char *);
int fatal_error;
int big_name_found;
int main(
int argc,
char *argv[])
{
big_name_found=FALSE;
fatal_error=FALSE;
if (argc < 2)
report_big_names("");
else
report_big_names(argv[1]);
if ((! fatal_error) && (! big_name_found))
printf("No extended names found.\n");
return(fatal_error);
}
static void report_big_names(
char *path_name)
{
int char_num;
char *char_ptr;
dir_node_ptr dir_head;
char *dir_name;
dir_node_ptr dir_ptr;
dir_node_ptr dir_tail;
int extended_name;
char *new_path_name;
if ((dir_name=(char *) malloc(5+strlen(path_name))) == NULL)
{
fatal_error=TRUE;
printf("Fatal error: out of memory.\n");
}
else
{
strcpy(dir_name,path_name);
strcat(dir_name,"\\*.*");
dir_head=dir_tail=NULL;
get_dir(dir_name,&dir_head,&dir_tail);
while ((! fatal_error) && (dir_head != NULL))
{
if (dir_head->file_name[0] != '.')
{
char_ptr=dir_head->file_name;
char_num=1;
while ((*char_ptr)
&& (*char_ptr != '.')
&& (char_num <= 8))
{
char_ptr++;
char_num++;
};
if (*char_ptr == '\0')
extended_name=FALSE;
else
if (*char_ptr == '.')
{
char_num=0;
do
{
char_ptr++;
char_num++;
}
while ((*char_ptr)
&& (*char_ptr != '.')
&& (char_num <= 3));
if (*char_ptr == '\0')
extended_name=FALSE;
else
extended_name=TRUE;
}
else
extended_name=TRUE;
if (extended_name)
{
big_name_found=TRUE;
if ((new_path_name=(char *)
malloc(2+strlen(path_name)+strlen(dir_head->file_name)))
== NULL)
{
fatal_error=TRUE;
printf("Fatal error: out of memory.\n");
}
else
{
strcpy(new_path_name,path_name);
strcat(new_path_name,"\\");
strcat(new_path_name,dir_head->file_name);
if ((dir_head->attributes) & ((ULONG) FILE_DIRECTORY))
printf("*%s\n",new_path_name);
else
printf(" %s\n",new_path_name);
free((char *) new_path_name);
}
}
if ((! fatal_error)
&& ((dir_head->attributes) & ((ULONG) FILE_DIRECTORY)))
{
if ((new_path_name=(char *)
malloc(2+strlen(path_name)+strlen(dir_head->file_name)))
== NULL)
{
fatal_error=TRUE;
printf("Fatal error: out of memory.\n");
}
else
{
strcpy(new_path_name,path_name);
strcat(new_path_name,"\\");
strcat(new_path_name,dir_head->file_name);
report_big_names(new_path_name);
free((char *) new_path_name);
}
}
}
dir_ptr=dir_head;
dir_head=dir_head->next;
free((char *) dir_ptr);
}
free((char *) dir_name);
}
return;
}
static void get_dir(
char *dir_name,
dir_node_ptr *dir_head,
dir_node_ptr *dir_tail)
{
static dir_node_ptr new_dir_entry;
static ULONG dir_allow;
static HDIR dir_handle;
static FILEFINDBUF3 dir_result;
static ULONG dir_result_count;
static ULONG dir_result_length;
dir_handle=(ULONG) HDIR_CREATE;
dir_allow=((ULONG) FILE_ARCHIVED)|((ULONG) FILE_DIRECTORY)
|((ULONG) FILE_SYSTEM)|((ULONG) FILE_HIDDEN)|((ULONG) FILE_READONLY);
dir_result_length=(ULONG) sizeof(dir_result);
dir_result_count=(ULONG) 1;
if (! DosFindFirst((PSZ) dir_name,&dir_handle,dir_allow,&dir_result,
dir_result_length,&dir_result_count,(ULONG) 1))
do
{
if (*dir_head == NULL)
{
if ((*dir_head
=(struct dir_node *)
malloc((unsigned) sizeof(struct dir_node))) == NULL)
{
fatal_error=TRUE;
printf("Fatal error: out of memory.\n");
}
else
{
*dir_tail=*dir_head;
(*dir_head)->next=NULL;
strcpy((*dir_head)->file_name,dir_result.achName);
(*dir_head)->date.day=dir_result.fdateLastWrite.day;
(*dir_head)->date.month=dir_result.fdateLastWrite.month;
(*dir_head)->date.year=dir_result.fdateLastWrite.year;
(*dir_head)->attributes=dir_result.attrFile;
}
}
else
{
if ((new_dir_entry=(struct dir_node *)
malloc((unsigned) sizeof(struct dir_node))) == NULL)
{
fatal_error=TRUE;
printf("Fatal error: out of memory.\n");
}
else
{
strcpy(new_dir_entry->file_name,dir_result.achName);
new_dir_entry->attributes=dir_result.attrFile;
new_dir_entry->date.day=dir_result.fdateLastWrite.day;
new_dir_entry->date.month=dir_result.fdateLastWrite.month;
new_dir_entry->date.year=dir_result.fdateLastWrite.year;
new_dir_entry->next=NULL;
(*dir_tail)->next=new_dir_entry;
(*dir_tail)=new_dir_entry;
}
}
}
while ((! fatal_error)
&& (! DosFindNext(dir_handle,&dir_result,dir_result_length,
&dir_result_count)));
return;
}