/* man_filename is of the form "/dir/dir/dir/name.s" Z_SUFFIX */ static int show_manpage(const char *pager, char *man_filename, int man, int level) { #if ENABLE_FEATURE_SEAMLESS_LZMA if (run_pipe(pager, man_filename, man, level)) return 1; #endif #if ENABLE_FEATURE_SEAMLESS_BZ2 #if ENABLE_FEATURE_SEAMLESS_LZMA strcpy(strrchr(man_filename, '.') + 1, "bz2"); #endif if (run_pipe(pager, man_filename, man, level)) return 1; #endif #if ENABLE_FEATURE_SEAMLESS_GZ #if ENABLE_FEATURE_SEAMLESS_LZMA || ENABLE_FEATURE_SEAMLESS_BZ2 strcpy(strrchr(man_filename, '.') + 1, "gz"); #endif if (run_pipe(pager, man_filename, man, level)) return 1; #endif #if ENABLE_FEATURE_SEAMLESS_LZMA || ENABLE_FEATURE_SEAMLESS_BZ2 || ENABLE_FEATURE_SEAMLESS_GZ *strrchr(man_filename, '.') = '\0'; #endif if (run_pipe(pager, man_filename, man, level)) return 1; return 0; }
/* man_filename is of the form "/dir/dir/dir/name.s" */ static int show_manpage(const char *pager, char *man_filename, int man, int level) { #if SEAMLESS_COMPRESSION /* We leak this allocation... */ char *filename_with_zext = xasprintf("%s.lzma", man_filename); char *ext = strrchr(filename_with_zext, '.') + 1; #endif #if ENABLE_FEATURE_SEAMLESS_LZMA if (run_pipe(pager, filename_with_zext, man, level)) return 1; #endif #if ENABLE_FEATURE_SEAMLESS_XZ strcpy(ext, "xz"); if (run_pipe(pager, filename_with_zext, man, level)) return 1; #endif #if ENABLE_FEATURE_SEAMLESS_BZ2 strcpy(ext, "bz2"); if (run_pipe(pager, filename_with_zext, man, level)) return 1; #endif #if ENABLE_FEATURE_SEAMLESS_GZ strcpy(ext, "gz"); if (run_pipe(pager, filename_with_zext, man, level)) return 1; #endif return run_pipe(pager, man_filename, man, level); }
int run_pipe(command_t **comandos, int num_args, int num_args0) //pipeline { int pd[2]; int pid; if(pipe(pd) < 0){ perror("pipe"); exit(1); }else{ pid = fork(); if (pid < 0) { //erro perror("fork"); exit(1); }else if (pid > 0){ //processo pai - roda o comando close(1); dup2(pd[1], 1); close(pd[1]); close(pd[0]); if(num_args != 0) run_pipe(comandos,num_args-1, num_args0); else return 0; }else{ //processo filho - continua o pipeline close(0); dup2(pd[0], 0); close(pd[0]); close(pd[1]); executa_comando(comandos[num_args0-num_args]); } } }