source: trunk/emx/src/libomflib/omflibut.c@ 2446

Last change on this file since 2446 was 18, checked in by bird, 22 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 2.1 KB
Line 
1/* omflibut.c (emx+gcc) -- Copyright (c) 1993-1996 by Eberhard Mattes */
2
3/* Utility functions for dealing with OMFLIBs. */
4
5#include <stdio.h>
6#include <stdlib.h>
7#include <string.h>
8#include "omflib0.h"
9#include <sys/omflib.h>
10
11int omflib_set_error (char *error)
12{
13 strcpy (error, strerror (errno));
14 return -1;
15}
16
17
18int omflib_close (struct omflib *p, char *error)
19{
20 int i;
21
22 fclose (p->f);
23 if (p->dict != NULL)
24 free (p->dict);
25 if (p->mod_tab != NULL)
26 {
27 for (i = 0; i < p->mod_count; ++i)
28 free (p->mod_tab[i].name);
29 free (p->mod_tab);
30 }
31 if (p->pub_tab != NULL)
32 {
33 for (i = 0; i < p->pub_count; ++i)
34 free (p->pub_tab[i].name);
35 free (p->pub_tab);
36 }
37 free (p);
38 return 0;
39}
40
41
42#define ROL2(x) (((unsigned)(x) << 2) | ((unsigned)(x) >> 14))
43#define ROR2(x) (((unsigned)(x) >> 2) | ((unsigned)(x) << 14))
44
45void omflib_hash (struct omflib *p, const byte *name)
46{
47 int i, len;
48 word block_index, bucket_index, block_index_delta, bucket_index_delta;
49 byte c;
50
51 len = name[0];
52 block_index = 0;
53 block_index_delta = 0;
54 bucket_index = 0;
55 bucket_index_delta = 0;
56 for (i = 0; i < len; ++i)
57 {
58 c = name[i] | 0x20;
59 block_index = ROL2 (block_index) ^ c;
60 bucket_index_delta = ROR2 (bucket_index_delta) ^ c;
61 c = name[len-i] | 0x20;
62 bucket_index = ROR2 (bucket_index) ^ c;
63 block_index_delta = ROL2 (block_index_delta) ^ c;
64 }
65 p->block_index = block_index % p->dict_blocks;
66 p->block_index_delta = block_index_delta % p->dict_blocks;
67 if (p->block_index_delta == 0)
68 p->block_index_delta = 1;
69 p->bucket_index = bucket_index % 37;
70 p->bucket_index_delta = bucket_index_delta % 37;
71 if (p->bucket_index_delta == 0)
72 p->bucket_index_delta = 1;
73}
74
75
76int omflib_module_name (char *dst, const char *src)
77{
78 const char *base;
79 char *s;
80 int len;
81
82 base = _getname (src);
83 s = strchr (base, '.');
84 if (s != NULL)
85 len = s - base;
86 else
87 len = strlen (base);
88 if (len > 255)
89 {
90 memcpy (dst, base, 255);
91 dst[255] = 0;
92 return -1;
93 }
94 else
95 {
96 memcpy (dst, base, len);
97 dst[len] = 0;
98 return 0;
99 }
100}
Note: See TracBrowser for help on using the repository browser.