Exemple #1
0
static modification
test_modification (int i) {
  switch (i) {
  case  0: return mod_assign (path (), "Hi");
  case  1: return mod_insert (path (), 0, tree (TUPLE, "a", "b"));
  case  2: return mod_remove (path (), 0, 2);
  case  3: return mod_split (path (), 0, 1);
  case  4: return mod_join (path (), 0);
  case  5: return mod_assign_node (path (), TUPLE);
  case  6: return mod_insert_node (path (), 1, tree (TUPLE, "a", "b"));
  case  7: return mod_remove_node (path (), 0);

  case  8: return mod_insert (path (), 1, tree (TUPLE, "a", "b"));
  case  9: return mod_insert (path (), 2, tree (TUPLE, "a", "b"));
  case 10: return mod_remove (path (), 1, 2);
  case 11: return mod_remove (path (), 2, 2);
  case 12: return mod_split (path (), 1, 2);
  case 13: return mod_split (path (), 2, 1);
  case 14: return mod_join (path (), 1);
  case 15: return mod_join (path (), 2);
  case 16: return mod_remove_node (path (), 1);
  case 17: return mod_remove_node (path (), 2);

  case 18: case 19: case 20: case 21: case 22: case 23: case 24: case 25:
    return path (0) * test_modification (i-18);
  case 26: case 27: case 28: case 29: case 30: case 31: case 32: case 33:
    return path (1) * test_modification (i-26);
  case 34: case 35: case 36: case 37: case 38: case 39: case 40: case 41:
    return path (2) * test_modification (i-34);
  default:
    FAILED ("not implemented");
    return mod_assign (path (), "");
  }
}
Exemple #2
0
bool
join (modification& m1, modification m2, tree t) {
  if (m1->k == MOD_INSERT &&
      m2->k == MOD_INSERT &&
      is_atomic (m1->t) &&
      root (m1) == root (m2) &&
      (index (m2) == index (m1) ||
       index (m2) == index (m1) + N (m1->t->label)))
    {
      string s= m1->t->label * m2->t->label;
      if (index (m2) == index (m1))
	s= m2->t->label * m1->t->label;
      m1= mod_insert (root (m1), index (m1), tree (s));
      return true;
    }
  if (m1->k == MOD_REMOVE &&
      m2->k == MOD_REMOVE &&
      is_atomic (subtree (t, root (m1))) &&
      root (m1) == root (m2) &&
      (index (m1) == index (m2) ||
       index (m1) == index (m2) + argument (m2)))
    {
      m1= mod_remove (root (m2), index (m2),
		      argument (m1) + argument (m2));
      return true;
    }
  return false;
}
Exemple #3
0
int modprobe_main(int argc, char** argv)
{
	int rc = EXIT_SUCCESS;
	char *unused;

	bb_opt_complementally = "?V-:q-v:v-q";
	main_opts = bb_getopt_ulflags(argc, argv, "acdklnqrst:vVC:",
							&unused, &unused);
	if((main_opts & (DUMP_CONF_EXIT | LIST_ALL)))
				return EXIT_SUCCESS;
	if((main_opts & (RESTRICT_DIR | CONFIG_FILE)))
				bb_error_msg_and_die("-t and -C not supported");

	depend = build_dep ( );

	if ( !depend )
		bb_error_msg_and_die ( "could not parse modules.dep" );

	if (remove_opt) {
		do {
			if (mod_remove ( optind < argc ?
						argv [optind] : NULL )) {
				bb_error_msg ("failed to remove module %s",
						argv [optind] );
				rc = EXIT_FAILURE;
			}
		} while ( ++optind < argc );
	} else {
		if (optind >= argc)
			bb_error_msg_and_die ( "No module or pattern provided" );

		if ( mod_insert ( argv [optind], argc - optind - 1, argv + optind + 1 ))
			bb_error_msg_and_die ( "failed to load module %s", argv [optind] );
	}

	/* Here would be a good place to free up memory allocated during the dependencies build. */

	return rc;
}
int modprobe_main(int argc, char **argv)
{
	int rc = EXIT_SUCCESS;
	char *unused;

	opt_complementary = "q-v:v-q";
	getopt32(argv, MAIN_OPT_STR, &unused, &unused);

	if (option_mask32 & (DUMP_CONF_EXIT | LIST_ALL))
		return EXIT_SUCCESS;
	if (option_mask32 & (RESTRICT_DIR | CONFIG_FILE))
		bb_error_msg_and_die("-t and -C not supported");

	depend = build_dep();

	if (!depend)
		bb_error_msg_and_die("cannot parse "CONFIG_DEFAULT_DEPMOD_FILE);

	if (remove_opt) {
		do {
			/* argv[optind] can be NULL here */
			if (mod_remove(argv[optind])) {
				bb_error_msg("failed to %s module %s", "remove",
						argv[optind]);
				rc = EXIT_FAILURE;
			}
		} while (++optind < argc);
	} else {
		if (optind >= argc)
			bb_error_msg_and_die("no module or pattern provided");

		if (mod_insert(argv[optind], argc - optind - 1, argv + optind + 1))
			bb_error_msg_and_die("failed to %s module %s", "load", argv[optind]);
	}

	/* Here would be a good place to free up memory allocated during the dependencies build. */

	return rc;
}
Exemple #5
0
modification
invert (modification m, tree t) {
  ASSERT (is_applicable (t, m), "modification not applicable");
  path rp= root (m);
  switch (m->k) {
  case MOD_ASSIGN:
    return mod_assign (rp, copy (subtree (t, rp)));
  case MOD_INSERT:
    return mod_remove (rp, index (m), insert_length (m->t));
  case MOD_REMOVE:
    {
      int i= index (m);
      int n= argument (m);
      return mod_insert (rp, i, copy (insert_range (subtree (t, rp), i, n)));
    }
  case MOD_SPLIT:
    return mod_join (rp, index (m));
  case MOD_JOIN:
    {
      int  i= index (m);
      return mod_split (rp, i, insert_length (subtree (t, rp * i)));
    }
  case MOD_ASSIGN_NODE:
    return mod_assign_node (rp, L (subtree (t, rp)));
  case MOD_INSERT_NODE:
    return mod_remove_node (rp, argument (m));
  case MOD_REMOVE_NODE:
    {
      tree u= subtree (t, rp);
      int  i= index (m);
      return mod_insert_node (rp, i, copy (u (0, i) * u (i+1, N(u))));
    }
  case MOD_SET_CURSOR:
    return m;
  default:
    FAILED ("unexpected situation");
  }
}
extern int modprobe_main(int argc, char** argv)
{
	int	opt;
	int remove_opt = 0;

	autoclean = show_only = quiet = do_syslog = verbose = 0;

	while ((opt = getopt(argc, argv, "acdklnqrst:vVC:")) != -1) {
		switch(opt) {
		case 'c': // no config used
		case 'l': // no pattern matching
			return EXIT_SUCCESS;
			break;
		case 'C': // no config used
		case 't': // no pattern matching
			error_msg_and_die("-t and -C not supported");

		case 'a': // ignore
		case 'd': // ignore
			break;
		case 'k':
			autoclean++;
			break;
		case 'n':
			show_only++;
			break;
		case 'q':
			quiet++;
			break;
		case 'r':
			remove_opt++;
			break;
		case 's':
			do_syslog++;
			break;
		case 'v':
			verbose++;
			break;
		case 'V':
		default:
			show_usage();
			break;
		}
	}
	
	depend = build_dep ( );	

	if ( !depend ) 
		error_msg_and_die ( "could not parse modules.dep\n" );
	
	if (remove_opt) {
		do {
			mod_remove ( optind < argc ? xstrdup ( argv [optind] ) : 0 );
		} while ( ++optind < argc );
		
		return EXIT_SUCCESS;
	}

	if (optind >= argc) 
		error_msg_and_die ( "No module or pattern provided\n" );
	
	return mod_insert ( xstrdup ( argv [optind] ), argc - optind - 1, argv + optind + 1 ) ? \
	       EXIT_FAILURE : EXIT_SUCCESS;
}
/*
 ****************************************************************
 *	Cria o arquivo de sinopse				*
 ****************************************************************
 */
