home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 193_01 / setatr.c < prev    next >
Text File  |  1985-11-14  |  8KB  |  203 lines

  1. /*-----------------------------------------------------------------*/
  2. /*  PROGRAMME  ==>  setatr.c                                       */
  3. /*  VERSION:        1.2      Written: 13th July, 1986              */
  4. /*  -------                  -------  Phil. E. Cogar               */
  5. /*  Will set the nominated byte of the filename to give -          */
  6. /*                                                                 */
  7. /*       R/O  -  read only status                                  */
  8. /*       R/W  -  read/write status                                 */
  9. /*       SYS  -  system file (not shown in directory)              */
  10. /*       DIR  -  directory file                                    */
  11. /*       ARC  -  file has been archived already                    */
  12. /*       CPY  -  file can be copied by archive programme           */
  13. /*                                                                 */
  14. /*  This programme uses the CP/M functions -                       */
  15. /*                                                                 */
  16. /*                 17   search first                               */
  17. /*                 18   search next                                */
  18. /*                 26   set DMA address                            */
  19. /*                 30   set file attributes                        */
  20. /*                                                                 */
  21. /*  to do the required work.                                       */
  22. /*  Note that it requires "DEFF3" for the BDOS functions which     */
  23. /*  form part of the compiled programme.  Also DEFF4.              */
  24. /*  Copyright 1986 - Cogar Computer Services Pty.Ltd.              */
  25. /*-----------------------------------------------------------------*/
  26. #include <bdscio.h>    /* NOTE: This programme is specific to     */
  27.             /* ----  BDS 'C'.   If you use a different */
  28.             /*       C then you must change this line. */
  29. #include <pec.h>    /* Needed for this file                    */
  30. /*-----------------------------------------------------------------*/
  31.  
  32. main(argc,argv)
  33. short argc;
  34. char *argv[];
  35. {
  36.     short count, file_count, i, j, n;    /* counters                */
  37.     short offset;
  38.     char name[14];    /* The file name buffer                    */
  39.     char fcb[36];    /* The file control block  used throughout */
  40.     char mode[4];    /* The file mode                           */
  41.     short drive;    /* To save the current drive               */
  42.     char name_buf[3200];    /* Use to hold the file name       */
  43.                  /* Note present limit of 100       */
  44.     char dma[128];    /* The DMA buffer for CP/M to use          */
  45. /*-----------------------------------------------------------------*/
  46. /*    Start of the programme                                     */
  47. /*-----------------------------------------------------------------*/
  48.     
  49.     offset = file_count = 0;    /* starting value          */
  50.  
  51.     pec_clear();    /* clear the screen to start               */
  52.  
  53.     set_dma(dma);    /* create a DMA buffer                     */
  54. /*-----------------------------------------------------------------*/
  55. /*  Now check to see what was entered from the keyboard.   If the  */
  56. /*  file name and mode aren't specified then ask for them.         */
  57. /*-----------------------------------------------------------------*/
  58.     
  59.     if(argc < 2)    /* check to see if name given              */
  60.         put_header(name);
  61.     else strcpy(name,argv[1]);
  62. /*-----------------------------------------------------------------*/
  63. /*  Save the drive name for later use                              */
  64. /*-----------------------------------------------------------------*/
  65.     if(name[1] == ':')
  66.         drive = toupper(name[0]) - 'A' + 1;
  67.     else drive = 0;
  68.     
  69.     setfcb(fcb,name); /* put name into file control block      */
  70.  
  71.     if(argc < 3)    /* check to see if a MODE is nominated     */
  72.         get_mode(mode);
  73.     else strcpy(mode,argv[2]);
  74.     mode[3] = '\0';        /* Null-terminated */
  75.  
  76. /*-----------------------------------------------------------------*/
  77. /*  Now let the user know what we are looking for                  */
  78. /*-----------------------------------------------------------------*/
  79.  
  80.     printf("\nThe file mask in use is -  ");
  81.     for(n = 1; n < 12; n++)
  82.         putchar(fcb[n]);
  83.     printf(" with mode = %s\n", mode);
  84.     
  85. /*-----------------------------------------------------------------*/
  86. /*  Use the CP/M functions "search first" and, if required,        */
  87. /*  "search next" to seek out matching file names from the disk    */
  88. /*  directory.   Any that are found are then saved into the  name  */
  89. /*   buffer.                                                       */
  90. /*-----------------------------------------------------------------*/
  91.  
  92.     if((i = search_first(fcb)) != 255)
  93.     {
  94.         count = save_name(i, dma, name_buf, file_count, offset);
  95.         file_count = count;
  96.         offset = offset + 32;
  97.     }
  98.     else do_exit();
  99.  
  100.  
  101.     while((i = search_next()) != 255)
  102.     {
  103.         count = save_name(i, dma, name_buf, file_count, offset);
  104.         file_count = count;
  105.         offset = offset + 32;
  106. /*-----------------------------------------------------------------*/
  107. /*  Note the buffer limit of 100 file names.   If this is exceeded */
  108. /*  then the programme fails.                                      */
  109. /*-----------------------------------------------------------------*/
  110.         if(file_count > 99)
  111.         {
  112.             printf("\nWe have a limit of 100 files.\n");
  113.             printf("Try smaller groupings.\n");
  114.             exit();
  115.         }
  116.     }
  117.         
  118. /*-----------------------------------------------------------------*/
  119. /*  Have now loaded all the file names in to the large (name )     */
  120. /*  buffer and can  change the attributes in these in the order    */
  121. /*  they were found.                                               */
  122. /*-----------------------------------------------------------------*/
  123.  
  124.     offset = 0; /* re-set the offset to start of name buffer   */
  125.     
  126.     for(n = 0; n < file_count; n++)
  127.     {
  128.         fcb_zero(fcb);
  129.         for(j = 0; j < 32; j++)
  130.             fcb[j] = name_buf[offset + j];
  131.         fcb[0] = drive;    /* Make sure proper drive used     */
  132.         set_bit(fcb,mode);
  133.         printf("\nHave now altered - ");
  134.         for(j = 1; j < 12; j++)
  135.             putchar(fcb[j]);
  136.     offset = offset + 32;
  137.     }
  138.  
  139.     printf("\n\nAll finished.   Return to CP/M.");
  140. }
  141. /*------------END OF MAIN PROGRAMME--------------------------------*/
  142. /*  SUPPORT ROUTINES USED IN MAIN PROGRAMME                        */
  143. /*-----------------------------------------------------------------*/
  144.  
  145. save_name(identifier, dma, buffer, count, ptr)
  146. short identifier, count, ptr;
  147. char dma[128], *buffer;
  148. {
  149.     short n;
  150.     identifier = identifier*32; /* find the name in DMA buffer */
  151.     for(n = 0; n < 32; n++)
  152.         buffer[ptr + n] = dma[identifier + n];
  153.     count++;
  154.     return(count);
  155. }
  156. /*-----------------------------------------------------------------*/
  157.  
  158. fcb_zero(fcb)
  159. char fcb[36];
  160. {
  161.     short n;
  162.  
  163.     for(n = 0; n < 36; n++)
  164.         fcb[n] = '\0';
  165. }
  166. /*-----------------------------------------------------------------*/
  167.  
  168. get_mode(str)
  169. char str[3];
  170. {
  171.  
  172. printf("\n\nSay which attribute you wish to set.   The choices are -\n\n");
  173. printf("          R/O - read only\n");
  174. printf("          R/W - read/write\n");
  175. printf("          SYS - system file\n");
  176. printf("          DIR - directory file\n");
  177. printf("          ARC - can't be archived\n");
  178. printf("          CPY - available for archiving\n\n");
  179. printf("Either upper case or lower case is OK.\n\n");
  180. gets(str);
  181.  
  182. }
  183. /*-----------------------------------------------------------------*/
  184.  
  185. put_header(name)
  186. char name[14];
  187. {
  188.     printf("Enter the name of the file you wish to alter.\n");
  189.     printf("The entry should be in the form -\n\n");
  190.     printf("          [d:]filename\n\n");
  191.     printf("where 'd' is the optional drive name.\n\n");
  192.     gets(name);
  193. }
  194. /*-----------------------------------------------------------------*/
  195.  
  196. do_exit()
  197. {
  198.     printf("\nUnable to locate the named file.\n");
  199.     exit();
  200. }
  201. /*------------END OF PROGRAMME-------------------------------------*/or(j = 0; j < 32; j++)
  202.             fcb[j] = name_buf[offset + j];
  203.         fcb[0] = drive;    /* Ma