Changeset 7751 for trunk/projects


Ignore:
Timestamp:
09/14/11 15:45:50 (8 years ago)
Author:
hinerm
Message:

Modified javaTools library for Windows functionality

JTools was previously dependent on dirent.h, which is a POSIX library
dirent functionality was thus captured in conditional preprocessor macro code,
to be used on a windows system.
dirent.h is still included on Mac/Linux

Location:
trunk/projects/jar2lib/src/main/resources/project-files/jtools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/projects/jar2lib/src/main/resources/project-files/jtools/include/javaTools.h

    r7734 r7751  
    4949#include "jace/OptionList.h" 
    5050 
     51#ifdef WIN32 
     52  #ifndef MYAPI_API 
     53    #define MYAPI_API __declspec(dllexport) 
     54  #endif 
     55#else 
     56  #ifndef MYAPI_API 
     57    #define MYAPI_API 
     58  #endif 
     59#endif 
     60 
    5161using namespace std; 
    5262 
     
    5565 * of the various BFITK plugin implementations. 
    5666 */ 
    57 class JavaTools 
     67class MYAPI_API JavaTools 
    5868{ 
    5969  public: 
  • trunk/projects/jar2lib/src/main/resources/project-files/jtools/source/javaTools.cxx

    r7734 r7751  
    4343#include "javaTools.h" 
    4444 
     45#ifndef PATH_MAX 
     46#define PATH_MAX 1024 
     47#endif 
     48 
     49#ifdef WIN32 
     50#include <windows.h> 
     51#include <errno.h> 
     52#define mkdir fake_posix_mkdir 
     53static int fake_posix_mkdir(const char *name) 
     54{ 
     55          return mkdir(name); 
     56} 
     57 
     58static void die(const char *fmt, ...) 
     59{ 
     60  va_list ap; 
     61 
     62  va_start(ap, fmt); 
     63  vfprintf(stderr, fmt, ap); 
     64  va_end(ap); 
     65  fputc('\n', stderr); 
     66 
     67  exit(1); 
     68} 
     69 
     70static void *xcalloc(size_t size, size_t nmemb) 
     71{ 
     72  void *result = calloc(size, nmemb); 
     73  if (!result) 
     74    die("Out of memory"); 
     75 
     76  return result; 
     77} 
     78 
     79static void string_release(std::string *string) 
     80{ 
     81  if (string) { 
     82    free(string); 
     83  } 
     84} 
     85 
     86struct entry { 
     87  char d_name[PATH_MAX]; 
     88  int d_namlen; 
     89} entry; 
     90 
     91struct dir { 
     92  std::string pattern; 
     93  HANDLE handle; 
     94  WIN32_FIND_DATA find_data; 
     95  int done; 
     96  struct entry entry; 
     97}; 
     98 
     99struct dir *open_dir(const char *path) 
     100{ 
     101  struct dir *result = (dir*)xcalloc(sizeof(struct dir), 1); 
     102  if (!result) 
     103    return result; 
     104/* 
     105  result->pattern = (std::string*)malloc(strlen(path) + 3); 
     106  if (!result->pattern) { 
     107    errno = ENOMEM; 
     108    return NULL; 
     109  } 
     110*/ 
     111  result->pattern.assign(path); 
     112  result->pattern.append(".*"); 
     113  result->handle = FindFirstFile(result->pattern.c_str(), &(result->find_data)); 
     114  if (result->handle == INVALID_HANDLE_VALUE) { 
     115    //free(result->pattern); 
     116    free(result); 
     117    return NULL; 
     118  } 
     119  result->done = 0; 
     120  return result; 
     121} 
     122 
     123struct entry *read_dir(struct dir *dir) 
     124{ 
     125  if (dir->done) 
     126    return NULL; 
     127  strcpy(dir->entry.d_name, dir->find_data.cFileName); 
     128  dir->entry.d_namlen = strlen(dir->entry.d_name); 
     129  if (FindNextFile(dir->handle, &dir->find_data) == 0) 
     130    dir->done = 1; 
     131  return &dir->entry; 
     132} 
     133 
     134int close_dir(struct dir *dir) 
     135{ 
     136  //string_release(dir->pattern); 
     137  FindClose(dir->handle); 
     138  free(dir); 
     139  return 0; 
     140} 
     141 
     142#define DIR struct dir 
     143#define dirent entry 
     144#define opendir open_dir 
     145#define readdir read_dir 
     146#define closedir close_dir 
     147#else 
     148#include <dirent.h> 
     149#endif 
     150 
    45151#if defined (_WIN32) 
    46152#define PATHSTEP ';' 
Note: See TracChangeset for help on using the changeset viewer.