mirror of
https://github.com/mikpe/pdp10-tools.git
synced 2026-01-24 11:22:52 +00:00
change strtol:parse/2 to return a standard {ok,Result} 2-tuple
This commit is contained in:
parent
ce0595ef44
commit
180fcbc1b9
@ -1127,11 +1127,7 @@ read_ar_name(FP) ->
|
||||
"/" -> {ok, String}; % archive symbol table
|
||||
"//" -> {ok, String}; % archive string table
|
||||
[$/ | Numeral] -> % offset into archive string table
|
||||
case strtol:parse(Numeral, 10) of
|
||||
{ok, Value, []} -> {ok, Value};
|
||||
{ok, _Value, _} -> {error, trailing_garbage};
|
||||
{error, _Reason} = Error -> Error
|
||||
end;
|
||||
strtol(Numeral, 10);
|
||||
_ ->
|
||||
case string:split(String ++ "$", "/") of
|
||||
[FileName, "$"] -> {ok, FileName};
|
||||
@ -1149,18 +1145,20 @@ read_ar_uid(FP) ->
|
||||
|
||||
read_number(FP, Base, FieldSize) ->
|
||||
case read_string(FP, FieldSize) of
|
||||
{ok, String} ->
|
||||
case strtol:parse(trim_trailing_spaces(String), Base) of
|
||||
{ok, Value, []} -> {ok, Value};
|
||||
{ok, _Value, _} -> {error, trailing_garbage};
|
||||
{error, _Reason} = Error -> Error
|
||||
end;
|
||||
{ok, String} -> strtol(trim_trailing_spaces(String), Base);
|
||||
{error, _Reason} = Error -> Error
|
||||
end.
|
||||
|
||||
trim_trailing_spaces(String) ->
|
||||
string:trim(String, trailing, [$\s]).
|
||||
|
||||
strtol(String, Base) ->
|
||||
case strtol:parse(String, Base) of
|
||||
{ok, {Value, _Rest = []}} -> {ok, Value};
|
||||
{ok, {_Value, _Rest}} -> {error, trailing_garbage};
|
||||
{error, _Reason} = Error -> Error
|
||||
end.
|
||||
|
||||
%% read FieldSize characters
|
||||
read_string(FP, FieldSize) ->
|
||||
case pdp10_stdio:fread(1, FieldSize, FP) of
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
%%% -*- erlang-indent-level: 2 -*-
|
||||
%%%
|
||||
%%% strtol() clone for Erlang
|
||||
%%% Copyright (C) 2018 Mikael Pettersson
|
||||
%%% Copyright (C) 2018-2019 Mikael Pettersson
|
||||
%%%
|
||||
%%% This file is part of pdp10-tools.
|
||||
%%%
|
||||
@ -30,7 +30,7 @@
|
||||
|
||||
-type base() :: 0 | 2..36.
|
||||
|
||||
-spec parse(string(), base()) -> {ok, integer(), string()} | {error, any()}.
|
||||
-spec parse(string(), base()) -> {ok, {integer(), string()}} | {error, any()}.
|
||||
parse(String, Base) ->
|
||||
scan_spaces(String, Base).
|
||||
|
||||
@ -98,7 +98,7 @@ scan_digits(String, Value, Base, Minus) ->
|
||||
|
||||
return(Rest, Value0, Minus) ->
|
||||
Value = if Minus -> -Value0; true -> Value0 end,
|
||||
{ok, Value, Rest}.
|
||||
{ok, {Value, Rest}}.
|
||||
|
||||
no_digits() ->
|
||||
{error, no_digits}.
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
%%% -*- erlang-indent-level: 2 -*-
|
||||
%%%
|
||||
%%% 'od' clone for files with 9-bit bytes
|
||||
%%% Copyright (C) 2013-2018 Mikael Pettersson
|
||||
%%% Copyright (C) 2013-2019 Mikael Pettersson
|
||||
%%%
|
||||
%%% This file is part of pdp10-tools.
|
||||
%%%
|
||||
@ -139,7 +139,7 @@ parse_radix(String) ->
|
||||
|
||||
parse_bytes(String) ->
|
||||
case strtol:parse(String, 0) of
|
||||
{ok, Value, Rest} ->
|
||||
{ok, {Value, Rest}} ->
|
||||
Value * parse_multiplier(Rest);
|
||||
{error, _Reason} ->
|
||||
escript_runtime:fatal("invalid number '~s'\n", [String])
|
||||
@ -178,7 +178,7 @@ parse_size(String, OutputType, Opts) ->
|
||||
[$L | Rest] -> parse_z(Rest, 4, OutputType, Opts);
|
||||
_ ->
|
||||
case strtol:parse(String, 10) of
|
||||
{ok, Size, Rest} when Size =:= 1; Size =:= 2; Size =:= 4 ->
|
||||
{ok, {Size, Rest}} when Size =:= 1; Size =:= 2; Size =:= 4 ->
|
||||
parse_z(Rest, Size, OutputType, Opts);
|
||||
_ -> escript_runtime:fatal("invalid type size '~s'\n", [String])
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user