⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 110.htm

📁 尝试使用有意义的结构与组织
💻 HTM
📖 第 1 页 / 共 2 页
字号:
: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 &quot;smb&quot; 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 &quot;lapland&quot; that has a printer <br>
# exported called &quot;printer&quot; 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=&quot;password&quot; <br>
# <br>
# E.g. <br>
# server=PAULS_PC <br>
# service=CJET_371 <br>
# password=&quot;&quot; <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 &gt;&gt; to &gt; if you want to same space. <br>
# <br>
echo &quot;server $server, service $service&quot; &gt;&gt; $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 &quot;print -&quot; <br>
cat <br>
) | /usr/bin/smbclient &quot;\\\\$server\\$service&quot; $password -U $user -N -P &gt;&gt;
$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] &lt;filename&gt; <br>
-a prints &lt;filename&gt; as ASCII <br>
-c prints &lt;filename&gt; formatted as source code <br>
-p prints &lt;filename&gt; 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 = &quot;/usr/bin/smbprint&quot;; <br>
<br>
# Set the path and name to nenscript (the ASCII--&gt;Postscript converter) <br>
$nenscript = &quot;/usr/bin/nenscript&quot;; <br>
<br>
unless ( -f $print_prog ) { <br>
die &quot;Can't find $print_prog!&quot;; <br>
} <br>
unless ( -f $nenscript ) { <br>
die &quot;Can't find $nenscript!&quot;; <br>
} <br>
<br>
&amp;ParseCmdLine(@ARGV); <br>
<br>
# DBG <br>
print &quot;filetype is $filetype\n&quot;; <br>
<br>
if ($filetype eq &quot;ASCII&quot;) { <br>
&amp;wrap($line_length); <br>
} elsif ($filetype eq &quot;code&quot;) { <br>
&amp;codeformat; <br>
} elsif ($filetype eq &quot;ps&quot;) { <br>
&amp;createarray; <br>
} else { <br>
print &quot;Sorry..no known file type.\n&quot;; <br>
exit 0; <br>
} <br>
# Pipe the array to smbprint <br>
open(PRINTER, &quot;|$print_prog&quot;) || die &quot;Can't open $print_prog: $!\n&quot;; <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 &quot;\n&quot;; <br>
close(PRINTER); <br>
print &quot;Completed\n&quot;; <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 ($#_ &lt; 0) { <br>
&amp;usage; <br>
} <br>
# DBG <br>
# foreach $element (@_) { <br>
# print &quot;*$element* \n&quot;; <br>
# } <br>
<br>
$arg = shift(@_); <br>
if ($arg =~ /\-./) { <br>
$cmd = $arg; <br>
# DBG <br>
# print &quot;\$cmd found.\n&quot;; <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 = &quot;ps&quot;; <br>
} elsif ($file =~ /\.java$|\.c$|\.h$|\.pl$|\.sh$|\.csh$|\.m4$|\.inc$|\.html$|\.htm$/) { <br>
$filetype = &quot;code&quot;; <br>
} else { <br>
$filetype = &quot;ASCII&quot;; <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 = &quot;ps&quot;; <br>
} elsif ($cmd =~ /^-c$/) { <br>
$filetype = &quot;code&quot;; <br>
} elsif ($cmd =~ /^-a$/) { <br>
$filetype = &quot;ASCII&quot; <br>
} <br>
} <br>
} <br>
<br>
sub usage { <br>
print &quot; <br>
Usage: print [-a|c|p] &lt;filename&gt; <br>
-a prints &lt;filename&gt; as ASCII <br>
-c prints &lt;filename&gt; formatted as source code <br>
-p prints &lt;filename&gt; as Postscript <br>
If no switch is given, print attempts to <br>
guess the file type and print appropriately.\n <br>
&quot;; <br>
exit(0); <br>
} <br>
<br>
sub wrap { <br>
# Create an array of file lines, where each line is &lt; 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 &quot;Entering subroutine wrap\n&quot;; <br>
#print &quot;The line length limit is $limit\n&quot;; <br>
<br>
# Read in the file, parse and put into an array. <br>
open(FILE, &quot;&lt;$file&quot;) || die &quot;Can't open $file: $!\n&quot;; <br>
while(&lt;FILE&gt;) { <br>
$line = $_; <br>
<br>
# DBG <br>
#print &quot;The line is:\n$line\n&quot;; <br>
<br>
# Wrap the line if it is over the limit. <br>
while ( length($line) &gt; $limit ) { <br>
<br>
# DBG <br>
#print &quot;Wrapping...&quot;; <br>
<br>
# Get the first $limit +1 characters. <br>
$part = substr($line,0,$limit +1); <br>
<br>
# DBG <br>
#print &quot;The partial line is:\n$part\n&quot;; <br>
<br>
# Check to see if the last character is a space. <br>
$last_char = substr($part,-1, 1); <br>
if ( &quot; &quot; eq $last_char ) { <br>
# If it is, print the rest. <br>
<br>
# DBG <br>
#print &quot;The last character was a space\n&quot;; <br>
<br>
substr($line,0,$limit + 1) = &quot;&quot;; <br>
substr($part,-1,1) = &quot;&quot;; <br>
push(@newlines,&quot;$part\n&quot;); <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 &quot;The last character was not a space\n&quot;; <br>
<br>
# Remove the character past $limit <br>
substr($part,-1,1) = &quot;&quot;; <br>
# Reverse the line to make it easy to find <br>
# the last space. <br>
$revpart = reverse($part); <br>
$index = index($revpart,&quot; &quot;); <br>
if ( $index &gt; 0 ) { <br>
substr($line,0,$limit-$index) = &quot;&quot;; <br>
push(@newlines,substr($part,0,$limit-$index) <br>
. &quot;\n&quot;); <br>
} else { <br>
# There was no space in the line, so <br>
# print it up to $limit. <br>
substr($line,0,$limit) = &quot;&quot;; <br>
push(@newlines,substr($part,0,$limit) <br>
. &quot;\n&quot;); <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>
&amp;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 = &quot;/tmp/nenscript$$&quot;; <br>
open(FILE, &quot;|$nenscript -2G -i$file -N -p$tmpfile -r&quot;) || <br>
die &quot;Can't open nenscript: $!\n&quot;; <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 = (&quot;&quot;); <br>
open(FILE, &quot;&lt;$tmpfile&quot;) || die &quot;Can't open $file: $!\n&quot;; <br>
while(&lt;FILE&gt;) { <br>
push(@newlines,$_); <br>
} <br>
close(FILE); <br>
system(&quot;rm $tmpfile&quot;); <br>
} <br>
<br>
sub createarray { <br>
# Create the array for postscript <br>
open(FILE, &quot;&lt;$file&quot;) || die &quot;Can't open $file: $!\n&quot;; <br>
while(&lt;FILE&gt;) { <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 + -