aboutsummaryrefslogtreecommitdiffstats
path: root/os/hal/boards/simulator/board.h
blob: ec6ed8b66019977ff896d00e8ac03cf28af1594f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/*
    ChibiOS - Copyright (C) 2006..2016 Giovanni Di Sirio

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
*/

#ifndef _BOARD_H_
#define _BOARD_H_

#if !defined(_FROM_ASM_)
#ifdef __cplusplus
extern "C" {
#endif
  void boardInit(void);
#ifdef __cplusplus
}
#endif
#endif /* _FROM_ASM_ */

#endif /* _BOARD_H_ */
#bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
package org.xenoserver.cmdline;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

import org.xenoserver.control.CommandFailedException;
import org.xenoserver.control.Defaults;
import org.xenoserver.control.PartitionManager;
import org.xenoserver.control.Settings;
import org.xenoserver.control.VirtualDiskManager;
import org.xenoserver.control.XML;

/**
 * Subclasses of Parser know how to parse arguments for a given command
 * and execute it, displaying any output.
 */
public abstract class CommandParser {
    /**
     * Subclasses should implement this method such that it outputs any successful
     * output to the screen, or throws an exception if required arguments
     * are missing or malformed. It also may propagate exceptions from the
     * command execution.
     * 
     * @param d The defaults object to use.
     * @param args The arguments to parse.
     * @throws ParseFailedException if the arguments are not suitable.
     * @throws CommandFailedException if the command did not execute successfully.
     */
    public abstract void parse(Defaults d, LinkedList args)
        throws ParseFailedException, CommandFailedException;

    /** @return The command name which will be matched on the command line. */
    public abstract String getName();
    /** @return A usage string for this command. */
    public abstract String getUsage();
    /** @return The help text for this command. */
    public abstract String getHelpText();

    /**
     * Print a usage string for this command.
     * @param prefix The command prefix for this command
     */
    public void printUsage(String prefix) {
        String name = getName();
        if (prefix != null) {
            name = prefix + " " + name;
        }
        String usage = getUsage();
        while (name.length() < 16) {
            name = name + " ";
        }
        System.out.println("   " + name + usage);
    }

    /**
     * Prints the help text for this command.
     * @param args Command arguments, ignored for normal commands.
     */
    public void printHelpText(LinkedList args) {
        System.out.println(getName() + " " + getUsage());
        System.out.println();
        System.out.println(getHelpText());
    }

    /**
     * Get a string parameter
     * @param args Argument list to search
     * @param key Argument key
     * @param def Default value
     * @return parameter, or default if none found
     */
    public String getStringParameter(List args, char key, String def) {
        String r = getParameter(args, key);
        return (r == null) ? def : r;
    }

    /**
     * Get an int parameter
     * @param args Argument list to search
     * @param key Argument key
     * @param def Default value
     * @return parameter, or default if none found
     */
    public int getIntParameter(List args, char key, int def) {
        String r = getParameter(args, key);
        return (r == null) ? def : (Integer.parseInt(r.trim()));
    }

    /**
     * Get a boolean parameter
     * @param args Argument list to search
     * @param key Argument key
     * @return parameter, or false if none found
     */
    public boolean getFlagParameter(List args, char key) {
        String r = getParameter(args, key);
        return (r == null) ? false : true;
    }

    /**
     * Get a parameter
     * @param args Argument list to search
     * @param key Key to look for
     * @return Value, or "" if no value, or null if no such argument
     */
    protected String getParameter(List args, char key) {
        String result = null;
        Iterator i = args.iterator();
        while (i.hasNext()) {
            String arg = (String) i.next();
            if (arg.startsWith("-" + key)) {
                if (arg.length() > 2) {
                    result = arg.substring(2);
                } else {
                    result = "";
                }
            }
        }
        return result;
    }

    /**
     * Load the partition and disk manager state
     */
    protected void loadState() {
        XML.loadState(
            PartitionManager.IT,
            VirtualDiskManager.IT,
            Settings.STATE_INPUT_FILE);
    }

    /**
     * Save the partition and disk manager state
     */
    protected void saveState() {
        XML.saveState(
            PartitionManager.IT,
            VirtualDiskManager.IT,
            Settings.STATE_OUTPUT_FILE);
    }
}