• 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

39 #define VERIFY_LIST(list) verify_list (list)
46 argument list. It is a recursive list structure. Structure sharing
51 FCT_REQUIRED, /* The format argument list cannot end before this argument. */
52 FCT_OPTIONAL /* The format argument list may end before this argument. */
74 enum format_cdr_type presence; /* Can the argument list end right before
77 struct format_arg_list *list; /* For FAT_LIST: List elements. */
91 /* The constraints for the potentially infinite argument list are assumed
108 struct format_arg_list *list;
119 PT_V /* variable taken from argument list */
131 static void verify_list (const struct format_arg_list *list);
132 static void free_list (struct format_arg_list *list);
133 static struct format_arg_list * copy_list (const struct format_arg_list *list);
140 (struct format_arg_list *list);
154 verify_list (e->list);
160 verify_list (const struct format_arg_list *list)
165 ASSERT (list->initial.count <= list->initial.allocated);
167 for (i = 0; i < list->initial.count; i++)
169 verify_element (&list->initial.element[i]);
170 total_repcount += list->initial.element[i].repcount;
172 ASSERT (total_repcount == list->initial.length);
174 ASSERT (list->repeated.count <= list->repeated.allocated);
176 for (i = 0; i < list->repeated.count; i++)
178 verify_element (&list->repeated.element[i]);
179 total_repcount += list->repeated.element[i].repcount;
181 ASSERT (total_repcount == list->repeated.length);
184 #define VERIFY_LIST(list) verify_list (list)
189 /* Free the data belonging to an argument list element. */
194 free_list (element->list);
197 /* Free an argument list. */
198 /* Memory effects: Frees list. */
200 free_list (struct format_arg_list *list)
204 for (i = 0; i < list->initial.count; i++)
205 free_element (&list->initial.element[i]);
206 if (list->initial.element != NULL)
207 free (list->initial.element);
209 for (i = 0; i < list->repeated.count; i++)
210 free_element (&list->repeated.element[i]);
211 if (list->repeated.element != NULL)
212 free (list->repeated.element);
218 /* Copy the data belonging to an argument list element. */
227 newelement->list = copy_list (oldelement->list);
230 /* Copy an argument list. */
233 copy_list (const struct format_arg_list *list)
239 VERIFY_LIST (list);
243 newlist->initial.count = newlist->initial.allocated = list->initial.count;
245 if (list->initial.count == 0)
251 for (i = 0; i < list->initial.count; i++)
254 &list->initial.element[i]);
255 length += list->initial.element[i].repcount;
258 ASSERT (length == list->initial.length);
261 newlist->repeated.count = newlist->repeated.allocated = list->repeated.count;
263 if (list->repeated.count == 0)
269 for (i = 0; i < list->repeated.count; i++)
272 &list->repeated.element[i]);
273 length += list->repeated.element[i].repcount;
276 ASSERT (length == list->repeated.length);
294 && (e1->type == FAT_LIST ? equal_list (e1->list, e2->list) : true));
297 /* Tests whether two normalized argument list constraints are equivalent. */
338 /* Ensure list->initial.allocated >= newcount. */
340 ensure_initial_alloc (struct format_arg_list *list, unsigned int newcount)
342 if (newcount > list->initial.allocated)
344 list->initial.allocated =
345 MAX (2 * list->initial.allocated + 1, newcount);
346 list->initial.element =
348 xrealloc (list->initial.element,
349 list->initial.allocated * sizeof (struct format_arg));
353 /* Ensure list->initial.allocated > list->initial.count. */
355 grow_initial_alloc (struct format_arg_list *list)
357 if (list->initial.count >= list->initial.allocated)
359 list->initial.allocated =
360 MAX (2 * list->initial.allocated + 1, list->initial.count + 1);
361 list->initial.element =
363 xrealloc (list->initial.element,
364 list->initial.allocated * sizeof (struct format_arg));
368 /* Ensure list->repeated.allocated >= newcount. */
370 ensure_repeated_alloc (struct format_arg_list *list, unsigned int newcount)
372 if (newcount > list->repeated.allocated)
374 list->repeated.allocated =
375 MAX (2 * list->repeated.allocated + 1, newcount);
376 list->repeated.element =
378 xrealloc (list->repeated.element,
379 list->repeated.allocated * sizeof (struct format_arg));
383 /* Ensure list->repeated.allocated > list->repeated.count. */
385 grow_repeated_alloc (struct format_arg_list *list)
387 if (list->repeated.count >= list->repeated.allocated)
389 list->repeated.allocated =
390 MAX (2 * list->repeated.allocated + 1, list->repeated.count + 1);
391 list->repeated.element =
393 xrealloc (list->repeated.element,
394 list->repeated.allocated * sizeof (struct format_arg));
401 /* Normalize an argument list constraint, assuming all sublists are already
403 /* Memory effects: Destructively modifies list. */
405 normalize_outermost_list (struct format_arg_list *list)
412 n = list->initial.count;
415 && equal_element (&list->initial.element[i],
416 &list->initial.element[j-1]))
418 list->initial.element[j-1].repcount +=
419 list->initial.element[i].repcount;
420 free_element (&list->initial.element[i]);
425 list->initial.element[j] = list->initial.element[i];
428 list->initial.count = j;
430 n = list->repeated.count;
433 && equal_element (&list->repeated.element[i],
434 &list->repeated.element[j-1]))
436 list->repeated.element[j-1].repcount +=
437 list->repeated.element[i].repcount;
438 free_element (&list->repeated.element[i]);
443 list->repeated.element[j] = list->repeated.element[i];
446 list->repeated.count = j;
449 if (list->repeated.count > 0)
454 n = list->repeated.count;
457 && equal_element (&list->repeated.element[0],
458 &list->repeated.element[n-1]))
460 repcount0_extra = list->repeated.element[n-1].repcount;
464 list->repeated.element[0].repcount incremented by repcount0_extra. */
472 if (!((list->repeated.element[i].repcount
474 == list->repeated.element[i+m].repcount)
475 && equal_element (&list->repeated.element[i],
476 &list->repeated.element[i+m])))
484 free_element (&list->repeated.element[i]);
485 if (n < list->repeated.count)
486 list->repeated.element[m] = list->repeated.element[n];
487 list->repeated.count = list->repeated.count - n + m;
488 list->repeated.length /= n / m;
495 if (list->repeated.count == 1)
497 if (list->initial.count > 0
498 && equal_element (&list->initial.element[list->initial.count-1],
499 &list->repeated.element[0]))
504 list->initial.length -=
505 list->initial.element[list->initial.count-1].repcount;
506 list->initial.count--;
511 while (list->initial.count > 0
512 && equal_element (&list->initial.element[list->initial.count-1],
513 &list->repeated.element[list->repeated.count-1]))
516 MIN (list->initial.element[list->initial.count-1].repcount,
517 list->repeated.element[list->repeated.count-1].repcount);
519 /* Add the element at the start of list->repeated. */
520 if (equal_element (&list->repeated.element[0],
521 &list->repeated.element[list->repeated.count-1]))
522 list->repeated.element[0].repcount += moved_repcount;
525 unsigned int newcount = list->repeated.count + 1;
526 ensure_repeated_alloc (list, newcount);
528 list->repeated.element[i] = list->repeated.element[i-1];
529 list->repeated.count = newcount;
530 copy_element (&list->repeated.element[0],
531 &list->repeated.element[list->repeated.count-1]);
532 list->repeated.element[0].repcount = moved_repcount;
535 /* Remove the element from the end of list->repeated. */
536 list->repeated.element[list->repeated.count-1].repcount -=
538 if (list->repeated.element[list->repeated.count-1].repcount == 0)
540 free_element (&list->repeated.element[list->repeated.count-1]);
541 list->repeated.count--;
544 /* Remove the element from the end of list->initial. */
545 list->initial.element[list->initial.count-1].repcount -=
547 if (list->initial.element[list->initial.count-1].repcount == 0)
549 free_element (&list->initial.element[list->initial.count-1]);
550 list->initial.count--;
552 list->initial.length -= moved_repcount;
558 /* Normalize an argument list constraint. */
559 /* Memory effects: Destructively modifies list. */
561 normalize_list (struct format_arg_list *list)
565 VERIFY_LIST (list);
568 n = list->initial.count;
570 if (list->initial.element[i].type == FAT_LIST)
571 normalize_list (list->initial.element[i].list);
572 n = list->repeated.count;
574 if (list->repeated.element[i].type == FAT_LIST)
575 normalize_list (list->repeated.element[i].list);
577 /* Then normalize the top level list. */
578 normalize_outermost_list (list);
580 VERIFY_LIST (list);
590 /* Create an unconstrained argument list. */
595 struct format_arg_list *list;
597 list = XMALLOC (struct format_arg_list);
598 list->initial.count = 0;
599 list->initial.allocated = 0;
600 list->initial.element = NULL;
601 list->initial.length = 0;
602 list->repeated.count = 1;
603 list->repeated.allocated = 1;
604 list->repeated.element = XNMALLOC (1, struct format_arg);
605 list->repeated.element[0].repcount = 1;
606 list->repeated.element[0].presence = FCT_OPTIONAL;
607 list->repeated.element[0].type = FAT_OBJECT;
608 list->repeated.length = 1;
610 VERIFY_LIST (list);
612 return list;
616 /* Create an empty argument list. */
621 struct format_arg_list *list;
623 list = XMALLOC (struct format_arg_list);
624 list->initial.count = 0;
625 list->initial.allocated = 0;
626 list->initial.element = NULL;
627 list->initial.length = 0;
628 list->repeated.count = 0;
629 list->repeated.allocated = 0;
630 list->repeated.element = NULL;
631 list->repeated.length = 0;
633 VERIFY_LIST (list);
635 return list;
639 /* Test for an empty list. */
642 is_empty_list (const struct format_arg_list *list)
644 return (list->initial.count == 0 && list->repeated.count == 0);
650 /* Unfold list->repeated m times, where m >= 1.
651 Assumes list->repeated.count > 0. */
652 /* Memory effects: list is destructively modified. */
654 unfold_loop (struct format_arg_list *list, unsigned int m)
660 unsigned int newcount = list->repeated.count * m;
661 ensure_repeated_alloc (list, newcount);
662 i = list->repeated.count;
664 for (j = 0; j < list->repeated.count; j++, i++)
665 copy_element (&list->repeated.element[i], &list->repeated.element[j]);
666 list->repeated.count = newcount;
667 list->repeated.length = list->repeated.length * m;
671 /* Ensure list->initial.length := m, where m >= list->initial.length.
672 Assumes list->repeated.count > 0. */
673 /* Memory effects: list is destructively modified. */
675 rotate_loop (struct format_arg_list *list, unsigned int m)
677 if (m == list->initial.length)
680 if (list->repeated.count == 1)
682 /* Instead of multiple copies of list->repeated.element[0], a single
683 copy with higher repcount is appended to list->initial. */
686 newcount = list->initial.count + 1;
687 ensure_initial_alloc (list, newcount);
688 i = list->initial.count;
689 copy_element (&list->initial.element[i], &list->repeated.element[0]);
690 list->initial.element[i].repcount = m - list->initial.length;
691 list->initial.count = newcount;
692 list->initial.length = m;
696 unsigned int n = list->repeated.length;
698 /* Write m = list->initial.length + q * n + r with 0 <= r < n. */
699 unsigned int q = (m - list->initial.length) / n;
700 unsigned int r = (m - list->initial.length) % n;
702 /* Determine how many entries of list->repeated are needed for
708 s < list->repeated.count && t >= list->repeated.element[s].repcount;
709 t -= list->repeated.element[s].repcount, s++)
712 /* s must be < list->repeated.count, otherwise r would have been >= n. */
713 ASSERT (s < list->repeated.count);
715 /* So we need to add to list->initial:
716 q full copies of list->repeated,
717 plus the s first elements of list->repeated,
718 plus, if t > 0, a splitoff of list->repeated.element[s]. */
722 i = list->initial.count;
723 newcount = i + q * list->repeated.count + s + (t > 0 ? 1 : 0);
724 ensure_initial_alloc (list, newcount);
726 for (j = 0; j < list->repeated.count; j++, i++)
727 copy_element (&list->initial.element[i],
728 &list->repeated.element[j]);
730 copy_element (&list->initial.element[i], &list->repeated.element[j]);
733 copy_element (&list->initial.element[i],
734 &list->repeated.element[j]);
735 list->initial.element[i].repcount = t;
739 list->initial.count = newcount;
741 = list->initial.length
742 + q * list->repeated.length
743 + list->repeated[0..s-1].repcount + t
744 = list->initial.length + q * n + r
747 list->initial.length = m;
750 /* And rotate list->repeated. */
756 oldcount = list->repeated.count;
757 newcount = list->repeated.count + (t > 0 ? 1 : 0);
761 newelement[i] = list->repeated.element[j];
763 newelement[i] = list->repeated.element[j];
770 free (list->repeated.element);
771 list->repeated.element = newelement;
778 i.e. if 0 < n < list->initial.length, then n-1 and n are covered by two
780 /* Memory effects: list is destructively modified. */
782 initial_splitelement (struct format_arg_list *list, unsigned int n)
790 VERIFY_LIST (list);
792 if (n > list->initial.length)
794 ASSERT (list->repeated.count > 0);
795 rotate_loop (list, n);
796 ASSERT (n <= list->initial.length);
799 /* Determine how many entries of list->initial need to be skipped. */
801 s < list->initial.count && t >= list->initial.element[s].repcount;
802 t -= list->initial.element[s].repcount, s++)
808 ASSERT (s < list->initial.count);
811 oldrepcount = list->initial.element[s].repcount;
812 newcount = list->initial.count + 1;
813 ensure_initial_alloc (list, newcount);
814 for (i = list->initial.count - 1; i > s; i--)
815 list->initial.element[i+1] = list->initial.element[i];
816 copy_element (&list->initial.element[s+1], &list->initial.element[s]);
817 list->initial.element[s].repcount = t;
818 list->initial.element[s+1].repcount = oldrepcount - t;
819 list->initial.count = newcount;
821 VERIFY_LIST (list);
828 /* Memory effects: list is destructively modified. */
830 initial_unshare (struct format_arg_list *list, unsigned int n)
833 initial_splitelement (list, n);
834 initial_splitelement (list, n + 1);
839 VERIFY_LIST (list);
841 if (n >= list->initial.length)
843 ASSERT (list->repeated.count > 0);
844 rotate_loop (list, n + 1);
845 ASSERT (n < list->initial.length);
848 /* Determine how many entries of list->initial need to be skipped. */
850 s < list->initial.count && t >= list->initial.element[s].repcount;
851 t -= list->initial.element[s].repcount, s++)
854 /* s must be < list->initial.count. */
855 ASSERT (s < list->initial.count);
857 if (list->initial.element[s].repcount > 1)
861 unsigned int oldrepcount = list->initial.element[s].repcount;
863 list->initial.count + (t == 0 || t == oldrepcount - 1 ? 1 : 2);
864 ensure_initial_alloc (list, newcount);
869 for (i = list->initial.count - 1; i > s; i--)
870 list->initial.element[i+1] = list->initial.element[i];
871 copy_element (&list->initial.element[s+1], &list->initial.element[s]);
874 list->initial.element[s].repcount = 1;
875 list->initial.element[s+1].repcount = oldrepcount - 1;
879 list->initial.element[s].repcount = oldrepcount - 1;
880 list->initial.element[s+1].repcount = 1;
887 for (i = list->initial.count - 1; i > s; i--)
888 list->initial.element[i+2] = list->initial.element[i];
889 copy_element (&list->initial.element[s+2], &list->initial.element[s]);
890 copy_element (&list->initial.element[s+1], &list->initial.element[s]);
891 list->initial.element[s].repcount = t;
892 list->initial.element[s+1].repcount = 1;
893 list->initial.element[s+2].repcount = oldrepcount - 1 - t;
895 list->initial.count = newcount;
901 ASSERT (list->initial.element[s].repcount == 1);
903 VERIFY_LIST (list);
909 /* Add n unconstrained elements at the front of the list. */
910 /* Memory effects: list is destructively modified. */
912 shift_list (struct format_arg_list *list, unsigned int n)
914 VERIFY_LIST (list);
920 grow_initial_alloc (list);
921 for (i = list->initial.count; i > 0; i--)
922 list->initial.element[i] = list->initial.element[i-1];
923 list->initial.element[0].repcount = n;
924 list->initial.element[0].presence = FCT_REQUIRED;
925 list->initial.element[0].type = FAT_OBJECT;
926 list->initial.count++;
927 list->initial.length += n;
929 normalize_outermost_list (list);
932 VERIFY_LIST (list);
958 re->list = copy_list (e2->list);
964 re->list = copy_list (e1->list);
972 re->list = make_intersection_with_empty_list (e1->list);
973 if (re->list == NULL)
982 re->list = make_intersection_with_empty_list (e2->list);
983 if (re->list == NULL)
1027 re->list = make_intersected_list (copy_list (e1->list),
1028 copy_list (e2->list));
1029 if (re->list == NULL)
1041 /* Append list->repeated to list->initial, and clear list->repeated. */
1042 /* Memory effects: list is destructively modified. */
1044 append_repeated_to_initial (struct format_arg_list *list)
1046 if (list->repeated.count > 0)
1048 /* Move list->repeated over to list->initial. */
1051 newcount = list->initial.count + list->repeated.count;
1052 ensure_initial_alloc (list, newcount);
1053 i = list->initial.count;
1054 for (j = 0; j < list->repeated.count; j++, i++)
1055 list->initial.element[i] = list->repeated.element[j];
1056 list->initial.count = newcount;
1057 list->initial.length = list->initial.length + list->repeated.length;
1058 free (list->repeated.element);
1059 list->repeated.element = NULL;
1060 list->repeated.allocated = 0;
1061 list->repeated.count = 0;
1062 list->repeated.length = 0;
1067 The list consists only of an initial segment. The repeated segment is
1069 list at this point, or - if none is found - returns NULL. */
1070 /* Memory effects: list is destructively modified. If NULL is returned,
1071 list is freed. */
1073 backtrack_in_initial (struct format_arg_list *list)
1075 ASSERT (list->repeated.count == 0);
1077 while (list->initial.count > 0)
1079 unsigned int i = list->initial.count - 1;
1080 if (list->initial.element[i].presence == FCT_REQUIRED)
1083 list->initial.length -= list->initial.element[i].repcount;
1084 free_element (&list->initial.element[i]);
1085 list->initial.count = i;
1087 else /* list->initial.element[i].presence == FCT_OPTIONAL */
1089 /* The list must end here. */
1090 list->initial.length--;
1091 if (list->initial.element[i].repcount > 1)
1092 list->initial.element[i].repcount--;
1095 free_element (&list->initial.element[i]);
1096 list->initial.count = i;
1098 VERIFY_LIST (list);
1099 return list;
1103 free_list (list);
1107 /* Create the intersection (i.e. combined constraints) of two argument list
1187 /* If re->presence == FCT_OPTIONAL, the result list ends here. */
1232 /* Intersecting a finite and an infinite list. */
1242 /* Intersecting an infinite and a finite list. */
1277 /* If re->presence == FCT_OPTIONAL, the result list ends here. */
1317 /* Create the intersection of an argument list and the empty list.
1321 make_intersection_with_empty_list (struct format_arg_list *list)
1324 return make_intersected_list (copy_list (list), make_empty_list ());
1326 if (list->initial.count > 0
1327 ? list->initial.element[0].presence == FCT_REQUIRED
1328 : list->repeated.count > 0
1329 && list->repeated.element[0].presence == FCT_REQUIRED)
1338 /* Create the intersection of two argument list constraints. NULL stands
1389 re->list = make_union_list (copy_list (e1->list),
1390 copy_list (e2->list));
1428 else if (e1->type == FAT_LIST && is_empty_list (e1->list))
1441 else if (e2->type == FAT_LIST && is_empty_list (e2->list))
1471 /* Create the union (i.e. alternative constraints) of two argument list
1744 /* Create the union of an argument list and the empty list. */
1745 /* Memory effects: list is freed. The result is freshly allocated. */
1747 make_union_with_empty_list (struct format_arg_list *list)
1750 return make_union_list (list, make_empty_list ());
1752 VERIFY_LIST (list);
1754 if (list->initial.count > 0
1755 ? list->initial.element[0].presence == FCT_REQUIRED
1756 : list->repeated.count > 0
1757 && list->repeated.element[0].presence == FCT_REQUIRED)
1759 initial_splitelement (list, 1);
1760 ASSERT (list->initial.count > 0);
1761 ASSERT (list->initial.element[0].repcount == 1);
1762 ASSERT (list->initial.element[0].presence == FCT_REQUIRED);
1763 list->initial.element[0].presence = FCT_OPTIONAL;
1765 /* We might need to merge list->initial.element[0] and
1766 list->initial.element[1]. */
1767 normalize_outermost_list (list);
1770 VERIFY_LIST (list);
1772 return list;
1777 /* Create the union of two argument list constraints. NULL stands for an
1804 /* Test whether arguments 0..n are required arguments in a list. */
1806 is_required (const struct format_arg_list *list, unsigned int n)
1814 /* Walk the list->initial segment. */
1816 s < list->initial.count && t >= list->initial.element[s].repcount;
1817 t -= list->initial.element[s].repcount, s++)
1818 if (list->initial.element[s].presence != FCT_REQUIRED)
1824 if (s < list->initial.count)
1826 if (list->initial.element[s].presence != FCT_REQUIRED)
1832 /* Walk the list->repeated segment. */
1833 if (list->repeated.count == 0)
1837 s < list->repeated.count && t >= list->repeated.element[s].repcount;
1838 t -= list->repeated.element[s].repcount, s++)
1839 if (list->repeated.element[s].presence != FCT_REQUIRED)
1845 if (s < list->repeated.count)
1847 if (list->repeated.element[s].presence != FCT_REQUIRED)
1853 /* The list->repeated segment consists only of FCT_REQUIRED. So,
1854 regardless how many more passes through list->repeated would be
1860 /* Add a constraint to an argument list, namely that the arguments 0...n are
1862 /* Memory effects: list is freed. The result is freshly allocated. */
1864 add_required_constraint (struct format_arg_list *list, unsigned int n)
1868 if (list == NULL)
1871 VERIFY_LIST (list);
1873 if (list->repeated.count == 0 && list->initial.length <= n)
1875 /* list is already constrained to have at most length n.
1877 free_list (list);
1881 initial_splitelement (list, n + 1);
1885 list->initial.element[i].presence = FCT_REQUIRED;
1886 rest -= list->initial.element[i].repcount;
1890 VERIFY_LIST (list);
1892 return list;
1896 /* Add a constraint to an argument list, namely that the argument n is
1899 /* Memory effects: list is freed. The result is freshly allocated. */
1901 add_end_constraint (struct format_arg_list *list, unsigned int n)
1906 if (list == NULL)
1909 VERIFY_LIST (list);
1911 if (list->repeated.count == 0 && list->initial.length <= n)
1912 /* list is already constrained to have at most length n. */
1913 return list;
1915 s = initial_splitelement (list, n);
1917 (s < list->initial.count
1918 ? /* n < list->initial.length */ list->initial.element[s].presence
1919 : /* n >= list->initial.length */ list->repeated.element[0].presence);
1921 for (i = s; i < list->initial.count; i++)
1923 list->initial.length -= list->initial.element[i].repcount;
1924 free_element (&list->initial.element[i]);
1926 list->initial.count = s;
1928 for (i = 0; i < list->repeated.count; i++)
1929 free_element (&list->repeated.element[i]);
1930 if (list->repeated.element != NULL)
1931 free (list->repeated.element);
1932 list->repeated.element = NULL;
1933 list->repeated.allocated = 0;
1934 list->repeated.count = 0;
1935 list->repeated.length = 0;
1938 return backtrack_in_initial (list);
1940 return list;
1944 /* Add a constraint to an argument list, namely that the argument n is
1946 contradiction. Assumes a preceding add_required_constraint (list, n). */
1947 /* Memory effects: list is freed. The result is freshly allocated. */
1949 add_type_constraint (struct format_arg_list *list, unsigned int n,
1956 if (list == NULL)
1960 list->initial.length >= n+1. */
1962 s = initial_unshare (list, n);
1967 &list->initial.element[s], &newconstraint))
1968 return add_end_constraint (list, n);
1969 free_element (&list->initial.element[s]);
1970 list->initial.element[s].type = tmpelement.type;
1971 list->initial.element[s].list = tmpelement.list;
1973 VERIFY_LIST (list);
1975 return list;
1979 /* Add a constraint to an argument list, namely that the argument n is
1980 of a given list type. NULL stands for an impossible situation, i.e. a
1981 contradiction. Assumes a preceding add_required_constraint (list, n). */
1982 /* Memory effects: list is freed. The result is freshly allocated. */
1984 add_listtype_constraint (struct format_arg_list *list, unsigned int n,
1992 if (list == NULL)
1996 list->initial.length >= n+1. */
1998 s = initial_unshare (list, n);
2002 newconstraint.list = sublist;
2004 &list->initial.element[s], &newconstraint))
2005 return add_end_constraint (list, n);
2006 free_element (&list->initial.element[s]);
2007 list->initial.element[s].type = tmpelement.type;
2008 list->initial.element[s].list = tmpelement.list;
2010 VERIFY_LIST (list);
2012 return list;
2037 /* Create an endless repeated list whose elements are lists constrained
2044 /* The list cannot have a single element. */
2062 listlist->repeated.element[0].list = sublist;
2072 /* Create an endless repeated list which represents the union of a finite
2087 struct format_arg_list *list;
2097 /* L is a finite list. */
2109 /* L is an infinite list. */
2146 list = XMALLOC (struct format_arg_list);
2147 list->initial.count = 0;
2148 list->initial.allocated = 0;
2149 list->initial.element = NULL;
2150 list->initial.length = 0;
2151 list->repeated.count = 0;
2152 list->repeated.allocated = 0;
2153 list->repeated.element = NULL;
2154 list->repeated.length = 0;
2158 list->initial.element[i] = srcseg->element[i];
2159 list->initial.element[0].presence = FCT_OPTIONAL; // union with empty list
2161 list->initial.element[i] = srcseg->element[i] & list->initial.element[j];
2171 /* Ensure room in list->initial. */
2172 grow_initial_alloc (list);
2173 copy_element (&list->initial.element[list->initial.count],
2175 list->initial.element[list->initial.count].repcount = k;
2176 list->initial.count++;
2177 list->initial.length += k;
2188 ASSERT (list->initial.count > 0);
2189 if (list->initial.element[0].presence == FCT_REQUIRED)
2191 initial_splitelement (list, 1);
2192 ASSERT (list->initial.element[0].presence == FCT_REQUIRED);
2193 ASSERT (list->initial.element[0].repcount == 1);
2194 list->initial.element[0].presence = FCT_OPTIONAL;
2202 list->initial.element[sj].repcount - tj);
2204 /* Ensure room in list->initial. */
2205 grow_initial_alloc (list);
2206 if (!make_intersected_element (&list->initial.element[list->initial.count],
2208 &list->initial.element[sj]))
2210 if (list->initial.element[list->initial.count].presence == FCT_REQUIRED)
2213 list = backtrack_in_initial (list);
2214 ASSERT (list != NULL); /* at least the empty list is valid */
2215 return list;
2219 /* The list ends here. */
2224 list->initial.element[list->initial.count].repcount = k;
2225 list->initial.count++;
2226 list->initial.length += k;
2238 if (tj == list->initial.element[sj].repcount)
2245 ASSERT (list->initial.length == n);
2249 for (i = 0; i < list->initial.length; i += period)
2251 si = initial_unshare (list, i);
2252 list->initial.element[si].presence = FCT_OPTIONAL;
2258 splitindex = initial_splitelement (list, n - p);
2259 newcount = list->initial.count - splitindex;
2260 if (newcount > list->repeated.allocated)
2262 list->repeated.allocated = newcount;
2263 list->repeated.element = XNMALLOC (newcount, struct format_arg);
2266 list->repeated.element[j] = list->initial.element[i];
2267 list->repeated.count = newcount;
2268 list->repeated.length = p;
2269 list->initial.count = splitindex;
2270 list->initial.length = n - p;
2273 VERIFY_LIST (list);
2275 return list;
2311 list. Return false and fill in *invalid_reason if the format string is
2397 For V params, add the constraint to the argument list.
2424 position is the position in this argument list, if known, or -1 if unknown.
2425 list represents the argument list constraints at the current parse point.
2427 escape represents the union of the argument list constraints at all the
2449 struct format_arg_list *list = *listp;
2572 if (!check_params (&list, paramcount, params, 4, IIIC,
2579 add_req_type_constraint (&list, position++, FAT_OBJECT);
2583 if (!check_params (&list, paramcount, params, 0, NULL,
2590 add_req_type_constraint (&list, position++, FAT_OBJECT);
2597 if (!check_params (&list, paramcount, params, 4, ICCI,
2604 add_req_type_constraint (&list, position++, FAT_INTEGER);
2608 if (!check_params (&list, paramcount, params, 5, IICCI,
2615 add_req_type_constraint (&list, position++, FAT_INTEGER);
2619 if (!check_params (&list, paramcount, params, 0, NULL,
2632 add_req_type_constraint (&list, position++, FAT_OBJECT);
2636 if (!check_params (&list, paramcount, params, 0, NULL,
2643 add_req_type_constraint (&list, position++, FAT_CHARACTER);
2647 if (!check_params (&list, paramcount, params, 5, IIICC,
2654 add_req_type_constraint (&list, position++, FAT_REAL);
2659 if (!check_params (&list, paramcount, params, 7, IIIICCC,
2666 add_req_type_constraint (&list, position++, FAT_REAL);
2670 if (!check_params (&list, paramcount, params, 4, IIIC,
2677 add_req_type_constraint (&list, position++, FAT_REAL);
2685 if (!check_params (&list, paramcount, params, 1, I,
2695 if (!check_params (&list, paramcount, params, 0, NULL,
2704 if (!check_params (&list, paramcount, params, 2, II,
2713 if (!check_params (&list, paramcount, params, 1, I,
2771 if (!check_params (&list, paramcount, params, 0, NULL,
2778 add_req_type_constraint (&list, position++, FAT_FORMATSTRING);
2785 add_req_listtype_constraint (&list, position++,
2792 if (!check_params (&list, paramcount, params, 0, NULL,
2799 add_req_type_constraint (&list, position++, FAT_OBJECT);
2813 if (!check_params (&list, paramcount, params, 0, NULL,
2821 *listp = list;
2835 list = *listp;
2847 if (!check_params (&list, paramcount, params, 0, NULL,
2855 *listp = list;
2872 if (!check_params (&list, paramcount, params, 0, NULL,
2883 nil_list = (list != NULL ? copy_list (list) : NULL);
2896 (list != NULL ? copy_list (list) : NULL);
2928 if (list != NULL)
2929 free_list (list);
2930 list = union_list;
2937 if (!check_params (&list, paramcount, params, 0, NULL,
2945 add_req_type_constraint (&list, position++, FAT_OBJECT);
2956 (list != NULL ? copy_list (list) : NULL);
2990 (list != NULL ? copy_list (list) : NULL);
3015 if (list != NULL)
3016 free_list (list);
3017 list = union_list;
3026 if (!check_params (&list, paramcount, params, 1, I,
3039 add_req_type_constraint (&list, position++, FAT_OBJECT);
3053 (list != NULL ? copy_list (list) : NULL);
3089 if (list != NULL)
3090 union_list = union (union_list, copy_list (list));
3098 if (list != NULL)
3099 free_list (list);
3100 list = union_list;
3112 if (!check_params (&list, paramcount, params, 0, NULL,
3120 *listp = list;
3125 if (!check_params (&list, paramcount, params, 1, I,
3138 sub_spec.list = sub_list;
3153 add_req_type_constraint (&list, position++, FAT_FORMATSTRING);
3170 single list. */
3203 if (list != NULL && position >= 0)
3206 list = make_intersected_list (list, sub_list);
3212 /* The argument is a list. */
3214 add_req_listtype_constraint (&list, position++,
3229 if (!check_params (&list, paramcount, params, 0, NULL,
3237 *listp = list;
3242 if (!check_params (&list, paramcount, params, 4, IIIC,
3253 *listp = list;
3272 list = *listp;
3277 list = union (list, sub_escape);
3289 if (!check_params (&list, paramcount, params, 0, NULL,
3297 *listp = list;
3302 if (!check_params (&list, paramcount, params, 3, THREE,
3308 if (position >= 0 && list != NULL && is_required (list, position))
3311 if (list != NULL)
3313 struct format_arg_list *this_escape = copy_list (list);
3319 list = add_required_constraint (list, position);
3332 if (!check_params (&list, paramcount, params, 1, I,
3341 if (!check_params (&list, paramcount, params, 0, NULL,
3350 *listp = list;
3356 if (!nocheck_params (&list, paramcount, params,
3364 add_req_type_constraint (&list, position++, FAT_FUNCTION);
3365 add_req_type_constraint (&list, position++, FAT_OBJECT);
3392 *listp = list;
3416 spec.list = make_unconstrained_list ();
3419 if (!parse_upto (&format, &position, &spec.list, &escape,
3426 spec.list = union (spec.list, escape);
3428 if (spec.list == NULL)
3437 normalize_list (spec.list);
3449 free_list (spec->list);
3471 if (!equal_list (spec1->list, spec2->list))
3482 make_intersected_list (copy_list (spec1->list),
3483 copy_list (spec2->list));
3487 equal_list (intersection, spec2->list))))
3516 /* Test program: Print the argument list specification returned by
3521 static void print_list (struct format_arg_list *list);
3561 print_list (element->list);
3575 print_list (struct format_arg_list *list)
3581 for (i = 0; i < list->initial.count; i++)
3582 for (j = 0; j < list->initial.element[i].repcount; j++)
3586 print_element (&list->initial.element[i]);
3589 if (list->repeated.count > 0)
3592 for (i = 0; i < list->repeated.count; i++)
3593 for (j = 0; j < list->repeated.element[i].repcount; j++)
3596 print_element (&list->repeated.element[i]);
3614 print_list (spec->list);