/usr/share/gap/lib/lbutil.g is in gap-libs 4r8p8-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 | ############################################################################
##
#W lbutil.g GAP Library Frank Lübeck
##
##
#Y Copyright (C) 2004 The GAP Group
##
## This file contain a few simple tools for translating text files between
## different line break conventions for Unix, DOS/Windows, MacOS.
##
############################################################################
##
#F DosUnixLinebreaks( <infile>[, <outfile> ] ) . . . . . . translate
#F text file with Unix line breaks to a file with DOS/Windows line breaks
##
#F UnixDosLinebreaks( <infile>[, <outfile> ] ) . . . . . . translate
#F text file with DOS/Windows line breaks to a file with Unix line breaks
##
#F MacUnixLinebreaks( <infile>[, <outfile> ] ) . . . . . . translate
#F text file with Unix line breaks to a file with MacOS line breaks
##
#F UnixMacLinebreaks( <infile>[, <outfile> ] ) . . . . . . translate
#F text file with MacOS line breaks to a file with Unix line breaks
##
## <infile> must be the name of an existing text file and <outfile> the
## name of a file to which the result is (over-)written.
## If not given <outfile> is the same as <infile>, so <infile> itself is
## overwritten by the result.
##
## DosUnix:
## This function first substitutes all substrings "\r\n" in infile to
## "\n" and then all "\n" to "\r\n". (So, existing "\r\n" are left alone
## and "\n" without a previous "\r" are changed to "\r\n".) The result is
## written to <outfile>.
##
## UnixDos:
## This translates "\r\n" substrings to "\n".
##
## MacUnix:
## This translates "\n" to "\r".
##
## UnixMac:
## This translates "\r" to "\n".
##
BindGlobal("DosUnixLinebreaks", function(arg)
local infile, outfile, s;
infile := arg[1];
if Length(arg) > 1 then
outfile := arg[2];
else
outfile := infile;
fi;
if not (IsString(infile) and IsString(outfile)) then
Error("arguments must be strings describing the names of the input \n",
"and output files.");
fi;
s := StringFile(infile);
if s = fail then
Error("cannot read input file.");
fi;
s := ReplacedString(s, "\r\n", "\n");
s := ReplacedString(s, "\n", "\r\n");
s := FileString(outfile, s);
if s = fail then
Error("cannot write output file.");
fi;
end);
BindGlobal("UnixDosLinebreaks", function(arg)
local infile, outfile, s;
infile := arg[1];
if Length(arg) > 1 then
outfile := arg[2];
else
outfile := infile;
fi;
if not (IsString(infile) and IsString(outfile)) then
Error("arguments must be strings describing the names of the input \n",
"and output files.");
fi;
s := StringFile(infile);
if s = fail then
Error("cannot read input file.");
fi;
s := ReplacedString(s, "\r\n", "\n");
s := FileString(outfile, s);
if s = fail then
Error("cannot write output file.");
fi;
end);
BindGlobal("UnixMacLinebreaks", function(arg)
local infile, outfile, s;
infile := arg[1];
if Length(arg) > 1 then
outfile := arg[2];
else
outfile := infile;
fi;
if not (IsString(infile) and IsString(outfile)) then
Error("arguments must be strings describing the names of the input \n",
"and output files.");
fi;
s := StringFile(infile);
if s = fail then
Error("cannot read input file.");
fi;
s := ReplacedString(s, "\r", "\n");
s := FileString(outfile, s);
if s = fail then
Error("cannot write output file.");
fi;
end);
BindGlobal("MacUnixLinebreaks", function(arg)
local infile, outfile, s;
infile := arg[1];
if Length(arg) > 1 then
outfile := arg[2];
else
outfile := infile;
fi;
if not (IsString(infile) and IsString(outfile)) then
Error("arguments must be strings describing the names of the input \n",
"and output files.");
fi;
s := StringFile(infile);
if s = fail then
Error("cannot read input file.");
fi;
s := ReplacedString(s, "\n", "\r");
s := FileString(outfile, s);
if s = fail then
Error("cannot write output file.");
fi;
end);
|