8 #define _CRT_SECURE_NO_WARNINGS //use traditional C calls like strncpy()
63 strcpy(node->name, name);
64 node->len = strlen(node->data);
67 head->tail->next = node;
77 if (node == 0)
return;
102 if (!(array_buf = malloc(
MAXARRAY)))
111 int len = strlen(element);
112 if ((len + node->index + 1) >=
MAXARRAY)
115 strcpy(node->data + node->index, element);
117 node->data[node->index++] =
'\r';
118 node->data[node->index] = 0;
119 node->len = node->index;
142 sprintf(command,
"DA %s[]", node->name);
147 sprintf(command,
"DM %s[%i]", node->name, node->elements);
161 if (head->count == 0)
166 size_t bytes_written;
168 int data_left = head->count;
171 if (!(file = fopen(file_path,
"wb")))
177 bytes = strlen(node->name);
178 bytes_written = fwrite(node->name, 1, bytes, file);
181 if (colcount != head->count)
183 bytes_written += fwrite(
",", 1, 1, file);
188 bytes_written += fwrite(
"\r", 1, 1, file);
192 if (bytes_written != bytes)
210 if (node->index != node->len)
212 while ((node->data[node->index] !=
'\r')
213 && (node->index < node->len))
215 if (node->data[node->index] !=
' ')
217 bytes_written += fwrite(node->data + node->index, 1, 1, file);
223 if (node->index == node->len)
230 if (colcount != head->count)
232 bytes_written += fwrite(
",", 1, 1, file);
237 bytes_written += fwrite(
"\r", 1, 1, file);
242 if (bytes_written != bytes)
273 if (!(file = fopen(file_path,
"rb")))
279 while (fread(&c, 1, 1, file))
281 if ((c ==
',') || (c ==
'\r'))
302 while (fread(&c, 1, 1, file))
304 if ((c ==
',') || (c ==
'\r'))
313 if (node == 0) node = &head;
337 char array_names[1024];
351 bytes = strlen(strcpy(array_names, names));
355 if ((rc =
GCmdT(g,
"LA", array_names,
sizeof(array_names), 0)) !=
G_NO_ERROR)
358 bytes = strlen(array_names);
362 for (i = 0; i < bytes; i++)
369 if ((c !=
' ') && (c !=
'\r') && (c !=
'\n') && !bracket)
371 name[n++] = array_names[i];
375 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.