[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] New pickle for TAR files.
From: |
Mohammad-Reza Nabipoor |
Subject: |
Re: [PATCH] New pickle for TAR files. |
Date: |
Sun, 6 Aug 2023 18:30:45 +0200 |
Hello Kostas.
Thanks for the revised version!
Please find the comments below.
(I hope this time you send the revised verison sooner :D)
diff --git a/ChangeLog b/ChangeLog
index cd17e6d8..3267ce60 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2023-08-05 Konstantinos Chasialis <koschasialis@gmail.com>
+
+ * pickles/tar.px: New pickle for TAR files.
+ * testsuite/poke.pickles/tar-1-test.pk: New test.
+ * testsuite/poke.pickles/tar-2-test.pk: Likewise.
+ * testsuite/Makefile.am (EXTRA_DIST): Add new tests.
+
2023-07-06 Mohammad-Reza Nabipoor <mnabipoor@gnu.org>
* doc/poke.texi (Integral Structs): Update.
diff --git a/doc/gendocs_template b/doc/gendocs_template
index 1be0b607..a101977d 100644
--- a/doc/gendocs_template
+++ b/doc/gendocs_template
@@ -1,66 +1,101 @@
-<!DOCTYPE html public "-//w3c//dtd html 4.0 transitional//en">
-<html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
- <link rel="stylesheet" href="http://jemarch.net/homepage.css"/>
- <link rel="shortcut icon" href="http://jemarch.net/images/poke.ico"/>
[...]
</html>
This is an artifact of bootstrap.
Please make sure you `git restore doc/gendocs_template' when boostraping.
This should not be part of a patch :)
diff --git a/pickles/tar.pk b/pickles/tar.pk
new file mode 100644
index 00000000..c8021f10
--- /dev/null
+++ b/pickles/tar.pk
@@ -0,0 +1,216 @@
+/* tar.pk - TAR implementation for GNU poke. */
+
+/* Copyright (C) 2019, 2020, 2021, 2022, 2023 Jose E. Marchesi. */
Again, as I mentioned in my previous email :)
> > You have to put your name here and the year 2023.
Or you can also use "The poke authors" if you want.
+
+/* This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* This file contains a description of tar files (PAX). */
+
And, also, as I mentioned in the previous email:
> > It is always useful to put some links to documents that specify the
> > protocol.
> > Links like:
> > - https://pubs.opengroup.org/onlinepubs/9699919799/utilities/pax.html
> > "EXTENDED DESCRIPTION" section.
> > - https://www.mkssoftware.com/docs/man4/pax.4.asp
> > - ...
+type TAR_Thdr =
+ struct
+ {
+ uint<8>[100] name_chars; /* File name. */
+ uint<8>[8] mode_chars; /* File mode. */
+ uint<8>[8] uid_chars; /* Owner's numeric user ID. */
+type TAR_Tfile =
+ struct
+ {
+ TAR_Thdr thdr;
+ var fsize = thdr.get_size;
+ var file_data_offset = OFFSET;
+ // end of data padding for alignment
+ uint<8>[0] @ file_data_offset + fsize + alignto(fsize, 512#B);
Please put a space before the open paren (GNU style).
+
+ method get_file_data_offset = off64:
Please don't use `off64', instead use `offset<int<64>,b>`.
Standard types (types which are defined in `std-types.pk`) are only useful
for interactive use. If you use them in pickles, then users of your pickle
cannot use them in things like gdb intergration.
+ {
+ return file_data_offset;
+ }
+
+ method get_eof_offset = off64:
Ditto.
+ {
+ return file_data_offset + fsize + alignto(fsize, 512#B);
Please put a space before the open paren (GNU style).
+ }
+ };
\ No newline at end of file
diff --git a/testsuite/poke.pickles/tar-1-test.pk
b/testsuite/poke.pickles/tar-1-test.pk
new file mode 100644
index 00000000..09531553
--- /dev/null
+++ b/testsuite/poke.pickles/tar-1-test.pk
@@ -0,0 +1,1325 @@
+/* tar-1-test.pk - Tests for the TAR pickle. */
+
+/* Copyright (C) 2022, 2023 Jose E. Marchesi. */
Use your name and year 2023.
[...]
+
+load pktest;
+load tar;
+
+var data = open ("*data*");
[...]
+
+var tests = [
+ PkTest {
+ name = "empty tar",
+ func = lambda (string name) void:
+ {
+ var tfiles = TAR_Tfile[] @ data : 0#B;
+
+ assert (tfiles'length == 2UL);
Apparently this is wrong!
This works on my machine:
assert (tfiles'length == 1UL);
+ assert (tfiles[0].thdr.get_size == 0#B);
+ assert (tfiles[0].thdr.get_magic == "ustar ");
+ assert (tfiles[0].thdr.get_mode == 0o0000775);
+ },
+ },
+];
+
+var ok = pktest_run (tests);
+
+close (data);
+exit (ok ? 0 : 1);
diff --git a/testsuite/poke.pickles/tar-2-test.pk
b/testsuite/poke.pickles/tar-2-test.pk
new file mode 100644
index 00000000..2e277989
--- /dev/null
+++ b/testsuite/poke.pickles/tar-2-test.pk
@@ -0,0 +1,2657 @@
+/* tar-1-test.pk - Tests for the TAR pickle. */
+
+/* Copyright (C) 2022, 2023 Jose E. Marchesi. */
Ditto :)
+
+
+var tests = [
+ PkTest {
+ name = "project tar",
+ func = lambda (string name) void:
+ {
+ var tfiles = TAR_Tfile[] @ data : 0#B;
+
+ assert (tfiles'length == 7UL);
+
+ assert (tfiles[0].thdr.get_name == "project/");
+ assert (tfiles[0].thdr.get_size == 0#B);
+ assert (tfiles[0].thdr.get_magic == "ustar ");
+ assert (tfiles[0].thdr.get_mode == 0o0000775);
+
+ assert (tfiles[1].thdr.get_name == "project/src/");
+ assert (tfiles[1].thdr.get_size == 0#B);
+ assert (tfiles[1].thdr.get_magic == "ustar ");
+ assert (tfiles[1].thdr.get_mode == 0o0000775);
+
+ assert (tfiles[2].thdr.get_name == "project/src/lib.cpp");
Jose will kick you because of this C++ file XD!
Be careful!
+ {
+ var contents = byte[tfiles[2].thdr.get_size] @
tfiles[0].get_eof_offset +
s/byte/uint<8>/
+ tfiles[1].get_eof_offset +
tfiles[2].get_file_data_offset;
+ assert (catos(contents) == "#include \"lib.h\"\n\nvoid
print_msg(const char *msg) {\n printf(\"%s\\n\", msg);\n}");
+ }
+ assert (tfiles[2].thdr.get_magic == "ustar ");
+ assert (tfiles[2].thdr.get_mode == 0o0000600);
+
+ assert (tfiles[3].thdr.get_name == "project/src/lib.h");
+ {
+ var contents = byte[tfiles[3].thdr.get_size] @
tfiles[0].get_eof_offset +
Ditto.
+ tfiles[1].get_eof_offset + tfiles[2].get_eof_offset +
+ tfiles[2].get_file_data_offset;
+ assert (catos(contents) == "#ifndef LIB_H\n#define LIB_H\n\n#include
<stdio.h>\n\nvoid print_msg(const char *msg);\n\n#undef");
1. Put space before paren.
2. You can define a variable (before `tests`) called `CONTENT1' and change the
this assertion to: `assert (catos (contents) == CONTENT1);'.
You can define the `CONTENT1` like this:
```poke
var CONTENT1 = "#include <stdlib.h>
#include \"lib.h\"
int main() {
print_msg(\"Testing tar pickle!\");
return EXIT_SUCCESS;
}";
```
Yes! Poke supports multi-line string literals :)
3. It'd be nice to have a method to give the offset for a conent, then the user
is not required to do all the math like what you did.
+ }
+ assert (tfiles[3].thdr.get_magic == "ustar ");
+ assert (tfiles[3].thdr.get_mode == 0o0000666);
+
+ assert (tfiles[4].thdr.get_name == "project/src/main.c");
+ {
+ var contents = byte[tfiles[4].thdr.get_size] @
tfiles[0].get_eof_offset +
s/byte/uint<8>/
+ tfiles[1].get_eof_offset + tfiles[2].get_eof_offset +
+ tfiles[3].get_eof_offset +
tfiles[4].get_file_data_offset;
+ assert (catos(contents) == "#include <stdlib.h>\n#include
\"lib.h\"\n\nint main() {\n print_msg(\"Testing tar pickle!\");\n\n
return EXIT_SUCCESS;\n}");
+ }
+ assert (tfiles[4].thdr.get_magic == "ustar ");
+ assert (tfiles[4].thdr.get_mode == 0o0000770);
+
+ assert (tfiles[5].thdr.get_name == "project/doc/");
+ assert (tfiles[5].thdr.get_size == 0#B);
+ assert (tfiles[5].thdr.get_magic == "ustar ");
+ assert (tfiles[5].thdr.get_mode == 0o0000775);
+
+ assert (tfiles[6].thdr.get_name == "project/doc/README.md");
+ {
+ var contents = char[tfiles[6].thdr.get_size] @
tfiles[0].get_eof_offset +
s/char/uint<8>/
+ tfiles[1].get_eof_offset + tfiles[2].get_eof_offset +
+ tfiles[3].get_eof_offset + tfiles[4].get_eof_offset +
+ tfiles[5].get_eof_offset +
tfiles[6].get_file_data_offset;
GNU style please :)
https://www.gnu.org/prep/standards/html_node/Formatting.html
When you split an expression into multiple lines, split it before an
operator, not after one. Here is the right way:
if (foo_this_is_long && bar > win (x, y, z)
&& remaining_condition)
+ assert (catos(contents) == "# TAR pickle test\n\nIn up so discovery
my middleton eagerness dejection explained. Estimating excellence ye contrasted
insensible as. Oh up unsatiable advantages decisively as at interested. Present
suppose in esteems in demesne colonel it to. End horrible she landlord screened
stanhill. Repeated offended you opinions off dissuade ask packages screened.
She alteration everything sympathize impossible his get compliment. Collected
few extremity suffering met had sportsman. \nIs at purse tried jokes china
ready decay an. Small its shy way had woody downs power. To denoting admitted
speaking learning my exercise so in. Procured shutters mr it feelings. To or
three offer house begin taken am at. As dissuade cheerful overcame so of
friendly he indulged unpacked. Alteration connection to so as collecting me.
Difficult in delivered extensive at direction allowance. Alteration put use
diminution can considered sentiments interested discretion. An seeing feebly
stairs am branch income me unable.\nUp maids me an ample stood given. Certainty
say suffering his him collected intention promotion. Hill sold ham men made
lose case. Views abode law heard jokes too. Was are delightful solicitude
discovered collecting man day. Resolving neglected sir tolerably but existence
conveying for. Day his put off unaffected literature partiality
inhabiting.\nFor who thoroughly her boy estimating conviction. Removed demands
expense account in outward tedious do. Particular way thoroughly unaffected
projection favourable mrs can projecting own. Thirty it matter enable become
admire in giving. See resolved goodness felicity shy civility domestic had but.
Drawings offended yet answered jennings perceive laughing six did
far.\nIgnorant branched humanity led now marianne too strongly entrance. Rose
to shew bore no ye of paid rent form. Old design are dinner better nearer
silent excuse. She which are maids boy sense her shade. Considered reasonable
we affronting on expression in. So cordial anxious mr delight. Shot his has
must wish from sell nay. Remark fat set why are sudden depend change entire
wanted. Performed remainder attending led fat residence far.\nHusbands ask
repeated resolved but laughter debating. She end cordial visitor noisier fat
subject general picture. Or if offering confined entrance no. Nay rapturous him
see something residence. Highly talked do so vulgar. Her use behaved spirits
and natural attempt say feeling. Exquisite mr incommode immediate he something
ourselves it of. Law conduct yet chiefly beloved examine village
proceed.\nPerformed suspicion in certainty so frankness by attention pretended.
Newspaper or in tolerably education enjoyment. Extremity excellent certainty
discourse sincerity no he so resembled. Joy house worse arise total boy but.
Elderly up chicken do at feeling is. Like seen drew no make fond at on rent.
Behaviour extremely her explained situation yet september gentleman are who. Is
thought or pointed hearing he.\nBy impossible of in difficulty discovered
celebrated ye. Justice joy manners boy met resolve produce. Bed head loud next
plan rent had easy add him. As earnestly shameless elsewhere defective
estimable fulfilled of. Esteem my advice it an excuse enable. Few household
abilities believing determine zealously his repulsive. To open draw dear be by
side like.\nAbilities forfeited situation extremely my to he resembled. Old had
conviction discretion understood put principles you. Match means keeps round
one her quick. She forming two comfort invited. Yet she income effect edward.
Entire desire way design few. Mrs sentiments led solicitude estimating
friendship fat. Meant those event is weeks state it to or. Boy but has folly
charm there its. Its fact ten spot drew.\nTerminated principles sentiments of
no pianoforte if projection impossible. Horses pulled nature favour number yet
highly his has old. Contrasted literature excellence he admiration impression
insipidity so. Scale ought who terms after own quick since. Servants margaret
husbands to screened in throwing. Imprudence oh an collecting partiality.
Admiration gay difficulty unaffected how.\n");
Same for this string literal.
But it'd be nice if you use `fmt' on your `project/doc/README.md' file
before creating the TAR. It's nice to have standard (80 column) text.
And please make sure lines in `project/doc/README.md' are not ended in
whitespaces, because otherwise `make syntax-check' will be unhappy.
(BTW `make syntax-check' is already unhappy; try to keep it happy :D)
+ }
+ assert (tfiles[6].thdr.get_magic == "ustar ");
+ assert (tfiles[6].thdr.get_mode == 0o0000777);
+ },
+ },
+];
Thank you,
Mohammad-Reza
- Prev by Date:
Re: [PATCH] ios: fix write of {,u}int<{16,24,32,40,48,56,64}>
- Next by Date:
Re: [PATCH] ios: fix write of {,u}int<{16,24,32,40,48,56,64}>
- Previous by thread:
Re: [PATCH] New pickle for TAR files.
- Next by thread:
Re: [PATCH] New pickle for TAR files.
- Index(es):