anchor.diff:      %% which separates erlang from concuerror options
       Pred = fun(P) -> {concuerror_options, []} /= P end,
       [_ | Args2] = lists:dropwhile(Pred, Args1),
  -    Res =
  -        %% There should be no plain_arguments
  -        case init:get_plain_arguments() of
  -            [] -> Options = parse(Args2, []), cliAux(Options);
  -            [Arg|_] ->
  -                Msg = io_lib:format("unrecognised argument: ~s", [Arg]),
  -                {'error', 'arguments', Msg}
  -        end,
  -    Res,
  -    true.
  +    %% There should be no plain_arguments
  +    case init:get_plain_arguments() of
  +        [Arg|_] ->
  +            io:format("~s: unrecognised argument: ~s", [?APP_STRING, Arg]),
  +            init:stop(1);
  +        [] -> continue
  +    end,
  +    Options =
  +        case parse(Args2, []) of
  +            {'error', 'arguments', Msg1} ->
  +                io:format("~s: ~s\n", [?APP_STRING, Msg1]),
  +                init:stop(1);
  +            Opts -> Opts
  +        end,
  +    case cliAux(Options) of
  +        {'ok', 'gui'} ->
  +            true;
  +        {'error', 'arguments', Msg2} ->
  +            io:format("~s: ~s\n", [?APP_STRING, Msg2]),
  +            init:stop(1);
  +        Result ->
  +            %% Set output file
  +            Output =
  +                case lists:keyfind(output, 1, Options) of
  +                    {output, O} -> O;
  +                    false -> "results.txt"
  +                end,
  +            case export(Result, Output) of
  +                {'error', Msg3} ->
  +                    io:format("~s: ~s\n",
  +                        [?APP_STRING, file:format_error(Msg3)]),
  +                    init:stop(1);
  +                ok -> true
  +            end
  +    end.
   
   cliAux(Options) ->
       case lists:keyfind('gui', 1, Options) of
  
positive.code:                 Msg2 = "no input files specified",
                  {'error', 'arguments', Msg2}
          end,
      %% Set output file
      Output =
          case lists:keyfind(output, 1, Options) of
              {output, O} -> O;
              false -> "results.txt"
          end,
      %% Set include dirs
      Include =
          case lists:keyfind(include, 1, Options) of
  
negative.code:     %% Start the analysis
      sched:analyze(Target, Files, AnalysisOptions).
  
  
  %%%----------------------------------------------------------------------
  %%% Export Analysis results into a file
  %%%----------------------------------------------------------------------
  
  %% @spec export(sched:analysis_ret(), file()) ->
  %%              'ok' | {'error', file:posix() | badarg | system_limit}
  %% @doc: Export the analysis results into a text file.
  -spec export(sched:analysis_ret(), file()) ->
      'ok' | {'error', file:posix() | badarg | system_limit}.
  export(Results, File) ->
      case file:open(File, ['write']) of
          {ok, IoDevice} ->
              exportAux(Results, IoDevice),
              file:close(IoDevice);
          Error -> Error
      end.
  
  exportAux({'ok', {_Target, RunCount}}, IoDevice) ->
      Msg = io_lib:format("Checked ~w interleaving(s). No errors found.\n",
          [RunCount]),
      file:write(IoDevice, Msg);
  exportAux({error, instr, {_Target, _RunCount}}, IoDevice) ->
      Msg = io_lib:format("Instrumentation error.\n"),
      file:write(IoDevice, Msg);
  exportAux({error, analysis, {_Target, RunCount}, Tickets}, IoDevice) ->
      TickLen = length(Tickets),
      Msg1 = io_lib:format("Checked ~w interleaving(s). ~w errors found.\n\n",
          [RunCount, TickLen]),
      file:write(IoDevice, Msg1),
      showDetails(1, ticket:sort(Tickets), IoDevice).
  
  %% Show details about each ticket
  showDetails(Count, [Ticket|Tickets], IoDevice) ->
      Error = ticket:get_error(Ticket),
      Msg1 = io_lib:format("~p\n~s\n", [Count, error:long(Error)]),
      file:write(IoDevice, Msg1),
      Details = ticket:get_state(Ticket),
      lists:foreach(fun(Detail) ->
                  D = proc_action:to_string(Detail),
                  Msg2 = io_lib:format("  ~s\n", [D]),
                  file:write(IoDevice, Msg2) end,
          Details),
      file:write(IoDevice, "\n\n"),
      showDetails(Count+1, Tickets, IoDevice);
  showDetails(_Count, [], _IoDevice) -> ok.
  
  
  %%%----------------------------------------------------------------------
  