Subversion Repositories Kolibri OS

Rev

Rev 9763 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <sys/ksys.h>
  5. #include <clayer/boxlib.h>
  6. #include <conio.h>
  7.  
  8. #include "func.h"
  9. #include "parser.h"
  10.  
  11. #define nullptr 0
  12. #define dword unsigned int
  13.  
  14. enum BUTTONS {
  15.         BTN_QUIT = 1,
  16.         BTN_EDIT = 5
  17. };
  18.  
  19. const char STR_PROGRAM_TITLENAME[] = "Graph";
  20. const char empty_text[] = "No function loaded. Type file name and press Enter. ";
  21. const char er_file_not_found[] = "Cannot open file. ";
  22. const char str_filename[] = "Filename:";
  23. const char str_editfile[] = "Edit";
  24. const char STR_ERR_CONSOLEINIT[] = "Unable to initialize console.";
  25. const char STR_MSG_HELP_USAGE[] = "Usage: %s [OPTION] [FILENAME]...\n";
  26. const char* STR_MSG_HELP[] = {
  27.         "Draws a graph by calculating mathematical function or using list of points.\n\n",
  28.  
  29.         "\t--help\t\tdisplay this help and exit\n\n",
  30.  
  31.         "You can provide path to file if you want it to be opened immediately.\n",
  32. };
  33.  
  34. // íà÷àëüíûå ðàçìåðû
  35. #define WND_W 600
  36. #define WND_H 470
  37.  
  38. #define LIGHTGREEN 0xff0000
  39. #define WHITE 0xffffff
  40. #define BLACK 0x0
  41. #define LIGHTBLUE 0x0000ff
  42. #define LIGHTRED 0xff0000
  43.  
  44. // font colors
  45. #define BIGFONTCOLOR BLACK
  46. #define SMALLFONTCOLOR BLACK
  47.  
  48. #define THREE 3.0
  49. // minimum space: 3 pixels
  50.  
  51. #define BIG_HEIGHT 4.0
  52. #define SMALL_HEIGHT 2.0
  53. #define TEXT_X 15.0
  54. // numeric format for output
  55. #define FORMAT "%.2f%c"
  56. // format for two coords
  57. #define FORMAT_COORD "(%.2f, %.2f)%c"
  58. // special value to text if enough space
  59. #define FORMAT_TEST "0.00"
  60.  
  61. #define DELTA_BIG 1.0
  62. #define DELTA_SMALL 0.1
  63.  
  64. int SysColor = 0;
  65.  
  66. double* points;
  67. dword point_count = 0;
  68. double x1, y1, x2, y2;
  69. char* funct = nullptr;
  70.  
  71. char edit_path[256];
  72. edit_box mybox = { 200, 92, WND_H-16-32, 0xffffff, 0x94AECE, 0, 0x808080, 0x10000000,
  73.                                         sizeof(edit_path)-1, (void*)&edit_path, 0, 0, 0 };
  74.  
  75. char* full_head;
  76.  
  77. char* HugeBuf = nullptr;
  78.  
  79. // constructor of TCoord
  80. TCoord coord(double x, double y) {
  81.   TCoord r;
  82.   r.x = x;
  83.   r.y = y;
  84.   return r;
  85. }
  86.  
  87. // move and scale mathematical coords to fit screen coords
  88. TCoord mat2Graf(TCoord c, TCoord scrMin, TCoord scrMax, TCoord mMin, TCoord mMax) {
  89.   TCoord r;
  90.   if (c.x > mMax.x)
  91.     c.x = mMax.x;
  92.   if (c.x < mMin.x)
  93.     c.x = mMin.x;
  94.   if (c.y > mMax.y)
  95.     c.y = mMax.y;
  96.   if (c.y < mMin.y)
  97.     c.y = mMin.y;
  98.   r.x = (scrMax.x - scrMin.x) / (mMax.x - mMin.x) * (c.x - mMin.x) + scrMin.x;
  99.   r.y = (scrMax.y - scrMin.y) / (mMax.y - mMin.y) * (mMax.y - c.y) + scrMin.y;
  100.  
  101.   return r;
  102. }
  103.  
  104. // huge function to draw all the stuff except the function itself
  105. void drawAxis(TCoord scrMin, TCoord scrMax, TCoord mMin, TCoord mMax) {
  106.   TCoord cZero={0.0,0.0},
  107.            gMin, gMax, gZero, step;
  108.   TCoord from, to;
  109.   double i=0.0;
  110.   int j;
  111.   double xmin, xmin2, ymin, ymin2;
  112.   char buf[30]="";
  113.   int strlentemp;
  114.  
  115.  
  116. // scr means Screen(bounding rect)
  117. // m   means Mathematical
  118. // g   means Graphic(real screen position)
  119.  
  120.   //_ksys_debug_puts("draw axis called\n");
  121.  
  122.   //sprintf(debuf, "test: %f,%f,%f,%f\n", 123.45, 1.0, -0.9, 12.57);
  123.   //_ksys_debug_puts(debuf);
  124.  
  125.   gMin = mat2Graf(mMin, scrMin, scrMax, mMin, mMax);
  126.   gMax = mat2Graf(mMax, scrMin, scrMax, mMin, mMax);
  127.   gZero = mat2Graf(cZero, scrMin, scrMax, mMin, mMax);
  128.  
  129.   // clear
  130.  // SysColor = WHITE;
  131.  //rectangle(di(gMin.x), di(gMin.y), di(gMax.x), di(gMax.y));
  132.   // ftopku
  133.  
  134.   SysColor = BLACK;
  135.   // osy X
  136.   _ksys_draw_line(gMin.x, gZero.y ,gMax.x, gZero.y, SysColor);
  137.   // osy Y
  138.   _ksys_draw_line(gZero.x, gMin.y, gZero.x, gMax.y, SysColor);
  139.   // bounding rect
  140.   _ksys_draw_line(gMin.x, gMin.y, gMax.x, gMin.y, SysColor);
  141.   _ksys_draw_line(gMin.x, gMax.y, gMax.x, gMax.y, SysColor);
  142.  
  143.   _ksys_draw_line(gMin.x, gMin.y, gMin.x, gMax.y, SysColor);
  144.   _ksys_draw_line(gMax.x, gMin.y, gMax.x, gMax.y, SysColor);
  145.  
  146.   // coords of the rect : lower left
  147.   sprintf(buf, FORMAT_COORD, x1, y1, '\0');
  148.   //_ksys_debug_puts(buf);
  149.   strlentemp = strlen(buf);
  150.   _ksys_draw_text(buf, gMin.x, gMin.y + textheight(buf, strlentemp), strlentemp, SysColor);
  151.   // upper left
  152.   sprintf(buf, FORMAT_COORD, x1, y2, '\0');
  153.   strlentemp = strlen(buf);
  154.   _ksys_draw_text(buf, gMin.x, gMax.y - textheight(buf, strlentemp), strlentemp, SysColor);
  155.   // lower right
  156.   sprintf(buf, FORMAT_COORD, x2, y1, '\0');
  157.   strlentemp = strlen(buf);
  158.   _ksys_draw_text(buf, gMax.x - textwidth(buf, strlentemp), gMin.y + textheight(buf, strlentemp), strlentemp, SysColor);
  159.   // upper right
  160.   sprintf(buf, FORMAT_COORD, x2, y2, '\0');
  161.   strlentemp = strlen(buf);
  162.   _ksys_draw_text(buf, gMax.x - textwidth(buf, strlentemp), gMax.y - textheight(buf, strlentemp), strlentemp, SysColor);
  163.  
  164.   //_ksys_debug_puts("some lines painted\n");
  165.  
  166.  
  167.   step.x = (mMax.x - mMin.x) / (scrMax.x - scrMin.x);
  168.   step.y = (mMax.y - mMin.y) / (scrMax.y - scrMin.y);
  169.  
  170. // round values
  171.   xmin = (int)((mMin.x / DELTA_BIG) * DELTA_BIG);
  172.   ymin = (int)((mMin.y / DELTA_BIG) * DELTA_BIG);
  173.  
  174.   // (0,0)
  175.  
  176.   if ((x1 * x2 <= 0.0) && (y1 * y2 <= 0.0))
  177.   {
  178.           from.x=0.0;
  179.           from.y=0.0;
  180.           from = mat2Graf(from, scrMin, scrMax, mMin, mMax);
  181.           SysColor = BLACK;
  182.           sprintf(buf, FORMAT, 0.0, '\0');
  183.           strlentemp = strlen(buf);
  184.           _ksys_draw_text(buf, from.x - textwidth(buf, strlentemp), from.y + textheight(buf, strlentemp), strlentemp, SysColor);
  185.   }
  186.  
  187.  
  188.   // big marks on X
  189.   //settextstyle(0, 0, 1);
  190.   if (DELTA_BIG / step.x > THREE) {
  191.     for (i = xmin; i <= mMax.x; i += DELTA_BIG) {
  192.           if (i != 0.0) {
  193.                   from.x = i;
  194.                   to.x = from.x;
  195.                   from.y = -BIG_HEIGHT * step.y;
  196.                   to.y = BIG_HEIGHT * step.y;
  197.                   from = mat2Graf(from, scrMin, scrMax, mMin, mMax);
  198.                   to = mat2Graf(to, scrMin, scrMax, mMin, mMax);
  199.                   SysColor = BLACK;
  200.                   _ksys_draw_line(from.x, from.y, to.x, to.y, SysColor);
  201.                   // write number
  202.                   sprintf(buf, FORMAT, i, '\0');
  203.                   strlentemp = strlen(buf);
  204.                   // if it fits in the GAP, then write it
  205.                   if (from.y > scrMin.y && (DELTA_BIG > (textwidth(buf, strlentemp) + 1.0) * step.x)) {
  206.                            SysColor = BIGFONTCOLOR;
  207.                            _ksys_draw_text(buf, from.x - textwidth(buf, strlentemp) / 2.0, to.y - textheight(buf, strlentemp), strlentemp, SysColor);
  208.                   }
  209.           }
  210.     }
  211.   }
  212.   //_ksys_debug_puts("big marks x painted\n");
  213.  
  214.   // big marks on Y
  215.   if (DELTA_BIG / step.y > THREE) {
  216.     for (i = ymin; i <= mMax.y; i += DELTA_BIG) {
  217.           if (i != 0.0) {
  218.                   from.y = i;
  219.                   to.y = from.y;
  220.                   from.x = -BIG_HEIGHT * step.x;
  221.                   to.x = BIG_HEIGHT * step.x;
  222.                   from = mat2Graf(from, scrMin, scrMax, mMin, mMax);
  223.                   to = mat2Graf(to, scrMin, scrMax, mMin, mMax);
  224.                   SysColor = BLACK;
  225.                   _ksys_draw_line(from.x, from.y, to.x, to.y, SysColor);
  226.                   sprintf(buf, FORMAT, i, '\0');
  227.                   strlentemp = strlen(buf);
  228.                   if (from.x > scrMin.x && (DELTA_BIG > textheight(buf, strlentemp) * step.y)) {
  229.                            SysColor = BIGFONTCOLOR;
  230.                          _ksys_draw_text(buf, from.x + TEXT_X, to.y - textheight(buf, strlentemp) / 2.0, strlentemp, SysColor);
  231.                   }
  232.           }
  233.     }
  234.   }
  235.  
  236.   xmin2 = (int)(mMin.x / DELTA_SMALL) * DELTA_SMALL;
  237.   ymin2 = (int)(mMin.y / DELTA_SMALL) * DELTA_SMALL;
  238.  
  239.   if (DELTA_SMALL / step.x  > THREE) {
  240.     j = (int)(( - xmin + xmin2 ) / DELTA_SMALL);
  241.     for (i = xmin2; i <= mMax.x; i += DELTA_SMALL, j++) {
  242.       if (j % 10 == 0) {
  243.       // we need to skip every tenth mark, to avoid overwriting big marks
  244.                 j = 0;
  245.                 continue;
  246.       }
  247.       from.x = i;
  248.       to.x = from.x;
  249.       from.y = -SMALL_HEIGHT * step.y;
  250.       to.y = SMALL_HEIGHT * step.y;
  251.       from = mat2Graf(from, scrMin, scrMax, mMin, mMax);
  252.           to = mat2Graf(to, scrMin, scrMax, mMin, mMax);
  253.       SysColor = BLACK;
  254.       _ksys_draw_line(from.x, from.y, to.x, to.y, SysColor);
  255.       sprintf(buf, FORMAT, i, '\0');
  256.           strlentemp = strlen(buf);
  257.       if (from.y > scrMin.y && (DELTA_SMALL > textwidth(buf, strlentemp) * step.x)) {
  258.                 SysColor = SMALLFONTCOLOR;
  259.                 _ksys_draw_text(buf, from.x - textwidth(buf, strlentemp) / 2.0, to.y - textheight(buf, strlentemp), strlentemp, SysColor);
  260.       }
  261.  
  262.  
  263.     }
  264.  
  265.   }
  266.  
  267.   // finally small marks on Y
  268.   if (DELTA_SMALL / step.y > THREE) {
  269.     //_ksys_debug_puts("really small marks y painted\n");
  270.     j = (int)(( - ymin + ymin2) / DELTA_SMALL);
  271.     for (i = ymin2; i <= mMax.y; i += DELTA_SMALL, j++) {
  272.       if (j % 10 == 0) {
  273.       // we need to skip every tenth, to avoid overwriting
  274.                 j = 0;
  275.                 continue;
  276.       }
  277.       from.y = i;
  278.       to.y = from.y;
  279.       from.x = -SMALL_HEIGHT * step.x;
  280.       to.x = SMALL_HEIGHT * step.x;
  281.       from = mat2Graf(from, scrMin, scrMax, mMin, mMax);
  282.       to = mat2Graf(to, scrMin, scrMax, mMin, mMax);
  283.       SysColor = BLACK;
  284.       _ksys_draw_line(from.x, from.y, to.x, to.y, SysColor);
  285.       sprintf(buf, FORMAT, i, '\0');
  286.           strlentemp = strlen(buf);
  287.       if (from.x > scrMin.x && (DELTA_SMALL > textheight(buf, strlentemp) * step.y)) {
  288.         SysColor = SMALLFONTCOLOR;
  289.         _ksys_draw_text(buf, from.x + TEXT_X, from.y - textheight(buf, strlentemp) / 2.0, strlentemp, SysColor);
  290.       }
  291.     }
  292.   }
  293.  
  294. }
  295.  
  296. /*
  297.   ends fucking piece of shit
  298. */
  299.  
  300. void drawFunction( function_t fi, TCoord scrMin, TCoord scrMax,
  301.                    TCoord mMin, TCoord mMax, int color) {
  302.   double x;
  303.   double y;
  304.   int firstPoint = 1;
  305.   TCoord p, p0 = {0.0, 0.0}, step;
  306.  
  307.   drawAxis(scrMin, scrMax, mMin, mMax);
  308.  
  309.   SysColor = color;
  310.   step.x = (mMax.x - mMin.x) / (scrMax.x - scrMin.x);
  311.  
  312.   for (x = mMin.x; x < mMax.x; x += step.x) {
  313.     y = fi(x);
  314. // function is defined here and gets in the range
  315.     if (1) { // òóò áûëî óñëîâèå, ÷òî ôóíêöèÿ ïðàâèëüíî âû÷èñëåíà
  316.       if ((y > mMin.y) && (y < mMax.y)) {
  317.               p = mat2Graf(coord(x, y), scrMin, scrMax, mMin, mMax);
  318.         // if it's our first point, only remember its coords
  319.         // otherwise, draw a line from prev to current
  320.         if (firstPoint == 0) {
  321.           _ksys_draw_line(p0.x, p0.y, p.x, p.y, SysColor);
  322.         } else firstPoint = 0;
  323.         p0 = p;
  324.       }
  325.       else {// too big/small
  326.               firstPoint = 1;
  327.       }
  328.     }
  329.     else { // no value
  330.       firstPoint = 1;
  331.     }
  332.   }
  333.  
  334. }
  335.  
  336. // èòîãîâàÿ âåðñèÿ ÷èòàëêè òåêñòîâûõ ôàéëîâ
  337. int load_points3() {
  338.         ksys_bdfe_t bdfe;
  339.         int filePointer = 0;
  340.  
  341.         int i,j,k;
  342.         double d;
  343.         dword filesize, num_number;
  344.  
  345.         double* p2=0;
  346.  
  347.         // get file size
  348.         int rr = _ksys_file_get_info(edit_path, &bdfe);
  349.         sprintf(debuf, "getsize: %d\n", rr);
  350.         _ksys_debug_puts(debuf);
  351.         if (rr != 0) {
  352.                 _ksys_draw_text((char*)er_file_not_found, 10, 10, strlen(er_file_not_found), 0x90FF0000);
  353.                 return 0;
  354.         }
  355.  
  356.         filesize = bdfe.size;
  357.         num_number = filesize / 2;
  358.  
  359.         HugeBuf = (char*)malloc(filesize + 1); // ðàçáèðàåì êàê ñòðîêó, îòñþäà òåðìèíàòîð \0
  360.  
  361.         for (i=0;i<filesize+1;i++)
  362.                 HugeBuf[i] = 0;
  363.  
  364.         rr = _ksys_file_read_file(edit_path, 0, filesize, HugeBuf, nullptr);
  365.         sprintf(debuf, "read3: %d\n", rr);
  366.         _ksys_debug_puts(debuf);
  367.  
  368.         strcpy(full_head, STR_PROGRAM_TITLENAME);
  369.         strcpy(full_head+strlen(full_head), " - ");
  370.         strcpy(full_head+strlen(full_head), edit_path);         // bad code
  371.  
  372.         // à òåïåðü ðàçîáðàòüñÿ â ýòîì
  373.  
  374.         i=0;
  375.         k=0;
  376.         while (i < filesize) {
  377.  
  378.                 while (isalpha(HugeBuf[i]) && i<filesize) i++;
  379.                 if (i == filesize) break;
  380.                 if (k==4 && HugeBuf[i] == '=') {
  381.                         //sprintf(debuf,"function: %S",HugeBuf + i);
  382.                         //_ksys_debug_puts(debuf);
  383.                         // we have a function here
  384.                         //HugeBuf[0] = ' ';
  385.                         funct = HugeBuf + i + 1;
  386.                         strcpy(full_head+strlen(full_head), ". Function y=");
  387.                         strcpy(full_head+strlen(full_head), funct);
  388.                         return 1;
  389.                 }
  390.  
  391.                 d = convert(HugeBuf+i, &j);
  392.                 if (d == ERROR) {
  393.                         sprintf(debuf, "Error in input file, byte %d, count %d\n", i, k);
  394.                         _ksys_debug_puts(debuf);
  395.                         _ksys_draw_text((char*)debuf, 10, 10, strlen(debuf), 0x000000);
  396.                         return 0;
  397.                 }
  398.                 if (d == ERROR_END) {
  399.                         _ksys_debug_puts("EOF :)!\n");
  400.                         break;
  401.                 }
  402.  
  403.                 i+=j;
  404.                 switch (k) {
  405.                         case 0:
  406.                                 x1=d;
  407.                                 break;
  408.                         case 1:
  409.                                 x2=d;
  410.                                 break;
  411.                         case 2:
  412.                                 y1=d;
  413.                                 break;
  414.                         case 3:
  415.                                 y2=d;
  416.                                 break;
  417.                         default: {
  418.                                 if (p2 == NULL)
  419.                                         p2 = (double*)malloc(num_number * 8);
  420.                                 p2[k-4]=d;
  421.                         }
  422.                 }
  423.                 k++;
  424.         }
  425. //      sprintf(debuf, "(%f,%f)-(%f,%f)",x1,y1,x2,y2);
  426. //      _ksys_debug_puts(debuf);
  427.         point_count=(k - 4)/2;
  428.  
  429.         //
  430.         points = (double*)malloc(point_count * 2 * 8);
  431.         for (i = 0; i < point_count * 2; i++)
  432.                 points[i] = p2[i];
  433.         free(p2);
  434. //      sprintf(debuf, "count: %d\n", point_count);
  435. //      _ksys_debug_puts(debuf);
  436.         sprintf(debuf, ". Number of points: %u.", point_count);
  437.         strcpy(full_head+strlen(full_head), debuf);
  438.         free(HugeBuf);
  439.         HugeBuf = NULL;
  440.         return 1;
  441. }
  442.  
  443. // âû÷èñëèòü çàäàííóþ ôóíêöèþ èëè êóñî÷íî-ëèíåéíóþ ìåæäó òî÷êàìè
  444. double fu(double x) {
  445.         int i;
  446.         double res;
  447.  
  448.         if (funct) {
  449.                 set_exp(funct,x);
  450.                 get_exp(&res);          // ïàðñèòü äëÿ êàæäîãî çíà÷åíèÿ õ? äà ÿ ñ óìà ñîøåë.
  451.                 return res;
  452.         }
  453.  
  454.         if (point_count == 0) {
  455.                 return 0.0;
  456.         }
  457.  
  458.         if (x <= points[0])
  459.                 return points[1];
  460.         if (x >= points[(point_count-1) * 2])
  461.                 return points[(point_count-1) * 2 + 1];
  462.  
  463.         for (i = 0; i < point_count; i++) {
  464.                 if ((x >= points[2 * i]) && (x < points[2 * (i + 1)]))
  465.                         break;
  466.         }
  467.  
  468.         return (x - points[2 * i]) / (points[2 * (i + 1)] - points[2 * i])
  469.                 * (points[2 * (i + 1) + 1] - points[2 * i + 1]) + points[2 * i + 1];
  470.  
  471. }
  472.  
  473. void draw_window(void) {
  474.         double xx0=0.0, yy0=0.0;
  475.  
  476.         _ksys_start_draw();
  477.         _ksys_create_window(100, 80, WND_W, WND_H, full_head, 0xFFFFFF, 0x33);
  478.         _ksys_end_draw();
  479.  
  480.         ksys_thread_t info;
  481.         _ksys_thread_info(&info, 0xFFFFFFFF);
  482.         int cWidth = info.winx_size - 9;
  483.         int cHeight = info.winy_size - _ksys_get_skin_height() - 4;
  484.  
  485.         mybox.top = cHeight - 50;
  486.         mybox.width = cWidth - mybox.left - 80;
  487.  
  488.         if (info.window_state&0x04) return; //draw nothing if window is rolled-up
  489.  
  490.         if (point_count == 0 && funct == NULL) {
  491.                 _ksys_draw_text((char *)empty_text, (cWidth - 8 * strlen(empty_text))/2,cHeight/2-25, strlen(empty_text), 0x90000000);
  492.         } else {
  493.                 drawFunction(&fu, coord(10, 20), coord(cWidth - 20, cHeight - 70), coord(x1,y1), coord(x2,y2), 0x00ff0000);
  494.         }
  495.  
  496.         _ksys_draw_text((char*)str_filename, 15, mybox.top + 4, strlen(str_filename), 0x90000000);
  497.  
  498.         edit_box_draw(&mybox);
  499.  
  500.         _ksys_define_button(cWidth - 70, mybox.top, 50, 21, BTN_EDIT, 0xc0c0c0);
  501.         _ksys_draw_text((char*)str_editfile, cWidth - 60, mybox.top + 4, 0, 0x90000000);
  502. }
  503.  
  504. void consoleInit() {
  505.         if (con_init()) { // Init fail
  506.                 _ksys_debug_puts("[");
  507.                 _ksys_debug_puts(STR_PROGRAM_TITLENAME);
  508.                 _ksys_debug_puts("] ");
  509.                 _ksys_debug_puts(STR_ERR_CONSOLEINIT);
  510.                 _ksys_debug_puts("\n");
  511.                 exit(2);
  512.         }
  513.         (*con_set_title)(STR_PROGRAM_TITLENAME);
  514. }
  515.  
  516. void consoleExit() {
  517.         (*con_exit)(0);
  518. }
  519.  
  520. int main(int argc, char** argv) {
  521.         full_head = (char*)malloc(300);
  522.         strcpy(full_head, STR_PROGRAM_TITLENAME);
  523.  
  524.         if (argc == 2) {
  525.                 if (!strcmp(argv[1], "--help") || !strcmp(argv[1], "-h")) {
  526.                         consoleInit();
  527.                         printf(STR_MSG_HELP_USAGE, argv[0]);
  528.                         for (int j = 0; j < sizeof(STR_MSG_HELP)/sizeof(STR_MSG_HELP[0]); ++j) puts(STR_MSG_HELP[j]);
  529.                         consoleExit();
  530.                         return 0;
  531.                 } else {
  532.                         strcpy(edit_path, argv[1]);
  533.                         if (load_points3())
  534.                                 draw_window();
  535.                 }
  536.         } else if (argc > 2) {
  537.                 consoleInit();
  538.                 printf(STR_MSG_HELP_USAGE, argv[0]);
  539.                 consoleExit();
  540.                 return 1;
  541.         }
  542.  
  543.         _ksys_set_event_mask(0xC0000027);
  544.         int event;
  545.         while (1) {
  546.                 edit_box_mouse(&mybox);
  547.                 event = _ksys_get_event();
  548.                 switch (event) {
  549.                         case KSYS_EVENT_REDRAW:
  550.                                 draw_window();
  551.                                 break;
  552.                         case KSYS_EVENT_KEY: {
  553.                                 ksys_oskey_t kc = _ksys_get_key();
  554.                                 switch (kc.code) {
  555.                                         case 0x0D:
  556.                                                 if (HugeBuf) {
  557.                                                         //sprintf(debuf, "freemem: HugeBuf = %X", HugeBuf);
  558.                                                         //_ksys_debug_puts(debuf);
  559.                                                         free(HugeBuf); // ÷òî çà áàã - ïîíÿòü íå ìîãó.
  560.                                                         HugeBuf = nullptr;
  561.                                                         funct = nullptr;
  562.                                                 }
  563.                                                 if (points) {
  564.                                                         //sprintf(debuf, "freemem: points = %X", points);
  565.                                                         //_ksys_debug_puts(debuf);
  566.                                                         free(points); // è òóò. íó íå îáðàùàþñü ÿ ê ýòîìó óêàçàòåëþ, òîëüêî ïàìÿòü â íåãî, ïîòîì ñíîâà âûäåëÿþ
  567.                                                         points = nullptr;
  568.                                                 }
  569.                                                 point_count = 0;
  570.                                                 _ksys_draw_bar(10, 10, 200, 20, 0xFFFFFF); // ôîí äëÿ ñîîáùåíèé îá îøèáêàõ
  571.                                                 if (load_points3())
  572.                                                         draw_window();
  573.                                                 break;
  574.                                         default:
  575.                                                 edit_box_key_safe(&mybox, kc);
  576.                                 }
  577.                                 break;
  578.                         }
  579.                         case KSYS_EVENT_BUTTON: {
  580.                                 // button pressed; we have only one button, close
  581.                                 uint32_t button = _ksys_get_button();
  582.                                 if (button == BTN_QUIT)
  583.                                         _ksys_exit();
  584.                                 else if (button == BTN_EDIT)
  585.                                         _ksys_exec("/sys/develop/cedit", edit_path);
  586.                         }
  587.                 }
  588.         }
  589.         return 0;
  590. }
  591.