62 strcpy(node->name, name);
63 node->len = strlen(node->data);
66 head->tail->next = node;
76 if (node == 0)
return;
101 if (!(array_buf = malloc(
MAXARRAY)))
110 int len = strlen(element);
111 if ((len + node->index + 1) >=
MAXARRAY)
114 strcpy(node->data + node->index, element);
116 node->data[node->index++] =
'\r';
117 node->data[node->index] = 0;
118 node->len = node->index;
141 sprintf(command,
"DA %s[]", node->name);
146 sprintf(command,
"DM %s[%i]", node->name, node->elements);
160 if (head->count == 0)
165 size_t bytes_written;
167 int data_left = head->count;
170 if (!(file = fopen(file_path,
"wb")))
176 bytes = strlen(node->name);
177 bytes_written = fwrite(node->name, 1, bytes, file);
180 if (colcount != head->count)
182 bytes_written += fwrite(
",", 1, 1, file);
187 bytes_written += fwrite(
"\r", 1, 1, file);
191 if (bytes_written != bytes)
209 if (node->index != node->len)
211 while ((node->data[node->index] !=
'\r')
212 && (node->index < node->len))
214 if (node->data[node->index] !=
' ')
216 bytes_written += fwrite(node->data + node->index, 1, 1, file);
222 if (node->index == node->len)
229 if (colcount != head->count)
231 bytes_written += fwrite(
",", 1, 1, file);
236 bytes_written += fwrite(
"\r", 1, 1, file);
241 if (bytes_written != bytes)
272 if (!(file = fopen(file_path,
"rb")))
278 while (fread(&c, 1, 1, file))
280 if ((c ==
',') || (c ==
'\r'))
301 while (fread(&c, 1, 1, file))
303 if ((c ==
',') || (c ==
'\r'))
312 if (node == 0) node = &head;
336 char array_names[1024];
350 bytes = strlen(strcpy(array_names, names));
354 if ((rc =
GCmdT(g,
"LA", array_names,
sizeof(array_names), 0)) !=
G_NO_ERROR)
357 bytes = strlen(array_names);
361 for (i = 0; i < bytes; i++)
368 if ((c !=
' ') && (c !=
'\r') && (c !=
'\n') && !bracket)
370 name[n++] = array_names[i];
374 if ((c ==
' ') || (c ==
'\r') || (i == bytes - 1))
Structure to create a linked list for array data.
GReturn H_AddArray(ArrayNode *head, char *name, char *data)
Add an ArrayData node to the linked list.
GCLIB_DLL_EXPORTED GReturn GCALL GCmdT(GCon g, GCStringIn command, GCStringOut trimmed_response, GSize response_len, GCStringOut *front)
Wrapper around GCommand that trims the response.
void H_InitArrayNode(ArrayNode *node)
Function to initialize the memory of a new node.
GCLIB_DLL_EXPORTED GReturn GCALL GArrayUpload(GCon g, const GCStringIn array_name, GOption first, GOption last, GOption delim, GBufOut buffer, GSize buffer_len)
Uploads array data from the controller's array table.
#define MAXARRAY
Maximum size for an array table upload.
GReturn H_UploadArrayToList(GCon g, ArrayNode *head, char *name)
Uplaods a particular array and adds it to the linked list.
void * GCon
Connection handle. Unique for each connection in process. Assigned a non-zero value in GOpen()...
void H_FreeArrays(ArrayNode *node)
Frees all memory downsteam of node. After passing list head to this function, all memory is freed and...
GCLIB_DLL_EXPORTED GReturn GCALL GArrayDownload(GCon g, const GCStringIn array_name, GOption first, GOption last, GCStringIn buffer)
Downloads array data to a pre-dimensioned array in the controller's array table.
int GReturn
Every function returns a value of type GReturn. See gclib_errors.h for possible values.
#define G_BAD_FULL_MEMORY
Not enough memory for an operation, e.g. all connections allowed for a process already taken...
const char * GCStringIn
C-string input to the library. Implies null-termination.
GReturn H_ArrayAddElement(ArrayNode *node, GCStringIn element)
Adds an array element to an array node.
#define G_BOUNDS
For functions that take range options, e.g. GArrayUpload(), use this value for full range...
#define G_NO_ERROR
Return value if function succeeded.
GReturn GCALL GArrayDownloadFile(GCon g, GCStringIn file_path)
Array download from file.
GReturn H_CreateArrayNode(ArrayNode *head, char *name)
Creates a buffer on the heap to write data, and adds it to the linked list.
GReturn GCALL GArrayUploadFile(GCon g, GCStringIn file_path, GCStringIn names)
Array upload to file.
GReturn H_WriteArrayCsv(ArrayNode *head, GCStringIn file_path)
After filling the array list, this function is called to write out the CSV.
GReturn H_DownloadArraysFromList(GCon g, ArrayNode *head)
Walks through the array linked list, downloading each.
#define GCALL
Specify calling convention for Windows.
GCLIB_DLL_EXPORTED GReturn GCALL GCmd(GCon g, GCStringIn command)
Wrapper around GCommand for use when the return value is not desired.
#define G_BAD_FILE
Bad file path, bad file contents, or bad write.
#define G_CR
For GArrayUpload(), use this value in the delim field to delimit with carriage returns.