Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.     umka_shell: User-Mode KolibriOS developer tools, the shell
  3.     Copyright (C) 2018--2020  Ivan Baravy <dunkaist@gmail.com>
  4.  
  5.     This program is free software: you can redistribute it and/or modify
  6.     it under the terms of the GNU General Public License as published by
  7.     the Free Software Foundation, either version 2 of the License, or
  8.     (at your option) any later version.
  9.  
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU General Public License
  16.     along with this program.  If not, see <https://www.gnu.org/licenses/>.
  17. */
  18.  
  19. #include <fcntl.h>
  20. #include <inttypes.h>
  21. #include <limits.h>
  22. #include <stdio.h>
  23. #include <stdlib.h>
  24. #include <string.h>
  25. #include <sys/types.h>
  26. #include <sys/stat.h>
  27. #include <unistd.h>
  28. #include "shell.h"
  29. #include "umka.h"
  30. #include "trace.h"
  31.  
  32. #define UMKA_DEFAULT_DISPLAY_WIDTH 400
  33. #define UMKA_DEFAULT_DISPLAY_HEIGHT 300
  34.  
  35. int
  36. main(int argc, char **argv) {
  37.     umka_tool = UMKA_SHELL;
  38.     const char *usage = \
  39.         "usage: umka_shell [test_file.t] [-c]\n"
  40.         "  -c               collect coverage";
  41.     const char *infile = NULL;
  42.     char outfile[PATH_MAX] = {0};
  43.     FILE *fin = stdin, *fout = stdout;
  44.  
  45.     kos_boot.bpp = 32;
  46.     kos_boot.x_res = UMKA_DEFAULT_DISPLAY_WIDTH;
  47.     kos_boot.y_res = UMKA_DEFAULT_DISPLAY_HEIGHT;
  48.     kos_boot.pitch = UMKA_DEFAULT_DISPLAY_WIDTH*4;  // 32bpp
  49.  
  50.     // skip 'umka_shell'
  51.     argc -= 1;
  52.     argv += 1;
  53.  
  54.     while (argc) {
  55.         if (!strcmp(argv[0], "-c")) {
  56.             coverage = 1;
  57.             argc -= 1;
  58.             argv += 1;
  59.             continue;
  60.         } else if (!strcmp(argv[0], "-i") && argc > 1) {
  61.             infile = argv[1];
  62.             strncpy(outfile, infile, PATH_MAX-2); // ".t" is shorter than ".out"
  63.             char *last_dot = strrchr(outfile, '.');
  64.             if (!last_dot) {
  65.                 printf("[!] test file must have '.t' suffix\n");
  66.                 exit(1);
  67.             }
  68.             strcpy(last_dot, ".out.log");
  69.             fin = fopen(infile, "r");
  70.             if (!fin) {
  71.                 perror("[!] can't open file");
  72.                 exit(1);
  73.             }
  74.             fout = fopen(outfile, "w");
  75.             if (!fout) {
  76.                 perror("[!] can't open file");
  77.                 exit(1);
  78.             }
  79.             argc -= 2;
  80.             argv += 2;
  81.             continue;
  82.         } else {
  83.             printf("bad option: %s\n", argv[0]);
  84.             puts(usage);
  85.             exit(1);
  86.         }
  87.     }
  88.  
  89.     if (coverage)
  90.         trace_begin();
  91.  
  92.     run_test(fin, fout, 1);
  93.  
  94.     if (coverage)
  95.         trace_end();
  96.  
  97.     return 0;
  98. }
  99.