Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,7 @@ buildversion.o: version.h conftypes.h patchlevel.h $(srcdir)/version.c

bash2py: .made
mv bash bash2py
@chmod a+rx bash2py

# This is missing some dependencies. Can build by pasting the whole bash.exe command & changing to fix_string.
fix_string: burp.o translate_expr.o fix_string.c
Expand Down
6 changes: 0 additions & 6 deletions burp.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,6 @@ static void increase_burp(burpT *burpP)
return;
}
max = burpP->m_max << 1;
if (max & 0x40000000) {
// Very serious problems trying to print whatever it might be..
fprintf(stderr,"Burp can't print\n");
assert(FALSE);
exit(1);
}
burpP->m_P = realloc(burpP->m_P, max);
if (!burpP->m_P) {
fprintf(stderr, "Burp can't realloc(%d)\n", max);
Expand Down
2 changes: 1 addition & 1 deletion dynamo.c
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ void write_function(char *first_line, ...) // first arg is broken out to comply
*pFmt = '\0';

if (g_inside_class)
fprintf(outputF, " #\n");
fprintf(outputF, "\n");
va_start(lines, first_line);
vfprintf(outputF, fmt, lines);
va_end(lines);
Expand Down
22 changes: 16 additions & 6 deletions parse.y
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ extern int extended_glob;
#endif

#ifdef BASH2PY
extern burpT g_output;
extern burpT g_commentBuffer, g_output;
#define LINE_NUMBER position.line
#define VALUE(X) X.value
#else
Expand All @@ -143,9 +143,6 @@ extern int bash_input_fd_changed;
#endif

extern int errno;
#ifdef BASH2PY
extern void seen_comment_char(int c);
#endif

/* **************************************************************** */
/* */
Expand Down Expand Up @@ -455,6 +452,9 @@ inputunit: simple_list simple_list_terminator
/* Case of regular command, but not a very
interesting one. Return a NULL command. */
global_command = (COMMAND *)NULL;
#ifdef BASH2PY
if (g_commentBuffer.m_lth == 0) burpc(&g_commentBuffer, '\n');
#endif
if (parser_state & PST_CMDSUBST)
parser_state |= PST_EOFTOKEN;
YYACCEPT;
Expand Down Expand Up @@ -3000,11 +3000,11 @@ discard_until (character)
int c;

#ifdef BASH2PY
seen_comment_char(-1);
burpc(&g_commentBuffer, '#');
#endif
while ((c = shell_getc (0)) != EOF) {
#ifdef BASH2PY
seen_comment_char(c);
burpc(&g_commentBuffer, (char)c);
#endif
if (c == character) {
break;
Expand Down Expand Up @@ -3492,6 +3492,16 @@ read_token (command)
re_read_token:
#endif /* ALIAS */

#ifdef BASH2PY
/* If there is a pending comment flush it. This should be a whole-line comment
that precedes the next command, not an end-of-line comment. */
if (g_commentBuffer.m_lth > 0)
{
burps(&g_output, g_commentBuffer.m_P);
burp_reset(&g_commentBuffer);
}
#endif

/* Read a single word from input. Start by skipping blanks. */
while ((character = shell_getc (1)) != EOF && shellblank (character))
;
Expand Down
13 changes: 10 additions & 3 deletions tests/SWAG_tests/comments
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
#A comment
x=1 #Another
y=2 #Final


#A whole-line comment
x=1 #First EOL comment

# Full-line comment after a blank line
# Second consecutive full-line comment
y=2 #Second EOL comment
echo "$x+$y"

# Comment at EOF
71 changes: 12 additions & 59 deletions translate.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ static burpT g_case_var = {0,0,0,0,0,0};

burpT g_output = {0, 0, 0, 0, 0, 0};

static burpT g_commentBuffer = {0, 0, 0, 0, 0, 0};
burpT g_commentBuffer = {0, 0, 0, 0, 0, 0};
static burpT g_temp = {0, 0, 0, 0, 0, 0};
static burpT save = {0,0,0,0,0,0};

Expand Down Expand Up @@ -174,9 +174,6 @@ void seen_global(const char *nameP, _BOOL local)
//#define UNCHANGED burps(&g_output, "^^")
#define UNCHANGED

extern POSITION position;
static int comment_byte = -1;

static void print_heredoc_header (REDIRECT *redirect)
{
int kill_leading;
Expand Down Expand Up @@ -827,22 +824,6 @@ typedef struct commentS {
char *m_textP;
} commentT;

commentT *g_comment_headP = NULL, *g_comment_tailP = NULL;

static void print_comments(int before_byte)
{
commentT *commentP = g_comment_headP;

while (commentP && commentP->m_byte < before_byte) {
//MMMM deprecated, but we should print the comment sans html: burps_html(&g_output, commentP->m_textP);
newline("");
commentT* temp = commentP;
commentP = commentP->m_nextP;
free(temp);
}
g_comment_headP = NULL;
}

static void translate_unary_operation(char *operatorP, int complex1, char *term1P)
{
int left, mode;
Expand Down Expand Up @@ -2865,9 +2846,6 @@ static void emit_command (COMMAND *command)
if (!command)
return;

assert(0 <= command->position.byte);
print_comments(command->position.byte);

handle_redirection_list(&command->redirects);
if (command->flags & CMD_TIME_PIPELINE) {
UNCHANGED;
Expand Down Expand Up @@ -3018,41 +2996,14 @@ char * make_command_string (COMMAND *command)
void print_command (COMMAND *command)
{
make_command_string (command);
burpc(&g_output, '\n');
}

// This is a worrisome function that would probably break if ever (indirectly) used by print_comments()
void seen_comment_char(int c)
{
char *P;

if (c < 0) {
/* Start */

comment_byte = position.byte;
g_commentBuffer.m_lth = 0;
// burpc(&g_commentBuffer, '\n');
c = '#';
}
if (c == '\n') {

/* End */
P = g_commentBuffer.m_P;
if (*P != '#' || P[1] != '!') {
commentT *commentP = (commentT *) malloc(sizeof(commentT));
commentP->m_nextP = NULL;
commentP->m_byte = comment_byte;
commentP->m_textP = P; // So every comment points to the same place???
g_comment_tailP = commentP;
if (!g_comment_headP) g_comment_headP = g_comment_tailP;
g_commentBuffer.m_lth = 0;
g_commentBuffer.m_max = 0;
g_commentBuffer.m_P = NULL;
}
return;
/* Append buffered EOL comment if there is one. */
if (g_commentBuffer.m_lth > 0) {
burpc(&g_output, ' ');
burps(&g_output, g_commentBuffer.m_P);
burp_reset(&g_commentBuffer);
}
if (c) {
burpc(&g_commentBuffer, c);
else {
burpc(&g_output, '\n');
}
}

Expand Down Expand Up @@ -3563,8 +3514,10 @@ static void emitBash2PyClass(void)

void close_translator(const char *output_fname)
{
//TODO This is probably here to flush any remaining comments but is a no-op.
print_comments(999999999);
if (g_commentBuffer.m_lth > 0) {
burps(&g_output, g_commentBuffer.m_P);
burp_reset(&g_commentBuffer);
}

// What do we need
neededExpands();
Expand Down