Fixed missing return statement in new_settings_t.

Fri, 27 May 2011 12:49:33 +0200

author
Mike Becker <universe@uap-core.de>
date
Fri, 27 May 2011 12:49:33 +0200
changeset 4
c3acfb3b4957
parent 3
510d6b198dde
child 5
9393eff3d2f9

Fixed missing return statement in new_settings_t.
Added support for c++ compilers.
Added destroy_settings_t function

cline.c file | annotate | diff | comparison | revisions
cline.h file | annotate | diff | comparison | revisions
functions.h file | annotate | diff | comparison | revisions
     1.1 --- a/cline.c	Thu May 26 14:39:52 2011 +0200
     1.2 +++ b/cline.c	Fri May 27 12:49:33 2011 +0200
     1.3 @@ -12,6 +12,15 @@
     1.4    settings->recursive          = false;
     1.5    settings->includeSuffixes    = false;
     1.6    settings->matchesOnly        = false;
     1.7 +  
     1.8 +  return settings;
     1.9 +}
    1.10 +
    1.11 +void destroy_settings_t(settings_t* settings) {
    1.12 +  if (settings->suffixv != NULL) {
    1.13 +    free(settings->suffixv);
    1.14 +  }
    1.15 +  free(settings);
    1.16  }
    1.17  
    1.18  void printHelpText(const char* prgName) {
    1.19 @@ -177,13 +186,13 @@
    1.20    DIR *dir = opendir(directory);
    1.21    if (dir == NULL) {
    1.22      perror("Operation failed");
    1.23 -    free(settings->suffixv);
    1.24 -    free(settings);
    1.25 +    destroy_settings_t(settings);
    1.26      return 1;
    1.27    }
    1.28    
    1.29    // Scan directory
    1.30    int lines = scanDirectory(dir, 0, directory, settings);
    1.31 +  closedir(dir);
    1.32  
    1.33    // Print double line and line count
    1.34    #ifdef _WIN32
    1.35 @@ -201,8 +210,6 @@
    1.36      printf("\n%74d lines\n", lines);
    1.37    #endif /* _WIN32 */
    1.38  
    1.39 -  closedir(dir);
    1.40 -  free(settings->suffixv);
    1.41 -  free(settings);
    1.42 +  destroy_settings_t(settings);
    1.43    return 0;
    1.44  }
     2.1 --- a/cline.h	Thu May 26 14:39:52 2011 +0200
     2.2 +++ b/cline.h	Fri May 27 12:49:33 2011 +0200
     2.3 @@ -16,8 +16,15 @@
     2.4    bool matchesOnly;
     2.5  } settings_t;
     2.6  
     2.7 +#ifdef _cplusplus
     2.8 +extern "C" {
     2.9 +#endif
    2.10  settings_t* new_settings_t();
    2.11 +void destroy_settings_t(settings_t*);
    2.12  
    2.13 -void printHelpText(const char* prgName);
    2.14 +void printHelpText(const char*);
    2.15 +#ifdef _cplusplus
    2.16 +}
    2.17 +#endif
    2.18  
    2.19  #endif /* _CLINE_H */
     3.1 --- a/functions.h	Thu May 26 14:39:52 2011 +0200
     3.2 +++ b/functions.h	Fri May 27 12:49:33 2011 +0200
     3.3 @@ -1,9 +1,17 @@
     3.4  #ifndef _CLINE_FUNCTIONS_H
     3.5  #define _CLINE_FUNCTIONS_H
     3.6  
     3.7 +#ifdef _cplusplus
     3.8 +extern "C" {
     3.9 +#endif
    3.10 +
    3.11  int checkArgument(const char*, const char*);
    3.12  bool testSuffix(char* filename, settings_t* settings);
    3.13  int scanDirectory(DIR *dir, const int spaces,
    3.14                    char* currdir, settings_t* settings);
    3.15  
    3.16 -#endif /* V2_H */
    3.17 +#ifdef _cplusplus
    3.18 +}
    3.19 +#endif 
    3.20 +                  
    3.21 +#endif /* _CLINE_FUNCTIONS_H */

mercurial