Changeset 10f4b47c in mainline for uspace/app/bdsh/input.c


Ignore:
Timestamp:
2011-07-24T17:44:44Z (13 years ago)
Author:
Petr Koupy <petr.koupy@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1e891d0
Parents:
e76e833
Message:

(Experimental) Added very simple support for executing batches of bdsh commands stored in a file.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/input.c

    re76e833 r10f4b47c  
    169169                new_iostate.stdout = to;
    170170        }
    171        
    172         rc = run_command(cmd, usr, &new_iostate);
     171
     172        if (str_cmp(actual_cmd[0], "batch") == 0 && actual_cmd[1] != NULL) {
     173                FILE *batch = fopen(actual_cmd[1], "r");
     174                if (batch == NULL) {
     175                        printf("Cannot open file %s\n", actual_cmd[1]);
     176                        rc = errno;
     177                } else {
     178                        cliuser_t fusr;
     179                        fusr.name = usr->name;
     180                        fusr.cwd = usr->cwd;
     181                        fusr.prompt = usr->prompt;
     182                        fusr.line = malloc(INPUT_MAX + 1);
     183                        char *cur = fusr.line;
     184                        char *end = fusr.line + INPUT_MAX;
     185                        int c = fgetc(batch);
     186                        while (fusr.line != NULL) {
     187                                if (c == '\n' || c == EOF || cur == end) {
     188                                        *cur = '\0';
     189                                        if (cur == fusr.line) {
     190                                                /* skip empty line */
     191                                                rc = 0;
     192                                                free(cur);
     193                                        } else {
     194                                                printf(">%s\n", fusr.line);
     195                                                rc = process_input(&fusr);
     196                                                /* fusr->line was freed by process_input() */
     197                                        }
     198                                        if (rc == 0 && c != EOF) {
     199                                                fusr.line = malloc(INPUT_MAX + 1);
     200                                                cur = fusr.line;
     201                                                end = fusr.line + INPUT_MAX;
     202                                        } else {
     203                                                break;
     204                                        }
     205                                } else {
     206                                        *cur++ = c;
     207                                }
     208                                c = fgetc(batch);
     209                        }
     210                        fclose(batch);
     211                }
     212        } else {
     213                rc = run_command(actual_cmd, usr, &new_iostate);
     214        }       
    173215       
    174216finit_with_files:
Note: See TracChangeset for help on using the changeset viewer.