home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c023 / 1.img / PROGRAMS / ZAPHDR.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-03-19  |  2.2 KB  |  85 lines

  1. /* Copyright (C)  Walter L. Peacock 1984-1988.  All rights reserved */
  2. /*  Z A P H D R . C  01/30/85 */
  3.  
  4. #include <stdio.h>
  5. #include "cbtree.h"
  6.  
  7. #if AmigaDOS & LC
  8. #define printf iprintf
  9. #endif
  10.  
  11. void main(argc, argv)
  12. int   argc;
  13. char *argv[];
  14. {
  15.    extern char *calloc();
  16.    extern char *strcpy();
  17.    extern int   exit();
  18.    extern int   open();
  19.    extern int   close();
  20.    BTBLKHDR freespc;
  21.    int fd;
  22.    char filename[32], num_s[15];
  23.    long atol(), xtol();
  24.    long lbuff[2], lseek();
  25.  
  26.    wopen("CON:0/0/640/200/Zaphdrl");
  27.  
  28.    scr_clr();
  29.    printf(
  30.    "\n\n    ZAP file header record FREE SPACE and END-OF-FILE pointers.\n");
  31.  
  32.    fd = getfname(argc, argv, "idx", filename);
  33.  
  34.    /* get the current values for the freelst and eof pointers */
  35.    getfhdr(&freespc, fd);
  36.    lbuff[0] = freespc.freelst;   /* remember these */
  37.    lbuff[1] = freespc.eoflst;
  38.  
  39.    printf("\n    Enter New Free List Pointer <%lu (0x%04lx)> ==> ",
  40.    lbuff[0], lbuff[0]);
  41.    gets(num_s);
  42.  
  43.    if (*num_s != '\0')
  44.       lbuff[0] = (strncmp(num_s, "0x", 2) == 0) ?
  45.                xtol(num_s+2) : atol(num_s);
  46.  
  47.    printf("\n    Enter New End Of File Pointer <%lu (0x%04lx)> ==> ",
  48.    lbuff[1],  lbuff[1]);
  49.    gets(num_s);
  50.  
  51.    if (*num_s != '\0')
  52.       lbuff[1] = (strncmp(num_s, "0x", 2) == 0) ?
  53.                xtol(num_s+2) : atol(num_s);
  54.  
  55.    printf("\n\n    New Free List Pointer  for  file '%s' is: %lu (0x%04lx)",
  56.                                  filename, lbuff[0], lbuff[0]);
  57.    printf("\n\n    New End Of File Pointer for file '%s' is: %lu (0x%04lx)",
  58.                                  filename, lbuff[1], lbuff[1]);
  59.  
  60.    if (lseek(fd, 0L, 0) == -1L)
  61.       ckerror(- CK_SEEK, "zaphdrl: fd");
  62.    if (write(fd, (char *)lbuff, sizeof(lbuff) ) == ERR)
  63.       ckerror(- CK_WRIT, "zaphdrl: lbuff");
  64.  
  65.    close(fd);
  66.    wclose();   /* close Amiga window */
  67.    puts("\n\n");
  68. }
  69.  
  70. long xtol(s)   /* NUL-terminated hex-ascii string to long */
  71. char *s;
  72. {
  73.    char c;
  74.    long l = 0L;
  75.  
  76.    while ( ((c = toupper(*s)) >= '0' && c <= '9') || (c >= 'A' && c <= 'F') )
  77.    {
  78.       ++s;
  79.       l <<= 4;
  80.       l += (c <= '9') ? (c - '0') : (c - 'A' + 0xA);
  81.    }
  82.    return (l);
  83. }
  84.  
  85.