"SfR Fresh" - the SfR Freeware/Shareware Archive 
Member "ocre-0.029/ocre/src/asocia.c" of archive ocre_v0_029.tgz:
As a special service "SfR Fresh" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting with prefixed line numbers.
Alternatively you can here view or download the uninterpreted source code file.
That can be also achieved for any archive member file by clicking within an archive contents listing on the first character of the file(path) respectively on the according byte size field.
1
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <string.h>
5
6 #include "asocia.h"
7 #include "base.h"
8 #include "errors.h"
9
10 void leeT1 (char * dir, char * nf, char *** pt0, int * pnl)
11 {
12 FILE * fd;
13 char nfl[128];
14 char b0[128];
15 int i;
16 int nc;
17 int nl;
18 char **t0;
19 sprintf(nfl, "%s/%s", dir, nf);
20 fd = fopen (nfl, "r");
21 compruebaFd (fd, nf, "asocia.leeT1");
22 fscanf (fd, "%d", & nl);
23 t0 = (char **) malloc (nl * sizeof(char *));
24 for (i=0; i<nl; i++) {
25 fscanf(fd, "%s ", b0);
26 nc = strlen (b0);
27 t0 [i] = (char *) malloc ((nc+1) * sizeof(char));
28 strcpy (t0 [i], b0);
29 }
30 fclose (fd);
31 *pnl = nl;
32 *pt0 = t0;
33 }
34
35 void leeT2 (char * dir, char * nf, char *** pt0, char *** pt1, int * pnl)
36 {
37 FILE * fd;
38 char nfl[128];
39 char b0[128], b1[128];
40 int i;
41 int nc;
42 int nl;
43 char **t0, **t1;
44 sprintf(nfl, "%s/%s", dir, nf);
45 fd = fopen (nfl, "r");
46 compruebaFd (fd, nf, "asocia.leeT2");
47 fscanf (fd, "%d", & nl);
48 t0 = (char **) malloc (nl * sizeof(char *));
49 t1 = (char **) malloc (nl * sizeof(char *));
50 for (i=0; i<nl; i++) {
51 fscanf(fd, "%s %s ", b0, b1);
52 nc = strlen (b0);
53 t0 [i] = (char *) malloc ((nc+1) * sizeof(char));
54 strcpy (t0 [i], b0);
55 nc = strlen (b1);
56 t1 [i] = (char *) malloc ((nc+1) * sizeof(char));
57 strcpy (t1 [i], b1);
58 }
59 fclose (fd);
60 *pnl = nl;
61 *pt0 = t0;
62 *pt1 = t1;
63 }
64
65 void leeT3 (char * dir, char * nf, char *** pt0, char *** pt1, char *** pt2, int * pnl)
66 {
67 FILE * fd;
68 char nfl[128];
69 char b0[128], b1[128], b2[128];
70 int i;
71 int nc;
72 int nl;
73 char **t0, **t1, **t2;
74 sprintf(nfl, "%s/%s", dir, nf);
75 fd = fopen (nfl, "r");
76 compruebaFd (fd, nf, "asocia.leeT3");
77 fscanf (fd, "%d", & nl);
78 t0 = (char **) malloc (nl * sizeof(char *));
79 t1 = (char **) malloc (nl * sizeof(char *));
80 t2 = (char **) malloc (nl * sizeof(char *));
81 for (i=0; i<nl; i++) {
82 fscanf(fd, "%s %s %s ", b0, b1, b2);
83 nc = strlen (b0);
84 t0 [i] = (char *) malloc ((nc+1) * sizeof(char));
85 strcpy (t0 [i], b0);
86 nc = strlen (b1);
87 t1 [i] = (char *) malloc ((nc+1) * sizeof(char));
88 strcpy (t1 [i], b1);
89 nc = strlen (b2);
90 t2 [i] = (char *) malloc ((nc+1) * sizeof(char));
91 strcpy (t2 [i], b2);
92 }
93 fclose (fd);
94 *pnl = nl;
95 *pt0 = t0;
96 *pt1 = t1;
97 *pt2 = t2;
98 }
99
100 // nm0 entrada
101 int asocT1 (char * nm0, char ** t0, int nl)
102 {
103 int n0, n1, n2;
104 int encontrado;
105 int res;
106 n0 = 0;
107 n2 = nl - 1;
108 if (strcmp(t0[n0], nm0)==0) {
109 return TRUE;
110 }
111 if (strcmp(t0[n2], nm0)==0) {
112 return TRUE;
113 }
114 n1 = (n0 + n2) / 2;
115 encontrado = FALSE;
116 for (; ((n2 - n0)>1) && ! encontrado; n1=(n0+n2)/2) {
117 res = strcmp(t0[n1], nm0);
118 if (res < 0) n0 = n1;
119 if (res > 0) n2 = n1;
120 if (res == 0) encontrado = TRUE;
121 }
122 return encontrado ;
123 }
124
125 // nm0 entrada, nm1 salida
126 int asocT2 (char * nm0, char * nm1, char ** t0, char ** t1, int nl)
127 {
128 int n0, n1, n2;
129 int encontrado;
130 int res;
131 n0 = 0;
132 n2 = nl - 1;
133 if (strcmp(t0[n0], nm0)==0) {
134 strcpy (nm1, t1[n0]);
135 return TRUE;
136 }
137 if (strcmp(t0[n2], nm0)==0) {
138 strcpy (nm1, t1[n2]);
139 return TRUE;
140 }
141 n1 = (n0 + n2) / 2;
142 encontrado = FALSE;
143 for (; ((n2 - n0)>1) && ! encontrado; n1=(n0+n2)/2) {
144 res = strcmp(t0[n1], nm0);
145 if (res < 0) n0 = n1;
146 if (res > 0) n2 = n1;
147 if (res == 0) encontrado = TRUE;
148 }
149 if (encontrado)
150 strcpy (nm1, t1[n1]);
151 return encontrado ;
152 }
153
154 // nm0 entrada, nm1 y nm2 salidas
155 int asocT3 (char * nm0, char * nm1, char * nm2, char ** t0, char ** t1, char ** t2, int nl)
156 {
157 Boolean encontrado;
158 encontrado = asocT2 (nm0, nm1, t0, t1, nl);
159 encontrado = encontrado && asocT2 (nm0, nm2, t0, t2, nl);
160 return encontrado;
161 }