• 大小: 8.52MB
    文件类型: .gz
    金币: 1
    下载: 0 次
    发布日期: 2023-10-06
  • 语言: 其他
  • 标签: bash  源码  

资源简介

bash4.4源代码,学习了解bash原理,及系统级别开发的绝佳参考

资源截图

代码片段和文件信息

/* alias.c -- Not a full alias but just the kind that we use in the
   shell.  Csh style alias is somewhere else (‘over there in a box‘). */

/* Copyright (C) 1987-2015 Free Software Foundation Inc.

   This file is part of GNU Bash the Bourne Again SHell.

   Bash is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation either version 3 of the License or
   (at your option) any later version.

   Bash is distributed in the hope that it will be useful
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with Bash.  If not see .
*/

#include “config.h“

#if defined (ALIAS)

#if defined (HAVE_UNISTD_H)
#  ifdef _MINIX
#    include 
#  endif
#  include 
#endif

#include 
#include “chartypes.h“
#include “bashansi.h“
#include “command.h“
#include “general.h“
#include “externs.h“
#include “alias.h“

#if defined (PROGRAMMABLE_COMPLETION)
#  include “pcomplete.h“
#endif

#if defined (HAVE_MBSTR_H) && defined (HAVE_MBSCHR)
#  include  /* mbschr */
#endif

#define ALIAS_HASH_BUCKETS 64 /* must be power of two */

typedef int sh_alias_map_func_t __P((alias_t *));

static void free_alias_data __P((PTR_T));
static alias_t **map_over_aliases __P((sh_alias_map_func_t *));
static void sort_aliases __P((alias_t **));
static int qsort_alias_compare __P((alias_t ** alias_t **));

#if defined (READLINE)
static int skipquotes __P((char * int));
static int skipws __P((char * int));
static int rd_token __P((char * int));
#endif

/* Non-zero means expand all words on the line.  Otherwise expand
   after first expansion if the expansion ends in a space. */
int alias_expand_all = 0;

/* The list of aliases that we have. */
HASH_TABLE *aliases = (HASH_TABLE *)NULL;

void
initialize_aliases ()
{
  if (aliases == 0)
    aliases = hash_create (ALIAS_HASH_BUCKETS);
}

/* Scan the list of aliases looking for one with NAME.  Return NULL
   if the alias doesn‘t exist else a pointer to the alias_t. */
alias_t *
find_alias (name)
     char *name;
{
  BUCKET_CONTENTS *al;

  if (aliases == 0)
    return ((alias_t *)NULL);

  al = hash_search (name aliases 0);
  return (al ? (alias_t *)al->data : (alias_t *)NULL);
}

/* Return the value of the alias for NAME or NULL if there is none. */
char *
get_alias_value (name)
     char *name;
{
  alias_t *alias;

  if (aliases == 0)
    return ((char *)NULL);

  alias = find_alias (name);
  return (alias ? alias->value : (char *)NULL);
}

/* Make a new alias from NAME and VALUE.  If NAME can be found
   then replace its value. */
void
add_alias (name value)
     char *name *value;
{
  BUCKET_CONTENTS *elt;
  alias_t *temp;
  int n;

  if (aliases == 0

评论

共有 条评论