about summary refs log tree commit diff
path: root/buildtools/libopt.c
diff options
context:
space:
mode:
Diffstat (limited to 'buildtools/libopt.c')
-rw-r--r--buildtools/libopt.c104
1 files changed, 54 insertions, 50 deletions
diff --git a/buildtools/libopt.c b/buildtools/libopt.c
index f62194e5..c714f416 100644
--- a/buildtools/libopt.c
+++ b/buildtools/libopt.c
@@ -17,7 +17,7 @@
   The "lib" part of the library name, which we call the prefix, may be
   other than "lib".  The list of recognized values is compiled in as
   the macro SHLIBPREFIXLIST (see below).
-  
+
   There is no newline or null character or anything after the output.
 
   If you specify the option "-runtime", the output includes a -R
@@ -78,7 +78,7 @@
    have.  "lib" is traditionally the only prefix, as in libc or
    libnetpbm.  However, on Windows there is a convention of using
    different prefixes to distinguish different co-existent versions of
-   the same library (kind of like a major number in some unices). 
+   the same library (kind of like a major number in some unices).
    E.g. the value "cyg lib" is appropriate for a Cygwin system.
 */
 #ifndef SHLIBPREFIXLIST
@@ -103,7 +103,7 @@ static const char * dllverstr = DLLVERSTR;
 static const char * dllverstr = "";
 #endif
 
-bool const explicit = 
+bool const explicit =
 #ifdef EXPLICIT
 TRUE
 #else
@@ -117,8 +117,9 @@ strfree(const char * const arg) {
 }
 
 
+
 static void
