Commit 41ff9ecb authored by Michael Aaron Murphy's avatar Michael Aaron Murphy
Browse files

Public items now have crate-level visibility

This is the next step towards using Ion as a library for an upcoming project.
parent a61f0ec9
pub const ERR_EXIT: u8 = 1;
pub const PRINT_COMMS: u8 = 2;
pub(crate) const ERR_EXIT: u8 = 1;
pub(crate) const PRINT_COMMS: u8 = 2;
......@@ -11,14 +11,14 @@ use std::io::{self, stdout, Write};
use std::mem;
use types::Array;
pub enum Condition {
pub(crate) enum Condition {
Continue,
Break,
NoOp,
SigInt,
}
pub trait FlowLogic {
pub(crate) trait FlowLogic {
/// Receives a command and attempts to execute the contents.
fn on_command(&mut self, command_string: &str);
......
......@@ -7,7 +7,7 @@ use types::*;
use types::Identifier;
#[derive(Debug, PartialEq, Clone)]
pub struct ElseIf {
pub(crate) struct ElseIf {
pub expression: Pipeline,
pub success: Vec<Statement>,
}
......@@ -33,7 +33,7 @@ pub struct ElseIf {
/// Case { value: None, ... }
/// ```
#[derive(Debug, PartialEq, Clone)]
pub struct Case {
pub(crate) struct Case {
pub value: Option<String>,
pub binding: Option<String>,
pub conditional: Option<String>,
......@@ -42,7 +42,7 @@ pub struct Case {
// TODO: Enable statements and expressions to contain &str values.
#[derive(Debug, PartialEq, Clone)]
pub enum Statement {
pub(crate) enum Statement {
Let { expression: String },
Case(Case),
Export(String),
......@@ -83,7 +83,7 @@ pub enum Statement {
}
impl Statement {
pub fn short(&self) -> &'static str {
pub(crate) fn short(&self) -> &'static str {
match *self {
Statement::Let { .. } => "Let { .. }",
Statement::Case(_) => "Case { .. }",
......@@ -106,7 +106,7 @@ impl Statement {
}
}
pub struct FlowControl {
pub(crate) struct FlowControl {
pub level: usize,
pub current_statement: Statement,
pub current_if_mode: u8, // { 0 = SUCCESS; 1 = FAILURE }
......@@ -123,20 +123,20 @@ impl Default for FlowControl {
}
#[derive(Clone)]
pub struct Function {
pub(crate) struct Function {
pub description: Option<String>,
pub name: Identifier,
pub args: Vec<KeyBuf>,
pub statements: Vec<Statement>,
}
pub enum FunctionError {
pub(crate) enum FunctionError {
InvalidArgumentCount,
InvalidArgumentType(Primitive, String),
}
impl Function {
pub fn execute(self, shell: &mut Shell, args: &[&str]) -> Result<(), FunctionError> {
pub(crate) fn execute(self, shell: &mut Shell, args: &[&str]) -> Result<(), FunctionError> {
if args.len() - 1 != self.args.len() {
return Err(FunctionError::InvalidArgumentCount);
}
......@@ -192,7 +192,7 @@ impl Function {
}
}
pub fn collect_cases<I>(
pub(crate) fn collect_cases<I>(
iterator: &mut I,
cases: &mut Vec<Case>,
level: &mut usize,
......@@ -255,7 +255,7 @@ pub fn collect_cases<I>(
return Ok(());
}
pub fn collect_loops<I: Iterator<Item = Statement>>(
pub(crate) fn collect_loops<I: Iterator<Item = Statement>>(
iterator: &mut I,
statements: &mut Vec<Statement>,
level: &mut usize,
......@@ -292,7 +292,7 @@ pub fn collect_loops<I: Iterator<Item = Statement>>(
}
}
pub fn collect_if<I>(
pub(crate) fn collect_if<I>(
iterator: &mut I,
success: &mut Vec<Statement>,
else_if: &mut Vec<ElseIf>,
......
......@@ -19,14 +19,14 @@ bitflags! {
}
}
pub struct IgnoreSetting {
pub(crate) struct IgnoreSetting {
flags: IgnoreFlags,
// Yes, a bad heap-based Vec, however unfortunately its not possible to store Regex'es in Array
regexes: Option<Vec<Regex>>,
}
impl IgnoreSetting {
pub fn default() -> IgnoreSetting {
pub(crate) fn default() -> IgnoreSetting {
IgnoreSetting {
flags: IgnoreFlags::empty(),
regexes: None,
......@@ -35,7 +35,7 @@ impl IgnoreSetting {
}
/// Contains all history-related functionality for the `Shell`.
pub trait ShellHistory {
pub(crate) trait ShellHistory {
/// Prints the commands contained within the history buffers to standard output.
fn print_history(&self, _arguments: &[&str]) -> i32;
......
......@@ -10,7 +10,7 @@ use smallstring::SmallString;
use types::*;
#[derive(Debug, PartialEq, Clone, Copy)]
pub enum JobKind {
pub(crate) enum JobKind {
And,
Background,
Last,
......@@ -19,14 +19,14 @@ pub enum JobKind {
}
#[derive(Debug, PartialEq, Clone)]
pub struct Job {
pub(crate) struct Job {
pub command: Identifier,
pub args: Array,
pub kind: JobKind,
}
impl Job {
pub fn new(args: Array, kind: JobKind) -> Self {
pub(crate) fn new(args: Array, kind: JobKind) -> Self {
let command = SmallString::from_str(&args[0]);
Job {
command,
......@@ -37,7 +37,7 @@ impl Job {
/// Takes the current job's arguments and expands them, one argument at a
/// time, returning a new `Job` with the expanded arguments.
pub fn expand<E: Expander>(&mut self, expanders: &E) {
pub(crate) fn expand<E: Expander>(&mut self, expanders: &E) {
let mut expanded = Array::new();
expanded.grow(self.args.len());
expanded.extend(self.args.drain().flat_map(|arg| {
......@@ -54,7 +54,7 @@ impl Job {
/// This represents a job that has been processed and expanded to be run
/// as part of some pipeline
pub enum RefinedJob {
pub(crate) enum RefinedJob {
/// An external program that is executed by this shell
External(Command),
/// A procedure embedded into Ion
......@@ -101,7 +101,7 @@ macro_rules! set_field {
}
impl RefinedJob {
pub fn builtin(name: Identifier, args: Array) -> Self {
pub(crate) fn builtin(name: Identifier, args: Array) -> Self {
RefinedJob::Builtin {
name,
args,
......@@ -111,7 +111,7 @@ impl RefinedJob {
}
}
pub fn function(name: Identifier, args: Array) -> Self {
pub(crate) fn function(name: Identifier, args: Array) -> Self {
RefinedJob::Function {
name,
args,
......@@ -121,21 +121,21 @@ impl RefinedJob {
}
}
pub fn stdin(&mut self, file: File) {
pub(crate) fn stdin(&mut self, file: File) {
set_field!(self, stdin, file);
}
pub fn stdout(&mut self, file: File) {
pub(crate) fn stdout(&mut self, file: File) {
set_field!(self, stdout, file);
}
pub fn stderr(&mut self, file: File) {
pub(crate) fn stderr(&mut self, file: File) {
set_field!(self, stderr, file);
}
/// Returns a short description of this job: often just the command
/// or builtin name
pub fn short(&self) -> String {
pub(crate) fn short(&self) -> String {
match *self {
RefinedJob::External(ref cmd) => {
format!("{:?}", cmd).split('"').nth(1).unwrap_or("").to_string()
......@@ -147,7 +147,7 @@ impl RefinedJob {
}
/// Returns a long description of this job: the commands and arguments
pub fn long(&self) -> String {
pub(crate) fn long(&self) -> String {
match *self {
RefinedJob::External(ref cmd) => {
let command = format!("{:?}", cmd);
......
......@@ -14,11 +14,11 @@ pub mod signals;
pub mod status;
pub mod variables;
pub use self::binary::Binary;
pub use self::flow::FlowLogic;
pub use self::history::{IgnoreSetting, ShellHistory};
pub use self::job::{Job, JobKind};
pub use self::pipe_exec::{foreground, job_control};
pub(crate) use self::binary::Binary;
pub(crate) use self::flow::FlowLogic;
pub(crate) use self::history::{IgnoreSetting, ShellHistory};
pub(crate) use self::job::{Job, JobKind};
pub(crate) use self::pipe_exec::{foreground, job_control};
use self::directory_stack::DirectoryStack;
use self::flags::*;
......@@ -49,7 +49,7 @@ use types::*;
/// the entirety of the
/// program. It is initialized at the beginning of the program, and lives until the end of the
/// program.
pub struct Shell<'a> {
pub(crate) struct Shell<'a> {
/// Contains a list of built-in commands that were created when the program started.
pub builtins: &'a FnvHashMap<&'static str, Builtin>,
/// Contains the history, completions, and manages writes to the history file.
......@@ -88,7 +88,7 @@ pub struct Shell<'a> {
impl<'a> Shell<'a> {
/// Panics if DirectoryStack construction fails
pub fn new(builtins: &'a FnvHashMap<&'static str, Builtin>) -> Shell<'a> {
pub(crate) fn new(builtins: &'a FnvHashMap<&'static str, Builtin>) -> Shell<'a> {
Shell {
builtins: builtins,
context: None,
......@@ -108,7 +108,7 @@ impl<'a> Shell<'a> {
}
}
pub fn next_signal(&self) -> Option<i32> {
pub(crate) fn next_signal(&self) -> Option<i32> {
for sig in 0..32 {
if signals::PENDING.fetch_and(!(1 << sig), Ordering::SeqCst) & (1 << sig) == 1 << sig {
return Some(sig);
......@@ -118,7 +118,7 @@ impl<'a> Shell<'a> {
None
}
pub fn exit(&mut self, status: i32) -> ! {
pub(crate) fn exit(&mut self, status: i32) -> ! {
if let Some(context) = self.context.as_mut() {
context.history.commit_history();
}
......@@ -147,7 +147,7 @@ impl<'a> Shell<'a> {
}
/// Evaluates the source init file in the user's home directory.
pub fn evaluate_init_file(&mut self) {
pub(crate) fn evaluate_init_file(&mut self) {
match app_root(
AppDataType::UserConfig,
&AppInfo {
......
......@@ -2,7 +2,7 @@
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
pub enum BackgroundResult {
pub(crate) enum BackgroundResult {
Errored,
Status(u8),
}
......@@ -11,7 +11,7 @@ pub enum BackgroundResult {
/// communication between the shell and background threads. The `fg` command uses this
/// structure to notify a background thread that it needs to wait for and return
/// the exit status back to the `fg` function.
pub struct ForegroundSignals {
pub(crate) struct ForegroundSignals {
grab: AtomicUsize, // TODO: Use AtomicU32 when stable
status: AtomicUsize, // TODO: Use AtomicU8 when stable
reply: AtomicBool,
......@@ -19,7 +19,7 @@ pub struct ForegroundSignals {
}
impl ForegroundSignals {
pub fn new() -> ForegroundSignals {
pub(crate) fn new() -> ForegroundSignals {
ForegroundSignals {
grab: AtomicUsize::new(0),
status: AtomicUsize::new(0),
......@@ -28,21 +28,21 @@ impl ForegroundSignals {
}
}
pub fn signal_to_grab(&self, pid: u32) { self.grab.store(pid as usize, Ordering::Relaxed); }
pub(crate) fn signal_to_grab(&self, pid: u32) { self.grab.store(pid as usize, Ordering::Relaxed); }
pub fn reply_with(&self, status: i8) {
pub(crate) fn reply_with(&self, status: i8) {
self.grab.store(0, Ordering::Relaxed);
self.status.store(status as usize, Ordering::Relaxed);
self.reply.store(true, Ordering::Relaxed);
}
pub fn errored(&self) {
pub(crate) fn errored(&self) {
self.grab.store(0, Ordering::Relaxed);
self.errored.store(true, Ordering::Relaxed);
self.reply.store(true, Ordering::Relaxed);
}
pub fn was_processed(&self) -> Option<BackgroundResult> {
pub(crate) fn was_processed(&self) -> Option<BackgroundResult> {
if self.reply.load(Ordering::Relaxed) {
self.reply.store(false, Ordering::Relaxed);
if self.errored.load(Ordering::Relaxed) {
......@@ -56,7 +56,7 @@ impl ForegroundSignals {
}
}
pub fn was_grabbed(&self, pid: u32) -> bool {
pub(crate) fn was_grabbed(&self, pid: u32) -> bool {
self.grab.load(Ordering::Relaxed) == pid as usize
}
}
use sys;
/// Ensures that the forked child is given a unique process ID.
pub fn create_process_group(pgid: u32) { let _ = sys::setpgid(0, pgid); }
pub(crate) fn create_process_group(pgid: u32) { let _ = sys::setpgid(0, pgid); }
use super::job_control::{JobControl, ProcessState};
use super::pipe;
......@@ -12,7 +12,7 @@ use std::process::exit;
/// Forks the shell, adding the child to the parent's background list, and executing
/// the given commands in the child fork.
pub fn fork_pipe(
pub(crate) fn fork_pipe(
shell: &mut Shell,
commands: Vec<(RefinedJob, JobKind)>,
command_name: String,
......
......@@ -9,16 +9,16 @@ use std::time::Duration;
use sys;
use sys::job_control as self_sys;
pub use sys::job_control::watch_background;
pub(crate) use sys::job_control::watch_background;
/// When given a process ID, that process's group will be assigned as the foreground process group.
pub fn set_foreground_as(pid: u32) {
pub(crate) fn set_foreground_as(pid: u32) {
signals::block();
let _ = sys::tcsetpgrp(0, pid);
signals::unblock();
}
pub trait JobControl {
pub(crate) trait JobControl {
/// Waits for background jobs to finish before returning.
fn wait_for_background(&mut self);
/// Takes a background tasks's PID and whether or not it needs to be continued; resumes the
......@@ -44,7 +44,7 @@ pub trait JobControl {
#[derive(Clone, Copy, Debug, PartialEq)]
/// Defines whether the background process is running or stopped.
pub enum ProcessState {
pub(crate) enum ProcessState {
Running,
Stopped,
Empty,
......@@ -60,7 +60,7 @@ impl fmt::Display for ProcessState {
}
}
pub fn add_to_background(
pub(crate) fn add_to_background(
processes: Arc<Mutex<Vec<BackgroundProcess>>>,
pid: u32,
state: ProcessState,
......@@ -95,7 +95,7 @@ pub fn add_to_background(
/// by the shell. The shell will only retain information about the process, such
/// as the process ID, state that the process is in, and the command that the
/// process is executing.
pub struct BackgroundProcess {
pub(crate) struct BackgroundProcess {
pub pid: u32,
pub ignore_sighup: bool,
pub state: ProcessState,
......
......@@ -158,7 +158,7 @@ fn redirect_output(stdout: Redirection, piped_commands: &mut Vec<(RefinedJob, Jo
false
}
pub trait PipelineExecution {
pub(crate) trait PipelineExecution {
/// Given a pipeline, generates commands and executes them.
///
/// The `Pipeline` structure contains a vector of `Job`s, and redirections to perform on the
......@@ -449,7 +449,7 @@ impl<'a> PipelineExecution for Shell<'a> {
}
/// This function will panic if called with an empty slice
pub fn pipe(shell: &mut Shell, commands: Vec<(RefinedJob, JobKind)>, foreground: bool) -> i32 {
pub(crate) fn pipe(shell: &mut Shell, commands: Vec<(RefinedJob, JobKind)>, foreground: bool) -> i32 {
fn close(file: &Option<File>) {
if let &Some(ref file) = file {
if let Err(e) = sys::close(file.as_raw_fd()) {
......
#[cfg(target_os = "redox")]
mod redox;
#[cfg(target_os = "redox")]
pub use self::redox::*;
pub(crate) use self::redox::*;
#[cfg(all(unix, not(target_os = "redox")))]
mod unix;
#[cfg(all(unix, not(target_os = "redox")))]
pub use self::unix::*;
pub(crate) use self::unix::*;
use std::fs::ReadDir;
use types::Identifier;
pub struct Library;
pub(crate) struct Library;
/// Grabs all `Library` entries found within a given directory
pub struct LibraryIterator {
pub(crate) struct LibraryIterator {
directory: ReadDir,
}
impl LibraryIterator {
pub fn new(directory: ReadDir) -> LibraryIterator { LibraryIterator { directory } }
pub(crate) fn new(directory: ReadDir) -> LibraryIterator { LibraryIterator { directory } }
}
impl Iterator for LibraryIterator {
......
......@@ -3,12 +3,12 @@ use std::fs::ReadDir;
use types::Identifier;
/// Grabs all `Library` entries found within a given directory
pub struct LibraryIterator {
pub(crate) struct LibraryIterator {
directory: ReadDir,
}
impl LibraryIterator {
pub fn new(directory: ReadDir) -> LibraryIterator { LibraryIterator { directory } }
pub(crate) fn new(directory: ReadDir) -> LibraryIterator { LibraryIterator { directory } }
}
impl Iterator for LibraryIterator {
......
#[cfg(target_os = "redox")]
mod redox;
#[cfg(target_os = "redox")]
pub use self::redox::*;
pub(crate) use self::redox::*;
#[cfg(all(unix, not(target_os = "redox")))]
mod unix;
#[cfg(all(unix, not(target_os = "redox")))]
pub use self::unix::*;
pub(crate) use self::unix::*;
use super::super::StringError;
pub enum MethodArguments {
pub(crate) enum MethodArguments {
StringArg(String, Vec<String>),
Array(Vec<String>, Vec<String>),
NoArgs,
}
pub struct StringMethodPlugins;
pub(crate) struct StringMethodPlugins;
impl StringMethodPlugins {
pub fn new() -> StringMethodPlugins { StringMethodPlugins }
pub(crate) fn new() -> StringMethodPlugins { StringMethodPlugins }
pub fn execute(
pub(crate) fn execute(
&self,
_function: &str,
_arguments: MethodArguments,
......@@ -24,4 +24,4 @@ impl StringMethodPlugins {
///
/// This function is meant to be called with `lazy_static` to ensure that there isn't a
/// cost to collecting all this information when the shell never uses it in the first place!
pub fn collect() -> StringMethodPlugins { StringMethodPlugins::new() }
pub(crate) fn collect() -> StringMethodPlugins { StringMethodPlugins::new() }
......@@ -13,7 +13,7 @@ use types::Identifier;
/// Either one or the other will be set. Optional status can be conveyed by setting the
/// corresponding field to `NULL`. Libraries importing this structure should check for nullness.
#[repr(C)]
pub struct RawMethodArguments {
pub(crate) struct RawMethodArguments {
key_ptr: *mut i8,
key_array_ptr: *mut *mut i8,
args_ptr: *mut *mut i8,
......@@ -21,7 +21,7 @@ pub struct RawMethodArguments {
args_len: usize,
}
pub enum MethodArguments {
pub(crate) enum MethodArguments {
StringArg(String, Vec<String>),
Array(Vec<String>, Vec<String>),
NoArgs,
......@@ -97,7 +97,7 @@ impl From<MethodArguments> for RawMethodArguments {
/// plugin to ensure that the plugin remains loaded in memory, and it's contained symbols
/// remain validly-executable; and B) holds a map of functions that may be executed within
/// the namespace.
pub struct StringMethodPlugins {
pub(crate) struct StringMethodPlugins {
#[allow(dead_code)]
/// Contains all of the loaded libraries from whence the symbols were obtained.
libraries: Vec<Library>,
......@@ -107,14 +107,14 @@ pub struct StringMethodPlugins {
}
impl StringMethodPlugins {
pub fn new() -> StringMethodPlugins {
pub(crate) fn new() -> StringMethodPlugins {
StringMethodPlugins {
libraries: Vec::new(),
symbols: FnvHashMap::default(),
}
}
pub fn load(&mut self, library: Library) -> Result<(), StringError> {
pub(crate) fn load(&mut self, library: Library) -> Result<(), StringError> {
unsafe {
{
// The `index` function contains a list of functions provided by the library.
......@@ -197,7 +197,7 @@ impl StringMethodPlugins {
///
/// If the function exists, it is executed, and it's return value is then converted into a
/// proper Rusty type.
pub fn execute(
pub(crate) fn execute(
&self,
function: &str,
arguments: MethodArguments,
......@@ -222,7 +222,7 @@ impl StringMethodPlugins {
///
/// This function is meant to be called with `lazy_static` to ensure that there isn't a
/// cost to collecting all this information when the shell never uses it in the first place!
pub fn collect() -> StringMethodPlugins {
pub(crate) fn collect() -> StringMethodPlugins {
let mut methods = StringMethodPlugins::new();
if let Some(mut path) = config_dir() {
path.push("methods");
......
......@@ -3,13 +3,13 @@ pub mod namespaces;
mod library_iter;
mod string;
pub use self::library_iter::*;
pub use self::string::StringError;
pub(crate) use self::library_iter::*;
pub(crate) use self::string::StringError;
use app_dirs::{app_root, AppDataType, AppInfo};
use std::path::PathBuf;
pub fn config_dir() -> Option<PathBuf> {
pub(crate) fn config_dir() -> Option<PathBuf> {
match app_root(
AppDataType::UserConfig,
&AppInfo {
......
#[cfg(target_os = "redox")]
mod redox;
#[cfg(target_os = "redox")]
pub use self::redox::*;
pub(crate) use</