9804 hal-set-property should support --direct option
[unleashed.git] / usr / src / cmd / refer / inv6.c
blob572c10a36dcd00e4b83cbf716a0e5a9a28718c5c
1 /*
2 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
4 */
6 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
7 /* All Rights Reserved */
9 /*
10 * Copyright (c) 1980 Regents of the University of California.
11 * All rights reserved. The Berkeley software License Agreement
12 * specifies the terms and conditions for redistribution.
15 #pragma ident "%Z%%M% %I% %E% SMI"
17 #include <stdio.h>
18 #include <assert.h>
20 static void putl(long, FILE *);
22 void
23 whash(FILE *ft, FILE *fa, FILE *fb, int nhash, int iflong,
24 long *ptotct, int *phused)
26 char line[100];
27 int hash = 0, hused = 0;
28 long totct = 0L;
29 int ct = 0;
30 long point;
31 long opoint = -1;
32 int m;
33 int k;
34 long lp;
35 long *hpt;
36 int *hfreq = NULL;
38 hpt = (long *)calloc(nhash+1, sizeof (*hpt));
39 assert(hpt != NULL);
40 hfreq = (int *)calloc(nhash, sizeof (*hfreq));
41 assert(hfreq != NULL);
42 hpt[0] = 0;
43 lp = 0;
44 while (fgets(line, 100, ft)) {
45 totct++;
46 sscanf(line, "%d %ld", &k, &point);
47 if (hash < k) {
48 hused++;
49 if (iflong) putl(-1L, fb);
50 else putw(-1, fb);
51 hfreq[hash] = ct;
52 while (hash < k) {
53 hpt[++hash] = lp;
54 hfreq[hash] = 0;
56 hpt[hash] = lp += iflong ? sizeof (long) : sizeof (int);
57 opoint = -1;
58 ct = 0;
60 if (point != opoint) {
61 if (iflong)
62 putl(opoint = point, fb);
63 else
64 putw((int)(opoint = point), fb);
65 lp += iflong ? sizeof (long) : sizeof (int);
66 ct++;
69 if (iflong) putl(-1L, fb);
70 else putw(-1, fb);
71 while (hash < nhash)
72 hpt[++hash] = lp;
73 fwrite(&nhash, sizeof (nhash), 1, fa);
74 fwrite(&iflong, sizeof (iflong), 1, fa);
75 fwrite(hpt, sizeof (*hpt), nhash, fa);
76 fwrite(hfreq, sizeof (*hfreq), nhash, fa);
77 *ptotct = totct;
78 *phused = hused;
81 static void
82 putl(long ll, FILE *f)
84 putw(ll, f);
87 long
88 getl(FILE *f)
90 return (getw(f));