1/////////////////////////////////////////////////////////////////////////
2// $Id$
3/////////////////////////////////////////////////////////////////////////
4//
5//  Copyright (C) 2001  MandrakeSoft S.A.
6//
7//    MandrakeSoft S.A.
8//    43, rue d'Aboukir
9//    75002 Paris - France
10//    http://www.linux-mandrake.com/
11//    http://www.mandrakesoft.com/
12//
13//  This library is free software; you can redistribute it and/or
14//  modify it under the terms of the GNU Lesser General Public
15//  License as published by the Free Software Foundation; either
16//  version 2 of the License, or (at your option) any later version.
17//
18//  This library is distributed in the hope that it will be useful,
19//  but WITHOUT ANY WARRANTY; without even the implied warranty of
20//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21//  Lesser General Public License for more details.
22//
23//  You should have received a copy of the GNU Lesser General Public
24//  License along with this library; if not, write to the Free Software
25//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
26
27#include <sys/types.h>
28#include <sys/stat.h>
29#include <fcntl.h>
30#include <stdlib.h>
31#include <stdio.h>
32#include <unistd.h>
33
34
35unsigned char bios[65536];
36
37  int
38main(int argc, char *argv[])
39{
40  int bios_file;
41  FILE * org_file;
42  unsigned org, last_org, offset;
43  int retval;
44  unsigned int to_read, index;
45  double elements, ratio;
46
47  if (argc !=3 ) {
48    fprintf(stderr, "Usage: usage bios-file org-file\n");
49    exit(1);
50    }
51
52  bios_file = open(argv[1], O_RDONLY);
53  org_file = fopen(argv[2], "r");
54
55  if ( (bios_file<0) | (org_file==NULL) ) {
56    fprintf(stderr, "problems opening files.\n");
57    exit(1);
58    }
59
60  printf("files opened OK\n");
61
62  to_read = 65536;
63  index   = 0;
64  while (to_read > 0) {
65    retval = read(bios_file, &bios[index], to_read);
66    if (retval <= 0) {
67      fprintf(stderr, "problem reading bios file\n");
68      exit(1);
69      }
70    to_read -= retval;
71    index   += retval;
72    }
73  printf("bios file read in OK\n");
74
75  last_org = 0;
76
77  while (1) {
78    retval = fscanf(org_file, "0x%x\n", &org);
79    if (retval <= 0) break;
80    printf("%04x .. %04x ", last_org, org-1);
81    for (offset=org-1; offset>last_org; offset--) {
82      if (bios[offset] != 0) break;
83      }
84    if (offset > last_org) {
85      elements = (1.0 + double(offset) - double(last_org));
86      }
87    else {
88      if (bios[last_org] == 0)
89        elements = 0.0;
90      else
91        elements = 1.0;
92      }
93
94    ratio = elements / (double(org) - double(last_org));
95    ratio *= 100.0;
96    printf("%6.2lf\n", ratio);
97    last_org = org;
98    }
99}
100