Announce

PukiWiki contents have been moved into SONOTS Plugin (20070703)

13.neonote

ノート線印刷

投稿者s1080134
作成日?
最終更新日2003/09/04 (学部4年夏休み)
言語perl
Table of Contents

説明

Neoclassic というサークルの方が作った、ノートの線を印刷してノート代をケチろう、neonote の改変です。 perl スクリプトから tex コードを作成し、コンパイルして印刷しているようです。

元々はファイル出力が dvi か ps ファイルしかできなかったのですが、 tex ファイルも出力できるようにしました。

後記:印刷部は会津大学依存です。他は必要とされるコマンドがあれば使えます。

書式

使い方は以下のようになっています。

% ./neonote
   NeoNote(TM): Print the note paper              (c)Neoclassic 
   Usage:   %neonote [options]
              options:      only number = Number of papers
                            -print  = Print (default)
                            -ps = Output as ps file
                            -dvi = Output as dvi file
                            -tex= Output as tex file
                            -P [printername]  = Specify the printer which you want to use.
                            -nv  = Not vervose
                            -date= Output with Date
                            -l [num] = Make [num] lines (default 33 line)
                            -noboth = Print to one side only
                            -str [string] = [string] outputs in last line
                            -help, -h, --help = Show this Usage

のようになっているっぽいです。少しオプションも変更させてもらいました。

ソースコード

#!/usr/local/bin/perl --  # -*-Perl-*-
'di';
'ig00';
# neonote.pl	-- KATSUO
#  modified by Naotoshi Seo, s1080134. (-ps, -tex, -dvi, -date (Y2K problem?))
# $Log$
$RCSHEADER = '$Header$';	#'
'$Revision$'  =~ /^\$\w+:\s+([.1234567890]+)\s+\$$/;	#'
$VERSION = $1;

########################################################
$| = 1;
	# These next few lines are legal in both Perl and Nroff.


# Globals
$NO_VERBOSE    = 0;		# output print status?
$COPY_NUM      = 1;		# number of output paper
$PRINT_TYPE    = "ps";		# output type
$TAIL_STRING   = "Neoclassic";	# output string in last line
$BOTH_SIDE     = "bothside";	# output as bothside?
$HOLISONTAL_LINE = 33;
$START_LINE      = 7;
$LINE_SPACE      = 7;
$XEROX_PRINTER = 1;
$WITH_DATE = 0;
$DAY=$MON=$YEAR=' ';
$FILE_OUTPUT = 0;
$OUTPUT_FILENAME = '';
$printer = '';

# #define
$LPR_COM       = "lpr";
$PLATEX_COM    = "platex";
$DVIPS_COM     = "dvips -q";
# Delete file list used as temporally file
@dellist       = ("/tmp/texput.aux", "/tmp/texput.dvi", "/tmp/texput.log");


format STDOUT =
\documentclass[a4paper]{article}
\usepackage{times}
\setlength{\parindent}{0mm}
\setlength{\textwidth}{190mm}
\setlength{\textheight}{280mm}
\newlength{\mypaperwidth}
\newlength{\mypaperheight}
\setlength{\mypaperwidth}{210mm}
\setlength{\mypaperheight}{297mm}
\setlength{\oddsidemargin}{0.5\mypaperwidth}
\addtolength{\oddsidemargin}{-1in}
\addtolength{\oddsidemargin}{-0.5\textwidth}
\setlength{\evensidemargin}{\oddsidemargin}
\setlength{\topmargin}{0.5\mypaperheight}
\addtolength{\topmargin}{-1in}
\addtolength{\topmargin}{-0.5\textheight}
\setlength{\footskip}{\topmargin}
\setlength{\headheight}{0mm}
\setlength{\headsep}{0mm}
\begin{document}
\pagestyle{empty}
\setlength{\unitlength}{1mm}

