/* REXX */

/*
-----------------------------------------------------------------
  unpacker (v0.1) = public domain : free for any use

  AUTHOR: rugxulo _AT_ gmail

  TESTED: Regina 3.7, BRexx 2.1.9, r4 4.00, ooREXX 4.1.3

  BUG:    Can't use literal '*'+'/' pair in embedded data files.
-----------------------------------------------------------------
*/

/* --- UNPACKER BEGINS --- */

if arg() \= 0 then parse arg onlyfile . ; else onlyfile=''
parse source . . srcfile . ; lineno=0 ; writeln=0

bar = '===' ; prefix='/*' bar ; postfix = bar '*/'
headpost=' begins' postfix ; footpost=' ends' postfix
headlen=length(headpost) ; footlen=length(footpost)

if lines(srcfile)=1 then do while lines(srcfile) \= 0
  call grab
end
else do lines(srcfile)
  call grab
end

exit

grab:
  line=linein(srcfile) ; lineno=lineno+1
  if pos(headpost,line) \= 0 then do
    parse var line ' ' (bar) ' ' outfile (headpost) .
    if onlyfile='' then say outfile
    writeln=1
  end
  else if pos(footpost,line) \= 0 then writeln=0
  if pos(headpost,line)=0 & pos(footpost,line)=0 & writeln then ,
    if onlyfile='' | onlyfile=outfile then ,
      call lineout outfile, line
return

/* --- UNPACKER ENDS --- */

/*
------------------------------------------------------------
*** DATA BEGINS DATA BEGINS DATA BEGINS DATA BEGINS ***

/* these data files = public domain : free for any use */
------------------------------------------------------------

/* === Str.ob2 begins === */
(* public domain, nenies proprajho, free for any use *)
MODULE Str; (* XDS *)
IMPORT S := O2Strings;

PROCEDURE Length*(s:ARRAY OF CHAR):INTEGER;
BEGIN RETURN S.Length(s)
END Length;

PROCEDURE Append*(this:ARRAY OF CHAR; VAR that:ARRAY OF CHAR);
BEGIN S.Append(this,that)
END Append;

PROCEDURE Pos*(findthis,lookhere:ARRAY OF CHAR; start:INTEGER):INTEGER;
BEGIN RETURN S.Pos(findthis,lookhere,start)
END Pos;

PROCEDURE Extract*(src:ARRAY OF CHAR; start,howmany:INTEGER; VAR dest:ARRAY OF CHAR);
BEGIN S.Extract(src,start,howmany,dest)
END Extract;

PROCEDURE Insert*(src:ARRAY OF CHAR; where:INTEGER; VAR dest:ARRAY OF CHAR);
BEGIN S.Insert(src,where,dest)
END Insert;

PROCEDURE Delete*(VAR inhere:ARRAY OF CHAR; where,howmany:INTEGER);
BEGIN S.Delete(inhere,where,howmany)
END Delete;

END Str.
/* === Str.ob2 ends === */

/* === Str.m begins === */
(* public domain, nenies proprajho, free for any use *)
MODULE Str; (* Oxford *)
IMPORT S := Strings;

PROCEDURE Length*(s:ARRAY OF CHAR):INTEGER;
BEGIN RETURN S.Length(s)
END Length;

PROCEDURE Append*(this:ARRAY OF CHAR; VAR that:ARRAY OF CHAR);
BEGIN S.Append(this,that)
END Append;

PROCEDURE Pos*(findthis,lookhere:ARRAY OF CHAR; start:INTEGER):INTEGER;
BEGIN RETURN S.Pos(findthis,lookhere,start)
END Pos;

PROCEDURE Extract*(src:ARRAY OF CHAR; start,howmany:INTEGER; VAR dest:ARRAY OF CHAR);
BEGIN S.Extract(src,start,howmany,dest)
END Extract;

PROCEDURE Insert*(src:ARRAY OF CHAR; where:INTEGER; VAR dest:ARRAY OF CHAR);
BEGIN S.Insert(src,where,dest)
END Insert;

PROCEDURE Delete*(VAR inhere:ARRAY OF CHAR; where,howmany:INTEGER);
BEGIN S.Delete(inhere,where,howmany)
END Delete;

END Str.
/* === Str.m ends === */


# --- extract.awk begins ---
#!/usr/bin/awk -f

/[b]egins ===/{
  fname=$3 ; print fname
  while (getline > 0) {
    if ($0 !~ / [e]nds ===/) {
      print > fname
    }
    else {
      close(fname)
      break
    }
  }
}
# --- extract.awk ends ---

------------------------------------------------------------
*** DATA ENDS DATA ENDS DATA ENDS DATA ENDS ***
------------------------------------------------------------
*/

/* EOF */
