Skip to content

Commit

Permalink
record: skip whitespaces after shebang for scripts
Browse files Browse the repository at this point in the history
Python tracing won't work when the shebang line has a space like below:

" #! /usr/bin/env python3 "

This patch makes uftrace to understand the above shebang as well.

Fixed: namhyung#1690

Signed-off-by: Gabriel Kim <[email protected]>
  • Loading branch information
GabrielKimm committed Aug 31, 2023
1 parent 5897da8 commit a5c0f43
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
49 changes: 49 additions & 0 deletions utils/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,22 @@ char *strjoin(char *left, char *right, const char *delim)
return new;
}

/**
* str_trim - to trim all spaces
* @str: input string
*
* This function make @str to all trimmed @str
*/
char *str_trim(char *str)
{
if (!str)
return NULL;
str = str_ltrim(str);
str = str_rtrim(str);
str = str_mtrim(str);
return str;
}

/**
* str_ltrim - to trim left spaces
* @str: input string
Expand Down Expand Up @@ -625,6 +641,39 @@ char *str_rtrim(char *str)
return str;
}

/**
* str_mtrim - to trim middle spaces
* @str: input string
*
* This function make @str to middle trimmed @str
*/
char *str_mtrim(char *str)
{
if (!str)
return NULL;

char *read_ptr = str;
char *write_ptr = str;
int space_flag = 0;

while (*read_ptr != '\0') {
if (isspace((unsigned char)*read_ptr)) {
if (!space_flag) {
*write_ptr++ = ' ';
space_flag = 1;
}
}
else {
*write_ptr++ = *read_ptr;
space_flag = 0;
}
read_ptr++;
}

*write_ptr = '\0';
return str;
}

/**
* strv_split - split given string and construct a string vector
* @strv: string vector
Expand Down
2 changes: 2 additions & 0 deletions utils/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,10 @@ void strv_append(struct strv *strv, const char *str);
void strv_replace(struct strv *strv, int idx, const char *str);
char *strv_join(struct strv *strv, const char *delim);
void strv_free(struct strv *strv);
char *str_trim(char *str);
char *str_ltrim(char *str);
char *str_rtrim(char *str);
char *str_mtrim(char *str);

char **parse_cmdline(char *cmd, int *argc);
void free_parsed_cmdline(char **argv);
Expand Down

0 comments on commit a5c0f43

Please sign in to comment.