\begin{picture}(190,280)(0,0)
\linethickness{0.2mm}
\put(0,256){\line(1,0){190}}
\put(0,245){\line(1,0){190}}
\put(0,7){\line(1,0){190}}
\multiput(0,245)(47.5,0){5}{\line(0,-1){0.6}}
\multiput(0,7)(47.5,0){5}{\line(0,1){0.6}}
\multiput(-1,210)(0,-35){6}{\circle*{0.02}}
\multiput(191,210)(0,-35){6}{\circle*{0.02}}
\put(135,256){\makebox(45,7)[r]{\small {\sf DATE@<<<<<<<<<<<<<<<$\cdot$@<<<<<<<<<<<<<<<$\cdot$@<<<<<<<<<<<<<<<}}}
$YEAR,$MON,$DAY
\linethickness{0.005mm}
\multiput(0,@<<<<)(0,@<<<<){@<<<<<<<}{\line(1,0){190}}
$START_LINE,$LINE_SPACE,$HOLISONTAL_LINE
\multiput(0,245)(5.9375,0){33}{\line(0,-1){0.4}}
\multiput(0,7)(5.9375,0){33}{\line(0,1){0.4}}
\put(0,0){\makebox(190,7)[]{\sf @>>>>>>>>>>>>>>>>>>>>>}}
$TAIL_STRING
\end{picture}
\newpage
\begin{picture}(190,280)(0,0)
\linethickness{0.2mm}
\put(0,256){\line(1,0){190}}
\put(0,245){\line(1,0){190}}
\put(0,7){\line(1,0){190}}
\multiput(0,245)(47.5,0){5}{\line(0,-1){0.6}}
\multiput(0,7)(47.5,0){5}{\line(0,1){0.6}}
\multiput(-1,210)(0,-35){6}{\circle*{0.02}}
\multiput(191,210)(0,-35){6}{\circle*{0.02}}
\put(135,256){\makebox(45,7)[r]{\small {\sf DATE@<<<<<<<<<<<<<<<$\cdot$@<<<<<<<<<<<<<<<$\cdot$@<<<<<<<<<<<<<<<}}}
$YEAR,$MON,$DAY
\linethickness{0.005mm}
\multiput(0,@<<<<)(0,@<<<<){@<<<<<<<}{\line(1,0){190}}
$START_LINE,$LINE_SPACE,$HOLISONTAL_LINE
\multiput(0,245)(5.9375,0){33}{\line(0,-1){0.4}}
\multiput(0,7)(5.9375,0){33}{\line(0,1){0.4}}
\put(0,0){\makebox(190,7)[]{\sf @>>>>>>>>>>>>>>>>>>>>>}}
$TAIL_STRING
\end{picture}
\end{document}
.

# Start Main() routine
# Search command options...
for($i = 0; $i <= $#ARGV; $i++ ){
    if( $ARGV[$i] eq '-print' ){
	$PRINT_TYPE = "ps"
    }elsif( $ARGV[$i] eq '-ps' ){
	$FILE_OUTPUT = 1;
	$PRINT_TYPE = "ps"
    }elsif( $ARGV[$i] eq '-dvi' ){
	$FILE_OUTPUT = 1;
	$PRINT_TYPE = "dvi";
    }elsif( $ARGV[$i] eq '-tex' ){
	$FILE_OUTPUT = 1;
	$PRINT_TYPE = "tex";
    }elsif( $ARGV[$i] eq '-noboth' ){
	$BOTH_SIDE = '';
    }elsif( $ARGV[$i] eq '-nv' ){
	$NO_VERBOSE = 1;
    }elsif( $ARGV[$i] eq '-date' ){
	$WITH_DATE = 1;
    }elsif( $ARGV[$i] =~ /^-P(.*)/ ){
	if( $ARGV[$i] eq '-P' ){
	    $i++;
	    $printer = $ARGV[$i];
	}else{
	    $printer = $1;
	}
    }elsif( $ARGV[$i] eq '-str' ){
	$i++;
	$TAIL_STRING = $ARGV[$i];
    }elsif( $ARGV[$i] eq '-l' ){
	$i++;
	if( $ARGV[$i] =~ /^\d*/ ){
	    $HOLISONTAL_LINE = $ARGV[$i];
	}else{
	    print STDERR "NeoNote: Illegal option \"$ARGV[$i-1]\".\n";
	    print STDERR "NeoNote: It is not a number \"$ARGV[$i]\".\n";
	    print STDERR "NeoNote: see the usage with: neonote -h/-help/--help\n";
	exit;
	}
    }elsif( $ARGV[$i] =~ /^\d{1,4}/ ){
	$COPY_NUM = $ARGV[$i];
    }elsif( $ARGV[$i] eq '-h' || $ARGV[$i] eq '--h' || $ARGV[$i] =~  /^-[-]*help/  ){
	&printUsage();
	exit;
    }else{
	print STDERR "NeoNote: Illegal option \"$ARGV[$i]\".\n";
	print STDERR "NeoNote: see the usage with: neonote -h/-help/--help\n";
	exit;
    }
}

