Cover V02, I06
Article
Figure 1
Listing 1
Listing 2

nov93.tar


Listing 2: passPart.c

1  #include <stdio.h>
2
3  main(argc, argv)
4      int argc; char *argv[];
5  {
6      int n;              /* Number of start/end pairs */
7      int *start;         /* Where the bad header starts */
8      int *end;           /* Where the good header starts after a bad header */
9      makeSkipList (argv[1], &n, &start, &end);
10      {   int i;
11          for (i=0; i<n; i++)
12              fprintf (stderr, "start[%d] = %d\tend[%d] = %d\n", i, start[i], i, end[i]);
13      }
14      passBytes (n, start, end);
15  }
16
17  makeSkipList (filename, Pn, PPstart, PPend)
18      char *filename; int *Pn, **PPstart, **PPend;
19  {
20      char line[100];
21      char isNow = 'n';   /* h for being in the HEADER area; n for not */
22      FILE *fp = fopen (filename, "r");
23      *Pn = 0;
24      *PPstart = (int *) calloc (1, sizeof(int));
25      *PPend   = (int *) calloc (1, sizeof(int));
26
27      while (fgets (line, sizeof(line), fp)) {    /* exit at EOF or error */
28          if (line[0] == 'H' && isNow == 'n') {
29              *PPstart = (int *) realloc (*PPstart, (*Pn)+1);
30              sscanf (line, "%*s %*s %d", &((*PPstart)[*Pn]));
31              isNow = 'h';
32          }
33          if (line[0] != 'H' && isNow == 'h') {
34              *PPend = (int *) realloc (*PPend, (*Pn)+1);
35              sscanf (line, "%d", &((*PPend)[*Pn]));
36              isNow = 'n';
37              (*Pn)++;
38          }
39      }
40      fclose(fp);
41  }
42
43  passBytes (n, Pstart, Pend)
44      int n, *Pstart, *Pend;
45  {
46      int i;      /* indexing the Pstart and Pend arrays */
47      int b = 0;  /* Current Byte number */
48      for (i = 0; i < n; i++) {
49          register int s = Pstart[i];
50          register int e = Pend[i];
51          for (; b < s; b++) {
52              putchar (getchar ());
53          }
54          for (; b < e; b++) {
55              getchar();
56          }
57      }
58      while (EOF != (i = getchar()))
59          putchar(i);
60  }
61  /* End of File */