bool CNCSJPCMainHeader::CloseEncoderFiles(bool bDelete)
{
	bool bRet = true;
	if(m_pEncoderPLTFile) {
		char *pPLTFilename = bDelete ? NCSStrDup(CHAR_STRING(m_pEncoderPLTFile->GetName())) : NULL;
		bRet = m_pEncoderPLTFile->Close() == NCS_SUCCESS;
		if(bDelete && pPLTFilename) {
			NCSDeleteFile(pPLTFilename);
			NCSFree(pPLTFilename);
		}
		delete m_pEncoderPLTFile;
		m_pEncoderPLTFile = NULL;
	}
	if(m_pEncoderOffsetFile) {
		char *pPLTFilename = bDelete ? NCSStrDup(CHAR_STRING(m_pEncoderOffsetFile->GetName())) : NULL;
		bRet = m_pEncoderOffsetFile->Close() == NCS_SUCCESS;
		if(bDelete && pPLTFilename) {
			NCSDeleteFile(pPLTFilename);
			NCSFree(pPLTFilename);
		}
		delete m_pEncoderOffsetFile;
		m_pEncoderOffsetFile = NULL;
	}
	for(INT32 r = 0; r < (INT32)m_EncoderFiles.size(); r++) {
		char *pPLTFilename = bDelete ? NCSStrDup(CHAR_STRING(m_EncoderFiles[r]->GetName())) : NULL;
		bRet = m_EncoderFiles[r]->Close() == NCS_SUCCESS;
		if(bDelete && pPLTFilename) {
			NCSDeleteFile(pPLTFilename);
			NCSFree(pPLTFilename);
		}
		delete m_EncoderFiles[r];
		m_EncoderFiles[r] = NULL;
	}
	m_EncoderFiles.clear();
	return(bRet);
}
Beispiel #2
0
static ptrdiff_t
xfont_decode_coding_xlfd (char *xlfd, int len, char *output)
{
  char *p0 = xlfd, *p1 = output;
  int c;

  while (*p0)
    {
      c = *(unsigned char *) p0++;
      p1 += CHAR_STRING (c, (unsigned char *) p1);
      if (--len == 0)
	break;
    }
  *p1 = 0;
  return (p1 - output);
}
Beispiel #3
0
int
doprnt (char *buffer, register int bufsize, const char *format,
        const char *format_end, va_list ap)
{
    const char *fmt = format;	/* Pointer into format string */
    register char *bufptr = buffer; /* Pointer into output buffer.. */

    /* Use this for sprintf unless we need something really big.  */
    char tembuf[DBL_MAX_10_EXP + 100];

    /* Size of sprintf_buffer.  */
    unsigned size_allocated = sizeof (tembuf);

    /* Buffer to use for sprintf.  Either tembuf or same as BIG_BUFFER.  */
    char *sprintf_buffer = tembuf;

    /* Buffer we have got with malloc.  */
    char *big_buffer = 0;

    register int tem;
    unsigned char *string;
    char fixed_buffer[20];	/* Default buffer for small formatting. */
    char *fmtcpy;
    int minlen;
    unsigned char charbuf[MAX_MULTIBYTE_LENGTH + 1];	/* Used for %c.  */

    if (format_end == 0)
        format_end = format + strlen (format);

    if ((format_end - format + 1) < sizeof (fixed_buffer))
        fmtcpy = fixed_buffer;
    else
        fmtcpy = (char *) alloca (format_end - format + 1);

    bufsize--;

    /* Loop until end of format string or buffer full. */
    while (fmt != format_end && bufsize > 0)
    {
        if (*fmt == '%')	/* Check for a '%' character */
        {
            unsigned size_bound = 0;
            int width;		/* Columns occupied by STRING.  */

            fmt++;
            /* Copy this one %-spec into fmtcpy.  */
            string = (unsigned char *) fmtcpy;
            *string++ = '%';
            while (1)
            {
                *string++ = *fmt;
                if ('0' <= *fmt && *fmt <= '9')
                {
                    /* Get an idea of how much space we might need.
                       This might be a field width or a precision; e.g.
                       %1.1000f and %1000.1f both might need 1000+ bytes.
                       Parse the width or precision, checking for overflow.  */
                    unsigned n = *fmt - '0';
                    while ('0' <= fmt[1] && fmt[1] <= '9')
                    {
                        if (n * 10 + fmt[1] - '0' < n)
                            error ("Format width or precision too large");
                        n = n * 10 + fmt[1] - '0';
                        *string++ = *++fmt;
                    }

                    if (size_bound < n)
                        size_bound = n;
                }
                else if (*fmt == '-' || *fmt == ' ' || *fmt == '.' || *fmt == '+')
                    ;
                else
                    break;
                fmt++;
            }
            *string = 0;

            /* Make the size bound large enough to handle floating point formats
               with large numbers.  */
            if (size_bound + DBL_MAX_10_EXP + 50 < size_bound)
                error ("Format width or precision too large");
            size_bound += DBL_MAX_10_EXP + 50;

            /* Make sure we have that much.  */
            if (size_bound > size_allocated)
            {
                if (big_buffer)
                    big_buffer = (char *) xrealloc (big_buffer, size_bound);
                else
                    big_buffer = (char *) xmalloc (size_bound);
                sprintf_buffer = big_buffer;
                size_allocated = size_bound;
            }
            minlen = 0;
            switch (*fmt++)
            {
            default:
                error ("Invalid format operation %%%c", fmt[-1]);

            /*	    case 'b': */
            case 'd':
            case 'o':
            case 'x':
                if (sizeof (int) == sizeof (EMACS_INT))
                    ;
                else if (sizeof (long) == sizeof (EMACS_INT))
                    /* Insert an `l' the right place.  */
                    string[1] = string[0],
                                string[0] = string[-1],
                                            string[-1] = 'l',
                                                         string++;
                else
                    abort ();
                sprintf (sprintf_buffer, fmtcpy, va_arg(ap, char *));
                /* Now copy into final output, truncating as nec.  */
                string = (unsigned char *) sprintf_buffer;
                goto doit;

            case 'f':
            case 'e':
            case 'g':
            {
                double d = va_arg(ap, double);
                sprintf (sprintf_buffer, fmtcpy, d);
                /* Now copy into final output, truncating as nec.  */
                string = (unsigned char *) sprintf_buffer;
                goto doit;
            }

            case 'S':
                string[-1] = 's';
            case 's':
                if (fmtcpy[1] != 's')
                    minlen = atoi (&fmtcpy[1]);
                string = va_arg(ap, unsigned char *);
                tem = strlen (string);
                width = strwidth (string, tem);
                goto doit1;

                /* Copy string into final output, truncating if no room.  */
doit:
                /* Coming here means STRING contains ASCII only.  */
                width = tem = strlen (string);
doit1:
                /* We have already calculated:
                TEM -- length of STRING,
                 WIDTH -- columns occupied by STRING when displayed, and
                 MINLEN -- minimum columns of the output.  */
                if (minlen > 0)
                {
                    while (minlen > width && bufsize > 0)
                    {
                        *bufptr++ = ' ';
                        bufsize--;
                        minlen--;
                    }
                    minlen = 0;
                }
                if (tem > bufsize)
                {
                    /* Truncate the string at character boundary.  */
                    tem = bufsize;
                    while (!CHAR_HEAD_P (string[tem - 1])) tem--;
                    memcpy (bufptr, string, tem);
                    /* We must calculate WIDTH again.  */
                    width = strwidth (bufptr, tem);
                }
                else
                    memcpy (bufptr, string, tem);
                bufptr += tem;
                bufsize -= tem;
                if (minlen < 0)
                {
                    while (minlen < - width && bufsize > 0)
                    {
                        *bufptr++ = ' ';
                        bufsize--;
                        minlen++;
                    }
                    minlen = 0;
                }
                continue;

            case 'c':
            {
                /* Sometimes for %c we pass a char, which would widen
                   to int.  Sometimes we pass XFASTINT() or XINT()
                   values, which would be EMACS_INT.  Let's hope that
                   both are passed the same way, otherwise we'll need
                   to rewrite callers.  */
                EMACS_INT chr = va_arg(ap, EMACS_INT);
                tem = CHAR_STRING ((int) chr, charbuf);
                string = charbuf;
                string[tem] = 0;
                width = strwidth (string, tem);
                if (fmtcpy[1] != 'c')
                    minlen = atoi (&fmtcpy[1]);
                goto doit1;
            }

            case '%':
                fmt--;    /* Drop thru and this % will be treated as normal */
            }
        }

        {
            /* Just some character; Copy it if the whole multi-byte form
               fit in the buffer.  */
            char *save_bufptr = bufptr;

            do {
                *bufptr++ = *fmt++;
            }
            while (--bufsize > 0 && !CHAR_HEAD_P (*fmt));
            if (!CHAR_HEAD_P (*fmt))
            {
                bufptr = save_bufptr;
                break;
            }
        }
    };
Beispiel #4
0
ptrdiff_t
doprnt (char *buffer, ptrdiff_t bufsize, const char *format,
	const char *format_end, va_list ap)
{
  const char *fmt = format;	/* Pointer into format string.  */
  char *bufptr = buffer;	/* Pointer into output buffer.  */

  /* Use this for sprintf unless we need something really big.  */
  char tembuf[DBL_MAX_10_EXP + 100];

  /* Size of sprintf_buffer.  */
  ptrdiff_t size_allocated = sizeof (tembuf);

  /* Buffer to use for sprintf.  Either tembuf or same as BIG_BUFFER.  */
  char *sprintf_buffer = tembuf;

  /* Buffer we have got with malloc.  */
  char *big_buffer = NULL;

  enum text_quoting_style quoting_style = text_quoting_style ();
  ptrdiff_t tem = -1;
  char *string;
  char fixed_buffer[20];	/* Default buffer for small formatting. */
  char *fmtcpy;
  int minlen;
  char charbuf[MAX_MULTIBYTE_LENGTH + 1];	/* Used for %c.  */
  USE_SAFE_ALLOCA;

  if (format_end == 0)
    format_end = format + strlen (format);

  fmtcpy = (format_end - format < sizeof (fixed_buffer) - 1
	    ? fixed_buffer
	    : SAFE_ALLOCA (format_end - format + 1));

  bufsize--;

  /* Loop until end of format string or buffer full. */
  while (fmt < format_end && bufsize > 0)
    {
      char const *fmt0 = fmt;
      char fmtchar = *fmt++;
      if (fmtchar == '%')
	{
	  ptrdiff_t size_bound = 0;
	  ptrdiff_t width;  /* Columns occupied by STRING on display.  */
	  enum {
	    pDlen = sizeof pD - 1,
	    pIlen = sizeof pI - 1,
	    pMlen = sizeof pMd - 2
	  };
	  enum {
	    no_modifier, long_modifier, pD_modifier, pI_modifier, pM_modifier
	  } length_modifier = no_modifier;
	  static char const modifier_len[] = { 0, 1, pDlen, pIlen, pMlen };
	  int maxmlen = max (max (1, pDlen), max (pIlen, pMlen));
	  int mlen;

	  /* Copy this one %-spec into fmtcpy.  */
	  string = fmtcpy;
	  *string++ = '%';
	  while (fmt < format_end)
	    {
	      *string++ = *fmt;
	      if ('0' <= *fmt && *fmt <= '9')
		{
		  /* Get an idea of how much space we might need.
		     This might be a field width or a precision; e.g.
		     %1.1000f and %1000.1f both might need 1000+ bytes.
		     Parse the width or precision, checking for overflow.  */
		  ptrdiff_t n = *fmt - '0';
		  while (fmt + 1 < format_end
			 && '0' <= fmt[1] && fmt[1] <= '9')
		    {
		      /* Avoid ptrdiff_t, size_t, and int overflow, as
			 many sprintfs mishandle widths greater than INT_MAX.
			 This test is simple but slightly conservative: e.g.,
			 (INT_MAX - INT_MAX % 10) is reported as an overflow
			 even when it's not.  */
		      if (n >= min (INT_MAX, min (PTRDIFF_MAX, SIZE_MAX)) / 10)
			error ("Format width or precision too large");
		      n = n * 10 + fmt[1] - '0';
		      *string++ = *++fmt;
		    }

		  if (size_bound < n)
		    size_bound = n;
		}
	      else if (! (*fmt == '-' || *fmt == ' ' || *fmt == '.'
			  || *fmt == '+'))
		break;
	      fmt++;
	    }

	  /* Check for the length modifiers in textual length order, so
	     that longer modifiers override shorter ones.  */
	  for (mlen = 1; mlen <= maxmlen; mlen++)
	    {
	      if (format_end - fmt < mlen)
		break;
	      if (mlen == 1 && *fmt == 'l')
		length_modifier = long_modifier;
	      if (mlen == pDlen && memcmp (fmt, pD, pDlen) == 0)
		length_modifier = pD_modifier;
	      if (mlen == pIlen && memcmp (fmt, pI, pIlen) == 0)
		length_modifier = pI_modifier;
	      if (mlen == pMlen && memcmp (fmt, pMd, pMlen) == 0)
		length_modifier = pM_modifier;
	    }

	  mlen = modifier_len[length_modifier];
	  memcpy (string, fmt + 1, mlen);
	  string += mlen;
	  fmt += mlen;
	  *string = 0;

	  /* Make the size bound large enough to handle floating point formats
	     with large numbers.  */
	  if (size_bound > min (PTRDIFF_MAX, SIZE_MAX) - DBL_MAX_10_EXP - 50)
	    error ("Format width or precision too large");
	  size_bound += DBL_MAX_10_EXP + 50;

	  /* Make sure we have that much.  */
	  if (size_bound > size_allocated)
	    {
	      if (big_buffer)
		xfree (big_buffer);
	      big_buffer = xmalloc (size_bound);
	      sprintf_buffer = big_buffer;
	      size_allocated = size_bound;
	    }
	  minlen = 0;
	  switch (*fmt++)
	    {
	    default:
	      error ("Invalid format operation %s", fmtcpy);

/*	    case 'b': */
	    case 'l':
	    case 'd':
	      switch (length_modifier)
		{
		case no_modifier:
		  {
		    int v = va_arg (ap, int);
		    tem = sprintf (sprintf_buffer, fmtcpy, v);
		  }
		  break;
		case long_modifier:
		  {
		    long v = va_arg (ap, long);
		    tem = sprintf (sprintf_buffer, fmtcpy, v);
		  }
		  break;
		case pD_modifier:
		signed_pD_modifier:
		  {
		    ptrdiff_t v = va_arg (ap, ptrdiff_t);
		    tem = sprintf (sprintf_buffer, fmtcpy, v);
		  }
		  break;
		case pI_modifier:
		  {
		    EMACS_INT v = va_arg (ap, EMACS_INT);
		    tem = sprintf (sprintf_buffer, fmtcpy, v);
		  }
		  break;
		case pM_modifier:
		  {
		    intmax_t v = va_arg (ap, intmax_t);
		    tem = sprintf (sprintf_buffer, fmtcpy, v);
		  }
		  break;
		}
	      /* Now copy into final output, truncating as necessary.  */
	      string = sprintf_buffer;
	      goto doit;

	    case 'o':
	    case 'x':
	      switch (length_modifier)
		{
		case no_modifier:
		  {
		    unsigned v = va_arg (ap, unsigned);
		    tem = sprintf (sprintf_buffer, fmtcpy, v);
		  }
		  break;
		case long_modifier:
		  {
		    unsigned long v = va_arg (ap, unsigned long);
		    tem = sprintf (sprintf_buffer, fmtcpy, v);
		  }
		  break;
		case pD_modifier:
		  goto signed_pD_modifier;
		case pI_modifier:
		  {
		    EMACS_UINT v = va_arg (ap, EMACS_UINT);
		    tem = sprintf (sprintf_buffer, fmtcpy, v);
		  }
		  break;
		case pM_modifier:
		  {
		    uintmax_t v = va_arg (ap, uintmax_t);
		    tem = sprintf (sprintf_buffer, fmtcpy, v);
		  }
		  break;
		}
	      /* Now copy into final output, truncating as necessary.  */
	      string = sprintf_buffer;
	      goto doit;

	    case 'f':
	    case 'e':
	    case 'g':
	      {
		double d = va_arg (ap, double);
		tem = sprintf (sprintf_buffer, fmtcpy, d);
		/* Now copy into final output, truncating as necessary.  */
		string = sprintf_buffer;
		goto doit;
	      }

	    case 'S':
	      string[-1] = 's';
	    case 's':
	      if (fmtcpy[1] != 's')
		minlen = atoi (&fmtcpy[1]);
	      string = va_arg (ap, char *);
	      tem = strlen (string);
	      if (STRING_BYTES_BOUND < tem)
		error ("String for %%s or %%S format is too long");
	      width = strwidth (string, tem);
	      goto doit1;

	      /* Copy string into final output, truncating if no room.  */
	    doit:
	      eassert (0 <= tem);
	      /* Coming here means STRING contains ASCII only.  */
	      if (STRING_BYTES_BOUND < tem)
		error ("Format width or precision too large");
	      width = tem;
	    doit1:
	      /* We have already calculated:
		 TEM -- length of STRING,
		 WIDTH -- columns occupied by STRING when displayed, and
		 MINLEN -- minimum columns of the output.  */
	      if (minlen > 0)
		{
		  while (minlen > width && bufsize > 0)
		    {
		      *bufptr++ = ' ';
		      bufsize--;
		      minlen--;
		    }
		  minlen = 0;
		}
	      if (tem > bufsize)
		{
		  /* Truncate the string at character boundary.  */
		  tem = bufsize;
		  do
		    {
		      tem--;
		      if (CHAR_HEAD_P (string[tem]))
			{
			  if (BYTES_BY_CHAR_HEAD (string[tem]) <= bufsize - tem)
			    tem = bufsize;
			  break;
			}
		    }
		  while (tem != 0);

		  memcpy (bufptr, string, tem);
		  bufptr[tem] = 0;
		  /* Trigger exit from the loop, but make sure we
		     return to the caller a value which will indicate
		     that the buffer was too small.  */
		  bufptr += bufsize;
		  bufsize = 0;
		  continue;
		}
	      memcpy (bufptr, string, tem);
	      bufptr += tem;
	      bufsize -= tem;
	      if (minlen < 0)
		{
		  while (minlen < - width && bufsize > 0)
		    {
		      *bufptr++ = ' ';
		      bufsize--;
		      minlen++;
		    }
		  minlen = 0;
		}
	      continue;

	    case 'c':
	      {
		int chr = va_arg (ap, int);
		tem = CHAR_STRING (chr, (unsigned char *) charbuf);
		string = charbuf;
		string[tem] = 0;
		width = strwidth (string, tem);
		if (fmtcpy[1] != 'c')
		  minlen = atoi (&fmtcpy[1]);
		goto doit1;
	      }

	    case '%':
	      fmt--;    /* Drop thru and this % will be treated as normal */
	    }
	}

      char const *src;
      ptrdiff_t srclen;
      if (quoting_style == CURVE_QUOTING_STYLE && fmtchar == '`')
	src = uLSQM, srclen = sizeof uLSQM - 1;
      else if (quoting_style == CURVE_QUOTING_STYLE && fmtchar == '\'')
	src = uRSQM, srclen = sizeof uRSQM - 1;
      else if (quoting_style == STRAIGHT_QUOTING_STYLE && fmtchar == '`')
	src = "'", srclen = 1;
      else
	{
	  while (fmt < format_end && !CHAR_HEAD_P (*fmt))
	    fmt++;
	  src = fmt0, srclen = fmt - fmt0;
	}

      if (bufsize < srclen)
	{
	  /* Truncate, but return value that will signal to caller
	     that the buffer was too small.  */
	  do
	    *bufptr++ = '\0';
	  while (--bufsize != 0);
	}
      else
	{
	  do
	    *bufptr++ = *src++;
	  while (--srclen != 0);
	}
    }
Beispiel #5
0
/*
** Get a temporary file name
**
** Can pass in Dir to use instead of %TEMP%
** Can pass in prefix to use instead of NCS
** Can pass in file extension to use instead of .tmp
*/
char *NCSGetTempFileName(char *pDir,
						 char *pPrefix,
						 char *pExt)
{
	char *pTmpName = NULL;

#if defined PALM

	return(NULL);

#else	/* MACINTOSH */
	
    char buf[MAX_PATH];

    if(pDir == (char *)NULL || (pDir && strlen(pDir) == 0)) {
		pDir = NCSGetTempDirectory();
    } else {
		pDir = NCSStrDup(pDir);
	}
	if(pExt == NULL) {
		pExt = ".tmp";
	}
	if(pPrefix == NULL) {
		pPrefix = "NCS";
	}

#ifdef WIN32
	{
		int i = 0;
#ifndef _WIN32_WCE
		srand( (unsigned)time( NULL ) );
#endif	
		while(i < 65535) {
			sprintf(buf, "%s\\%s%lx%lx%s", pDir, pPrefix, rand(), rand(), pExt);
#if defined(_WIN32_WCE)||defined(NCS_MINDEP_BUILD)
			if(NCSFileSizeBytes(buf) < 0) {
#else
			if(PathFileExistsA(buf) == FALSE) {
#endif
				pTmpName = NCSStrDup(buf);
				break;
			} 
			i++;
		}
	}
	NCSFree((void*)pDir);
	
#elif defined( MACOSX )
    sprintf(buf, "%sXXXXXX", pPrefix ? pPrefix : "NCS");

    pTmpName = NCSMalloc(strlen(pDir) + strlen(buf) + strlen(pExt) + 3, FALSE);
    sprintf(pTmpName, "%s/%s", pDir, buf);

    mktemp(pTmpName);

    NCSFree((void*)pDir);
    strcat(pTmpName, pExt);	// FIXME: Is this really going to be unique?

#else

	sprintf(buf, "%sXXXXXX", pPrefix ? pPrefix : "NCS");

	pTmpName = NCSMalloc(strlen(pDir) + strlen(buf) + strlen(pExt) + 3, FALSE);
	sprintf(pTmpName, "%s/%s", pDir, buf);

    mktemp(pTmpName);

	NCSFree((void*)pDir);
	strcat(pTmpName, pExt);	// FIXME: Is this really going to be unique?

#endif
#endif

    return(pTmpName);
}

/*
** Get name of temp directory
**
** WIN32:
** Default: %TEMP% env variable
** 9x:		C:\Windows\Temp
** NT:		C:\Temp
** CE:		\Temp
*/
char *NCSGetTempDirectory(void)
{
#ifdef _WIN32_WCE

	return(NCSStrDup("\\Temp"));

#elif defined WIN32

	NCSTChar winbuf[MAX_PATH];

	if(GetTempPath((DWORD)MAX_PATH, winbuf) == 0) {
		if(GetSystemDirectory(winbuf, MAX_PATH)) {
			if(NCSGetPlatform() == NCS_WINDOWS_NT) {
				/* eg, c:\Temp */
				winbuf[3] = '\0';
				NCSTCat(winbuf, NCS_T("Temp"));
			} else {
				/* eg, c:\Windows\Temp */
				NCSTCat(winbuf, NCS_T("Temp"));
			}
		}
	}
	if((winbuf[0] != '\0') && (winbuf[NCSTLen(winbuf) - 1] == '\\')) {
		winbuf[NCSTLen(winbuf) - 1] = '\0';
	}
	return(NCSStrDup(CHAR_STRING(winbuf)));

#elif defined PALM

	return(NCSStrDup(""));

#elif defined MACOSX

        FSRef tempRef;
        UInt8 szPath[1024] = "";
        
        
        if( FSFindFolder( kUserDomain, kTemporaryFolderType, kDontCreateFolder, &tempRef ) == noErr ) {
            if( FSRefMakePath( &tempRef, szPath, 1024 ) == noErr ) {
            }
        }
         

        return( NCSStrDup(szPath) );

#elif defined POSIX

	return(NCSStrDup("/tmp"));

#else	/* PALM */
	char *szTmpDir = getenv("TMP");
	if (szTmpDir != NULL)
		return NCSStrDup(szTmpDir);
	else return NCSStrDup("/tmp");

#endif
}

/*
** Get File Version information [01]
**
*/
BOOLEAN NCSFileGetVersion(char *pFileName,
						  UINT16 *pMajor,
						  UINT16 *pMinor,
						  UINT16 *pRevision,
						  UINT16 *pBuild)
{
	BOOLEAN bRVal = FALSE;

	if(pFileName) {
#if defined(_WIN32_WCE)||defined(NCS_MINDEP_BUILD)

	return(FALSE);

#elif defined WIN32
		DWORD dwVISize;
		DWORD dwZero;

		dwVISize = GetFileVersionInfoSize(OS_STRING(pFileName), &dwZero);

		if(dwVISize != 0) {
			LPVOID lpData = NCSMalloc(dwVISize, TRUE);

			if(lpData) {
				if(GetFileVersionInfo(OS_STRING(pFileName),
									  0,
									  dwVISize,
									  lpData)) {
					VS_FIXEDFILEINFO *pVI = (VS_FIXEDFILEINFO*)NULL;
					UINT dwSize;

					if(VerQueryValue(lpData, 
									 NCS_T("\\"), 
									 (LPVOID*)&pVI,
									 &dwSize) && pVI) {
				
						if(pMajor) {
							*pMajor = (UINT16)(pVI->dwFileVersionMS >> 16);
						}
						if(pMinor) {
							*pMinor = (UINT16)(pVI->dwFileVersionMS & 0xffff);
						}
						if(pRevision) {
							*pRevision = (UINT16)(pVI->dwFileVersionLS >> 16);
						}
						if(pBuild) {
							*pBuild = (UINT16)(pVI->dwFileVersionLS & 0xffff);
						}
						bRVal = TRUE;
					}
				}
				NCSFree(lpData);
			}
		}
Beispiel #6
0
/*
** Get the size of the given file
*/
INT64 NCSFileSizeBytes(NCSTChar *pFilename)
{
#ifdef WIN32
#ifdef _WIN32_WCE
	DWORD dwLow;
	DWORD dwHigh;
	HANDLE hFile;

	if(hFile = CreateFile(pFilename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL)) {
		dwLow = GetFileSize(hFile, &dwHigh);
		
		if(dwLow == 0xffffffff && GetLastError() != NO_ERROR) {
			CloseHandle(hFile);
			return(-1);
		} else {
			CloseHandle(hFile);
			return((UINT64)dwLow | ((UINT64)dwHigh << 32));
		}
	} else {
		return(-1);
	}

#else	/* _WIN32_WCE */
	struct _stati64 statbuf;
#ifdef NCS_BUILD_UNICODE
#define _tstati64 _wstati64
#else
#define _tstati64 _stati64
#endif

    if(_tstati64(pFilename, &statbuf) != 0) {
		DWORD dwLow;
		DWORD dwHigh;
		HANDLE hFile;

#ifdef NCS_BUILD_UNICODE
		if(hFile = CreateFileW(pFilename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL)) {
#else
		if(hFile = CreateFileA(pFilename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL)) {
#endif
			dwLow = GetFileSize(hFile, &dwHigh);
			
			if(dwLow == 0xffffffff && GetLastError() != NO_ERROR) {
				CloseHandle(hFile);
				return(-1);
			} else {
				CloseHandle(hFile);
				return((UINT64)dwLow | ((UINT64)dwHigh << 32));
			}
		} else {
			return(-1);
		}
    }
    return((INT64)statbuf.st_size);
#undef _tstati64
#endif

#elif defined POSIX

#ifdef _LARGEFILE64_SOURCE
    struct stat64 statbuf;

    if (stat64(CHAR_STRING(pFilename), &statbuf) != 0) {
        return(-1); 
    }
    return((INT64)statbuf.st_size);
#else
    struct stat statbuf;

    if (stat(CHAR_STRING(pFilename), &statbuf) != 0) {
        return(-1); 
    }
    return((INT64)statbuf.st_size);
#endif


#elif defined IRIX

	struct stat64 statbuf;

    if (stat(CHAR_STRING(pFilename), &statbuf) != 0) {
        return(-1);
    }
	return((INT64)statbuf.st_size);

#elif defined PALM
	
	NCS_FILE_HANDLE hFile;
	
	if(NCSFileOpen(pFilename, NCS_FILE_READ, &hFile) == NCS_SUCCESS) {
		INT32 nFileSize = hFile->nDBSize;
		
		NCSFileClose(hFile);
		return((INT64)nFileSize);
	}
	return(-1);

#else	/* WIN32 */
#error 	NCSFileSizeBytes();
#endif	/* WIN32 */
}

/*
** Get the size of the given file
*/
INT64 NCSFreeDiskSpaceBytes(char *pDirName, INT64 *pTotal)
{
#ifdef WIN32
	NCS_FUNCADDR pGetDiskFreeSpaceEx;
	//WINBASEAPI BOOL (WINAPI *pGetDiskFreeSpaceEx)(LPCSTR, PULARGE_INTEGER, PULARGE_INTEGER, PULARGE_INTEGER);

	char szPath[MAX_PATH];

	strcpy(szPath, pDirName);
	if(szPath[0] == '\\' && szPath[strlen(szPath) - 1] != '\\') {
		// UNC dir must have trailing backslash
		strcat(szPath, "\\");
	}

	pGetDiskFreeSpaceEx = (NCS_FUNCADDR)GetProcAddress( GetModuleHandle(NCS_T("kernel32.dll")),
							"GetDiskFreeSpaceExA");

	if(pGetDiskFreeSpaceEx) {
		ULARGE_INTEGER i64FreeBytesToCaller;
		ULARGE_INTEGER i64TotalBytes;
		ULARGE_INTEGER i64FreeBytes;

		if(((BOOL (WINAPI *)(LPCSTR, PULARGE_INTEGER, PULARGE_INTEGER, PULARGE_INTEGER))pGetDiskFreeSpaceEx)(szPath,
					(PULARGE_INTEGER)&i64FreeBytesToCaller,
					(PULARGE_INTEGER)&i64TotalBytes,
					(PULARGE_INTEGER)&i64FreeBytes)) {
			
			if(pTotal) {
				*pTotal = (INT64)i64TotalBytes.QuadPart;
			}
			return((INT64)i64FreeBytesToCaller.QuadPart);
		} else {
			return(-1);
		}
	} else {
#if !defined(_WIN32_WCE)
		DWORD dwSectPerClust;
		DWORD dwBytesPerSect;
		DWORD dwFreeClusters;
		DWORD dwTotalClusters;

		if(GetDiskFreeSpace(OS_STRING(szPath), 
							&dwSectPerClust, 
							&dwBytesPerSect,
							&dwFreeClusters, 
							&dwTotalClusters)) {
			if(pTotal) {
				*pTotal = (INT64)dwBytesPerSect * (INT64)dwSectPerClust * (INT64)dwTotalClusters;
			}
			return((INT64)dwBytesPerSect * (INT64)dwSectPerClust * (INT64)dwFreeClusters);
		} else {
			return(-1);
		}
#elif defined(_WIN32_WCE)
		ULARGE_INTEGER nFreeBytesToCaller;
		ULARGE_INTEGER nTotalBytes;
		ULARGE_INTEGER nTotalFreeBytes;

		if (GetDiskFreeSpaceEx(OS_STRING(szPath), &nFreeBytesToCaller, &nTotalBytes, &nTotalFreeBytes)) {
			if(pTotal) {
				*pTotal = (INT64) nFreeBytesToCaller.QuadPart;
			}
			return((INT64)nFreeBytesToCaller.QuadPart);
		} else {
			return (-1);
		}
#endif
	}
#else // WIN32
	return(-1);
#endif
}
Beispiel #7
0
NCSError NCSFileOpen(const NCSTChar *szFilename, int iFlags, NCS_FILE_HANDLE *phFile)
{
#ifdef WIN32
	DWORD dwMode = GENERIC_READ;
	DWORD dwCreate = OPEN_EXISTING;

	if(iFlags & NCS_FILE_READ) dwMode = GENERIC_READ;
	if(iFlags & NCS_FILE_READ_WRITE) dwMode = GENERIC_READ|GENERIC_WRITE;
	if(iFlags & NCS_FILE_CREATE) dwCreate = CREATE_ALWAYS;
	if(iFlags & NCS_FILE_CREATE_UNIQUE) dwCreate = CREATE_NEW;
	if(iFlags & NCS_FILE_APPEND) dwCreate = OPEN_ALWAYS;

	*phFile = CreateFile(szFilename,			        // file name
						 dwMode,						// Generic read mode 
						 FILE_SHARE_READ,				// Let anyone access and share the file
						 NULL,							// No security info (so can't be inherited by child process)
						 dwCreate,						// File must exist to be opened
						 FILE_FLAG_RANDOM_ACCESS,		// Going to be doing lots of random access
						 NULL);							// And no template file for attributes
	if( *phFile == INVALID_HANDLE_VALUE ) {
		return( NCS_FILE_OPEN_FAILED );
	} else {
		return( NCS_SUCCESS );
	}

#elif defined MACINTOSH
#if __POWERPC__
	
	int i,length, result;
	Str255		pascalString;
	FSSpec		fileSpec;
		//	We have a C string, we need a PASCAL string.
	length = strlen(szFilename) + 1;
	for(i = 1; i < length; ++i)
		pascalString[i] = szFilename[i - 1];
	pascalString[0] = strlen(szFilename);
			
	//	Create a File Specification Record, then create a File
	result = FSMakeFSSpec(0,0,pascalString,&fileSpec);	// return is meaningless, since the only possible error doesn't effect processing in this case
			
	switch(result) {
		case noErr:
				// we could dRes pFile here, but we are the only user
				result =FSpOpenDF(&fileSpec, fsRdPerm, (short *)phFile);
				if(result) return NCS_FILE_OPEN_FAILED;
				else return NCS_SUCCESS;
			break;
		default:
			    return NCS_SUCCESS;
		    break;
	}

#else	/* __POWERPC__ */

	int i,length, result;
	Str255		pascalString;
	//	We have a C string, we need a PASCAL string.
	length = strlen(szFilename) + 1;
	for(i = 1; i < length; ++i)
		pascalString[i] = szFilename[i - 1];
	pascalString[0] = strlen(szFilename);
		
	result =FSOpen(pascalString, 0, (short *)phFile);
	if(result) return TRUE;
	else return FALSE;

#endif	/* __POWERPC__ */
#elif defined PALM

	NCS_FILE_HANDLE hFile;
	Err eErr;
	UInt32 nMode = 0;
	
	if(hFile = (NCS_FILE_HANDLE)NCSMalloc(sizeof(NCS_FILE_HANDLE_STRUCT), TRUE)) {
		hFile->dbID = DmFindDatabase(0, szFilename);
		
		if(hFile->dbID) {
	   		Char nameP[dmDBNameLength];
	   		UInt16 attributes;
	   		UInt16 version;
	   		UInt32 crDate;
	   		UInt32 modDate;
	   		UInt32 bckUpDate;
	   		UInt32 modNum;
	   		LocalID appInfoID;
	   		LocalID sortInfoID;
	   		UInt32 type;
	   		UInt32 creator;
					
	   		DmDatabaseInfo(0, hFile->dbID, nameP,
	   					   &attributes, 
	   					   &version,
	   					   &crDate,
	   					   &modDate,
	   					   &bckUpDate,
	   					   &modNum,
	   					   &appInfoID,
	   					   &sortInfoID,
	   					   &type,
	   					   &creator);
	   					   
	   		if(creator == NCS_PALM_CREATOR_ID) {
	   			if(hFile->dbRef = DmOpenDatabase(0, hFile->dbID, dmModeReadOnly|dmModeShowSecret)) {
	   				UInt32 nRecords;
	   				UInt32 nTotalBytes;
	   				UInt32 nDataBytes;
	   				
	   				eErr = DmDatabaseSize(0, hFile->dbID, &nRecords, &nTotalBytes, &nDataBytes);
	   				
	   				if(eErr == errNone) {
	   					MemHandle hRecord;
	   					
	   					hFile->nRecords = nRecords;
	   					hFile->nDBSize = nDataBytes;
#ifdef NOTDEF	   					
	   					if(hRecord = DmGetRecord(hFile->dbRef, 0)) {
	   						MemPtr pData;
	   						
							if(pData = MemHandleLock(hRecord)) {
								hFile->nRecordSize = ((UINT16*)pData)[0];
							
								MemHandleUnlock(hRecord);
							}
							DmReleaseRecord(hFile->dbRef, 0, false);
						}
#endif
						*phFile = hFile;
						return(NCS_SUCCESS);
	   				}
	   				DmCloseDatabase(hFile->dbRef);
	   				return(NCSPalmGetNCSError(eErr));
	   			}
	   		}
		}
	} else {
		return(NCS_COULDNT_ALLOC_MEMORY);
	}
/*	
	if(iFlags & NCS_FILE_READ) nMode = fileModeReadOnly|fileModeAnyTypeCreator;
	if(iFlags & NCS_FILE_READ_WRITE) nMode = fileModeUpdate|fileModeAnyTypeCreator;
	if(iFlags & NCS_FILE_CREATE) nMode = fileModeReadWrite|fileModeAnyTypeCreator;
	if(iFlags & NCS_FILE_CREATE_UNIQUE) nMode = fileModeReadWrite|fileModeDontOverwrite|fileModeAnyTypeCreator;
	if(iFlags & NCS_FILE_APPEND) nMode = fileModeAppend|fileModeAnyTypeCreator;
	
	*phFile = FileOpen(0, (char*)szFilename, 0, 0, nMode, &eErr);
	
	return(NCSPalmGetNCSError(eErr));			   
*/					
#elif defined(POSIX)

	int flags = O_RDONLY;

	if(iFlags & NCS_FILE_READ) flags = O_RDONLY;
	if(iFlags & NCS_FILE_READ_WRITE) flags = O_RDWR;
	if(iFlags & NCS_FILE_CREATE) flags |= O_CREAT;
	if(iFlags & NCS_FILE_CREATE_UNIQUE) flags |= O_CREAT|O_EXCL;
	if(iFlags & NCS_FILE_APPEND) flags |= O_APPEND;

#if defined SOLARIS || (defined(HPUX) && !defined(__LP64__))
	// Enable 64bit!
	flags |= O_LARGEFILE;
#endif

#ifdef HPUX
	*phFile = open64((const char*)CHAR_STRING(szFilename), (int)flags);

#ifdef NOTDEF
	if (*phFile < 0) {
		fprintf(stderr, "Error opening file : %ld\n", errno); 
		if (errno == EOVERFLOW) {
			fprintf(stderr, "The named file is a regular file and the size "
                          "of the file cannot be represented correctly in an object of "
                          "size off_t.");
		}
	}
#endif

#else
	*phFile = open((const char*)CHAR_STRING(szFilename), (int)flags, S_IRUSR|S_IWUSR);
#endif
	if(*phFile != -1) {
		return(NCS_SUCCESS);
	} else {
		return(NCS_FILE_OPEN_FAILED);
	}

#else	/* SOLARIS||IRIX */
#error ERROR  EcwFileCreate() routine is not defined for this platform
#endif	/* WIN32 */
}
Beispiel #8
0
static Lisp_Object
casify_object (enum case_action flag, Lisp_Object obj)
{
  register int c, c1;
  register int inword = flag == CASE_DOWN;

  /* If the case table is flagged as modified, rescan it.  */
  if (NILP (XCHAR_TABLE (BVAR (current_buffer, downcase_table))->extras[1]))
    Fset_case_table (BVAR (current_buffer, downcase_table));

  if (INTEGERP (obj))
    {
      int flagbits = (CHAR_ALT | CHAR_SUPER | CHAR_HYPER
		      | CHAR_SHIFT | CHAR_CTL | CHAR_META);
      int flags = XINT (obj) & flagbits;
      int multibyte = ! NILP (BVAR (current_buffer, enable_multibyte_characters));

      /* If the character has higher bits set
	 above the flags, return it unchanged.
	 It is not a real character.  */
      if ((unsigned) XFASTINT (obj) > (unsigned) flagbits)
	return obj;

      c1 = XFASTINT (obj) & ~flagbits;
      /* FIXME: Even if enable-multibyte-characters is nil, we may
	 manipulate multibyte chars.  This means we have a bug for latin-1
	 chars since when we receive an int 128-255 we can't tell whether
	 it's an eight-bit byte or a latin-1 char.  */
      if (c1 >= 256)
	multibyte = 1;
      if (! multibyte)
	MAKE_CHAR_MULTIBYTE (c1);
      c = downcase (c1);
      if (inword)
	XSETFASTINT (obj, c | flags);
      else if (c == (XFASTINT (obj) & ~flagbits))
	{
	  if (! inword)
	    c = upcase1 (c1);
	  if (! multibyte)
	    MAKE_CHAR_UNIBYTE (c);
	  XSETFASTINT (obj, c | flags);
	}
      return obj;
    }

  if (!STRINGP (obj))
    wrong_type_argument (Qchar_or_string_p, obj);
  else if (!STRING_MULTIBYTE (obj))
    {
      EMACS_INT i;
      EMACS_INT size = SCHARS (obj);

      obj = Fcopy_sequence (obj);
      for (i = 0; i < size; i++)
	{
	  c = SREF (obj, i);
	  MAKE_CHAR_MULTIBYTE (c);
	  c1 = c;
	  if (inword && flag != CASE_CAPITALIZE_UP)
	    c = downcase (c);
	  else if (!uppercasep (c)
		   && (!inword || flag != CASE_CAPITALIZE_UP))
	    c = upcase1 (c1);
	  if ((int) flag >= (int) CASE_CAPITALIZE)
	    inword = (SYNTAX (c) == Sword);
	  if (c != c1)
	    {
		  MAKE_CHAR_UNIBYTE (c);
	      /* If the char can't be converted to a valid byte, just don't
		 change it.  */
	      if (c >= 0 && c < 256)
		SSET (obj, i, c);
	    }
	}
      return obj;
    }
  else
    {
      EMACS_INT i, i_byte, size = SCHARS (obj);
      int len;
      USE_SAFE_ALLOCA;
      unsigned char *dst, *o;
      /* Over-allocate by 12%: this is a minor overhead, but should be
	 sufficient in 99.999% of the cases to avoid a reallocation.  */
      EMACS_INT o_size = SBYTES (obj) + SBYTES (obj) / 8 + MAX_MULTIBYTE_LENGTH;
      SAFE_ALLOCA (dst, void *, o_size);
      o = dst;

      for (i = i_byte = 0; i < size; i++, i_byte += len)
	{
	  if ((o - dst) + MAX_MULTIBYTE_LENGTH > o_size)
	    { /* Not enough space for the next char: grow the destination.  */
	      unsigned char *old_dst = dst;
	      o_size += o_size;	/* Probably overkill, but extremely rare.  */
	      SAFE_ALLOCA (dst, void *, o_size);
	      memcpy (dst, old_dst, o - old_dst);
	      o = dst + (o - old_dst);
	    }
	  c = STRING_CHAR_AND_LENGTH (SDATA (obj) + i_byte, len);
	  if (inword && flag != CASE_CAPITALIZE_UP)
	    c = downcase (c);
	  else if (!uppercasep (c)
		   && (!inword || flag != CASE_CAPITALIZE_UP))
	    c = upcase1 (c);
	  if ((int) flag >= (int) CASE_CAPITALIZE)
	    inword = (SYNTAX (c) == Sword);
	  o += CHAR_STRING (c, o);
	}
      eassert (o - dst <= o_size);
      obj = make_multibyte_string ((char *) dst, size, o - dst);
      SAFE_FREE ();
      return obj;
    }
}