From 96cf67bd29957cfde6c5f15cfec7e370c6dbabe2 Mon Sep 17 00:00:00 2001 From: Paul Smith Date: Fri, 17 May 2013 02:29:46 -0400 Subject: Update source file format: remove TABs, use GNU coding styles. --- function.c | 675 ++++++++++++++++++++++++++++++------------------------------- 1 file changed, 337 insertions(+), 338 deletions(-) (limited to 'function.c') diff --git a/function.c b/function.c index d5ca677..3b9f1de 100644 --- a/function.c +++ b/function.c @@ -87,42 +87,42 @@ subst_expand (char *o, const char *text, const char *subst, const char *replace, /* The first occurrence of "" in any string is its end. */ o = variable_buffer_output (o, t, strlen (t)); if (rlen > 0) - o = variable_buffer_output (o, replace, rlen); + o = variable_buffer_output (o, replace, rlen); return o; } do { if (by_word && slen == 0) - /* When matching by words, the empty string should match - the end of each word, rather than the end of the whole text. */ - p = end_of_token (next_token (t)); + /* When matching by words, the empty string should match + the end of each word, rather than the end of the whole text. */ + p = end_of_token (next_token (t)); else - { - p = strstr (t, subst); - if (p == 0) - { - /* No more matches. Output everything left on the end. */ - o = variable_buffer_output (o, t, strlen (t)); - return o; - } - } + { + p = strstr (t, subst); + if (p == 0) + { + /* No more matches. Output everything left on the end. */ + o = variable_buffer_output (o, t, strlen (t)); + return o; + } + } /* Output everything before this occurrence of the string to replace. */ if (p > t) - o = variable_buffer_output (o, t, p - t); + o = variable_buffer_output (o, t, p - t); /* If we're substituting only by fully matched words, - or only at the ends of words, check that this case qualifies. */ + or only at the ends of words, check that this case qualifies. */ if (by_word && ((p > text && !isblank ((unsigned char)p[-1])) || (p[slen] != '\0' && !isblank ((unsigned char)p[slen])))) - /* Struck out. Output the rest of the string that is - no longer to be replaced. */ - o = variable_buffer_output (o, subst, slen); + /* Struck out. Output the rest of the string that is + no longer to be replaced. */ + o = variable_buffer_output (o, subst, slen); else if (rlen > 0) - /* Output the replacement string. */ - o = variable_buffer_output (o, replace, rlen); + /* Output the replacement string. */ + o = variable_buffer_output (o, replace, rlen); /* Advance T past the string to be replaced. */ t = p + slen; @@ -169,7 +169,7 @@ patsubst_expand_pat (char *o, const char *text, if (!pattern_percent) /* With no % in the pattern, this is just a simple substitution. */ return subst_expand (o, text, pattern, replace, - strlen (pattern), strlen (replace), 1); + strlen (pattern), strlen (replace), 1); /* Record the length of PATTERN before and after the % so we don't have to compute it more than once. */ @@ -182,53 +182,53 @@ patsubst_expand_pat (char *o, const char *text, /* Is it big enough to match? */ if (len < pattern_prepercent_len + pattern_postpercent_len) - fail = 1; + fail = 1; /* Does the prefix match? */ if (!fail && pattern_prepercent_len > 0 - && (*t != *pattern - || t[pattern_prepercent_len - 1] != pattern_percent[-2] - || !strneq (t + 1, pattern + 1, pattern_prepercent_len - 1))) - fail = 1; + && (*t != *pattern + || t[pattern_prepercent_len - 1] != pattern_percent[-2] + || !strneq (t + 1, pattern + 1, pattern_prepercent_len - 1))) + fail = 1; /* Does the suffix match? */ if (!fail && pattern_postpercent_len > 0 - && (t[len - 1] != pattern_percent[pattern_postpercent_len - 1] - || t[len - pattern_postpercent_len] != *pattern_percent - || !strneq (&t[len - pattern_postpercent_len], - pattern_percent, pattern_postpercent_len - 1))) - fail = 1; + && (t[len - 1] != pattern_percent[pattern_postpercent_len - 1] + || t[len - pattern_postpercent_len] != *pattern_percent + || !strneq (&t[len - pattern_postpercent_len], + pattern_percent, pattern_postpercent_len - 1))) + fail = 1; if (fail) - /* It didn't match. Output the string. */ - o = variable_buffer_output (o, t, len); + /* It didn't match. Output the string. */ + o = variable_buffer_output (o, t, len); else - { - /* It matched. Output the replacement. */ - - /* Output the part of the replacement before the %. */ - o = variable_buffer_output (o, replace, replace_prepercent_len); - - if (replace_percent != 0) - { - /* Output the part of the matched string that - matched the % in the pattern. */ - o = variable_buffer_output (o, t + pattern_prepercent_len, - len - (pattern_prepercent_len - + pattern_postpercent_len)); - /* Output the part of the replacement after the %. */ - o = variable_buffer_output (o, replace_percent, - replace_postpercent_len); - } - } + { + /* It matched. Output the replacement. */ + + /* Output the part of the replacement before the %. */ + o = variable_buffer_output (o, replace, replace_prepercent_len); + + if (replace_percent != 0) + { + /* Output the part of the matched string that + matched the % in the pattern. */ + o = variable_buffer_output (o, t + pattern_prepercent_len, + len - (pattern_prepercent_len + + pattern_postpercent_len)); + /* Output the part of the replacement after the %. */ + o = variable_buffer_output (o, replace_percent, + replace_postpercent_len); + } + } /* Output a space, but not if the replacement is "". */ if (fail || replace_prepercent_len > 0 - || (replace_percent != 0 && len + replace_postpercent_len > 0)) - { - o = variable_buffer_output (o, " ", 1); - doneany = 1; - } + || (replace_percent != 0 && len + replace_postpercent_len > 0)) + { + o = variable_buffer_output (o, " ", 1); + doneany = 1; + } } if (doneany) /* Kill the last space. */ @@ -299,7 +299,7 @@ pattern_matches (const char *pattern, const char *percent, const char *str) memcpy (new_chars, pattern, len); percent = find_percent (new_chars); if (percent == 0) - return streq (new_chars, str); + return streq (new_chars, str); pattern = new_chars; } @@ -333,9 +333,9 @@ find_next_argument (char startparen, char endparen, else if (*ptr == endparen) { - --count; - if (count < 0) - return NULL; + --count; + if (count < 0) + return NULL; } else if (*ptr == ',' && !count) @@ -430,17 +430,17 @@ func_join (char *o, char **argv, const char *funcname UNUSED) tp = find_next_token (&list1_iterator, &len1); if (tp != 0) - o = variable_buffer_output (o, tp, len1); + o = variable_buffer_output (o, tp, len1); pp = find_next_token (&list2_iterator, &len2); if (pp != 0) - o = variable_buffer_output (o, pp, len2); + o = variable_buffer_output (o, pp, len2); if (tp != 0 || pp != 0) - { - o = variable_buffer_output (o, " ", 1); - doneany = 1; - } + { + o = variable_buffer_output (o, " ", 1); + doneany = 1; + } } while (tp != 0 || pp != 0); if (doneany) @@ -463,29 +463,29 @@ func_origin (char *o, char **argv, const char *funcname UNUSED) { default: case o_invalid: - abort (); - break; + abort (); + break; case o_default: - o = variable_buffer_output (o, "default", 7); - break; + o = variable_buffer_output (o, "default", 7); + break; case o_env: - o = variable_buffer_output (o, "environment", 11); - break; + o = variable_buffer_output (o, "environment", 11); + break; case o_file: - o = variable_buffer_output (o, "file", 4); - break; + o = variable_buffer_output (o, "file", 4); + break; case o_env_override: - o = variable_buffer_output (o, "environment override", 20); - break; + o = variable_buffer_output (o, "environment override", 20); + break; case o_command: - o = variable_buffer_output (o, "command line", 12); - break; + o = variable_buffer_output (o, "command line", 12); + break; case o_override: - o = variable_buffer_output (o, "override", 8); - break; + o = variable_buffer_output (o, "override", 8); + break; case o_automatic: - o = variable_buffer_output (o, "automatic", 9); - break; + o = variable_buffer_output (o, "automatic", 9); + break; } return o; @@ -535,36 +535,36 @@ func_notdir_suffix (char *o, char **argv, const char *funcname) while (p >= p2 && (!is_suffix || *p != '.')) - { - if (IS_PATHSEP (*p)) - break; - --p; - } + { + if (IS_PATHSEP (*p)) + break; + --p; + } if (p >= p2) - { - if (is_notdir) - ++p; - else if (*p != '.') - continue; - o = variable_buffer_output (o, p, len - (p - p2)); - } + { + if (is_notdir) + ++p; + else if (*p != '.') + continue; + o = variable_buffer_output (o, p, len - (p - p2)); + } #ifdef HAVE_DOS_PATHS /* Handle the case of "d:foo/bar". */ else if (is_notdir && p2[0] && p2[1] == ':') - { - p = p2 + 2; - o = variable_buffer_output (o, p, len - (p - p2)); - } + { + p = p2 + 2; + o = variable_buffer_output (o, p, len - (p - p2)); + } #endif else if (is_notdir) - o = variable_buffer_output (o, p2, len); + o = variable_buffer_output (o, p2, len); if (is_notdir || p >= p2) - { - o = variable_buffer_output (o, " ", 1); - doneany = 1; - } + { + o = variable_buffer_output (o, " ", 1); + doneany = 1; + } } if (doneany) @@ -646,10 +646,10 @@ func_addsuffix_addprefix (char *o, char **argv, const char *funcname) while ((p = find_next_token (&list_iterator, &len)) != 0) { if (is_addprefix) - o = variable_buffer_output (o, argv[0], fixlen); + o = variable_buffer_output (o, argv[0], fixlen); o = variable_buffer_output (o, p, len); if (is_addsuffix) - o = variable_buffer_output (o, argv[0], fixlen); + o = variable_buffer_output (o, argv[0], fixlen); o = variable_buffer_output (o, " ", 1); doneany = 1; } @@ -665,7 +665,7 @@ static char * func_subst (char *o, char **argv, const char *funcname UNUSED) { o = subst_expand (o, argv[2], argv[0], argv[1], strlen (argv[0]), - strlen (argv[1]), 0); + strlen (argv[1]), 0); return o; } @@ -782,9 +782,9 @@ func_wordlist (char *o, char **argv, const char *funcname UNUSED) /* Check the arguments. */ check_numeric (argv[0], - _("non-numeric first argument to 'wordlist' function")); + _("non-numeric first argument to 'wordlist' function")); check_numeric (argv[1], - _("non-numeric second argument to 'wordlist' function")); + _("non-numeric second argument to 'wordlist' function")); start = atoi (argv[0]); if (start < 1) @@ -898,7 +898,7 @@ a_word_hash_cmp (const void *x, const void *y) if (result) return result; return_STRING_COMPARE (((struct a_word const *) x)->str, - ((struct a_word const *) y)->str); + ((struct a_word const *) y)->str); } struct a_pattern @@ -942,13 +942,13 @@ func_filter_filterout (char *o, char **argv, const char *funcname) pattail = &pat->next; if (*pat_iterator != '\0') - ++pat_iterator; + ++pat_iterator; pat->str = p; p[len] = '\0'; pat->percent = find_percent (p); if (pat->percent == 0) - literals++; + literals++; /* find_percent() might shorten the string so LEN is wrong. */ pat->length = strlen (pat->str); @@ -966,7 +966,7 @@ func_filter_filterout (char *o, char **argv, const char *funcname) wordtail = &word->next; if (*word_iterator != '\0') - ++word_iterator; + ++word_iterator; p[len] = '\0'; word->str = p; @@ -984,11 +984,11 @@ func_filter_filterout (char *o, char **argv, const char *funcname) hash_init (&a_word_table, words, a_word_hash_1, a_word_hash_2, a_word_hash_cmp); for (wp = wordhead; wp != 0; wp = wp->next) - { - struct a_word *owp = hash_insert (&a_word_table, wp); - if (owp) - wp->chain = owp; - } + { + struct a_word *owp = hash_insert (&a_word_table, wp); + if (owp) + wp->chain = owp; + } } if (words) @@ -997,40 +997,40 @@ func_filter_filterout (char *o, char **argv, const char *funcname) /* Run each pattern through the words, killing words. */ for (pp = pathead; pp != 0; pp = pp->next) - { - if (pp->percent) - for (wp = wordhead; wp != 0; wp = wp->next) - wp->matched |= pattern_matches (pp->str, pp->percent, wp->str); - else if (hashing) - { - struct a_word a_word_key; - a_word_key.str = pp->str; - a_word_key.length = pp->length; - wp = hash_find_item (&a_word_table, &a_word_key); - while (wp) - { - wp->matched |= 1; - wp = wp->chain; - } - } - else - for (wp = wordhead; wp != 0; wp = wp->next) - wp->matched |= (wp->length == pp->length - && strneq (pp->str, wp->str, wp->length)); - } + { + if (pp->percent) + for (wp = wordhead; wp != 0; wp = wp->next) + wp->matched |= pattern_matches (pp->str, pp->percent, wp->str); + else if (hashing) + { + struct a_word a_word_key; + a_word_key.str = pp->str; + a_word_key.length = pp->length; + wp = hash_find_item (&a_word_table, &a_word_key); + while (wp) + { + wp->matched |= 1; + wp = wp->chain; + } + } + else + for (wp = wordhead; wp != 0; wp = wp->next) + wp->matched |= (wp->length == pp->length + && strneq (pp->str, wp->str, wp->length)); + } /* Output the words that matched (or didn't, for filter-out). */ for (wp = wordhead; wp != 0; wp = wp->next) - if (is_filter ? wp->matched : !wp->matched) - { - o = variable_buffer_output (o, wp->str, strlen (wp->str)); - o = variable_buffer_output (o, " ", 1); - doneany = 1; - } + if (is_filter ? wp->matched : !wp->matched) + { + o = variable_buffer_output (o, wp->str, strlen (wp->str)); + o = variable_buffer_output (o, " ", 1); + doneany = 1; + } if (doneany) - /* Kill the last space. */ - --o; + /* Kill the last space. */ + --o; } if (hashing) @@ -1052,12 +1052,12 @@ func_strip (char *o, char **argv, const char *funcname UNUSED) const char *word_start; while (isspace ((unsigned char)*p)) - ++p; + ++p; word_start = p; for (i=0; *p != '\0' && !isspace ((unsigned char)*p); ++p, ++i) - {} + {} if (!i) - break; + break; o = variable_buffer_output (o, word_start, i); o = variable_buffer_output (o, " ", 1); doneany = 1; @@ -1097,7 +1097,8 @@ func_error (char *o, char **argv, const char *funcname) } strcpy (p, *argvp); - switch (*funcname) { + switch (*funcname) + { case 'e': fatal (reading_file, "%s", msg); @@ -1107,12 +1108,12 @@ func_error (char *o, char **argv, const char *funcname) case 'i': printf ("%s\n", msg); - fflush(stdout); + fflush (stdout); break; default: fatal (*expanding_var, "Internal error: func_error: '%s'", funcname); - } + } /* The warning function expands to the empty string. */ return o; @@ -1381,7 +1382,7 @@ func_value (char *o, char **argv, const char *funcname UNUSED) /* Copy its value into the output buffer without expanding it. */ if (v) - o = variable_buffer_output (o, v->value, strlen(v->value)); + o = variable_buffer_output (o, v->value, strlen (v->value)); return o; } @@ -1399,16 +1400,16 @@ fold_newlines (char *buffer, unsigned int *length, int trim_newlines) for (; *src != '\0'; ++src) { if (src[0] == '\r' && src[1] == '\n') - continue; + continue; if (*src == '\n') - { - *dst++ = ' '; - } + { + *dst++ = ' '; + } else - { - last_nonnl = dst; - *dst++ = *src; - } + { + last_nonnl = dst; + *dst++ = *src; + } } if (!trim_newlines && (last_nonnl < (dst - 2))) @@ -1454,108 +1455,105 @@ windows32_openpipe (int *pipedes, pid_t *pid_p, char **command_argv, char **envp INVALID_HANDLE_VALUE if the parent process closed them. If that happens, we open the null device and pass its handle to process_begin below as the corresponding handle to inherit. */ - tmpIn = GetStdHandle(STD_INPUT_HANDLE); - if (DuplicateHandle (GetCurrentProcess(), - tmpIn, - GetCurrentProcess(), - &hIn, - 0, - TRUE, - DUPLICATE_SAME_ACCESS) == FALSE) { - if ((e = GetLastError()) == ERROR_INVALID_HANDLE) { - tmpIn = CreateFile("NUL", GENERIC_READ, - FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, - OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - if (tmpIn != INVALID_HANDLE_VALUE - && DuplicateHandle(GetCurrentProcess(), - tmpIn, - GetCurrentProcess(), - &hIn, - 0, - TRUE, - DUPLICATE_SAME_ACCESS) == FALSE) - CloseHandle(tmpIn); - } - if (hIn == INVALID_HANDLE_VALUE) { - error (NILF, _("windows32_openpipe: DuplicateHandle(In) failed (e=%ld)\n"), e); - return -1; + tmpIn = GetStdHandle (STD_INPUT_HANDLE); + if (DuplicateHandle (GetCurrentProcess (), tmpIn, + GetCurrentProcess (), &hIn, + 0, TRUE, DUPLICATE_SAME_ACCESS) == FALSE) + { + e = GetLastError (); + if (e == ERROR_INVALID_HANDLE) + { + tmpIn = CreateFile ("NUL", GENERIC_READ, + FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, + OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + if (tmpIn != INVALID_HANDLE_VALUE + && DuplicateHandle (GetCurrentProcess (), tmpIn, + GetCurrentProcess (), &hIn, + 0, TRUE, DUPLICATE_SAME_ACCESS) == FALSE) + CloseHandle (tmpIn); + } + if (hIn == INVALID_HANDLE_VALUE) + { + error (NILF, _("windows32_openpipe: DuplicateHandle(In) failed (e=%ld)\n"), e); + return -1; + } } - } - tmpErr = GetStdHandle(STD_ERROR_HANDLE); - if (DuplicateHandle(GetCurrentProcess(), - tmpErr, - GetCurrentProcess(), - &hErr, - 0, - TRUE, - DUPLICATE_SAME_ACCESS) == FALSE) { - if ((e = GetLastError()) == ERROR_INVALID_HANDLE) { - tmpErr = CreateFile("NUL", GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, - OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - if (tmpErr != INVALID_HANDLE_VALUE - && DuplicateHandle(GetCurrentProcess(), - tmpErr, - GetCurrentProcess(), - &hErr, - 0, - TRUE, - DUPLICATE_SAME_ACCESS) == FALSE) - CloseHandle(tmpErr); + tmpErr = GetStdHandle (STD_ERROR_HANDLE); + if (DuplicateHandle (GetCurrentProcess (), tmpErr, + GetCurrentProcess (), &hErr, + 0, TRUE, DUPLICATE_SAME_ACCESS) == FALSE) + { + e = GetLastError (); + if (e == ERROR_INVALID_HANDLE) + { + tmpErr = CreateFile ("NUL", GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, + OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + if (tmpErr != INVALID_HANDLE_VALUE + && DuplicateHandle (GetCurrentProcess (), tmpErr, + GetCurrentProcess (), &hErr, + 0, TRUE, DUPLICATE_SAME_ACCESS) == FALSE) + CloseHandle (tmpErr); + } + if (hErr == INVALID_HANDLE_VALUE) + { + error (NILF, _("windows32_openpipe: DuplicateHandle(Err) failed (e=%ld)\n"), e); + return -1; + } } - if (hErr == INVALID_HANDLE_VALUE) { - error (NILF, _("windows32_openpipe: DuplicateHandle(Err) failed (e=%ld)\n"), e); + + if (! CreatePipe (&hChildOutRd, &hChildOutWr, &saAttr, 0)) + { + error (NILF, _("CreatePipe() failed (e=%ld)\n"), GetLastError()); return -1; } - } - - if (!CreatePipe(&hChildOutRd, &hChildOutWr, &saAttr, 0)) { - error (NILF, _("CreatePipe() failed (e=%ld)\n"), GetLastError()); - return -1; - } - hProcess = process_init_fd(hIn, hChildOutWr, hErr); + hProcess = process_init_fd (hIn, hChildOutWr, hErr); - if (!hProcess) { - error (NILF, _("windows32_openpipe(): process_init_fd() failed\n")); - return -1; - } + if (!hProcess) + { + error (NILF, _("windows32_openpipe(): process_init_fd() failed\n")); + return -1; + } /* make sure that CreateProcess() has Path it needs */ - sync_Path_environment(); + sync_Path_environment (); /* 'sync_Path_environment' may realloc 'environ', so take note of the new value. */ envp = environ; - if (!process_begin(hProcess, command_argv, envp, command_argv[0], NULL)) { - /* register process for wait */ - process_register(hProcess); + if (! process_begin (hProcess, command_argv, envp, command_argv[0], NULL)) + { + /* register process for wait */ + process_register (hProcess); - /* set the pid for returning to caller */ - *pid_p = (pid_t) hProcess; + /* set the pid for returning to caller */ + *pid_p = (pid_t) hProcess; - /* set up to read data from child */ - pipedes[0] = _open_osfhandle((intptr_t) hChildOutRd, O_RDONLY); + /* set up to read data from child */ + pipedes[0] = _open_osfhandle ((intptr_t) hChildOutRd, O_RDONLY); - /* this will be closed almost right away */ - pipedes[1] = _open_osfhandle((intptr_t) hChildOutWr, O_APPEND); - return 0; - } else { - /* reap/cleanup the failed process */ - process_cleanup(hProcess); + /* this will be closed almost right away */ + pipedes[1] = _open_osfhandle ((intptr_t) hChildOutWr, O_APPEND); + return 0; + } + else + { + /* reap/cleanup the failed process */ + process_cleanup (hProcess); - /* close handles which were duplicated, they weren't used */ - if (hIn != INVALID_HANDLE_VALUE) - CloseHandle(hIn); - if (hErr != INVALID_HANDLE_VALUE) - CloseHandle(hErr); + /* close handles which were duplicated, they weren't used */ + if (hIn != INVALID_HANDLE_VALUE) + CloseHandle (hIn); + if (hErr != INVALID_HANDLE_VALUE) + CloseHandle (hErr); - /* close pipe handles, they won't be used */ - CloseHandle(hChildOutRd); - CloseHandle(hChildOutWr); + /* close pipe handles, they won't be used */ + CloseHandle (hChildOutRd); + CloseHandle (hChildOutWr); - return -1; - } + return -1; + } } #endif @@ -1580,7 +1578,7 @@ msdos_openpipe (int* pipedes, int *pidp, char *text) { char buf[PATH_MAX + 7]; /* This makes sure $SHELL value is used by $(shell), even - though the target environment is not passed to it. */ + though the target environment is not passed to it. */ sprintf (buf, "SHELL=%s", sh->value); putenv (buf); } @@ -1599,9 +1597,9 @@ msdos_openpipe (int* pipedes, int *pidp, char *text) pipedes[0] = -1; *pidp = -1; if (dos_status) - errno = EINTR; + errno = EINTR; else if (errno == 0) - errno = ENOMEM; + errno = ENOMEM; shell_function_completed = -1; } else @@ -1753,10 +1751,10 @@ func_shell_base (char *o, char **argv, int trim_newlines) free (command_argv); /* Close the write side of the pipe. We test for -1, since - pipedes[1] is -1 on MS-Windows, and some versions of MS - libraries barf when 'close' is called with -1. */ + pipedes[1] is -1 on MS-Windows, and some versions of MS + libraries barf when 'close' is called with -1. */ if (pipedes[1] >= 0) - close (pipedes[1]); + close (pipedes[1]); #endif /* Set up and read from the pipe. */ @@ -1766,23 +1764,23 @@ func_shell_base (char *o, char **argv, int trim_newlines) /* Read from the pipe until it gets EOF. */ for (i = 0; ; i += cc) - { - if (i == maxlen) - { - maxlen += 512; - buffer = xrealloc (buffer, maxlen + 1); - } - - EINTRLOOP (cc, read (pipedes[0], &buffer[i], maxlen - i)); - if (cc <= 0) - break; - } + { + if (i == maxlen) + { + maxlen += 512; + buffer = xrealloc (buffer, maxlen + 1); + } + + EINTRLOOP (cc, read (pipedes[0], &buffer[i], maxlen - i)); + if (cc <= 0) + break; + } buffer[i] = '\0'; /* Close the read side of the pipe. */ #ifdef __MSDOS__ if (fpipe) - (void) pclose (fpipe); + (void) pclose (fpipe); #else (void) close (pipedes[0]); #endif @@ -1790,34 +1788,35 @@ func_shell_base (char *o, char **argv, int trim_newlines) /* Loop until child_handler or reap_children() sets shell_function_completed to the status of our child shell. */ while (shell_function_completed == 0) - reap_children (1, 0); + reap_children (1, 0); - if (batch_filename) { - DB (DB_VERBOSE, (_("Cleaning up temporary batch file %s\n"), - batch_filename)); - remove (batch_filename); - free (batch_filename); - } + if (batch_filename) + { + DB (DB_VERBOSE, (_("Cleaning up temporary batch file %s\n"), + batch_filename)); + remove (batch_filename); + free (batch_filename); + } shell_function_pid = 0; /* The child_handler function will set shell_function_completed - to 1 when the child dies normally, or to -1 if it - dies with status 127, which is most likely an exec fail. */ + to 1 when the child dies normally, or to -1 if it + dies with status 127, which is most likely an exec fail. */ if (shell_function_completed == -1) - { - /* This likely means that the execvp failed, so we should just - write the error message in the pipe from the child. */ - fputs (buffer, stderr); - fflush (stderr); - } + { + /* This likely means that the execvp failed, so we should just + write the error message in the pipe from the child. */ + fputs (buffer, stderr); + fflush (stderr); + } else - { - /* The child finished normally. Replace all newlines in its output - with spaces, and put that in the variable output buffer. */ - fold_newlines (buffer, &i, trim_newlines); - o = variable_buffer_output (o, buffer, i); - } + { + /* The child finished normally. Replace all newlines in its output + with spaces, and put that in the variable output buffer. */ + fold_newlines (buffer, &i, trim_newlines); + o = variable_buffer_output (o, buffer, i); + } free (buffer); } @@ -1825,7 +1824,7 @@ func_shell_base (char *o, char **argv, int trim_newlines) return o; } -#else /* _AMIGA */ +#else /* _AMIGA */ /* Do the Amiga version of func_shell. */ @@ -1895,14 +1894,14 @@ func_shell_base (char *o, char **argv, int trim_newlines) do { if (i == maxlen) - { - maxlen += 512; - buffer = xrealloc (buffer, maxlen + 1); - } + { + maxlen += 512; + buffer = xrealloc (buffer, maxlen + 1); + } cc = Read (child_stdout, &buffer[i], maxlen - i); if (cc > 0) - i += cc; + i += cc; } while (cc > 0); Close (child_stdout); @@ -1979,26 +1978,26 @@ abspath (const char *name, char *apath) { /* It is unlikely we would make it until here but just to make sure. */ if (!starting_directory) - return NULL; + return NULL; strcpy (apath, starting_directory); #ifdef HAVE_DOS_PATHS if (IS_PATHSEP(name[0])) - { - if (IS_PATHSEP(name[1])) - { - /* A UNC. Don't prepend a drive letter. */ - apath[0] = name[0]; - apath[1] = name[1]; - root_len = 2; - } - /* We have /foo, an absolute file name except for the drive - letter. Assume the missing drive letter is the current - drive, which we can get if we remove from starting_directory - everything past the root directory. */ - apath[root_len] = '\0'; - } + { + if (IS_PATHSEP(name[1])) + { + /* A UNC. Don't prepend a drive letter. */ + apath[0] = name[0]; + apath[1] = name[1]; + root_len = 2; + } + /* We have /foo, an absolute file name except for the drive + letter. Assume the missing drive letter is the current + drive, which we can get if we remove from starting_directory + everything past the root directory. */ + apath[root_len] = '\0'; + } #endif dest = strchr (apath, '\0'); @@ -2012,17 +2011,17 @@ abspath (const char *name, char *apath) name += root_len; #ifdef HAVE_DOS_PATHS if (!IS_PATHSEP(apath[2])) - { - /* Convert d:foo into d:./foo and increase root_len. */ - apath[2] = '.'; - apath[3] = '/'; - dest++; - root_len++; - /* strncpy above copied one character too many. */ - name--; - } + { + /* Convert d:foo into d:./foo and increase root_len. */ + apath[2] = '.'; + apath[3] = '/'; + dest++; + root_len++; + /* strncpy above copied one character too many. */ + name--; + } else - apath[2] = '/'; /* make sure it's a forward slash */ + apath[2] = '/'; /* make sure it's a forward slash */ #endif } @@ -2032,7 +2031,7 @@ abspath (const char *name, char *apath) /* Skip sequence of multiple path-separators. */ while (IS_PATHSEP(*start)) - ++start; + ++start; /* Find end of path component. */ for (end = start; *end != '\0' && !IS_PATHSEP(*end); ++end) @@ -2041,27 +2040,27 @@ abspath (const char *name, char *apath) len = end - start; if (len == 0) - break; + break; else if (len == 1 && start[0] == '.') - /* nothing */; + /* nothing */; else if (len == 2 && start[0] == '.' && start[1] == '.') - { - /* Back up to previous component, ignore if at root already. */ - if (dest > apath + root_len) - for (--dest; !IS_PATHSEP(dest[-1]); --dest); - } + { + /* Back up to previous component, ignore if at root already. */ + if (dest > apath + root_len) + for (--dest; !IS_PATHSEP(dest[-1]); --dest); + } else - { - if (!IS_PATHSEP(dest[-1])) + { + if (!IS_PATHSEP(dest[-1])) *dest++ = '/'; - if (dest + len >= apath_limit) + if (dest + len >= apath_limit) return NULL; - dest = memcpy (dest, start, len); + dest = memcpy (dest, start, len); dest += len; - *dest = '\0'; - } + *dest = '\0'; + } } /* Unless it is root strip trailing separator. */ @@ -2149,7 +2148,7 @@ func_file (char *o, char **argv, const char *funcname UNUSED) int l = strlen (argv[1]); int nl = (l == 0 || argv[1][l-1] != '\n'); - if (fputs (argv[1], fp) == EOF || (nl && fputc('\n', fp) == EOF)) + if (fputs (argv[1], fp) == EOF || (nl && fputc ('\n', fp) == EOF)) fatal (reading_file, _("write: %s: %s"), fn, strerror (errno)); fclose (fp); @@ -2346,8 +2345,8 @@ handle_function (char **op, const char **stringp) if (count >= 0) fatal (*expanding_var, - _("unterminated call to function '%s': missing '%c'"), - entry_p->name, closeparen); + _("unterminated call to function '%s': missing '%c'"), + entry_p->name, closeparen); *stringp = end; @@ -2525,9 +2524,9 @@ func_call (char *o, char **argv, const char *funcname UNUSED) } void -define_new_function(const gmk_floc *flocp, - const char *name, int min, int max, int expand, - char *(*func)(const char *, int, char **)) +define_new_function (const gmk_floc *flocp, + const char *name, int min, int max, int expand, + char *(*func)(const char *, int, char **)) { struct function_table_entry *ent; size_t len = strlen (name); @@ -2557,8 +2556,8 @@ void hash_init_function_table (void) { hash_init (&function_table, FUNCTION_TABLE_ENTRIES * 2, - function_table_entry_hash_1, function_table_entry_hash_2, - function_table_entry_hash_cmp); + function_table_entry_hash_1, function_table_entry_hash_2, + function_table_entry_hash_cmp); hash_load (&function_table, function_table_init, - FUNCTION_TABLE_ENTRIES, sizeof (struct function_table_entry)); + FUNCTION_TABLE_ENTRIES, sizeof (struct function_table_entry)); } -- cgit v1.2.3