-

A library of common code used by all of the Inform tools. This is version 1.

+

A library of utility functions for command-line tools. This is version 1.


    diff --git a/docs/foundation-test/index.html b/docs/foundation-test/index.html index 27c7832..49fe033 100644 --- a/docs/foundation-test/index.html +++ b/docs/foundation-test/index.html @@ -52,12 +52,12 @@

-

Importing:

+

This program also incorporates the following web(s) as module(s):

  • -

    +

    inweb/foundation - - A library of common code used by all of the Inform tools.

    + - A library of utility functions for command-line tools.

diff --git a/docs/goldbach/goldbach.pdf b/docs/goldbach/goldbach.pdf index 7eeb563..69796fa 100644 Binary files a/docs/goldbach/goldbach.pdf and b/docs/goldbach/goldbach.pdf differ diff --git a/docs/inweb/3-tc.html b/docs/inweb/3-tc.html index 527c8e2..05fdc72 100644 --- a/docs/inweb/3-tc.html +++ b/docs/inweb/3-tc.html @@ -141,28 +141,29 @@ if so, they can always be subdivided. cls.into_file = into; cls.modules = NEW_LINKED_LIST(module); if (W) { - module *M; - LOOP_OVER_LINKED_LIST(M, module, W->md->as_module->dependencies) { - text_stream *owner = Collater::module_owner(M, W); - if (Str::len(owner) == 0) - ADD_TO_LINKED_LIST(M, module, cls.modules); - } - LOOP_OVER_LINKED_LIST(M, module, W->md->as_module->dependencies) { - text_stream *owner = Collater::module_owner(M, W); - if ((Str::len(owner) > 0) && (Str::ne_insensitive(owner, I"inweb"))) - ADD_TO_LINKED_LIST(M, module, cls.modules); - } - LOOP_OVER_LINKED_LIST(M, module, W->md->as_module->dependencies) { - text_stream *owner = Collater::module_owner(M, W); - if ((Str::len(owner) > 0) && (Str::eq_insensitive(owner, I"inweb"))) - ADD_TO_LINKED_LIST(M, module, cls.modules); - } + int c = LinkedLists::len(W->md->as_module->dependencies); + if (c > 0) Form the list of imported modules3.1; } - Read in the source file containing the contents page template3.1; + Read in the source file containing the contents page template3.2; return cls; } -

§3.1. Read in the source file containing the contents page template3.1 = +

§3.1. Form the list of imported modules3.1 = +

+ +
+    module **module_array =
+        Memory::calloc(c, sizeof(module *), CLS_SORTING_MREASON);
+    module *M; int d=0;
+    LOOP_OVER_LINKED_LIST(M, module, W->md->as_module->dependencies)
+        module_array[d++] = M;
+    Collater::sort_web(W);
+    qsort(module_array, (size_t) c, sizeof(module *), Collater::sort_comparison);
+    for (int d=0; d<c; d++) ADD_TO_LINKED_LIST(module_array[d], module, cls.modules);
+    Memory::I7_free(module_array, CLS_SORTING_MREASON, c*((int) sizeof(module *)));
+
+
  • This code is used in §3.
+

§3.2. Read in the source file containing the contents page template3.2 =

@@ -178,7 +179,7 @@ if so, they can always be subdivided.
 

§4.

-void Collater::temp_line(text_stream *line, text_file_position *tfp, void *v_ies) {
+void Collater::temp_line(text_stream *line, text_file_position *tfp, void *v_ies) {
     collater_state *cls = (collater_state *) v_ies;
     if (cls->no_tlines < MAX_TEMPLATE_LINES)
         cls->tlines[cls->no_tlines++] = Str::duplicate(line);
@@ -968,7 +969,7 @@ empty text) if it appears to belong to the current web 
 
 
-text_stream *Collater::module_owner(module *M, web *W) {
+text_stream *Collater::module_owner(const module *M, web *W) {
     text_stream *owner =
         Pathnames::directory_name(Pathnames::up(M->module_location));
     text_stream *me = NULL;
@@ -978,6 +979,40 @@ empty text) if it appears to belong to the current web     return NULL;
 }
 
+

§7. This enables us to sort them. The empty owner (i.e., the current web) comes +top, then all other owners, in alphabetical order, and then last of all Inweb, +so that foundation will always be at the bottom. +

+ +
+web *sorting_web = NULL;
+void Collater::sort_web(web *W) {
+    sorting_web = W;
+}
+int Collater::sort_comparison(const void *ent1, const void *ent2) {
+    const module *M1 = *((const module **) ent1);
+    const module *M2 = *((const module **) ent2);
+    text_stream *O1 = Collater::module_owner(M1, sorting_web);
+    text_stream *O2 = Collater::module_owner(M2, sorting_web);
+    int r = Collater::cmp_owners(O1, O2);
+    if (r != 0) return r;
+    return Str::cmp_insensitive(M1->module_name, M2->module_name);
+}
+
+int Collater::cmp_owners(text_stream *O1, text_stream *O2) {
+    if (Str::len(O1) == 0) {
+        if (Str::len(O2) > 0) return -1;
+        return 0;
+    }
+    if (Str::len(O2) == 0) return 1;
+    if (Str::eq_insensitive(O1, I"inweb")) {
+        if (Str::eq_insensitive(O2, I"inweb") == FALSE) return 1;
+        return 0;
+    }
+    if (Str::eq_insensitive(O2, I"inweb")) return -1;
+    return Str::cmp_insensitive(O1, O2);
+}
+
diff --git a/docs/inweb/index.html b/docs/inweb/index.html index a5161ca..37f711a 100644 --- a/docs/inweb/index.html +++ b/docs/inweb/index.html @@ -321,12 +321,12 @@