/usr/share/gnudatalanguage/lib/file_lines.pro is in libgnudatalanguage0 0.9.7-6.
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 | ;+
; NAME: FILE_LINES
;
; PURPOSE: return the number of lines in an ASCII file
;
; CATEGORY:
;
; CALLING SEQUENCE: nb_lines=FILE_LINES(filename)
;
; INPUTS: -- the file name, can be prefixed by the path
;
; OPTIONAL INPUTS: none
;
; KEYWORD PARAMETERS: /compress is not available now
; /noexpand_path is not available now
;
; OUTPUTS: -- the line number, in Long type
;
; OPTIONAL OUTPUTS: none
;
; COMMON BLOCKS: none
;
; SIDE EFFECTS: as is on July 2012, we still have problems related to
; WordExp() in "str.cpp", when a file is prefixed or
; suffixed by white space, FILE_TEST() returns "1" wrongly.
;
; RESTRICTIONS: only for Unix (Unix, Linux and Mac OS X) systems
;
; PROCEDURE:
;
; EXAMPLE: print, FILE_LINES("/etc/passwd")
;
; MODIFICATION HISTORY:
; - 26/07/2006: created by Alain Coulais (ARSC)
; - 30/05/2008: Michael Mueller (U of Arizona) fixed inconsistent
; handling of files that don't end in newline
; - 14/01/2010: Lucio Baggio (LATMOS/CNRS) avoided shell interaction
; - 04/07/2012: Alain
; * Correcting bug 3189065 : better message when no-existing file !
; * Correcting bug 3175753 : bad value when filename begin with number
; * managing input files list
; - 25/03/2014: Alain
; * pb when "~" in filename
; - 11/05/2015: Alain : better managment of Directories !
;
;-
; LICENCE:
; Copyright (C) 2006--2014 Alain Coulais
; This program is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 2 of the License, or
; (at your option) any later version.
;-
;
function FILE_LINES, filenames, compress=compress, noexpand_path=noexpand_path, $
verbose=verbose, test=test
;
ON_ERROR, 2 ;Return to caller
;
if KEYWORD_SET(compress) then begin
;; we consider 2 solutions : zgrep and zcat
zcommand=['']
SPAWN, 'zgrep --help', res, error, exit_status=status
if (status EQ 0) then begin
zcommand=['zgrep -Ec "$" ']
endif else begin
SPAWN, 'zcat --help', res, error, exit_status=status
if (status EQ 0) then zcommand=['zcat ','| wc -l']
endelse
if (STRLEN(zcommand[0]) EQ 0) then begin
print, 'Sorry, no solution found for Keyword COMPRESS (please help !)'
return, -1
endif
endif
;
if KEYWORD_SET(noexpand_path) then begin
print, 'Sorry, Keyword NOEXPAND_PATH is not available now.'
return, -1
endif
;
nbp=LONARR(N_ELEMENTS(filenames))
;
for ii=0, N_ELEMENTS(filenames)-1 do begin
;;
filename=filenames[ii]
if (FILE_TEST(filename) EQ 0) then begin
MESSAGE, 'Error opening file. File: '+filename
endif
if (FILE_TEST(filename,/directory) EQ 1) then begin
MESSAGE, 'Unable to open directory. File: '+filename
endif
;;
;; subsituting "~" when at first place
;; (seems to be no sense to be in another place)
;;
if STRPOS(filename,'~') EQ 0 then begin
filename=GETENV('HOME')+STRMID(filename,1)
endif
;;
if KEYWORD_SET(compress) then begin
;; we consider 2 solutions : zgrep and zcat
if N_ELEMENTS(zcommand) EQ 1 then begin
commande=zcommand[0]+filename
endif else begin
commande=zcommand[0]+filename+zcommand[1]
endelse
SPAWN, commande, resultat
nbp[ii]=(LONG((STRSPLIT(resultat,' ',/extract))[0]))
endif else begin
commande=["wc", "-l",filename]
SPAWN, commande, resultat, /NOSHELL
nbp[ii]=(LONG((STRSPLIT(resultat,' ',/extract))[0]))
;;nbp[ii]=(LONG(STRCOMPRESS(resultat,/remove_all)))(0)
;;
;; checking remaining missing bad endline
commande=["tail","-c 1",filename]
SPAWN, commande, resultat, /NOSHELL
nbp[ii] += resultat NE ''
endelse
if KEYWORD_SET(verbose) then print, filename, ' : ', nbp[ii]
endfor
;
if KEYWORD_SET(test) then STOP
;
if N_ELEMENTS(filenames) EQ 1 then return, nbp[0] else return, nbp
;
end
|