This file is indexed.

/usr/lib/grass64/etc/gm/mapprint.tcl is in grass-gui 6.4.3-3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
###############################################################
# mapprint.tcl - GRASS GIS Manager procedures for postscript and
# lpr printing, and pdf and eps output
# January 2006 Michael Barton, Arizona State University
# COPYRIGHT:	(C) 1999 - 2006 by the GRASS Development Team
#
#		This program is free software under the GNU General Public
#		License (>=v2). Read the file COPYING that comes with GRASS
#		for details.
#
##########################################################################


namespace eval psprint {
	variable docht
	variable docwd
	variable epsfile
	variable format
	variable gsdevices
	variable gsexists
	variable gspresent
	variable gsstate
	variable ldevice
	variable mbottom
	variable mleft
	variable mright
	variable mtop
	variable orient
	variable paper
	variable paper_preset
	variable paper_presetlv
	variable pdffile
	variable pght
	variable pgwd
	variable printer
	variable printmode
	variable res
	variable tmppngfile
	variable tmpppmfile
	variable tmppsfile 
	variable tmpscript 
	variable PPap 
	variable PVar 
	variable PView
	variable PWid 
	global array can ;# mon
}


#initialize variables
proc psprint::init { } {
	variable pgwd
	variable pght
	variable docwd
	variable docht
	variable paper
	variable paper_preset
	variable paper_presetlv
	variable printmode
	variable printer
	variable gsexists
	variable orient
	variable mleft
	variable mright
	variable mtop
	variable mbottom
	variable gsstate
	variable ldevice
	variable gsdevices
	variable res
	global mon
	global mingw

	set psprint::pgwd 8.5
	set psprint::pght 11
	set psprint::docwd 7.5
	set psprint::docht 10
	set psprint::paper "preset"
	set psprint::paper_preset "letter"
	set psprint::paper_presetlv ""
	set psprint::printer ""
	set psprint::gsexists 1
	set psprint::orient "landscape"
	set psprint::res 300
	set psprint::mleft 1
	set psprint::mright 1
	set psprint::mtop 1
	set psprint::mbottom 1
	
	# default is lpr printing
	set printmode "lpr"

	# check for ghostscript	
	# switch to native windows version of ghostscript if runing wingrass
	if { $mingw == 1 } {
		set cmd "gswin32c"
	} else {
		set cmd "gs"
	}

	#enable additional printing options if Ghostscript available
	if {![catch {set input [exec $cmd -help]} error]} {
		regexp ".*Available devices:(.*)Search path:" $input string gsdevices 
		set gsstate "normal"
		regsub -all {   } $gsdevices { } gsdevices
		regsub -all { } $gsdevices \n gsdevices
		regsub -all \n\n $gsdevices \n gsdevices
	} else {
		set gsdevices "none available"
		set gsstate "disabled"
		#set printmode "eps"
		tk_messageBox -type ok -icon error -message [G_msg "Ghostscript not available"]
	}
}	

# calculate paper size and document size on paper (all in inches)  
proc psprint::paper { } {
	variable paper
	variable paper_preset
	variable printmode
	variable pgwd
	variable pght
	variable mleft
	variable mright
	variable mtop
	variable mbottom
	variable docwd
	variable docht
	variable orient
    
	# set paper dimensions
	if { $paper == "preset" } {
		switch $paper_preset {
			"11x17" {
				set pgwd 11
				set pght 17
			}
			"ledger" {
				set pgwd 17
				set pght 11
			}
			"legal" {
				set pgwd 8.5
				set pght 14
			}
			"letter" {
				set pgwd 8.5
				set pght 11
			}
			"a0" {
				set pgwd 33.0556
				set pght 46.7778
			}
			"a1" {
				set pgwd 23.3889
				set pght 33.055
			}
			"a2" {
				set pgwd 16.5278
				set pght 23.3889
			}
			"a3" {
				set pgwd 11.6944
				set pght 16.5278 
			}
			"a4" {
				set pgwd 8.26389 
				set pght 11.6944
			}
		}
	}

	set docwd [expr $pgwd - $mright - $mleft]
	set docht [expr $pght - $mtop - $mbottom]
	
	if { $orient == "landscape" && $printmode == "pdf" } {
		set docwd [expr $docwd + 2]
		set docht [expr $docht + 2]
	} else {
		set docwd [expr $docwd + 1]
		set docht [expr $docht + 1]
	}
		
	update
	
}

# initialize tmpfiles for poscript printing
proc psprint::init_tmpfiles { } {
	variable tmpscript
	variable tmppsfile
	variable tmppngfile

	# get temporary file for postscript printing
	set pid [ pid ]
	if {[catch {set tmppsfile [ exec g.tempfile pid=$pid ]} error]} {
		GmLib::errmsg $error [G_msg "Error creating tempfile"]
	}

	append tmppsfile ".ps"
	set pid [ pid ]
    
	if {[catch {set tmppngfile [ exec g.tempfile pid=$pid ]} error]} {
		GmLib::errmsg $error [G_msg "Error creating tempfile"]
	}
	    append tmppngfile ".png"
}