int
do_replace (const char *argv[])
{
	MOD		*mp, *lp, *ap;
	const char	*mod_nm, **cpp;
	char		*mod_path, *nm_point;
	int		len, max_len, r, modif = 0, sort = 0;
	STAT		s;
	HEADER		h;

	/*
	 *	Pequena consistência
	 */
	if (argv[0] == NOSTR)
		error ("$A substituição deve ter nomes de <módulo>s");

	/*
	 *	Lê a sinopse e insere todos os símbolos na tabela HASH
	 */
	read_sinop_file (1);

	if ((hash_tb = calloc (HASHSZ, sizeof (SYMTB *))) == NULL)
		error (NOSTR);

	hash_all_sym ();

	/*
	 *	Prepara o prefixo dos nomes dos módulos
	 */
	for (cpp = argv, max_len = 0; *cpp != NOSTR; cpp++)
	{
		if (max_len < (len = strlen (*cpp)))
			max_len = len;
	}

	mod_path = alloca (lib_dir_nm_len + 1 + max_len);

	strcpy (mod_path, lib_dir_nm);

	strcat (mod_path, "/");	nm_point = strend (mod_path);

	/*
	 *	Processa cada um dos argumentos (módulos)
	 */
	while ((mod_nm = *argv++) != NOSTR)
	{
		strcpy (nm_point, mod_nm);

		if (mod_copy (last_nm (mod_nm), /* => */ mod_path, &s, &h) < 0)
			continue;

		/*
		 *	Verifica se o módulo já está na biblioteca
		 */
		if ((mp = mod_search (mod_nm)) == NOMOD)
		{
			/* O módulo ainda NÃO pertence à biblioteca */

			if ((mp = malloc (sizeof (MOD))) == NOMOD)
				error (NOSTR);

			mp->m_mod_nm = mod_nm;
			mp->m_ino = s.st_ino;
		   /***	mp->m_sym = ...; ***/
		   /***	mp->m_n_sym = ...; ***/
		   /***	mp->m_next = ...; ***/

			/* Insere já no local correto da lista */

			for (ap = NOMOD, lp = mod_first; lp != NOMOD; ap = lp, lp = lp->m_next)
			{
				if (strcmp (lp->m_mod_nm, mp->m_mod_nm) > 0)
					break;
			}

			if (ap == NOMOD)
				mod_first = mp;
			else
				ap->m_next = mp;

			mp->m_next = lp;

			if (mod_insert (mod_nm, mp, &s, &h) < 0)
				continue;

			modif++; sort++;
		}
		else
		{
			/* O módulo já pertence à biblioteca */

			if ((r = mod_replace (mp, &s, &h, 'r')) > 0)
				modif += r;
		}

	}	/* end for (nomes de módulos) */

	free (hash_tb);

	if (sort)
		return (-modif);	/* < 0  =>  Ordena */
	else
		return (modif);

}	/* end do_replace */