if( $printer eq '' ){
    $printer = &printerDetect();
    if( $printer eq '' ){
	print STDERR "NeoNote: No supported printer in this room\n";
	exit;
    }
}

# calculate the line space
if( $HOLISONTAL_LINE == 0 ){	# To avoid division error 
    $HOLISONTAL_LINE = 1;
}
$LINE_SPACE = (238) / $HOLISONTAL_LINE;
$START_LINE += $LINE_SPACE;

if($HOLISONTAL_LINE % 2 != 0 ){	# 奇数本の場合一番上の線が重なるのでそれを防ぐ
    $HOLISONTAL_LINE--;
}


if( $WITH_DATE == 1){
    ($sec,$min,$hour,$DAY,$MON,$YEAR,$wday,$yday,$isdst) = localtime(time);
    $YEAR += 1900;
    $YEAR = "\\hspace{7mm}".$YEAR;
    $MON = "\\hspace{4mm}".$MON;
    $DAY = "\\hspace{4mm}".$DAY;
}else{
    $YEAR = "\\hspace{10mm}";
    $MON = "\\hspace{10mm}";
    $DAY = '';
}


if( $XEROX_PRINTER == 1){
    $lpr_command = "$LPR_COM -P$printer -t -1 $BOTH_SIDE,copies=$COPY_NUM";
}
#else{
#    $lpr_command = "$LPR_COM -P$printer -C\"filetype=$PRINT_TYPE,duplex,copies=$COPY_NUM\"";
#}

$olddir = $ENV{'PWD'};
if( chdir("/tmp") ){		# change the directory :/tmp:
    if( $FILE_OUTPUT != 1){
	print STDERR "-----------------------------\n";
	print STDERR "Printer = $printer\n";
	print STDERR "printout $COPY_NUM papers\n";
	print STDERR "-----------------------------\n";
	print STDERR "TeX compiling.";
	open(STDOUT,"|$PLATEX_COM > /dev/null ");
	print STDERR ".";
	write;
	print STDERR "..";
	close(STDOUT);
	print STDERR ".";

	if( $PRINT_TYPE eq "ps"){
	    print STDERR ".\nPostScript generating:";
	    system("$DVIPS_COM /tmp/texput.dvi | $lpr_command");
	    print STDERR "\n";
	}
	#else{
	#    print STDERR ".\n";
	#    system("echo /tmp/texput.dvi | $lpr_command");
	#}
    }else{
	if( $PRINT_TYPE eq "tex"){
	    print STDERR "-----------------------------\n";
	    print STDERR "Printer = $printer\n";
	    print STDERR "output as tex file\n";
	    print STDERR "-----------------------------\n";
	    $OUTPUT_FILENAME = "$olddir/neonote.tex";
	    open(STDOUT,"> $OUTPUT_FILENAME");
	    print STDERR "[$OUTPUT_FILENAME]\n";
	    write;
	    close(STDOUT);
	}
	else{
	    print STDERR "-----------------------------\n";
	    print STDERR "Printer = $printer\n";
	    print STDERR "output as file\n";
	    print STDERR "-----------------------------\n";
	    print STDERR "TeX compiling.";
	    open(STDOUT,"|$PLATEX_COM > /dev/null ");
	    print STDERR ".";
	    write;
	    print STDERR "..";
	    close(STDOUT);
	    print STDERR ".";
	    
	    if( $PRINT_TYPE eq "ps"){
		$OUTPUT_FILENAME = "$olddir/neonote.ps";
		print STDERR ".\nPostScript generating:";
		system("$DVIPS_COM /tmp/texput.dvi > $OUTPUT_FILENAME");
		print STDERR "[$OUTPUT_FILENAME]\n";
	    }elsif( $PRINT_TYPE eq "dvi"){
		$OUTPUT_FILENAME = "$olddir/neonote.dvi";
		print STDERR ".\n";
		rename("/tmp/texput.dvi", $OUTPUT_FILENAME);
		print STDERR ">[$OUTPUT_FILENAME]\n";
	    }
	}
    }
}else{
    print STDERR "Can\'t change the directory to /tmp.\n";
    exit;
}
# delete temporally files
unlink(@dellist);
chdir($olddir);
print STDERR "done\n";