# show gs printer devices in output window
proc psprint::show_devices { } {
	variable gsdevices

	set ah [monitor_annotation_start {} "Ghostscript Output Devices" {}]
	monitor_annotate $ah $gsdevices
}


# create printer options window
proc psprint::window { cm cv cx cy } {
	variable pgwd
	variable pght
	variable paper
	variable paper_preset
	variable paper_presetlv
	variable printmode
	variable printer
	variable gsexists
	variable epsfile
	variable pdffile
	variable orient
	variable res
	variable pgwd
	variable pght
	variable mleft
	variable mright
	variable mtop
	variable mbottom
	variable gspresent
	variable ldevice
	variable gsdevices
	variable gsstate
	global mon
	
	set mon $cm
	    
	# check if opened
	if { [winfo exists .printwin] } {
		wm deiconify .printwin
		raise .printwin
		return
	}
	
	set PW [toplevel .printwin]
	wm title $PW [G_msg "Postscript and LPR printing of map display"]
	
	# Left part paper + output
	set PWid(left) [ frame $PW.left -padx 5 -pady 5]  
	pack $PWid(left) -side left -anchor w
	
	# paper size, scale
	set PWid(paper) [ frame $PWid(left).paper]  
	pack $PWid(paper) -side top -anchor w
	
	    # preset paper sizes (from ghostscript)
	set row [ frame $PWid(paper).row1 ]
	radiobutton $row.a -variable psprint::paper -value "preset" \
		-highlightthickness 0 
	Label $row.b -anchor w -text [G_msg "Preset paper type"]
	ComboBox $row.c -label "" -width 20  -textvariable psprint::paper_preset \
		-values {"letter" "a4" "legal" "11x17" "a3" "ledger" "a0" "a1" "a2" } \
		-modifycmd psprint::paper \
		-labels [list [G_msg "letter"] [G_msg "A4"] [G_msg "legal"] [G_msg "11x17"] [G_msg "A3"] [G_msg "ledger"] [G_msg "A0"] [G_msg "A1"] [G_msg "A2"]] \
		-labelsvariable psprint::paper_presetlv
	pack $row.a $row.b $row.c -side left;
	pack $row -side top -fill x -expand no -anchor n
	
	# custom paper sizes
	set row [ frame $PWid(paper).row2 ]
	radiobutton $row.a -variable psprint::paper -value "custom" \
		-highlightthickness 0
	Label $row.b -anchor w -text [G_msg "Custom paper size"]
	Label $row.c -anchor w -text [G_msg "width:"]
	Entry $row.d -width 10 -textvariable psprint::pgwd
	Label $row.e -anchor w -text [G_msg "  height:"]
	Entry $row.f -width 10 -textvariable psprint::pght 
	pack $row.a $row.b $row.c $row.d $row.e $row.f -side left;
	pack $row -side top -fill x -expand no -anchor n
	
	#margins
	set row [ frame $PWid(paper).row3]
	Label $row.a -anchor w -text [G_msg "Margins  left:"]
	Entry $row.b -width 10 -textvariable psprint::mleft 
	Label $row.c -anchor w -text [G_msg " right:"] 
	Entry $row.d -width 10 -textvariable psprint::mright 
	Label $row.e -anchor w -text [G_msg " top:"]
	Entry $row.f -width 10 -textvariable psprint::mtop 
	Label $row.g -anchor w -text [G_msg " bottom:"]
	Entry $row.h -width 10 -textvariable psprint::mbottom 
	
	pack $row.a $row.b $row.c $row.d $row.e $row.f $row.g $row.h -side left;
	pack $row -side top -fill x -expand no -anchor n
	
	# portrait or landscape
	set row [ frame $PWid(paper).row4 ]
		LabelEntry $row.a -label [G_msg "Resolution (dpi) for printing and PDF "] \
		-textvariable psprint::res -width 4
	Label $row.b -anchor w -text "  "
	radiobutton $row.c -variable psprint::orient -value "landscape" \
		-text "landscape mode" -highlightthickness 0
	radiobutton $row.d -variable psprint::orient -value "portrait" \
		-text "portrait mode  " -highlightthickness 0
	pack $row.a $row.b $row.c $row.d -side left;
	pack $row -side top -fill x -expand no -anchor n
	
	# output options
	set PWid(output) [ frame $PWid(left).output ]  
	pack $PWid(output) -side top -anchor w
	
	# LPR printer
	set row [ frame $PWid(output).lpr ]
	radiobutton $row.a -variable psprint::printmode -value "lpr" \
		-highlightthickness 0
	Label $row.b -anchor w -text [G_msg "Print on LPR printer"]
	pack $row.a $row.b -side left;
	pack $row -side top -fill x -expand no -anchor n
	
	# Postscript printer
	set row [ frame $PWid(output).psprinter ]
	radiobutton $row.a -variable psprint::printmode -value "psprint" \
		-state $psprint::gsstate -highlightthickness 0
	Label $row.b -anchor w -text [G_msg "Print on postscript device* "] \
		-state $psprint::gsstate
	ComboBox $row.c -width 20 -textvariable psprint::printer  \
		-values $psprint::gsdevices -editable 0 -entrybg white
	pack $row.a $row.b $row.c -side left;
	pack $row -side top -fill x -expand no -anchor n
	
	# PDF file
	set row [ frame $PWid(output).pdffile]
	radiobutton $row.a -variable psprint::printmode -value "pdf" \
		-state $psprint::gsstate -highlightthickness 0 
	Label $row.b -anchor w -text [G_msg "Save to PDF file*              "]  \
		-state $psprint::gsstate 
	Entry $row.c -width 30 -textvariable psprint::pdffile  -state $gsstate
	Button $row.d -text [G_msg "Browse"]  -command { set psprint::pdffile \
		[tk_getSaveFile -initialdir $Gm::last_directory -title "Output PDF file" -defaultextension ".pdf"]} \
		-state $psprint::gsstate
	pack $row.a $row.b $row.c $row.d -side left;
	pack $row -side top -fill x -expand no -anchor n
	
	# EPS file
	set row [ frame $PWid(output).epsfile ]
	radiobutton $row.a -variable psprint::printmode -value "eps" \
		-highlightthickness 0 
	Label $row.b -anchor w -text [G_msg "Save to EPS file               "] 
	Entry $row.c -width 30 -textvariable psprint::epsfile 
	Button $row.d -text [G_msg "Browse"] -command { set psprint::epsfile \
	       [ tk_getSaveFile -initialdir $Gm::last_directory -title "Output EPS file" -defaultextension ".eps"] }
	pack $row.a $row.b $row.c $row.d -side left;
	pack $row -side top -fill x -expand no -anchor n
	
	set row [ frame $PWid(output).gsmessage ]
	Label $row.a -anchor w -text [G_msg "*requires ghostscript to be installed and in path"]
	pack $row.a -side bottom;
	pack $row -side top -fill x -expand yes -anchor center
	
	# Buttons 
	set but [ frame $PWid(left).buttons ]  
	pack $but -side top
	
	Button $but.print -text [G_msg "Print"] -command "update; psprint::print $cv"
	Button $but.close -text [G_msg "Close"] -command { destroy .printwin }
	pack $but.print $but.close -side left 

}

