📄 110.htm
字号:
<br>-------------------------------------------------------------------------------- <br><br><br>要取得更多资讯,请看 Printing HOWTO 或者关於 printcap 的 man page. <br><br><br><br>-------------------------------------------------------------------------------- <br><br># /etc/printcap <br># <br># //zimmerman/oreilly via smbprint <br># <br>lp:\ <br>:cm=HP 5MP Postscript OReilly on zimmerman:\ <br>: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><hr SIZE="0"><p align="center"><a href="linux.htm">返回</a></p></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -