-
Notifications
You must be signed in to change notification settings - Fork 0
/
itemcopy.c
51 lines (46 loc) · 1.09 KB
/
itemcopy.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "functions.h"
#include "mem.h"
#include "types.h"
#include "constant.h"
struct item item_copy (item)
struct item item;
{
struct item result;
int i,j;
if (item.datatype == SCALAR) {
result = item;
}
else if (item.datatype == MATRIX) {
result.data.mat.rows = item.data.mat.rows;
result.data.mat.cols = item.data.mat.cols;
result.data.mat.m = array (result.data.mat.rows,
result.data.mat.cols);
result.datatype = MATRIX;
for (i=0; i<result.data.mat.rows; i++)
for (j=0; j<result.data.mat.cols; j++)
result.data.mat.m[i][j] = item.data.mat.m[i][j];
}
else if (item.datatype == NAME) {
result = item;
result.data.p = MALLOC (strlen(item.data.p)+1, char);
strcpy (result.data.p, item.data.p);
}
else {
printf ("Internal error in item_copy\n");
exit (1);
}
return (result);
}
void del_item (item)
struct item item;
{
if (item.datatype == MATRIX) {
free_array (item.data.mat.m);
}
else if (item.datatype == NAME) {
free(item.data.p);
}
}