#!/usr/bin/sh
echo '* Am creating a new file '$4
exec $psys/psl $* <<%EOP
(OFF ECHO)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Copyright (C) 1996 Joergen Backelin
%%
%% Bergman is distributed in the hope that it will be useful,
%% but WITHOUT ANY WARRANTY.  No author or distributor
%% accepts responsibility to anyone for the consequences of using it
%% or for whether it serves any particular purpose or works at all,
%% unless (s)he says so in writing.  Refer to the Bergman General
%% Public License for full details.

%% Everyone is granted permission to copy, modify and redistribute
%% bergman, but only under the conditions described in the
%% Bergman General Public License.   A copy of this license is
%% supposed to have been given to you along with bergman so you
%% can know your rights and responsibilities.  It should be in a
%% file named copyright.  Among other things, the copyright notice
%% and this notice must be preserved on all copies.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% For debugging:
% (LOAD addr2id)
(off raise)
(on eolinstringok)
(global '(pRIME pRpRIME hALFpRIME cOMPOSIT!* mpfeRROR aRGUMENTS
	  &*askstrong &*newnumber primlist
	   firstprimroot expvect logvect oUTfILE))
%%(SETQ Arguments (GETUNIXARGS))
%(SETQ Prime (GETV UNIXARGS* 1))
(progn
(setq pRIME $1)
(setq pRpRIME (sub1 pRIME))
(setq hALFpRIME (quotient pRIME 2))
%(SETQ Composit!* (GETV UNIXARGS* 2))
(setq cOMPOSIT!* $2)
%(SETQ MPFError!* (GETV UNIXARGS* 3))
(setq mpfeRROR!* $3)
% (SETQ PrimeFilePreAmble "/usr/local/matte/bergman/domains/P")
% (SETQ PrimeFilePreAmble $4)
(load "$5")
(dskin "$bmdomains/PRL")
(setq pl (penultima primlist))
(cond ((eq (decide1 pRIME) 'composite)
       (exit-with-status cOMPOSITE!*)))
% (SETQ OutFile (APPENDNUMBERTOSTRING Prime PrimeFilePreAmble))
(setq oUTfILE "$4")

% Doing the job

(setq firstprimroot (fIRSTpRIMITIVErOOT))
(setq expvect (mkvect (times2 2 pRIME)))
(setq logvect (mkvect (times2 2 pRIME)))
(mAKEexp!&logvectS (times2 2 pRIME))

% For debugging:
% EXPVECT LOGVECT INTERPBACKTRACE

% Saving the result on OutFile

(wrs (open oUTfILE 'output))
(prin2 "% Preparation file for modulus calculation,
% with the prime modulus ")
(print pRIME)
(prin2 "% The exponents and logarithms are calculated
% with the base ") (print firstprimroot)
(terpri)


(writevectprog 'expvect (times2 pRpRIME 2))
(terpri)
(terpri)

(writevectprog 'logvect (times2 pRpRIME 2))
(terpri)

(close (wrs nil))

(prin2 "* Now the file $4 should exist") (terpri)
)
(exit-with-status 0)
%EOP
