File: banner.sh_init

package info (click to toggle)
cti-ifhp 2.1.8-2
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 932 kB
  • ctags: 845
  • sloc: ansic: 6,036; sh: 1,524; makefile: 318
file content (136 lines) | stat: -rwxr-xr-x 2,818 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!_SHELL_
# shell for banner printing
# This is a simple minded banner printer that has been umm... ahh...
# "borrowed" from the CTI print spooler software,
# and has been suitably mangled/hacked/slashed/pruned and abused
# to run as a GAWK shell script
#
# Input to the script are lines of the form
# key: field key: field
# valid keys are:
#   User: user name
#   Host: host name
#   Job:  job title name
#
echo $0 "$@" 1>&2
/usr/local/bin/awk '
BEGIN{
	xpos = 0;
	ypos = 0;
	incr = 0;
	margins="\033&l0u0Z"
	lightbar="\033*c1800a100b45g2P"
	darkbar="\033*c1800a100b25g2P"
	fontchange="\033(8U\033(s1p%dv0s0b4148T" 
	position= "\033*p%dx%dY"
	UEL="\033%-12345X"
	UELPJL="\033%-12345X@PJL \r\n"
	PCLRESETSTR="\033E"
	CRLFSTR="\033&k2G"
}
function moveto( x, y ){
	printf position, x, y ;
}
function fontsize( size ){
	incr = (size*300*1.1)/72;
	printf fontchange, size;
}
function outline(s){
	printf "%s", s
}
function argline(key,value){
	if( value != "" ){
		textline( key , 1, 0 );
		textline( value, 0, 1 );
	}
}

function textline( line, start, end ){
	if( start ){
		moveto( xpos, ypos );
	}
	printf "%s", line
	if( end ){
		ypos += incr;
	}
}
function pcl_banner(){
    outline(UEL);
    outline(PCLRESETSTR);
    outline(UELPJL);
	outline(CRLFSTR);
	outline(margins);

	# do light bar 
	xpos = 0; ypos = 0;
	moveto( xpos, ypos );
	outline( lightbar );
	ypos += 100;

	# set font size 
	fontsize( 24 );
	ypos += incr;
	moveto( xpos, ypos );

	for( key in arg ){
		argline(key,arg[key])
	}

	# smaller font 
	fontsize( 12 );

	moveto(xpos,ypos);
	"date" | getline date;
	textline( "Date: ", 0, 1 );
	textline( date, 0, 1 );
	
	moveto( xpos, ypos );
	outline( darkbar );

	outline(FFEED);
    outline(UEL);
    outline(PCLRESETSTR);
} 
{
	# line is broken up at word:
	line = $0;
	# print "BANNER" $0 >/dev/stderr
	/* skip blank or bad formatted lines */
	firstentry = 0;
	while( line != "" ){
		printf "Line \"%s\"\n",line
		p = match( line, /^[ \t][ \t]*/);
		while( p ){
			printf "p %d RSTART %d\n",p, RSTART;
			line = substr(line,RSTART+p);
			p = match( line, /^[ \t][ \t]*/);
		}
		p = match( line, /^[A-Za-z][A-Za-z]*:/ );
		if( p == 0 ) break;
		key = substr(line,RSTART,RLENGTH);
		line = substr(line,RSTART+RLENGTH);
		printf "Key \"%s\" Line \"%s\"\n",key,line
		# get the next colon
		p = match( line, /[A-Za-z][A-Za-z]*:/ );
		if( p == 0 ){
			value = line;
			line = "";
		} else {
			# back up from the colon
			value = substr(line,1,RSTART-1);
			line = substr(line,RSTART);
		}
		lkey = tolower(key);
		arg[lkey] = " " value;
		if( firstentry == 0 && arg["user"] == "" && arg["host"] == "" && arg["job"] == "" ){
			arg["class:"] = " " key;
			arg["user:"] = " " value;
			arg[lkey] = "";
		}
		firstentry = 1;
		printf "Key \"%s\" value \"%s\" line\n",key,value
	}
	pcl_banner();
	quit;
}
'