?? 110.htm
字號:
:lp=/dev/lp1:\ <br>
:sd=/var/spool/lpd/lp:\ <br>
:af=/var/spool/lpd/lp/acct:\ <br>
:mx#0:\ <br>
:if=/usr/bin/smbprint: <br>
<br>
<br>
-------------------------------------------------------------------------------- <br>
<br>
<br>
請確定 spool 和 accounting{帳號} 的目錄存在且可寫入.
請確信某行有適當的路徑指到 smbprint script (在下面會給)
而且確定適當的設備被指到 ( /dev 下某個檔). <br>
<br>
下個是 smbprint script 本身. 它通常被擺在 /usr/bin 而且是因為 Andrew
Tridgell 的緣故,而據我所知是他創造了 Samba. 它隨附在 Samba source
發行套件, 但在某些 binary 發行套件并沒有, 所以在這我再造一個. <br>
<br>
你可以希望仔細地看這個.
有某些較小的修改已經證明它們是很有用的. <br>
<br>
<br>
<br>
-------------------------------------------------------------------------------- <br>
<br>
#!/bin/sh -x <br>
<br>
# This script is an input filter for printcap printing on a unix machine. It <br>
# uses the smbclient program to print the file to the specified smb-based <br>
# server and service. <br>
# For example you could have a printcap entry like this <br>
# <br>
# smb:lp=/dev/null:sd=/usr/spool/smb:sh:if=/usr/local/samba/smbprint <br>
# <br>
# which would create a unix printer called "smb" that will print via this <br>
# script. You will need to create the spool directory /usr/spool/smb with <br>
# appropriate permissions and ownerships for your system. <br>
<br>
# Set these to the server and service you wish to print to <br>
# In this example I have a WfWg PC called "lapland" that has a printer <br>
# exported called "printer" with no password. <br>
<br>
# <br>
# Script further altered by hamiltom@ecnz.co.nz (Michael Hamilton) <br>
# so that the server, service, and password can be read from <br>
# a /usr/var/spool/lpd/PRINTNAME/.config file. <br>
# <br>
# In order for this to work the /etc/printcap entry must include an <br>
# accounting file (af=...): <br>
# <br>
# cdcolour:\ <br>
# :cm=CD IBM Colorjet on 6th:\ <br>
# :sd=/var/spool/lpd/cdcolour:\ <br>
# :af=/var/spool/lpd/cdcolour/acct:\ <br>
# :if=/usr/local/etc/smbprint:\ <br>
# :mx=0:\ <br>
# :lp=/dev/null: <br>
# <br>
# The /usr/var/spool/lpd/PRINTNAME/.config file should contain: <br>
# server=PC_SERVER <br>
# service=PR_SHARENAME <br>
# password="password" <br>
# <br>
# E.g. <br>
# server=PAULS_PC <br>
# service=CJET_371 <br>
# password="" <br>
<br>
# <br>
# Debugging log file, change to /dev/null if you like. <br>
# <br>
logfile=/tmp/smb-print.log <br>
# logfile=/dev/null <br>
<br>
<br>
# <br>
# The last parameter to the filter is the accounting file name. <br>
# <br>
spool_dir=/var/spool/lpd/lp <br>
config_file=$spool_dir/.config <br>
<br>
# Should read the following variables set in the config file: <br>
# server <br>
# service <br>
# password <br>
# user <br>
eval `cat $config_file` <br>
<br>
# <br>
# Some debugging help, change the >> to > if you want to same space. <br>
# <br>
echo "server $server, service $service" >> $logfile <br>
<br>
( <br>
# NOTE You may wish to add the line `echo translate' if you want automatic <br>
# CR/LF translation when printing. <br>
echo translate <br>
echo "print -" <br>
cat <br>
) | /usr/bin/smbclient "\\\\$server\\$service" $password -U $user -N -P >>
$logfile <br>
<br>
<br>
-------------------------------------------------------------------------------- <br>
<br>
<br>
大部分 linux 發行套件隨附 nenscript 其用來轉換 ASCII 文件成 Postscript.
以下 perl script 經由 smbprint 使更容易提供一種簡單介面給 linux 的列印.
<br>
<br>
<br>
<br>
-------------------------------------------------------------------------------- <br>
<br>
Usage: print [-a|c|p] <filename> <br>
-a prints <filename> as ASCII <br>
-c prints <filename> formatted as source code <br>
-p prints <filename> as Postscript <br>
If no switch is given, print attempts to <br>
guess the file type and print appropriately. <br>
<br>
<br>
-------------------------------------------------------------------------------- <br>
<br>
<br>
使用 smbprint 來列印 ASCII 檔案便於截斷過長的行. 如果可能的話,這個
script 截斷長行於空白鍵處(取代在字的中間). <br>
<br>
格式化過的原始碼是被 nenscript 處理過. 它處理 ASCII
檔而且用個特選的標頭(像 date,filename等)格式化成兩欄.
它也可計算行數. 使用這當作例子, 其他格式型態可以達成的. <br>
<br>
Postscript 文件已經適當地格式化了,所以它們直接通過. <br>
<br>
<br>
<br>
-------------------------------------------------------------------------------- <br>
<br>
#!/usr/bin/perl <br>
<br>
# Script: print <br>
# Authors: Brad Marshall, David Wood <br>
# Plugged In Communications <br>
# Date: 960808 <br>
# <br>
# Script to print to oreilly which is currently on zimmerman <br>
# Purpose: Takes files of various types as arguments and <br>
# processes them appropriately for piping to a Samba print script. <br>
# <br>
# Currently supported file types: <br>
# <br>
# ASCII - ensures that lines longer than $line_length characters wrap on <br>
# whitespace. <br>
# Postscript - Takes no action. <br>
# Code - Formats in Postscript (using nenscript) to display <br>
# properly (landscape, font, etc). <br>
# <br>
<br>
# Set the maximum allowable length for each line of ASCII text. <br>
$line_length = 76; <br>
<br>
# Set the path and name of the Samba print script <br>
$print_prog = "/usr/bin/smbprint"; <br>
<br>
# Set the path and name to nenscript (the ASCII-->Postscript converter) <br>
$nenscript = "/usr/bin/nenscript"; <br>
<br>
unless ( -f $print_prog ) { <br>
die "Can't find $print_prog!"; <br>
} <br>
unless ( -f $nenscript ) { <br>
die "Can't find $nenscript!"; <br>
} <br>
<br>
&ParseCmdLine(@ARGV); <br>
<br>
# DBG <br>
print "filetype is $filetype\n"; <br>
<br>
if ($filetype eq "ASCII") { <br>
&wrap($line_length); <br>
} elsif ($filetype eq "code") { <br>
&codeformat; <br>
} elsif ($filetype eq "ps") { <br>
&createarray; <br>
} else { <br>
print "Sorry..no known file type.\n"; <br>
exit 0; <br>
} <br>
# Pipe the array to smbprint <br>
open(PRINTER, "|$print_prog") || die "Can't open $print_prog: $!\n"; <br>
foreach $line (@newlines) { <br>
print PRINTER $line; <br>
} <br>
# Send an extra linefeed in case a file has an incomplete last line. <br>
print PRINTER "\n"; <br>
close(PRINTER); <br>
print "Completed\n"; <br>
exit 0; <br>
<br>
# --------------------------------------------------- # <br>
# Everything below here is a subroutine # <br>
# --------------------------------------------------- # <br>
<br>
sub ParseCmdLine { <br>
# Parses the command line, finding out what file type the file is <br>
<br>
# Gets $arg and $file to be the arguments (if the exists) <br>
# and the filename <br>
if ($#_ < 0) { <br>
&usage; <br>
} <br>
# DBG <br>
# foreach $element (@_) { <br>
# print "*$element* \n"; <br>
# } <br>
<br>
$arg = shift(@_); <br>
if ($arg =~ /\-./) { <br>
$cmd = $arg; <br>
# DBG <br>
# print "\$cmd found.\n"; <br>
<br>
$file = shift(@_); <br>
} else { <br>
$file = $arg; <br>
} <br>
<br>
# Defining the file type <br>
unless ($cmd) { <br>
# We have no arguments <br>
<br>
if ($file =~ /\.ps$/) { <br>
$filetype = "ps"; <br>
} elsif ($file =~ /\.java$|\.c$|\.h$|\.pl$|\.sh$|\.csh$|\.m4$|\.inc$|\.html$|\.htm$/) { <br>
$filetype = "code"; <br>
} else { <br>
$filetype = "ASCII"; <br>
} <br>
<br>
# Process $file for what type is it and return $filetype <br>
} else { <br>
# We have what type it is in $arg <br>
if ($cmd =~ /^-p$/) { <br>
$filetype = "ps"; <br>
} elsif ($cmd =~ /^-c$/) { <br>
$filetype = "code"; <br>
} elsif ($cmd =~ /^-a$/) { <br>
$filetype = "ASCII" <br>
} <br>
} <br>
} <br>
<br>
sub usage { <br>
print " <br>
Usage: print [-a|c|p] <filename> <br>
-a prints <filename> as ASCII <br>
-c prints <filename> formatted as source code <br>
-p prints <filename> as Postscript <br>
If no switch is given, print attempts to <br>
guess the file type and print appropriately.\n <br>
"; <br>
exit(0); <br>
} <br>
<br>
sub wrap { <br>
# Create an array of file lines, where each line is < the <br>
# number of characters specified, and wrapped only on whitespace <br>
<br>
# Get the number of characters to limit the line to. <br>
$limit = pop(@_); <br>
<br>
# DBG <br>
#print "Entering subroutine wrap\n"; <br>
#print "The line length limit is $limit\n"; <br>
<br>
# Read in the file, parse and put into an array. <br>
open(FILE, "<$file") || die "Can't open $file: $!\n"; <br>
while(<FILE>) { <br>
$line = $_; <br>
<br>
# DBG <br>
#print "The line is:\n$line\n"; <br>
<br>
# Wrap the line if it is over the limit. <br>
while ( length($line) > $limit ) { <br>
<br>
# DBG <br>
#print "Wrapping..."; <br>
<br>
# Get the first $limit +1 characters. <br>
$part = substr($line,0,$limit +1); <br>
<br>
# DBG <br>
#print "The partial line is:\n$part\n"; <br>
<br>
# Check to see if the last character is a space. <br>
$last_char = substr($part,-1, 1); <br>
if ( " " eq $last_char ) { <br>
# If it is, print the rest. <br>
<br>
# DBG <br>
#print "The last character was a space\n"; <br>
<br>
substr($line,0,$limit + 1) = ""; <br>
substr($part,-1,1) = ""; <br>
push(@newlines,"$part\n"); <br>
} else { <br>
# If it is not, find the last space in the <br>
# sub-line and print up to there. <br>
<br>
# DBG <br>
#print "The last character was not a space\n"; <br>
<br>
# Remove the character past $limit <br>
substr($part,-1,1) = ""; <br>
# Reverse the line to make it easy to find <br>
# the last space. <br>
$revpart = reverse($part); <br>
$index = index($revpart," "); <br>
if ( $index > 0 ) { <br>
substr($line,0,$limit-$index) = ""; <br>
push(@newlines,substr($part,0,$limit-$index) <br>
. "\n"); <br>
} else { <br>
# There was no space in the line, so <br>
# print it up to $limit. <br>
substr($line,0,$limit) = ""; <br>
push(@newlines,substr($part,0,$limit) <br>
. "\n"); <br>
} <br>
} <br>
} <br>
push(@newlines,$line); <br>
} <br>
close(FILE); <br>
} <br>
<br>
sub codeformat { <br>
# Call subroutine wrap then filter through nenscript <br>
&wrap($line_length); <br>
<br>
# Pipe the results through nenscript to create a Postscript <br>
# file that adheres to some decent format for printing <br>
# source code (landscape, Courier font, line numbers). <br>
# Print this to a temporary file first. <br>
$tmpfile = "/tmp/nenscript$$"; <br>
open(FILE, "|$nenscript -2G -i$file -N -p$tmpfile -r") || <br>
die "Can't open nenscript: $!\n"; <br>
foreach $line (@newlines) { <br>
print FILE $line; <br>
} <br>
close(FILE); <br>
<br>
# Read the temporary file back into an array so it can be <br>
# passed to the Samba print script. <br>
@newlines = (""); <br>
open(FILE, "<$tmpfile") || die "Can't open $file: $!\n"; <br>
while(<FILE>) { <br>
push(@newlines,$_); <br>
} <br>
close(FILE); <br>
system("rm $tmpfile"); <br>
} <br>
<br>
sub createarray { <br>
# Create the array for postscript <br>
open(FILE, "<$file") || die "Can't open $file: $!\n"; <br>
while(<FILE>) { <br>
push(@newlines,$_); <br>
} <br>
close(FILE); <br>
} <br>
<br>
<br>
-------------------------------------------------------------------------------- <br>
<br>
10. 版權 <br>
1996 年的 HOWTO 版權是屬於 David Wood.
它可以用任何型式的再重覆產生以及自由的散播,只要這個檔原封不動,包含這段敘述.</p>
<BR>
<hr color="#EE9B73" size="1" width="94%">
</TD>
<TD CLASS="tt3" VALIGN="bottom" width="8%" bgcolor="#e0e0e0"><strong><A HREF="111.htm">后一頁</A><BR>
<A HREF="109.htm">前一頁</A><BR>
<A HREF="index.html">回目錄</A><BR>
<A HREF="../../../../index.htm">回首頁</A><BR>
</strong>
</TD>
</TR>
</table>
</BODY></HTML>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -