65 strcpy(node->name, name);
66 node->len = strlen(node->data);
69 head->tail->next = node;
79 if (node == 0)
return;
104 if (!(array_buf = malloc(
MAXARRAY)))
113 int len = strlen(element);
114 if ((len + node->index + 1) >=
MAXARRAY)
117 strcpy(node->data + node->index, element);
119 node->data[node->index++] =
'\r';
120 node->data[node->index] = 0;
121 node->len = node->index;
143 sprintf(command,
"DA %s[]", node->name);
148 sprintf(command,
"DM %s[%i]", node->name, node->elements);
163 if (head->count == 0)
168 size_t bytes_written;
170 int data_left = head->count;
173 if (!(file = fopen(file_path,
"wb")))
179 bytes = strlen(node->name);
180 bytes_written = fwrite(node->name, 1, bytes, file);
183 if (colcount != head->count)
185 bytes_written += fwrite(
",", 1, 1, file);
190 bytes_written += fwrite(
"\r", 1, 1, file);
194 if (bytes_written != bytes)
212 if (node->index != node->len)
214 while ((node->data[node->index] !=
'\r')
215 && (node->index < node->len))
217 if (node->data[node->index] !=
' ')
219 bytes_written += fwrite(node->data + node->index, 1, 1, file);
225 if (node->index == node->len)
232 if (colcount != head->count)
234 bytes_written += fwrite(
",", 1, 1, file);
239 bytes_written += fwrite(
"\r", 1, 1, file);
244 if (bytes_written != bytes)
269 char c = array_data[pos];
279 if (c ==
',' || c ==
'\r')
307 if ((c ==
',') || (c ==
'\r'))
316 if (node == 0) node = &head;
344 if (c > 31 && c < 127)
369 for (i = 0; i < arr_size; i++)
371 if ((
int)arr[i] == index)
383 if (!(file = fopen(file_path,
"rb")))
387 fseek(file, 0, SEEK_END);
388 int in_len = ftell(file);
392 char* in_buf = (
char*)malloc(
sizeof(
char) * in_len);
393 fread(in_buf,
sizeof(
char), in_len, file);
411 char array_names[1024];
425 bytes = strlen(strcpy(array_names, names));
429 if ((rc =
GCmdT(g,
"LA", array_names,
sizeof(array_names), 0)) !=
G_NO_ERROR)
432 bytes = strlen(array_names);
436 for (i = 0; i < bytes; i++)
443 if ((c !=
' ') && (c !=
'\r') && (c !=
'\n') && !bracket)
445 name[n++] = array_names[i];
448 if ((c ==
' ') || (c ==
'\r') || (i == bytes - 1))
480 file = fopen(file_path,
"rb");
484 fseek(file, 0, SEEK_END);
485 in_len = ftell(file);
489 unsigned char* in_buf = (
unsigned char*)malloc(
sizeof(
unsigned char) * in_len);
490 fread(in_buf,
sizeof(
unsigned char), in_len, file);
495 uLong out_len = (
unsigned int)((in_buf[0] << 24) | (in_buf[1] << 16) | (in_buf[2] << 8) | (in_buf[3]));
496 unsigned char* out_buf = (
unsigned char*)malloc(
sizeof(
unsigned char) * out_len);
499 rc = uncompress(out_buf, &out_len, in_buf + 4, in_len - 4);
508 if (info != NULL && info_len > 0) {
516 for (i = 0; i < info_len; i++)
522 else if (i == (info_len - 1))
532 for (i = 1; i < 7; i++)
534 if (i == 1 || i == 3)
542 rc += (1 << (i - 1));
548 if (options & 0x8000)
554 int len = out_len - 1;
555 for (i = 0; i < len; i++)
557 sector = (
char*)out_buf + i + 1;
567 if (options & 0x0002)
573 if (options & 0x0008)
579 if (options & 0x0010)
585 if (options & 0x0020)
int GOption
Option integer for various formatting, etc.
GReturn H_DownloadArraysFromList(GCon g, ArrayNode *head, int fail)
Walks through the array linked list, downloading each.
GReturn GCALL GSetupDownloadFile(GCon g, GCStringIn file_path, GOption options, GCStringOut info, GSize info_len)
Download a saved controller configuration from a file.
unsigned int GSize
Size of buffers, etc.
Structure to create a linked list for array data.
GReturn H_DownloadData(GCon g, const char *data, int fail)
Helper function to send a string of commands to the controller, one at at time.
#define G_BAD_RESPONSE_QUESTION_MARK
Operation received a ?, indicating controller has a TC error.
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)
Uploads 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 downstream of node. After passing list head to this function, all memory is freed an...
GCLIB_DLL_EXPORTED GReturn GCALL GProgramDownload(GCon g, GCStringIn program, GCStringIn preprocessor)
Downloads a program to the controller's program buffer.
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.
GReturn H_ArrayDownloadFromMemory(GCon g, const char *array_data, int fail)
Helper function to download a block of arrays to the controller.
int GReturn
Every function returns a value of type GReturn. See gclib_errors.h for possible values.
char * H_FindSector(char *arr, int arr_size, int index)
Function that returns a pointer to the start of the specified sector in the GCB data.
#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.
char * GCStringOut
C-string output from the library. Implies null-termination.
#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.