inv2.c (0:68f95e015346) inv2.c (719:6c26331bc6b8)
1/*
2 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
4 */
5
1/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
2/* All Rights Reserved */
3
6/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
7/* All Rights Reserved */
8
4
5/*
6 * Copyright (c) 1980 Regents of the University of California.
7 * All rights reserved. The Berkeley software License Agreement
8 * specifies the terms and conditions for redistribution.
9 */
10
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.
13 */
14
11/*
12 * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
13 * All Rights Reserved.
14 */
15#pragma ident "%Z%%M% %I% %E% SMI"
15
16
16#pragma ident "%Z%%M% %I% %E% SMI"
17
18#include <stdio.h>
19#include <assert.h>
17#include <stdio.h>
18#include <assert.h>
20#define LINESIZ 1250
19#define LINESIZ 1250
21
20
22newkeys (outf, inf, recf, nhash, fd, iflong)
23FILE *outf, *inf, *recf, *fd;
24int *iflong;
21extern int hash();
22
23int
24newkeys(FILE *outf, FILE *inf, FILE *recf, int nhash, FILE *fd, int *iflong)
25{
25{
26 /* reads key lines from inf; hashes and writes on outf;
26 /*
27 * reads key lines from inf; hashes and writes on outf;
27 * writes orig key on recf, records pointer on outf too.
28 * format of outf is : hash code space record pointer
29 */
30
31 long lp, ftell();
28 * writes orig key on recf, records pointer on outf too.
29 * format of outf is : hash code space record pointer
30 */
31
32 long lp, ftell();
32 long ld = 0;
33 long ld = 0;
33 int ll = 0, lt = 0;
34 char line[LINESIZ];
35 char key[30], bkeys[40];
36 char *p, *s;
37 char *keyv[500];
38 int i, nk, ndoc = 0, more = 0, c;
39
34 int ll = 0, lt = 0;
35 char line[LINESIZ];
36 char key[30], bkeys[40];
37 char *p, *s;
38 char *keyv[500];
39 int i, nk, ndoc = 0, more = 0, c;
40
40 lp = ftell (recf);
41 while (fgets(line, LINESIZ, inf))
42 {
41 lp = ftell(recf);
42 while (fgets(line, LINESIZ, inf)) {
43 p = line;
44 while (*p != '\t') p++;
43 p = line;
44 while (*p != '\t') p++;
45 *p++ =0;
45 *p++ = 0;
46 fputs(line, recf);
46 fputs(line, recf);
47 if (fd)
48 {
47 if (fd) {
49 sprintf(bkeys, ";%ld", ld);
50 ll = strlen(p);
51 lt = strlen(bkeys);
52 fputs(bkeys, recf);
53 sprintf(bkeys, ",%d", ll);
54 lt += strlen(bkeys);
55 fputs(bkeys, recf);
56 ld += ll;
57 fputs(p, fd);
58 }
48 sprintf(bkeys, ";%ld", ld);
49 ll = strlen(p);
50 lt = strlen(bkeys);
51 fputs(bkeys, recf);
52 sprintf(bkeys, ",%d", ll);
53 lt += strlen(bkeys);
54 fputs(bkeys, recf);
55 ld += ll;
56 fputs(p, fd);
57 }
59 putc('\n',recf);
60 for(s=p; *s; s++);
61 if (*--s == '\n')
62 {
63 more=0;
64 *s=0;
65 }
66 else
67 more=1;
68 assert (fd==0 || more==0);
58 putc('\n', recf);
59 for (s = p; *s; s++)
60 ;
61 if (*--s == '\n') {
62 more = 0;
63 *s = 0;
64 } else
65 more = 1;
66 assert(fd == 0 || more == 0);
69 nk = getargs(p, keyv);
70 if (more)
71 nk--;
67 nk = getargs(p, keyv);
68 if (more)
69 nk--;
72 for(i=0; i<nk; i++)
73 fprintf(outf,"%04d %06ld\n",hash(keyv[i])%nhash, lp);
74# if D1
75 for(i=0; i<nk; i++)
76 printf("key %s hash %d\n",keyv[i],hash(keyv[i])%nhash);
77# endif
78 if (more) /* allow more than LINESIZ keys */
79 {
70 for (i = 0; i < nk; i++)
71 fprintf(outf, "%04d %06ld\n", hash(keyv[i])%nhash, lp);
72#if D1
73 for (i = 0; i < nk; i++)
74 printf("key %s hash %d\n",
75 keyv[i], hash(keyv[i])%nhash);
76#endif
77 if (more) { /* allow more than LINESIZ keys */
80 strcpy(key, keyv[nk]);
78 strcpy(key, keyv[nk]);
81 for(s=key; *s; s++);
82 while ( (c=getc(inf)) != '\n')
83 {
84 if (c != ' ')
85 {
79 for (s = key; *s; s++)
80 ;
81 while ((c = getc(inf)) != '\n') {
82 if (c != ' ') {
86 *s++ = c;
87 continue;
88 }
83 *s++ = c;
84 continue;
85 }
89 *s=0;
90 if (s>key)
91 fprintf(outf, "%04d %06ld\n",hash(key)%nhash, lp);
86 *s = 0;
87 if (s > key)
88 fprintf(outf, "%04d %06ld\n",
89 hash(key)%nhash, lp);
92 s = key;
93 }
94 }
95 lp += (strlen(line)+lt+1);
96 ndoc++;
97 }
90 s = key;
91 }
92 }
93 lp += (strlen(line)+lt+1);
94 ndoc++;
95 }
98 *iflong = (lp>=65536L);
99 if (sizeof(int)>2) *iflong=1; /* force long on VAX */
96 *iflong = (lp >= 65536L);
97 if (sizeof (int) > 2) *iflong = 1; /* force long on VAX */
100 fclose(recf);
98 fclose(recf);
101 return(ndoc);
99 return (ndoc);
102}
103
100}
101
104trimnl(p)
105char *p;
102
103void
104trimnl(char *p)
106{
107 while (*p) p++;
108 p--;
105{
106 while (*p) p++;
107 p--;
109 if (*p == '\n') *p=0;
108 if (*p == '\n') *p = 0;
110}
109}