netsurf-website: branch master updated. b4683be3acfe5d262bf7399f6fe760ede66f5b9c
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf-website.git/shortlog/b4683be3acfe5...
...commit http://git.netsurf-browser.org/netsurf-website.git/commit/b4683be3acfe5d2...
...tree http://git.netsurf-browser.org/netsurf-website.git/tree/b4683be3acfe5d262...
The branch, master has been updated
via b4683be3acfe5d262bf7399f6fe760ede66f5b9c (commit)
from 8431cd726f7f4c8664abebedb283dcdde5f443c1 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/netsurf-website.git/commit/?id=b4683be3acf...
commit b4683be3acfe5d262bf7399f6fe760ede66f5b9c
Author: Michael Drake <michael.drake(a)codethink.co.uk>
Commit: Michael Drake <michael.drake(a)codethink.co.uk>
Purge all mention of Flash
diff --git a/documentation/guide.html b/documentation/guide.html
index 84d3d95..80d3c68 100644
--- a/documentation/guide.html
+++ b/documentation/guide.html
@@ -766,7 +766,6 @@
<tr><td>ANT URL</td><td>&b28</td><td><abbr title="Not Applicable">N/A</abbr></td></tr>
<tr><td>CSS</td><td>&f79</td><td>text/css</td></tr>
<tr><td>Drawfile</td><td>&aff</td><td>application/drawfile<br>application/x-drawfile<br>image/drawfile<br>image/x-drawfile</td></tr>
-<tr><td>Flash</td><td>&188</td><td>application/x-shockwave-flash</td></tr>
<tr><td>GIF</td><td>&695</td><td>image/gif</td></tr>
<tr><td>HTML</td><td>&faf</td><td>text/html</td></tr>
<tr><td>IEURL</td><td>&1ba</td><td><abbr title="Not Applicable">N/A</abbr></td></tr>
@@ -779,8 +778,6 @@
<tr><td>Text</td><td>&fff</td><td>text/plain</td></tr>
</table>
-<p>Flash files are not handled by NetSurf directly but are displayed by an <a href="info#GettingStartedAdditionalResources">external plugin</a>.</p>
-
<p>NetSurf recognises different file types by their RISC OS file type for local files and by their content-type header for files sourced from the internet. Files are not identified by their extension or content. This means that for a file to be displayed, servers must be configured to send the correct content-type header and local files must have the correct RISC OS file type set.</p>
<h2 id="DownloadWindow">Download Window</h2>
@@ -1222,8 +1219,6 @@
<dd>This option can be used to stop NetSurf from displaying advertisements on web pages. This can be useful for pages which contain distracting or obtrusive adverts. Note that NetSurf can only make an educated guess at which content is an advert and which is not. This can mean that some adverts will be fail to be blocked, or more seriously, when advertisement blocking is enabled some valid content may occasionally be blocked.</dd>
<dt>Disable pop-up windows</dt>
<dd>This option can be used to stop web pages from opening new browser windows on your desktop. Some pages may try to open advertisements in new windows, when you visit the page, or open some links in pop-up windows, instead of the current window. Disabling pop-ups means that the only way a new window can be opened is when a user explicitly opens it.</dd>
-<dt>Disable plug-ins</dt>
-<dd>This option can be used to disable plug-ins. Plug-ins are external applications that can handle specific types of content, for example Flash files. This option disables the use of plug-ins, meaning that NetSurf will simply not display the particular file, or use any alternative content provided by a web page.</dd>
</dl>
</div>
diff --git a/documentation/roinfo.html b/documentation/roinfo.html
index 6518874..c41f6cc 100644
--- a/documentation/roinfo.html
+++ b/documentation/roinfo.html
@@ -120,8 +120,6 @@
<p>The following resources are not required to run NetSurf, although they do add additional functionality.</p>
<dl>
-<dt><a href="http://www.ecs.soton.ac.uk/~jmb202/">Flash plugin</a></dt>
-<dd>This allows you to view Flash files on web sites.</dd>
<dt><a href="http://www.beebware.com/software/mappings/">MimeMap Datafile</a></dt>
<dd>A resource containing many different MIME types and their equivalent RISC OS file types.</dd>
</dl>
-----------------------------------------------------------------------
Summary of changes:
documentation/guide.html | 5 -----
documentation/roinfo.html | 2 --
2 files changed, 7 deletions(-)
diff --git a/documentation/guide.html b/documentation/guide.html
index 84d3d95..80d3c68 100644
--- a/documentation/guide.html
+++ b/documentation/guide.html
@@ -766,7 +766,6 @@
<tr><td>ANT URL</td><td>&b28</td><td><abbr title="Not Applicable">N/A</abbr></td></tr>
<tr><td>CSS</td><td>&f79</td><td>text/css</td></tr>
<tr><td>Drawfile</td><td>&aff</td><td>application/drawfile<br>application/x-drawfile<br>image/drawfile<br>image/x-drawfile</td></tr>
-<tr><td>Flash</td><td>&188</td><td>application/x-shockwave-flash</td></tr>
<tr><td>GIF</td><td>&695</td><td>image/gif</td></tr>
<tr><td>HTML</td><td>&faf</td><td>text/html</td></tr>
<tr><td>IEURL</td><td>&1ba</td><td><abbr title="Not Applicable">N/A</abbr></td></tr>
@@ -779,8 +778,6 @@
<tr><td>Text</td><td>&fff</td><td>text/plain</td></tr>
</table>
-<p>Flash files are not handled by NetSurf directly but are displayed by an <a href="info#GettingStartedAdditionalResources">external plugin</a>.</p>
-
<p>NetSurf recognises different file types by their RISC OS file type for local files and by their content-type header for files sourced from the internet. Files are not identified by their extension or content. This means that for a file to be displayed, servers must be configured to send the correct content-type header and local files must have the correct RISC OS file type set.</p>
<h2 id="DownloadWindow">Download Window</h2>
@@ -1222,8 +1219,6 @@
<dd>This option can be used to stop NetSurf from displaying advertisements on web pages. This can be useful for pages which contain distracting or obtrusive adverts. Note that NetSurf can only make an educated guess at which content is an advert and which is not. This can mean that some adverts will be fail to be blocked, or more seriously, when advertisement blocking is enabled some valid content may occasionally be blocked.</dd>
<dt>Disable pop-up windows</dt>
<dd>This option can be used to stop web pages from opening new browser windows on your desktop. Some pages may try to open advertisements in new windows, when you visit the page, or open some links in pop-up windows, instead of the current window. Disabling pop-ups means that the only way a new window can be opened is when a user explicitly opens it.</dd>
-<dt>Disable plug-ins</dt>
-<dd>This option can be used to disable plug-ins. Plug-ins are external applications that can handle specific types of content, for example Flash files. This option disables the use of plug-ins, meaning that NetSurf will simply not display the particular file, or use any alternative content provided by a web page.</dd>
</dl>
</div>
diff --git a/documentation/roinfo.html b/documentation/roinfo.html
index 6518874..c41f6cc 100644
--- a/documentation/roinfo.html
+++ b/documentation/roinfo.html
@@ -120,8 +120,6 @@
<p>The following resources are not required to run NetSurf, although they do add additional functionality.</p>
<dl>
-<dt><a href="http://www.ecs.soton.ac.uk/~jmb202/">Flash plugin</a></dt>
-<dd>This allows you to view Flash files on web sites.</dd>
<dt><a href="http://www.beebware.com/software/mappings/">MimeMap Datafile</a></dt>
<dd>A resource containing many different MIME types and their equivalent RISC OS file types.</dd>
</dl>
--
NetSurf website source for *.netsurf-browser.org
8 months
netsurf: branch master updated. release/3.10-352-gb22e618
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/b22e61871ccfce6c6bc66...
...commit http://git.netsurf-browser.org/netsurf.git/commit/b22e61871ccfce6c6bc6613...
...tree http://git.netsurf-browser.org/netsurf.git/tree/b22e61871ccfce6c6bc66130e...
The branch, master has been updated
via b22e61871ccfce6c6bc66130e7c6eed0f89b3386 (commit)
from f7a0135300ead08731fe10a63891a12cc2dbe067 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=b22e61871ccfce6c6bc...
commit b22e61871ccfce6c6bc66130e7c6eed0f89b3386
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
gtk: Don't try to make zero-size bitmaps
Fixes complete failure to render wikipedia and the register when
built against rsvg.
diff --git a/frontends/gtk/bitmap.c b/frontends/gtk/bitmap.c
index bfd29e1..a995a9e 100644
--- a/frontends/gtk/bitmap.c
+++ b/frontends/gtk/bitmap.c
@@ -53,6 +53,10 @@ static void *bitmap_create(int width, int height, enum gui_bitmap_flags flags)
{
struct bitmap *gbitmap;
+ if (width == 0 || height == 0) {
+ return NULL;
+ }
+
gbitmap = calloc(1, sizeof(struct bitmap));
if (gbitmap != NULL) {
if (flags & BITMAP_OPAQUE) {
-----------------------------------------------------------------------
Summary of changes:
frontends/gtk/bitmap.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/frontends/gtk/bitmap.c b/frontends/gtk/bitmap.c
index bfd29e1..a995a9e 100644
--- a/frontends/gtk/bitmap.c
+++ b/frontends/gtk/bitmap.c
@@ -53,6 +53,10 @@ static void *bitmap_create(int width, int height, enum gui_bitmap_flags flags)
{
struct bitmap *gbitmap;
+ if (width == 0 || height == 0) {
+ return NULL;
+ }
+
gbitmap = calloc(1, sizeof(struct bitmap));
if (gbitmap != NULL) {
if (flags & BITMAP_OPAQUE) {
--
NetSurf Browser
8 months
libnsgif: branch master updated. release/0.2.1-227-ge126efe
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/libnsgif.git/shortlog/e126efe78c6841e57af4...
...commit http://git.netsurf-browser.org/libnsgif.git/commit/e126efe78c6841e57af4f3...
...tree http://git.netsurf-browser.org/libnsgif.git/tree/e126efe78c6841e57af4f3d9...
The branch, master has been updated
via e126efe78c6841e57af4f3d92dad272dba8ab153 (commit)
via 8062f9197c8b640cbf2e4902479da3eeaa05b688 (commit)
from 6dee5d6e11540aa9a7c0e4db58cdeb45392a2ba0 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/libnsgif.git/commit/?id=e126efe78c6841e57a...
commit e126efe78c6841e57af4f3d92dad272dba8ab153
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <mdrake.unique(a)gmail.com>
api: Remove NSGIF_ERR_FRAME_COUNT error code
diff --git a/include/nsgif.h b/include/nsgif.h
index 26897df..e6873b6 100644
--- a/include/nsgif.h
+++ b/include/nsgif.h
@@ -80,11 +80,6 @@ typedef enum {
NSGIF_ERR_DATA_FRAME,
/**
- * Too many frames.
- */
- NSGIF_ERR_FRAME_COUNT,
-
- /**
* Unexpected end of GIF source data.
*/
NSGIF_ERR_END_OF_DATA,
commitdiff http://git.netsurf-browser.org/libnsgif.git/commit/?id=8062f9197c8b640cbf...
commit 8062f9197c8b640cbf2e4902479da3eeaa05b688
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <mdrake.unique(a)gmail.com>
gif: Drop arbitrary frame limit
If we're still successfully decoding frames, there's no reason
to stop.
diff --git a/src/gif.c b/src/gif.c
index dafee1a..73814bf 100644
--- a/src/gif.c
+++ b/src/gif.c
@@ -1349,13 +1349,6 @@ static nsgif_error nsgif__process_frame(
if (pos < end && pos[0] == NSGIF_TRAILER) {
return NSGIF_OK;
}
-
- /* We could theoretically get some junk data that gives us
- * millions of frames, so we ensure that we don't have a
- * silly number. */
- if (frame_idx > 4096) {
- return NSGIF_ERR_FRAME_COUNT;
- }
}
ret = nsgif__parse_frame_extensions(gif, frame, &pos, !decode);
@@ -2051,7 +2044,6 @@ const char *nsgif_strerror(nsgif_error err)
[NSGIF_ERR_DATA] = "Invalid source data",
[NSGIF_ERR_BAD_FRAME] = "Requested frame does not exist",
[NSGIF_ERR_DATA_FRAME] = "Invalid frame data",
- [NSGIF_ERR_FRAME_COUNT] = "Excessive number of frames",
[NSGIF_ERR_END_OF_DATA] = "Unexpected end of GIF source data",
[NSGIF_ERR_DATA_COMPLETE] = "Can't add data to completed GIF",
[NSGIF_ERR_FRAME_DISPLAY] = "Frame can't be displayed",
-----------------------------------------------------------------------
Summary of changes:
include/nsgif.h | 5 -----
src/gif.c | 8 --------
2 files changed, 13 deletions(-)
diff --git a/include/nsgif.h b/include/nsgif.h
index 26897df..e6873b6 100644
--- a/include/nsgif.h
+++ b/include/nsgif.h
@@ -80,11 +80,6 @@ typedef enum {
NSGIF_ERR_DATA_FRAME,
/**
- * Too many frames.
- */
- NSGIF_ERR_FRAME_COUNT,
-
- /**
* Unexpected end of GIF source data.
*/
NSGIF_ERR_END_OF_DATA,
diff --git a/src/gif.c b/src/gif.c
index dafee1a..73814bf 100644
--- a/src/gif.c
+++ b/src/gif.c
@@ -1349,13 +1349,6 @@ static nsgif_error nsgif__process_frame(
if (pos < end && pos[0] == NSGIF_TRAILER) {
return NSGIF_OK;
}
-
- /* We could theoretically get some junk data that gives us
- * millions of frames, so we ensure that we don't have a
- * silly number. */
- if (frame_idx > 4096) {
- return NSGIF_ERR_FRAME_COUNT;
- }
}
ret = nsgif__parse_frame_extensions(gif, frame, &pos, !decode);
@@ -2051,7 +2044,6 @@ const char *nsgif_strerror(nsgif_error err)
[NSGIF_ERR_DATA] = "Invalid source data",
[NSGIF_ERR_BAD_FRAME] = "Requested frame does not exist",
[NSGIF_ERR_DATA_FRAME] = "Invalid frame data",
- [NSGIF_ERR_FRAME_COUNT] = "Excessive number of frames",
[NSGIF_ERR_END_OF_DATA] = "Unexpected end of GIF source data",
[NSGIF_ERR_DATA_COMPLETE] = "Can't add data to completed GIF",
[NSGIF_ERR_FRAME_DISPLAY] = "Frame can't be displayed",
--
NetSurf GIF Decoder
8 months
libnsgif: branch master updated. release/0.2.1-225-g6dee5d6
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/libnsgif.git/shortlog/6dee5d6e11540aa9a7c0...
...commit http://git.netsurf-browser.org/libnsgif.git/commit/6dee5d6e11540aa9a7c0e4...
...tree http://git.netsurf-browser.org/libnsgif.git/tree/6dee5d6e11540aa9a7c0e4db...
The branch, master has been updated
via 6dee5d6e11540aa9a7c0e4db58cdeb45392a2ba0 (commit)
via 550b6fa74e7f5c6a7800d2f6f4841636a3f93544 (commit)
via 0837e397a55e4a6c2993f67276d9921ab9f2974b (commit)
from 5d3093f8c79e54827864b04ec6b470488d72c960 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/libnsgif.git/commit/?id=6dee5d6e11540aa9a7...
commit 6dee5d6e11540aa9a7c0e4db58cdeb45392a2ba0
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <mdrake.unique(a)gmail.com>
test: nsgif: Print whether frames are interlaced
diff --git a/test/nsgif.c b/test/nsgif.c
index 16a4bc9..29341e7 100644
--- a/test/nsgif.c
+++ b/test/nsgif.c
@@ -187,6 +187,7 @@ static void print_gif_frame_info(const nsgif_frame_info_t *info, uint32_t i)
fprintf(stdout, " local palette: %s\n", info->local_palette ? "yes" : "no");
fprintf(stdout, " disposal-method: %s\n", disposal);
fprintf(stdout, " transparency: %s\n", info->transparency ? "yes" : "no");
+ fprintf(stdout, " interlaced: %s\n", info->interlaced ? "yes" : "no");
fprintf(stdout, " display: %s\n", info->display ? "yes" : "no");
fprintf(stdout, " delay: %"PRIu32"\n", info->delay);
fprintf(stdout, " rect:\n");
commitdiff http://git.netsurf-browser.org/libnsgif.git/commit/?id=550b6fa74e7f5c6a78...
commit 550b6fa74e7f5c6a7800d2f6f4841636a3f93544
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <mdrake.unique(a)gmail.com>
gif: Set interlaced bool in frame info
diff --git a/src/gif.c b/src/gif.c
index 44c60a9..dafee1a 100644
--- a/src/gif.c
+++ b/src/gif.c
@@ -600,20 +600,15 @@ static inline nsgif_error nsgif__decode(
const uint8_t *data,
uint32_t *restrict frame_data)
{
- enum {
- GIF_MASK_INTERLACE = 0x40,
- };
-
nsgif_error ret;
uint32_t width = frame->info.rect.x1 - frame->info.rect.x0;
uint32_t height = frame->info.rect.y1 - frame->info.rect.y0;
uint32_t offset_x = frame->info.rect.x0;
uint32_t offset_y = frame->info.rect.y0;
- uint32_t interlace = frame->flags & GIF_MASK_INTERLACE;
uint32_t transparency_index = frame->transparency_index;
uint32_t *restrict colour_table = gif->colour_table;
- if (interlace == false && offset_x == 0 &&
+ if (frame->info.interlaced == false && offset_x == 0 &&
width == gif->info.width &&
width == gif->rowspan) {
ret = nsgif__decode_simple(gif, height, offset_y,
@@ -621,7 +616,7 @@ static inline nsgif_error nsgif__decode(
frame_data, colour_table);
} else {
ret = nsgif__decode_complex(gif, width, height,
- offset_x, offset_y, interlace,
+ offset_x, offset_y, frame->info.interlaced,
data, transparency_index,
frame_data, colour_table);
}
@@ -1020,6 +1015,7 @@ static nsgif_error nsgif__parse_image_descriptor(
enum {
NSGIF_IMAGE_DESCRIPTOR_LEN = 10u,
NSGIF_IMAGE_SEPARATOR = 0x2Cu,
+ NSGIF_MASK_INTERLACE = 0x40u,
};
assert(gif != NULL);
@@ -1047,6 +1043,8 @@ static nsgif_error nsgif__parse_image_descriptor(
frame->info.rect.x1 = x + w;
frame->info.rect.y1 = y + h;
+ frame->info.interlaced = frame->flags & NSGIF_MASK_INTERLACE;
+
/* Allow first frame to grow image dimensions. */
if (gif->info.frame_count == 0) {
if (x + w > gif->info.width) {
commitdiff http://git.netsurf-browser.org/libnsgif.git/commit/?id=0837e397a55e4a6c29...
commit 0837e397a55e4a6c2993f67276d9921ab9f2974b
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <mdrake.unique(a)gmail.com>
api: Add interlaced bool to frame info
diff --git a/include/nsgif.h b/include/nsgif.h
index 7df8981..26897df 100644
--- a/include/nsgif.h
+++ b/include/nsgif.h
@@ -429,7 +429,8 @@ typedef struct nsgif_frame_info {
bool transparency;
/** whether the frame has a local colour table */
bool local_palette;
-
+ /** whether the frame is interlaced */
+ bool interlaced;
/** Disposal method for previous frame; affects plotting */
uint8_t disposal;
/** delay (in cs) before animating the frame */
-----------------------------------------------------------------------
Summary of changes:
include/nsgif.h | 3 ++-
src/gif.c | 12 +++++-------
test/nsgif.c | 1 +
3 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/include/nsgif.h b/include/nsgif.h
index 7df8981..26897df 100644
--- a/include/nsgif.h
+++ b/include/nsgif.h
@@ -429,7 +429,8 @@ typedef struct nsgif_frame_info {
bool transparency;
/** whether the frame has a local colour table */
bool local_palette;
-
+ /** whether the frame is interlaced */
+ bool interlaced;
/** Disposal method for previous frame; affects plotting */
uint8_t disposal;
/** delay (in cs) before animating the frame */
diff --git a/src/gif.c b/src/gif.c
index 44c60a9..dafee1a 100644
--- a/src/gif.c
+++ b/src/gif.c
@@ -600,20 +600,15 @@ static inline nsgif_error nsgif__decode(
const uint8_t *data,
uint32_t *restrict frame_data)
{
- enum {
- GIF_MASK_INTERLACE = 0x40,
- };
-
nsgif_error ret;
uint32_t width = frame->info.rect.x1 - frame->info.rect.x0;
uint32_t height = frame->info.rect.y1 - frame->info.rect.y0;
uint32_t offset_x = frame->info.rect.x0;
uint32_t offset_y = frame->info.rect.y0;
- uint32_t interlace = frame->flags & GIF_MASK_INTERLACE;
uint32_t transparency_index = frame->transparency_index;
uint32_t *restrict colour_table = gif->colour_table;
- if (interlace == false && offset_x == 0 &&
+ if (frame->info.interlaced == false && offset_x == 0 &&
width == gif->info.width &&
width == gif->rowspan) {
ret = nsgif__decode_simple(gif, height, offset_y,
@@ -621,7 +616,7 @@ static inline nsgif_error nsgif__decode(
frame_data, colour_table);
} else {
ret = nsgif__decode_complex(gif, width, height,
- offset_x, offset_y, interlace,
+ offset_x, offset_y, frame->info.interlaced,
data, transparency_index,
frame_data, colour_table);
}
@@ -1020,6 +1015,7 @@ static nsgif_error nsgif__parse_image_descriptor(
enum {
NSGIF_IMAGE_DESCRIPTOR_LEN = 10u,
NSGIF_IMAGE_SEPARATOR = 0x2Cu,
+ NSGIF_MASK_INTERLACE = 0x40u,
};
assert(gif != NULL);
@@ -1047,6 +1043,8 @@ static nsgif_error nsgif__parse_image_descriptor(
frame->info.rect.x1 = x + w;
frame->info.rect.y1 = y + h;
+ frame->info.interlaced = frame->flags & NSGIF_MASK_INTERLACE;
+
/* Allow first frame to grow image dimensions. */
if (gif->info.frame_count == 0) {
if (x + w > gif->info.width) {
diff --git a/test/nsgif.c b/test/nsgif.c
index 16a4bc9..29341e7 100644
--- a/test/nsgif.c
+++ b/test/nsgif.c
@@ -187,6 +187,7 @@ static void print_gif_frame_info(const nsgif_frame_info_t *info, uint32_t i)
fprintf(stdout, " local palette: %s\n", info->local_palette ? "yes" : "no");
fprintf(stdout, " disposal-method: %s\n", disposal);
fprintf(stdout, " transparency: %s\n", info->transparency ? "yes" : "no");
+ fprintf(stdout, " interlaced: %s\n", info->interlaced ? "yes" : "no");
fprintf(stdout, " display: %s\n", info->display ? "yes" : "no");
fprintf(stdout, " delay: %"PRIu32"\n", info->delay);
fprintf(stdout, " rect:\n");
--
NetSurf GIF Decoder
8 months
libnsgif: branch tlsa/expose-interlace created. release/0.2.1-225-gbe93a58
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/libnsgif.git/shortlog/be93a588b0e1d362b958...
...commit http://git.netsurf-browser.org/libnsgif.git/commit/be93a588b0e1d362b9587c...
...tree http://git.netsurf-browser.org/libnsgif.git/tree/be93a588b0e1d362b9587c2b...
The branch, tlsa/expose-interlace has been created
at be93a588b0e1d362b9587c2bdb1841b7743ef2e6 (commit)
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/libnsgif.git/commit/?id=be93a588b0e1d362b9...
commit be93a588b0e1d362b9587c2bdb1841b7743ef2e6
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
test: nsgif: Print whether frames are interlaced
diff --git a/test/nsgif.c b/test/nsgif.c
index 16a4bc9..29341e7 100644
--- a/test/nsgif.c
+++ b/test/nsgif.c
@@ -187,6 +187,7 @@ static void print_gif_frame_info(const nsgif_frame_info_t *info, uint32_t i)
fprintf(stdout, " local palette: %s\n", info->local_palette ? "yes" : "no");
fprintf(stdout, " disposal-method: %s\n", disposal);
fprintf(stdout, " transparency: %s\n", info->transparency ? "yes" : "no");
+ fprintf(stdout, " interlaced: %s\n", info->interlaced ? "yes" : "no");
fprintf(stdout, " display: %s\n", info->display ? "yes" : "no");
fprintf(stdout, " delay: %"PRIu32"\n", info->delay);
fprintf(stdout, " rect:\n");
commitdiff http://git.netsurf-browser.org/libnsgif.git/commit/?id=aae138c2cf28e22201...
commit aae138c2cf28e2220198bfaaabb4f5a646102837
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
gif: Set interlaced bool in frame info
diff --git a/src/gif.c b/src/gif.c
index 44c60a9..dafee1a 100644
--- a/src/gif.c
+++ b/src/gif.c
@@ -600,20 +600,15 @@ static inline nsgif_error nsgif__decode(
const uint8_t *data,
uint32_t *restrict frame_data)
{
- enum {
- GIF_MASK_INTERLACE = 0x40,
- };
-
nsgif_error ret;
uint32_t width = frame->info.rect.x1 - frame->info.rect.x0;
uint32_t height = frame->info.rect.y1 - frame->info.rect.y0;
uint32_t offset_x = frame->info.rect.x0;
uint32_t offset_y = frame->info.rect.y0;
- uint32_t interlace = frame->flags & GIF_MASK_INTERLACE;
uint32_t transparency_index = frame->transparency_index;
uint32_t *restrict colour_table = gif->colour_table;
- if (interlace == false && offset_x == 0 &&
+ if (frame->info.interlaced == false && offset_x == 0 &&
width == gif->info.width &&
width == gif->rowspan) {
ret = nsgif__decode_simple(gif, height, offset_y,
@@ -621,7 +616,7 @@ static inline nsgif_error nsgif__decode(
frame_data, colour_table);
} else {
ret = nsgif__decode_complex(gif, width, height,
- offset_x, offset_y, interlace,
+ offset_x, offset_y, frame->info.interlaced,
data, transparency_index,
frame_data, colour_table);
}
@@ -1020,6 +1015,7 @@ static nsgif_error nsgif__parse_image_descriptor(
enum {
NSGIF_IMAGE_DESCRIPTOR_LEN = 10u,
NSGIF_IMAGE_SEPARATOR = 0x2Cu,
+ NSGIF_MASK_INTERLACE = 0x40u,
};
assert(gif != NULL);
@@ -1047,6 +1043,8 @@ static nsgif_error nsgif__parse_image_descriptor(
frame->info.rect.x1 = x + w;
frame->info.rect.y1 = y + h;
+ frame->info.interlaced = frame->flags & NSGIF_MASK_INTERLACE;
+
/* Allow first frame to grow image dimensions. */
if (gif->info.frame_count == 0) {
if (x + w > gif->info.width) {
commitdiff http://git.netsurf-browser.org/libnsgif.git/commit/?id=721319de4dbe15a772...
commit 721319de4dbe15a772b11fff62fe0436373ab7fc
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
api: Add interlaced bool to frame info
diff --git a/include/nsgif.h b/include/nsgif.h
index 7df8981..26897df 100644
--- a/include/nsgif.h
+++ b/include/nsgif.h
@@ -429,7 +429,8 @@ typedef struct nsgif_frame_info {
bool transparency;
/** whether the frame has a local colour table */
bool local_palette;
-
+ /** whether the frame is interlaced */
+ bool interlaced;
/** Disposal method for previous frame; affects plotting */
uint8_t disposal;
/** delay (in cs) before animating the frame */
-----------------------------------------------------------------------
--
NetSurf GIF Decoder
8 months
libnsgif: branch master updated. release/0.2.1-222-g5d3093f
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/libnsgif.git/shortlog/5d3093f8c79e54827864...
...commit http://git.netsurf-browser.org/libnsgif.git/commit/5d3093f8c79e54827864b0...
...tree http://git.netsurf-browser.org/libnsgif.git/tree/5d3093f8c79e54827864b04e...
The branch, master has been updated
via 5d3093f8c79e54827864b04ec6b470488d72c960 (commit)
via 0451fa34f6c88eb7e53bdc3762e37ff1f0c0927a (commit)
via 29d64c885b190043ec3fdde26874ec8cb9992a32 (commit)
from fbe9f636b08d86bc10427283e35d60d2900aa5cc (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/libnsgif.git/commit/?id=5d3093f8c79e548278...
commit 5d3093f8c79e54827864b04ec6b470488d72c960
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <mdrake.unique(a)gmail.com>
test: nsgif: Add CLI option to print version
diff --git a/test/nsgif.c b/test/nsgif.c
index f873bab..16a4bc9 100644
--- a/test/nsgif.c
+++ b/test/nsgif.c
@@ -21,6 +21,9 @@
#include "cli.h"
#include "cli.c"
+#define STR_VAL(_S) STR(_S)
+#define STR(_S) #_S
+
#define BYTES_PER_PIXEL 4
static struct nsgif_options {
@@ -28,6 +31,7 @@ static struct nsgif_options {
const char *ppm;
uint64_t loops;
bool palette;
+ bool version;
bool info;
bool help;
} nsgif_options;
@@ -71,6 +75,14 @@ static const struct cli_table_entry cli_entries[] = {
.d = "Save palette images."
},
{
+ .s = 'V',
+ .l = "version",
+ .t = CLI_BOOL,
+ .no_pos = true,
+ .v.b = &nsgif_options.version,
+ .d = "Print version number."
+ },
+ {
.p = true,
.l = "FILE",
.t = CLI_STRING,
@@ -372,6 +384,11 @@ int main(int argc, char *argv[])
return EXIT_SUCCESS;
}
+ if (nsgif_options.version) {
+ printf("%s %s\n", STR_VAL(NSGIF_NAME), STR_VAL(NSGIF_VERSION));
+ return EXIT_SUCCESS;
+ }
+
if (nsgif_options.ppm != NULL) {
ppm = fopen(nsgif_options.ppm, "w+");
if (ppm == NULL) {
commitdiff http://git.netsurf-browser.org/libnsgif.git/commit/?id=0451fa34f6c88eb7e5...
commit 0451fa34f6c88eb7e53bdc3762e37ff1f0c0927a
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <mdrake.unique(a)gmail.com>
Buildsystem: Define component name and version
diff --git a/Makefile b/Makefile
index 082f044..0a33555 100644
--- a/Makefile
+++ b/Makefile
@@ -27,7 +27,8 @@ ifneq ($(BUILD),i586-pc-haiku)
WARNFLAGS := $(WARNFLAGS) -Werror
endif
-CFLAGS := \
+CFLAGS := -DNSGIF_NAME=$(COMPONENT) \
+ -DNSGIF_VERSION=$(COMPONENT_VERSION) \
-I$(CURDIR)/include/ -I$(CURDIR)/src \
$(WARNFLAGS) $(CFLAGS)
ifneq ($(GCCVER),2)
commitdiff http://git.netsurf-browser.org/libnsgif.git/commit/?id=29d64c885b190043ec...
commit 29d64c885b190043ec3fdde26874ec8cb9992a32
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <mdrake.unique(a)gmail.com>
Buildsystem: No need for _{BSD,DEFAULT}_SOURCE
diff --git a/Makefile b/Makefile
index 42aba3a..082f044 100644
--- a/Makefile
+++ b/Makefile
@@ -27,7 +27,7 @@ ifneq ($(BUILD),i586-pc-haiku)
WARNFLAGS := $(WARNFLAGS) -Werror
endif
-CFLAGS := -D_BSD_SOURCE -D_DEFAULT_SOURCE \
+CFLAGS := \
-I$(CURDIR)/include/ -I$(CURDIR)/src \
$(WARNFLAGS) $(CFLAGS)
ifneq ($(GCCVER),2)
-----------------------------------------------------------------------
Summary of changes:
Makefile | 3 ++-
test/nsgif.c | 17 +++++++++++++++++
2 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/Makefile b/Makefile
index 42aba3a..0a33555 100644
--- a/Makefile
+++ b/Makefile
@@ -27,7 +27,8 @@ ifneq ($(BUILD),i586-pc-haiku)
WARNFLAGS := $(WARNFLAGS) -Werror
endif
-CFLAGS := -D_BSD_SOURCE -D_DEFAULT_SOURCE \
+CFLAGS := -DNSGIF_NAME=$(COMPONENT) \
+ -DNSGIF_VERSION=$(COMPONENT_VERSION) \
-I$(CURDIR)/include/ -I$(CURDIR)/src \
$(WARNFLAGS) $(CFLAGS)
ifneq ($(GCCVER),2)
diff --git a/test/nsgif.c b/test/nsgif.c
index f873bab..16a4bc9 100644
--- a/test/nsgif.c
+++ b/test/nsgif.c
@@ -21,6 +21,9 @@
#include "cli.h"
#include "cli.c"
+#define STR_VAL(_S) STR(_S)
+#define STR(_S) #_S
+
#define BYTES_PER_PIXEL 4
static struct nsgif_options {
@@ -28,6 +31,7 @@ static struct nsgif_options {
const char *ppm;
uint64_t loops;
bool palette;
+ bool version;
bool info;
bool help;
} nsgif_options;
@@ -71,6 +75,14 @@ static const struct cli_table_entry cli_entries[] = {
.d = "Save palette images."
},
{
+ .s = 'V',
+ .l = "version",
+ .t = CLI_BOOL,
+ .no_pos = true,
+ .v.b = &nsgif_options.version,
+ .d = "Print version number."
+ },
+ {
.p = true,
.l = "FILE",
.t = CLI_STRING,
@@ -372,6 +384,11 @@ int main(int argc, char *argv[])
return EXIT_SUCCESS;
}
+ if (nsgif_options.version) {
+ printf("%s %s\n", STR_VAL(NSGIF_NAME), STR_VAL(NSGIF_VERSION));
+ return EXIT_SUCCESS;
+ }
+
if (nsgif_options.ppm != NULL) {
ppm = fopen(nsgif_options.ppm, "w+");
if (ppm == NULL) {
--
NetSurf GIF Decoder
8 months
libnsgif: branch tlsa/ci-sanitize updated. release/0.2.1-220-g1c29a0d
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/libnsgif.git/shortlog/1c29a0d7ee6e525a5fe0...
...commit http://git.netsurf-browser.org/libnsgif.git/commit/1c29a0d7ee6e525a5fe03f...
...tree http://git.netsurf-browser.org/libnsgif.git/tree/1c29a0d7ee6e525a5fe03f48...
The branch, tlsa/ci-sanitize has been updated
discards 622cf7e422a8ef0acabad1bc8a98731cb1a7f5a9 (commit)
via 1c29a0d7ee6e525a5fe03f4818dafdcbffbd2e72 (commit)
via fbe9f636b08d86bc10427283e35d60d2900aa5cc (commit)
via d4e69fcebd776233c42ef044230ce3b5b83e61de (commit)
via 68350cd5c6d73ad210e1ae9d1dd102f4295639c1 (commit)
via 26dd4eae0c35b25d1f8cf9ce3896317cf04961ce (commit)
via ffec523aa0a938beab7def1893d41685e28d2b34 (commit)
via fde3d979ace97bd109fce443b49cbbfa5a9307a2 (commit)
via d63e9e479c63f8f0a1579ea58205862047297f1a (commit)
This update added new revisions after undoing existing revisions. That is
to say, the old revision is not a strict subset of the new revision. This
situation occurs when you --force push a change and generate a repository
containing something like this:
* -- * -- B -- O -- O -- O (622cf7e422a8ef0acabad1bc8a98731cb1a7f5a9)
\
N -- N -- N (1c29a0d7ee6e525a5fe03f4818dafdcbffbd2e72)
When this happens we assume that you've already had alert emails for all
of the O revisions, and so we here report only the revisions in the N
branch from the common base, B.
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/libnsgif.git/commit/?id=1c29a0d7ee6e525a5f...
commit 1c29a0d7ee6e525a5fe03f4818dafdcbffbd2e72
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
CI: Add sanitizer jobs
diff --git a/.github/workflows/sanitize.yaml b/.github/workflows/sanitize.yaml
new file mode 100644
index 0000000..70a2f3c
--- /dev/null
+++ b/.github/workflows/sanitize.yaml
@@ -0,0 +1,65 @@
+name: "Linux Sanitize"
+
+on: [push]
+
+jobs:
+ linux:
+ name: '${{ matrix.os }}: ${{ matrix.compiler.vendor }}'
+ runs-on: ${{ matrix.os }}
+ strategy:
+ fail-fast: false
+ matrix:
+ os:
+ - ubuntu-22.04
+ compiler:
+ # The NetSurf build system can't find LLVM AR (it looks for it
+ # in /usr/lib instead of /usr/bin:
+ # `make: /usr/lib/llvm-ar: No such file or directory`).
+ # So we need to make it explicit for llvm.
+ - { vendor: gnu, CC: gcc, AR: ar }
+ - { vendor: llvm, CC: clang, AR: llvm-ar }
+
+ steps:
+ - name: Checkout repository
+ uses: actions/checkout@v3
+ with:
+ fetch-depth: 1
+
+ - name: apt-get install packages
+ run: sudo apt-get update -qq &&
+ sudo apt-get install --no-install-recommends -y
+ bison
+ build-essential
+ check
+ clang
+ flex
+ git
+ gperf
+ llvm
+ pkg-config
+
+ - name: Get env.sh
+ run: |
+ mkdir projects
+ wget -O projects/env.sh https://git.netsurf-browser.org/netsurf.git/plain/docs/env.sh
+
+ - name: Build and install project deps
+ env:
+ CC: ${{ matrix.compiler.CC }}
+ AR: ${{ matrix.compiler.AR }}
+ TARGET: ${{ github.event.repository.name }}
+ run: |
+ export TARGET_WORKSPACE="$(pwd)/projects"
+ source projects/env.sh
+ ns-clone -d -s
+ ns-make-libs install
+
+ - name: Build and Sanitize
+ env:
+ CC: ${{ matrix.compiler.CC }}
+ AR: ${{ matrix.compiler.AR }}
+ TARGET: ${{ github.event.repository.name }}
+ run: |
+ export TARGET_WORKSPACE="$(pwd)/projects"
+ source projects/env.sh
+ make sanitize
-----------------------------------------------------------------------
Summary of changes:
include/nsgif.h | 15 +--
src/gif.c | 14 +--
test/cli.c | 292 +++++++++++++++++++++++++++++++++----------------------
test/cli.h | 17 ++--
test/nsgif.c | 25 ++++-
5 files changed, 225 insertions(+), 138 deletions(-)
diff --git a/include/nsgif.h b/include/nsgif.h
index 7e6aa83..7df8981 100644
--- a/include/nsgif.h
+++ b/include/nsgif.h
@@ -166,15 +166,14 @@ typedef enum nsgif_bitmap_fmt {
/**
* Client bitmap type.
*
- * These are client-created and destroyed, via the \ref bitmap callbacks,
- * but they are owned by a \ref nsgif_t.
+ * These are client-created and destroyed, via the \ref nsgif_bitmap_cb_vt
+ * callbacks, but they are owned by a \ref nsgif_t.
*
* See \ref nsgif_bitmap_fmt for pixel format information.
*
* The bitmap may have a row_span greater than the bitmap width, but the
* difference between row span and width must be a whole number of pixels
- * (a multiple of four bytes). If row span is greater than width, the
- * \ref get_rowspan callback must be provided.
+ * (a multiple of four bytes).
*/
typedef void nsgif_bitmap_t;
@@ -238,6 +237,8 @@ typedef struct nsgif_bitmap_cb_vt {
*
* If this callback is not provided, LibNSGIF will use the width.
*
+ * If row span is greater than width, this callback must be provided.
+ *
* \param[in] bitmap The bitmap.
*/
uint32_t (*get_rowspan)(nsgif_bitmap_t *bitmap);
@@ -485,7 +486,7 @@ void nsgif_global_palette(
* Colours in same pixel format as \ref nsgif_bitmap_t.
*
* \param[in] gif The \ref nsgif_t object.
- * \param[in] frame The \ref frame to get the palette for.
+ * \param[in] frame The frame to get the palette for.
* \param[out] table Client buffer to hold the colour table.
* \param[out] entries The number of used entries in the colour table.
* \return true if a palette is returned, false otherwise.
@@ -511,7 +512,7 @@ bool nsgif_local_palette(
*
* Both the minimum and the default values can be overridden for a given GIF
* by the client. To get frame delays exactly as specified by the GIF file, set
- * \ref delay_min to zero.
+ * `delay_min` to zero.
*
* Note that this does not affect the frame delay in the frame info
* (\ref nsgif_frame_info_t) structure, which will always contain values
@@ -520,7 +521,7 @@ bool nsgif_local_palette(
* \param[in] gif The \ref nsgif_t object to configure.
* \param[in] delay_min The minimum frame delay in centiseconds.
* \param[in] delay_default The delay to use if a frame delay is less than
- * \ref delay_min.
+ * `delay_min`.
*/
void nsgif_set_frame_delay_behaviour(
nsgif_t *gif,
diff --git a/src/gif.c b/src/gif.c
index 688fe12..44c60a9 100644
--- a/src/gif.c
+++ b/src/gif.c
@@ -1068,7 +1068,7 @@ static nsgif_error nsgif__parse_image_descriptor(
* \param[in] colour_table The colour table to populate.
* \param[in] layout la.
* \param[in] colour_table_entries The number of colour table entries.
- * \param[in] Data Raw colour table data.
+ * \param[in] data Raw colour table data.
*/
static void nsgif__colour_table_decode(
uint32_t colour_table[NSGIF_MAX_COLOURS],
@@ -1097,11 +1097,13 @@ static void nsgif__colour_table_decode(
/**
* Extract a GIF colour table into a LibNSGIF colour table buffer.
*
- * \param[in] gif The gif object we're decoding.
- * \param[in] colour_table The colour table to populate.
- * \param[in] colour_table_entries The number of colour table entries.
- * \param[in] pos Current position in data, updated on exit.
- * \param[in] decode Whether to decode the colour table.
+ * \param[in] colour_table The colour table to populate.
+ * \param[in] layout The target pixel format to decode to.
+ * \param[in] colour_table_entries The number of colour table entries.
+ * \param[in] data Current position in data.
+ * \param[in] data_len The available length of `data`.
+ * \param[out] used Number of colour table bytes read.
+ * \param[in] decode Whether to decode the colour table.
* \return NSGIF_OK on success, appropriate error otherwise.
*/
static inline nsgif_error nsgif__colour_table_extract(
diff --git a/test/cli.c b/test/cli.c
index 031cd97..9c095fe 100644
--- a/test/cli.c
+++ b/test/cli.c
@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: ISC
*
- * Copyright (C) 2021 Michael Drake <tlsa(a)netsurf-browser.org>
+ * Copyright (C) 2021-2022 Michael Drake <tlsa(a)netsurf-browser.org>
*/
/**
@@ -18,6 +18,15 @@
#include "cli.h"
/**
+ * CLI parsing context.
+ */
+struct cli_ctx {
+ const struct cli_table *cli; /**< Client CLI spec. */
+ size_t pos_count; /**< The number of positional arguments found. */
+ bool no_pos; /**< Have an argument that negates min_positional. */
+};
+
+/**
* Check whether a CLI argument type should have a numerical value.
*
* \param[in] type An argument type.
@@ -112,6 +121,8 @@ static bool cli__parse_value_enum(
}
}
+ fprintf(stderr, "ERROR: Unknown enum value '%s'.\n", str);
+
return false;
}
@@ -286,16 +297,82 @@ static bool cli__handle_arg_value(const struct cli_table_entry *entry,
return true;
}
+static inline bool cli__is_negative(const char *arg)
+{
+ int64_t i;
+ size_t pos = 0;
+
+ return cli__parse_value_int(arg, &i, &pos)
+ && pos == strlen(arg)
+ && i < 0;
+}
+
+/**
+ * Parse a positional argument according to the given CLI spec entry.
+ *
+ * \param[in] ctx Command line interface parsing context.
+ * \param[in] entry Client command line interface argument specification.
+ * \param[in] arg Argument to parse.
+ * \return true on success, or false otherwise.
+ */
+static bool cli__parse_positional_entry(struct cli_ctx *ctx,
+ const struct cli_table_entry *entry,
+ const char *arg)
+{
+ size_t pos = 0;
+ bool ret;
+
+ ret = cli__parse_value(entry, arg, &pos);
+ if (ret != true) {
+ return ret;
+ } else if (arg[pos] != '\0') {
+ fprintf(stderr, "Failed to parse value '%s' for arg '%s'\n",
+ arg, entry->l);
+ return false;
+ }
+
+ ctx->pos_count++;
+ return true;
+}
+
+/**
+ * Parse a positional argument.
+ *
+ * \param[in] ctx Command line interface parsing context.
+ * \param[in] arg Argument to parse.
+ * \return true on success, or false otherwise.
+ */
+static bool cli__parse_positional(struct cli_ctx *ctx,
+ const char *arg)
+{
+ const struct cli_table *cli = ctx->cli;
+ size_t positional = 0;
+
+ for (size_t i = 0; i < cli->count; i++) {
+ if (cli__entry_is_positional(&cli->entries[i])) {
+ if (positional == ctx->pos_count) {
+ return cli__parse_positional_entry(ctx,
+ &cli->entries[i], arg);
+ }
+
+ positional++;
+ }
+ }
+
+ fprintf(stderr, "Unexpected positional argument: '%s'\n", arg);
+ return false;
+}
+
/**
* Parse a flags argument.
*
- * \param[in] cli Client command line interface specification.
+ * \param[in] ctx Command line interface parsing context.
* \param[in] argc Number of command line arguments.
* \param[in] argv String vector containing command line arguments.
* \param[out] arg_pos Current position in argv, updated on exit.
* \return true on success, or false otherwise.
*/
-static bool cli__parse_short(const struct cli_table *cli,
+static bool cli__parse_short(struct cli_ctx *ctx,
int argc, const char **argv, int *arg_pos)
{
const char *arg = argv[*arg_pos];
@@ -308,11 +385,18 @@ static bool cli__parse_short(const struct cli_table *cli,
while (arg[pos] != '\0') {
const struct cli_table_entry *entry;
- entry = cli__lookup_short(cli, arg[pos]);
+ entry = cli__lookup_short(ctx->cli, arg[pos]);
if (entry == NULL) {
+ if (cli__is_negative(argv[pos])) {
+ return cli__parse_positional(ctx, argv[pos]);
+ }
return false;
}
+ if (entry->no_pos) {
+ ctx->no_pos = true;
+ }
+
if (entry->t == CLI_BOOL) {
*entry->v.b = true;
} else {
@@ -364,13 +448,13 @@ static const struct cli_table_entry *cli__lookup_long(
/**
* Parse a long argument.
*
- * \param[in] cli Client command line interface specification.
+ * \param[in] ctx Command line interface parsing context.
* \param[in] argc Number of command line arguments.
* \param[in] argv String vector containing command line arguments.
* \param[out] arg_pos Current position in argv, updated on exit.
* \return true on success, or false otherwise.
*/
-static bool cli__parse_long(const struct cli_table *cli,
+static bool cli__parse_long(struct cli_ctx *ctx,
int argc, const char **argv, int *arg_pos)
{
const struct cli_table_entry *entry;
@@ -382,11 +466,15 @@ static bool cli__parse_long(const struct cli_table *cli,
return false;
}
- entry = cli__lookup_long(cli, arg, &pos);
+ entry = cli__lookup_long(ctx->cli, arg, &pos);
if (entry == NULL) {
return false;
}
+ if (entry->no_pos) {
+ ctx->no_pos = true;
+ }
+
if (entry->t == CLI_BOOL) {
if (arg[pos] != '\0') {
fprintf(stderr, "Unexpected value for argument '%s'\n",
@@ -408,60 +496,6 @@ static bool cli__parse_long(const struct cli_table *cli,
}
/**
- * Parse a positional argument according to the given CLI spec entry.
- *
- * \param[in] entry Client command line interface argument specification.
- * \param[in] arg Argument to parse.
- * \return true on success, or false otherwise.
- */
-static bool cli__parse_positional_entry(
- const struct cli_table_entry *entry,
- const char *arg)
-{
- size_t pos = 0;
- bool ret;
-
- ret = cli__parse_value(entry, arg, &pos);
- if (ret != true) {
- return ret;
- } else if (arg[pos] != '\0') {
- fprintf(stderr, "Failed to parse value '%s' for arg '%s'\n",
- arg, entry->l);
- return false;
- }
-
- return true;
-}
-
-/**
- * Parse a positional argument.
- *
- * \param[in] cli Client command line interface specification.
- * \param[in] arg Argument to parse.
- * \param[in] count Number of positional arguments parsed already.
- * \return true on success, or false otherwise.
- */
-static bool cli__parse_positional(const struct cli_table *cli,
- const char *arg, size_t count)
-{
- size_t positional = 0;
-
- for (size_t i = 0; i < cli->count; i++) {
- if (cli__entry_is_positional(&cli->entries[i])) {
- if (positional == count) {
- return cli__parse_positional_entry(
- &cli->entries[i], arg);
- }
-
- positional++;
- }
- }
-
- fprintf(stderr, "Unexpected positional argument: '%s'\n", arg);
- return false;
-}
-
-/**
* Get the string to indicate type of value expected for an argument.
*
* \param[in] type The argument type.
@@ -553,20 +587,12 @@ static void cli__count(const struct cli_table *cli,
}
}
-static inline bool cli__is_negative(const char *arg)
-{
- int64_t i;
- size_t pos = 0;
-
- return cli__parse_value_int(arg, &i, &pos)
- && pos == strlen(arg)
- && i < 0;
-}
-
/* Documented in cli.h */
bool cli_parse(const struct cli_table *cli, int argc, const char **argv)
{
- size_t pos_count = 0;
+ struct cli_ctx ctx = {
+ .cli = cli,
+ };
enum {
ARG_PROG_NAME,
ARG_FIRST,
@@ -574,36 +600,24 @@ bool cli_parse(const struct cli_table *cli, int argc, const char **argv)
for (int i = ARG_FIRST; i < argc; i++) {
const char *arg = argv[i];
- size_t pos_inc = 0;
bool ret;
if (arg[0] == '-') {
if (arg[1] == '-') {
- ret = cli__parse_long(cli, argc, argv, &i);
+ ret = cli__parse_long(&ctx, argc, argv, &i);
} else {
- ret = cli__parse_short(cli, argc, argv, &i);
- if (ret != true) {
- if (cli__is_negative(argv[i])) {
- pos_inc = 1;
- ret = cli__parse_positional(
- cli, argv[i],
- pos_count);
- }
- }
+ ret = cli__parse_short(&ctx, argc, argv, &i);
}
} else {
- pos_inc = 1;
- ret = cli__parse_positional(cli, argv[i], pos_count);
+ ret = cli__parse_positional(&ctx, argv[i]);
}
if (ret != true) {
return ret;
}
-
- pos_count += pos_inc;
}
- if (pos_count < cli->min_positional) {
+ if (ctx.no_pos == false && ctx.pos_count < cli->min_positional) {
fprintf(stderr, "Insufficient positional arguments found.\n");
return false;
}
@@ -622,46 +636,90 @@ static size_t cli__terminal_width(void)
}
/**
- * Print an entry's description, with a given indent.
+ * Print a wrapped string, with a given indent.
*
* The indent is assumed to already be applied for the first line of the
* output by the caller.
- *
- * \param[in] entry The entry to print the description for.
+ *
+ * \param[in] str The string to print.
* \param[in] indent The number of spaces to pad the left margin with.
*/
-static void cli__print_description(const struct cli_table_entry *entry,
- size_t indent)
+static void cli__print_wrapping_string(const char *str, size_t indent)
{
size_t terminal_width = cli__terminal_width();
size_t avail = (indent > terminal_width) ? 0 : terminal_width - indent;
size_t space = avail;
- const char *desc = entry->d;
-
- if (desc != NULL) {
- while (*desc != '\0') {
- size_t word_len = strcspn(desc, " \n\t");
- if (word_len <= space || space == avail) {
- fprintf(stderr, "%*.*s",
- (int)word_len,
- (int)word_len, desc);
- desc += word_len;
- if (word_len <= space) {
- space -= word_len;
- }
- if (space > 0) {
- fprintf(stderr, " ");
- space--;
- }
- } else {
- fprintf(stderr, "\n%*s", (int)indent, "");
- space = avail;
+
+ while (*str != '\0') {
+ size_t word_len = strcspn(str, " \n\t");
+ if (word_len <= space || space == avail) {
+ fprintf(stderr, "%*.*s",
+ (int)word_len,
+ (int)word_len, str);
+ str += word_len;
+ if (word_len <= space) {
+ space -= word_len;
+ }
+ if (space > 0) {
+ fprintf(stderr, " ");
+ space--;
}
- desc += strspn(desc, " \n\t");
+ } else {
+ fprintf(stderr, "\n%*s", (int)indent, "");
+ space = avail;
}
+ str += strspn(str, " \n\t");
+ }
+}
+
+/**
+ * Print an entry's description, with a given indent.
+ *
+ * The indent is assumed to already be applied for the first line of the
+ * output by the caller.
+ *
+ * \param[in] entry The entry to print the description for.
+ * \param[in] indent The number of spaces to pad the left margin with.
+ */
+static void cli__print_description(const struct cli_table_entry *entry,
+ size_t indent)
+{
+ if (entry->d != NULL) {
+ cli__print_wrapping_string(entry->d, indent);
}
fprintf(stderr, "\n");
+
+ if (entry->t == CLI_ENUM) {
+ size_t max_len = 0;
+
+ for (const struct cli_str_val *e = entry->v.e.desc;
+ e->str != NULL; e++) {
+ size_t len = strlen(e->str);
+ if (max_len < len) {
+ max_len = len;
+ }
+ }
+
+ fprintf(stderr, "\n");
+
+ for (const struct cli_str_val *e = entry->v.e.desc;
+ e->str != NULL; e++) {
+ fprintf(stderr, " ");
+
+ if (e->d == NULL || e->d[0] == '\0') {
+ fprintf(stderr, "%s\n",
+ e->str);
+ } else {
+ fprintf(stderr, "%-*s - ",
+ (int)(max_len),
+ e->str);
+ cli__print_wrapping_string(e->d,
+ 8 + max_len + 3);
+ fprintf(stderr, "\n");
+ }
+ }
+ }
}
/* Documented in cli.h */
@@ -679,6 +737,12 @@ void cli_help(const struct cli_table *cli, const char *prog_name)
cli__count(cli, &count, &pcount, &max_len, &pmax_len, &phas_desc);
+ if (cli->d != NULL) {
+ fprintf(stderr, "\n");
+ cli__print_wrapping_string(cli->d, 0);
+ fprintf(stderr, "\n");
+ }
+
fprintf(stderr, "\nUsage: %s", prog_name);
if (pcount > 0) {
diff --git a/test/cli.h b/test/cli.h
index 91db086..ffcd272 100644
--- a/test/cli.h
+++ b/test/cli.h
@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: ISC
*
- * Copyright (C) 2021 Michael Drake <tlsa(a)netsurf-browser.org>
+ * Copyright (C) 2021-2022 Michael Drake <tlsa(a)netsurf-browser.org>
*/
/**
@@ -34,13 +34,16 @@ enum cli_arg_type {
CLI_STRING, /**< Has string value. */
};
+/** Enum value descriptor. */
struct cli_str_val {
- const char *str;
- int64_t val;
+ const char *str; /**< String for the enum value name. */
+ int64_t val; /**< The value for this string. */
+ const char *d; /**< Description of this value for help output. */
};
+/** Enum data. */
struct cli_enum {
- const struct cli_str_val *desc;
+ const struct cli_str_val *desc; /**< Array describing enum values. */
int64_t *e; /**< Location to store \ref CLI_ENUM value. */
};
@@ -51,15 +54,16 @@ struct cli_table_entry {
const char *l; /**< Long argument name. */
const char s; /**< Short flag name. (Non-positional arguments.) */
bool p; /**< Whether the argument is a positional argument. */
+ bool no_pos; /**< When present, no positional arguments are required. */
enum cli_arg_type t; /**< Argument type. */
union {
bool *b; /**< Location to store \ref CLI_BOOL value. */
int64_t *i; /**< Location to store \ref CLI_INT value. */
uint64_t *u; /**< Location to store \ref CLI_UINT value. */
const char **s; /**< Location to store \ref CLI_STRING value. */
- struct cli_enum e;
+ struct cli_enum e; /**< \ref CLI_ENUM value details. */
} v; /**< Where to store type-specific values. */
- const char *d; /**< Description. */
+ const char *d; /**< Description of this argument for help output. */
};
/**
@@ -69,6 +73,7 @@ struct cli_table {
const struct cli_table_entry *entries;
size_t count;
size_t min_positional;
+ const char *d; /**< Description of this application for help output. */
};
/**
diff --git a/test/nsgif.c b/test/nsgif.c
index 7d61504..f873bab 100644
--- a/test/nsgif.c
+++ b/test/nsgif.c
@@ -29,15 +29,17 @@ static struct nsgif_options {
uint64_t loops;
bool palette;
bool info;
+ bool help;
} nsgif_options;
static const struct cli_table_entry cli_entries[] = {
{
- .s = 'm',
- .l = "ppm",
- .t = CLI_STRING,
- .v.s = &nsgif_options.ppm,
- .d = "Convert frames to PPM image at given path."
+ .s = 'h',
+ .l = "help",
+ .t = CLI_BOOL,
+ .no_pos = true,
+ .v.b = &nsgif_options.help,
+ .d = "Print this text.",
},
{
.s = 'i',
@@ -55,6 +57,13 @@ static const struct cli_table_entry cli_entries[] = {
"The default is 1."
},
{
+ .s = 'm',
+ .l = "ppm",
+ .t = CLI_STRING,
+ .v.s = &nsgif_options.ppm,
+ .d = "Convert frames to PPM image at given path."
+ },
+ {
.s = 'p',
.l = "palette",
.t = CLI_BOOL,
@@ -74,6 +83,7 @@ const struct cli_table cli = {
.entries = cli_entries,
.count = (sizeof(cli_entries))/(sizeof(*cli_entries)),
.min_positional = 1,
+ .d = "NSGIF - A utility for inspecting and decoding GIFs with libnsgif",
};
static void *bitmap_create(int width, int height)
@@ -357,6 +367,11 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
}
+ if (nsgif_options.help) {
+ cli_help(&cli, argv[0]);
+ return EXIT_SUCCESS;
+ }
+
if (nsgif_options.ppm != NULL) {
ppm = fopen(nsgif_options.ppm, "w+");
if (ppm == NULL) {
--
NetSurf GIF Decoder
8 months, 3 weeks
libnsgif: branch master updated. release/0.2.1-219-gfbe9f63
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/libnsgif.git/shortlog/fbe9f636b08d86bc1042...
...commit http://git.netsurf-browser.org/libnsgif.git/commit/fbe9f636b08d86bc104272...
...tree http://git.netsurf-browser.org/libnsgif.git/tree/fbe9f636b08d86bc10427283...
The branch, master has been updated
via fbe9f636b08d86bc10427283e35d60d2900aa5cc (commit)
from d4e69fcebd776233c42ef044230ce3b5b83e61de (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/libnsgif.git/commit/?id=fbe9f636b08d86bc10...
commit fbe9f636b08d86bc10427283e35d60d2900aa5cc
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <mdrake.unique(a)gmail.com>
docs: Various doxygen comment fixes
diff --git a/include/nsgif.h b/include/nsgif.h
index 7e6aa83..7df8981 100644
--- a/include/nsgif.h
+++ b/include/nsgif.h
@@ -166,15 +166,14 @@ typedef enum nsgif_bitmap_fmt {
/**
* Client bitmap type.
*
- * These are client-created and destroyed, via the \ref bitmap callbacks,
- * but they are owned by a \ref nsgif_t.
+ * These are client-created and destroyed, via the \ref nsgif_bitmap_cb_vt
+ * callbacks, but they are owned by a \ref nsgif_t.
*
* See \ref nsgif_bitmap_fmt for pixel format information.
*
* The bitmap may have a row_span greater than the bitmap width, but the
* difference between row span and width must be a whole number of pixels
- * (a multiple of four bytes). If row span is greater than width, the
- * \ref get_rowspan callback must be provided.
+ * (a multiple of four bytes).
*/
typedef void nsgif_bitmap_t;
@@ -238,6 +237,8 @@ typedef struct nsgif_bitmap_cb_vt {
*
* If this callback is not provided, LibNSGIF will use the width.
*
+ * If row span is greater than width, this callback must be provided.
+ *
* \param[in] bitmap The bitmap.
*/
uint32_t (*get_rowspan)(nsgif_bitmap_t *bitmap);
@@ -485,7 +486,7 @@ void nsgif_global_palette(
* Colours in same pixel format as \ref nsgif_bitmap_t.
*
* \param[in] gif The \ref nsgif_t object.
- * \param[in] frame The \ref frame to get the palette for.
+ * \param[in] frame The frame to get the palette for.
* \param[out] table Client buffer to hold the colour table.
* \param[out] entries The number of used entries in the colour table.
* \return true if a palette is returned, false otherwise.
@@ -511,7 +512,7 @@ bool nsgif_local_palette(
*
* Both the minimum and the default values can be overridden for a given GIF
* by the client. To get frame delays exactly as specified by the GIF file, set
- * \ref delay_min to zero.
+ * `delay_min` to zero.
*
* Note that this does not affect the frame delay in the frame info
* (\ref nsgif_frame_info_t) structure, which will always contain values
@@ -520,7 +521,7 @@ bool nsgif_local_palette(
* \param[in] gif The \ref nsgif_t object to configure.
* \param[in] delay_min The minimum frame delay in centiseconds.
* \param[in] delay_default The delay to use if a frame delay is less than
- * \ref delay_min.
+ * `delay_min`.
*/
void nsgif_set_frame_delay_behaviour(
nsgif_t *gif,
diff --git a/src/gif.c b/src/gif.c
index 688fe12..44c60a9 100644
--- a/src/gif.c
+++ b/src/gif.c
@@ -1068,7 +1068,7 @@ static nsgif_error nsgif__parse_image_descriptor(
* \param[in] colour_table The colour table to populate.
* \param[in] layout la.
* \param[in] colour_table_entries The number of colour table entries.
- * \param[in] Data Raw colour table data.
+ * \param[in] data Raw colour table data.
*/
static void nsgif__colour_table_decode(
uint32_t colour_table[NSGIF_MAX_COLOURS],
@@ -1097,11 +1097,13 @@ static void nsgif__colour_table_decode(
/**
* Extract a GIF colour table into a LibNSGIF colour table buffer.
*
- * \param[in] gif The gif object we're decoding.
- * \param[in] colour_table The colour table to populate.
- * \param[in] colour_table_entries The number of colour table entries.
- * \param[in] pos Current position in data, updated on exit.
- * \param[in] decode Whether to decode the colour table.
+ * \param[in] colour_table The colour table to populate.
+ * \param[in] layout The target pixel format to decode to.
+ * \param[in] colour_table_entries The number of colour table entries.
+ * \param[in] data Current position in data.
+ * \param[in] data_len The available length of `data`.
+ * \param[out] used Number of colour table bytes read.
+ * \param[in] decode Whether to decode the colour table.
* \return NSGIF_OK on success, appropriate error otherwise.
*/
static inline nsgif_error nsgif__colour_table_extract(
diff --git a/test/cli.c b/test/cli.c
index 851750c..9c095fe 100644
--- a/test/cli.c
+++ b/test/cli.c
@@ -340,7 +340,6 @@ static bool cli__parse_positional_entry(struct cli_ctx *ctx,
*
* \param[in] ctx Command line interface parsing context.
* \param[in] arg Argument to parse.
- * \param[in] count Number of positional arguments parsed already.
* \return true on success, or false otherwise.
*/
static bool cli__parse_positional(struct cli_ctx *ctx,
-----------------------------------------------------------------------
Summary of changes:
include/nsgif.h | 15 ++++++++-------
src/gif.c | 14 ++++++++------
test/cli.c | 1 -
3 files changed, 16 insertions(+), 14 deletions(-)
diff --git a/include/nsgif.h b/include/nsgif.h
index 7e6aa83..7df8981 100644
--- a/include/nsgif.h
+++ b/include/nsgif.h
@@ -166,15 +166,14 @@ typedef enum nsgif_bitmap_fmt {
/**
* Client bitmap type.
*
- * These are client-created and destroyed, via the \ref bitmap callbacks,
- * but they are owned by a \ref nsgif_t.
+ * These are client-created and destroyed, via the \ref nsgif_bitmap_cb_vt
+ * callbacks, but they are owned by a \ref nsgif_t.
*
* See \ref nsgif_bitmap_fmt for pixel format information.
*
* The bitmap may have a row_span greater than the bitmap width, but the
* difference between row span and width must be a whole number of pixels
- * (a multiple of four bytes). If row span is greater than width, the
- * \ref get_rowspan callback must be provided.
+ * (a multiple of four bytes).
*/
typedef void nsgif_bitmap_t;
@@ -238,6 +237,8 @@ typedef struct nsgif_bitmap_cb_vt {
*
* If this callback is not provided, LibNSGIF will use the width.
*
+ * If row span is greater than width, this callback must be provided.
+ *
* \param[in] bitmap The bitmap.
*/
uint32_t (*get_rowspan)(nsgif_bitmap_t *bitmap);
@@ -485,7 +486,7 @@ void nsgif_global_palette(
* Colours in same pixel format as \ref nsgif_bitmap_t.
*
* \param[in] gif The \ref nsgif_t object.
- * \param[in] frame The \ref frame to get the palette for.
+ * \param[in] frame The frame to get the palette for.
* \param[out] table Client buffer to hold the colour table.
* \param[out] entries The number of used entries in the colour table.
* \return true if a palette is returned, false otherwise.
@@ -511,7 +512,7 @@ bool nsgif_local_palette(
*
* Both the minimum and the default values can be overridden for a given GIF
* by the client. To get frame delays exactly as specified by the GIF file, set
- * \ref delay_min to zero.
+ * `delay_min` to zero.
*
* Note that this does not affect the frame delay in the frame info
* (\ref nsgif_frame_info_t) structure, which will always contain values
@@ -520,7 +521,7 @@ bool nsgif_local_palette(
* \param[in] gif The \ref nsgif_t object to configure.
* \param[in] delay_min The minimum frame delay in centiseconds.
* \param[in] delay_default The delay to use if a frame delay is less than
- * \ref delay_min.
+ * `delay_min`.
*/
void nsgif_set_frame_delay_behaviour(
nsgif_t *gif,
diff --git a/src/gif.c b/src/gif.c
index 688fe12..44c60a9 100644
--- a/src/gif.c
+++ b/src/gif.c
@@ -1068,7 +1068,7 @@ static nsgif_error nsgif__parse_image_descriptor(
* \param[in] colour_table The colour table to populate.
* \param[in] layout la.
* \param[in] colour_table_entries The number of colour table entries.
- * \param[in] Data Raw colour table data.
+ * \param[in] data Raw colour table data.
*/
static void nsgif__colour_table_decode(
uint32_t colour_table[NSGIF_MAX_COLOURS],
@@ -1097,11 +1097,13 @@ static void nsgif__colour_table_decode(
/**
* Extract a GIF colour table into a LibNSGIF colour table buffer.
*
- * \param[in] gif The gif object we're decoding.
- * \param[in] colour_table The colour table to populate.
- * \param[in] colour_table_entries The number of colour table entries.
- * \param[in] pos Current position in data, updated on exit.
- * \param[in] decode Whether to decode the colour table.
+ * \param[in] colour_table The colour table to populate.
+ * \param[in] layout The target pixel format to decode to.
+ * \param[in] colour_table_entries The number of colour table entries.
+ * \param[in] data Current position in data.
+ * \param[in] data_len The available length of `data`.
+ * \param[out] used Number of colour table bytes read.
+ * \param[in] decode Whether to decode the colour table.
* \return NSGIF_OK on success, appropriate error otherwise.
*/
static inline nsgif_error nsgif__colour_table_extract(
diff --git a/test/cli.c b/test/cli.c
index 851750c..9c095fe 100644
--- a/test/cli.c
+++ b/test/cli.c
@@ -340,7 +340,6 @@ static bool cli__parse_positional_entry(struct cli_ctx *ctx,
*
* \param[in] ctx Command line interface parsing context.
* \param[in] arg Argument to parse.
- * \param[in] count Number of positional arguments parsed already.
* \return true on success, or false otherwise.
*/
static bool cli__parse_positional(struct cli_ctx *ctx,
--
NetSurf GIF Decoder
8 months, 3 weeks
libnsgif: branch tlsa/docs created. release/0.2.1-219-g4b34a0e
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/libnsgif.git/shortlog/4b34a0e16faef75ec1e4...
...commit http://git.netsurf-browser.org/libnsgif.git/commit/4b34a0e16faef75ec1e46b...
...tree http://git.netsurf-browser.org/libnsgif.git/tree/4b34a0e16faef75ec1e46bf1...
The branch, tlsa/docs has been created
at 4b34a0e16faef75ec1e46bf1a6b887d1295975af (commit)
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/libnsgif.git/commit/?id=4b34a0e16faef75ec1...
commit 4b34a0e16faef75ec1e46bf1a6b887d1295975af
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
docs: Various doxygen comment fixes
diff --git a/include/nsgif.h b/include/nsgif.h
index 7e6aa83..7df8981 100644
--- a/include/nsgif.h
+++ b/include/nsgif.h
@@ -166,15 +166,14 @@ typedef enum nsgif_bitmap_fmt {
/**
* Client bitmap type.
*
- * These are client-created and destroyed, via the \ref bitmap callbacks,
- * but they are owned by a \ref nsgif_t.
+ * These are client-created and destroyed, via the \ref nsgif_bitmap_cb_vt
+ * callbacks, but they are owned by a \ref nsgif_t.
*
* See \ref nsgif_bitmap_fmt for pixel format information.
*
* The bitmap may have a row_span greater than the bitmap width, but the
* difference between row span and width must be a whole number of pixels
- * (a multiple of four bytes). If row span is greater than width, the
- * \ref get_rowspan callback must be provided.
+ * (a multiple of four bytes).
*/
typedef void nsgif_bitmap_t;
@@ -238,6 +237,8 @@ typedef struct nsgif_bitmap_cb_vt {
*
* If this callback is not provided, LibNSGIF will use the width.
*
+ * If row span is greater than width, this callback must be provided.
+ *
* \param[in] bitmap The bitmap.
*/
uint32_t (*get_rowspan)(nsgif_bitmap_t *bitmap);
@@ -485,7 +486,7 @@ void nsgif_global_palette(
* Colours in same pixel format as \ref nsgif_bitmap_t.
*
* \param[in] gif The \ref nsgif_t object.
- * \param[in] frame The \ref frame to get the palette for.
+ * \param[in] frame The frame to get the palette for.
* \param[out] table Client buffer to hold the colour table.
* \param[out] entries The number of used entries in the colour table.
* \return true if a palette is returned, false otherwise.
@@ -511,7 +512,7 @@ bool nsgif_local_palette(
*
* Both the minimum and the default values can be overridden for a given GIF
* by the client. To get frame delays exactly as specified by the GIF file, set
- * \ref delay_min to zero.
+ * `delay_min` to zero.
*
* Note that this does not affect the frame delay in the frame info
* (\ref nsgif_frame_info_t) structure, which will always contain values
@@ -520,7 +521,7 @@ bool nsgif_local_palette(
* \param[in] gif The \ref nsgif_t object to configure.
* \param[in] delay_min The minimum frame delay in centiseconds.
* \param[in] delay_default The delay to use if a frame delay is less than
- * \ref delay_min.
+ * `delay_min`.
*/
void nsgif_set_frame_delay_behaviour(
nsgif_t *gif,
diff --git a/src/gif.c b/src/gif.c
index 688fe12..44c60a9 100644
--- a/src/gif.c
+++ b/src/gif.c
@@ -1068,7 +1068,7 @@ static nsgif_error nsgif__parse_image_descriptor(
* \param[in] colour_table The colour table to populate.
* \param[in] layout la.
* \param[in] colour_table_entries The number of colour table entries.
- * \param[in] Data Raw colour table data.
+ * \param[in] data Raw colour table data.
*/
static void nsgif__colour_table_decode(
uint32_t colour_table[NSGIF_MAX_COLOURS],
@@ -1097,11 +1097,13 @@ static void nsgif__colour_table_decode(
/**
* Extract a GIF colour table into a LibNSGIF colour table buffer.
*
- * \param[in] gif The gif object we're decoding.
- * \param[in] colour_table The colour table to populate.
- * \param[in] colour_table_entries The number of colour table entries.
- * \param[in] pos Current position in data, updated on exit.
- * \param[in] decode Whether to decode the colour table.
+ * \param[in] colour_table The colour table to populate.
+ * \param[in] layout The target pixel format to decode to.
+ * \param[in] colour_table_entries The number of colour table entries.
+ * \param[in] data Current position in data.
+ * \param[in] data_len The available length of `data`.
+ * \param[out] used Number of colour table bytes read.
+ * \param[in] decode Whether to decode the colour table.
* \return NSGIF_OK on success, appropriate error otherwise.
*/
static inline nsgif_error nsgif__colour_table_extract(
diff --git a/test/cli.c b/test/cli.c
index 851750c..9c095fe 100644
--- a/test/cli.c
+++ b/test/cli.c
@@ -340,7 +340,6 @@ static bool cli__parse_positional_entry(struct cli_ctx *ctx,
*
* \param[in] ctx Command line interface parsing context.
* \param[in] arg Argument to parse.
- * \param[in] count Number of positional arguments parsed already.
* \return true on success, or false otherwise.
*/
static bool cli__parse_positional(struct cli_ctx *ctx,
-----------------------------------------------------------------------
--
NetSurf GIF Decoder
8 months, 3 weeks
libnsgif: branch master updated. release/0.2.1-218-gd4e69fc
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/libnsgif.git/shortlog/d4e69fcebd776233c42e...
...commit http://git.netsurf-browser.org/libnsgif.git/commit/d4e69fcebd776233c42ef0...
...tree http://git.netsurf-browser.org/libnsgif.git/tree/d4e69fcebd776233c42ef044...
The branch, master has been updated
via d4e69fcebd776233c42ef044230ce3b5b83e61de (commit)
via 68350cd5c6d73ad210e1ae9d1dd102f4295639c1 (commit)
via 26dd4eae0c35b25d1f8cf9ce3896317cf04961ce (commit)
via ffec523aa0a938beab7def1893d41685e28d2b34 (commit)
via fde3d979ace97bd109fce443b49cbbfa5a9307a2 (commit)
via d63e9e479c63f8f0a1579ea58205862047297f1a (commit)
from ca8b9c3784f1f0f074cff1e5474d4a16b80885c6 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/libnsgif.git/commit/?id=d4e69fcebd776233c4...
commit d4e69fcebd776233c42ef044230ce3b5b83e61de
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <mdrake.unique(a)gmail.com>
test: Add --help option to nsgif utility
diff --git a/test/nsgif.c b/test/nsgif.c
index 53c6a68..f873bab 100644
--- a/test/nsgif.c
+++ b/test/nsgif.c
@@ -29,15 +29,17 @@ static struct nsgif_options {
uint64_t loops;
bool palette;
bool info;
+ bool help;
} nsgif_options;
static const struct cli_table_entry cli_entries[] = {
{
- .s = 'm',
- .l = "ppm",
- .t = CLI_STRING,
- .v.s = &nsgif_options.ppm,
- .d = "Convert frames to PPM image at given path."
+ .s = 'h',
+ .l = "help",
+ .t = CLI_BOOL,
+ .no_pos = true,
+ .v.b = &nsgif_options.help,
+ .d = "Print this text.",
},
{
.s = 'i',
@@ -55,6 +57,13 @@ static const struct cli_table_entry cli_entries[] = {
"The default is 1."
},
{
+ .s = 'm',
+ .l = "ppm",
+ .t = CLI_STRING,
+ .v.s = &nsgif_options.ppm,
+ .d = "Convert frames to PPM image at given path."
+ },
+ {
.s = 'p',
.l = "palette",
.t = CLI_BOOL,
@@ -358,6 +367,11 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
}
+ if (nsgif_options.help) {
+ cli_help(&cli, argv[0]);
+ return EXIT_SUCCESS;
+ }
+
if (nsgif_options.ppm != NULL) {
ppm = fopen(nsgif_options.ppm, "w+");
if (ppm == NULL) {
commitdiff http://git.netsurf-browser.org/libnsgif.git/commit/?id=68350cd5c6d73ad210...
commit 68350cd5c6d73ad210e1ae9d1dd102f4295639c1
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <mdrake.unique(a)gmail.com>
test: Add appliction description to help output
diff --git a/test/nsgif.c b/test/nsgif.c
index 7d61504..53c6a68 100644
--- a/test/nsgif.c
+++ b/test/nsgif.c
@@ -74,6 +74,7 @@ const struct cli_table cli = {
.entries = cli_entries,
.count = (sizeof(cli_entries))/(sizeof(*cli_entries)),
.min_positional = 1,
+ .d = "NSGIF - A utility for inspecting and decoding GIFs with libnsgif",
};
static void *bitmap_create(int width, int height)
commitdiff http://git.netsurf-browser.org/libnsgif.git/commit/?id=26dd4eae0c35b25d1f...
commit 26dd4eae0c35b25d1f8cf9ce3896317cf04961ce
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <mdrake.unique(a)gmail.com>
cli: Print useful error message for unknown enum value
diff --git a/test/cli.c b/test/cli.c
index b1b776f..851750c 100644
--- a/test/cli.c
+++ b/test/cli.c
@@ -22,6 +22,7 @@
*/
struct cli_ctx {
const struct cli_table *cli; /**< Client CLI spec. */
+ size_t pos_count; /**< The number of positional arguments found. */
bool no_pos; /**< Have an argument that negates min_positional. */
};
@@ -120,6 +121,8 @@ static bool cli__parse_value_enum(
}
}
+ fprintf(stderr, "ERROR: Unknown enum value '%s'.\n", str);
+
return false;
}
@@ -294,6 +297,73 @@ static bool cli__handle_arg_value(const struct cli_table_entry *entry,
return true;
}
+static inline bool cli__is_negative(const char *arg)
+{
+ int64_t i;
+ size_t pos = 0;
+
+ return cli__parse_value_int(arg, &i, &pos)
+ && pos == strlen(arg)
+ && i < 0;
+}
+
+/**
+ * Parse a positional argument according to the given CLI spec entry.
+ *
+ * \param[in] ctx Command line interface parsing context.
+ * \param[in] entry Client command line interface argument specification.
+ * \param[in] arg Argument to parse.
+ * \return true on success, or false otherwise.
+ */
+static bool cli__parse_positional_entry(struct cli_ctx *ctx,
+ const struct cli_table_entry *entry,
+ const char *arg)
+{
+ size_t pos = 0;
+ bool ret;
+
+ ret = cli__parse_value(entry, arg, &pos);
+ if (ret != true) {
+ return ret;
+ } else if (arg[pos] != '\0') {
+ fprintf(stderr, "Failed to parse value '%s' for arg '%s'\n",
+ arg, entry->l);
+ return false;
+ }
+
+ ctx->pos_count++;
+ return true;
+}
+
+/**
+ * Parse a positional argument.
+ *
+ * \param[in] ctx Command line interface parsing context.
+ * \param[in] arg Argument to parse.
+ * \param[in] count Number of positional arguments parsed already.
+ * \return true on success, or false otherwise.
+ */
+static bool cli__parse_positional(struct cli_ctx *ctx,
+ const char *arg)
+{
+ const struct cli_table *cli = ctx->cli;
+ size_t positional = 0;
+
+ for (size_t i = 0; i < cli->count; i++) {
+ if (cli__entry_is_positional(&cli->entries[i])) {
+ if (positional == ctx->pos_count) {
+ return cli__parse_positional_entry(ctx,
+ &cli->entries[i], arg);
+ }
+
+ positional++;
+ }
+ }
+
+ fprintf(stderr, "Unexpected positional argument: '%s'\n", arg);
+ return false;
+}
+
/**
* Parse a flags argument.
*
@@ -318,6 +388,9 @@ static bool cli__parse_short(struct cli_ctx *ctx,
entry = cli__lookup_short(ctx->cli, arg[pos]);
if (entry == NULL) {
+ if (cli__is_negative(argv[pos])) {
+ return cli__parse_positional(ctx, argv[pos]);
+ }
return false;
}
@@ -424,60 +497,6 @@ static bool cli__parse_long(struct cli_ctx *ctx,
}
/**
- * Parse a positional argument according to the given CLI spec entry.
- *
- * \param[in] entry Client command line interface argument specification.
- * \param[in] arg Argument to parse.
- * \return true on success, or false otherwise.
- */
-static bool cli__parse_positional_entry(
- const struct cli_table_entry *entry,
- const char *arg)
-{
- size_t pos = 0;
- bool ret;
-
- ret = cli__parse_value(entry, arg, &pos);
- if (ret != true) {
- return ret;
- } else if (arg[pos] != '\0') {
- fprintf(stderr, "Failed to parse value '%s' for arg '%s'\n",
- arg, entry->l);
- return false;
- }
-
- return true;
-}
-
-/**
- * Parse a positional argument.
- *
- * \param[in] cli Client command line interface specification.
- * \param[in] arg Argument to parse.
- * \param[in] count Number of positional arguments parsed already.
- * \return true on success, or false otherwise.
- */
-static bool cli__parse_positional(const struct cli_table *cli,
- const char *arg, size_t count)
-{
- size_t positional = 0;
-
- for (size_t i = 0; i < cli->count; i++) {
- if (cli__entry_is_positional(&cli->entries[i])) {
- if (positional == count) {
- return cli__parse_positional_entry(
- &cli->entries[i], arg);
- }
-
- positional++;
- }
- }
-
- fprintf(stderr, "Unexpected positional argument: '%s'\n", arg);
- return false;
-}
-
-/**
* Get the string to indicate type of value expected for an argument.
*
* \param[in] type The argument type.
@@ -569,20 +588,9 @@ static void cli__count(const struct cli_table *cli,
}
}
-static inline bool cli__is_negative(const char *arg)
-{
- int64_t i;
- size_t pos = 0;
-
- return cli__parse_value_int(arg, &i, &pos)
- && pos == strlen(arg)
- && i < 0;
-}
-
/* Documented in cli.h */
bool cli_parse(const struct cli_table *cli, int argc, const char **argv)
{
- size_t pos_count = 0;
struct cli_ctx ctx = {
.cli = cli,
};
@@ -593,7 +601,6 @@ bool cli_parse(const struct cli_table *cli, int argc, const char **argv)
for (int i = ARG_FIRST; i < argc; i++) {
const char *arg = argv[i];
- size_t pos_inc = 0;
bool ret;
if (arg[0] == '-') {
@@ -601,28 +608,17 @@ bool cli_parse(const struct cli_table *cli, int argc, const char **argv)
ret = cli__parse_long(&ctx, argc, argv, &i);
} else {
ret = cli__parse_short(&ctx, argc, argv, &i);
- if (ret != true) {
- if (cli__is_negative(argv[i])) {
- pos_inc = 1;
- ret = cli__parse_positional(
- cli, argv[i],
- pos_count);
- }
- }
}
} else {
- pos_inc = 1;
- ret = cli__parse_positional(cli, argv[i], pos_count);
+ ret = cli__parse_positional(&ctx, argv[i]);
}
if (ret != true) {
return ret;
}
-
- pos_count += pos_inc;
}
- if (ctx.no_pos == false && pos_count < cli->min_positional) {
+ if (ctx.no_pos == false && ctx.pos_count < cli->min_positional) {
fprintf(stderr, "Insufficient positional arguments found.\n");
return false;
}
commitdiff http://git.netsurf-browser.org/libnsgif.git/commit/?id=ffec523aa0a938beab...
commit ffec523aa0a938beab7def1893d41685e28d2b34
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <mdrake.unique(a)gmail.com>
cli: Allow optional application description
diff --git a/test/cli.c b/test/cli.c
index 8f32228..b1b776f 100644
--- a/test/cli.c
+++ b/test/cli.c
@@ -742,6 +742,12 @@ void cli_help(const struct cli_table *cli, const char *prog_name)
cli__count(cli, &count, &pcount, &max_len, &pmax_len, &phas_desc);
+ if (cli->d != NULL) {
+ fprintf(stderr, "\n");
+ cli__print_wrapping_string(cli->d, 0);
+ fprintf(stderr, "\n");
+ }
+
fprintf(stderr, "\nUsage: %s", prog_name);
if (pcount > 0) {
diff --git a/test/cli.h b/test/cli.h
index d7493e4..ffcd272 100644
--- a/test/cli.h
+++ b/test/cli.h
@@ -73,6 +73,7 @@ struct cli_table {
const struct cli_table_entry *entries;
size_t count;
size_t min_positional;
+ const char *d; /**< Description of this application for help output. */
};
/**
commitdiff http://git.netsurf-browser.org/libnsgif.git/commit/?id=fde3d979ace97bd109...
commit fde3d979ace97bd109fce443b49cbbfa5a9307a2
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <mdrake.unique(a)gmail.com>
cli: Improve help output for enum arguments
diff --git a/test/cli.c b/test/cli.c
index e1d1a8b..8f32228 100644
--- a/test/cli.c
+++ b/test/cli.c
@@ -641,46 +641,90 @@ static size_t cli__terminal_width(void)
}
/**
- * Print an entry's description, with a given indent.
+ * Print a wrapped string, with a given indent.
*
* The indent is assumed to already be applied for the first line of the
* output by the caller.
- *
- * \param[in] entry The entry to print the description for.
+ *
+ * \param[in] str The string to print.
* \param[in] indent The number of spaces to pad the left margin with.
*/
-static void cli__print_description(const struct cli_table_entry *entry,
- size_t indent)
+static void cli__print_wrapping_string(const char *str, size_t indent)
{
size_t terminal_width = cli__terminal_width();
size_t avail = (indent > terminal_width) ? 0 : terminal_width - indent;
size_t space = avail;
- const char *desc = entry->d;
-
- if (desc != NULL) {
- while (*desc != '\0') {
- size_t word_len = strcspn(desc, " \n\t");
- if (word_len <= space || space == avail) {
- fprintf(stderr, "%*.*s",
- (int)word_len,
- (int)word_len, desc);
- desc += word_len;
- if (word_len <= space) {
- space -= word_len;
- }
- if (space > 0) {
- fprintf(stderr, " ");
- space--;
- }
- } else {
- fprintf(stderr, "\n%*s", (int)indent, "");
- space = avail;
+
+ while (*str != '\0') {
+ size_t word_len = strcspn(str, " \n\t");
+ if (word_len <= space || space == avail) {
+ fprintf(stderr, "%*.*s",
+ (int)word_len,
+ (int)word_len, str);
+ str += word_len;
+ if (word_len <= space) {
+ space -= word_len;
+ }
+ if (space > 0) {
+ fprintf(stderr, " ");
+ space--;
}
- desc += strspn(desc, " \n\t");
+ } else {
+ fprintf(stderr, "\n%*s", (int)indent, "");
+ space = avail;
}
+ str += strspn(str, " \n\t");
+ }
+}
+
+/**
+ * Print an entry's description, with a given indent.
+ *
+ * The indent is assumed to already be applied for the first line of the
+ * output by the caller.
+ *
+ * \param[in] entry The entry to print the description for.
+ * \param[in] indent The number of spaces to pad the left margin with.
+ */
+static void cli__print_description(const struct cli_table_entry *entry,
+ size_t indent)
+{
+ if (entry->d != NULL) {
+ cli__print_wrapping_string(entry->d, indent);
}
fprintf(stderr, "\n");
+
+ if (entry->t == CLI_ENUM) {
+ size_t max_len = 0;
+
+ for (const struct cli_str_val *e = entry->v.e.desc;
+ e->str != NULL; e++) {
+ size_t len = strlen(e->str);
+ if (max_len < len) {
+ max_len = len;
+ }
+ }
+
+ fprintf(stderr, "\n");
+
+ for (const struct cli_str_val *e = entry->v.e.desc;
+ e->str != NULL; e++) {
+ fprintf(stderr, " ");
+
+ if (e->d == NULL || e->d[0] == '\0') {
+ fprintf(stderr, "%s\n",
+ e->str);
+ } else {
+ fprintf(stderr, "%-*s - ",
+ (int)(max_len),
+ e->str);
+ cli__print_wrapping_string(e->d,
+ 8 + max_len + 3);
+ fprintf(stderr, "\n");
+ }
+ }
+ }
}
/* Documented in cli.h */
diff --git a/test/cli.h b/test/cli.h
index ec14d1e..d7493e4 100644
--- a/test/cli.h
+++ b/test/cli.h
@@ -34,13 +34,16 @@ enum cli_arg_type {
CLI_STRING, /**< Has string value. */
};
+/** Enum value descriptor. */
struct cli_str_val {
- const char *str;
- int64_t val;
+ const char *str; /**< String for the enum value name. */
+ int64_t val; /**< The value for this string. */
+ const char *d; /**< Description of this value for help output. */
};
+/** Enum data. */
struct cli_enum {
- const struct cli_str_val *desc;
+ const struct cli_str_val *desc; /**< Array describing enum values. */
int64_t *e; /**< Location to store \ref CLI_ENUM value. */
};
@@ -58,9 +61,9 @@ struct cli_table_entry {
int64_t *i; /**< Location to store \ref CLI_INT value. */
uint64_t *u; /**< Location to store \ref CLI_UINT value. */
const char **s; /**< Location to store \ref CLI_STRING value. */
- struct cli_enum e;
+ struct cli_enum e; /**< \ref CLI_ENUM value details. */
} v; /**< Where to store type-specific values. */
- const char *d; /**< Description. */
+ const char *d; /**< Description of this argument for help output. */
};
/**
commitdiff http://git.netsurf-browser.org/libnsgif.git/commit/?id=d63e9e479c63f8f0a1...
commit d63e9e479c63f8f0a1579ea58205862047297f1a
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <mdrake.unique(a)gmail.com>
cli: Allow arguments that disable positional argument requirement
diff --git a/test/cli.c b/test/cli.c
index 031cd97..e1d1a8b 100644
--- a/test/cli.c
+++ b/test/cli.c
@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: ISC
*
- * Copyright (C) 2021 Michael Drake <tlsa(a)netsurf-browser.org>
+ * Copyright (C) 2021-2022 Michael Drake <tlsa(a)netsurf-browser.org>
*/
/**
@@ -18,6 +18,14 @@
#include "cli.h"
/**
+ * CLI parsing context.
+ */
+struct cli_ctx {
+ const struct cli_table *cli; /**< Client CLI spec. */
+ bool no_pos; /**< Have an argument that negates min_positional. */
+};
+
+/**
* Check whether a CLI argument type should have a numerical value.
*
* \param[in] type An argument type.
@@ -289,13 +297,13 @@ static bool cli__handle_arg_value(const struct cli_table_entry *entry,
/**
* Parse a flags argument.
*
- * \param[in] cli Client command line interface specification.
+ * \param[in] ctx Command line interface parsing context.
* \param[in] argc Number of command line arguments.
* \param[in] argv String vector containing command line arguments.
* \param[out] arg_pos Current position in argv, updated on exit.
* \return true on success, or false otherwise.
*/
-static bool cli__parse_short(const struct cli_table *cli,
+static bool cli__parse_short(struct cli_ctx *ctx,
int argc, const char **argv, int *arg_pos)
{
const char *arg = argv[*arg_pos];
@@ -308,11 +316,15 @@ static bool cli__parse_short(const struct cli_table *cli,
while (arg[pos] != '\0') {
const struct cli_table_entry *entry;
- entry = cli__lookup_short(cli, arg[pos]);
+ entry = cli__lookup_short(ctx->cli, arg[pos]);
if (entry == NULL) {
return false;
}
+ if (entry->no_pos) {
+ ctx->no_pos = true;
+ }
+
if (entry->t == CLI_BOOL) {
*entry->v.b = true;
} else {
@@ -364,13 +376,13 @@ static const struct cli_table_entry *cli__lookup_long(
/**
* Parse a long argument.
*
- * \param[in] cli Client command line interface specification.
+ * \param[in] ctx Command line interface parsing context.
* \param[in] argc Number of command line arguments.
* \param[in] argv String vector containing command line arguments.
* \param[out] arg_pos Current position in argv, updated on exit.
* \return true on success, or false otherwise.
*/
-static bool cli__parse_long(const struct cli_table *cli,
+static bool cli__parse_long(struct cli_ctx *ctx,
int argc, const char **argv, int *arg_pos)
{
const struct cli_table_entry *entry;
@@ -382,11 +394,15 @@ static bool cli__parse_long(const struct cli_table *cli,
return false;
}
- entry = cli__lookup_long(cli, arg, &pos);
+ entry = cli__lookup_long(ctx->cli, arg, &pos);
if (entry == NULL) {
return false;
}
+ if (entry->no_pos) {
+ ctx->no_pos = true;
+ }
+
if (entry->t == CLI_BOOL) {
if (arg[pos] != '\0') {
fprintf(stderr, "Unexpected value for argument '%s'\n",
@@ -567,6 +583,9 @@ static inline bool cli__is_negative(const char *arg)
bool cli_parse(const struct cli_table *cli, int argc, const char **argv)
{
size_t pos_count = 0;
+ struct cli_ctx ctx = {
+ .cli = cli,
+ };
enum {
ARG_PROG_NAME,
ARG_FIRST,
@@ -579,9 +598,9 @@ bool cli_parse(const struct cli_table *cli, int argc, const char **argv)
if (arg[0] == '-') {
if (arg[1] == '-') {
- ret = cli__parse_long(cli, argc, argv, &i);
+ ret = cli__parse_long(&ctx, argc, argv, &i);
} else {
- ret = cli__parse_short(cli, argc, argv, &i);
+ ret = cli__parse_short(&ctx, argc, argv, &i);
if (ret != true) {
if (cli__is_negative(argv[i])) {
pos_inc = 1;
@@ -603,7 +622,7 @@ bool cli_parse(const struct cli_table *cli, int argc, const char **argv)
pos_count += pos_inc;
}
- if (pos_count < cli->min_positional) {
+ if (ctx.no_pos == false && pos_count < cli->min_positional) {
fprintf(stderr, "Insufficient positional arguments found.\n");
return false;
}
diff --git a/test/cli.h b/test/cli.h
index 91db086..ec14d1e 100644
--- a/test/cli.h
+++ b/test/cli.h
@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: ISC
*
- * Copyright (C) 2021 Michael Drake <tlsa(a)netsurf-browser.org>
+ * Copyright (C) 2021-2022 Michael Drake <tlsa(a)netsurf-browser.org>
*/
/**
@@ -51,6 +51,7 @@ struct cli_table_entry {
const char *l; /**< Long argument name. */
const char s; /**< Short flag name. (Non-positional arguments.) */
bool p; /**< Whether the argument is a positional argument. */
+ bool no_pos; /**< When present, no positional arguments are required. */
enum cli_arg_type t; /**< Argument type. */
union {
bool *b; /**< Location to store \ref CLI_BOOL value. */
-----------------------------------------------------------------------
Summary of changes:
test/cli.c | 293 +++++++++++++++++++++++++++++++++++-----------------------
test/cli.h | 17 ++--
test/nsgif.c | 25 ++++-
3 files changed, 210 insertions(+), 125 deletions(-)
diff --git a/test/cli.c b/test/cli.c
index 031cd97..851750c 100644
--- a/test/cli.c
+++ b/test/cli.c
@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: ISC
*
- * Copyright (C) 2021 Michael Drake <tlsa(a)netsurf-browser.org>
+ * Copyright (C) 2021-2022 Michael Drake <tlsa(a)netsurf-browser.org>
*/
/**
@@ -18,6 +18,15 @@
#include "cli.h"
/**
+ * CLI parsing context.
+ */
+struct cli_ctx {
+ const struct cli_table *cli; /**< Client CLI spec. */
+ size_t pos_count; /**< The number of positional arguments found. */
+ bool no_pos; /**< Have an argument that negates min_positional. */
+};
+
+/**
* Check whether a CLI argument type should have a numerical value.
*
* \param[in] type An argument type.
@@ -112,6 +121,8 @@ static bool cli__parse_value_enum(
}
}
+ fprintf(stderr, "ERROR: Unknown enum value '%s'.\n", str);
+
return false;
}
@@ -286,16 +297,83 @@ static bool cli__handle_arg_value(const struct cli_table_entry *entry,
return true;
}
+static inline bool cli__is_negative(const char *arg)
+{
+ int64_t i;
+ size_t pos = 0;
+
+ return cli__parse_value_int(arg, &i, &pos)
+ && pos == strlen(arg)
+ && i < 0;
+}
+
+/**
+ * Parse a positional argument according to the given CLI spec entry.
+ *
+ * \param[in] ctx Command line interface parsing context.
+ * \param[in] entry Client command line interface argument specification.
+ * \param[in] arg Argument to parse.
+ * \return true on success, or false otherwise.
+ */
+static bool cli__parse_positional_entry(struct cli_ctx *ctx,
+ const struct cli_table_entry *entry,
+ const char *arg)
+{
+ size_t pos = 0;
+ bool ret;
+
+ ret = cli__parse_value(entry, arg, &pos);
+ if (ret != true) {
+ return ret;
+ } else if (arg[pos] != '\0') {
+ fprintf(stderr, "Failed to parse value '%s' for arg '%s'\n",
+ arg, entry->l);
+ return false;
+ }
+
+ ctx->pos_count++;
+ return true;
+}
+
+/**
+ * Parse a positional argument.
+ *
+ * \param[in] ctx Command line interface parsing context.
+ * \param[in] arg Argument to parse.
+ * \param[in] count Number of positional arguments parsed already.
+ * \return true on success, or false otherwise.
+ */
+static bool cli__parse_positional(struct cli_ctx *ctx,
+ const char *arg)
+{
+ const struct cli_table *cli = ctx->cli;
+ size_t positional = 0;
+
+ for (size_t i = 0; i < cli->count; i++) {
+ if (cli__entry_is_positional(&cli->entries[i])) {
+ if (positional == ctx->pos_count) {
+ return cli__parse_positional_entry(ctx,
+ &cli->entries[i], arg);
+ }
+
+ positional++;
+ }
+ }
+
+ fprintf(stderr, "Unexpected positional argument: '%s'\n", arg);
+ return false;
+}
+
/**
* Parse a flags argument.
*
- * \param[in] cli Client command line interface specification.
+ * \param[in] ctx Command line interface parsing context.
* \param[in] argc Number of command line arguments.
* \param[in] argv String vector containing command line arguments.
* \param[out] arg_pos Current position in argv, updated on exit.
* \return true on success, or false otherwise.
*/
-static bool cli__parse_short(const struct cli_table *cli,
+static bool cli__parse_short(struct cli_ctx *ctx,
int argc, const char **argv, int *arg_pos)
{
const char *arg = argv[*arg_pos];
@@ -308,11 +386,18 @@ static bool cli__parse_short(const struct cli_table *cli,
while (arg[pos] != '\0') {
const struct cli_table_entry *entry;
- entry = cli__lookup_short(cli, arg[pos]);
+ entry = cli__lookup_short(ctx->cli, arg[pos]);
if (entry == NULL) {
+ if (cli__is_negative(argv[pos])) {
+ return cli__parse_positional(ctx, argv[pos]);
+ }
return false;
}
+ if (entry->no_pos) {
+ ctx->no_pos = true;
+ }
+
if (entry->t == CLI_BOOL) {
*entry->v.b = true;
} else {
@@ -364,13 +449,13 @@ static const struct cli_table_entry *cli__lookup_long(
/**
* Parse a long argument.
*
- * \param[in] cli Client command line interface specification.
+ * \param[in] ctx Command line interface parsing context.
* \param[in] argc Number of command line arguments.
* \param[in] argv String vector containing command line arguments.
* \param[out] arg_pos Current position in argv, updated on exit.
* \return true on success, or false otherwise.
*/
-static bool cli__parse_long(const struct cli_table *cli,
+static bool cli__parse_long(struct cli_ctx *ctx,
int argc, const char **argv, int *arg_pos)
{
const struct cli_table_entry *entry;
@@ -382,11 +467,15 @@ static bool cli__parse_long(const struct cli_table *cli,
return false;
}
- entry = cli__lookup_long(cli, arg, &pos);
+ entry = cli__lookup_long(ctx->cli, arg, &pos);
if (entry == NULL) {
return false;
}
+ if (entry->no_pos) {
+ ctx->no_pos = true;
+ }
+
if (entry->t == CLI_BOOL) {
if (arg[pos] != '\0') {
fprintf(stderr, "Unexpected value for argument '%s'\n",
@@ -408,60 +497,6 @@ static bool cli__parse_long(const struct cli_table *cli,
}
/**
- * Parse a positional argument according to the given CLI spec entry.
- *
- * \param[in] entry Client command line interface argument specification.
- * \param[in] arg Argument to parse.
- * \return true on success, or false otherwise.
- */
-static bool cli__parse_positional_entry(
- const struct cli_table_entry *entry,
- const char *arg)
-{
- size_t pos = 0;
- bool ret;
-
- ret = cli__parse_value(entry, arg, &pos);
- if (ret != true) {
- return ret;
- } else if (arg[pos] != '\0') {
- fprintf(stderr, "Failed to parse value '%s' for arg '%s'\n",
- arg, entry->l);
- return false;
- }
-
- return true;
-}
-
-/**
- * Parse a positional argument.
- *
- * \param[in] cli Client command line interface specification.
- * \param[in] arg Argument to parse.
- * \param[in] count Number of positional arguments parsed already.
- * \return true on success, or false otherwise.
- */
-static bool cli__parse_positional(const struct cli_table *cli,
- const char *arg, size_t count)
-{
- size_t positional = 0;
-
- for (size_t i = 0; i < cli->count; i++) {
- if (cli__entry_is_positional(&cli->entries[i])) {
- if (positional == count) {
- return cli__parse_positional_entry(
- &cli->entries[i], arg);
- }
-
- positional++;
- }
- }
-
- fprintf(stderr, "Unexpected positional argument: '%s'\n", arg);
- return false;
-}
-
-/**
* Get the string to indicate type of value expected for an argument.
*
* \param[in] type The argument type.
@@ -553,20 +588,12 @@ static void cli__count(const struct cli_table *cli,
}
}
-static inline bool cli__is_negative(const char *arg)
-{
- int64_t i;
- size_t pos = 0;
-
- return cli__parse_value_int(arg, &i, &pos)
- && pos == strlen(arg)
- && i < 0;
-}
-
/* Documented in cli.h */
bool cli_parse(const struct cli_table *cli, int argc, const char **argv)
{
- size_t pos_count = 0;
+ struct cli_ctx ctx = {
+ .cli = cli,
+ };
enum {
ARG_PROG_NAME,
ARG_FIRST,
@@ -574,36 +601,24 @@ bool cli_parse(const struct cli_table *cli, int argc, const char **argv)
for (int i = ARG_FIRST; i < argc; i++) {
const char *arg = argv[i];
- size_t pos_inc = 0;
bool ret;
if (arg[0] == '-') {
if (arg[1] == '-') {
- ret = cli__parse_long(cli, argc, argv, &i);
+ ret = cli__parse_long(&ctx, argc, argv, &i);
} else {
- ret = cli__parse_short(cli, argc, argv, &i);
- if (ret != true) {
- if (cli__is_negative(argv[i])) {
- pos_inc = 1;
- ret = cli__parse_positional(
- cli, argv[i],
- pos_count);
- }
- }
+ ret = cli__parse_short(&ctx, argc, argv, &i);
}
} else {
- pos_inc = 1;
- ret = cli__parse_positional(cli, argv[i], pos_count);
+ ret = cli__parse_positional(&ctx, argv[i]);
}
if (ret != true) {
return ret;
}
-
- pos_count += pos_inc;
}
- if (pos_count < cli->min_positional) {
+ if (ctx.no_pos == false && ctx.pos_count < cli->min_positional) {
fprintf(stderr, "Insufficient positional arguments found.\n");
return false;
}
@@ -622,46 +637,90 @@ static size_t cli__terminal_width(void)
}
/**
- * Print an entry's description, with a given indent.
+ * Print a wrapped string, with a given indent.
*
* The indent is assumed to already be applied for the first line of the
* output by the caller.
- *
- * \param[in] entry The entry to print the description for.
+ *
+ * \param[in] str The string to print.
* \param[in] indent The number of spaces to pad the left margin with.
*/
-static void cli__print_description(const struct cli_table_entry *entry,
- size_t indent)
+static void cli__print_wrapping_string(const char *str, size_t indent)
{
size_t terminal_width = cli__terminal_width();
size_t avail = (indent > terminal_width) ? 0 : terminal_width - indent;
size_t space = avail;
- const char *desc = entry->d;
-
- if (desc != NULL) {
- while (*desc != '\0') {
- size_t word_len = strcspn(desc, " \n\t");
- if (word_len <= space || space == avail) {
- fprintf(stderr, "%*.*s",
- (int)word_len,
- (int)word_len, desc);
- desc += word_len;
- if (word_len <= space) {
- space -= word_len;
- }
- if (space > 0) {
- fprintf(stderr, " ");
- space--;
- }
- } else {
- fprintf(stderr, "\n%*s", (int)indent, "");
- space = avail;
+
+ while (*str != '\0') {
+ size_t word_len = strcspn(str, " \n\t");
+ if (word_len <= space || space == avail) {
+ fprintf(stderr, "%*.*s",
+ (int)word_len,
+ (int)word_len, str);
+ str += word_len;
+ if (word_len <= space) {
+ space -= word_len;
}
- desc += strspn(desc, " \n\t");
+ if (space > 0) {
+ fprintf(stderr, " ");
+ space--;
+ }
+ } else {
+ fprintf(stderr, "\n%*s", (int)indent, "");
+ space = avail;
}
+ str += strspn(str, " \n\t");
+ }
+}
+
+/**
+ * Print an entry's description, with a given indent.
+ *
+ * The indent is assumed to already be applied for the first line of the
+ * output by the caller.
+ *
+ * \param[in] entry The entry to print the description for.
+ * \param[in] indent The number of spaces to pad the left margin with.
+ */
+static void cli__print_description(const struct cli_table_entry *entry,
+ size_t indent)
+{
+ if (entry->d != NULL) {
+ cli__print_wrapping_string(entry->d, indent);
}
fprintf(stderr, "\n");
+
+ if (entry->t == CLI_ENUM) {
+ size_t max_len = 0;
+
+ for (const struct cli_str_val *e = entry->v.e.desc;
+ e->str != NULL; e++) {
+ size_t len = strlen(e->str);
+ if (max_len < len) {
+ max_len = len;
+ }
+ }
+
+ fprintf(stderr, "\n");
+
+ for (const struct cli_str_val *e = entry->v.e.desc;
+ e->str != NULL; e++) {
+ fprintf(stderr, " ");
+
+ if (e->d == NULL || e->d[0] == '\0') {
+ fprintf(stderr, "%s\n",
+ e->str);
+ } else {
+ fprintf(stderr, "%-*s - ",
+ (int)(max_len),
+ e->str);
+ cli__print_wrapping_string(e->d,
+ 8 + max_len + 3);
+ fprintf(stderr, "\n");
+ }
+ }
+ }
}
/* Documented in cli.h */
@@ -679,6 +738,12 @@ void cli_help(const struct cli_table *cli, const char *prog_name)
cli__count(cli, &count, &pcount, &max_len, &pmax_len, &phas_desc);
+ if (cli->d != NULL) {
+ fprintf(stderr, "\n");
+ cli__print_wrapping_string(cli->d, 0);
+ fprintf(stderr, "\n");
+ }
+
fprintf(stderr, "\nUsage: %s", prog_name);
if (pcount > 0) {
diff --git a/test/cli.h b/test/cli.h
index 91db086..ffcd272 100644
--- a/test/cli.h
+++ b/test/cli.h
@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: ISC
*
- * Copyright (C) 2021 Michael Drake <tlsa(a)netsurf-browser.org>
+ * Copyright (C) 2021-2022 Michael Drake <tlsa(a)netsurf-browser.org>
*/
/**
@@ -34,13 +34,16 @@ enum cli_arg_type {
CLI_STRING, /**< Has string value. */
};
+/** Enum value descriptor. */
struct cli_str_val {
- const char *str;
- int64_t val;
+ const char *str; /**< String for the enum value name. */
+ int64_t val; /**< The value for this string. */
+ const char *d; /**< Description of this value for help output. */
};
+/** Enum data. */
struct cli_enum {
- const struct cli_str_val *desc;
+ const struct cli_str_val *desc; /**< Array describing enum values. */
int64_t *e; /**< Location to store \ref CLI_ENUM value. */
};
@@ -51,15 +54,16 @@ struct cli_table_entry {
const char *l; /**< Long argument name. */
const char s; /**< Short flag name. (Non-positional arguments.) */
bool p; /**< Whether the argument is a positional argument. */
+ bool no_pos; /**< When present, no positional arguments are required. */
enum cli_arg_type t; /**< Argument type. */
union {
bool *b; /**< Location to store \ref CLI_BOOL value. */
int64_t *i; /**< Location to store \ref CLI_INT value. */
uint64_t *u; /**< Location to store \ref CLI_UINT value. */
const char **s; /**< Location to store \ref CLI_STRING value. */
- struct cli_enum e;
+ struct cli_enum e; /**< \ref CLI_ENUM value details. */
} v; /**< Where to store type-specific values. */
- const char *d; /**< Description. */
+ const char *d; /**< Description of this argument for help output. */
};
/**
@@ -69,6 +73,7 @@ struct cli_table {
const struct cli_table_entry *entries;
size_t count;
size_t min_positional;
+ const char *d; /**< Description of this application for help output. */
};
/**
diff --git a/test/nsgif.c b/test/nsgif.c
index 7d61504..f873bab 100644
--- a/test/nsgif.c
+++ b/test/nsgif.c
@@ -29,15 +29,17 @@ static struct nsgif_options {
uint64_t loops;
bool palette;
bool info;
+ bool help;
} nsgif_options;
static const struct cli_table_entry cli_entries[] = {
{
- .s = 'm',
- .l = "ppm",
- .t = CLI_STRING,
- .v.s = &nsgif_options.ppm,
- .d = "Convert frames to PPM image at given path."
+ .s = 'h',
+ .l = "help",
+ .t = CLI_BOOL,
+ .no_pos = true,
+ .v.b = &nsgif_options.help,
+ .d = "Print this text.",
},
{
.s = 'i',
@@ -55,6 +57,13 @@ static const struct cli_table_entry cli_entries[] = {
"The default is 1."
},
{
+ .s = 'm',
+ .l = "ppm",
+ .t = CLI_STRING,
+ .v.s = &nsgif_options.ppm,
+ .d = "Convert frames to PPM image at given path."
+ },
+ {
.s = 'p',
.l = "palette",
.t = CLI_BOOL,
@@ -74,6 +83,7 @@ const struct cli_table cli = {
.entries = cli_entries,
.count = (sizeof(cli_entries))/(sizeof(*cli_entries)),
.min_positional = 1,
+ .d = "NSGIF - A utility for inspecting and decoding GIFs with libnsgif",
};
static void *bitmap_create(int width, int height)
@@ -357,6 +367,11 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
}
+ if (nsgif_options.help) {
+ cli_help(&cli, argv[0]);
+ return EXIT_SUCCESS;
+ }
+
if (nsgif_options.ppm != NULL) {
ppm = fopen(nsgif_options.ppm, "w+");
if (ppm == NULL) {
--
NetSurf GIF Decoder
8 months, 3 weeks