job ordering

Kurt Van Dijck kurt.van.dijck at skynet.be
Sun Jan 1 06:29:06 PST 2006


hi,

I patched a thing in CUPS to reverse the order that jobs are listed.
This places most recents jobs first.
Basically, it does the job searching, and when the list is complete, only then starts outputting.
Because the job list is a single linked list, I must malloc(realloc) the list. It were better as a double linked list (with 'next' & 'prev' pointers).

patch is :
diff -Naur cupsys-1.1.23-original/scheduler/ipp.c cupsys-1.1.23/scheduler/ipp.c
--- cupsys-1.1.23-original/scheduler/ipp.c      2005-12-31 15:25:04.000000000 +0100
+++ cupsys-1.1.23/scheduler/ipp.c       2006-01-01 14:56:51.000000000 +0100
@@ -86,6 +86,9 @@
 #  include <paper.h>
 #endif /* HAVE_LIBPAPER */

+/* e-circ patch : reverse the job list */
+#define jobs_reverse
+

 /*
  * PPD default choice structure...
@@ -3414,6 +3417,20 @@
 /*
  * 'get_jobs()' - Get a list of jobs for the specified printer.
  */
+#ifdef jobs_reverse
+static
+int inc_list (job_t *** list, size_t * size) {
+   size_t sz_new = *size ? *size *2 : 16;
+   job_t ** tmp = realloc(*list, sz_new * sizeof(job_t *));
+   if (!tmp) {
+      return -1;
+   }
+   memset(&tmp[*size], 0, sizeof(job_t *) * (sz_new - *size));
+   *size = sz_new;
+   *list = tmp;
+   return 0;
+}
+#endif

 static void
 get_jobs(client_t        *con,         /* I - Client connection */
@@ -3439,6 +3456,13 @@
   job_t                        *job;           /* Current job pointer */
   char                 job_uri[HTTP_MAX_URI];
                                        /* Job URI... */
+#ifdef jobs_reverse
+  job_t      ** jlp; /* job loop */
+  struct {
+     size_t   size;
+     job_t ** lst;
+  } tmp;
+#endif


   LogMessage(L_DEBUG2, "get_jobs(%p[%d], %s)\n", con, con->http.fd,
@@ -3524,6 +3548,9 @@
  /*
   * OK, build a list of jobs for this printer...
   */
+#ifdef jobs_reverse
+  memset(&tmp, 0, sizeof(tmp));
+#endif

   for (count = 0, job = Jobs; count < limit && job != NULL; job = job->next)
   {
@@ -3551,7 +3578,22 @@
     count ++;

     LogMessage(L_DEBUG2, "get_jobs: count = %d", count);
+#ifdef jobs_reverse
+    /* e-circ patch : reverse the job list returned */

+    if (count > tmp.size) inc_list(&tmp.lst, &tmp.size);
+    if (count > tmp.size) {
+       LogMessage(L_DEBUG, "malloc() jobs temporary list failed");
+       if (0 != tmp.lst) free(tmp.lst);
+       return;
+    }
+    tmp.lst[count -1] = job;
+  }
+
+  if (count)
+  for (jlp = &tmp.lst[count -1]; jlp >= tmp.lst; --jlp) {
+     job = *jlp;
+#endif
    /*
     * Send the requested attributes for each job...
     */
@@ -3579,6 +3621,9 @@

     ippAddSeparator(con->response);
   }
+#ifdef jobs_reverse
+  if (tmp.lst) free(tmp.lst);
+#endif

   if (requested != NULL)
     con->response->request.status.status_code = IPP_OK_SUBST;





More information about the cups mailing list