⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 import.c

📁 汇编源代码大全
💻 C
📖 第 1 页 / 共 3 页
字号:

boolean ValidDOSName( const char *s,
                      const boolean longname )
{
   char *ptr;
   size_t len = strlen ( s );
   char tempname[FILENAME_MAX];

   static char *longCharSet = NULL;

/*--------------------------------------------------------------------*/
/*                      Define our character set                      */
/*--------------------------------------------------------------------*/

   if ( E_charset == NULL )
      E_charset = DOSCHARS;

   if ( longname )
   {

#if defined(FAMILYAPI) || defined(__OS2__)

/*--------------------------------------------------------------------*/
/*       Ask OS/2 if the file name is okay.  Because the invoked      */
/*       function accepts wildcards, we pre-test for them and reject  */
/*       them as needed.                                              */
/*--------------------------------------------------------------------*/

      if ((strchr( s, '*') == NULL ) && (strchr( s, '?') == NULL))
      {

#ifdef __OS2__
         APIRET result = DosQPathInfo( (PSZ) s,
                                       FIL_QUERYFULLNAME,
                                       (PVOID) tempname,
                                       sizeof tempname );
#else
         USHORT result = DosQPathInfo( (PSZ) s,
                                       FIL_NAMEISVALID,
                                       (PBYTE) tempname,
                                       sizeof tempname,
                                       0 );

#endif
         if ( result == 0 )
            return TRUE;

         printmsg(2,
                  "ValidDOSName: Invalid name %s, syntax error code %d",
                   s,
                   (int) result);

      } /* if */

#endif

      if ( longCharSet == NULL )
      {
         *tempname = '.';
         longCharSet = newstr(strcpy( tempname + 1, E_charset ));
      }

      if (strspn(s, longCharSet) == len)
      {
         printmsg(9,"ValidDOSName: \"%s\" is valid long name", s);
         return TRUE;
      }

   } /* if ( longname ) */

/*--------------------------------------------------------------------*/
/*                 Name must be 12 characters or less                 */
/*--------------------------------------------------------------------*/

   if (len > 12)
      return FALSE;

   strcpy( tempname, s);      /* Make a temp copy we can alter       */

/*--------------------------------------------------------------------*/
/*    Simple file name without extension must be eight chracters      */
/*    or less                                                         */
/*--------------------------------------------------------------------*/

   ptr = strrchr(tempname, '.');
   if (ptr == NULL)
   {
      if (len > 8)
         return FALSE;
   }

/*--------------------------------------------------------------------*/
/*          Period must be in second through ninth character          */
/*--------------------------------------------------------------------*/

   else {
      if ((ptr == tempname) || (ptr > &tempname[8]))
         return FALSE;

/*--------------------------------------------------------------------*/
/*             Extension must be three characters or less             */
/*--------------------------------------------------------------------*/

      if ( strlen( ptr ) > 4) /* Three characters plus the period?   */
         return FALSE;        /* No --> Too much                     */

/*--------------------------------------------------------------------*/
/*                          Only one period                           */
/*--------------------------------------------------------------------*/

      if (ptr != strchr(tempname, '.'))
         return FALSE;
   } /* else */

/*--------------------------------------------------------------------*/
/*                Must only be valid MS-DOS characters                */
/*--------------------------------------------------------------------*/

   strlwr( tempname );        /* Map into our desired character set  */
   if ( ptr != NULL )
      *ptr = 'x';             /* We've already accounted for the
                                 period, don't let it ruin our day   */

   if (strspn(tempname, E_charset ) == len)
   {
      printmsg(9,"ValidDOSName: \"%s\" is valid", s);
      return TRUE;
   }
   else
      return FALSE;

} /* ValidateDOSName */

#if defined(FAMILYAPI) || defined( __OS2__ )

/*--------------------------------------------------------------------*/
/*       a d v a n c e d F S                       (OS/2 version)     */
/*                                                                    */
/*       Determine if a file system is advanced (supports better than */
/*       8.3 file names)                                              */
/*--------------------------------------------------------------------*/

