Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it

563642 views
1
/****************************************************************************
2
@
3
@ ----------------------------------------------------------------------------
4
@
5
@ FILE: Q_catalog.c
6
@
7
@ ----------------------------------------------------------------------------
8
@
9
******************************************************************************/
10
11
#include "typedef.h"
12
#include "name.h"
13
14
void (*(display_element [NR_OF_ELEMENTS_IN_EACH_ENTRY])) (entry *data);
15
void (*(load_element [NR_OF_ELEMENTS_IN_EACH_ENTRY])) (const char *string, entry *data);
16
void (*(delete_element [NR_OF_ELEMENTS_IN_EACH_ENTRY])) (entry *data);
17
int (*(compare_element [NR_OF_ELEMENTS_IN_EACH_ENTRY])) (entry *data1, entry *data2);
18
const char *name_element [NR_OF_ELEMENTS_IN_EACH_ENTRY];
19
20
21
static int bitfield [32] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536};
22
23
static void *xmalloc(int size, const char *string)
24
{
25
void *pointer;
26
if ( (pointer = malloc (size)) == NULL)
27
{
28
perror (string);
29
exit (2);
30
}
31
32
return pointer;
33
}
34
35
36
37
static void display_abbreviation (entry *element)
38
{
39
fprintf (stdout, "%s ", element->abbreviation);
40
}
41
42
static void display_degree (entry *element)
43
{
44
fprintf (stdout, "%i ", element->degree);
45
}
46
47
static void display_symbol (entry *element)
48
{
49
fprintf (stdout, "%s ", element->symbol);
50
}
51
52
53
static void display_order (entry *element)
54
{
55
fprintf (stdout, "%i ", element->order);
56
}
57
58
static void display_discriminant (entry *element)
59
{
60
fprintf (stdout, "%s ", element->discriminant);
61
}
62
63
static void display_zclasses (entry *element)
64
{
65
fprintf (stdout, "%i ", element->zclasses);
66
}
67
68
static void display_affine (entry *element)
69
{
70
fprintf (stdout, "%i ", element->affine);
71
}
72
73
static void display_torsionfree (entry *element)
74
{
75
if (element->torsionfree != -1)
76
fprintf (stdout, "%i ", element->torsionfree);
77
else
78
fprintf (stdout, "Unknown ");
79
}
80
81
static void display_no_conclass (entry *element)
82
{
83
fprintf (stdout, "%i ", element->no_conclass);
84
}
85
86
static void display_no_idem (entry *element)
87
{
88
fprintf (stdout, "%i ", element->no_idem);
89
}
90
91
92
static void load_abbreviation (const char *string, entry *element)
93
{
94
/* if ( (element->abbreviation = (char *) malloc ( (strlen (string) + 1) * sizeof (char))) == NULL ||
95
sprintf (element->abbreviation, string) < 0)
96
{
97
perror ("load_abbreviation");
98
exit (EXIT_FAILURE);
99
}*/
100
101
element->abbreviation = (char *) xmalloc ( (strlen(string)+1) * sizeof(char),
102
"load_abbreviation");
103
104
if ( sprintf (element->abbreviation, string) < 0)
105
{
106
perror ("load_abbreviation");
107
exit (4);
108
}
109
110
111
}
112
113
static void load_degree (const char *string, entry *element)
114
{
115
if (sscanf (string, "%i", &(element->degree)) != 1)
116
{
117
fprintf (stderr, "Data has wrong structure.\n");
118
exit (4);
119
}
120
}
121
122
static void load_symbol (const char *string, entry *element)
123
{
124
125
/* if ( (element->symbol = (char *) malloc ( (strlen (string) + 1) * sizeof (char))) == NULL ||
126
sprintf (element->symbol, string) < 0)
127
{
128
perror ("load_symbol");
129
exit (EXIT_FAILURE);
130
}*/
131
132
element->symbol = (char *) xmalloc ( (strlen(string)+1) * sizeof(char),
133
"load_symbol");
134
135
if( sprintf(element->symbol, string) < 0)
136
{
137
perror ("load_symbol");
138
exit (4);
139
}
140
}
141
142
143
static void load_order (const char *string, entry *element)
144
{
145
if (sscanf (string, "%i", &(element->order)) != 1)
146
{
147
fprintf (stderr, "Data has wrong structure.\n");
148
exit (4);
149
}
150
}
151
152
static void load_discriminant (const char *string, entry *element)
153
{
154
155
/* if ( (element->discriminant = (char *) malloc ( (strlen (string) + 1) * sizeof (char))) == NULL || */
156
/* sprintf (element->discriminant, string) < 0) */
157
/* { */
158
/* perror ("load_discriminant"); */
159
/* exit (EXIT_FAILURE); */
160
/* } */
161
162
element->discriminant = (char *) xmalloc ( (strlen(string)+1) * sizeof(char),
163
"load_discriminant");
164
165
if( sprintf (element->discriminant, string) < 0)
166
{
167
perror ("load_discriminant");
168
exit (4);
169
}
170
171
}
172
173
static void load_zclasses (const char *string, entry *element)
174
{
175
if (sscanf (string, "%i", &(element->zclasses)) != 1)
176
{
177
fprintf (stderr, "Data has wrong structure.\n");
178
exit (4);
179
}
180
}
181
182
static void load_affine (const char *string, entry *element)
183
{
184
if (sscanf (string, "%i", &(element->affine)) != 1)
185
{
186
fprintf (stderr, "Data has wrong structure.\n");
187
exit (4);
188
}
189
}
190
191
static void load_torsionfree (const char *string, entry *element)
192
{
193
if (sscanf (string, "%i", &(element->torsionfree)) != 1)
194
{
195
fprintf (stderr, "Data has wrong structure.\n");
196
exit (4);
197
}
198
}
199
200
static void load_no_conclass (const char *string, entry *element)
201
{
202
if (sscanf (string, "%i", &(element->no_conclass) ) != 1)
203
{
204
fprintf (stderr, "Data has wrong structure.\n");
205
exit (4);
206
}
207
}
208
209
static void load_no_idem (const char *string, entry *element)
210
{
211
if (sscanf (string, "%i", &(element->no_idem) ) != 1)
212
{
213
fprintf (stderr, "Data has wrong structure.\n");
214
exit (4);
215
}
216
}
217
218
219
220
static void delete_abbreviation (entry *element)
221
{
222
free (element->abbreviation);
223
}
224
225
static void delete_degree (entry *element)
226
{
227
return;
228
}
229
230
static void delete_symbol (entry *element)
231
{
232
free (element->symbol);
233
}
234
235
static void delete_order (entry *element)
236
{
237
return;
238
}
239
240
static void delete_discriminant (entry *element)
241
{
242
free (element->discriminant);
243
}
244
245
static void delete_zclasses (entry *element)
246
{
247
return;
248
}
249
250
static void delete_affine (entry *element)
251
{
252
return;
253
}
254
255
static void delete_torsionfree (entry *element)
256
{
257
return;
258
}
259
260
static void delete_no_conclass (entry *element)
261
{
262
return;
263
}
264
265
static void delete_no_idem (entry *element)
266
{
267
return;
268
}
269
270
271
static int cmp_abbreviation (entry *entry1, entry *entry2)
272
{
273
/* If the abb(..)-name contains no dot, then it should match with any
274
database entry matching to the first dot. */
275
if (strchr (entry2->abbreviation, '.') != NULL)
276
{
277
if (strcmp (entry1->abbreviation, entry2->abbreviation) == 0)
278
return 0;
279
}
280
else
281
if (strncmp (entry1->abbreviation, entry2->abbreviation, strlen (entry2->abbreviation)) == 0)
282
return 0;
283
284
return bitfield [COND_ABBREVIATION];
285
}
286
287
static int cmp_degree (entry *entry1, entry *entry2)
288
{
289
if (entry1->degree == entry2->degree)
290
return 0;
291
292
return bitfield [COND_DEGREE];
293
}
294
295
static int cmp_symbol (entry *entry1, entry *entry2)
296
{
297
if ( ! strcmp (entry1->symbol, entry2->symbol))
298
return 0;
299
300
return bitfield [COND_SYMBOL];
301
}
302
303
static int cmp_order (entry *entry1, entry *entry2)
304
{
305
if (entry1->order == entry2->order)
306
return 0;
307
308
return bitfield [COND_ORDER];
309
}
310
311
static int cmp_discriminant (entry *entry1, entry *entry2)
312
{
313
if ( ! strcmp (entry1->discriminant, entry2->discriminant))
314
return 0;
315
316
return bitfield [COND_DISCRIMINANT];
317
}
318
319
static int cmp_zclasses (entry *entry1, entry *entry2)
320
{
321
if (entry1->zclasses == entry2->zclasses)
322
return 0;
323
324
return bitfield [COND_ZCLASSES];
325
}
326
327
static int cmp_affine (entry *entry1, entry *entry2)
328
{
329
if (entry1->affine == entry2->affine)
330
return 0;
331
332
return bitfield [COND_AFFINE];
333
}
334
335
static int cmp_torsionfree (entry *entry1, entry *entry2)
336
{
337
if (entry1->torsionfree == entry2->torsionfree)
338
return 0;
339
340
return bitfield [COND_TORSIONFREE];
341
}
342
343
static int cmp_no_conclass (entry *entry1, entry *entry2)
344
{
345
if (entry1->no_conclass == entry2->no_conclass)
346
return 0;
347
348
return bitfield [COND_NO_CONCLASS];
349
}
350
351
static int cmp_no_idem (entry *entry1, entry *entry2)
352
{
353
if (entry1->no_idem == entry2->no_idem)
354
return 0;
355
356
return bitfield [COND_NO_IDEM];
357
}
358
359
360
361
static void read_database_entry (FILE *file, entry *data)
362
{
363
int i;
364
const char string[200];
365
366
for (i=0; i<NR_OF_ELEMENTS_IN_EACH_ENTRY; i++)
367
{
368
if (fscanf (file, "%199s", string) != 1)
369
{
370
fprintf (stderr, "Data has wrong structure.\n");
371
exit (4);
372
}
373
(load_element [i]) (string, data);
374
}
375
}
376
377
378
void apply_cond_to_display_list (conditions *cond, database *database, int display_list[], int new_condition)
379
{
380
int i;
381
382
for (i=0; i<database->nr; i++)
383
{
384
display_list [i] = display_list [i] | bitfield [new_condition];
385
display_list [i] -= (compare_element [new_condition]) ( & ( (database->entry)[i]), & (cond->entry));
386
}
387
return;
388
}
389
390
void unapply_cond_to_display_list (database *database, int display_list[], int unset_condition)
391
{
392
int i;
393
for (i=0; i<database->nr; i++)
394
display_list [i] = display_list [i] | bitfield [unset_condition];
395
}
396
397
database *load_database (const char *filename, int degree)
398
{
399
FILE *file;
400
401
int i, j, entries_in_this_file;
402
403
char *complete_name;
404
405
database *datas;
406
407
(display_element [COND_ABBREVIATION]) = display_abbreviation,
408
(display_element [COND_DEGREE]) = display_degree,
409
(display_element [COND_SYMBOL]) = display_symbol,
410
(display_element [COND_ORDER]) = display_order,
411
(display_element [COND_DISCRIMINANT]) = display_discriminant,
412
(display_element [COND_ZCLASSES]) = display_zclasses,
413
(display_element [COND_AFFINE]) = display_affine,
414
(display_element [COND_TORSIONFREE]) = display_torsionfree,
415
(display_element [COND_NO_CONCLASS]) = display_no_conclass,
416
(display_element [COND_NO_IDEM]) = display_no_idem;
417
418
(load_element [COND_ABBREVIATION]) = load_abbreviation,
419
(load_element [COND_DEGREE]) = load_degree,
420
(load_element [COND_SYMBOL]) = load_symbol,
421
(load_element [COND_ORDER]) = load_order,
422
(load_element [COND_DISCRIMINANT]) = load_discriminant,
423
(load_element [COND_ZCLASSES]) = load_zclasses,
424
(load_element [COND_AFFINE]) = load_affine,
425
(load_element [COND_TORSIONFREE]) = load_torsionfree,
426
(load_element [COND_NO_CONCLASS]) = load_no_conclass,
427
(load_element [COND_NO_IDEM]) = load_no_idem;
428
429
(delete_element [COND_ABBREVIATION]) = delete_abbreviation,
430
(delete_element [COND_DEGREE]) = delete_degree,
431
(delete_element [COND_SYMBOL]) = delete_symbol,
432
(delete_element [COND_ORDER]) = delete_order,
433
(delete_element [COND_DISCRIMINANT]) = delete_discriminant,
434
(delete_element [COND_ZCLASSES]) = delete_zclasses,
435
(delete_element [COND_AFFINE]) = delete_affine,
436
(delete_element [COND_TORSIONFREE]) = delete_torsionfree,
437
(delete_element [COND_NO_CONCLASS]) = delete_no_conclass,
438
(delete_element [COND_NO_IDEM]) = delete_no_idem;
439
440
(compare_element [COND_ABBREVIATION]) = cmp_abbreviation,
441
(compare_element [COND_DEGREE]) = cmp_degree,
442
(compare_element [COND_SYMBOL]) = cmp_symbol,
443
(compare_element [COND_ORDER]) = cmp_order,
444
(compare_element [COND_DISCRIMINANT]) = cmp_discriminant,
445
(compare_element [COND_ZCLASSES]) = cmp_zclasses,
446
(compare_element [COND_AFFINE]) = cmp_affine,
447
(compare_element [COND_TORSIONFREE]) = cmp_torsionfree,
448
(compare_element [COND_NO_CONCLASS]) = cmp_no_conclass,
449
(compare_element [COND_NO_IDEM]) = cmp_no_idem;
450
451
name_element [COND_ABBREVIATION] = "abbreviation",
452
name_element [COND_DEGREE] = "degree",
453
name_element [COND_SYMBOL] = "symbol",
454
name_element [COND_ORDER] = "order",
455
name_element [COND_DISCRIMINANT] = "discriminant",
456
name_element [COND_ZCLASSES] = "zclasses",
457
name_element [COND_AFFINE] = "affine_classes",
458
name_element [COND_TORSIONFREE] = "torsionfree_space_groups",
459
name_element [COND_NO_CONCLASS] = "con_classes_number",
460
name_element [COND_NO_IDEM] = "idempotent_number";
461
462
463
complete_name = xmalloc ( (strlen(filename) + 16) * sizeof(char), "load_database");
464
465
datas = (database *) xmalloc (sizeof (database), "load_database");
466
467
datas->nr = 0;
468
469
datas->entry = NULL;
470
471
for (i=0; i < 6; i++)
472
if (degree == 0 || degree == i+1)
473
{
474
475
(void) sprintf (complete_name, "%s%d",filename,i+1);
476
477
if ( (file = fopen (complete_name, "r") ) == NULL)
478
{
479
perror ("Open database-file");
480
fprintf (stderr, "Could not open: %s\n", complete_name);
481
exit (4);
482
}
483
484
if (fscanf (file, "%i\n", &entries_in_this_file) != 1)
485
{
486
fprintf (stderr, "Data has wrong structure.\n");
487
exit (4);
488
}
489
490
if (datas->entry == NULL)
491
/* Dieses if wird durch ein BUG in unseren Malloc-Wrappern
492
notwendig. Denn "realloc" mit uebergegenem Null-Pointer
493
verhaelt sich so, wie "malloc". Bei unserer Library wird
494
aber, wird 4 vom Nullpointer abgezogen und dann wird das
495
eigentlich "realloc" mit Speicherzelle -4 aufgerufen, was
496
zu einem Segmetation-fault fuehrt. */
497
datas->entry = (entry *) xmalloc (entries_in_this_file * sizeof (entry), "load_database");
498
else if ( (datas->entry = (entry *) realloc (datas->entry, (datas->nr + entries_in_this_file) * sizeof (entry)) ) == NULL)
499
{
500
perror ("load database");
501
exit (2);
502
}
503
504
for (j=0; j < entries_in_this_file; j++)
505
read_database_entry (file, &(datas->entry [datas->nr + j]) );
506
507
datas->nr += entries_in_this_file;
508
509
if (fclose (file) == EOF)
510
{
511
perror ("Closing database-file");
512
exit (4);
513
}
514
515
}
516
517
518
free (complete_name);
519
520
521
522
523
524
525
return datas;
526
}
527
528
void free_database (database *datas)
529
{
530
int i, j;
531
532
for (i=0; i<datas->nr; i++)
533
for (j=0; j<NR_OF_ELEMENTS_IN_EACH_ENTRY; j++)
534
(delete_element [j]) ( &(datas->entry [i]) );
535
536
537
free (datas->entry);
538
free (datas);
539
}
540
541
void display_entry (entry *element)
542
{
543
int i;
544
545
for (i=0; i<NR_OF_ELEMENTS_IN_EACH_ENTRY; i++)
546
(display_element [i]) (element);
547
548
fprintf (stdout, "\n");
549
}
550
551
void display_data_list (database *datas, int display_list[])
552
{
553
int i;
554
555
fprintf (stdout,"\n");
556
557
for (i=0; i<NR_OF_ELEMENTS_IN_EACH_ENTRY; i++)
558
fprintf (stdout,"%s ", name_element [i]);
559
fprintf (stdout,"\n\n");
560
561
562
for (i=0; i<datas->nr; i++)
563
if (display_list[i] == ALL_MATCH)
564
display_entry ( &(datas->entry[i]) );
565
566
fprintf (stdout, "\n");
567
568
return;
569
}
570
571