exit;




# Sub routines

# Find Printer in the room
sub printerDetect{
    local($printername,$host);
    
    $host = $ENV{'HOST'};
    
    if( $host =~ /^std1ss(\d){1,2}/ ){ # nlbp4
	$printername = "std1pr1";
	$XEROX_PRINTER = 0;

    }elsif( $host =~ /^std2ss(\d){1,2}/ ){ # nlbp6
	$printername = "std2pr1";
	$XEROX_PRINTER = 0;

    }elsif( $host =~ /^std3ss(\d){1,2}/ || $host =~ /std3sgi1/ ){ # nlbp29
	$printername = "std3pr1";
	$XEROX_PRINTER = 0;

    }elsif( $host =~ /^std4ss(\d){1,2}/ || $host =~ /std4sgi1/ ){ # nlbp31
	$printername = "std4pr1";
	$XEROX_PRINTER = 0;

    }elsif( $host =~ /std5sgi(\d){1,2}/ ){ # std5pr1
	$printername = "std5pr1";
	$XEROX_PRINTER = 1;

    }elsif( $host =~ /^std6sgi(\d){1,2}/ ){ # std6pr1
	$printername = "std6pr1";
	$XEROX_PRINTER = 1;

    }elsif( $host =~ /^cai1ss(\d){1,2}/ ){ # nlbp8
	$printername = "nlbp8";
	$XEROX_PRINTER = 0;

    }elsif( $host =~ /^cai2ss(\d){1,2}/ ){ # nlbp10
	$printername = "nlbp10";
	$XEROX_PRINTER = 0;

    }elsif( $host =~ /^hdw1ss(\d){1,2}/ ){ # hdw1pr1
	$printername = "hdw1pr1";
	$XEROX_PRINTER = 1;

    }elsif( $host =~ /^hdw2ss(\d){1,2}/ ){ # hdw2pr1
	$printername = "hdw2pr1";
	$XEROX_PRINTER = 1;

    }elsif( $host =~ /^hdw3hp(\d){1,2}/ ){ # hdw3pr1
	$printername = "hdw3pr1";
	$XEROX_PRINTER = 1;

    }elsif( $host =~ /^hdw4hp(\d){1,2}/ ){ # hdw4pr1
	$printername = "hdw4pr1";
	$XEROX_PRINTER = 1;

    }elsif( $host =~ /^lml1sn(\d){1,2}/ ){ # smlbp0(?)
	$printername = "smlbp0";
	$XEROX_PRINTER = 0;

    }elsif( $host =~ /^lml2sn(\d){1,2}/ ){ # smlbp0(?)
	$printername = "smlbp0";
	$XEROX_PRINTER = 0;

    }elsif( $host =~ /^pross(\d)*/ ){ # pross*
	$printername = "locallbp";
	$XEROX_PRINTER = 0;

    }else{
	$printername = '';
    }

    return $printername;
}



# Output usage
sub printUsage{
    print STDERR "NeoNote(TM): Print the note paper              (c)Neoclassic \n";
    print STDERR "Usage:   %neonote [options]\n";
    print STDERR "           options:      only number = Number of papers\n";
    print STDERR "                         -print  = Print (default)\n";
    print STDERR "                         -ps = Output as ps file\n";
    print STDERR "                         -dvi = Output as dvi file\n";
    print STDERR "                         -tex= Output as tex file\n";
    print STDERR "                         -P [printername]  = Specify the printer which you want to use.\n";
    print STDERR "                         -nv  = Not vervose\n";
    print STDERR "                         -date= Output with Date\n";
    print STDERR "                         -l [num] = Make [num] lines (default 33 line)\n";
    print STDERR "                         -noboth = Print to one side only\n";
    print STDERR "                         -str [string] = [string] outputs in last line\n";
    print STDERR "                         -help, -h, --help = Show this Usage\n";
    print STDERR "\n";
}