Data update

This commit is contained in:
Ingy döt Net 2026-02-01 16:33:20 -08:00
parent 5150844a7d
commit 4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions

View file

@ -1,55 +0,0 @@
with Ada.Command_Line, Ada.Sequential_IO, Ada.Directories;
procedure Truncate_File is
type Byte is mod 256;
for Byte'Size use 8;
package Byte_IO is new Ada.Sequential_IO(Byte);
function Arg(N: Positive) return String renames Ada.Command_Line.Argument;
function Args return Natural renames Ada.Command_Line.Argument_Count;
begin
-- give help output if neccessary
if Args < 2 or else Args > 3 then
raise Program_Error
with "usage: truncate_file <filename> <length> [<temp_file>]";
end if;
-- now do the real work
declare
File_Name: String := Arg(1);
Temp_Name: String := (if Args = 2 then Arg(1) & ".tmp" else Arg(3));
-- an Ada 2012 conditional expression
File, Temp: Byte_IO.File_Type;
Count: Natural := Natural'Value(Arg(2));
Value: Byte;
begin
-- open files
Byte_IO.Open (File => File, Mode => Byte_IO.In_File, Name => File_Name);
Byte_IO.Create(File => Temp, Mode => Byte_IO.Out_File, Name => Temp_Name);
-- copy the required bytes (but at most as much as File has) from File to Temp
while (not Byte_IO.End_Of_File(File)) and Count > 0 loop
Byte_IO.Read (File, Value);
Byte_IO.Write(Temp, Value);
Count := Count - 1;
end loop;
-- close files
Byte_IO.Close(Temp);
Byte_IO.Close(File);
if Count = 0 then -- File was at least Count bytes long
-- remove File and rename Temp to File
Ada.Directories.Delete_File(Name => File_Name);
Ada.Directories.Rename(Old_Name => Temp_Name, New_Name => File_Name);
else -- File was too short
-- remove Temp and leave File as it is, output error
Ada.Directories.Delete_File(Name => Temp_Name);
raise Program_Error
with "Size of """ & File_Name & """ less than " & Arg(2);
end if;
end;
end Truncate_File;

View file

@ -1,28 +1,16 @@
import system'io;
import extensions;
extension fileOp : File
public Program()
{
set Length(int len)
{
auto stream := FileStream.openForEdit(self);
stream.Length := len;
stream.close()
}
}
public program()
{
if (program_arguments.Length != 3)
{ console.printLine("Please provide the path to the file and a new length"); AbortException.raise() };
if (Program_arguments.Length != 3)
{ Console.printLine("Please provide the path to the file and a new length"); AbortException.raise() };
auto file := File.assign(program_arguments[1]);
var length := program_arguments[2].toInt();
var length := Program_arguments[2].toInt();
ifnot(file.Available)
{ console.printLine("File ",file," does not exist"); AbortException.raise() };
if:not(file.Available)
{ Console.printLine("File ",file," does not exist"); AbortException.raise() };
file.Length := length
}

View file

@ -1,3 +0,0 @@
Function Truncate-File(fname) {
$null | Set-Content -Path "$fname"
}

View file

@ -1,39 +0,0 @@
Sub truncate(fpath,n)
'Check if file exist
Set objfso = CreateObject("Scripting.FileSystemObject")
If objfso.FileExists(fpath) = False Then
WScript.Echo fpath & " does not exist"
Exit Sub
End If
content = ""
'stream the input file
Set objinstream = CreateObject("Adodb.Stream")
With objinstream
.Type = 1
.Open
.LoadFromFile(fpath)
'check if the specified size is larger than the file content
If n <= .Size Then
content = .Read(n)
Else
WScript.Echo "The specified size is larger than the file content"
Exit Sub
End If
.Close
End With
'write the truncated version
Set objoutstream = CreateObject("Adodb.Stream")
With objoutstream
.Type = 1
.Open
.Write content
.SaveToFile fpath,2
.Close
End With
Set objinstream = Nothing
Set objoutstream = Nothing
Set objfso = Nothing
End Sub
'testing
Call truncate("C:\temp\test.txt",30)