Metropoli BBS
VIEWER: indexma.c MODE: TEXT (ASCII)
/*Copyright (C) 1992, 1994 by Thomas Glen Smith.  All Rights Reserved.*/
/* indexma APL2 V1.0.0 *************************************************
* Called from indexm to determine the output dimensions.               *
***********************************************************************/
#define INCLUDES APLCB+APLMEM+INDEXMI
#include "includes.h"
Aplcb indexma(p)
struct ix *p;
{
	Cat; Errstop; Getcb; Indxsub; Integer; Iscalar; Shape;
     extern int aplerr, indxorg;
	Aplcb dimcb,*s,t,u;
	int i,*ip,j,k,leftrank,*op,tempsave;

	dimcb = getcb(NULL,0,APLINT+APLTEMP,1,NULL);
	s = (p->x)->aplptr.aplapl;
	leftrank = (p->l)->aplrank;
	ip = (p->l)->apldim + leftrank - 1; /* addr(lowest dimension) */
	op = leftrank - 1 + (p->z = malloc(sizeof(int) * leftrank));
	k = 1; /* factor for lowest dimension */
	for (i=0; i < leftrank; i++) {
		*op-- = k; /* set factor */
		k *= *ip--; /* next factor */
		if (NULL == (t = *s)) {
			u = iscalar(j = *((p->l)->apldim + i));
			*s = indxsub(j);
		}
		else {
			if (!(t->aplflags & APLINT)) {
				*s = t = integer(t);
				if (aplerr)
					return(errstop(0,NULL,NULL,dimcb));
			}
			if (tempsave = t->aplflags & APLTEMP)
				t->aplflags -= APLTEMP;
			u = shape(t);
			t->aplflags += tempsave;
		}
		dimcb = cat(dimcb,u,indxorg);
		s++;
	}
	return(dimcb);
}
[ RETURN TO DIRECTORY ]