home *** CD-ROM | disk | FTP | other *** search
/ PC-Online 1996 May / PCOnline_05_1996.bin / linux / source / a / bin / modules-.2 / modules- / modules-1.2.8 / depmod / config1.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-31  |  2.0 KB  |  89 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <ctype.h>
  5. #include <limits.h>
  6. #include "link.h"
  7.  
  8. /*
  9.     Check if a module name is indeed an alias for another module.
  10.     Return the real module or this one (mod) if it is not an alias
  11. */
  12. const char *any_alias(const char *mod)
  13. {
  14.     const char *modname = stripo(mod);
  15.     int len = strlen(modname);
  16.     /* #Specification: /etc/conf.modules / alias / format
  17.         The format of the alias command in /etc/conf.modules
  18.         is
  19.         #
  20.         alias alias_name module_name
  21.         #
  22.         THe different word are separated by tabs or spaces.
  23.     */
  24.     for (int i = 0; i < aliasavail; i++) {
  25.         if (strncmp(aliaslist[i], modname, len) == 0
  26.             && isspace(aliaslist[i][len])) {
  27.             return str_skip(&(aliaslist[i][len]));
  28.         }
  29.     }
  30.     return mod;
  31. }
  32.  
  33.  
  34. /*
  35.     Locate all module matching "match".
  36.     Return the number of modules found. The caller must free the content
  37.     of abs_path[].
  38. */
  39. int config_locate (
  40.     const char *match,
  41.     char *abs_path[1000],
  42.     const char *type)    // Restric search to path[type]
  43.                         // or type is NULL (No restriction)
  44. {
  45.     int ret=0;
  46.     if (strchr(match,'/')!=NULL){
  47.         abs_path[0] = strdup_err (match);
  48.         ret = 1;
  49.     }else{
  50.         char *lst[1000];
  51.         match = any_alias (match);
  52.         if (!match || !(*match) || (strcmp(match, "off") == 0))
  53.             return -1;
  54.         char match_o[PATH_MAX];
  55.         sprintf (match_o,"%s.o",match);
  56.         int nb = config_lstmod (match_o,type,lst
  57.             ,strpbrk(match, SHELL_WILD) != NULL ? 1 : 0);
  58.         if (nb > 0){
  59.             // The list may contain many duplication of some module
  60.             // for example, the module slip may be in /lib/modules/default/net
  61.             // and in /lib/modules/x.y.z/net
  62.             for (int i=0; i<nb; i++){
  63.                 char *found = lst[i];
  64.                 if (found != NULL){
  65.                     abs_path[ret++] = found;
  66.                     lst[i] = NULL;
  67.                     char name[PATH_MAX];
  68.                     path_extrname (found,name);
  69.                     for (int j=i+1; j<nb; j++){
  70.                         char *nxt = lst[j];
  71.                         if (nxt != NULL){
  72.                             char name2[PATH_MAX];
  73.                             path_extrname(nxt,name2);
  74.                             if (strcmp(name,name2)==0){
  75.                                 free (nxt);
  76.                                 lst[j] = NULL;
  77.                             }
  78.                         }
  79.                     }
  80.                 }
  81.             }
  82.             tbstr_free (lst,nb);
  83.         }
  84.     }
  85.     return ret;
  86. }
  87.  
  88.  
  89.