Skip to content

Commit

Permalink
base64 encoding, lower case quoting, aton prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
urbanjost committed Jan 11, 2025
1 parent 2a51122 commit 52a0712
Show file tree
Hide file tree
Showing 295 changed files with 8,236 additions and 6,958 deletions.
Empty file modified .github/workflows/deploy_api_docs.yml
100755 → 100644
Empty file.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public entities:
use M_strings, only : [split2020](https://urbanjost.github.io/M_strings/split2020.3m_strings), [find_field](https://urbanjost.github.io/M_strings/find_field.3m_strings)
use M_strings, only : [substitute](https://urbanjost.github.io/M_strings/substitute.3m_strings), [change](https://urbanjost.github.io/M_strings/change.3m_strings), [modif](https://urbanjost.github.io/M_strings/modif.3m_strings), [transliterate](https://urbanjost.github.io/M_strings/transliterate.3m_strings), [reverse](https://urbanjost.github.io/M_strings/reverse.3m_strings), [squeeze](https://urbanjost.github.io/M_strings/squeeze.3m_strings)
use M_strings, only : [replace](https://urbanjost.github.io/M_strings/replace.3m_strings), [join](https://urbanjost.github.io/M_strings/join.3m_strings)
use M_strings, only : [upper](https://urbanjost.github.io/M_strings/upper.3m_strings), [lower](https://urbanjost.github.io/M_strings/lower.3m_strings), [upper_quoted](https://urbanjost.github.io/M_strings/upper_quoted.3m_strings)
use M_strings, only : [upper](https://urbanjost.github.io/M_strings/upper.3m_strings), [lower](https://urbanjost.github.io/M_strings/lower.3m_strings), [upper_quoted](https://urbanjost.github.io/M_strings/upper_quoted.3m_strings), [lower_quoted](https://urbanjost.github.io/M_strings/lower_quoted.3m_strings)
use M_strings, only : [rotate13](https://urbanjost.github.io/M_strings/rotate13.3m_strings), [percent_encode](https://urbanjost.github.io/M_strings/percent_encode.3m_strings)
use M_strings, only : [adjustc](https://urbanjost.github.io/M_strings/adjustc.3m_strings), [compact](https://urbanjost.github.io/M_strings/compact.3m_strings), [nospace](https://urbanjost.github.io/M_strings/nospace.3m_strings), [indent](https://urbanjost.github.io/M_strings/indent.3m_strings)
use M_strings, only : [crop](https://urbanjost.github.io/M_strings/crop.3m_strings), [clip](https://urbanjost.github.io/M_strings/clip.3m_strings), [unquote](https://urbanjost.github.io/M_strings/unquote.3m_strings), [quote](https://urbanjost.github.io/M_strings/quote.3m_strings), [matching_delimiter](https://urbanjost.github.io/M_strings/matching_delimiter.3m_strings)
Expand All @@ -47,9 +47,8 @@ public entities:
use M_strings, only : [describe](https://urbanjost.github.io/M_strings/describe.3m_strings)
use M_strings, only : [edit_distance](https://urbanjost.github.io/M_strings/edit_distance.3m_strings)
use M_strings, only : [cc](https://urbanjost.github.io/M_strings/cc.3m_strings)
use M_strings, only :
[int](https://urbanjost.github.io/M_strings/int.3m_strings), [dble](https://urbanjost.github.io/M_strings/dble.3m_strings), [nint](https://urbanjost.github.io/M_strings/nint.3m_strings)
use M_strings, only : [atoi](https://urbanjost.github.io/M_strings/atoi.3m_strings), [atol](https://urbanjost.github.io/M_strings/atol.3m_strings), [dble](https://urbanjost.github.io/M_strings/ato.3m_strings)
use M_strings, only : [int](https://urbanjost.github.io/M_strings/int.3m_strings), [real](https://urbanjost.github.io/M_strings/real.3m_strings), [dble](https://urbanjost.github.io/M_strings/dble.3m_strings), [nint](https://urbanjost.github.io/M_strings/nint.3m_strings)
use M_strings, only : [atoi](https://urbanjost.github.io/M_strings/atoi.3m_strings), [atol](https://urbanjost.github.io/M_strings/atol.3m_strings), [ato](https://urbanjost.github.io/M_strings/ato.3m_strings)

## Intrinsics

Expand Down
100 changes: 100 additions & 0 deletions app/b64.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
program demo_base64
use M_io, only : filebyte
use M_strings, only : encode_base64, decode_base64
use M_CLI2, only : set_args, iget, lget, infiles=>unnamed
! encode data to base64 encryption as defined by RFC-4648 and print to standard output
! usage: base64 inputfile > outputfile
! currently stdin and stdout cannot be defined as streams, so stdin should
! be restricted to ASCII files with a newline terminator at end, and stdout is
! potentially subject to linelength limits of the platform.
! reading input into memory could be expensive if the file is large
use,intrinsic :: iso_fortran_env, only : int8, int32, stderr=>ERROR_UNIT, stdout=>OUTPUT_UNIT
implicit none
integer(kind=int32) :: i, j, column, sz, pad, iostat
character(len=1),allocatable :: text(:) ! array to hold file in memory
character(len=1) :: chunk(4)
character(len=1) :: tri(3)
character(len=1),allocatable :: trilast(:)
integer :: wrap
character(len=*),parameter :: rfc4648_alphabet='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
integer,parameter :: rfc4648_linelength=76
character(len=1),parameter :: rfc4648_padding='='
character(len=:),allocatable :: help_text(:), version_text(:)
logical :: decode
logical :: ignore_garbage
call setup()
call set_args('--wrap:w 76 --decode:d F --ignore-garbage:i F',help_text,version_text)
wrap=iget('wrap')
ignore_garbage=lget('ignore-garbage')
decode=lget('decode')
if(size(infiles).eq.0)infiles=[character(len=1):: '-']
! reading the file into memory can be a problem when the files are large, and this routine currently reads stdin
! until an end-of-file while writing it to a scratch file first, which can be slow and use file space resources
! can change it to process the file in a buffered mannner so reading from stdin is performed more efficiently
call filebyte(infiles(1),text) ! allocate character array and copy file into it and pad with two characters at end
if(.not.allocated(text))then
stop '<ERROR>*base64* text not allocated'
endif
! non-advancing I/O is not stream I/O so this could hit a line length limit
select case(decode)
case(.false.)
write(*,fmt='(*(a))',advance='no')encode_base64(text,width=wrap)
case default
write(*,fmt='(*(a))',advance='no')decode_base64(text,ignore_garbage=ignore_garbage)
end select
contains
subroutine setup()
help_text=[ CHARACTER(LEN=128) :: &
'NAME',&
' b64-(1f) - [FUNIX:FILESYSTEM] encode/data specified file to stdout',&
' using base64 encoding as defined in RFC-4648 ',&
' (LICENSE:MIT) ',&
' ',&
'SYNOPSIS ',&
' b64- [[ --decode] [ --ignore-garbage]]|[ --wrap COLS] [FILE] ',&
' |[ --help|--version] ',&
' ',&
'DESCRIPTION ',&
' b64(1f) encodes or decodes a file as described for the ',&
' b64alphabet-encoding in RFC 4648. When decoding, whitespace characters',&
' on input are ignored. ',&
' ',&
' b64(1f) takes stdin or one filename on the command line and encodes ',&
' or decodes it onto standard output. ',&
' ',&
' With no FILE, or when FILE is "-", read standard input. ',&
' ',&
' To ignore all bytes not in the formal base64 alphabet, use ',&
' --ignore-garbage. This option will attempt to recover from any other ',&
' non-alphabet bytes in the encoded stream. ',&
' ',&
'OPTIONS ',&
' ',&
' filename name of file to encode ',&
' --decode,-d decode instead of encode data ',&
' --ignore-garbage,i when decoding, ignore non-alphabet characters ',&
' --wrap=COLS,-w COLS wrap encoded lines after COLS characters ',&
' (default 76). Use 0 to disable line wrapping ',&
' --version,-v Print version information on standard output then',&
' exit successfully. ',&
' --help,-h Print usage information on standard output then ',&
' exit successfully. ',&
'EXAMPLE ',&
' Sample commands ',&
' ',&
' b64 input > output.b64 ',&
' ',&
'SEE ALSO ',&
' base64(1), uuencode(1), uudecode(1) ',&
'']
version_text=[ CHARACTER(LEN=128) :: &
'PRODUCT: GPF (General Purpose Fortran) utilities and examples',&
'PROGRAM: b64(1f) ',&
'DESCRIPTION: encode a file to the base 64 encoding standard defined in RFC-4648',&
'VERSION: 1.0, 2024-11-11 ',&
'AUTHOR: John S. Urban ',&
'LICENSE: MIT ',&
'']
end subroutine setup

end program demo_base64
102 changes: 102 additions & 0 deletions app/b64.ff
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
program demo_base64
use M_io, only : filebyte, putchar
use M_strings, only : encode_base64, decode_base64
use M_CLI2, only : set_args, iget, lget, infiles=>unnamed
! encode data to base64 encryption as defined by RFC-4648 and print to standard output
! usage: base64 inputfile > outputfile
! currently stdin and stdout cannot be defined as streams, so stdin should
! be restricted to ASCII files with a newline terminator at end, and stdout is
! potentially subject to linelength limits of the platform.
! reading input into memory could be expensive if the file is large
use,intrinsic :: iso_fortran_env, only : int8, int32, stderr=>ERROR_UNIT, stdout=>OUTPUT_UNIT
implicit none
integer(kind=int32) :: i, j, column, sz, pad, iostat
character(len=1),allocatable :: text(:) ! array to hold file in memory
character(len=1) :: chunk(4)
character(len=1) :: tri(3)
character(len=1),allocatable :: trilast(:)
integer :: wrap
character(len=*),parameter :: rfc4648_alphabet='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
integer,parameter :: rfc4648_linelength=76
character(len=1),parameter :: rfc4648_padding='='
character(len=:),allocatable :: help_text(:), version_text(:)
logical :: decode
logical :: ignore_garbage
call setup()
call set_args('--wrap:w 76 --decode:d F --ignore-garbage:i F',help_text,version_text)
wrap=iget('wrap')
ignore_garbage=lget('ignore-garbage')
decode=lget('decode')
if(size(infiles).eq.0)infiles=[character(len=1):: '-']
! reading the file into memory can be a problem when the files are large, and this routine currently reads stdin
! until an end-of-file while writing it to a scratch file first, which can be slow and use file space resources
! can change it to process the file in a buffered mannner so reading from stdin is performed more efficiently
call filebyte(infiles(1),text) ! allocate character array and copy file into it and pad with two characters at end
if(.not.allocated(text))then
stop '<ERROR>*base64* text not allocated'
endif
! non-advancing I/O is not stream I/O so this could hit a line length limit
select case(decode)
case(.false.)
write(*,fmt='(*(a))',advance='no')encode_base64(text,width=wrap)
case default
write(*,fmt='(*(a))',advance='no')decode_base64(text,ignore_garbage=ignore_garbage)
end select
contains
subroutine setup()
$!@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
$BLOCK VARIABLE --varname help_text --file b64-.1.man
NAME
b64-(1f) - [FUNIX:FILESYSTEM] encode/data specified file to stdout
using base64 encoding as defined in RFC-4648
(LICENSE:MIT)

SYNOPSIS
b64- [[ --decode] [ --ignore-garbage]]|[ --wrap COLS] [FILE]
|[ --help|--version]

DESCRIPTION
b64(1f) encodes or decodes a file as described for the
b64alphabet-encoding in RFC 4648. When decoding, whitespace characters
on input are ignored.

b64(1f) takes stdin or one filename on the command line and encodes
or decodes it onto standard output.

With no FILE, or when FILE is "-", read standard input.

To ignore all bytes not in the formal base64 alphabet, use
--ignore-garbage. This option will attempt to recover from any other
non-alphabet bytes in the encoded stream.

OPTIONS

filename name of file to encode
--decode,-d decode instead of encode data
--ignore-garbage,i when decoding, ignore non-alphabet characters
--wrap=COLS,-w COLS wrap encoded lines after COLS characters
(default 76). Use 0 to disable line wrapping
--version,-v Print version information on standard output then
exit successfully.
--help,-h Print usage information on standard output then
exit successfully.
EXAMPLE
Sample commands

b64 input > output.b64

SEE ALSO
base64(1), uuencode(1), uudecode(1)
$!@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
$BLOCK VARIABLE --varname version_text
PRODUCT: GPF (General Purpose Fortran) utilities and examples
PROGRAM: b64(1f)
DESCRIPTION: encode a file to the base 64 encoding standard defined in RFC-4648
VERSION: 1.0, 2024-11-11
AUTHOR: John S. Urban
LICENSE: MIT
$BLOCK END
$!@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
end subroutine setup

end program demo_base64
Empty file modified bench/test_atoi.f90
100755 → 100644
Empty file.
Empty file modified bench/time_atoi.f90
100755 → 100644
Empty file.
Empty file modified bench/time_ator.f90
100755 → 100644
Empty file.
2 changes: 1 addition & 1 deletion docs/BOOK_M_strings.html
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta name="generator" content="vi(1)/vim(1)" />
<meta name="description" content="@(#)M_strings::BOOK_M_strings: BOOK composed of pages for man(1) topic M_strings"/>
<meta name="author" content="urbanjs" />
<meta name="date" content="2024-09-21" />
<meta name="date" content="2025-01-10" />
<meta name="keywords" content="Fortran, Fortran code, source code repository, Fortran library, Fortran archive, source code" />
<!--
Pick your favorite style sheet from among the eight offerings:
Expand Down
2 changes: 1 addition & 1 deletion docs/BOOK_M_strings__oop.html
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta name="generator" content="vi(1)/vim(1)" />
<meta name="description" content="@(#)M_strings__oop::BOOK_M_strings__oop: BOOK composed of pages for man(1) topic M_strings__oop"/>
<meta name="author" content="urbanjs" />
<meta name="date" content="2024-09-21" />
<meta name="date" content="2025-01-10" />
<meta name="keywords" content="Fortran, Fortran code, source code repository, Fortran library, Fortran archive, source code" />
<!--
Pick your favorite style sheet from among the eight offerings:
Expand Down
Empty file modified docs/CHANGELOG.md
100644 → 100755
Empty file.
46 changes: 27 additions & 19 deletions docs/M_strings.3m_strings.html
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,10 @@ <H3>NAME</H3>
<A HREF=#2>Synopsis</A><BR>
<A HREF=#3>See Also</A><BR>
<A HREF=#4>Examples</A><BR>
<A HREF=#5>Example</A><BR>
<A HREF=#6>Author</A><BR>
<A HREF=#7>License</A><BR>
<A HREF=#5>Author</A><BR>
<A HREF=#6>License</A><BR>
</BLOCKQUOTE>
<A name=8>
<A name=7>

<H3>DESCRIPTION</H3>

Expand Down Expand Up @@ -98,8 +97,9 @@ <H3>SYNOPSIS</H3>
use M_strings,only : substitute, change, modif, transliterate, &
& reverse, squeeze
use M_strings,only : replace, join
use M_strings,only : upper, lower, upper_quoted
use M_strings,only : upper, lower, upper_quoted, lower_quoted
use M_strings,only : rotate13, percent_encode, percent_decode
use M_strings,only : encode_base64, decode_base64
use M_strings,only : adjustc, compact, nospace, indent
use M_strings,only : crop, clip, unquote, quote, matching_delimiter
use M_strings,only : len_white, pad, lpad, cpad, rpad, zpad, &
Expand Down Expand Up @@ -180,7 +180,7 @@ <H4>&nbsp; &nbsp; CONTRIBUTIONS</H4>
</TD></TR>
<TR valign=top><TD colspan=2>
<B>find_field</B> </TD></TR><TR valign=top><TD width=6%>&nbsp;</TD><TD>
token a string
parse a string into tokens
</TD></TR>
<TR></TR></TABLE></BLOCKQUOTE>
<A name=>
Expand Down Expand Up @@ -240,6 +240,16 @@ <H4>&nbsp; &nbsp; EDITING</H4>
apply percent-decryption (aka. URL decryption) to characters
</TD></TR>
<TR valign=top><TD colspan=2>
<B>encode_base64</B> </TD></TR><TR valign=top><TD width=6%>&nbsp;</TD><TD>
apply base64 encoding (as defined in RFC-4648)
to an array of bytes
</TD></TR>
<TR valign=top><TD colspan=2>
<B>decode_base64</B> </TD></TR><TR valign=top><TD width=6%>&nbsp;</TD><TD>
apply base64 decoding (as defined in RFC-4648)
to an array of bytes
</TD></TR>
<TR valign=top><TD colspan=2>
<B>squeeze</B> </TD></TR><TR valign=top><TD width=6%>&nbsp;</TD><TD>
delete adjacent duplicate characters from a string
</TD></TR>
Expand All @@ -264,6 +274,11 @@ <H4>&nbsp; &nbsp; CASE</H4>
function converts string to uppercase skipping strings
quoted per Fortran rules
</TD></TR>
<TR valign=top><TD colspan=2>
<B>lower_quoted</B> </TD></TR><TR valign=top><TD width=6%>&nbsp;</TD><TD>
function converts string to lowercase skipping strings
quoted per Fortran rules
</TD></TR>
<TR></TR></TABLE></BLOCKQUOTE>
<A name=>

Expand Down Expand Up @@ -371,8 +386,6 @@ <H4>&nbsp; &nbsp; QUOTES</H4>
add quotes to string as if written with list-directed output
</TD></TR>
<TR></TR></TABLE></BLOCKQUOTE>
<P>
<P>
<A name=>

<H4>&nbsp; &nbsp; CHARACTER ARRAY VERSUS STRING</H4>
Expand Down Expand Up @@ -719,13 +732,7 @@ <H3>EXAMPLES</H3>
<BLOCKQUOTE>
Each of the procedures includes an [example](example/) program in
the corresponding man(1) page for the function.
</BLOCKQUOTE>
<A name=5>

<H3>EXAMPLE</H3>

</A>
<BLOCKQUOTE>
<P>
Sample program:
<P>
<PRE>
Expand All @@ -735,8 +742,9 @@ <H3>EXAMPLE</H3>
use M_strings,only : substitute, change, modif, transliterate, &
& reverse, squeeze
use M_strings,only : REPLACE, join
use M_strings,only : UPPER, LOWER, upper_quoted
use M_strings,only : UPPER, LOWER, upper_quoted, lower_quoted
use M_strings,only : rotate13, percent_encode, percent_decode
use M_strings,only : encode_base64, decode_base64
use M_strings,only : adjustc, compact, nospace, indent
use M_strings,only : crop, clip, unquote, quote, matching_delimiter
use M_strings,only : len_white, pad, lpad, cpad, rpad, zpad, &
Expand Down Expand Up @@ -785,15 +793,15 @@ <H3>EXAMPLE</H3>
<P>
</PRE>
</BLOCKQUOTE>
<A name=6>
<A name=5>

<H3>AUTHOR</H3>

</A>
<BLOCKQUOTE>
John S. Urban
</BLOCKQUOTE>
<A name=7>
<A name=6>

<H3>LICENSE</H3>

Expand All @@ -802,7 +810,7 @@ <H3>LICENSE</H3>
Public Domain
</BLOCKQUOTE>
<P><HR>
<TABLE width=100%><TR> <TD width=33%><I>Nemo Release 3.1</I></TD> <TD width=33% align=center>M_strings (3m_strings)</TD> <TD align=right width=33%><I>September 21, 2024</I></TD> </TR></TABLE><FONT SIZE=-1>Generated by <A HREF="http://www.squarebox.co.uk/download/manServer.shtml">manServer 1.08</A> from 29e24363-4413-4842-8c7c-5d1b9deb5448 using man macros.</FONT>
<TABLE width=100%><TR> <TD width=33%><I>Nemo Release 3.1</I></TD> <TD width=33% align=center>M_strings (3m_strings)</TD> <TD align=right width=33%><I>January 10, 2025</I></TD> </TR></TABLE><FONT SIZE=-1>Generated by <A HREF="http://www.squarebox.co.uk/download/manServer.shtml">manServer 1.08</A> from 001f7906-aa51-4ecb-8cbe-73c4ab6e51e6 using man macros.</FONT>
<br><br><center><img src="images/M_strings.gif"></center>
</div>
</div>
Expand Down
Loading

0 comments on commit 52a0712

Please sign in to comment.