- returnCommand = *commandPtr + (src - *commandPtr) + 1;
- break;
-
-#ifdef BB_FEATURE_SH_BACKTICKS
- case '`':
- /* Exec a backtick-ed command */
- {
- char* charptr1=NULL, *charptr2;
- char* ptr=NULL;
- struct job *newJob;
- struct jobSet njobList = { NULL, NULL };
- int pipefd[2];
- int size;
-
- ptr=strchr(++src, '`');
- if (ptr==NULL) {
- fprintf(stderr, "Unmatched '`' in command\n");
- freeJob(job);
- return 1;
- }
-
- /* Make some space to hold just the backticked command */
- charptr1 = charptr2 = xmalloc(1+ptr-src);
- memcpy(charptr1, src, ptr-src);
- charptr1[ptr-src] = '\0';
- newJob = xmalloc(sizeof(struct job));
- /* Now parse and run the backticked command */
- if (!parseCommand(&charptr1, newJob, &njobList, inBg)
- && newJob->numProgs) {
- pipe(pipefd);
- runCommand(newJob, &njobList, 0, pipefd);
- }
- checkJobs(jobList);
- freeJob(newJob);
- free(charptr2);
-
- /* Make a copy of any stuff left over in the command
- * line after the second backtick */
- charptr2 = xmalloc(strlen(ptr)+1);
- memcpy(charptr2, ptr+1, strlen(ptr));
-
-
- /* Copy the output from the backtick-ed command into the
- * command line, making extra room as needed */
- --src;
- charptr1 = xmalloc(BUFSIZ);
- while ( (size=fullRead(pipefd[0], charptr1, BUFSIZ-1)) >0) {
- int newSize=src - *commandPtr + size + 1 + strlen(charptr2);
- if (newSize > BUFSIZ) {
- *commandPtr=xrealloc(*commandPtr, src - *commandPtr +
- size + 1 + strlen(charptr2));
- }
- memcpy(src, charptr1, size);
- src+=size;
- }
- free(charptr1);
- close(pipefd[0]);
- if (*(src-1)=='\n')
- --src;
-
- /* Now paste into the *commandPtr all the stuff
- * leftover after the second backtick */
- memcpy(src, charptr2, strlen(charptr2)+1);
- free(charptr2);
-
- /* Now recursively call parseCommand to deal with the new
- * and improved version of the command line with the backtick
- * results expanded in place... */
- freeJob(job);
- return(parseCommand(commandPtr, job, jobList, inBg));
- }