--- /usr/bin/printtool2	Wed Oct 25 14:37:36 2000
+++ printtool	Wed Oct 25 17:11:18 2000
@@ -29,12 +29,13 @@
 
 set warn_samba 0
 set warn_ncpfs 0
+set warn_hylafax 0
 
 catch {source $env(CONTROL_PANEL_LIB_DIR)/printtool.warn}
 
 #########################################################
 ## @@ Random Data
-set version "3.48"
+set version "3.49"
 set printer_count 0
 set delete_index ""
 set trigger 0
@@ -939,6 +940,34 @@
 
 
 #
+# see if sendfax is installed
+# 
+proc find_sendfax {} {
+     global warn_hylafax
+
+    if [catch {open "|/usr/bin/sendfax -x"} input] {
+#	puts "open result was $input"
+    }
+
+    if { [string first "couldn't execute" $input] != -1 } {
+	set foo [rhs_dialog .foo "Error" "hylafax does not appear to be installed.
+
+You will not be able to send faxes without it installed.
+
+Please quit and install hylafax before configuring any FAX printer entries.
+
+If you are not interested in support of Hylafax fax printers, 
+
+please choose 'Ignore' and you will not see this message in the future.
+" error 0 "Ok" "Ignore"]
+	if { $foo != 0 } { 
+	    set warn_hylafax 0
+	}
+    }
+}
+
+
+#
 # load in the printer database
 #
 
@@ -1026,7 +1055,7 @@
 # printer_type_list is a list of printer types which should be presented
 # to the user -- ie everything but UNKNOWN
 
-set printer_type_list {LOCAL REMOTE SMB NCP DIRECT}
+set printer_type_list {LOCAL REMOTE SMB NCP FAX DIRECT}
 
 proc UNKNOWN_summaryline {i} { return "type unrecognized" }
 proc UNKNOWN_name {} { return "unknown printer type--should not appear" }
@@ -2485,7 +2514,6 @@
     }
 }
 
-
 #
 # NCP support by Fernando Lozano from BL Informática Ltda. at Rio de
 # Janeiro, Brazil, adopted to printtool by Bill Nottingham
@@ -2644,6 +2672,148 @@
     }
 }
 