static boolean advancedFS( const char *path )
{
   char buf[BUFSIZ];             // One generic large buffer

#ifdef __OS2__
   ULONG bufSize = sizeof buf;
   FSQBUFFER2 *dataBuffer = (FSQBUFFER2 *) buf;
   ULONG  result;
#else
   SHORT bufSize = sizeof buf;
   FSQBUFFER *dataBuffer = (FSQBUFFER *) buf;
   USHORT result;
#endif

/*--------------------------------------------------------------------*/
/*                  Get the drive letter to process                   */
/*--------------------------------------------------------------------*/

   char driveInfo[3];
   char *fileSystem;

   if ( isalpha( *path ) && (path[1] == ':') )
      strncpy( driveInfo, path, 2 );
   else
      strncpy( driveInfo, E_cwd, 2 );

   driveInfo[ sizeof(driveInfo) - 1 ] = '\0';   // Terminate string data

/*--------------------------------------------------------------------*/
/*      Query the drive (both 1.x and 2.x calls are supported).       */
/*--------------------------------------------------------------------*/

#ifdef __OS2__
   result = DosQueryFSAttach( (PSZ) driveInfo,
                          1,
                          FSAIL_QUERYNAME,
                          dataBuffer,
                          &bufSize );
   fileSystem = (char *) (dataBuffer->szFSDName + dataBuffer->cbName);
#else
   result = DosQFSAttach( driveInfo,
                          0,
                          FSAIL_QUERYNAME,
                          (PBYTE) buf,
                          &bufSize,
                          0L );
   fileSystem = (char *) (dataBuffer->szFSDName + dataBuffer->cbName - 1);
#endif

   if ( result != 0 )
   {
      printmsg(0, "advancedFS: Unable to query file system for %s, error = %d",
                  driveInfo,
                  (int)  result );
      return FALSE;
   }


   printmsg(4,"advancedFS: File system %d, name \"%s\", FS name \"%s\"",
               (int) dataBuffer->iType,
               dataBuffer->szName,
               fileSystem );

   if (equal( fileSystem, "FAT"))
      return FALSE;
   else
      return TRUE;

} /* advancedFS */

#elif WIN32

/*--------------------------------------------------------------------*/
/*       a d v a n c e d F S                    (Window NT version)   */
/*                                                                    */
/*       Determine if a file system is advanced (supports better than */
/*       8.3 file names)                                              */
/*--------------------------------------------------------------------*/

static boolean advancedFS( const char *path )
{
   char driveInfo[4];
   char fsType[5];
   BOOL result;
   char *shareNameEnd;

   if ( !path || *path == '\0' ) {       // use CWD
      strncpy( driveInfo, E_cwd, 3);
      driveInfo[3] = '\0';
   }
   else if ( isalpha( *path ) && (path[1] == ':') )
   {                                   // It's a local drive

      printmsg(5, "advancedFS: it's a drive letter");
      strncpy( driveInfo, path, 3 );
      driveInfo[3] = '\0';          // Terminate drive string data

   }
   else
      return FALSE;

/*--------------------------------------------------------------------*/
/*            We've got the drive letter, query its status            */
/*--------------------------------------------------------------------*/

   result = GetVolumeInformation(driveInfo, NULL, 0, NULL, NULL,
         NULL, fsType, 5);

   if ( !result )
   {
      DWORD dwError = GetLastError();
      printmsg(0, "advancedFS: Unable to query file system for %s", driveInfo);
      printNTerror("GetVolumeInformation", dwError);
      panic();
   }

   printmsg(4,"advancedFS: File system for \"%s\" has name \"%s\"",
               driveInfo,
               fsType );

   return strcmp( fsType, "FAT");

} /* advancedFS for WIN32 */

#else

/*--------------------------------------------------------------------*/
/*       a d v a n c e d F S                          (DOS version)   */
/*                                                                    */
/*       Determine if a file system is advanced (supports better than */
/*       8.3 file names)                                              */
/*--------------------------------------------------------------------*/

#ifdef __TURBOC__
#pragma argsused
#endif

static boolean advancedFS( const char *path )
{
   return FALSE;                 // DOS is always dumb on file systems!
} /* advancedFS for MS-DOS */

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -