home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / gnu / util_src / toglclr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-29  |  1.2 KB  |  80 lines

  1. /*
  2.  * utility to toggle clear TPA beyond BSS flag in .prg header for Tos 1.4
  3.  *
  4.  *    Usage: toglclr file file ....
  5.  *
  6.  *    ++jrb
  7.  */
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <unixlib.h>
  12. #include <string.h>
  13. #include <st-out.h>
  14.  
  15.  
  16. int toggle (fd, fn)
  17. int fd;
  18. char *fn;
  19. {
  20.     struct aexec head;
  21.     unsigned long t;
  22.     
  23.     if(read(fd, &head, sizeof(head)) != sizeof(head))
  24.     {
  25.     perror(fn);
  26.     return 4;
  27.     }
  28.     if(head.a_magic != CMAGIC)
  29.     {
  30.     fprintf(stderr,"%s: Invalid magic number %x\n", fn, head.a_magic);
  31.     return 8;
  32.     }
  33.  
  34.     t = head.a_AZero2;
  35.     head.a_AZero2 ^= 1;
  36.     lseek(fd, 0L, SEEK_SET);
  37.     if(write(fd, &head, sizeof(head)) != sizeof(head))
  38.     {
  39.     perror(fn);
  40.     return 16;
  41.     }
  42.  
  43.     printf("%s: was %d is %d\n", fn, (int)t, (int)head.a_AZero2);
  44.     return 0;
  45. }
  46.  
  47. int main(argc, argv)
  48. int argc;
  49. char **argv;
  50. {
  51.     int fd;
  52.     int status = 0;
  53.     char fn[FILENAME_MAX];
  54.     
  55.     if(argc < 2)
  56.     {
  57.     fprintf(stderr, "usage: toglclr file file .....\n");
  58.     exit(1);
  59.     }
  60.  
  61.     while(--argc > 0)
  62.     {
  63.     (void) strcpy(fn, *++argv);
  64.         if((fd = open(fn, 2)) < 0)
  65.         {
  66.         perror(fn);
  67.         continue;
  68.         }
  69.     status |= toggle(fd, fn);
  70.     if(close(fd))
  71.     {
  72.         perror(fn);
  73.         exit(2);
  74.     }
  75.     }
  76.     
  77.     return status;
  78. }
  79.  
  80.