+#
+# FAX support by Seth Mos from Coltex BV in the Netherlands.
+# contact seth.mos@coltex.nl for details. It is based on the NCP entry.
+#
+proc FAX_config {i} {
+    set spool_dir [printcap_field $i "sd=" "none"]
+    set config_file "$spool_dir/.config"
+
+    if {[string compare spool_dir none] == 0} {
+ 	return [list "" "" "" ""]
+    }
+    if [file exists $config_file] {
+        set fd [open $config_file]	
+        if {![regexp "server=\(.*\)" [gets $fd] dummy server]} {
+	    set server ""
+        }
+        if {![regexp "phone=\(.*\)" [gets $fd] dummy phone]} {
+ 	     set phone ""
+        }
+        if {![regexp "size=\(.*\)" [gets $fd] dummy size]} {
+ 	     set size "A4"
+        }
+
+        set translate no
+        return [list $server $phone $size]        
+    }
+    return [list "" "" "" ""]
+}
+
+proc FAX_summaryline {i} {
+    set printer [FILTERED_summaryline $i "printer"]
+    set config [FAX_config $i]
+    set servername  [lindex $config 0]
+    return "FAX - $printer on server $servername"
+}
+
+proc FAX_name {} { return "HylaFax Printer support(FAX)" }
+
+proc FAX_addpanel {w i} {
+    global fax_crlf
+
+    set fax_crlf 0
+    set config [FAX_config $i]
+
+    frame $w.faxserver
+    frame $w.faxphone
+    frame $w.faxsize
+
+    label $w.l5 -text "Fax Server Name" -anchor w
+    entry $w.v5 -font fixed -relief sunken -borderwidth 2
+    $w.v5 insert 0 [lindex $config 0]
+
+    label $w.l6 -text "Fax Phone Number" -anchor w
+    entry $w.v6 -font fixed -relief sunken -borderwidth 2
+    $w.v6 insert 0 [lindex $config 1]
+
+    label $w.l7 -text "Fax Paper Size" -anchor w
+    entry $w.v7 -font fixed -relief sunken -borderwidth 2
+    $w.v7 insert 0 [lindex $config 2]
+
+#
+# we'll handle cr/lf translation through the print filter if necessary
+#
+    set fax_crlf 0
+
+#    pack $w.l5 -pady 4 -side top -fill x -in $w.f1
+#    pack $w.l_hostip -pady 4 -side top -fill x -in $w.f1
+#    pack $w.l6 -pady 3 -side top -fill x -in $w.f1
+
+##    pack $w.v5 $w.v6 -side top -expand true -fill x -in $w.f2
+#    pack $w.v5 $w.v6_hostip $w.v6 $w.v7 $w.v8 -side top -expand true -fill x -in $w.f2
+
+    pack $w.l5 -side left -fill x -anchor w -in $w.faxserver
+    pack $w.v5 -side right -fill x -anchor e -in $w.faxserver
+    pack $w.l6 -side left -fill x -anchor w -in $w.faxphone
+    pack $w.v6 -side right -fill x -anchor e -in $w.faxphone
+    pack $w.l7 -side left -fill x -anchor w -in $w.faxsize
+    pack $w.v7 -side right -fill x -anchor e -in $w.faxsize
+
+    pack $w.faxserver $w.faxphone $w.faxsize -side top -fill x -in $w.f1
+
+    FILTERED_addpanel $w $i
+}
+
+proc FAX_updateentry {w i} {
+global fax_server fax_phone fax_size fax_crlf
+
+    set fax_server [$w.v5 get]
+    set fax_phone    [$w.v6 get]
+    set fax_size    [$w.v7 get]
+#
+#   get the auto_filter setup first
+#
+#   it will be the input filter, so it sets the printcap entry 'if='
+#
+    set filter [$w.v10 get]
+    FILTERED_updateentry $i $filter
+
+}
+
+proc FAX_setup {i} {
+    global fax_server fax_phone fax_size fax_crlf
+    global auto_flag
+    global filtersrcdir
+
+#
+#   now do faxprint related setup
+#
+#
+    set spool_dir [printcap_field $i "sd=" ""]
+    catch {exec mkdir -p $spool_dir}
+    catch {exec chown lp.lp $spool_dir}
+    catch {exec chmod 700 $spool_dir}
+
+    set fax_config "$spool_dir/.config"
+    set_printcap_field $i "af=" "$spool_dir/acct"
+    set_printcap_field $i "lp=" /dev/null
+    set_printcap_field $i "sh" ""
+    catch {exec rm -f $fax_config}
+
+    set ffd [open $fax_config w]
+    if {$fax_crlf} { set translate yes } else { set translate no }
+    puts $ffd "server=$fax_server"
+    puts $ffd "phone=$fax_phone"
+    puts $ffd "size=$fax_size"
+    close $ffd
+
+#
+#   see if any filter was specified, and if not, default
+#   to a filter that will just send data to remote FAX server
+#
+    set i_filter [printcap_field $i "if=" ""]
+    if {$i_filter != $auto_flag} {
+	set_printcap_field $i "if=" $filtersrcdir/faxprint
+    } else {
+#
+#       now setup the auto_filter
+#
+	FILTERED_setup $i
+    }
+}
+
 proc write_printcap {} {
     global print_count printer_comments printer_entry
     global printer_info printer_type
@@ -2991,7 +3161,7 @@
 
 Then it is necessary to select what type of printer is being added.
 
-There are five types of printers which can be configured with printtool:  LOCAL, REMOTE, SMB, NCP, and DIRECT.
+There are six types of printers which can be configured with printtool:  LOCAL, REMOTE, SMB, FAX, NCP, and DIRECT.
 
   LOCAL printers are attached to the printer port
   of the local machine. 
@@ -3005,11 +3175,20 @@
   printers on a machine running Windows or the
   samba software.
   
+  FAX printers are attached to another machine 
+  which is an FAX server. Use this to print to
+  printers on a machine running Windows or the
+  samba software.
+  
   NCP printers are attached to another machine
   which is an NCP server. Use this to print to
   printers on a machine running NetWare or the
   mars_nwe software.
 
+  FAX printers can be attached to another machine
+  which is an HylaFax server. Use this to print
+  to people who have a fax.
+
   DIRECT printers are attached directly to the 
   network, and leave a port (typically 9100)
   open. By sending data directly to this port
@@ -3081,6 +3260,13 @@
                      Someone should be able to tell you this if
                      you do not already know it.
 
+For FAX printers, the following are required:
+
+   Fax Server Name: Name of the machine to which hosts the Hylafax server.
+                        This can als be the local machine.
+
+   Fax number: Number of the remote FAX.
+
 For DIRECT printers, the following are also required:
 
    Printer IP address: Hostname of the remote printer.
@@ -3415,9 +3601,13 @@
 if { $warn_ncpfs != 0 } {
  find_nprint
 }
+if { $warn_hylafax != 0 } {
+ find_sendfax
+}
 set fd [ open $env(CONTROL_PANEL_LIB_DIR)/printtool.warn w ]
 puts $fd "set warn_samba $warn_samba"
 puts $fd "set warn_ncpfs $warn_ncpfs"
+puts $fd "set warn_hylafax $warn_hylafax"
 close $fd
 write_printcap
 redisplay
