Patch title: Release 87 bulk changes
Abstract:
File: /pliant/protocol/lpr/spool.pli
Key:
    Removed line
    Added line
   
module "/pliant/language/context.pli"
module "/pliant/language/stream.pli"
module "/pliant/language/unsafe.pli"
module "/pliant/language/schedule/daemon.pli"
module "/pliant/language/schedule/resourcesem.pli"
module "/pliant/language/context.pli"
module "/pliant/fullpliant/this_computer.pli"
module "/pliant/admin/file.pli"
submodule "database.pli"

module "/pliant/language/stream/pipe.pli"
module "/pliant/language/context.pli"
module "/pliant/language/stream.pli"
module "/pliant/language/unsafe.pli"
module "/pliant/language/schedule/daemon.pli"
module "/pliant/language/schedule/resourcesem.pli"
module "/pliant/language/context.pli"
module "/pliant/fullpliant/this_computer.pli"
module "/pliant/admin/file.pli"
submodule "database.pli"

module "/pliant/language/stream/pipe.pli"
module "/pliant/language/stream/flow.pli"
module "/pliant/graphic/color/gamut.pli"
module "/pliant/graphic/image/prototype.pli"
module "/pliant/graphic/image/resampling.pli"
module "/pliant/graphic/image/antialiasing.pli"
module "/pliant/graphic/image/convert.pli"
module "/pliant/graphic/image/sharpening.pli"
module "/pliant/graphic/image/lazy.pli"
module "/pliant/graphic/filter/io.pli"
module "device.pli"
module "embedded.pli"
module "/pliant/admin/execute.pli"


function lpr_cancel job stream
  arg_rw Data:LprJob job ; arg_rw Stream stream
  stream close
  if job:p_status="R"
    job p_status := "T"
  else
    file_delete (lpr_filename job "lpr")
    file_delete (lpr_filename job job:format)
    file_delete (lpr_filename job "prn")
module "/pliant/graphic/color/gamut.pli"
module "/pliant/graphic/image/prototype.pli"
module "/pliant/graphic/image/resampling.pli"
module "/pliant/graphic/image/antialiasing.pli"
module "/pliant/graphic/image/convert.pli"
module "/pliant/graphic/image/sharpening.pli"
module "/pliant/graphic/image/lazy.pli"
module "/pliant/graphic/filter/io.pli"
module "device.pli"
module "embedded.pli"
module "/pliant/admin/execute.pli"


function lpr_cancel job stream
  arg_rw Data:LprJob job ; arg_rw Stream stream
  stream close
  if job:p_status="R"
    job p_status := "T"
  else
    file_delete (lpr_filename job "lpr")
    file_delete (lpr_filename job job:format)
    file_delete (lpr_filename job "prn")
    if job:error=""
    if job:error="" or (job:e_timestamp<>undefined and datetime:seconds-job:e_timestamp:seconds>purge_errors_after)
      lpr_database:data:job delete keyof:job



