home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / dos / diverses / him / mfdel.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-12-01  |  4.4 KB  |  169 lines

  1. /***************** Program Source Module ***********************/
  2. #ifdef AUTOPDOC
  3.  
  4. MODULE:     mfdel.c
  5.  
  6. DESCRIPTION:
  7.  
  8.    A little file delete utility which will build a menu of
  9.    files in the current directory and allow you to mark/unmark each file.
  10.    When enter is pressed all marked files will be deleted.
  11.  
  12.    When the list is built, all files with a read-only attribute will show
  13.    up on the list but will be marked read-only so the user can't do anything
  14.    with it.
  15.  
  16. TABLE OF CONTENTS:
  17.  
  18. #endif
  19. /*
  20.  *
  21.  *   Copyright 1988  Allsoft (tm)
  22.  *   100 Calle Playa Del Sol NE
  23.  *   Albuquerque, NM  87109
  24.  *
  25.  *   ALL RIGHTS RESERVED.
  26.  *
  27.  *   Unauthorized distribution, adaptation or use may be 
  28.  *   subject to civil and criminal penalties.
  29.  *
  30.  */
  31. /********** Filled by Polytron Version Control System **********
  32.  
  33. $Author:   james borders  $
  34.  
  35. $Date:   01 Dec 1988 12:17:26  $
  36.  
  37. $Revision:   1.0  $
  38.  
  39. $Log:   D:/C/FMLIB/MM/VCS/MFDEL.C  $
  40.  * 
  41.  *    Rev 1.0   01 Dec 1988 12:17:26   james borders
  42.  * Initial revision.
  43.  
  44. ****************************************************************/
  45.  
  46. /*** Include Files ***/
  47.  
  48. #include "stdio.h"
  49. #ifdef MSC
  50. #include "malloc.h"
  51. #endif
  52. #include "dos.h"
  53. #ifdef TURBOC
  54. #include "alloc.h"
  55. #include "dir.h"
  56. #endif
  57. #include "lm.h"
  58. #include "wn.h"
  59. #include "km.h"
  60. #include "mm.h"
  61.  
  62. /*** Typedefs ***/
  63.  
  64. /*** Constants ***/
  65.  
  66. #define  BC    WNBLUE
  67. #define  FC    WNLCYAN
  68. #define  BBC   WNBLUE
  69. #define  BFC   WNCYAN
  70. #define  HBC   WNBLACK
  71. #define  HFC   WNCYAN
  72. #define  RBC   WNBLUE
  73. #define  RFC   WNDGRAY
  74. #define  MBC   WNBLUE
  75. #define  MFC   WNGREEN
  76. #define  TBC   WNBLACK
  77. #define  TFC   WNYELLOW
  78. #define  MC    '\001'
  79. #define  MK    ' '
  80.  
  81. #define  WIDTH   70
  82. #define  HEIGHT  0
  83. #define  ROW     15
  84. #define  COL     0
  85. #define  ABSATT  MMABSR | MMABSW
  86.  
  87. #ifdef MSC
  88. #define  LOOKUPKEY _A_RDONLY | _A_NORMAL
  89. #define  ROKEY     _A_RDONLY | _A_HIDDEN | _A_SYSTEM | _A_VOLID | _A_SUBDIR
  90. #define  FILEBLOCK struct find_t
  91. #define  getfirst(a,b,c)    _dos_findfirst((a), (b), (c))
  92. #define  getnext(a)         _dos_findnext(a)
  93. #define  attribfld          attrib
  94. #define  namefld            name
  95. #endif
  96. #ifdef TURBOC
  97. #define  LOOKUPKEY FA_RDONLY 
  98. #define  ROKEY     FA_RDONLY | FA_HIDDEN | FA_SYSTEM | FA_LABEL | FA_DIREC
  99. #define  FILEBLOCK struct ffblk
  100. #define  getfirst(a,b,c)    findfirst((a), (c), (b))
  101. #define  getnext(a)         findnext(a)
  102. #define  attribfld          ff_attrib
  103. #define  namefld            ff_name
  104. #endif
  105. /*** Global Vars ***/
  106.  
  107. /*** Macros ***/
  108.  
  109. main(argc,argv)
  110. /*****/             
  111. int  argc;
  112. char *argv[];
  113. {
  114. int code,mnum,mel,count;
  115. FILEBLOCK cfile;
  116. int kbhit(),getch();
  117. char *cfs;
  118. char buf[80];
  119.  
  120. lminit((char *(*)())malloc,free,0);           /* init list manager */
  121. wninit(0,0,NULL,0,(char *(*)())malloc,free);  /* window manager using memory */
  122. kminit(kbhit,getch);                        /* keyboard manager */
  123. mminit(kmgetch,NULL);                       /* menu manager */
  124.  
  125. mmscparms(BC,FC,BBC,BFC,RBC,RFC,MBC,MFC,HBC,HFC,TBC,TFC,MC,MK);
  126. mnum = mmcreate("files",MMPOPUP,ROW,COL,WIDTH,HEIGHT,ABSATT,
  127.                 "[ Files in Current Directory ]",
  128.                 "[ Space to Mark, ESC to Abort, Enter to Delete Marked ]",NULL,0,
  129.                 0,1,MMACTIONNULL,NULL);
  130.  
  131. count = 0;
  132. if (argc > 1)
  133.    cfs = argv[1];
  134. else
  135.    cfs = "*.*";
  136. code = getfirst(cfs,LOOKUPKEY,&cfile);
  137. while (code == 0){
  138.    count++;
  139.    sprintf(buf,"File [%s] is number %d",cfile.namefld,count);
  140.    mel = mmamel(mnum,"",cfile.namefld,buf,"",1,0,MMNOCASE | cfile.namefld[0],
  141.                 MMACTIONNULL,NULL);
  142.    if (cfile.attribfld & (ROKEY))
  143.       mmsmelronly(mnum,mel);                    /* make read only */
  144.    code = getnext(&cfile);
  145.    }
  146.  
  147. if (count){
  148.    code = mmpromenu(mnum,MMPROCESS,1);
  149.    if (code != 0){                              /* user didn't ESCAPE */
  150.       if (mmgmelstat(mnum,-1) > 0){                /* user marked files */
  151.          mel = mmgfirstmel(mnum);
  152.          while (mel > 0){
  153.             if (mmgmelstat(mnum,mel)){
  154.                if (unlink(mmgmelmdata(mnum,mel))){      /* delete file */
  155.                   printf("\nError deleting file [%s].",mmgmelmdata(mnum,mel));
  156.                   }
  157.                }
  158.             mel = mmgnextmel(mnum);
  159.             }
  160.          }
  161.       }
  162.    }
  163. else{
  164.    printf("\nNo files matching [%s]",cfs);
  165.    }
  166. mmdestroy(mnum); 
  167. exit(0);
  168. }
  169.