Annotation of capa/capa51/pProj/capaMapExpr.c, revision 1.2
1.2 ! albertel 1: /* definition of the /MAP and /RMAP commands
! 2: Copyright (C) 1992-2000 Michigan State University
! 3:
! 4: The CAPA system is free software; you can redistribute it and/or
! 5: modify it under the terms of the GNU Library General Public License as
! 6: published by the Free Software Foundation; either version 2 of the
! 7: License, or (at your option) any later version.
! 8:
! 9: The CAPA system is distributed in the hope that it will be useful,
! 10: but WITHOUT ANY WARRANTY; without even the implied warranty of
! 11: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
! 12: Library General Public License for more details.
! 13:
! 14: You should have received a copy of the GNU Library General Public
! 15: License along with the CAPA system; see the file COPYING. If not,
! 16: write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
! 17: Boston, MA 02111-1307, USA. */
! 18:
1.1 albertel 19: /* ========================================================================== */
20: /* capaMapExpr.c created by Isaac Tsai */
21: /* */
22: /* this is the main code to handle /MAP() function call in capa */
23: #include <stdio.h>
24: #include <string.h>
25: #include <math.h>
26:
27: #include "capaParser.h"
28: #include "capaToken.h"
29: #include "ranlib.h"
30:
31:
32:
33: /* |>|===============================================================|<| */
34: int
35: do_map(seed, varp, argp, argc, dir)
36: char *seed; ArgNode_t *varp; ArgNode_t *argp; int argc; int dir;
37: {
38: long orig_gen, current_gen, seed1, seed2;
39: long *idx_array, *ridx_array;
40: int idx, val;
41: Symbol val_array[ONE_K];
42: ArgNode_t *tmpArgp;
43:
44:
45: for(idx=0,tmpArgp=argp;idx<argc;idx++) {
46: switch( FIRST_ARGTYPE(tmpArgp) ) {
47: case I_VAR:
48: case I_CONSTANT:
49: (val_array[idx]).s_type = I_VAR;
50: (val_array[idx]).s_int = FIRST_ARGINT(tmpArgp); break;
51: case R_VAR:
52: case R_CONSTANT:
53: (val_array[idx]).s_type = R_VAR;
54: (val_array[idx]).s_real = FIRST_ARGREAL(tmpArgp); break;
55: case S_VAR:
56: case S_CONSTANT:
57: (val_array[idx]).s_type = S_VAR;
58: (val_array[idx]).s_str = strsave(FIRST_ARGSTR(tmpArgp)); break;
59: default:
60: return -1;
61: break;
62: }
63: tmpArgp = (tmpArgp->a_next);
64: }
65: idx_array = (long *)capa_malloc(sizeof(long), argc);
66: for(idx=0;idx<argc;idx++) idx_array[idx] = idx;
67: gscgn(GET_GENERATOR, &orig_gen);
68: current_gen = PERMUTATION_G;
69: gscgn(SET_GENERATOR, ¤t_gen);
70: phrtsd(seed, &seed1, &seed2);
71: setsd(seed1, seed2);
72: genprm(idx_array, (long)argc);
73: if(dir == REVERSE_MAP) {
74: ridx_array = (long *)capa_malloc(sizeof(long), argc);
75: for(idx=0;idx<argc;idx++) {
76: ridx_array[ idx_array[idx] ] = idx;
77: }
78: for(idx=0;idx<argc;idx++) {
79: idx_array[idx] = ridx_array[idx];
80: }
81: capa_mfree((char *)ridx_array);
82: }
83: for(idx=0,tmpArgp=varp;idx<argc;idx++) {
84: val = idx_array[idx];
85: switch( FIRST_ARGTYPE(tmpArgp) ) {
86: case IDENTIFIER:
87: case I_VAR: case I_CONSTANT:
88: case R_VAR: case R_CONSTANT: break;
89: case S_VAR: case S_CONSTANT: capa_mfree((char *)FIRST_ARGSTR(tmpArgp)); break;
90: }
91: FIRST_ARGTYPE(tmpArgp) = (val_array[val]).s_type;
92:
93: switch( val_array[val].s_type ) {
94: case I_VAR: FIRST_ARGINT(tmpArgp) = (val_array[val]).s_int; break;
95: case R_VAR: FIRST_ARGREAL(tmpArgp) = (val_array[val]).s_real; break;
96: case S_VAR: FIRST_ARGSTR(tmpArgp) = (val_array[val]).s_str; break;
97: }
98: tmpArgp = tmpArgp->a_next;
99: }
100: gscgn(SET_GENERATOR, &orig_gen);
101: capa_mfree((char *)idx_array);
102: return (0);
103: }
104:
105:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>