proc psprint::print { cv } {
	variable paper
	variable paper_preset
	variable printmode
	variable printer
	variable gsexists
	variable res
	variable format
	variable orient
	variable epsfile
	variable pdffile
	variable tmppsfile 
	variable tmppngfile
	variable pgwd
	variable pght
	variable docwd
	variable docht
	variable mright
	variable mleft
	variable mtop
	variable mbottom
	global gmpath
	global mon
	global mingw
    
	psprint::init_tmpfiles
   	psprint::paper
   	update
	set landscape $gmpath/landscap.ps
    
	#change doc size to points
	set cdocwd [expr $docwd * 72]
	set cdocht [expr $docht * 72]
    
 	# set paper size for postscript printer and pdf files
	set w [expr round($pgwd * $res)]
	set h [expr round($pght * $res)]
	set format "-g$w"
	append format "x$h"
	
	# switch to native windows version of ghostscript if runing wingrass
	if { $mingw == 1 } {
		set cmd "gswin32c"
	} else {
		set cmd "gs"
	}
		
		
   
	if { $orient == "portrait" } {
		$cv postscript -pageheight $cdocht -pagewidth $cdocwd \
			-file $tmppsfile
	} else {
		$cv postscript -rotate 1 -pageheight $cdocht -pagewidth $cdocwd \
			-file $tmppsfile			
	}	
	
	
	after 500

	# lpr printing		
 	if { $printmode == "lpr" } {
 		if {[catch {exec lpr -o position=center $tmppsfile } error]} {
			GmLib::errmsg $error
		}
	}

	# postsript printing via ghostsript
	if { $printmode == "psprint" && $printer != "" } {
		if {[catch {exec $cmd  $format -sDEVICE#$printer -r$res -sNOPAUSE -dBATCH -- $tmppsfile} error]} {
			GmLib::errmsg $error
		}
		 
	}

	# output to pdf file via ghostscript	
	if { $printmode == "pdf" && $pdffile != "" } {
		if {[catch {exec $cmd  $format -sDEVICE#pdfwrite -r$res -sNOPAUSE -sOutputFile#$pdffile -dBATCH -- $tmppsfile} error]} {
			GmLib::errmsg $error
		}
		set Gm::last_directory [file dirname $pdffile]
	}

	# output to eps file
	if { $printmode == "eps" && $epsfile != "" } {
		if { $orient == "portrait" } {
			$cv postscript -file "$epsfile"
		} else {
			$cv postscript -file "$epsfile" -rotate 1
		}
		set Gm::last_directory [file dirname $epsfile]
	}
	
	psprint::clean
}


proc psprint::set_option { key value } {
	variable PWid 
	variable PVar 
	variable PPap 
	variable PView
    
	set PVar($key) $value

}

# Delete temporary files
proc psprint::clean {  } {
	variable tmppsfile
	variable tmppngfile
    
	catch {file delete $tmppsfile}
	catch {file delete $tmppngfile}

}