-parse_prefixlist(const char * const prefixlist, 
+parse_prefixlist(const char * const prefixlist,
                  char * parsed_prefixes[MAX_PREFIXES+1],
                  bool * const errorP) {
 /*----------------------------------------------------------------------------
@@ -140,7 +141,7 @@ parse_prefixlist(const char * const prefixlist,
     if (prlist == NULL)
         *errorP = TRUE;
     else {
-        if (strlen(prlist) <= 0) 
+        if (strlen(prlist) <= 0)
             *errorP = TRUE;
         else {
             /* NOTE: Mac OS X, at least, does not have strtok_r().
@@ -149,7 +150,7 @@ parse_prefixlist(const char * const prefixlist,
             char * token;
             int num_tokens;
             int i;
-            
+
             for (i=0; i < MAX_PREFIXES + 1; i++) {
                 parsed_prefixes[i] = NULL;
             }
@@ -158,14 +159,14 @@ parse_prefixlist(const char * const prefixlist,
             *errorP = FALSE;  /* initial value */
             while (token != NULL && num_tokens < MAX_PREFIXES && !*errorP) {
                 parsed_prefixes[num_tokens] = strdup (token);
-                if (parsed_prefixes[num_tokens] == NULL) 
+                if (parsed_prefixes[num_tokens] == NULL)
                     *errorP = TRUE;
                 num_tokens++;
                 token = strtok(NULL, " ");
             }
             for (i = num_tokens; i < MAX_PREFIXES + 1 && !*errorP;  i++) {
                 parsed_prefixes[i] = strdup("");
-                if (parsed_prefixes[i] == NULL) 
+                if (parsed_prefixes[i] == NULL)
                     *errorP = TRUE;
             }
         }
@@ -183,31 +184,31 @@ parse_prefixlist(const char * const prefixlist,
 
 
 static void
-parse_prefix(const char * const filename, 
+parse_prefix(const char * const filename,
              bool * const prefix_good_p, unsigned int * const prefix_length_p,
              bool * const error_p) {
 /*----------------------------------------------------------------------------
    Find the library name prefix (e.g. "lib") in the library filename
    'filename'.
-   
+
    Return the length of the prefix, in characters, as *prefix_length_p.
    (The prefix always starts at the beginning of the filename).
 
    Iff we don't find a valid library name prefix, return *prefix_good_p
-   == FALSE.  
+   == FALSE.
 
    The list of valid prefixes is compiled in as the blank-delimited
    string which is the value of the SHLIBPREFIXLIST macro.
 -----------------------------------------------------------------------------*/
     char * shlibprefixlist[MAX_PREFIXES+1];
-        /* An argv-style array of prefix strings in the first entries, 
+        /* An argv-style array of prefix strings in the first entries,
            null strings in the later entries.  At most MAX_PREFIXES prefixes,
            so at least one null string.
         */
     char * prefix;
         /* The prefix that the filename actually
            uses.  e.g. if shlibprefixlist = { "lib", "cyg", "", ... } and the
-           filename is "path/to/cyg<something>.<extension>", then 
+           filename is "path/to/cyg<something>.<extension>", then
            prefix = "cyg".  String is in the same storage as pointed to by
            shlibprefixlist (shlibprefixlist[1] in this example).
         */
@@ -223,7 +224,7 @@ parse_prefix(const char * const filename,
         if (strcmp(shlibprefixlist[0], "") == 0) {
             fprintf(stderr, "libopt was compiled with an invalid value "
                     "of the SHLIBPREFIX macro.  It seems to have no "
-                    "tokens.  SHLIBPREFIX = '%s'", 
+                    "tokens.  SHLIBPREFIX = '%s'",
                     SHLIBPREFIXLIST);
             exit(100);
         }
@@ -236,9 +237,9 @@ parse_prefix(const char * const filename,
             /* stop condition: shlibprefixlist has MAX_PREFIXES+1 entries.
              * we only ever put tokens in the 0..MAX_PREFIXES-1 positions.
              * Then, we fill DOWN from the MAX_PREFIXES position with '\0'
-             * so we insure that the shlibprefixlist array contains at 
-             * least one final '\0' string, but probably many '\0' 
-             * strings (depending on how many tokens there were).               
+             * so we insure that the shlibprefixlist array contains at
+             * least one final '\0' string, but probably many '\0'
+             * strings (depending on how many tokens there were).
              */
             prefix_length = strlen(prefix);
             if (strncmp(filename, prefix, prefix_length) == 0) {
@@ -246,8 +247,8 @@ parse_prefix(const char * const filename,
                 /* at this point, prefix is pointing to the correct
                  * entry, and prefix_length has the correct value.
                  * When we bail out of the while loop because of the
-                 * !prefix_good clause, we can then use these 
-                 * vars (prefix, prefix_length) 
+                 * !prefix_good clause, we can then use these
+                 * vars (prefix, prefix_length)
                  */
             } else {
                 prefix = shlibprefixlist[++i];
@@ -255,9 +256,9 @@ parse_prefix(const char * const filename,
         }
         *prefix_length_p = prefix_length;
         *prefix_good_p = prefix_good;
-        { 
+        {
             int i;
-            for (i=0; i < MAX_PREFIXES + 1; i++) 
+            for (i=0; i < MAX_PREFIXES + 1; i++)
                 free (shlibprefixlist[i]);
         }
     }
@@ -276,7 +277,7 @@ parse_filename(const char *  const filename,
    is just a filename, not a whole pathname.
 
    Return it in newly malloc'ed storage pointed to by '*libname_p'.
-   
+
    E.g. for "libxyz.so", return "xyz".
 
    return *valid_library_p == TRUE iff 'filename' validly names a library
@@ -290,13 +291,13 @@ parse_filename(const char *  const filename,
 
    Do not allocate any memory if *error_p == TRUE or *valid_library_p == FALSE.
 -----------------------------------------------------------------------------*/
-    char *lastdot;  
+    char *lastdot;
     /* Pointer to last period in 'filename'.  Null if none */
-    
+
     /* We accept any period-delimited suffix as a library type suffix.
        It's probably .so or .a, but is could be .kalamazoo for all we
-       care. (HOWEVER, the double-suffixed import lib used on 
-       cygwin (.dll.a) is NOT understood). 
+       care. (HOWEVER, the double-suffixed import lib used on
+       cygwin (.dll.a) is NOT understood).
     */
     char *p;
 
@@ -321,8 +322,8 @@ parse_filename(const char *  const filename,
             if (!prefix_good) {
                 *valid_library_p = FALSE;
             } else {
-                /* Extract everything between <prefix> and "." as 
-                   the library name root. 
+                /* Extract everything between <prefix> and "." as
+                   the library name root.
                 */
                 char * libname;
 
@@ -334,7 +335,7 @@ parse_filename(const char *  const filename,
                     if (strlen(dllverstr) > 0) {
                         p = strstr(libname, dllverstr);
                         if (p) {
-                            if (libname + strlen(libname) 
+                            if (libname + strlen(libname)
                                 - strlen(dllverstr) == p) {
                                 *p = '\0';
                             }
@@ -350,17 +351,17 @@ parse_filename(const char *  const filename,
             }
         }
     }
-}   
+}
 
 
 
 static void
 parse_filepath(const char *  const filepath,
-               const char ** const directory_p, 
+               const char ** const directory_p,
                const char ** const filename_p,
                bool *        const error_p) {
 /*----------------------------------------------------------------------------
-   Extract the directory and filename components of the filepath 
+   Extract the directory and filename components of the filepath
    'filepath' and return them in newly malloc'ed storage pointed to by
    '*directory_p' and '*filename_p'.
 
@@ -373,7 +374,7 @@ parse_filepath(const char *  const filepath,
 
     if (lastslash == NULL) {
         /* There's no directory component; the filename starts at the
-           beginning of the filepath 
+           beginning of the filepath
         */
         *filename_p = strdup(filepath);
         if (*filename_p == NULL)
@@ -387,8 +388,8 @@ parse_filepath(const char *  const filepath,
                 *error_p = FALSE;
         }
     } else {
-        /* Split the string at the slash we just found, into filename and 
-           directory 
+        /* Split the string at the slash we just found, into filename and
+           directory
            */
         *filename_p = strdup(lastslash+1);
         if (*filename_p == NULL)
@@ -410,7 +411,7 @@ parse_filepath(const char *  const filepath,
 
 
 static void
-doOptions(const char *  const filepath, 
+doOptions(const char *  const filepath,
           const char *  const directory,
           const char *  const libname,
           bool          const runtime,
@@ -434,20 +435,20 @@ doOptions(const char *  const filepath,
     }
     if (runtime && !staticlib && strlen(directory) > 0) {
         options = malloc(strlen(linkopt) + strlen(directory) + 10);
-        sprintf(options, "%s -R%s", linkopt, directory); 
+        sprintf(options, "%s -R%s", linkopt, directory);
     } else
         options = strdup(linkopt);
-    
+
     strfree(linkopt);
-    
+
     *optionsP = options;
 }
 
 
 
 static void
-processOneLibrary(const char *  const filepath, 
-                  bool          const runtime, 
+processOneLibrary(const char *  const filepath,
+                  bool          const runtime,
                   bool          const explicit,
                   const char ** const optionsP,
                   bool *        const errorP) {
@@ -465,28 +466,28 @@ processOneLibrary(const char *  const filepath,
     if (!*errorP) {
         const char *libname;
             /* Library name component of 'filename'.  e.g. xyz in
-               libxyz.so 
+               libxyz.so
             */
-        bool valid_library;  
+        bool valid_library;
             /* Our argument is a valid library filepath that can be
-               converted to -l/-L notation.  
+               converted to -l/-L notation.
             */
         bool staticlib;
             /* Our argument appears to name a static library. */
 
-        parse_filename(filename, 
+        parse_filename(filename,
                        &libname, &valid_library, &staticlib, errorP);
-        
+
         if (!*errorP) {
             if (valid_library) {
-                doOptions(filepath, directory, libname, 
+                doOptions(filepath, directory, libname,
                           runtime, explicit, staticlib, optionsP);
 
                 strfree(libname);
             } else
                 *optionsP = strdup(filepath);
         }
-        strfree(directory); 
+        strfree(directory);
         strfree(filename);
     }
 }
@@ -513,10 +514,10 @@ main(int argc, char **argv) {
             /* Doesn't do anything today */
         } else {
             const char * options;
-            processOneLibrary(argv[arg], runtime, explicit, 
+            processOneLibrary(argv[arg], runtime, explicit,
                               &options, &error);
             if (!error) {
-                if (strlen(outputLine) + strlen(options) + 1 + 1 > 
+                if (strlen(outputLine) + strlen(options) + 1 + 1 >
                     sizeof(outputLine))
                     error = TRUE;
                 else {
@@ -537,3 +538,6 @@ main(int argc, char **argv) {
     }
     return retval;
 }
+
+
+