Week 1 Byteshell 1
Week 1 Byteshell 1
● WSL is a Windows
feature that allows
Linux programs to
run on Windows
computer
CODE EDITOR </>
do
{ printf("> ");
line = ACMShell_read_line();
BASIC ACM-Shell args = ACMShell_split_line(line);
Loop
add_to_hist(args);
status = ACMShell_execute(args);
free(line);
free(args);
} while (status);
Read a line
if (!buffer)
{
fprintf(stderr, "ACMShell: allocation error\n");
exit(EXIT_FAILURE);
}
while (1)
c = getchar();
if (c == '\n' )
buffer[position] = '\0';
return buffer;
else
buffer[position] = c;}
Position++;
if (position >= bufsize)
bufsize += ACMShell_RL_BUFSIZE;
buffer = realloc(buffer, bufsize);
if (!buffer)
fprintf(stderr, "ACMShell: allocation error\n");
exit(EXIT_FAILURE);
Parsing a line:
int main () {
char str[80] = "This is - openproject - Byteshell";
const char s[2] = "-";
char *token;
/* get the first token */
token = strtok(str, s);
/* walk through other tokens */
while( token != NULL ) {
printf( " %s\n", token );
token = strtok(NULL, s);
}
return(0);
}
while (token != NULL)
tokens[position] = token;
position++;
if (position >= bufsize)
bufsize += ACMShell_TOK_BUFSIZE;
tokens = realloc(tokens, bufsize * sizeof(char *));
if (!tokens)
fprintf(stderr, "ACMShell: allocation error\n");
exit(EXIT_FAILURE);
token = strtok(NULL, ACMShell_TOK_DELIM);
tokens[position] = NULL;
return tokens;
THANKS