home *** CD-ROM | disk | FTP | other *** search
- /* Unix/HPFS filename translation for FAT file systems */
-
- /* Author: Kai Uwe Rommel */
-
- #include <stddef.h>
- #include <string.h>
- #include <ctype.h>
-
-
- void ChangeNameForFAT(char *name)
- {
- char *src, *dst, *next, *ptr, *dot;
-
- if ( isalpha(name[0]) && (name[1] == ':') )
- src = dst = name + 2;
- else
- src = dst = name;
-
- if ( (*src == '/') || (*src == '\\') )
- src++, dst++;
-
- while ( *src )
- {
- for ( next = src; *next && (*next != '/') && (*next != '\\'); next++ );
-
- for ( ptr = src, dot = NULL; ptr < next; ptr++ )
- if ( *ptr == '.' )
- *(dot = ptr) = '_'; /* remember last dot */
-
- if ( dot && (dot > src) &&
- ((next - dot <= 4) ||
- ((next - src > 8) && (dot - src > 3))) )
- {
- *dot = '.';
-
- for ( ptr = src; (ptr < dot) && ((ptr - src) < 8); ptr++ )
- *dst++ = *ptr;
-
- for ( ptr = dot; (ptr < next) && ((ptr - dot) < 4); ptr++ )
- *dst++ = *ptr;
- }
- else
- for ( ptr = src; (ptr < next) && ((ptr - src) < 8); ptr++ )
- *dst++ = *ptr;
-
- *dst++ = *next; /* either '/' or 0 */
-
- if ( *next )
- {
- src = next + 1;
-
- if ( *src == 0 ) /* handle trailing '/' on dirs ! */
- *dst = 0;
- }
- else
- break;
- }
- }
-