Task 515: .PAS File Format

Task 515: .PAS File Format

File Format Specifications for .PAS

The .PAS file format is used for source code files written in the Pascal programming language or its variants (such as Object Pascal in Delphi). It is a plain text format with no binary structure. The content follows the syntax rules of the Pascal language, including keywords like program, begin, end, variables, procedures, and functions. Files are typically encoded in ASCII or UTF-8, with line endings as CRLF (Windows) or LF (Unix/Mac). There is no header or footer; the file is human-readable and can be edited in any text editor. For detailed syntax specifications, refer to the Pascal standard (ISO 7185) or Delphi documentation.

  1. List of all the properties of this file format intrinsic to its file system:
  • File Name
  • File Path
  • File Size (in bytes)
  • Creation Time
  • Modification Time
  • Access Time
  • Permissions (e.g., read/write/execute modes)
  • Owner User ID
  • Group ID
  • Inode Number
  • Number of Hard Links
  • Device ID
  1. Two direct download links for files of format .PAS:
  1. Ghost blog embedded HTML JavaScript for drag-and-drop .PAS file dump:
Ghost Blog Post: .PAS File Properties Dumper

.PAS File Properties Dumper

Drag and drop a .PAS file here to view its file system properties.

Drop .PAS file here
  1. Python class:
import os
import time

class PasFileHandler:
    def __init__(self, filename):
        self.filename = filename
        self.properties = self.get_properties()

    def get_properties(self):
        stat = os.stat(self.filename)
        props = {
            'File Name': os.path.basename(self.filename),
            'File Path': os.path.abspath(self.filename),
            'File Size (bytes)': stat.st_size,
            'Creation Time': time.ctime(stat.st_ctime),
            'Modification Time': time.ctime(stat.st_mtime),
            'Access Time': time.ctime(stat.st_atime),
            'Permissions': oct(stat.st_mode)[-3:],
            'Owner User ID': stat.st_uid,
            'Group ID': stat.st_gid,
            'Inode Number': stat.st_ino,
            'Number of Hard Links': stat.st_nlink,
            'Device ID': stat.st_dev
        }
        return props

    def read(self):
        with open(self.filename, 'r') as f:
            return f.read()

    def write(self, content):
        with open(self.filename, 'w') as f:
            f.write(content)

    def print_properties(self):
        for key, value in self.properties.items():
            print(f"{key}: {value}")

# Example usage:
# handler = PasFileHandler('example.pas')
# print(handler.read())  # Reads content
# handler.write('program Hello; begin writeln("Hello"); end.')  # Writes content
# handler.print_properties()  # Prints properties
  1. Java class:
import java.io.*;
import java.nio.file.*;
import java.nio.file.attribute.*;
import java.util.Date;

public class PasFileHandler {
    private String filename;
    private Path path;

    public PasFileHandler(String filename) {
        this.filename = filename;
        this.path = Paths.get(filename);
    }

    private BasicFileAttributes getProperties() throws IOException {
        return Files.readAttributes(path, BasicFileAttributes.class);
    }

    public String read() throws IOException {
        return new String(Files.readAllBytes(path));
    }

    public void write(String content) throws IOException {
        Files.write(path, content.getBytes());
    }

    public void printProperties() {
        try {
            BasicFileAttributes attrs = getProperties();
            File file = new File(filename);
            System.out.println("File Name: " + file.getName());
            System.out.println("File Path: " + file.getAbsolutePath());
            System.out.println("File Size (bytes): " + attrs.size());
            System.out.println("Creation Time: " + new Date(attrs.creationTime().toMillis()));
            System.out.println("Modification Time: " + new Date(attrs.lastModifiedTime().toMillis()));
            System.out.println("Access Time: " + new Date(attrs.lastAccessTime().toMillis()));
            System.out.println("Permissions: " + (file.canRead() ? "r" : "-") + (file.canWrite() ? "w" : "-") + (file.canExecute() ? "x" : "-"));
            PosixFileAttributes posix = Files.readAttributes(path, PosixFileAttributes.class, LinkOption.NOFOLLOW_LINKS);
            System.out.println("Owner User ID: " + posix.owner().getName());
            System.out.println("Group ID: " + posix.group().getName());
            // Inode, links, device not directly available in standard Java; require platform-specific extensions.
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    // Example usage:
    // public static void main(String[] args) throws IOException {
    //     PasFileHandler handler = new PasFileHandler("example.pas");
    //     System.out.println(handler.read());
    //     handler.write("program Hello; begin writeln(\"Hello\"); end.");
    //     handler.printProperties();
    // }
}
  1. JavaScript class:
class PasFileHandler {
    constructor(file) {
        this.file = file;  // Expect a File object (e.g., from input or drag-drop)
    }

    async read() {
        return await this.file.text();
    }

    // Write not directly supported in browser JS for local files; simulate with Blob download.
    write(content) {
        const blob = new Blob([content], { type: 'text/plain' });
        const url = URL.createObjectURL(blob);
        const a = document.createElement('a');
        a.href = url;
        a.download = this.file.name;
        a.click();
        URL.revokeObjectURL(url);
    }

    printProperties() {
        console.log(`File Name: ${this.file.name}`);
        console.log(`File Size (bytes): ${this.file.size}`);
        console.log(`Modification Time: ${new Date(this.file.lastModified)}`);
        console.log(`File Type: ${this.file.type}`);
        // Browser JS limited; no full FS properties like permissions, owner, inode.
    }
}

// Example usage:
// const input = document.createElement('input');
// input.type = 'file';
// input.accept = '.pas';
// input.onchange = (e) => {
//     const file = e.target.files[0];
//     const handler = new PasFileHandler(file);
//     handler.read().then(console.log);
//     handler.write('program Hello; begin writeln("Hello"); end.');
//     handler.printProperties();
// };
  1. C class (using C++ for class support):
#include <iostream>
#include <fstream>
#include <string>
#include <sys/stat.h>
#include <ctime>
#include <unistd.h>

class PasFileHandler {
private:
    std::string filename;

public:
    PasFileHandler(const std::string& fn) : filename(fn) {}

    std::string read() {
        std::ifstream file(filename);
        if (!file) return "";
        std::string content((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
        return content;
    }

    void write(const std::string& content) {
        std::ofstream file(filename);
        if (file) file << content;
    }

    void printProperties() {
        struct stat st;
        if (stat(filename.c_str(), &st) == 0) {
            std::cout << "File Name: " << filename << std::endl;
            std::cout << "File Path: " << realpath(filename.c_str(), nullptr) << std::endl;
            std::cout << "File Size (bytes): " << st.st_size << std::endl;
            std::cout << "Creation Time: " << std::ctime(&st.st_ctime);
            std::cout << "Modification Time: " << std::ctime(&st.st_mtime);
            std::cout << "Access Time: " << std::ctime(&st.st_atime);
            std::cout << "Permissions: " << std::oct << (st.st_mode & 0777) << std::endl;
            std::cout << "Owner User ID: " << st.st_uid << std::endl;
            std::cout << "Group ID: " << st.st_gid << std::endl;
            std::cout << "Inode Number: " << st.st_ino << std::endl;
            std::cout << "Number of Hard Links: " << st.st_nlink << std::endl;
            std::cout << "Device ID: " << st.st_dev << std::endl;
        } else {
            std::cerr << "Error getting properties." << std::endl;
        }
    }
};

// Example usage:
// int main() {
//     PasFileHandler handler("example.pas");
//     std::cout << handler.read() << std::endl;
//     handler.write("program Hello; begin writeln('Hello'); end.");
//     handler.printProperties();
//     return 0;
// }