char *exec(ListeString *listeArg, Commande *commande, Niveau *niveau){ int nbArgument = nbArg(commande); int fd[2]; pipe(fd); int status; pid_t pid = fork(); commande->pid = pid; child_pid = commande->pid; if (pid == -1) { wprintw(stdscr, "Erreur fork\n"); exit(EXIT_FAILURE); } if(pid == 0) { if (nbArgument == 0) { close(fd[0]); dup2(fd[1], 1); close(fd[1]); strcpy(commande->commande, deleteSpaces(commande->commande)); execlp(commande->commande, commande->commande, NULL); }else{ char **tab = malloc(sizeof(char)*TAILLE_MAX_COMMANDE*nbArgument); creeTabArgs(tab, listeArg, nbArgument); close(fd[0]); dup2(fd[1], 1); close(fd[1]); strcpy(tab[0], deleteSpaces(tab[0])); execvp(tab[0], tab); free(tab); } exit(0); }else { waitpid(pid, &status, WCONTINUED); if (WIFEXITED(status)) { commande->pid = getpid(); char *sortie = malloc(sizeof(char)*TAILLE_MAX_COMMANDE*200); read(fd[0], sortie, TAILLE_MAX_COMMANDE*200); // fprintf(stderr, "verification : %s\n", niveau->nom); verification(sortie, &(*niveau), commande); return sortie; } else return NULL; } }
void CTagCn::nodeIsReal(const CNode& node, CTreeNode& tree_node)const { nodeIsReal(node); size_t pos = 0; string num = deleteSpaces(node.text().as_string()); double d = stod(num, &pos); tree_node.value = d; }
//check node value is float void CTagCn::nodeIsReal(const CNode& node)const { size_t pos = 0; string num = deleteSpaces(node.text().as_string()); double d = stod(num, &pos); if (pos != num.length() || !num.length()) throwException(node, node.offset_debug(), INCORRECT_VALUE); }
/* * Corrects the entry of negative numbers. * Function translate expression like '(-x)' to '(0-x)'. * * @param str - string which need to fix. * @result str - fixed string. */ string fixNegativeVariables (string str) { for (int i=0; i < (int) str.size(); i++) { if (str.at(i) == '(') { if (str.at(i+1) == '-') { str = str.substr(0, i) + "(0" + str.substr(i+1, str.size()); str = deleteSpaces(str); i=0; } } } return str; }
/* * Fix the equation string. * Removes white space. * Fix repetitive characters. * Corrects the entry of negative numbers. * * @param str - string which need to fix. * @result string - fixed string. */ string fixEquation(string str) { return fixNegativeVariables(fixRepeteSigns(deleteSpaces(str))); }