www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2001/10/13/00:58:18

From: sandmann AT clio DOT rice DOT edu (Charles Sandmann)
Message-Id: <10110130452.AA20729@clio.rice.edu>
Subject: Re: W2K/XP fncase [was Re: New perl package]
To: eliz AT is DOT elta DOT co DOT il
Date: Fri, 12 Oct 2001 23:52:27 -0500 (CDT)
Cc: djgpp-workers AT delorie DOT com, tim DOT van DOT holder AT pandora DOT be, acottrel AT ihug DOT com DOT au
In-Reply-To: <1483-Sat13Oct2001004418+0200-eliz@is.elta.co.il> from "Eli Zaretskii" at Oct 13, 2001 12:44:19 AM
X-Mailer: ELM [version 2.5 PL2]
Mime-Version: 1.0
Reply-To: djgpp-workers AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp-workers AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

> That assumes we actually know how 71A8h works, which is what we need
> to duplicate.  I have some idea about that, but since it's nowehere
> documented, I cannot say if it's 100% true, since I never tested my
> hypothesis on too many files.

I think you are getting too worried about a broken Windows interrupt
here.  We use it merely to compare the name to the original file 
component to see if they are identical (including case).  If they 
are, we then lower case the name.  Attached is an example which
provides almost identical behavior to the windows version (and I
believe will behave completely identical when used with fncase stuff).
Tech-trivia: it handles spaces and multiple periods a bit differently,
but in those cases we want to leave the name alone anyway.

My basis was a Win95 OSR2 system.  It certainly behaves much better
on Win2K and XP than the interrupts.

#include <libc/stubs.h>
#include <fcntl.h>

static char short_char[] = {
0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,
0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,
0x5f,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2a,0x5f,0x5f,0x2d,0x2e,0x2f,
0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x5f,0x3c,0x5f,0x3e,0x3f,
0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,
0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a,0x5f,0x5c,0x5f,0x5e,0x5f,
0x60,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,
0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a,0x7b,0x7c,0x7d,0x7e,0x7f,
0x5f,0x5f,0x5f,0x83,0x5f,0x5f,0x5f,0x5f,0x5f,0x5f,0x5f,0x5f,0x5f,0x5f,0x5f,0x5f,
0x5f,0x5f,0x5f,0x5f,0x5f,0x5f,0x5f,0x5f,0x5f,0x5f,0x5f,0x5f,0x5f,0x5f,0x5f,0x5f,
0x5f,0xa1,0xa2,0xa3,0x5f,0xa5,0x5f,0x5f,0x5f,0x5f,0xaa,0xab,0xac,0x5f,0x5f,0x5f,
0xb0,0xb1,0xb2,0x5f,0x5f,0xb5,0x5f,0xb7,0x5f,0x5f,0xba,0xbb,0xbc,0xbd,0x5f,0xbf,
0x5f,0x5f,0x5f,0x5f,0xc4,0xc5,0xc6,0xc7,0x5f,0xc9,0x5f,0x5f,0x5f,0x5f,0x5f,0x5f,
0x5f,0xd1,0x5f,0x5f,0x5f,0x5f,0xd6,0x5f,0x5f,0x5f,0x5f,0x5f,0xdc,0x5f,0x5f,0xdf,
0x5f,0x5f,0x5f,0x5f,0xc4,0xc5,0xc6,0xc7,0x5f,0xc9,0x5f,0x5f,0x5f,0x5f,0x5f,0x5f,
0x5f,0xd1,0x5f,0x5f,0x5f,0x5f,0xd6,0xf7,0x5f,0x5f,0x5f,0x5f,0xdc,0x5f,0x5f,0x5f};

char *
_lfn_gen_short_fname(const char *long_fname, char *short_fname)
{
  const char *s = long_fname;
  char *e, *d = short_fname;
  char c, period_seen;

  if(*s == '.')			/* ignore starting period */
    s++;

  e = d + 8;			/* end */
  period_seen = 0;

  while ((*d++ = c = short_char[(unsigned char)*s++]))
    if (c == '.' && !period_seen) {
      period_seen = 1;
      e = d + 2;		/* already one past period */
    } else if (d > e) {
      if(period_seen) {
        *d = 0;
        break;
      } else
        *(--d) = 0;
    }

  if(*(d-2) == '.')		/* trim period from end of name */
   *(d-2) = 0;

  return short_fname;
}

#ifdef TEST
#include <stdio.h>

int main (int argc, char *argv[])
{
  char sh[13];
  if (argc > 1)
    printf ("Orig:  %s\nShort: %s\n",
	    argv[1], _lfn_gen_short_fname(argv[1], sh));
  return 0;
}

#endif

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019