• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /netgear-R7000-V1.0.7.12_1.2.5/ap/gpl/timemachine/gettext-0.17/gettext-tools/src/

Lines Matching refs:list

41 #define VERIFY_LIST(list) verify_list (list)
49 argument list. It is a recursive list structure. Structure sharing
54 FCT_REQUIRED, /* The format argument list cannot end before this argument. */
55 FCT_OPTIONAL /* The format argument list may end before this argument. */
77 enum format_cdr_type presence; /* Can the argument list end right before
80 struct format_arg_list *list; /* For FAT_LIST: List elements. */
94 /* The constraints for the potentially infinite argument list are assumed
111 struct format_arg_list *list;
122 PT_V /* variable taken from argument list */
134 static void verify_list (const struct format_arg_list *list);
135 static void free_list (struct format_arg_list *list);
136 static struct format_arg_list * copy_list (const struct format_arg_list *list);
143 (struct format_arg_list *list);
157 verify_list (e->list);
163 verify_list (const struct format_arg_list *list)
168 ASSERT (list->initial.count <= list->initial.allocated);
170 for (i = 0; i < list->initial.count; i++)
172 verify_element (&list->initial.element[i]);
173 total_repcount += list->initial.element[i].repcount;
175 ASSERT (total_repcount == list->initial.length);
177 ASSERT (list->repeated.count <= list->repeated.allocated);
179 for (i = 0; i < list->repeated.count; i++)
181 verify_element (&list->repeated.element[i]);
182 total_repcount += list->repeated.element[i].repcount;
184 ASSERT (total_repcount == list->repeated.length);
187 #define VERIFY_LIST(list) verify_list (list)
192 /* Free the data belonging to an argument list element. */
197 free_list (element->list);
200 /* Free an argument list. */
201 /* Memory effects: Frees list. */
203 free_list (struct format_arg_list *list)
207 for (i = 0; i < list->initial.count; i++)
208 free_element (&list->initial.element[i]);
209 if (list->initial.element != NULL)
210 free (list->initial.element);
212 for (i = 0; i < list->repeated.count; i++)
213 free_element (&list->repeated.element[i]);
214 if (list->repeated.element != NULL)
215 free (list->repeated.element);
221 /* Copy the data belonging to an argument list element. */
230 newelement->list = copy_list (oldelement->list);
233 /* Copy an argument list. */
236 copy_list (const struct format_arg_list *list)
242 VERIFY_LIST (list);
246 newlist->initial.count = newlist->initial.allocated = list->initial.count;
248 if (list->initial.count == 0)
254 for (i = 0; i < list->initial.count; i++)
257 &list->initial.element[i]);
258 length += list->initial.element[i].repcount;
261 ASSERT (length == list->initial.length);
264 newlist->repeated.count = newlist->repeated.allocated = list->repeated.count;
266 if (list->repeated.count == 0)
272 for (i = 0; i < list->repeated.count; i++)
275 &list->repeated.element[i]);
276 length += list->repeated.element[i].repcount;
279 ASSERT (length == list->repeated.length);
297 && (e1->type == FAT_LIST ? equal_list (e1->list, e2->list) : true));
300 /* Tests whether two normalized argument list constraints are equivalent. */
341 /* Ensure list->initial.allocated >= newcount. */
343 ensure_initial_alloc (struct format_arg_list *list, unsigned int newcount)
345 if (newcount > list->initial.allocated)
347 list->initial.allocated =
348 MAX (2 * list->initial.allocated + 1, newcount);
349 list->initial.element =
351 xrealloc (list->initial.element,
352 list->initial.allocated * sizeof (struct format_arg));
356 /* Ensure list->initial.allocated > list->initial.count. */
358 grow_initial_alloc (struct format_arg_list *list)
360 if (list->initial.count >= list->initial.allocated)
362 list->initial.allocated =
363 MAX (2 * list->initial.allocated + 1, list->initial.count + 1);
364 list->initial.element =
366 xrealloc (list->initial.element,
367 list->initial.allocated * sizeof (struct format_arg));
371 /* Ensure list->repeated.allocated >= newcount. */
373 ensure_repeated_alloc (struct format_arg_list *list, unsigned int newcount)
375 if (newcount > list->repeated.allocated)
377 list->repeated.allocated =
378 MAX (2 * list->repeated.allocated + 1, newcount);
379 list->repeated.element =
381 xrealloc (list->repeated.element,
382 list->repeated.allocated * sizeof (struct format_arg));
386 /* Ensure list->repeated.allocated > list->repeated.count. */
388 grow_repeated_alloc (struct format_arg_list *list)
390 if (list->repeated.count >= list->repeated.allocated)
392 list->repeated.allocated =
393 MAX (2 * list->repeated.allocated + 1, list->repeated.count + 1);
394 list->repeated.element =
396 xrealloc (list->repeated.element,
397 list->repeated.allocated * sizeof (struct format_arg));
404 /* Normalize an argument list constraint, assuming all sublists are already
406 /* Memory effects: Destructively modifies list. */
408 normalize_outermost_list (struct format_arg_list *list)
415 n = list->initial.count;
418 && equal_element (&list->initial.element[i],
419 &list->initial.element[j-1]))
421 list->initial.element[j-1].repcount +=
422 list->initial.element[i].repcount;
423 free_element (&list->initial.element[i]);
428 list->initial.element[j] = list->initial.element[i];
431 list->initial.count = j;
433 n = list->repeated.count;
436 && equal_element (&list->repeated.element[i],
437 &list->repeated.element[j-1]))
439 list->repeated.element[j-1].repcount +=
440 list->repeated.element[i].repcount;
441 free_element (&list->repeated.element[i]);
446 list->repeated.element[j] = list->repeated.element[i];
449 list->repeated.count = j;
452 if (list->repeated.count > 0)
457 n = list->repeated.count;
460 && equal_element (&list->repeated.element[0],
461 &list->repeated.element[n-1]))
463 repcount0_extra = list->repeated.element[n-1].repcount;
467 list->repeated.element[0].repcount incremented by repcount0_extra. */
475 if (!((list->repeated.element[i].repcount
477 == list->repeated.element[i+m].repcount)
478 && equal_element (&list->repeated.element[i],
479 &list->repeated.element[i+m])))
487 free_element (&list->repeated.element[i]);
488 if (n < list->repeated.count)
489 list->repeated.element[m] = list->repeated.element[n];
490 list->repeated.count = list->repeated.count - n + m;
491 list->repeated.length /= n / m;
498 if (list->repeated.count == 1)
500 if (list->initial.count > 0
501 && equal_element (&list->initial.element[list->initial.count-1],
502 &list->repeated.element[0]))
507 list->initial.length -=
508 list->initial.element[list->initial.count-1].repcount;
509 list->initial.count--;
514 while (list->initial.count > 0
515 && equal_element (&list->initial.element[list->initial.count-1],
516 &list->repeated.element[list->repeated.count-1]))
519 MIN (list->initial.element[list->initial.count-1].repcount,
520 list->repeated.element[list->repeated.count-1].repcount);
522 /* Add the element at the start of list->repeated. */
523 if (equal_element (&list->repeated.element[0],
524 &list->repeated.element[list->repeated.count-1]))
525 list->repeated.element[0].repcount += moved_repcount;
528 unsigned int newcount = list->repeated.count + 1;
529 ensure_repeated_alloc (list, newcount);
531 list->repeated.element[i] = list->repeated.element[i-1];
532 list->repeated.count = newcount;
533 copy_element (&list->repeated.element[0],
534 &list->repeated.element[list->repeated.count-1]);
535 list->repeated.element[0].repcount = moved_repcount;
538 /* Remove the element from the end of list->repeated. */
539 list->repeated.element[list->repeated.count-1].repcount -=
541 if (list->repeated.element[list->repeated.count-1].repcount == 0)
543 free_element (&list->repeated.element[list->repeated.count-1]);
544 list->repeated.count--;
547 /* Remove the element from the end of list->initial. */
548 list->initial.element[list->initial.count-1].repcount -=
550 if (list->initial.element[list->initial.count-1].repcount == 0)
552 free_element (&list->initial.element[list->initial.count-1]);
553 list->initial.count--;
555 list->initial.length -= moved_repcount;
561 /* Normalize an argument list constraint. */
562 /* Memory effects: Destructively modifies list. */
564 normalize_list (struct format_arg_list *list)
568 VERIFY_LIST (list);
571 n = list->initial.count;
573 if (list->initial.element[i].type == FAT_LIST)
574 normalize_list (list->initial.element[i].list);
575 n = list->repeated.count;
577 if (list->repeated.element[i].type == FAT_LIST)
578 normalize_list (list->repeated.element[i].list);
580 /* Then normalize the top level list. */
581 normalize_outermost_list (list);
583 VERIFY_LIST (list);
593 /* Create an unconstrained argument list. */
598 struct format_arg_list *list;
600 list = XMALLOC (struct format_arg_list);
601 list->initial.count = 0;
602 list->initial.allocated = 0;
603 list->initial.element = NULL;
604 list->initial.length = 0;
605 list->repeated.count = 1;
606 list->repeated.allocated = 1;
607 list->repeated.element = XNMALLOC (1, struct format_arg);
608 list->repeated.element[0].repcount = 1;
609 list->repeated.element[0].presence = FCT_OPTIONAL;
610 list->repeated.element[0].type = FAT_OBJECT;
611 list->repeated.length = 1;
613 VERIFY_LIST (list);
615 return list;
619 /* Create an empty argument list. */
624 struct format_arg_list *list;
626 list = XMALLOC (struct format_arg_list);
627 list->initial.count = 0;
628 list->initial.allocated = 0;
629 list->initial.element = NULL;
630 list->initial.length = 0;
631 list->repeated.count = 0;
632 list->repeated.allocated = 0;
633 list->repeated.element = NULL;
634 list->repeated.length = 0;
636 VERIFY_LIST (list);
638 return list;
642 /* Test for an empty list. */
645 is_empty_list (const struct format_arg_list *list)
647 return (list->initial.count == 0 && list->repeated.count == 0);
653 /* Unfold list->repeated m times, where m >= 1.
654 Assumes list->repeated.count > 0. */
655 /* Memory effects: list is destructively modified. */
657 unfold_loop (struct format_arg_list *list, unsigned int m)
663 unsigned int newcount = list->repeated.count * m;
664 ensure_repeated_alloc (list, newcount);
665 i = list->repeated.count;
667 for (j = 0; j < list->repeated.count; j++, i++)
668 copy_element (&list->repeated.element[i], &list->repeated.element[j]);
669 list->repeated.count = newcount;
670 list->repeated.length = list->repeated.length * m;
674 /* Ensure list->initial.length := m, where m >= list->initial.length.
675 Assumes list->repeated.count > 0. */
676 /* Memory effects: list is destructively modified. */
678 rotate_loop (struct format_arg_list *list, unsigned int m)
680 if (m == list->initial.length)
683 if (list->repeated.count == 1)
685 /* Instead of multiple copies of list->repeated.element[0], a single
686 copy with higher repcount is appended to list->initial. */
689 newcount = list->initial.count + 1;
690 ensure_initial_alloc (list, newcount);
691 i = list->initial.count;
692 copy_element (&list->initial.element[i], &list->repeated.element[0]);
693 list->initial.element[i].repcount = m - list->initial.length;
694 list->initial.count = newcount;
695 list->initial.length = m;
699 unsigned int n = list->repeated.length;
701 /* Write m = list->initial.length + q * n + r with 0 <= r < n. */
702 unsigned int q = (m - list->initial.length) / n;
703 unsigned int r = (m - list->initial.length) % n;
705 /* Determine how many entries of list->repeated are needed for
711 s < list->repeated.count && t >= list->repeated.element[s].repcount;
712 t -= list->repeated.element[s].repcount, s++)
715 /* s must be < list->repeated.count, otherwise r would have been >= n. */
716 ASSERT (s < list->repeated.count);
718 /* So we need to add to list->initial:
719 q full copies of list->repeated,
720 plus the s first elements of list->repeated,
721 plus, if t > 0, a splitoff of list->repeated.element[s]. */
725 i = list->initial.count;
726 newcount = i + q * list->repeated.count + s + (t > 0 ? 1 : 0);
727 ensure_initial_alloc (list, newcount);
729 for (j = 0; j < list->repeated.count; j++, i++)
730 copy_element (&list->initial.element[i],
731 &list->repeated.element[j]);
733 copy_element (&list->initial.element[i], &list->repeated.element[j]);
736 copy_element (&list->initial.element[i],
737 &list->repeated.element[j]);
738 list->initial.element[i].repcount = t;
742 list->initial.count = newcount;
744 = list->initial.length
745 + q * list->repeated.length
746 + list->repeated[0..s-1].repcount + t
747 = list->initial.length + q * n + r
750 list->initial.length = m;
753 /* And rotate list->repeated. */
759 oldcount = list->repeated.count;
760 newcount = list->repeated.count + (t > 0 ? 1 : 0);
764 newelement[i] = list->repeated.element[j];
766 newelement[i] = list->repeated.element[j];
773 free (list->repeated.element);
774 list->repeated.element = newelement;
781 i.e. if 0 < n < list->initial.length, then n-1 and n are covered by two
783 /* Memory effects: list is destructively modified. */
785 initial_splitelement (struct format_arg_list *list, unsigned int n)
793 VERIFY_LIST (list);
795 if (n > list->initial.length)
797 ASSERT (list->repeated.count > 0);
798 rotate_loop (list, n);
799 ASSERT (n <= list->initial.length);
802 /* Determine how many entries of list->initial need to be skipped. */
804 s < list->initial.count && t >= list->initial.element[s].repcount;
805 t -= list->initial.element[s].repcount, s++)
811 ASSERT (s < list->initial.count);
814 oldrepcount = list->initial.element[s].repcount;
815 newcount = list->initial.count + 1;
816 ensure_initial_alloc (list, newcount);
817 for (i = list->initial.count - 1; i > s; i--)
818 list->initial.element[i+1] = list->initial.element[i];
819 copy_element (&list->initial.element[s+1], &list->initial.element[s]);
820 list->initial.element[s].repcount = t;
821 list->initial.element[s+1].repcount = oldrepcount - t;
822 list->initial.count = newcount;
824 VERIFY_LIST (list);
831 /* Memory effects: list is destructively modified. */
833 initial_unshare (struct format_arg_list *list, unsigned int n)
836 initial_splitelement (list, n);
837 initial_splitelement (list, n + 1);
842 VERIFY_LIST (list);
844 if (n >= list->initial.length)
846 ASSERT (list->repeated.count > 0);
847 rotate_loop (list, n + 1);
848 ASSERT (n < list->initial.length);
851 /* Determine how many entries of list->initial need to be skipped. */
853 s < list->initial.count && t >= list->initial.element[s].repcount;
854 t -= list->initial.element[s].repcount, s++)
857 /* s must be < list->initial.count. */
858 ASSERT (s < list->initial.count);
860 if (list->initial.element[s].repcount > 1)
864 unsigned int oldrepcount = list->initial.element[s].repcount;
866 list->initial.count + (t == 0 || t == oldrepcount - 1 ? 1 : 2);
867 ensure_initial_alloc (list, newcount);
872 for (i = list->initial.count - 1; i > s; i--)
873 list->initial.element[i+1] = list->initial.element[i];
874 copy_element (&list->initial.element[s+1], &list->initial.element[s]);
877 list->initial.element[s].repcount = 1;
878 list->initial.element[s+1].repcount = oldrepcount - 1;
882 list->initial.element[s].repcount = oldrepcount - 1;
883 list->initial.element[s+1].repcount = 1;
890 for (i = list->initial.count - 1; i > s; i--)
891 list->initial.element[i+2] = list->initial.element[i];
892 copy_element (&list->initial.element[s+2], &list->initial.element[s]);
893 copy_element (&list->initial.element[s+1], &list->initial.element[s]);
894 list->initial.element[s].repcount = t;
895 list->initial.element[s+1].repcount = 1;
896 list->initial.element[s+2].repcount = oldrepcount - 1 - t;
898 list->initial.count = newcount;
904 ASSERT (list->initial.element[s].repcount == 1);
906 VERIFY_LIST (list);
912 /* Add n unconstrained elements at the front of the list. */
913 /* Memory effects: list is destructively modified. */
915 shift_list (struct format_arg_list *list, unsigned int n)
917 VERIFY_LIST (list);
923 grow_initial_alloc (list);
924 for (i = list->initial.count; i > 0; i--)
925 list->initial.element[i] = list->initial.element[i-1];
926 list->initial.element[0].repcount = n;
927 list->initial.element[0].presence = FCT_REQUIRED;
928 list->initial.element[0].type = FAT_OBJECT;
929 list->initial.count++;
930 list->initial.length += n;
932 normalize_outermost_list (list);
935 VERIFY_LIST (list);
961 re->list = copy_list (e2->list);
967 re->list = copy_list (e1->list);
975 re->list = make_intersection_with_empty_list (e1->list);
976 if (re->list == NULL)
985 re->list = make_intersection_with_empty_list (e2->list);
986 if (re->list == NULL)
1040 re->list = make_intersected_list (copy_list (e1->list),
1041 copy_list (e2->list));
1042 if (re->list == NULL)
1054 /* Append list->repeated to list->initial, and clear list->repeated. */
1055 /* Memory effects: list is destructively modified. */
1057 append_repeated_to_initial (struct format_arg_list *list)
1059 if (list->repeated.count > 0)
1061 /* Move list->repeated over to list->initial. */
1064 newcount = list->initial.count + list->repeated.count;
1065 ensure_initial_alloc (list, newcount);
1066 i = list->initial.count;
1067 for (j = 0; j < list->repeated.count; j++, i++)
1068 list->initial.element[i] = list->repeated.element[j];
1069 list->initial.count = newcount;
1070 list->initial.length = list->initial.length + list->repeated.length;
1071 free (list->repeated.element);
1072 list->repeated.element = NULL;
1073 list->repeated.allocated = 0;
1074 list->repeated.count = 0;
1075 list->repeated.length = 0;
1080 The list consists only of an initial segment. The repeated segment is
1082 list at this point, or - if none is found - returns NULL. */
1083 /* Memory effects: list is destructively modified. If NULL is returned,
1084 list is freed. */
1086 backtrack_in_initial (struct format_arg_list *list)
1088 ASSERT (list->repeated.count == 0);
1090 while (list->initial.count > 0)
1092 unsigned int i = list->initial.count - 1;
1093 if (list->initial.element[i].presence == FCT_REQUIRED)
1096 list->initial.length -= list->initial.element[i].repcount;
1097 free_element (&list->initial.element[i]);
1098 list->initial.count = i;
1100 else /* list->initial.element[i].presence == FCT_OPTIONAL */
1102 /* The list must end here. */
1103 list->initial.length--;
1104 if (list->initial.element[i].repcount > 1)
1105 list->initial.element[i].repcount--;
1108 free_element (&list->initial.element[i]);
1109 list->initial.count = i;
1111 VERIFY_LIST (list);
1112 return list;
1116 free_list (list);
1120 /* Create the intersection (i.e. combined constraints) of two argument list
1200 /* If re->presence == FCT_OPTIONAL, the result list ends here. */
1245 /* Intersecting a finite and an infinite list. */
1255 /* Intersecting an infinite and a finite list. */
1290 /* If re->presence == FCT_OPTIONAL, the result list ends here. */
1330 /* Create the intersection of an argument list and the empty list.
1334 make_intersection_with_empty_list (struct format_arg_list *list)
1337 return make_intersected_list (copy_list (list), make_empty_list ());
1339 if (list->initial.count > 0
1340 ? list->initial.element[0].presence == FCT_REQUIRED
1341 : list->repeated.count > 0
1342 && list->repeated.element[0].presence == FCT_REQUIRED)
1351 /* Create the intersection of two argument list constraints. NULL stands
1402 re->list = make_union_list (copy_list (e1->list),
1403 copy_list (e2->list));
1451 else if (e1->type == FAT_LIST && is_empty_list (e1->list))
1464 else if (e2->type == FAT_LIST && is_empty_list (e2->list))
1494 /* Create the union (i.e. alternative constraints) of two argument list
1767 /* Create the union of an argument list and the empty list. */
1768 /* Memory effects: list is freed. The result is freshly allocated. */
1770 make_union_with_empty_list (struct format_arg_list *list)
1773 return make_union_list (list, make_empty_list ());
1775 VERIFY_LIST (list);
1777 if (list->initial.count > 0
1778 ? list->initial.element[0].presence == FCT_REQUIRED
1779 : list->repeated.count > 0
1780 && list->repeated.element[0].presence == FCT_REQUIRED)
1782 initial_splitelement (list, 1);
1783 ASSERT (list->initial.count > 0);
1784 ASSERT (list->initial.element[0].repcount == 1);
1785 ASSERT (list->initial.element[0].presence == FCT_REQUIRED);
1786 list->initial.element[0].presence = FCT_OPTIONAL;
1788 /* We might need to merge list->initial.element[0] and
1789 list->initial.element[1]. */
1790 normalize_outermost_list (list);
1793 VERIFY_LIST (list);
1795 return list;
1800 /* Create the union of two argument list constraints. NULL stands for an
1827 /* Test whether arguments 0..n are required arguments in a list. */
1829 is_required (const struct format_arg_list *list, unsigned int n)
1837 /* Walk the list->initial segment. */
1839 s < list->initial.count && t >= list->initial.element[s].repcount;
1840 t -= list->initial.element[s].repcount, s++)
1841 if (list->initial.element[s].presence != FCT_REQUIRED)
1847 if (s < list->initial.count)
1849 if (list->initial.element[s].presence != FCT_REQUIRED)
1855 /* Walk the list->repeated segment. */
1856 if (list->repeated.count == 0)
1860 s < list->repeated.count && t >= list->repeated.element[s].repcount;
1861 t -= list->repeated.element[s].repcount, s++)
1862 if (list->repeated.element[s].presence != FCT_REQUIRED)
1868 if (s < list->repeated.count)
1870 if (list->repeated.element[s].presence != FCT_REQUIRED)
1876 /* The list->repeated segment consists only of FCT_REQUIRED. So,
1877 regardless how many more passes through list->repeated would be
1883 /* Add a constraint to an argument list, namely that the arguments 0...n are
1885 /* Memory effects: list is freed. The result is freshly allocated. */
1887 add_required_constraint (struct format_arg_list *list, unsigned int n)
1891 if (list == NULL)
1894 VERIFY_LIST (list);
1896 if (list->repeated.count == 0 && list->initial.length <= n)
1898 /* list is already constrained to have at most length n.
1900 free_list (list);
1904 initial_splitelement (list, n + 1);
1908 list->initial.element[i].presence = FCT_REQUIRED;
1909 rest -= list->initial.element[i].repcount;
1913 VERIFY_LIST (list);
1915 return list;
1919 /* Add a constraint to an argument list, namely that the argument n is
1922 /* Memory effects: list is freed. The result is freshly allocated. */
1924 add_end_constraint (struct format_arg_list *list, unsigned int n)
1929 if (list == NULL)
1932 VERIFY_LIST (list);
1934 if (list->repeated.count == 0 && list->initial.length <= n)
1935 /* list is already constrained to have at most length n. */
1936 return list;
1938 s = initial_splitelement (list, n);
1940 (s < list->initial.count
1941 ? /* n < list->initial.length */ list->initial.element[s].presence
1942 : /* n >= list->initial.length */ list->repeated.element[0].presence);
1944 for (i = s; i < list->initial.count; i++)
1946 list->initial.length -= list->initial.element[i].repcount;
1947 free_element (&list->initial.element[i]);
1949 list->initial.count = s;
1951 for (i = 0; i < list->repeated.count; i++)
1952 free_element (&list->repeated.element[i]);
1953 if (list->repeated.element != NULL)
1954 free (list->repeated.element);
1955 list->repeated.element = NULL;
1956 list->repeated.allocated = 0;
1957 list->repeated.count = 0;
1958 list->repeated.length = 0;
1961 return backtrack_in_initial (list);
1963 return list;
1967 /* Add a constraint to an argument list, namely that the argument n is
1969 contradiction. Assumes a preceding add_required_constraint (list, n). */
1970 /* Memory effects: list is freed. The result is freshly allocated. */
1972 add_type_constraint (struct format_arg_list *list, unsigned int n,
1979 if (list == NULL)
1983 list->initial.length >= n+1. */
1985 s = initial_unshare (list, n);
1990 &list->initial.element[s], &newconstraint))
1991 return add_end_constraint (list, n);
1992 free_element (&list->initial.element[s]);
1993 list->initial.element[s].type = tmpelement.type;
1994 list->initial.element[s].list = tmpelement.list;
1996 VERIFY_LIST (list);
1998 return list;
2002 /* Add a constraint to an argument list, namely that the argument n is
2003 of a given list type. NULL stands for an impossible situation, i.e. a
2004 contradiction. Assumes a preceding add_required_constraint (list, n). */
2005 /* Memory effects: list is freed. The result is freshly allocated. */
2007 add_listtype_constraint (struct format_arg_list *list, unsigned int n,
2015 if (list == NULL)
2019 list->initial.length >= n+1. */
2021 s = initial_unshare (list, n);
2025 newconstraint.list = sublist;
2027 &list->initial.element[s], &newconstraint))
2028 return add_end_constraint (list, n);
2029 free_element (&list->initial.element[s]);
2030 list->initial.element[s].type = tmpelement.type;
2031 list->initial.element[s].list = tmpelement.list;
2033 VERIFY_LIST (list);
2035 return list;
2060 /* Create an endless repeated list whose elements are lists constrained
2067 /* The list cannot have a single element. */
2085 listlist->repeated.element[0].list = sublist;
2095 /* Create an endless repeated list which represents the union of a finite
2110 struct format_arg_list *list;
2120 /* L is a finite list. */
2132 /* L is an infinite list. */
2169 list = XMALLOC (struct format_arg_list);
2170 list->initial.count = 0;
2171 list->initial.allocated = 0;
2172 list->initial.element = NULL;
2173 list->initial.length = 0;
2174 list->repeated.count = 0;
2175 list->repeated.allocated = 0;
2176 list->repeated.element = NULL;
2177 list->repeated.length = 0;
2181 list->initial.element[i] = srcseg->element[i];
2182 list->initial.element[0].presence = FCT_OPTIONAL; // union with empty list
2184 list->initial.element[i] = srcseg->element[i] & list->initial.element[j];
2194 /* Ensure room in list->initial. */
2195 grow_initial_alloc (list);
2196 copy_element (&list->initial.element[list->initial.count],
2198 list->initial.element[list->initial.count].repcount = k;
2199 list->initial.count++;
2200 list->initial.length += k;
2211 ASSERT (list->initial.count > 0);
2212 if (list->initial.element[0].presence == FCT_REQUIRED)
2214 initial_splitelement (list, 1);
2215 ASSERT (list->initial.element[0].presence == FCT_REQUIRED);
2216 ASSERT (list->initial.element[0].repcount == 1);
2217 list->initial.element[0].presence = FCT_OPTIONAL;
2225 list->initial.element[sj].repcount - tj);
2227 /* Ensure room in list->initial. */
2228 grow_initial_alloc (list);
2229 if (!make_intersected_element (&list->initial.element[list->initial.count],
2231 &list->initial.element[sj]))
2233 if (list->initial.element[list->initial.count].presence == FCT_REQUIRED)
2236 list = backtrack_in_initial (list);
2237 ASSERT (list != NULL); /* at least the empty list is valid */
2238 return list;
2242 /* The list ends here. */
2247 list->initial.element[list->initial.count].repcount = k;
2248 list->initial.count++;
2249 list->initial.length += k;
2261 if (tj == list->initial.element[sj].repcount)
2268 ASSERT (list->initial.length == n);
2272 for (i = 0; i < list->initial.length; i += period)
2274 si = initial_unshare (list, i);
2275 list->initial.element[si].presence = FCT_OPTIONAL;
2281 splitindex = initial_splitelement (list, n - p);
2282 newcount = list->initial.count - splitindex;
2283 if (newcount > list->repeated.allocated)
2285 list->repeated.allocated = newcount;
2286 list->repeated.element = XNMALLOC (newcount, struct format_arg);
2289 list->repeated.element[j] = list->initial.element[i];
2290 list->repeated.count = newcount;
2291 list->repeated.length = p;
2292 list->initial.count = splitindex;
2293 list->initial.length = n - p;
2296 VERIFY_LIST (list);
2298 return list;
2337 list. Return false and fill in *invalid_reason if the format string is
2427 position is the position in this argument list, if known, or -1 if unknown.
2428 list represents the argument list constraints at the current parse point.
2430 escape represents the union of the argument list constraints at all the
2452 struct format_arg_list *list = *listp;
2575 if (!check_params (&list, paramcount, params, 4, IIIC,
2582 add_req_type_constraint (&list, position++, FAT_OBJECT);
2586 if (!check_params (&list, paramcount, params, 1, I,
2595 add_req_type_constraint (&list, position++, FAT_CHARACTER);
2602 if (!check_params (&list, paramcount, params, 4, ICCI,
2609 add_req_type_constraint (&list, position++, FAT_INTEGER);
2613 if (!check_params (&list, paramcount, params, 5, IICCI,
2620 add_req_type_constraint (&list, position++, FAT_INTEGER);
2624 if (!check_params (&list, paramcount, params, 0, NULL,
2637 add_req_type_constraint (&list, position++, FAT_OBJECT);
2641 if (!check_params (&list, paramcount, params, 5, IIICC,
2648 add_req_type_constraint (&list, position++, FAT_REAL);
2653 if (!check_params (&list, paramcount, params, 7, IIIICCC,
2660 add_req_type_constraint (&list, position++, FAT_REAL);
2664 if (!check_params (&list, paramcount, params, 4, IIIC,
2671 add_req_type_constraint (&list, position++, FAT_REAL);
2675 if (!check_params (&list, paramcount, params, 5, IIICC,
2682 add_req_type_constraint (&list, position++, FAT_COMPLEX);
2686 if (!check_params (&list, paramcount, params, 0, NULL,
2693 add_req_type_constraint (&list, position++, FAT_OBJECT);
2702 if (!check_params (&list, paramcount, params, 1, I,
2713 if (!check_params (&list, paramcount, params, 0, NULL,
2722 if (!check_params (&list, paramcount, params, 3, IIC,
2731 if (!check_params (&list, paramcount, params, 1, I,
2789 if (!check_params (&list, paramcount, params, 0, NULL,
2796 add_req_type_constraint (&list, position++, FAT_FORMATSTRING);
2803 add_req_listtype_constraint (&list, position++,
2810 if (!check_params (&list, paramcount, params, 0, NULL,
2818 *listp = list;
2832 list = *listp;
2844 if (!check_params (&list, paramcount, params, 0, NULL,
2852 *listp = list;
2869 if (!check_params (&list, paramcount, params, 0, NULL,
2880 nil_list = (list != NULL ? copy_list (list) : NULL);
2893 (list != NULL ? copy_list (list) : NULL);
2925 if (list != NULL)
2926 free_list (list);
2927 list = union_list;
2934 if (!check_params (&list, paramcount, params, 0, NULL,
2942 add_req_type_constraint (&list, position++, FAT_OBJECT);
2953 (list != NULL ? copy_list (list) : NULL);
2987 (list != NULL ? copy_list (list) : NULL);
3012 if (list != NULL)
3013 free_list (list);
3014 list = union_list;
3023 if (!check_params (&list, paramcount, params, 1, I,
3036 add_req_type_constraint (&list, position++, FAT_OBJECT);
3050 (list != NULL ? copy_list (list) : NULL);
3086 if (list != NULL)
3087 union_list = union (union_list, copy_list (list));
3095 if (list != NULL)
3096 free_list (list);
3097 list = union_list;
3109 if (!check_params (&list, paramcount, params, 0, NULL,
3117 *listp = list;
3122 if (!check_params (&list, paramcount, params, 1, I,
3135 sub_spec.list = sub_list;
3150 add_req_type_constraint (&list, position++, FAT_FORMATSTRING);
3167 single list. */
3200 if (list != NULL && position >= 0)
3203 list = make_intersected_list (list, sub_list);
3209 /* The argument is a list. */
3211 add_req_listtype_constraint (&list, position++,
3226 if (!check_params (&list, paramcount, params, 0, NULL,
3234 *listp = list;
3239 if (!check_params (&list, paramcount, params, 3, THREE,
3245 if (position >= 0 && list != NULL && is_required (list, position))
3248 if (list != NULL)
3250 struct format_arg_list *this_escape = copy_list (list);
3256 list = add_required_constraint (list, position);
3269 if (!check_params (&list, paramcount, params, 1, I,
3278 if (!check_params (&list, paramcount, params, 0, NULL,
3287 *listp = list;
3315 *listp = list;
3339 spec.list = make_unconstrained_list ();
3342 if (!parse_upto (&format, &position, &spec.list, &escape,
3349 spec.list = union (spec.list, escape);
3351 if (spec.list == NULL)
3360 normalize_list (spec.list);
3372 free_list (spec->list);
3394 if (!equal_list (spec1->list, spec2->list))
3405 make_intersected_list (copy_list (spec1->list),
3406 copy_list (spec2->list));
3410 equal_list (intersection, spec2->list))))
3439 /* Test program: Print the argument list specification returned by
3444 static void print_list (struct format_arg_list *list);
3487 print_list (element->list);
3498 print_list (struct format_arg_list *list)
3504 for (i = 0; i < list->initial.count; i++)
3505 for (j = 0; j < list->initial.element[i].repcount; j++)
3509 print_element (&list->initial.element[i]);
3512 if (list->repeated.count > 0)
3515 for (i = 0; i < list->repeated.count; i++)
3516 for (j = 0; j < list->repeated.element[i].repcount; j++)
3519 print_element (&list->repeated.element[i]);
3537 print_list (spec->list);