/usr/share/jed/lib/compress.sl is in jed-common 1:0.99.19-4.
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 | private variable Compressed_File_Exts
= [".gz", ".Z", ".bz2"];
private variable Compress_File_Pgms
= ["gzip",
"uncompress",
"bzip2"];
private variable Uncompress_File_Pgms
= ["gzip -dc %s",
"uncompress -c %s",
"bzip2 -dc %s"
];
private variable Auto_Compression_Mode = 0;
private define check_is_compressed (file)
{
variable ext = path_extname (file);
variable i = where (ext == Compressed_File_Exts);
if (length (i))
return i[0];
return -1;
}
private define _write_compressed_region (file, append)
{
!if (blocal_var_exists ("Auto_Compression_Mode")
or Auto_Compression_Mode)
return 0;
variable i = check_is_compressed (file);
if (i == -1) return 0;
variable cmd = sprintf ("%s > %s", Compress_File_Pgms[i], file);
if (append)
cmd = sprintf ("%s >> %s", Compress_File_Pgms[i], file);
variable status = pipe_region (cmd);
if (status != 0)
verror ("%s returned %d", cmd, status);
return 1;
}
private define write_compressed_region (file)
{
return _write_compressed_region (file, 0);
}
private define append_compressed_region (file)
{
return _write_compressed_region (file, 1);
}
private define insert_compressed_file (file)
{
!if (Auto_Compression_Mode)
return 0;
variable i = check_is_compressed (file);
if (i == -1)
return 0;
if (1 != file_status (file))
return 0;
variable cmd = sprintf (Uncompress_File_Pgms[i], file);
() = run_shell_cmd (cmd);
return 1;
}
private define read_compressed_file (file)
{
if (insert_compressed_file (file))
{
create_blocal_var ("Auto_Compression_Mode");
return 1;
}
return 0;
}
add_to_hook ("_jed_insert_file_hooks", &insert_compressed_file);
add_to_hook ("_jed_read_file_hooks", &read_compressed_file);
append_to_hook ("_jed_write_region_hooks", &write_compressed_region);
append_to_hook ("_jed_append_region_hooks", &append_compressed_region);
private define compressed_set_mode_hook (ext)
{
variable i, file;
!if (Auto_Compression_Mode)
return 0;
(file,,,) = getbuf_info ();
i = check_is_compressed (file);
if (i != -1)
{
file = file[[0:strlen(file)-strlen(ext)-2]];
mode_hook (file_type (file));
return 1;
}
return 0;
}
add_to_hook ("_jed_set_mode_hooks", &compressed_set_mode_hook);
%!%+
%\function{auto_compression_mode}
%\synopsis{Toggle auto-compression-mode}
%\usage{auto_compression_mode ([Int_Type state [,&prev_state]])}
%\description
% The \var{auto_compression_mode} function toggles the auto-compression-mode
% on or off. When on, files whose names end with \exmp{.gz}, \exmp{.Z}, or
% \exmp{.bz2} will automatically uncompressed when read in, and compressed
% when written out.
%!%-
public define auto_compression_mode ()
{
if (_NARGS)
{
if (_NARGS == 2)
{
variable prev_statep = ();
@prev_statep = Auto_Compression_Mode;
}
Auto_Compression_Mode = ();
return;
}
variable state = "OFF";
Auto_Compression_Mode = not Auto_Compression_Mode;
if (Auto_Compression_Mode)
state = "ON";
vmessage ("Auto Compression Mode: %s", state);
}
|