/[gxemul]/upstream/0.4.4/experiments/try_runlen.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /upstream/0.4.4/experiments/try_runlen.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 35 - (show annotations)
Mon Oct 8 16:21:26 2007 UTC (16 years, 6 months ago) by dpavlin
File MIME type: text/plain
File size: 2782 byte(s)
0.4.4
1 /*
2 * Copyright (C) 2004 Anders Gavare. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * 3. The name of the author may not be used to endorse or promote products
13 * derived from this software without specific prior written permission.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
27 *
28 * $Id: try_runlen.c,v 1.4 2005/01/09 01:55:27 debug Exp $
29 *
30 * Run length test.
31 * This program takes a text file of the following format as input:
32 *
33 * 8003005c
34 * 80030060
35 * 80030064
36 * 80030068
37 * 8003006c
38 * 80030070
39 * 8013f740
40 * 8013f744
41 * 8013f748
42 * 8013f74c
43 *
44 * and returns the number of successive instructions in a block. Using
45 * the example above, the output would be:
46 *
47 * 6
48 * 4
49 */
50
51 #include <stdio.h>
52 #include <stdlib.h>
53 #include <limits.h>
54 #include <string.h>
55
56
57 int main(int argc, char *argv[])
58 {
59 FILE *f;
60 long long addr = 1; /* Magic number 1 */
61 long long newaddr;
62 char buf[100];
63 int count;
64
65 if (argc < 2) {
66 fprintf(stderr, "usage: %s inputfile\n", argv[0]);
67 exit(1);
68 }
69
70 f = fopen(argv[1], "r");
71 if (f == NULL) {
72 perror(argv[1]);
73 exit(1);
74 }
75
76 count = 0;
77 buf[0] = '0';
78 buf[1] = 'x';
79
80 while (!feof(f)) {
81 buf[2] = buf[sizeof(buf)-1] = 0;
82 fgets(buf + 2, sizeof(buf) - 2, f);
83
84 /* printf("buf = '%s'\n", buf); */
85
86 if (strlen(buf) < 4)
87 break;
88
89 newaddr = strtoull(buf, NULL, 0);
90 if (addr != 1 && newaddr != addr + 4) {
91 printf("%i\n", count);
92 count = 0;
93 }
94 count ++;
95
96 addr = newaddr;
97 }
98
99 /* Print the length of the last block: */
100 printf("%i\n", count);
101
102 return 0;
103 }
104

  ViewVC Help
Powered by ViewVC 1.1.26