]> Joshua Wise's Git repositories - tdl.git/blobdiff - list.c
Print 'danger warnings' based on deadline proximity.
[tdl.git] / list.c
diff --git a/list.c b/list.c
index a26a3c797080ee62e58a700338bf48126da0a863..450961c96b4c18d8d6b6b53c5d812311678f3029 100644 (file)
--- a/list.c
+++ b/list.c
@@ -219,6 +219,34 @@ static void print_details(struct node *y, int indent, int summarise_kids, const
     }
   }
   if (!options->monochrome) printf("%s", NORMAL);
+  if (y->required_by > 0) {
+    time_t delta = y->required_by - time(NULL);
+    if (delta < 0) {
+      printf(options->monochrome ?
+               " [OVERDUE]" :
+               RED " [OVERDUE]" NORMAL);
+    } else if (delta < 24*60*60) {
+      printf(options->monochrome ?
+               "  [due <24hr]" :
+               RED " [due <24hr]" NORMAL);
+    } else if (delta < 2*24*60*60) {
+      printf(options->monochrome ?
+               "  [due <2d]" :
+               RED " [due <2d]" NORMAL);
+    } else if (delta < 3*24*60*60) {
+      printf(options->monochrome ?
+               "  [due <3d]" :
+               YELLOW " [due <3d]" NORMAL);
+    } else if (delta < 4*24*60*60) {
+      printf(options->monochrome ?
+               "  [due <4d]" :
+               YELLOW " [due <4d]" NORMAL);
+    } else if (delta < 5*24*60*60) {
+      printf(options->monochrome ?
+               "  [due <5d]" :
+               GREEN " [due <5d]" NORMAL);
+    }
+  }
   printf("\n");
 
   if (options->verbose) {
@@ -237,17 +265,77 @@ static void print_details(struct node *y, int indent, int summarise_kids, const
 
 }
 /*}}}*/
+/* 1 if x has lower priority than y. */
+static int node_lessthan(struct node *x, struct node *y)/*{{{*/
+{
+  if (x->priority < y->priority)
+    return 1;
+  if (x->priority > y->priority)
+    return 0;
+  if (x->required_by == 0 && y->required_by == 0)
+    return (x->idx > y->idx);
+  if (y->required_by == 0)
+    return 1;
+  if (x->required_by == 0)
+    return 0;
+  return x->required_by < y->required_by;
+}
+/*}}}*/
+static void sort_chain(struct links *x)/*{{{*/
+{
+  struct links new;
+  struct node *y, *ynext, *yprev;
+  int idx;
+  
+  new.next = NULL;
+  new.prev = NULL;
+  
+  /* Stupidsort. */
+  for (y = x->next, idx = 1; y != (struct node *) x; y = ynext, ++idx) {
+    /* y is now the current node; go insert it into its rightful place in
+     * the new chain.  */
+    struct node **nextp = &(new.next);
+    struct node *ins;
+    for (ins = new.next; ins && node_lessthan(ins, y); nextp = &(ins->chain.next), ins = ins->chain.next)
+      ;
+    y->chain.next->chain.prev = y->chain.prev;
+    y->chain.prev->chain.next = y->chain.next;
+    ynext = y->chain.next;
+    y->chain.next = *nextp;
+    *nextp = y;
+    y->idx = idx;
+  }
+  
+  /* Now clean up the new links. */
+  yprev = (struct node *)x;
+  for (y = new.next; y; yprev = y, y = y->chain.next) {
+    y->chain.prev = yprev;
+  }
+  yprev->chain.next = (struct node *)x;
+  new.prev = y;
+  
+  if (new.next == NULL) {
+    x->next = (struct node *)x;
+    x->prev = (struct node *)x;
+  } else {
+    x->next = new.next;
+    x->prev = new.prev;
+  }
+}
+/*}}}*/
 static void list_chain(struct links *x, int indent, int depth, const struct list_options *options, char *index_buffer, enum Priority prio, time_t now, unsigned char *hits)/*{{{*/
 {
   struct node *y;
-  int idx, is_done, is_deferred, is_postponed;
+  int is_done, is_deferred, is_postponed;
   int show_node;
   char component_buffer[8];
   char new_index_buffer[64];
   
-  for (y = x->next, idx = 1;
+  sort_chain(x);
+    
+  for (y = x->next;
        y != (struct node *) x;
-       y = y->chain.next, ++idx) {
+       y = y->chain.next) {
     
     is_done = (y->done > 0);
     is_postponed = (y->arrived == POSTPONED_TIME);
@@ -257,7 +345,7 @@ static void list_chain(struct links *x, int indent, int depth, const struct list
              || (!is_deferred && !is_postponed);
     if (!show_node) continue;
 
-    sprintf(component_buffer, "%d", idx);
+    sprintf(component_buffer, "%d", y->idx);
     strcpy(new_index_buffer, index_buffer);
     if (strlen(new_index_buffer) > 0) {
       strcat(new_index_buffer, ".");
This page took 0.024871 seconds and 4 git commands to generate.