SDDS ToolKit Programs and Libraries for C and Python
All Classes Files Functions Variables Macros Pages
pvMultList.h File Reference

Detailed Description

Helper Functions used by cavget and cavput.

This file contains routines for creating PV (Process Variable) names through multiplication of string lists or numeric ranges.

License
This file is distributed under the terms of the Software License Agreement found in the file LICENSE included with this distribution.
Authors
  • M. Borland
  • R. Soliday
  • H. Shang

Definition in file pvMultList.h.

Go to the source code of this file.

Functions

void multiplyWithList (PV_VALUE **PVvalue, long *PVvalues, TERM_LIST *List, long listEntries)
 
void multiplyWithRange (PV_VALUE **PVvalue, long *PVvalues, long begin, long end, long interval, char *format)
 

Function Documentation

◆ multiplyWithList()

void multiplyWithList ( PV_VALUE ** PVvalue,
long * PVvalues,
TERM_LIST * List,
long listEntries )

Definition at line 27 of file pvMultList.c.

27 {
28 long newPVvalues, i, j, k;
29 PV_VALUE *newPVvalue;
30
31 if (!*PVvalues) {
32 *PVvalues = listEntries;
33 *PVvalue = tmalloc(sizeof(**PVvalue) * listEntries);
34 for (i = 0; i < listEntries; i++) {
35 SDDS_CopyString(&(*PVvalue)[i].name, List[i].string);
36 if (List[i].flags & VALUE_GIVEN)
37 SDDS_CopyString(&(*PVvalue)[i].value, List[i].value);
38 else
39 (*PVvalue)[i].value = 0;
40 }
41 } else {
42 newPVvalues = *PVvalues * listEntries;
43 newPVvalue = tmalloc(sizeof(*newPVvalue) * (newPVvalues));
44 for (i = k = 0; i < *PVvalues; i++) {
45 for (j = 0; j < listEntries; j++, k++) {
46 newPVvalue[k].name = tmalloc(sizeof(*newPVvalue[k].name) *
47 (strlen(List[j].string) + strlen((*PVvalue)[i].name) + 1));
48 strcpy(newPVvalue[k].name, (*PVvalue)[i].name);
49 strcat(newPVvalue[k].name, List[j].string);
50 if (List[j].flags & VALUE_GIVEN)
51 SDDS_CopyString(&newPVvalue[k].value, List[j].value);
52 else
53 SDDS_CopyString(&newPVvalue[k].value, (*PVvalue)[i].value);
54 }
55 }
56 for (i = 0; i < *PVvalues; i++) {
57 free((*PVvalue)[i].name);
58 if ((*PVvalue)[i].value)
59 free((*PVvalue)[i].value);
60 }
61 free(*PVvalue);
62 *PVvalue = newPVvalue;
63 *PVvalues = newPVvalues;
64 }
65}
int32_t SDDS_CopyString(char **target, const char *source)
Copies a source string to a target string with memory allocation.
Definition SDDS_utils.c:856
void * tmalloc(uint64_t size_of_block)
Allocates a memory block of the specified size with zero initialization.
Definition array.c:59

◆ multiplyWithRange()

void multiplyWithRange ( PV_VALUE ** PVvalue,
long * PVvalues,
long begin,
long end,
long interval,
char * format )

Definition at line 67 of file pvMultList.c.

67 {
68 long newPVvalues, value, i, j, k;
69 PV_VALUE *newPVvalue;
70 char buffer[256];
71
72 if (!*PVvalues) {
73 *PVvalue = tmalloc(sizeof(**PVvalue) * (end - begin + 1));
74 for (value = begin, j = k = 0; value <= end; value++, j++) {
75 if (j % interval)
76 continue;
77 sprintf(buffer, format, value);
78 SDDS_CopyString(&(*PVvalue)[k].name, buffer);
79 (*PVvalue)[k].value = 0;
80 k++;
81 }
82 *PVvalues = k;
83 } else {
84 newPVvalue = tmalloc(sizeof(*newPVvalue) * (*PVvalues * (end - begin + 1)));
85 newPVvalues = 0;
86 for (i = k = 0; i < *PVvalues; i++) {
87 for (value = begin, j = 0; value <= end; value++, j++) {
88 if (j % interval)
89 continue;
90 sprintf(buffer, format, value);
91 newPVvalue[k].name = tmalloc(sizeof(*newPVvalue[k].name) *
92 (strlen(buffer) + strlen((*PVvalue)[i].name) + 1));
93 strcpy(newPVvalue[k].name, (*PVvalue)[i].name);
94 strcat(newPVvalue[k].name, buffer);
95 newPVvalue[k].value = (*PVvalue)[i].value;
96 k++;
97 }
98 }
99 newPVvalues = k;
100 for (i = 0; i < *PVvalues; i++) {
101 free((*PVvalue)[i].name);
102 /* if ((*PVvalue)[i].value) free((*PVvalue)[i].value); */
103 }
104 free(*PVvalue);
105 *PVvalue = newPVvalue;
106 *PVvalues = newPVvalues;
107 }
108}