function lpr_spool
  daemon "print spooler daemon"
    while not daemon_emergency
      lpr_embedded_migrate "embedded:/"
      lpr_queue_sem request
      each job lpr_database:data:job filter job:error<>""
        if job:e_timestamp=undefined
          job e_timestamp := datetime
        eif datetime:seconds-job:e_timestamp:seconds>purge_e
          lpr_cancel job (var Stream no_data)
      each job lpr_database:data:job filter job:s_status<>"W
        var Str id := keyof job
        var Data:LprQueue queue :> job printer
        if queue:once or job:s_status="T"
          if job:format=""
            if job:s_status="T" or (file_query (lpr_filename
              part computer_format "Compute print job '"+id+
                lpr_compute_format job
      lpr_database:data:job delete keyof:job



function lpr_spool
  daemon "print spooler daemon"
    while not daemon_emergency
      lpr_embedded_migrate "embedded:/"
      lpr_queue_sem request
      each job lpr_database:data:job filter job:error<>""
        if job:e_timestamp=undefined
          job e_timestamp := datetime
        eif datetime:seconds-job:e_timestamp:seconds>purge_e
          lpr_cancel job (var Stream no_data)
      each job lpr_database:data:job filter job:s_status<>"W
        var Str id := keyof job
        var Data:LprQueue queue :> job printer
        if queue:once or job:s_status="T"
          if job:format=""
            if job:s_status="T" or (file_query (lpr_filename
              part computer_format "Compute print job '"+id+
                lpr_compute_format job
          eif job:r_status="W" and job:s_status="T"
          eif job:r_status="W" and ( job:s_status="T" or (queue:once and job:s_status="R" and (job:format="png" or job:format="jpeg" or job:format="packed") and (file_query (lpr_filename job job:format) standard)=defined) )
            if (lpr_rip_slot nowait_request 1)
              job r_startup := datetime
              job r_status := "R"
              thread
                var Data:LprJob j :> lpr_database:data:job i
                var Data:LprQueue q :> j printer
                part rip "Rip '"+j:format+"' job '"+id+"' fo
                  var Str file := lpr_filename j j:format
                  var Link:Stream prn :> new Stream
                  prn open (lpr_filename j "prn") out+safe
                  if prn=failure
                    lpr_error j "Failed to open the printer 
                  var ExtendedStatus rs
                  if (print_postscript and j:format="ps") or
                    rs := lpr_print_postscript file j prn
                  eif (print_png and j:format="png") or (pri
            if (lpr_rip_slot nowait_request 1)
              job r_startup := datetime
              job r_status := "R"
              thread
                var Data:LprJob j :> lpr_database:data:job i
                var Data:LprQueue q :> j printer
                part rip "Rip '"+j:format+"' job '"+id+"' fo
                  var Str file := lpr_filename j j:format
                  var Link:Stream prn :> new Stream
                  prn open (lpr_filename j "prn") out+safe
                  if prn=failure
                    lpr_error j "Failed to open the printer 
                  var ExtendedStatus rs
                  if (print_postscript and j:format="ps") or
                    rs := lpr_print_postscript file j prn
                  eif (print_png and j:format="png") or (pri
                    rs := lpr_print_image file j prn
                    var Str file_head file_tail
                    if job:s_status="R"
                      file_head := "[dq]flow:" ; file_tail := "[dq] flag_path [dq]"+(pathof job:s_status)+"[dq] flag_value [dq]R[dq]"
                    rs := lpr_print_image file_head+file+file_tail j prn
                  eif print_html and j:format="html"
                    rs := lpr_print_html file j prn
                  else
                    rs := failure "unsupported '"+j:format+"
                    plugin rip
                  if rs=failure
                    lpr_error j "Ripping error: "+rs:message
                  if prn:close=failure
                    lpr_error j "Failed to store the printer
                  j r_status := "T" ; j r_comment := ""
                  lpr_rip_slot release 1
          eif job:p_status="W" and ( job:r_status="T" or (qu
            var CBool lock := queue:printer<>""
            if not lock or (lpr_printer_sem nowait_request q
              job p_startup := datetime
              job p_status := "R"
              thread
                var Data:LprJob j :> lpr_database:data:job i
                var Data:LprQueue q :> j printer
                part rip "Print job '"+id+"' on '"+keyof:q+"
                  (var Stream src) open (lpr_filename j "prn
                  var Str target := lpr_device_search q:devi
                  if target:len>0 and (target target:len-1)=
                    target += shunt j:file<>"" j:file keyof:
                  (var Stream dest) open (string target)+" t
                  part copy
                    src read_available (var Address adr) (va
                    if size=0 and src=success and (j:s_statu
                      j p_comment := string:offset+" stalled
                      sleep 1
                      restart copy
                    if size>0
                      if j:p_status<>"R"
                        leave copy
                      dest raw_write adr size
                      if dest=success
                        offset += size ; j p_comment := stri
                        restart copy
                      else
                        lpr_error j (shunt offset=0 "Printer
                  src close
                  dest close
                  j p_status := "T" ; j p_comment := ""
                  lpr_cancel j dest
                  if strict_order
                    lpr_queue_sem rd_request ; lpr_queue_sem
                  if lock
                    lpr_printer_sem release q:printer
      lpr_queue_sem release
      daemon_sleep (min (max lpr_database:data:job:size 1) 5



export lpr_filename lpr_open lpr_close lpr_error lpr_cancel 
export lpr_init lpr_spool lpr_stop lpr_restart lpr_rip_slot
                  eif print_html and j:format="html"
                    rs := lpr_print_html file j prn
                  else
                    rs := failure "unsupported '"+j:format+"
                    plugin rip
                  if rs=failure
                    lpr_error j "Ripping error: "+rs:message
                  if prn:close=failure
                    lpr_error j "Failed to store the printer
                  j r_status := "T" ; j r_comment := ""
                  lpr_rip_slot release 1
          eif job:p_status="W" and ( job:r_status="T" or (qu
            var CBool lock := queue:printer<>""
            if not lock or (lpr_printer_sem nowait_request q
              job p_startup := datetime
              job p_status := "R"
              thread
                var Data:LprJob j :> lpr_database:data:job i
                var Data:LprQueue q :> j printer
                part rip "Print job '"+id+"' on '"+keyof:q+"
                  (var Stream src) open (lpr_filename j "prn
                  var Str target := lpr_device_search q:devi
                  if target:len>0 and (target target:len-1)=
                    target += shunt j:file<>"" j:file keyof:
                  (var Stream dest) open (string target)+" t
                  part copy
                    src read_available (var Address adr) (va
                    if size=0 and src=success and (j:s_statu
                      j p_comment := string:offset+" stalled
                      sleep 1
                      restart copy
                    if size>0
                      if j:p_status<>"R"
                        leave copy
                      dest raw_write adr size
                      if dest=success
                        offset += size ; j p_comment := stri
                        restart copy
                      else
                        lpr_error j (shunt offset=0 "Printer
                  src close
                  dest close
                  j p_status := "T" ; j p_comment := ""
                  lpr_cancel j dest
                  if strict_order
                    lpr_queue_sem rd_request ; lpr_queue_sem
                  if lock
                    lpr_printer_sem release q:printer
      lpr_queue_sem release
      daemon_sleep (min (max lpr_database:data:job:size 1) 5



export lpr_filename lpr_open lpr_close lpr_error lpr_cancel 
export lpr_init lpr_spool lpr_stop lpr_restart lpr_rip_slot