home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / BIGNAME.ZIP / BIGNAME.C < prev    next >
Text File  |  1993-01-29  |  8KB  |  215 lines

  1. #include <stdio.h>
  2. #include <ctype.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <malloc.h>
  6. #define INCL_DOS
  7. #include <os2.h>
  8.  
  9. typedef struct dir_node
  10.                  {
  11.                    char            file_name [CCHMAXPATHCOMP];
  12.                    ULONG           attributes;
  13.                    FDATE           date;
  14.                    struct dir_node *next;
  15.                  } *dir_node_ptr;
  16.  
  17. static void get_dir(char *,dir_node_ptr *,dir_node_ptr *);
  18.        int  main(int,char **);
  19. static void report_big_names(char *);
  20.  
  21. int fatal_error;
  22. int big_name_found;
  23.  
  24. int main(
  25.   int  argc,
  26.   char *argv[])
  27.     {
  28.       big_name_found=FALSE;
  29.       fatal_error=FALSE;
  30.       if (argc < 2)
  31.         report_big_names("");
  32.       else
  33.         report_big_names(argv[1]);
  34.       if ((! fatal_error) && (! big_name_found))
  35.         printf("No extended names found.\n");
  36.       return(fatal_error);
  37.     }
  38.   
  39. static void report_big_names(
  40.   char *path_name)
  41.     {
  42.       int          char_num;
  43.       char         *char_ptr;
  44.       dir_node_ptr dir_head;
  45.       char         *dir_name;
  46.       dir_node_ptr dir_ptr;
  47.       dir_node_ptr dir_tail;
  48.       int          extended_name;
  49.       char         *new_path_name;
  50.  
  51.       if ((dir_name=(char *) malloc(5+strlen(path_name))) == NULL)
  52.         {
  53.           fatal_error=TRUE;
  54.           printf("Fatal error:  out of memory.\n");
  55.         }
  56.       else
  57.         {
  58.           strcpy(dir_name,path_name);
  59.           strcat(dir_name,"\\*.*");
  60.           dir_head=dir_tail=NULL;
  61.           get_dir(dir_name,&dir_head,&dir_tail);
  62.           while ((! fatal_error) && (dir_head != NULL))
  63.             {
  64.               if (dir_head->file_name[0] != '.')
  65.                 {
  66.                   char_ptr=dir_head->file_name;
  67.                   char_num=1;
  68.                   while ((*char_ptr)
  69.                   &&     (*char_ptr != '.')
  70.                   &&     (char_num <= 8))
  71.                     {                   
  72.                       char_ptr++;
  73.                       char_num++;
  74.                     };
  75.                   if (*char_ptr == '\0')
  76.                     extended_name=FALSE;
  77.                   else
  78.                     if (*char_ptr == '.')
  79.                       {
  80.                         char_num=0;
  81.                         do
  82.                           {
  83.                             char_ptr++;
  84.                             char_num++;
  85.                           }
  86.                         while ((*char_ptr)
  87.                         &&     (*char_ptr != '.')
  88.                         &&     (char_num <= 3));
  89.                         if (*char_ptr == '\0')
  90.                           extended_name=FALSE;
  91.                         else
  92.                           extended_name=TRUE;
  93.                       }
  94.                     else
  95.                       extended_name=TRUE;
  96.                   if (extended_name)
  97.                     {
  98.                       big_name_found=TRUE;
  99.                       if ((new_path_name=(char *)
  100.                        malloc(2+strlen(path_name)+strlen(dir_head->file_name)))
  101.                        == NULL)
  102.                         {
  103.                           fatal_error=TRUE;
  104.                           printf("Fatal error:  out of memory.\n");
  105.                         }
  106.                       else
  107.                         {
  108.                           strcpy(new_path_name,path_name);
  109.                           strcat(new_path_name,"\\");
  110.                           strcat(new_path_name,dir_head->file_name);
  111.                           if ((dir_head->attributes) & ((ULONG) FILE_DIRECTORY))
  112.                             printf("*%s\n",new_path_name);
  113.                           else
  114.                             printf(" %s\n",new_path_name);
  115.                           free((char *) new_path_name);
  116.                         }
  117.                     }
  118.                   if ((! fatal_error)
  119.                   &&  ((dir_head->attributes) & ((ULONG) FILE_DIRECTORY)))
  120.                     {
  121.                       if ((new_path_name=(char *)
  122.                        malloc(2+strlen(path_name)+strlen(dir_head->file_name)))
  123.                        == NULL)
  124.                         {
  125.                           fatal_error=TRUE;
  126.                           printf("Fatal error:  out of memory.\n");
  127.                         }
  128.                       else
  129.                         {
  130.                           strcpy(new_path_name,path_name);
  131.                           strcat(new_path_name,"\\");
  132.                           strcat(new_path_name,dir_head->file_name);
  133.                           report_big_names(new_path_name);
  134.                           free((char *) new_path_name);
  135.                         }
  136.                     }
  137.                 }
  138.               dir_ptr=dir_head;
  139.               dir_head=dir_head->next;
  140.               free((char *) dir_ptr);
  141.             }
  142.           free((char *) dir_name);
  143.         }
  144.       return;
  145.     }
  146.  
  147. static void get_dir(
  148.   char         *dir_name,
  149.   dir_node_ptr *dir_head,
  150.   dir_node_ptr *dir_tail)
  151.     {
  152.       static dir_node_ptr  new_dir_entry;
  153.       static ULONG         dir_allow;
  154.       static HDIR          dir_handle;
  155.       static FILEFINDBUF3  dir_result;
  156.       static ULONG         dir_result_count;
  157.       static ULONG         dir_result_length;
  158.  
  159.       dir_handle=(ULONG) HDIR_CREATE;   
  160.       dir_allow=((ULONG) FILE_ARCHIVED)|((ULONG) FILE_DIRECTORY)
  161.        |((ULONG) FILE_SYSTEM)|((ULONG) FILE_HIDDEN)|((ULONG) FILE_READONLY);
  162.       dir_result_length=(ULONG) sizeof(dir_result);
  163.       dir_result_count=(ULONG) 1;
  164.       if (! DosFindFirst((PSZ) dir_name,&dir_handle,dir_allow,&dir_result,
  165.        dir_result_length,&dir_result_count,(ULONG) 1))
  166.         do
  167.           {
  168.             if (*dir_head == NULL)
  169.               {
  170.                 if ((*dir_head
  171.                  =(struct dir_node *)
  172.                  malloc((unsigned) sizeof(struct dir_node))) == NULL)
  173.                   {
  174.                     fatal_error=TRUE;
  175.                     printf("Fatal error:  out of memory.\n");
  176.                   }
  177.                 else
  178.                   {
  179.                     *dir_tail=*dir_head;
  180.                     (*dir_head)->next=NULL;
  181.                     strcpy((*dir_head)->file_name,dir_result.achName);
  182.                     (*dir_head)->date.day=dir_result.fdateLastWrite.day;
  183.                     (*dir_head)->date.month=dir_result.fdateLastWrite.month;
  184.                     (*dir_head)->date.year=dir_result.fdateLastWrite.year;
  185.                     (*dir_head)->attributes=dir_result.attrFile;
  186.                   }
  187.               }
  188.             else
  189.               {
  190.                 if ((new_dir_entry=(struct dir_node *)
  191.                  malloc((unsigned) sizeof(struct dir_node))) == NULL)
  192.                   {
  193.                     fatal_error=TRUE;
  194.                     printf("Fatal error:  out of memory.\n");
  195.                   }
  196.                 else
  197.                   {
  198.                     strcpy(new_dir_entry->file_name,dir_result.achName);
  199.                     new_dir_entry->attributes=dir_result.attrFile;
  200.                     new_dir_entry->date.day=dir_result.fdateLastWrite.day;
  201.                     new_dir_entry->date.month=dir_result.fdateLastWrite.month;
  202.                     new_dir_entry->date.year=dir_result.fdateLastWrite.year;
  203.                     new_dir_entry->next=NULL;
  204.                     (*dir_tail)->next=new_dir_entry;
  205.                     (*dir_tail)=new_dir_entry;
  206.                   }
  207.               }
  208.           }
  209.         while ((! fatal_error)
  210.         &&     (! DosFindNext(dir_handle,&dir_result,dir_result_length,
  211.          &dir_result_count)));
  212.       return;
  213.     }
  214. 
  215.