An ADD_IMG_ALT_MODIFIER DIFF file using DIFFCMD=diff -u - 12 files modified
1.
diff -u C:\FGCVS\Tidy\include\platform.h include\platform.h
**************** separator line only ****************
--- C:\FGCVS\Tidy\include\platform.h Wed Jun 15 14:45:39 2005
+++ include\platform.h Wed Jan 18 14:43:00 2006
@@ -50,6 +50,27 @@
/* #define SUPPORT_GETPWNAM */
+/* =====================================================
+ Enhanced IMG ALT text processing.
+ Define ADD_IMG_ALT_MODIFIER to provide a more meaningful
+ alt="text" to the IMG element. Tidy presently has an
+ option alt-text to add static text. This extends that
+ option to add variables to the string.
+This function ADDS an alt="..." attribute to an img element
+with a modifier in the Description
+%f add full path/file name of src.
+%n add file name only, no path.
+%p add just path name, if any.
+%s add file short title, no extension, or path.
+%x add file extension only.
+some problems 'finding the file', but if found
+%t add the date and time of file, if file found.
+%z add the size of file, if file found.
+And, of course these two will NOT function if
+other than tidyDocParseFile(...) is used.
+Of course, if you want to add a '%' just add 2
+ ====================================================== */
+#define ADD_IMG_ALT_MODIFIER
/* Enable/disable support for Big5 and Shift_JIS character encodings */
#ifndef SUPPORT_ASIAN_ENCODINGS
**************** separator line only ****************
2.
diff -u C:\FGCVS\Tidy\console\tidy.c console\tidy.c
**************** separator line only ****************
--- C:\FGCVS\Tidy\console\tidy.c Fri Oct 21 11:53:23 2005
+++ console\tidy.c Wed Jan 18 15:49:16 2006
@@ -197,6 +197,12 @@
". 0 is assumed if is missing.",
"accessibility-check: ", CmdOptProcDir },
#endif
+#ifdef ADD_IMG_ALT_MODIFIER
+ { "-alt-text ",
+ "add ALT attribute to IMG element, if missing. ( can include modifiers, src related: "
+ "%f=full name; %n name only; %p path; %s title; %x ext, if src %t time %z size.)",
+ NULL, CmdOptProcDir },
+#endif /* #ifdef ADD_IMG_ALT_MODIFIER */
{ "-raw",
"output values above 127 without conversion to entities",
NULL, CmdOptCharEnc },
@@ -266,6 +272,12 @@
{ "-show-config",
"list the current configuration settings",
NULL, CmdOptMisc },
+#ifdef ADD_IMG_ALT_MODIFIER
+ { "-show-alt-text",
+ "list alt-text options.",
+ NULL, CmdOptMisc },
+#endif /* #ifdef ADD_IMG_ALT_MODIFIER */
+ /* ALWAYS last in list */
{ NULL, NULL, NULL, CmdOptMisc }
};
@@ -822,6 +834,26 @@
ForEachSortedOption( tdoc, printOption );
}
+#ifdef ADD_IMG_ALT_MODIFIER
+void optionalttext( TidyDoc tdoc )
+{
+ printf( "Details of alt-text option.\n" );
+ printf( "This option ADDS an alt=\"...\" attribute to an img element, if none exists,\n" );
+ printf( "with the following modifiers available in the -\n" );
+ printf( " %%f add full path/file name of src.\n" );
+ printf( " %%n add file name only, no path.\n" );
+ printf( " %%p add just path name, if any.\n" );
+ printf( " %%s add file short title, no extension, or path.\n" );
+ printf( " %%x add file extension only.\n" );
+ printf( "Following 2 only available if source image file found\n" );
+ printf( "using a relative path. Will not function if URL used\n" );
+ printf( "in 'src' attribute.\n" );
+ printf( " %%t add the date and time of file, if file found.\n" );
+ printf( " %%z add the size of file, if file found.\n" );
+ printf( "Of course, if you want to add a '%%' to the text, just add 2 ...\n" );
+}
+#endif /* #ifdef ADD_IMG_ALT_MODIFIER */
+
static
void printOptionValues( TidyDoc ARG_UNUSED(tdoc), TidyOption topt,
OptionDesc *d )
@@ -1043,6 +1075,13 @@
tidyRelease( tdoc );
return 0; /* success */
}
+#ifdef ADD_IMG_ALT_MODIFIER
+ else if ( strcasecmp(arg, "show-alt-text") == 0 )
+ {
+ optionalttext( tdoc );
+ return 0; /* success */
+ }
+#endif /* #ifdef ADD_IMG_ALT_MODIFIER */
else if ( strcasecmp(arg, "config") == 0 )
{
if ( argc >= 3 )
**************** separator line only ****************
3.
diff -u C:\FGCVS\Tidy\src\attrs.c src\attrs.c
**************** separator line only ****************
--- C:\FGCVS\Tidy\src\attrs.c Mon Nov 14 10:07:10 2005
+++ src\attrs.c Wed Jan 18 14:45:13 2006
@@ -16,6 +16,9 @@
#include "message.h"
#include "tmbstr.h"
#include "utf8.h"
+#ifdef ADD_IMG_ALT_MODIFIER
+#include "time.h" /* for ctime() function */
+#endif /* #ifdef ADD_IMG_ALT_MODIFIER */
static AttrCheck CheckAction;
@@ -1674,6 +1677,217 @@
}
return;
}
+
+#ifdef ADD_IMG_ALT_MODIFIER
+/* =====================================================
+ Enhanced IMG ALT text processing.
+ Define ADD_IMG_ALT_MODIFIER to provide a more meaningful
+ alt="text" to the IMG element. Tidy presently has an
+ option alt-text to add static text. This extends that
+ option to add variables to the string.
+This function ADDS an alt="..." attribute to an img element
+with a modifier in the Description
+%f add full path/file name of src.
+%n add file name only, no path.
+%p add just path name, if any.
+%s add file short title, no extension, or path.
+%x add file extension only.
+maybe some problems 'finding the file', but
+%t add the date and time of file, if file found.
+%z add the size of file, if file found.
+And, of course these two will NOT function if
+other than tidyDocParseFile(...) is used.
+Of course, if you want to add a '%' just add 2
+ ====================================================== */
+
+static void dos_2_unix( tmbstr path )
+{
+ int i, len = tmbstrlen(path);
+ for( i = 0; i < len; i++ ) {
+ if( path[i] == '\\' )
+ path[i] = '/';
+ }
+}
+
+static int _get_file_info( TidyDocImpl* doc, tmbstr ftb, tmbstr sn, int type )
+{
+ static struct stat stat_buf;
+ int pos;
+ *ftb = 0;
+#ifdef WIN32
+ /* NOTE: this is NOT really required!
+ but, if there is a similar function in *nix? */
+ _fullpath(ftb, doc->inputFile, 256);
+#endif /* #ifdef WIN32 */
+ if(*ftb == 0)
+ tmbstrcpy(ftb, doc->inputFile);
+ dos_2_unix(ftb); /* ensure unix form */
+ pos = tmbstrrchr(ftb, tmbstrlen(ftb), '/') + 1;
+ tmbstrcpy( &ftb[pos], sn );
+ if ( stat(ftb,&stat_buf) == 0 ) {
+ if( type == 1 )
+ tmbstrcpy(ftb, (ctmbstr)ctime( &stat_buf.st_ctime ));
+ else
+ /* sprintf(ftb, "%u", stat_buf.st_size ); */
+ tmbsnprintf(ftb, 256, "%u", stat_buf.st_size);
+ } else {
+ /* failed - add anything? */
+ *ftb = 0;
+ if( type == 1 )
+ tmbstrcpy(ftb,"time unknown");
+ else
+ tmbstrcpy(ftb,"size unknown");
+ }
+ return tmbstrlen(ftb);
+}
+
+static int _get_file_size( TidyDocImpl* doc, tmbstr ftb, tmbstr sn )
+{
+ return _get_file_info( doc, ftb, sn, 0 );
+}
+static int _get_file_time( TidyDocImpl* doc, tmbstr ftb, tmbstr sn )
+{
+ return _get_file_info( doc, ftb, sn, 1 );
+}
+
+AttVal * AddAttributeAlt( TidyDocImpl* doc,
+ Node *node, ctmbstr name, ctmbstr value )
+{
+ AttVal *av = NewAttribute();
+
+ av->delim = '"';
+ av->attribute = tmbstrdup(name);
+
+ if (value) {
+ int len = tmbstrlen(value);
+ AttVal * sav = AttrGetById(node, TidyAttr_SRC);
+ tmbstr sn2 = sav ? sav->value : NULL;
+ int len2 = sn2 ? tmbstrlen(sn2) : 0;
+ if(len && len2 && (tmbstrnchr(value,len,'%') >= 0)) {
+ tmbstr sn = tmbstrdup(sn2); /* duplicate, in case modified */
+ tmbstr ts = MemAlloc(1024+264); /* get buffer for expansion */
+ tmbstr ftb = &ts[1024]; /* and for file time and size ... */
+ int i, c, io, i2, i3, pos;
+ len2 = tmbstrlen(sn);
+ if(tmbstrnchr(sn,len2,'%') >= 0) {
+ io = 0;
+ for( i = 0; i < len2; i++ ) {
+ c = sn[i];
+ if( c == '%' ) { /* found hex ... */
+ if(( (i + 2) < len2 ) && IsDigit(sn[i+1]) && IsDigit(sn[i+2])) {
+ c = ((sn[i+1] - '0') * 16) + (sn[i+2] - '0');
+ i += 2;
+ }
+ }
+ sn[io++] = (tmbchar)c;
+ }
+ sn[io] = 0;
+ len2 = io;
+ }
+ io = 0;
+ for( i = 0; i < len; i++ ) { /* process the string given */
+ c = value[i]; /* extract next */
+ if( c == '%' ) { /* our switch */
+ i++; /* to next value ... */
+ if( i < len ) {
+ c = value[i];
+ switch(c)
+ {
+ case '%': /* %% adds one */
+ ts[io++] = (tmbchar)c;
+ break;
+ case 'f': /* %f add full path file name of src. */
+ if(len2) {
+ for( i2 = 0; i2 < len2; i2++ ) {
+ ts[io++] = sn[i2];
+ }
+ }
+ break;
+ case 'n': /* %n add file name only, no path. */
+ if(len2) {
+ pos = tmbstrrchr(sn, len2, '/'); /* ret=-1 if NOT */
+ for( i2 = pos + 1; i2 < len2; i2++ ) {
+ ts[io++] = sn[i2];
+ }
+ }
+ break;
+ case 'p': /* %p add just path name, if any. */
+ if(len2) {
+ pos = tmbstrrchr(sn, len2, '/'); /* ret=-1 if NOT */
+ pos++;
+ for( i2 = 0; i2 < pos; i2++ ) {
+ ts[io++] = sn[i2];
+ }
+ }
+ break;
+ case 's': /* %s add file short name title, no extension, or path. */
+ if(len2) {
+ int pos2 = tmbstrrchr(sn, len2, '.');
+ pos = tmbstrrchr(sn, len2, '/'); /* ret=-1 if NOT */
+ if(pos2 < 0)
+ pos2 = len2;
+ for( i2 = pos + 1; i2 < pos2; i2++ ) {
+ ts[io++] = sn[i2];
+ }
+ }
+ break;
+ case 't': /* %t add the date and time of file, if file found. */
+ if(len2) {
+ if( doc->inputFile ) {
+ *ftb = 0;
+ i3 = _get_file_time( doc, ftb, sn );
+ for( i2 = 0; i2 < i3; i2++ ) {
+ if( ftb[i2] == '\n' ) /* ctime(...) adds this ... */
+ break;
+ ts[io++] = ftb[i2];
+ }
+ }
+ }
+ break;
+ case 'x': /* %x add file extension only. */
+ if(len2) {
+ pos = tmbstrrchr(sn, len2, '.'); /* ret=-1 if NOT */
+ for( i2 = pos + 1; i2 < len2; i2++ ) {
+ ts[io++] = sn[i2];
+ }
+ }
+ break;
+ case 'z': /* %z add the size of file, if file found. */
+ if(len2) {
+ if( doc->inputFile ) {
+ *ftb = 0;
+ i3 = _get_file_size( doc, ftb, sn );
+ for( i2 = 0; i2 < i3; i2++ ) {
+ ts[io++] = ftb[i2];
+ }
+ }
+ }
+ break;
+ /* quietly ignore anything else??? */
+ }
+ }
+ continue;
+ } else {
+ ts[io++] = (tmbchar)c;
+ }
+ }
+ ts[io] = 0; /* zero terminate string */
+ av->value = tmbstrdup(ts);
+ MemFree(ts);
+ MemFree(sn);
+ } else
+ av->value = tmbstrdup(value);
+ } else
+ av->value = NULL;
+
+ av->dict = lookup(&doc->attribs, name);
+
+ InsertAttributeAtEnd(node, av);
+
+ return av;
+}
+
+#endif /* #ifdef ADD_IMG_ALT_MODIFIER */
/*
* local variables:
**************** separator line only ****************
4.
diff -u C:\FGCVS\Tidy\src\attrs.h src\attrs.h
**************** separator line only ****************
--- C:\FGCVS\Tidy\src\attrs.h Thu Nov 10 17:51:59 2005
+++ src\attrs.h Wed Jan 18 14:43:00 2006
@@ -127,6 +127,11 @@
AttVal* AddAttribute( TidyDocImpl* doc,
Node *node, ctmbstr name, ctmbstr value );
+#ifdef ADD_IMG_ALT_MODIFIER
+AttVal* AddAttributeAlt( TidyDocImpl* doc,
+ Node *node, ctmbstr name, ctmbstr value );
+#endif /* #ifdef ADD_IMG_ALT_MODIFIER */
+
AttVal* RepairAttrValue(TidyDocImpl* doc, Node* node, ctmbstr name, ctmbstr value);
Bool IsUrl( TidyDocImpl* doc, ctmbstr attrname );
**************** separator line only ****************
5.
diff -u C:\FGCVS\Tidy\src\localize.c src\localize.c
**************** separator line only ****************
--- C:\FGCVS\Tidy\src\localize.c Thu Nov 10 17:51:59 2005
+++ src\localize.c Wed Jan 18 15:05:53 2006
@@ -30,7 +30,11 @@
*/
#define ATRC_ACCESS_URL "http://www.aprompt.ca/Tidy/accessibilitychecks.html"
+#ifdef ADD_IMG_ALT_MODIFIER
+static const char release_date[] = "18 January 2006";
+#else /* !#ifdef ADD_IMG_ALT_MODIFIER */
static const char release_date[] = "11 November 2005";
+#endif /* #ifdef ADD_IMG_ALT_MODIFIER y/n */
ctmbstr ReleaseDate(void)
{
@@ -1571,7 +1575,7 @@
{
tidy_out(doc, "For further advice on how to make your pages accessible, see\n");
tidy_out(doc, "%s", ACCESS_URL );
- tidy_out(doc, "and\n" );
+ tidy_out(doc, " and\n" );
tidy_out(doc, "%s", ATRC_ACCESS_URL );
tidy_out(doc, ".\n" );
tidy_out(doc, "You may also want to try \"http://www.cast.org/bobby/\" which is a free Web-based\n");
**************** separator line only ****************
6.
diff -u C:\FGCVS\Tidy\src\tags.c src\tags.c
**************** separator line only ****************
--- C:\FGCVS\Tidy\src\tags.c Mon Nov 14 10:07:10 2005
+++ src\tags.c Wed Jan 18 14:43:00 2006
@@ -630,8 +630,13 @@
ReportMissingAttr( doc, node, "alt" );
}
- if ( cfgStr(doc, TidyAltText) )
+ if ( cfgStr(doc, TidyAltText) ) {
+#ifdef ADD_IMG_ALT_MODIFIER
+ AddAttributeAlt( doc, node, "alt", cfgStr(doc, TidyAltText) );
+#else /* !#ifdef ADD_IMG_ALT_MODIFIER */
AddAttribute( doc, node, "alt", cfgStr(doc, TidyAltText) );
+#endif /* #ifdef ADD_IMG_ALT_MODIFIER y/n */
+ }
}
if ( !HasSrc && !HasDataFld )
**************** separator line only ****************
7.
diff -u C:\FGCVS\Tidy\src\tidy-int.h src\tidy-int.h
**************** separator line only ****************
--- C:\FGCVS\Tidy\src\tidy-int.h Sat Mar 06 18:07:02 2004
+++ src\tidy-int.h Wed Jan 18 14:43:00 2006
@@ -83,6 +83,11 @@
struct utimbuf filetimes;
#endif
tmbstr givenDoctype;
+
+#ifdef ADD_IMG_ALT_MODIFIER
+ ctmbstr inputFile; /* pointer to current input */
+#endif /* #ifdef ADD_IMG_ALT_MODIFIER */
+
};
**************** separator line only ****************
8.
diff -u C:\FGCVS\Tidy\src\tidylib.c src\tidylib.c
**************** separator line only ****************
--- C:\FGCVS\Tidy\src\tidylib.c Wed Aug 03 20:07:01 2005
+++ src\tidylib.c Wed Jan 18 14:43:00 2006
@@ -788,6 +788,9 @@
int TIDY_CALL tidyParseFile( TidyDoc tdoc, ctmbstr filnam )
{
TidyDocImpl* doc = tidyDocToImpl( tdoc );
+#ifdef ADD_IMG_ALT_MODIFIER
+ doc->inputFile = filnam; /* pointer to current input */
+#endif /* #ifdef ADD_IMG_ALT_MODIFIER */
return tidyDocParseFile( doc, filnam );
}
int TIDY_CALL tidyParseStdin( TidyDoc tdoc )
**************** separator line only ****************
9.
diff -u C:\FGCVS\Tidy\src\tmbstr.c src\tmbstr.c
**************** separator line only ****************
--- C:\FGCVS\Tidy\src\tmbstr.c Mon Aug 02 04:32:09 2004
+++ src\tmbstr.c Wed Jan 18 14:43:00 2006
@@ -288,3 +288,21 @@
va_end(args);
return retval;
}
+
+#ifdef ADD_IMG_ALT_MODIFIER
+/* return offset of cc from end of s1,
+** -1 if not found.
+*/
+int tmbstrrchr( ctmbstr s1, uint maxlen, tmbchar cc )
+{
+ int i;
+ if(maxlen > 0) {
+ for ( i = (int)(maxlen - 1); i >= 0; i-- ) {
+ if( s1[i] == cc )
+ return i;
+ }
+ }
+ return -1;
+}
+#endif /* #ifdef ADD_IMG_ALT_MODIFIER */
+
**************** separator line only ****************
10.
diff -u C:\FGCVS\Tidy\src\tmbstr.h src\tmbstr.h
**************** separator line only ****************
--- C:\FGCVS\Tidy\src\tmbstr.h Mon Dec 06 16:05:29 2004
+++ src\tmbstr.h Wed Jan 18 14:43:00 2006
@@ -85,6 +85,10 @@
#endif
;
+#ifdef ADD_IMG_ALT_MODIFIER
+int tmbstrrchr( ctmbstr s1, uint maxlen, tmbchar cc );
+#endif /* #ifdef ADD_IMG_ALT_MODIFIER */
+
#ifdef __cplusplus
} /* extern "C" */
#endif
**************** separator line only ****************
11.
diff -u C:\FGCVS\Tidy\htmldoc\Overview.html htmldoc\Overview.html
**************** separator line only ****************
--- C:\FGCVS\Tidy\htmldoc\Overview.html Fri May 25 11:34:41 2001
+++ htmldoc\Overview.html Wed Jan 18 16:10:25 2006
@@ -1001,6 +1001,28 @@
accessibility warnings. YOU ARE RESPONSIBLE FOR MAKING YOUR
DOCUMENTS ACCESSIBLE TO PEOPLE WHO CAN'T SEE THE
IMAGES!!!
+#ifdef ADD_IMG_ALT_MODIFIER /* if this is defined for the compile ... */
+Then, the string can include some modifiers that should help you make the alt
+text more meaningful ... but nothing beats a personalised image file
+description ... like "Mother, on her 80th birthday!" ...
+%f add full path/file name of src.
+%n add file name only, no path.
+%p add just path name, if any.
+%s add file short title, no extension, or path.
+%x add file extension only.
+and if the file can be found, in the relative path ...
+%t add the date and time of file, if file found.
+%z add the size of file, if file found.
+But it is worth REPEATING, and can NOT be stressed enough, YOU, AND ONLY
+YOU, ARE RESPONSIBLE FOR MAKING YOUR DOCUMENTS ACCESSIBLE TO PEOPLE WHO
+CAN'T SEE THE IMAGES CLEARLY!!! Please add to their life with a little
+of your effort!
+Now you can add alt-text: Image file %n, type %x, size %z, at %f, dated %t,
+or as you desire, to your config file, and add a little to their, and others,
+understanding of the web.
+Note, some accessibility warnings may remain, but you have added to the web
+experience ...
+#endif /* ADD_IMG_ALT_MODIFIER */
write-back: bool
**************** separator line only ****************
12.
diff -u C:\FGCVS\Tidy\htmldoc\release-notes.html htmldoc\release-notes.html
**************** separator line only ****************
--- C:\FGCVS\Tidy\htmldoc\release-notes.html Fri May 25 11:35:26 2001
+++ htmldoc\release-notes.html Wed Jan 18 16:14:27 2006
@@ -588,6 +588,12 @@
responsible for making your documents accessible to people who
can't view the images!
+This has recently been enhanced, January, 2006, to include modifiers in the
+string, if compiled using a ADD_IMG_ALT_MODIFIER, and this should help improve
+such 'automatic' additions, but this in no way absolves you of the
+responsibility to make such text meaningful. When re-compiled using the
+ADD_IMG_ALT_MODIFIER switch, use Tidy -show-alt-text to learn more.
+
Terry Teague spotted a bug in ParseConfigFile() that prevented
Tidy from parsing more that one file. This has been fixed by
setting the char buffer to zero in the call to InitConfig()
**************** separator line only ****************