Comments
Patch
@@ -15,3 +15,29 @@
return (val << 16) | (val >> 16);
}
+/*
+ * Prepare the command for sending process.
+ * */
+char *cmd_prepare(char *const command[], int *cmd_size)
+{
+ size_t cmd_length = 0;
+ char *new_cmd;
+ int i = 0;
+
+ while(command[i]){
+ cmd_length += strlen(command[i]) + 1;
+ ++i;
+ }
+
+ new_cmd = malloc(cmd_length + 1);
+ i = 0;
+ while(command[i]){
+ strcpy(new_cmd, command[i]);
+ new_cmd += strlen(command[i]) + 1;
+ ++i;
+ }
+ new_cmd -= cmd_length;
+
+ *cmd_size = cmd_length - 1;
+ return new_cmd;
+}
@@ -10,4 +10,23 @@
* */
uint32_t swap_uint32( uint32_t val );
+/**
+ * \brief Prepare the command for sending process.
+ *
+ * Replace all the blank space with the '\0' character.
+ * \param command an array that will contain the mercurial command
+ * \param cmd_size - array size
+ * \retval string representing the command that will be send to cmdsrv
+ * \retval *cmd_size will be set on string size
+ *
+ * \code
+ * char *command[] = {"tip", "-p", NULL};
+ * char *cmd_str = cmd_prepare(command, 0);
+ * prinf("==%s==", cmd_str);
+ * ---> ==tip\0-p==
+ * \endcode
+ * */
+char *cmd_prepare(char *const command[], int *cmd_size);
+
+
#endif