int cp (int argc, char *argv[]) { Stat_s a; Stat_s b; a = t_get_stats(TreeA); b = t_get_stats(TreeB); if (memcmp( &a, &b, sizeof(a)) != 0) { printf("We have a problem Huston.\n"); stp(argc, argv); } return t_compare(TreeA, TreeB); }
/**The comparison function used with scandir * *This function checks which flags are active to deside how to compare. *It utilises the strcasecmp function *to check whether the first string is less than, equal to, *or greater than the second string, and will return -1, 0, or 1 *repectively. *@param[in] entry1 the first entry to be compared *@param[in] entry2 the second entry to be compared *@return an integer -1, 0, or 1 if the first string was less *than, equal to or greater than the second. */ int compare(const struct dirent** entry1, const struct dirent** entry2) { //sort by time if(t_flag) { return t_compare(entry1, entry2); } //sort by size in bytes if(S_flag) { return S_compare(entry1, entry2); } //otherwise sort alphabetically (ascending) if(!r_flag) return strcasecmp((*entry1)->d_name,(*entry2)->d_name); //descending return strcasecmp((*entry2)->d_name,(*entry1)->d_name); }
/* Return data type after OPERAND operator OPERAND */ int type_after_operation(const int *operator_type, const TVariable *var_1, const TVariable *var_2) { /* String XOR String */ if (t_compare(var_1, TYPE_STRING) ^ t_compare(var_2, TYPE_STRING)) { my_exit_error(E_SEMANTIC_TYPES, 1); } switch (*operator_type) { case TOKEN_MUL: case TOKEN_DIV: case TOKEN_ADD: case TOKEN_SUB: /* String +/-* String */ if (t_compare(var_1, TYPE_STRING) || t_compare(var_2, TYPE_STRING)) { my_exit_error(E_SEMANTIC_TYPES, 2); } if (t_compare(var_1, TYPE_DOUBLE) || t_compare(var_2, TYPE_DOUBLE)) { return TYPE_DOUBLE; } } return TYPE_INT; }