Skip to content

Commit 01f50a2

Browse files
author
delphidabbler
committed
Merge branch 'release/2.0.0'
2 parents ac5ed3c + 3b03817 commit 01f50a2

File tree

670 files changed

+25561
-12
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

670 files changed

+25561
-12
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
_release

README.md

+13-12
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
11
# Code Snippets Collections
22

3-
This repository will be used to store one or more collections of reusable code snippets, mainly in Pascal.
3+
This repository is used to store a collection of reusable code snippets, mainly in Pascal.
44

5-
## Purpose
5+
> **NOTE:** Further collections may be added in the future.
66
7-
The collections that **will be** included here are designed, by and large, for use with the _DelphiDabbler [CodeSnip](https://github.com/delphidabbler/codesnip)_ program.
7+
## Purpose
88

9-
Having said that, the source code in the collections can be used stand-alone<sup>&dagger;</sup>. Each collection has meta data associated with it that was originally designed for use with _CodeSnip_, but can be used with any other software designed to parse the meta data. The meta data file formats will be documented.
9+
The purpose of this repository is to provide collections of snippets for use with the _DelphiDabbler [CodeSnip](https://github.com/delphidabbler/codesnip)_ program.
1010

11-
<sup>&dagger;</sup> Note though that some snippets depend on others. The meta data, in part, specifies those relationships.
11+
However the intent is that other applications will also be able to use the collections by parsing the meta data provided with the collections. It is intended that the meta data will be fully documented.
1212

1313
## Collections
1414

15-
> Available collections will be described here.
15+
So far there is just one collection, the _DelphiDabbler Code Snippets Database_. This collection is version 2 of the database. It is designed for use with _CodeSnip_ v4.16 and later.
1616

17-
## Development
17+
> The collection is not compatible with versions of _CodeSnip_ up to v4.15.1.
1818
19-
The repo uses the [Git Flow](http://nvie.com/posts/a-successful-git-branching-model/) methodology - i.e. development proceeds on the `develop` branch and `feature` branches off it. Only released content appears on the `master` branch.
19+
The collection can be found in the `csdb` directory. The actual collection is contained in the `collection` sub-directory and it is documented in the `docs` sub-directory - see `collection-format.html` for further information.
2020

21-
## License
21+
## Development
2222

23-
By default the source code contained in each collection is released under the [MIT License](./LICENSE.md) ***unless either***:
23+
This repo uses the [Git Flow](http://nvie.com/posts/a-successful-git-branching-model/) methodology - i.e. development proceeds on the `develop` branch and `feature` branches off it. Only released content appears on the `master` branch.
2424

25-
1. The directory containing the collection has its own `LICENSE.md` file - the license specified by such a file then takes precedence; ***or***
25+
## Licenses
2626

27-
2. The snippet's source code specifies a license. In this case that license applies.
27+
The license that applies to this project can be found in `LICENSE.md` in the repo's root directory.
2828

29+
Code snippets in collections may have a different license or licenses. See the documentation of each collection for details.

csdb/CHANGELOG.md

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Changelog
2+
3+
This is the change log for the _DelphiDabbler Code Snippets Database_ collection.
4+
5+
From v2.0.0 all notable changes to this project will be documented in this file.
6+
7+
> No change log was kept for version 1 of the collection.
8+
9+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
10+
11+
## v2.0.0 of 2020/05/02
12+
13+
Initial release of v2 of the collection.
14+
15+
### Changes since last v1 release
16+
17+
* Removed any code that restricted use of the collection to _[DelphiDabbler CodeSnip](https://github.com/delphidabbler/codesnip)_. The collection can now be used by 3rd party applications.
18+
* Removed backwards compatibility with _CodeSnip_ v4.15.1 and earlier.
19+
* Removed conditionally included code and _CodeSnip_ version dependent code from category .ini files.
20+
* Merged multiple versions of category .ini files down into a single file. (These multiple file were used to hide some categories from earlier versions of _CodeSnip_).
21+
* Removed duplicated, _CodeSnip_ version dependent, source code files: used a copy of the most recent version and removed version specifiers from the file names.
22+
* Rationalised and corrected errors in category .ini files:
23+
* Condensed two string management categories into one.
24+
* Removed `Desc` keys where they duplicated `DescEx` keys.
25+
* Removed some duplicate `Credits` and `Comments` keys.
26+
* Removed some empty keys.
27+
* Fixed or removed some broken web links.
28+
* Rephrased some descriptive text.
29+
* Changed layout of category .ini files and `categories.ini`:
30+
* Re-ordered sections of `categories.ini` in alphabetic order.
31+
* Removed all explanatory comments: there were inconsistencies.
32+
* Added header comments, including copyright and licensing information, to all .ini files.
33+
* File format changes:
34+
* Removed the `StandardFormat` key from the specification of category .ini files.
35+
* Added requirements for `LICENSE`, `LICENSE_INFO` and `VERSION` files and added suitable files to the collection.
36+
* Changed the required name for the contributors and testers files to `CONTRIBUTORS` and `TESTERS` respectively. Renamed the existing `contrib.txt` and `testers.txt` files accordingly.
37+
* Made support for REML v4 an official requirement.
38+
* Dropped support for conditional inclusion of code in .ini files.
39+
* Added documentation:
40+
* Of the collection file format.
41+
* A read-me file.
42+
* This change log.
43+
* Ensured that all files in the collection use the UTF-8 text file preamble (aka byte order mark).
44+
* Added a shell script to create releases.
45+
* Officially adopted the MIT license for source code files.

csdb/MakeRelease.sh

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/bin/bash
2+
3+
# --------------------------------------------------------------------------
4+
# DelphiDabbler Code Snippets Database v2
5+
#
6+
# Build tool for Windows to package up files ready for release.
7+
#
8+
# This file is licensed under the MIT license, copyright © 2020 Peter Johnson,
9+
# https://gravatar.com/delphidabbler
10+
#
11+
#
12+
# Two packages are made, each in a zip file: one containing the collection and
13+
# the other containing documentation. Both zip files are written to the
14+
# _release sub-folder in the collection's home directory.
15+
#
16+
# Any pre-existing _release sub-folder is cleared before the zip files are
17+
# created.
18+
#
19+
# Requirements:
20+
#
21+
# - The release version number must be passed to this script as a command
22+
# line.
23+
#
24+
# - The zip utility is required to zip up the files.
25+
#
26+
# --------------------------------------------------------------------------
27+
28+
29+
VERSION=$1
30+
RELEASE_DIR="./_release"
31+
RELEASE_FILE_STUB="${RELEASE_DIR}/csdb-v${VERSION}"
32+
33+
COLLECTION_ZIP_FILE="${RELEASE_FILE_STUB}-data.zip"
34+
DOCS_ZIP_FILE="${RELEASE_FILE_STUB}-docs.zip"
35+
36+
echo Creating CSDB release $1
37+
echo
38+
39+
rm -rf $RELEASE_DIR || true
40+
mkdir $RELEASE_DIR
41+
42+
echo Zipping data
43+
zip -j -q $COLLECTION_ZIP_FILE ./collection/*
44+
45+
echo Zipping documentation
46+
zip -j -q $DOCS_ZIP_FILE ./docs/*
47+
48+
echo Done

csdb/README.md

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# DelphiDabbler Code Snippets Database v2
2+
3+
This collection is version 2 of the DelphiDabbler Code Snippets Database.
4+
5+
The collection contains over 600 reusable Pascal code snippets. The majority are simple functions and procedures but there are also some constants and type definitions, including some advanced records with methods.
6+
7+
All of the snippets have been tested: some received basic testing while others have been tested more comprehensively. The collection contains details of the level of testing each snippet received.
8+
9+
## History
10+
11+
Version 1 was designed exclusively for use with _DelphiDabbler [CodeSnip](https://github.com/delphidabbler/codesnip)_ (v4.15.1 and earlier) and was downloaded by the program directly from a web service on DelphiDabbler.com.
12+
13+
Version 2 is designed to be able to be used by other applications in addition to _CodeSnip_ (v4.16.0 or later). This version is **not** backwards compatible with version 1.
14+
15+
## Using the Collection
16+
17+
Anyone is welcome to write applications or web pages that access the snippets in the collection, subject to the terms of the license (see below). You should read the collection's documentation which explains the file format in detail.
18+
19+
> **WARNING:** Implementors **must not** read the collection data directly from this GitHub repository - that could generate more than the permitted amount of traffic. Instead you must download a release from the _Releases_ tab and either distribute the collection with the application or host it on a web server.
20+
21+
## Documentation
22+
23+
The collection data format is fully documented in the file `collection-format.html` in the `docs` directory.
24+
25+
## Releases
26+
27+
Releases can be found on the `releases` tab on the GitHub project page.
28+
29+
Each release comprises two zip files, as follows (replace `X.Y.X` in the file names with the release version number):
30+
31+
* `csdb-vX.Y.Z-data.zip` - Contains all the data in the collection. Required by applications that access the collection.
32+
* `csdb-vX.Y.Z-docs.zip` - Contains the documentation developers need to understand the structure of the data.
33+
34+
## Change Log
35+
36+
The project's change log can be found in `CHANGELOG.md` in the collection's base directory.
37+
38+
## License
39+
40+
All snippets in this collection (stored in `.dat` files in the `collections` directory) are licensed under the MIT license and are copyright © 2005-2020, [Peter Johnson](https://gravatar.com/delphidabbler) and Contributors. The full license and a list of contributors can be found in the `LICENSE` and `CONTRIBUTORS` files in the `collection` sub-directory.
41+
42+
All other files in this project are licensed under the MIT license and are copyright © 2020, [Peter Johnson](https://gravatar.com/delphidabbler).

csdb/collection/001.dat

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
function WinFileTimeToDOSFileTime(FT: Windows.TFileTime): Integer;
2+
begin
3+
SysUtils.Win32Check(
4+
Windows.FileTimeToDosDateTime(
5+
FT, SysUtils.LongRec(Result).Hi, SysUtils.LongRec(Result).Lo
6+
)
7+
);
8+
end;

csdb/collection/002.dat

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
function WinFileTimeToDateTime(FT: Windows.TFileTime): TDateTime;
2+
var
3+
SysTime: Windows.TSystemTime; // stores date/time in system time format
4+
begin
5+
// Convert file time to system time, raising exception on error
6+
SysUtils.Win32Check(Windows.FileTimeToSystemTime(FT, SysTime));
7+
// Convert system time to Delphi date time, raising excpetion on error
8+
Result := SysUtils.SystemTimeToDateTime(SysTime);
9+
end;

csdb/collection/003.dat

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
function WinFileTimeToStr(FT: Windows.TFileTime): string;
2+
begin
3+
Result := SysUtils.DateTimeToStr(WinFileTimeToDateTime(FT));
4+
end;

csdb/collection/004.dat

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
function ParseDelims(const TextLine: string; var StartPos: Integer;
2+
const Delims: string): string;
3+
var
4+
StringEnd: Integer; // tracks end of current string being parsed out
5+
begin
6+
// Find next non-delimiter char - this is where token starts
7+
while (StartPos <= Length(TextLine))
8+
and SysUtils.IsDelimiter(Delims, TextLine, StartPos) do
9+
Inc(StartPos);
10+
// Now find next delimiter - this is where token ends
11+
StringEnd := StartPos;
12+
while (StringEnd <= Length(TextLine))
13+
and not SysUtils.IsDelimiter(Delims, TextLine, StringEnd) do
14+
Inc(StringEnd);
15+
// Copy result out of string
16+
Result := Copy(TextLine, StartPos, StringEnd - StartPos);
17+
StartPos := StringEnd + 1;
18+
end;

csdb/collection/005.dat

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
procedure CreateURLShortcut(const ShortcutFile, URL: string);
2+
var
3+
F: TextFile; // text file
4+
begin
5+
{$I+} // ensure file i/o raises exception on error
6+
// Open new file for writing (overwrites any existing file)
7+
AssignFile(F, ShortcutFile);
8+
Rewrite(F);
9+
try
10+
// Write file contents: this is simplest basic format of shortcut file
11+
WriteLn(F, '[InternetShortcut]');
12+
WriteLn(F, 'URL=', URL);
13+
finally
14+
// Close file
15+
CloseFile(F);
16+
end;
17+
end;

csdb/collection/006.dat

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
function DeleteFileWithUndo(const FileName: string): Boolean;
2+
var
3+
FOS: ShellAPI.TSHFileOpStruct; // contains info about required file operation
4+
begin
5+
// Set up structure that determines file operation
6+
FillChar(FOS, SizeOf(FOS), 0);
7+
with FOS do
8+
begin
9+
wFunc := ShellAPI.FO_DELETE; // we're deleting
10+
pFrom := PChar(FileName + #0); // this file (#0#0 terminated)
11+
fFlags := ShellAPI.FOF_ALLOWUNDO // with facility to undo op
12+
or ShellAPI.FOF_NOCONFIRMATION // and we don't want any dialogs
13+
or ShellAPI.FOF_SILENT;
14+
end;
15+
// Perform the operation
16+
Result := ShellAPI.SHFileOperation(FOS) = 0;
17+
end;

csdb/collection/007.dat

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
function IsDirectory(const DirName: string): Boolean;
2+
var
3+
Attr: Integer; // directory's file attributes
4+
begin
5+
Attr := SysUtils.FileGetAttr(DirName);
6+
Result := (Attr <> -1) and IsFlagSet(Attr, SysUtils.faDirectory);
7+
end;

csdb/collection/008.dat

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
function DOSToUnixPath(const PathName: string): string;
2+
begin
3+
Result := SysUtils.StringReplace(PathName, '\', '/', [SysUtils.rfReplaceAll]);
4+
end;

csdb/collection/009.dat

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
function GetFileDate(const FName: string): Integer;
2+
var
3+
FileH: Integer; // file handle
4+
begin
5+
// Open file
6+
FileH := SysUtils.FileOpen(FName, SysUtils.fmOpenRead);
7+
if FileH = -1 then
8+
// Couldn't open file - return -1 to indicate can't get date
9+
Result := -1
10+
else
11+
begin
12+
// File opened OK - record date and close file
13+
Result := SysUtils.FileGetDate(FileH);
14+
SysUtils.FileClose(FileH);
15+
end;
16+
end;

csdb/collection/010.dat

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
function GetFixedFileVerInfo(const FileName: string;
2+
out FFI: Windows.TVSFixedFileInfo): Boolean;
3+
var
4+
VerInfoBuf: Pointer; // points to memory storing version info
5+
VerInfoSize: Integer; // size of version info memory
6+
Dummy: Cardinal; // unused parameter required by API function
7+
PFFI: Pointer; // points to fixed file info
8+
FFISize: Windows.UINT; // size of file file info returned from API (unused)
9+
begin
10+
// Assume failure: sets zero result
11+
FillChar(FFI, SizeOf(FFI), 0);
12+
Result := False;
13+
// Get size of version info: there is none if this is zero
14+
VerInfoSize := Windows.GetFileVersionInfoSize(PChar(FileName), Dummy);
15+
if VerInfoSize > 0 then
16+
begin
17+
// Allocate memory to store ver info
18+
GetMem(VerInfoBuf, VerInfoSize);
19+
try
20+
// Get the version info, filling buffer
21+
if Windows.GetFileVersionInfo(
22+
PChar(FileName), Dummy, VerInfoSize, VerInfoBuf
23+
) then
24+
begin
25+
// Get a pointer to fixed file info
26+
if Windows.VerQueryValue(VerInfoBuf, '\', PFFI, FFISize) then
27+
begin
28+
// Got pointer OK: record file version
29+
FFI := Windows.PVSFixedFileInfo(PFFI)^;
30+
Result := True;
31+
end;
32+
end;
33+
finally
34+
// Dispose of ver info storage
35+
FreeMem(VerInfoBuf, VerInfoSize);
36+
end;
37+
end;
38+
end;

csdb/collection/011.dat

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
function SetFileDate(const FName: string; const ADate: Integer): Boolean;
2+
var
3+
FileH: Integer; // file handle
4+
begin
5+
// Open file (assume failure)
6+
Result := False;
7+
FileH := SysUtils.FileOpen(FName, SysUtils.fmOpenWrite);
8+
if FileH <> -1 then
9+
begin
10+
// File opened OK - set date and close file
11+
SysUtils.FileSetDate(FileH, ADate);
12+
SysUtils.FileClose(FileH);
13+
Result := True;
14+
end;
15+
end;

0 commit comments

Comments
 (0)