home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cenvi23.zip / FILENAME.LIB < prev    next >
Text File  |  1996-02-13  |  5KB  |  199 lines

  1. /*
  2.  * Filename.lib
  3.  *      Perform some common filename operations on any filename,
  4.  *      taking into account the differences among systems.
  5.  */
  6.  
  7.  
  8. filename_separator = "\\"; path_separator = ';'; path_chars = ":\\";
  9.  
  10. if( defined(_WINDOWS_) || defined(_NTWIN_) || defined(_NTCON_) ||
  11.     defined(_95CON_) )
  12. {
  13.   executable_extensions = { ".CMM", ".COM", ".EXE", ".BAT", ".PIF" };
  14. } else if( defined(_OS2_) )
  15. {
  16.   executable_extensions = { ".CMM", ".COM", ".EXE", ".CMD", ".BAT" };
  17. } else if( defined(_NWNLM_) )
  18. {
  19.   executable_extensions = { ".CMM", ".NLM", ".NCF" };
  20. } else if ( defined(_UNIX_) )
  21. {
  22.   executable_extensions = { ".cmm" };
  23. } else {
  24.   executable_extensions = { ".CMM", ".COM", ".EXE", ".BAT" };
  25. }
  26.  
  27.  
  28. if( defined(_UNIX_) )
  29.   {
  30.     filename_separator = "/";
  31.     path_separator = ':';
  32.     path_chars = "/";
  33.   }
  34. if( defined(_NWNLM_) )
  35.   {
  36.     filename_separator = "/";
  37.     path_chars = ":/";
  38.   }
  39. if( defined(_MAC_) )
  40.   {
  41.     filename_separator = ":";
  42.     path_separator = '\n';
  43.     path_chars = ":";
  44.   }
  45.  
  46.  
  47.    #define HKEY_CLASSES_ROOT       0x80000000
  48.    #define HKEY_CURRENT_USER       0x80000001
  49.    #define HKEY_LOCAL_MACHINE      0x80000002
  50.    #define HKEY_USERS              0x80000003
  51.    #define HKEY_PERFORMANCE_DATA   0x80000004
  52.  
  53.    #define REG_SZ                       1
  54.  
  55. RegCloseKey(pHKey)
  56. {
  57.    return DynamicLink("ADVAPI32","RegCloseKey",STDCALL,pHKey);
  58. }
  59.  
  60. RegCreateKey(pHKey,pSubKeyStr,pGetHKey)
  61. {
  62.    lRet = DynamicLink("ADVAPI32","RegCreateKeyA",STDCALL,pHKey,pSubKeyStr,lGetHKey);
  63.    pGetHKey = lGetHKey;
  64.    return lRet;
  65. }
  66.  
  67. RegQueryValueEx(pHKey,pValueName,pGetType,pGetData,pGetDataSize)
  68. {
  69.    lRet = DynamicLink("ADVAPI32","RegQueryValueExA",STDCALL,
  70.                       pHKey,pValueName,0,lGType,NULL,lBufSize);
  71.    if ( !lRet ) {
  72.       BLObSize(pGetData,lBufSize);
  73.       lRet = DynamicLink("ADVAPI32","RegQueryValueExA",STDCALL,
  74.                          pHKey,pValueName,0,lGetType,pGetData,pointer(lBufSize));
  75.       pGetType = lGetType;
  76.       pGetDataSize = lBufSize;
  77.    }
  78.    return lRet;                     
  79. }
  80.  
  81. /* ---------------------------------------------------------------------- */
  82.  
  83. /*
  84.  * Given a path string, such as under DOS:
  85.  *      PATH=c:\bin;c:\bin;..
  86.  * Return an array of all the paths
  87.  */
  88. path_string_to_array(path)
  89. {
  90.   if( path==NULL ) return NULL;
  91.   num = 0;
  92.   array = NULL;
  93.   strcpy(dopath,path);
  94.   while( dopath!=NULL && dopath[0]!='\0' )
  95.     {
  96.       loc = strchr(dopath,path_separator);
  97.       if( loc!=NULL )
  98.         {
  99.           loc[0] = '\0';
  100.           add = dopath; dopath = loc+1;
  101.         } else {
  102.           add = dopath; dopath = NULL;
  103.         }
  104.       if( num==0 ) undefine(array);
  105.       strcpy(array[num++],add);
  106.     }
  107.   return array;
  108. }
  109.  
  110.  
  111. path_add_to_array(value,num,array)
  112. {
  113.   value = FullPath(value);
  114.   if( value==NULL ) return;
  115.   if( value[strlen(value)-1]!=filename_separator[0] )
  116.     strcat(value,filename_separator);
  117.  
  118.   for( i=0;i<=GetArraySpan(array);i++ )
  119.     {
  120.       if( !stricmp(value,array[i]) ) return;
  121.     }
  122.   strcpy(array[num++],value);
  123. }
  124.  
  125.  
  126. /*
  127.  * Build an array of paths, with no duplicates. The array represents the
  128.  * search path CEnvi uses on that system. It is ordered based on what is
  129.  * searched when.
  130.  */
  131. build_path_list()
  132. {
  133.   num = 1;
  134.   array[0] = FullPath(".");
  135.   strcat(array[0],filename_separator);
  136.  
  137.   if( defined(_OS2_) || defined(_DOS_) || defined(_DOS32_) )
  138.     {
  139.       toadd = path_string_to_array(getenv("CMMPATH"));
  140.       for( i=0;toadd!=NULL && i<=GetArraySpan(toadd); i++ )
  141.         {
  142.           path_add_to_array(toadd[i],num,array);
  143.         }
  144.     }
  145.  
  146.    if( defined(_WINDOWS_) )
  147.      {
  148.        buffer = ""; SetArraySpan(buffer,100);
  149.        DynamicLink("KERNEL","GETPROFILESTRING",SWORD16,PASCAL,
  150.                    "CEnvi","CMMPATH","",buffer,100);
  151.       toadd = path_string_to_array(buffer);
  152.       for( i=0;toadd!=NULL && i<=GetArraySpan(toadd); i++ )
  153.         {
  154.           path_add_to_array(toadd[i],num,array);
  155.         }
  156.      }
  157.    if( defined(_NTCON_) || defined(_95CON_) )
  158.      {
  159.        Path = ""; SetArraySpan(Path,200);
  160.        RegCreateKey(HKEY_LOCAL_MACHINE,"Software\\Nombas\\CEnviC32",lKey);
  161.        RegQueryValueEx(lkey,"CMMPATH",REG_SZ,Path,200);
  162.        RegCloseKey(lkey);
  163.  
  164.       toadd = path_string_to_array(Path);
  165.       for( i=0;toadd!=NULL && i<=GetArraySpan(toadd); i++ )
  166.         {
  167.           path_add_to_array(toadd[i],num,array);
  168.         }
  169.      }
  170.  
  171.    if( defined(_NTWIN_) || defined(_95WIN_) )
  172.      {
  173.        Path = ""; SetArraySpan(Path,200);
  174.        RegCreateKey(HKEY_LOCAL_MACHINE,"Software\\Nombas\\CEnviW32",lKey);
  175.        RegQueryValueEx(lkey,"CMMPATH",REG_SZ,Path,200);
  176.        RegCloseKey(lkey);
  177.  
  178.       toadd = path_string_to_array(Path);
  179.       for( i=0;toadd!=NULL && i<=GetArraySpan(toadd); i++ )
  180.         {
  181.           path_add_to_array(toadd[i],num,array);
  182.         }
  183.      }
  184.  
  185.    // get full path of each directory from the PATH variable
  186.  
  187.    if( !defined(_NWNLM_) )
  188.      {
  189.        toadd = path_string_to_array(getenv("PATH"));
  190.        for( i=0;toadd!=NULL && i<=GetArraySpan(toadd); i++ )
  191.          {
  192.            path_add_to_array(toadd[i],num,array);
  193.          }
  194.      }
  195.  
  196.   return array;
  197. }
  198.  
  199.