diff -urN -x tidy.exe -x tidy.suo -x *.obj -x *.ncb -x *.sln -x *.vcproj -x *.pdb -x *.idb -x *.ilk -x *.pch -x *.lib -x BuildLog.htm -x upd.bat -x update.mak -x Debug -x DebugDLL -x Release -x ReleaseDLL -x CVS -x diff tidycvs\console\tidy.c tidydev3\console\tidy.c --- tidycvs\console\tidy.c Wed Feb 15 14:15:40 2006 +++ tidydev3\console\tidy.c Sun Feb 19 20:20:35 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 ) diff -urN -x tidy.exe -x tidy.suo -x *.obj -x *.ncb -x *.sln -x *.vcproj -x *.pdb -x *.idb -x *.ilk -x *.pch -x *.lib -x BuildLog.htm -x upd.bat -x update.mak -x Debug -x DebugDLL -x Release -x ReleaseDLL -x CVS -x diff tidycvs\htmldoc\Overview.html tidydev3\htmldoc\Overview.html --- tidycvs\htmldoc\Overview.html Fri May 25 11:34:41 2001 +++ tidydev3\htmldoc\Overview.html Sun Feb 19 20:33:26 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
diff -urN -x tidy.exe -x tidy.suo -x *.obj -x *.ncb -x *.sln -x *.vcproj -x *.pdb -x *.idb -x *.ilk -x *.pch -x *.lib -x BuildLog.htm -x upd.bat -x update.mak -x Debug -x DebugDLL -x Release -x ReleaseDLL -x CVS -x diff tidycvs\htmldoc\release-notes.html tidydev3\htmldoc\release-notes.html --- tidycvs\htmldoc\release-notes.html Fri May 25 11:35:26 2001 +++ tidydev3\htmldoc\release-notes.html Sun Feb 19 20:33:10 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() diff -urN -x tidy.exe -x tidy.suo -x *.obj -x *.ncb -x *.sln -x *.vcproj -x *.pdb -x *.idb -x *.ilk -x *.pch -x *.lib -x BuildLog.htm -x upd.bat -x update.mak -x Debug -x DebugDLL -x Release -x ReleaseDLL -x CVS -x diff tidycvs\include\platform.h tidydev3\include\platform.h --- tidycvs\include\platform.h Wed Feb 15 14:15:40 2006 +++ tidydev3\include\platform.h Sun Feb 19 20:30:03 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 diff -urN -x tidy.exe -x tidy.suo -x *.obj -x *.ncb -x *.sln -x *.vcproj -x *.pdb -x *.idb -x *.ilk -x *.pch -x *.lib -x BuildLog.htm -x upd.bat -x update.mak -x Debug -x DebugDLL -x Release -x ReleaseDLL -x CVS -x diff tidycvs\src\attrs.c tidydev3\src\attrs.c --- tidycvs\src\attrs.c Sun Feb 12 16:39:14 2006 +++ tidydev3\src\attrs.c Sun Feb 19 20:22: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; @@ -1687,6 +1690,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: diff -urN -x tidy.exe -x tidy.suo -x *.obj -x *.ncb -x *.sln -x *.vcproj -x *.pdb -x *.idb -x *.ilk -x *.pch -x *.lib -x BuildLog.htm -x upd.bat -x update.mak -x Debug -x DebugDLL -x Release -x ReleaseDLL -x CVS -x diff tidycvs\src\attrs.h tidydev3\src\attrs.h --- tidycvs\src\attrs.h Wed Jan 25 13:33:23 2006 +++ tidydev3\src\attrs.h Sun Feb 19 20:30:03 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 ); diff -urN -x tidy.exe -x tidy.suo -x *.obj -x *.ncb -x *.sln -x *.vcproj -x *.pdb -x *.idb -x *.ilk -x *.pch -x *.lib -x BuildLog.htm -x upd.bat -x update.mak -x Debug -x DebugDLL -x Release -x ReleaseDLL -x CVS -x diff tidycvs\src\tags.c tidydev3\src\tags.c --- tidycvs\src\tags.c Fri Jan 27 12:35:41 2006 +++ tidydev3\src\tags.c Sun Feb 19 20:30:03 2006 @@ -629,8 +629,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 ) diff -urN -x tidy.exe -x tidy.suo -x *.obj -x *.ncb -x *.sln -x *.vcproj -x *.pdb -x *.idb -x *.ilk -x *.pch -x *.lib -x BuildLog.htm -x upd.bat -x update.mak -x Debug -x DebugDLL -x Release -x ReleaseDLL -x CVS -x diff tidycvs\src\tidy-int.h tidydev3\src\tidy-int.h --- tidycvs\src\tidy-int.h Fri Jan 27 12:35:41 2006 +++ tidydev3\src\tidy-int.h Sun Feb 19 20:30:03 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 */ + }; diff -urN -x tidy.exe -x tidy.suo -x *.obj -x *.ncb -x *.sln -x *.vcproj -x *.pdb -x *.idb -x *.ilk -x *.pch -x *.lib -x BuildLog.htm -x upd.bat -x update.mak -x Debug -x DebugDLL -x Release -x ReleaseDLL -x CVS -x diff tidycvs\src\tidylib.c tidydev3\src\tidylib.c --- tidycvs\src\tidylib.c Wed Jan 25 18:43:39 2006 +++ tidydev3\src\tidylib.c Sun Feb 19 20:30:03 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 ) diff -urN -x tidy.exe -x tidy.suo -x *.obj -x *.ncb -x *.sln -x *.vcproj -x *.pdb -x *.idb -x *.ilk -x *.pch -x *.lib -x BuildLog.htm -x upd.bat -x update.mak -x Debug -x DebugDLL -x Release -x ReleaseDLL -x CVS -x diff tidycvs\src\tmbstr.c tidydev3\src\tmbstr.c --- tidycvs\src\tmbstr.c Mon Aug 02 04:32:09 2004 +++ tidydev3\src\tmbstr.c Sun Feb 19 20:30:03 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 */ + diff -urN -x tidy.exe -x tidy.suo -x *.obj -x *.ncb -x *.sln -x *.vcproj -x *.pdb -x *.idb -x *.ilk -x *.pch -x *.lib -x BuildLog.htm -x upd.bat -x update.mak -x Debug -x DebugDLL -x Release -x ReleaseDLL -x CVS -x diff tidycvs\src\tmbstr.h tidydev3\src\tmbstr.h --- tidycvs\src\tmbstr.h Mon Dec 06 16:05:29 2004 +++ tidydev3\src\tmbstr.h Sun Feb 19 20:30:03 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 diff -urN -x tidy.exe -x tidy.suo -x *.obj -x *.ncb -x *.sln -x *.vcproj -x *.pdb -x *.idb -x *.ilk -x *.pch -x *.lib -x BuildLog.htm -x upd.bat -x update.mak -x Debug -x DebugDLL -x Release -x ReleaseDLL -x CVS -x diff tidycvs\src\version.h tidydev3\src\version.h --- tidycvs\src\version.h Wed Feb 15 14:15:44 2006 +++ tidydev3\src\version.h Sun Feb 19 20:23:16 2006 @@ -11,4 +11,4 @@ */ -static const char release_date[] = "14 February 2006"; +static const char release_date[] = "14 February 2006 (tidydev3)";