Back to index

tetex-bin  3.0
list_routines.c
Go to the documentation of this file.
00001 /* list_routines.c: Types used in this program.
00002 
00003 This file is part of Omega,
00004 which is based on the web2c distribution of TeX,
00005 
00006 Copyright (c) 1994--2001 John Plaice and Yannis Haralambous
00007 
00008 Omega is free software; you can redistribute it and/or modify
00009 it under the terms of the GNU General Public License as published by
00010 the Free Software Foundation; either version 2 of the License, or
00011 (at your option) any later version.
00012 
00013 Omega is distributed in the hope that it will be useful,
00014 but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 GNU General Public License for more details.
00017 
00018 You should have received a copy of the GNU General Public License
00019 along with Omega; if not, write to the Free Software Foundation, Inc.,
00020 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
00021 
00022 */
00023 
00024 #include "cpascal.h"
00025 #include "list_routines.h"
00026 
00027 list
00028 cons (void *x, list L)
00029 {
00030 list temp;
00031 temp = (list) xmalloc(sizeof(cell));
00032 temp->contents = x;
00033 temp->ptr = L;
00034 return temp;
00035 }
00036 
00037 list
00038 list1 (void *x)
00039 {
00040 list temp;
00041 temp = (list) xmalloc(sizeof(cell));
00042 temp->contents = x;
00043 temp->ptr = NULL;
00044 return temp;
00045 }
00046 
00047 list
00048 list2 (void *x, void *y)
00049 {
00050 list temp, temp1;
00051 temp = (list) xmalloc(sizeof(cell));
00052 temp1 = (list) xmalloc(sizeof(cell));
00053 temp->contents = x;
00054 temp->ptr = temp1;
00055 temp1->contents = y;
00056 temp1->ptr = NULL;
00057 return temp;
00058 }
00059 
00060 list
00061 append (list K, list L)
00062 {
00063 if (K==NULL) return L;
00064 return cons(K->contents, append(K->ptr, L));
00065 }
00066 
00067 list
00068 append1 (list L, void *x)
00069 {
00070 return (append(L,list1(x)));
00071 }
00072 
00073 
00074 /* Attribute-value list functions */
00075 
00076 av_list
00077 av_cons (int attr, int val, av_list L)
00078 {
00079 av_list temp;
00080 temp = (av_list) xmalloc(sizeof(av_cell));
00081 temp->attribute = attr;
00082 temp->value = val;
00083 temp->ptr = L;
00084 return temp;
00085 }
00086 
00087 av_list
00088 av_list1 (int attr, int val)
00089 {
00090 av_list temp;
00091 temp = (av_list) xmalloc(sizeof(av_cell));
00092 temp->attribute = attr;
00093 temp->value = val;
00094 temp->ptr = NULL;
00095 return temp;
00096 }
00097 
00098 av_list
00099 av_list2 (int attr, int val, int attr1, int val1)
00100 {
00101 av_list temp, temp1;
00102 temp = (av_list) xmalloc(sizeof(av_cell));
00103 temp1 = (av_list) xmalloc(sizeof(av_cell));
00104 temp->attribute = attr;
00105 temp->value = val;
00106 temp->ptr = temp1;
00107 temp1->attribute = attr1;
00108 temp1->value = val1;
00109 temp1->ptr = NULL;
00110 return temp;
00111 }
00112 
00113 av_list
00114 av_append (av_list K, av_list L)
00115 {
00116 if (K==NULL) return L;
00117 return av_cons(K->attribute, K->value, av_append(K->ptr, L));
00118 }
00119 
00120 av_list
00121 av_append1 (av_list L, int attr, int val)
00122 {
00123 return (av_append(L,av_list1(attr, val)));
00124 }
00125 
00126 
00127 /* Index-value list functions */
00128 
00129 in_list
00130 in_cons (int val, in_list N, in_list L)
00131 {
00132 in_list temp;
00133 temp = (in_list) xmalloc(sizeof(in_cell));
00134 temp->value = val;
00135 temp->actual = N;
00136 temp->ptr = L;
00137 return temp;
00138 }
00139 
00140 in_list
00141 in_list1 (int val, in_list N)
00142 {
00143 in_list temp;
00144 temp = (in_list) xmalloc(sizeof(in_cell));
00145 temp->value = val;
00146 temp->actual = N;
00147 temp->ptr = NULL;
00148 return temp;
00149 }
00150 
00151 in_list
00152 in_list2 (int val, in_list N, int val1, in_list N1)
00153 {
00154 in_list temp, temp1;
00155 temp = (in_list) xmalloc(sizeof(in_cell));
00156 temp1 = (in_list) xmalloc(sizeof(in_cell));
00157 temp->value = val;
00158 temp->ptr = temp1;
00159 temp->actual = N;
00160 temp1->value = val1;
00161 temp->actual = N1;
00162 temp1->ptr = NULL;
00163 return temp;
00164 }
00165 
00166 in_list
00167 in_append (in_list K, in_list L)
00168 {
00169 if (K==NULL) return L;
00170 return in_cons(K->value, K->actual, in_append(K->ptr, L));
00171 }
00172 
00173 in_list
00174 in_append1 (in_list L, int val, in_list N)
00175 {
00176 return (in_append(L,in_list1(val, N)));
00177 }
00178 
00179 /* Attribute-value list functions */
00180 
00181 hash_list
00182 hash_cons (int x, int y, int new_class, int lig_z, hash_list L)
00183 {
00184 hash_list temp;
00185 temp = (hash_list) xmalloc(sizeof(hash_cell));
00186 temp->x = x;
00187 temp->y = y;
00188 temp->new_class = new_class;
00189 temp->lig_z = lig_z;
00190 temp->ptr = L;
00191 return temp;
00192 }
00193 
00194 hash_list
00195 hash_list1 (int x, int y, int new_class, int lig_z)
00196 {
00197 hash_list temp;
00198 temp = (hash_list) xmalloc(sizeof(hash_cell));
00199 temp->x = x;
00200 temp->y = y;
00201 temp->new_class = new_class;
00202 temp->lig_z = lig_z;
00203 temp->ptr = NULL;
00204 return temp;
00205 }
00206 
00207 hash_list
00208 hash_list2(int x,int y,int new_class,int lig_z,int x1,int y1,int class1,int lig_z1)
00209 {
00210 hash_list temp, temp1;
00211 temp = (hash_list) xmalloc(sizeof(hash_cell));
00212 temp1 = (hash_list) xmalloc(sizeof(hash_cell));
00213 temp->x = x;
00214 temp->y = y;
00215 temp->new_class = new_class;
00216 temp->lig_z = lig_z;
00217 temp->ptr = temp1;
00218 temp1->x = x1;
00219 temp1->y = y1;
00220 temp1->new_class = class1;
00221 temp1->lig_z = lig_z1;
00222 temp1->ptr = NULL;
00223 return temp;
00224 }
00225 
00226 hash_list
00227 hash_append (hash_list K, hash_list L)
00228 {
00229 if (K==NULL) return L;
00230 return hash_cons(K->x, K->y, K->new_class, K->lig_z, hash_append(K->ptr, L));
00231 }
00232 
00233 hash_list
00234 hash_append1 (hash_list L, int x, int y, int new_class, int lig_z)
00235 {
00236 return (hash_append(L,hash_list1(x, y, new_class, lig_z)));
00237 }
00238 
00239 void
00240 init_queue(queue *q)
00241 {
00242     q->front = NULL;
00243     q->tail = NULL;
00244 }
00245 
00246 void
00247 append_to_queue(queue *q, void *content)
00248 {
00249     if (q->front == NULL) {
00250         q->front = list1(content);
00251         q->tail = q->front;
00252     } else {
00253         q->tail->ptr = list1(content);
00254         q->tail = q->tail->ptr;
00255     }
00256 }