xref: /csrg-svn/old/lib2648/setmat.c (revision 18785)
111493Sralph /*
2*18785Sdist  * Copyright (c) 1980 Regents of the University of California.
3*18785Sdist  * All rights reserved.  The Berkeley software License Agreement
4*18785Sdist  * specifies the terms and conditions for redistribution.
5*18785Sdist  */
6*18785Sdist 
7*18785Sdist #ifndef lint
8*18785Sdist static char sccsid[] = "@(#)setmat.c	5.1 (Berkeley) 04/26/85";
9*18785Sdist #endif not lint
10*18785Sdist 
11*18785Sdist /*
1211493Sralph  * setmat: set the value in m[r, c] to nval.
1311493Sralph  */
1411493Sralph 
1511493Sralph #include "bit.h"
1611493Sralph 
setmat(m,rows,cols,r,c,nval)1711493Sralph setmat(m, rows, cols, r, c, nval)
1811493Sralph bitmat m;
1911493Sralph int rows, cols, r, c, nval;
2011493Sralph {
2111493Sralph 	register int offset, thisbit;
2211493Sralph 
2311493Sralph 	if (r<0 || c<0 || r>=rows || c>=cols) {
2411493Sralph #ifdef TRACE
2511493Sralph 		if (trace)
2611493Sralph 			fprintf(trace, "setmat range error: (%d, %d) <- %d in a (%d, %d) matrix %x\n", r, c, nval, rows, cols, m);
2711493Sralph #endif
2811493Sralph 
2911493Sralph 		return;
3011493Sralph 	}
3111493Sralph 	offset = r*((cols+7)>>3) + (c>>3);
3211493Sralph 	thisbit = 0x80 >> (c&7);
3311493Sralph 	if (nval)
3411493Sralph 		m[offset] |= thisbit;
3511493Sralph 	else
3611493Sralph 		m[offset] &= ~thisbit;
3711493Sralph }
38