aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2013-03-05 09:16:29 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2013-03-05 09:16:29 +0200
commitf142ee94c2fa3d5f8ec3686b2ced2e1f0b807def (patch)
tree6a150aea4679db77420db91c26e6a93865abbe65
parenta75760ff7d9bedcb1377fc3441f5e38178da1d6a (diff)
downloadalck-f142ee94c2fa3d5f8ec3686b2ced2e1f0b807def.tar.gz
alck-f142ee94c2fa3d5f8ec3686b2ced2e1f0b807def.tar.bz2
Revamp as a standalone project. Remove unneeded dependencies.
* Makefile.am: Remove * Makefile: Restore from bc518485 * ckaliases.c: Rename to alck.c * ckaliases.h: Rename to alck.h * gram.y (emalloc, error) (syserror, parserror): New functions. (main): Use traditional getopt. * lex.l: Use slist instead of obstack. * slist.c: New file.
-rw-r--r--Makefile13
-rw-r--r--Makefile.am23
-rw-r--r--alck.c (renamed from ckaliases.c)278
-rw-r--r--alck.h (renamed from ckaliases.h)54
-rw-r--r--gram.y115
-rw-r--r--lex.l65
-rw-r--r--slist.c97
7 files changed, 416 insertions, 229 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..00f7ea0
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,13 @@
1CFLAGS=-ggdb
2alck: lex.yy.o y.tab.o alck.o slist.o
3 cc -ggdb -o $@ $^
4
5y.tab.c y.tab.h: gram.y
6 yacc -vtd gram.y
7
8lex.yy.c: lex.l
9 lex -d lex.l
10
11lex.yy.o: lex.yy.c y.tab.h
12
13clean:; rm -rf *.o ckaliases \ No newline at end of file
diff --git a/Makefile.am b/Makefile.am
deleted file mode 100644
index 12f531c..0000000
--- a/Makefile.am
+++ /dev/null
@@ -1,23 +0,0 @@
1# This file is part of GSC
2# Copyright (C) 2005, 2006, 2007 Sergey Poznyakoff
3#
4# GSC is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation; either version 3, or (at your option)
7# any later version.
8#
9# GSC is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with GSC. If not, see <http://www.gnu.org/licenses/>.
16
17AM_YFLAGS=-vtd
18AM_LFLAGS=-d
19sbin_PROGRAMS=ckaliases
20noinst_HEADERS=gram.h
21ckaliases_SOURCES=gram.y lex.l ckaliases.c ckaliases.h
22LDADD=../lib/libgsc.a ../gnu/libgnu.a
23INCLUDES = -I$(top_srcdir)/lib -I$(top_srcdir)/gnu -I../gnu
diff --git a/ckaliases.c b/alck.c
index da0a5c1..f8a3d11 100644
--- a/ckaliases.c
+++ b/alck.c
@@ -14,7 +14,7 @@
14 You should have received a copy of the GNU General Public License along 14 You should have received a copy of the GNU General Public License along
15 with this program. If not, see <http://www.gnu.org/licenses/>. */ 15 with this program. If not, see <http://www.gnu.org/licenses/>. */
16 16
17#include "ckaliases.h" 17#include "alck.h"
18 18
19#ifndef CHAR_BIT 19#ifndef CHAR_BIT
20# define CHAR_BIT 8 20# define CHAR_BIT 8
@@ -77,115 +77,31 @@ TC(unsigned *R, int n)
77 } 77 }
78} 78}
79 79
80 80struct alias {
81void 81 struct alias *prev, *next;
82slist_add(SLIST **plist, char *str)
83{
84 struct string_list *p = xmalloc(sizeof(*p));
85 p->str = str;
86 p->next = NULL;
87
88 if (!*plist) {
89 *plist = xmalloc(sizeof(**plist));
90 (*plist)->head = NULL;
91 }
92
93 if ((*plist)->head == NULL) {
94 (*plist)->head = p;
95 (*plist)->count = 0;
96 } else {
97 (*plist)->tail->next = p;
98 (*plist)->count++;
99 }
100 (*plist)->tail = p;
101}
102
103void
104slist_append(SLIST **pdst, SLIST *src)
105{
106 struct string_list *tail;
107
108 if (!*pdst) {
109 *pdst = xmalloc(sizeof(**pdst));
110 (*pdst)->head = NULL;
111 (*pdst)->count = 0;
112 }
113
114 if ((*pdst)->head = NULL)
115 (*pdst)->head = src->head;
116
117 for (tail = src->tail; tail->next; tail = tail->next)
118 ;
119
120 (*pdst)->tail = tail;
121 (*pdst)->count += src->count;
122}
123
124char *
125slist_member(SLIST *plist, char *name)
126{
127 struct string_list *p;
128
129 if (plist)
130 for (p = plist->head; p; p = p->next)
131 if (p->str && strcmp(p->str, name) == 0)
132 return p->str;
133 return NULL;
134}
135
136void
137slist_destroy(SLIST **plist)
138{
139 struct string_list *p;
140 if (!plist || !*plist)
141 return;
142 p = (*plist)->head;
143 while (p) {
144 struct string_list *next = p->next;
145 free(p);
146 p = next;
147 }
148 free(*plist);
149 *plist = NULL;
150}
151
152
153typedef struct {
154 char *name; 82 char *name;
83 int num;
155 SLIST *exp; 84 SLIST *exp;
156} ALIAS; 85};
157 86
158struct obstack alias_stk; 87struct ali_list {
159unsigned alias_count; 88 struct alias *head, *tail;
160ALIAS *aliases; 89 size_t count;
90};
161 91
162void 92struct ali_list aliases;
163regalias(char *name, SLIST *exp)
164{
165 ALIAS a;
166 a.name = name;
167 a.exp = exp;
168 obstack_grow(&alias_stk, &a, sizeof a);
169 alias_count++;
170}
171
172void
173begin_aliases()
174{
175 obstack_init(&alias_stk);
176}
177 93
178static int 94static int
179alias_cmp(const void *a, const void *b) 95ali_cmp(struct alias *a, struct alias *b)
180{ 96{
181 return strcmp(((ALIAS *) a)->name, ((ALIAS *) b)->name); 97 return strcmp(a->name, b->name);
182} 98}
183 99
184static int 100static int
185alias_cmp2(const void *a, const void *b) 101ali_cmp2(struct alias *a, struct alias *b)
186{ 102{
187 char *aname = ((ALIAS *) a)->name; 103 char *aname = a->name;
188 char *bname = ((ALIAS *) b)->name; 104 char *bname = b->name;
189 int rc; 105 int rc;
190 int alen; 106 int alen;
191 int blen; 107 int blen;
@@ -208,29 +124,148 @@ alias_cmp2(const void *a, const void *b)
208} 124}
209 125
210void 126void
127ali_insert(struct ali_list *lp,
128 struct alias *anchor,
129 struct alias *ent, int before)
130{
131 struct alias *p;
132
133 if (!anchor) {
134 ent->prev = NULL;
135 ent->next = lp->head;
136 if (lp->head)
137 lp->head->prev = ent;
138 else
139 lp->tail = ent;
140 lp->head = ent;
141 lp->count++;
142 return;
143 }
144
145 if (before) {
146 ali_insert(lp, anchor->prev, ent, 0);
147 return;
148 }
149
150 ent->prev = anchor;
151 if (p = anchor->next)
152 p->prev = ent;
153 else
154 lp->tail = ent;
155 ent->next = p;
156 anchor->next = ent;
157 lp->count++;
158}
159
160void
161ali_join(struct ali_list *a, struct ali_list *b)
162{
163 if (!b->head)
164 return;
165 b->head->prev = a->tail;
166 if (a->tail)
167 a->tail->next = b->head;
168 else
169 a->head = b->head;
170 a->tail = b->tail;
171}
172
173void
174ali_sort(struct ali_list *list, int (*cmp)(struct alias *, struct alias *))
175{
176 struct alias *cur, *middle;
177 struct ali_list high_list, low_list;
178 int rc;