Subversion Repositories NedoOS

Rev

Rev 2378 | Blame | Compare with Previous | Last modification | View Log | Download

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <intrz80.h>
  4. #include <stdlib.h>
  5. #include <oscalls.h>
  6. #include <../common/terminal.c>
  7. #include <tcp.h>
  8. #include <osfs.h>
  9. #include <graphic.h>
  10. #include <ctype.h>
  11. #include <math.h>
  12. //
  13. #define true 1
  14. #define false 0
  15. #define screenHeight 23
  16. #define screenWidth 80
  17.  
  18. unsigned int RBR_THR = 0xf8ef;
  19. unsigned int IER = 0xf9ef;
  20. unsigned int IIR_FCR = 0xfaef;
  21. unsigned int LCR = 0xfbef;
  22. unsigned int MCR = 0xfcef;
  23. unsigned int LSR = 0xfdef;
  24. unsigned int MSR = 0xfeef;
  25. unsigned int SR = 0xffef;
  26. unsigned int divider = 1;
  27. unsigned int comType = 0;
  28. unsigned int espType = 32;
  29. unsigned int espRetry = 5;
  30. unsigned long factor, timerok, count = 0;
  31. unsigned int magic = 16;
  32. unsigned char netDriver = 0;
  33. unsigned char curHost;
  34. unsigned long contLen;
  35. unsigned int httpErr;
  36.  
  37. unsigned char uVer[] = "0.4";
  38. unsigned char curPath[128];
  39. unsigned char cmd[256];
  40. unsigned char search[256];
  41. unsigned char crlf[2] = {13, 10};
  42. const unsigned char gotWiFi[] = "WIFI GOT IP";
  43. char hosts[3][32] = {"next.zxart.ee", "zxdb.remysharp.com", "hood.speccy.cz"};
  44. unsigned char userAgent1[] = " HTTP/1.1\r\nHost: ";
  45. unsigned char userAgent2[] = "\r\nUser-Agent: Mozilla/4.0 (compatible; MSIE5.01; NedoOS; ZXDB)\r\n\r\n\0";
  46. unsigned char netbuf[4096];
  47. unsigned char buf[16384];
  48. struct sockaddr_in targetadr;
  49. struct readstructure readStruct;
  50. struct sockaddr_in dnsaddress;
  51.  
  52. struct window
  53. {
  54.         unsigned char x;
  55.         unsigned char y;
  56.         unsigned char w;
  57.         unsigned char h;
  58.         unsigned char text;
  59.         unsigned char back;
  60.         unsigned char tittle[80];
  61. } curWin;
  62.  
  63. struct time
  64. {
  65.         unsigned int hours;
  66.         unsigned int minutes;
  67.         unsigned char oldMinutes;
  68.  
  69. } clock;
  70.  
  71. struct linkStruct
  72. {
  73.         unsigned char host[128];
  74.         unsigned char path[512];
  75.         unsigned int port;
  76.         unsigned char hasName;
  77.         unsigned char fname[256];
  78. } link;
  79.  
  80. struct line
  81. {
  82.         unsigned long id;
  83.         unsigned char name[512];
  84.         unsigned char file[512];
  85.         unsigned char ext[5];
  86.         unsigned long size;
  87.         unsigned char option;
  88.         unsigned int year;
  89. } table[12];
  90.  
  91. struct limit
  92. {
  93.         int first;
  94.         int second;
  95.         int total;
  96.         int curline;
  97.         int curOpt;
  98.         int headLng;
  99.         int curPage;
  100. } limiter;
  101.  
  102. void spaces(unsigned char number)
  103. {
  104.         while (number > 0)
  105.         {
  106.                 putchar(' ');
  107.                 number--;
  108.         }
  109. }
  110.  
  111. void waitKey(void)
  112. {
  113.         do
  114.         {
  115.                 YIELD();
  116.         } while (OS_GETKEY() == 0);
  117. }
  118.  
  119. void clearStatus(void)
  120. {
  121.         OS_SETCOLOR(5);
  122.         OS_SETXY(0, 24);
  123.         spaces(79);
  124.         putchar('\r');
  125. }
  126.  
  127. void quit(void)
  128. {
  129.         OS_CLS(0);
  130.         OS_SETGFX(-1);
  131.         exit(0);
  132. }
  133.  
  134. void printTable(void)
  135. {
  136.         unsigned int cycle;
  137.  
  138.         for (cycle = 1; cycle < 256; cycle++)
  139.         {
  140.                 OS_SETCOLOR(7);
  141.                 printf("%03u:", cycle);
  142.                 OS_SETCOLOR(71);
  143.                 putchar(cycle);
  144.                 OS_SETCOLOR(7);
  145.                 printf(" ");
  146.                 if (cycle % 12 == 0)
  147.                 {
  148.                         printf("\r\n");
  149.                 }
  150.         }
  151. }
  152.  
  153. void delay(unsigned long counter)
  154. {
  155.         unsigned long start, finish;
  156.         counter = counter / 20;
  157.         if (counter < 1)
  158.         {
  159.                 counter = 1;
  160.         }
  161.         start = time();
  162.         finish = start + counter;
  163.  
  164.         while (start < finish)
  165.         {
  166.                 start = time();
  167.         }
  168. }
  169.  
  170. unsigned char delayLongKey(unsigned long counter)
  171. {
  172.         unsigned long start, finish, key;
  173.         counter = counter / 20;
  174.         if (counter < 1)
  175.         {
  176.                 counter = 1;
  177.         }
  178.         start = time();
  179.         finish = start + counter;
  180.  
  181.         while (start < finish)
  182.         {
  183.                 start = time();
  184.                 key = OS_GETKEY();
  185.                 if (key != 0)
  186.                 {
  187.                         return key;
  188.                 }
  189.                 YIELD();
  190.         }
  191.         return 32;
  192. }
  193.  
  194. ///////////////////////////
  195. #include <../common/esp-com.c>
  196. #include <../common/network.c>
  197. //////////////////////////
  198.  
  199. void clearNetbuf(void)
  200. {
  201.         unsigned int counter;
  202.         for (counter = 0; counter < sizeof(netbuf); counter++)
  203.         {
  204.                 netbuf[counter] = 0;
  205.         }
  206. }
  207.  
  208. int testOperation2(const char *process, int socket)
  209. {
  210.         if (socket < 0)
  211.         {
  212.                 printf("%s: [ERROR:", process);
  213.                 errorPrint(-socket);
  214.                 printf("]\r\n");
  215.                 YIELD();
  216.                 return -socket;
  217.         }
  218.         return 1;
  219. }
  220.  
  221. unsigned char saveBuf(unsigned char *fileNamePtr, unsigned char operation, unsigned int sizeOfBuf)
  222. {
  223.         FILE *fp2;
  224.  
  225.         switch (operation)
  226.         {
  227.         case 00:
  228.                 fp2 = OS_CREATEHANDLE(fileNamePtr, 0x80);
  229.                 if (((int)fp2) & 0xff)
  230.                 {
  231.                         clearStatus();
  232.                         printf("%s  creating error.", fileNamePtr);
  233.                         getchar();
  234.                         exit(0);
  235.                 }
  236.                 OS_CLOSEHANDLE(fp2);
  237.                 break;
  238.         case 01:
  239.                 fp2 = OS_OPENHANDLE(fileNamePtr, 0x80);
  240.                 if (((int)fp2) & 0xff)
  241.                 {
  242.                         clearStatus();
  243.                         printf("%s opening error.\r\n ", fileNamePtr);
  244.                         getchar();
  245.                         exit(0);
  246.                 }
  247.                 OS_SEEKHANDLE(fp2, OS_GETFILESIZE(fp2));
  248.                 OS_WRITEHANDLE(netbuf + limiter.headLng, fp2, sizeOfBuf);
  249.                 OS_CLOSEHANDLE(fp2);
  250.                 break;
  251.         case 02:
  252.                 OS_CLOSEHANDLE(fp2);
  253.                 break;
  254.         default:
  255.                 break;
  256.         }
  257.  
  258.         return 0;
  259. }
  260.  
  261. void drawClock(void)
  262. {
  263.         unsigned long dosTime;
  264.         dosTime = OS_GETTIME();
  265.         clock.hours = dosTime >> 11 & 31;        // 0b00011111
  266.         clock.minutes = (dosTime >> 5) & 63; // 0b00111111
  267.  
  268.         if (clock.minutes != clock.oldMinutes)
  269.         {
  270.                 clock.oldMinutes = clock.minutes;
  271.                 OS_SETCOLOR(103);
  272.                 OS_SETXY(73, 0);
  273.                 printf("[%02u:%02u]", clock.hours, clock.minutes);
  274.         }
  275. }
  276.  
  277. void drawPage(void)
  278. {
  279.         OS_SETCOLOR(103);
  280.         OS_SETXY(64, 0);
  281.         printf("[Page:%2d]", limiter.curPage);
  282. }
  283.  
  284. char readParamFromIni(void)
  285. {
  286.         FILE *fpini;
  287.         unsigned char *count1;
  288.         const char currentNetwork[] = "currentNetwork";
  289.         unsigned char curNet = 0;
  290.  
  291.         OS_GETPATH((unsigned int)&curPath);
  292.         OS_SETSYSDRV();
  293.         OS_CHDIR("/");
  294.         OS_CHDIR("ini");
  295.  
  296.         fpini = OS_OPENHANDLE("network.ini", 0x80);
  297.         if (((int)fpini) & 0xff)
  298.         {
  299.                 clearStatus();
  300.                 printf("network.ini not found.\r\n");
  301.                 getchar();
  302.                 return false;
  303.         }
  304.  
  305.         OS_READHANDLE(netbuf, fpini, sizeof(netbuf) - 1);
  306.         OS_CLOSEHANDLE(fpini);
  307.  
  308.         count1 = strstr(netbuf, currentNetwork);
  309.         if (count1 != NULL)
  310.         {
  311.                 sscanf(count1 + strlen(currentNetwork) + 1, "%u", &curNet);
  312.         }
  313.  
  314.         OS_CHDIR(curPath);
  315.         return curNet;
  316. }
  317.  
  318. void init(void)
  319. {
  320.         targetadr.family = AF_INET;
  321.         targetadr.porth = 00;
  322.         targetadr.portl = 80;
  323.         targetadr.b1 = 0;
  324.         targetadr.b2 = 0;
  325.         targetadr.b3 = 0;
  326.         targetadr.b4 = 0;
  327.         curHost = 0;
  328.         link.port = 80;
  329.         link.hasName = false;
  330.         limiter.curOpt = 1;
  331.         limiter.curPage = 0;
  332.         get_dns();
  333.         netDriver = readParamFromIni();
  334.         if (netDriver == 1)
  335.         {
  336.                 loadEspConfig();
  337.                 uart_init(divider);
  338.                 espReBoot();
  339.         }
  340.         OS_SETSYSDRV();
  341.         OS_MKDIR("../downloads");          // Create if not exist
  342.         OS_MKDIR("../downloads/zxdb"); // Create if not exist
  343.         OS_CHDIR("../downloads/zxdb");
  344.  
  345.         strcpy(link.host, hosts[curHost]);
  346.         clock.oldMinutes = 255;
  347. }
  348.  
  349. void errorBox(struct window w, const char *message)
  350. {
  351.         unsigned char wcount, tempx, tittleStart;
  352.  
  353.         w.h++;
  354.         OS_SETXY(w.x, w.y - 1);
  355.         BDBOX(w.x, w.y, w.w + 1, w.h, w.back, 32);
  356.         OS_SETXY(w.x, w.y);
  357.         OS_SETCOLOR(w.text);
  358.         putchar(201);
  359.         for (wcount = 0; wcount < w.w; wcount++)
  360.         {
  361.                 putchar(205);
  362.         }
  363.         putchar(187);
  364.         OS_SETXY(w.x, w.y + w.h);
  365.         putchar(200);
  366.         for (wcount = 0; wcount < w.w; wcount++)
  367.         {
  368.                 putchar(205);
  369.         }
  370.         putchar(188);
  371.  
  372.         tempx = w.x + w.w + 1;
  373.         for (wcount = 1; wcount < w.h; wcount++)
  374.         {
  375.                 OS_SETXY(w.x, w.y + wcount);
  376.                 putchar(186);
  377.                 OS_SETXY(tempx, w.y + wcount);
  378.                 putchar(186);
  379.         }
  380.         tittleStart = w.x + (w.w / 2) - (strlen(w.tittle) / 2);
  381.         OS_SETXY(tittleStart, w.y);
  382.         printf("[%s]", w.tittle);
  383.         OS_SETXY(w.x + 1, w.y + 1);
  384.         OS_SETCOLOR(w.back);
  385.         tittleStart = w.x + (w.w / 2) - (strlen(message) / 2);
  386.         OS_SETXY(tittleStart, w.y + 1);
  387.         printf("%s", message);
  388. }
  389.  
  390. void simpleBox(struct window w)
  391. {
  392.         unsigned char wcount, tempx;
  393.         w.h = w.h - 2;
  394.         OS_SETXY(w.x, w.y);
  395.         BDBOX(w.x, w.y + 1, w.w, w.h, w.back, 32);
  396.         w.w = w.w - 2;
  397.         OS_SETXY(w.x, w.y);
  398.         OS_SETCOLOR(w.text);
  399.         putchar(201);
  400.         for (wcount = 0; wcount < w.w; wcount++)
  401.         {
  402.                 putchar(205);
  403.         }
  404.         putchar(187);
  405.  
  406.         OS_SETXY(w.x, w.y + w.h);
  407.         putchar(200);
  408.         for (wcount = 0; wcount < w.w; wcount++)
  409.         {
  410.                 putchar(205);
  411.         }
  412.         putchar(188);
  413.         tempx = w.x + w.w + 1;
  414.         for (wcount = 1; wcount < w.h; wcount++)
  415.         {
  416.                 OS_SETXY(w.x, w.y + wcount);
  417.                 putchar(186);
  418.                 OS_SETXY(tempx, w.y + wcount);
  419.                 putchar(186);
  420.         }
  421. }
  422.  
  423. unsigned char inputBox(struct window w, const char *prefilled)
  424. {
  425.         unsigned char wcount, tempx, tittleStart;
  426.         unsigned char byte, counter;
  427.         w.h++;
  428.         OS_SETXY(w.x, w.y - 1);
  429.         BDBOX(w.x, w.y, w.w + 1, w.h, w.back, 32);
  430.         OS_SETXY(w.x, w.y);
  431.         OS_SETCOLOR(w.text);
  432.         putchar(201);
  433.         for (wcount = 0; wcount < w.w; wcount++)
  434.         {
  435.                 putchar(205);
  436.         }
  437.         putchar(187);
  438.         OS_SETXY(w.x, w.y + w.h);
  439.         putchar(200);
  440.         for (wcount = 0; wcount < w.w; wcount++)
  441.         {
  442.                 putchar(205);
  443.         }
  444.         putchar(188);
  445.  
  446.         tempx = w.x + w.w + 1;
  447.         for (wcount = 1; wcount < w.h; wcount++)
  448.         {
  449.                 OS_SETXY(w.x, w.y + wcount);
  450.                 putchar(186);
  451.                 OS_SETXY(tempx, w.y + wcount);
  452.                 putchar(186);
  453.         }
  454.         tittleStart = w.x + (w.w / 2) - (strlen(w.tittle) / 2);
  455.         OS_SETXY(tittleStart, w.y);
  456.         printf("[%s]", w.tittle);
  457.         OS_SETXY(w.x + 1, w.y + 1);
  458.         OS_SETCOLOR(w.back);
  459.         putchar(219);
  460.  
  461.         cmd[0] = 0;
  462.  
  463.         counter = strlen(prefilled);
  464.         if (counter != 0)
  465.         {
  466.                 strcpy(cmd, prefilled);
  467.                 goto skipKeys;
  468.         }
  469.  
  470.         do
  471.         {
  472.                 byte = OS_GETKEY();
  473.                 /*
  474.                 clearStatus();
  475.                 OS_SETCOLOR(103);
  476.                 printf("key = %u", byte);
  477.                 */
  478.                 if (byte != 0)
  479.                 {
  480.                         switch (byte)
  481.                         {
  482.                         case 0x08:
  483.                                 if (counter > 0)
  484.                                 {
  485.                                         counter--;
  486.                                         cmd[counter] = 0;
  487.                                 }
  488.                                 break;
  489.                         case 0x0d:
  490.  
  491.                                 if (counter == 0)
  492.                                 {
  493.                                         return false;
  494.                                 }
  495.                                 else
  496.                                 {
  497.                                         return true;
  498.                                 }
  499.  
  500.                         case 31:
  501.                                 break;
  502.                         case 250:
  503.                                 break;
  504.                         case 249:
  505.                                 break;
  506.                         case 248:
  507.                                 break;
  508.                         case 251: // Right
  509.                                 break;
  510.                         case 252: // Del
  511.                                 OS_SETXY(w.x + 1, w.y + 1);
  512.                                 spaces(counter + 1);
  513.                                 cmd[0] = 0;
  514.                                 counter = 0;
  515.                                 break;
  516.                         case 27:
  517.                                 cmd[0] = 0;
  518.                                 return false;
  519.  
  520.                         default:
  521.                                 if (counter < w.w - 1)
  522.                                 {
  523.                                         cmd[counter] = byte;
  524.                                         counter++;
  525.                                         cmd[counter] = 0;
  526.                                 }
  527.                                 break;
  528.                         }
  529.                 skipKeys:
  530.                         OS_SETXY(w.x + 1, w.y + 1);
  531.                         printf("%s", cmd);
  532.                         putchar(219);
  533.                         if (byte == 0x08)
  534.                         {
  535.                                 putchar(' ');
  536.                         }
  537.                 }
  538.                 YIELD();
  539.         } while (42);
  540.         return false;
  541. }
  542.  
  543. void sendReqdialog(void)
  544. {
  545.         curWin.w = 50;
  546.         curWin.x = 39 - curWin.w / 2;
  547.         curWin.y = 10;
  548.         curWin.h = 4;
  549.         curWin.text = 223;
  550.         curWin.back = 223;
  551.         simpleBox(curWin);
  552.         OS_SETXY(30, curWin.y + 1);
  553.         printf("Sending request...");
  554. }
  555.  
  556. void tittleDraw(void)
  557. {
  558.         clock.oldMinutes = 255;
  559.         OS_SETCOLOR(103);
  560.         OS_SETXY(0, 0);
  561.         spaces(79);
  562.         OS_SETXY(0, 0);
  563.         printf(" ZXDB downloader [%s]", uVer);
  564.         OS_SETXY(38 - strlen(link.host) / 2, 0);
  565.         printf("[");
  566.         OS_SETCOLOR(102);
  567.         printf("%s", link.host);
  568.         OS_SETCOLOR(103);
  569.         printf("]");
  570.         drawPage();
  571.         drawClock();
  572. }
  573. void drawSearch(void)
  574. {
  575.         OS_SETCOLOR(207);
  576.         OS_SETXY(38 - strlen(search) / 2, 1);
  577.         putchar('[');
  578.         OS_SETCOLOR(71);
  579.         printf("%s", search);
  580.         OS_SETCOLOR(curWin.text);
  581.         OS_SETCOLOR(207);
  582.         putchar(']');
  583. }
  584.  
  585. void mainWinDraw(void)
  586. {
  587.         tittleDraw();
  588.         OS_SETXY(0, 23);
  589.         OS_SETCOLOR(71);
  590.         printf("[");
  591.         OS_SETCOLOR(87);
  592.         printf("H");
  593.         OS_SETCOLOR(71);
  594.         printf("]change host       [");
  595.         OS_SETCOLOR(87);
  596.         printf("S");
  597.  
  598.         OS_SETCOLOR(71);
  599.         printf("]Search item        [");
  600.         OS_SETCOLOR(87);
  601.         printf("ENTER");
  602.         OS_SETCOLOR(71);
  603.         printf("]Download item       [");
  604.         OS_SETCOLOR(87);
  605.         printf("ESC");
  606.         OS_SETCOLOR(71);
  607.         printf("]Exit   ");
  608.  
  609.         curWin.x = 0;
  610.         curWin.y = 1;
  611.         curWin.w = 80;
  612.         curWin.h = 23;
  613.         curWin.text = 207;
  614.         curWin.back = 207;
  615.         simpleBox(curWin);
  616.         drawSearch();
  617.         clearStatus();
  618. }
  619.  
  620. int pos(unsigned char *s, unsigned char *c, unsigned int n, unsigned int startPos)
  621. {
  622.         unsigned int i, j;
  623.         unsigned int lenC, lenS;
  624.  
  625.         for (lenC = 0; c[lenC]; lenC++)
  626.                 ;
  627.         for (lenS = 0; s[lenS]; lenS++)
  628.                 ;
  629.  
  630.         for (i = startPos; i <= lenS - lenC; i++)
  631.         {
  632.                 for (j = 0; s[i + j] == c[j]; j++)
  633.                         ;
  634.  
  635.                 if (j - lenC == 1 && i == lenS - lenC && !(n - 1))
  636.                         return i;
  637.                 if (j == lenC)
  638.                         if (n - 1)
  639.                                 n--;
  640.                         else
  641.                                 return i;
  642.         }
  643.         return -1;
  644. }
  645.  
  646. void squeeze(char s[], int c)
  647. {
  648.         int i, j;
  649.  
  650.         for (i = j = 0; s[i] != '\0'; i++)
  651.                 if (s[i] != c)
  652.                         s[j++] = s[i];
  653.         s[j] = '\0';
  654. }
  655.  
  656. char *insert_string(const char *original, const char *to_insert, unsigned int position)
  657. {
  658.         unsigned int original_len = strlen(original);
  659.         unsigned int insert_len = strlen(to_insert);
  660.         unsigned int new_len = original_len + insert_len;
  661.  
  662.         char *new_string = (char *)malloc(new_len + 1); // +1 для \0
  663.         if (new_string == NULL)
  664.         {
  665.                 return NULL; // Обработка ошибки выделения памяти
  666.         }
  667.  
  668.         // Копирование части исходной строки до позиции вставки
  669.         strncpy(new_string, original, position);
  670.         new_string[position] = '\0';
  671.  
  672.         // Вставка строки
  673.         strcat(new_string, to_insert);
  674.  
  675.         // Добавление оставшейся части исходной строки
  676.         strcat(new_string, original + position);
  677.  
  678.         return new_string;
  679. }
  680.  
  681. int cutHeader(void)
  682. {
  683.         unsigned char *count1;
  684.         int counter;
  685.  
  686.         httpErr = httpError();
  687.         if (httpError() != 200)
  688.         {
  689.                 clearStatus();
  690.                 printf("HTTP response:[%u]", httpErr);
  691.                 return 0;
  692.         }
  693.         count1 = strstr(netbuf, "Content-Length:");
  694.         if (count1 == NULL)
  695.         {
  696.                 clearStatus();
  697.                 printf("contLen not found");
  698.                 contLen = 0;
  699.                 httpErr = 999; // bad kostil
  700.                 return 0;
  701.         }
  702.         contLen = atol(count1 + 15);
  703.         // printf("Content-Length: %lu \n\r", contLen);
  704.  
  705.         count1 = strstr(netbuf, "Content-Disposition: attachment; filename="); // 42
  706.                                                                                                                                                    // Content-Disposition: attachment; filename="WED_PRO.TRD"
  707.         if (count1 != NULL)
  708.         {
  709.                 strncpy(link.fname, count1 + 43, 64);
  710.                 strcat(link.fname, "\0");
  711.                 counter = 0;
  712.                 while (link.fname[counter] != '\"')
  713.                 {
  714.                         counter++;
  715.                 }
  716.                 link.fname[counter] = 0;
  717.                 link.hasName = true;
  718.         }
  719.         else
  720.         {
  721.                 strncpy(link.fname, table[limiter.curline].file, 57);
  722.                 strcat(link.fname, ".");
  723.                 strcat(link.fname, table[limiter.curline].ext);
  724.  
  725.                 counter = strlen(link.fname);
  726.                 while (counter != 0)
  727.                 {
  728.                         counter--;
  729.                         if (link.fname[counter] == '.' && table[limiter.curline].option > 1)
  730.                         {
  731.                                 const char *new_string;
  732.                                 char temp[65];
  733.                                 sprintf(temp, "-%02d", limiter.curOpt);
  734.                                 new_string = insert_string(link.fname, temp, counter);
  735.                                 strcpy(link.fname, new_string);
  736.                         }
  737.                 }
  738.                 link.hasName = false;
  739.         }
  740.  
  741.         count1 = strstr(netbuf, "\r\n\r\n");
  742.         if (count1 == NULL)
  743.         {
  744.                 clearStatus();
  745.                 printf("end of header not found\r\n");
  746.         }
  747.         else
  748.         {
  749.                 // printf("header %u bytes\r\n", ((unsigned int)count1 - (unsigned int)netbuf + 4));
  750.         }
  751.         return ((unsigned int)count1 - (unsigned int)netbuf + 4);
  752. }
  753.  
  754. void downDialog(void)
  755. {
  756.         unsigned int nameLong;
  757.  
  758.         mainWinDraw();
  759.  
  760.         nameLong = strlen(link.fname);
  761.         if (nameLong < 21)
  762.         {
  763.                 curWin.w = 23;
  764.         }
  765.         else
  766.         {
  767.                 curWin.w = nameLong + 4;
  768.         }
  769.         curWin.x = 39 - curWin.w / 2;
  770.         curWin.y = 10;
  771.         curWin.h = 4;
  772.         curWin.text = 223;
  773.         curWin.back = 223;
  774.         simpleBox(curWin);
  775.         OS_SETXY(38 - nameLong / 2, curWin.y);
  776.         printf("[%s]", link.fname);
  777. }
  778.  
  779. char getFileEsp(void)
  780. {
  781.         int todo;
  782.         unsigned char byte, firstPacket;
  783.         unsigned long downloaded = 0;
  784.         unsigned int count, fileSize1, down;
  785.         const unsigned char sendOk[] = "SEND OK";
  786.  
  787.         sprintf(cmd, "AT+CIPSTART=\"TCP\",\"%s\",%u", link.host, link.port);
  788.         sendcommand(cmd);
  789.  
  790.         do
  791.         {
  792.                 getAnswer3(); // CONNECT or ERROR or link is not valid
  793.  
  794.                 if (strstr(netbuf, "CONNECT") != NULL)
  795.                 {
  796.                         break;
  797.                 }
  798.                 else
  799.                 {
  800.                         if (strstr(netbuf, "ERROR") != NULL)
  801.                         {
  802.                                 return false;
  803.                         }
  804.                 }
  805.         } while (42); // Try until endo of the days recieve CONNECT or ERROR
  806.  
  807.         getAnswer3(); // OK
  808.  
  809.         sprintf(cmd, "AT+CIPSEND=%u", strlen(link.path) + 2);
  810.         sendcommand(cmd);
  811.         getAnswer3();
  812.  
  813.         do
  814.         {
  815.                 byte = uartReadBlock();
  816.         } while (byte != '>');
  817.  
  818.         // sendcommandNrn(link.path);
  819.         sendcommand(link.path);
  820.  
  821.         count = 0;
  822.         do
  823.         {
  824.                 byte = uartReadBlock();
  825.                 if (byte == sendOk[count])
  826.                 {
  827.                         count++;
  828.                         // putchar(byte);
  829.                 }
  830.                 else
  831.                 {
  832.                         count = 0;
  833.                 }
  834.         } while (count < strlen(sendOk));
  835.  
  836.         uartReadBlock(); // CR
  837.         uartReadBlock(); // LF
  838.  
  839.         firstPacket = true;
  840.         do
  841.         {
  842.                 unsigned char temp[64];
  843.                 limiter.headLng = 0;
  844.                 todo = recvHead();
  845.  
  846.                 if (!getdataEsp(todo))
  847.                 {
  848.                         OS_CLS(0);
  849.                         puts("[getdataEsp]Downloading timeout. Exit!");
  850.                         delayLongKey(5000);
  851.                         exit(0);
  852.                 }
  853.  
  854.                 if (firstPacket)
  855.                 {
  856.                         firstPacket = false;
  857.                         limiter.headLng = cutHeader();
  858.                         todo = todo - limiter.headLng;
  859.                         fileSize1 = contLen / 1024;
  860.  
  861.                         if (!link.hasName)
  862.                         {
  863.                                 curWin.w = 66;
  864.                                 curWin.x = 39 - curWin.w / 2;
  865.                                 curWin.y = 9;
  866.                                 curWin.h = 1;
  867.                                 curWin.text = 103;
  868.                                 curWin.back = 103;
  869.  
  870.                                 strcpy(curWin.tittle, "Введите имя файла");
  871.                                 if (inputBox(curWin, link.fname))
  872.                                 {
  873.                                         strncpy(link.fname, cmd, 64);
  874.                                         strcat(link.fname, "\0");
  875.                                 }
  876.                         }
  877.                         if (httpErr != 200)
  878.                         {
  879.                                 sendcommand("AT+CIPCLOSE");
  880.                                 getAnswer3(); // CLOSED
  881.                                 getAnswer3(); // OK
  882.                                 mainWinDraw();
  883.                                 return false;
  884.                         }
  885.                         downDialog();
  886.                         OS_DELETE(link.fname);
  887.                         saveBuf(link.fname, 00, 0);
  888.                 }
  889.  
  890.                 downloaded = downloaded + todo;
  891.                 down = downloaded / 1024;
  892.                 OS_SETCOLOR(223);
  893.                 sprintf(temp, "%4u  of %4u kb", down, fileSize1);
  894.                 OS_SETXY(38 - strlen(temp) / 2, 11);
  895.                 puts(temp);
  896.                 saveBuf(link.fname, 01, todo);
  897.                 drawClock();
  898.         } while (downloaded < contLen);
  899.         sendcommand("AT+CIPCLOSE");
  900.         getAnswer3(); // CLOSED
  901.         getAnswer3(); // OK
  902.         mainWinDraw();
  903.         return true;
  904. }
  905.  
  906. char getFileNet(void)
  907. {
  908.         int todo, socket;
  909.         char firstPacket;
  910.  
  911.         unsigned int fileSize1;
  912.         unsigned long downloaded = 0;
  913.         unsigned int down;
  914.  
  915.         socket = OpenSock(AF_INET, SOCK_STREAM);
  916.         if (testOperation2("OS_NETSOCKET", socket) != 1)
  917.         {
  918.                 getchar();
  919.                 quit();
  920.         }
  921.  
  922.         todo = netConnect(socket, 1);
  923.         if (testOperation2("OS_NETCONNECT", todo) != 1)
  924.         {
  925.                 getchar();
  926.                 quit();
  927.         }
  928.  
  929.         todo = tcpSend(socket, (unsigned int)&link.path, strlen(link.path), 1);
  930.         if (testOperation2("OS_WIZNETWRITE", todo) != 1)
  931.         {
  932.                 getchar();
  933.                 quit();
  934.         }
  935.  
  936.         firstPacket = true;
  937.         do
  938.         {
  939.                 unsigned char temp[64];
  940.                 limiter.headLng = 0;
  941.                 todo = tcpRead(socket, 1);
  942.                 testOperation("OS_WIZNETREAD", todo);
  943.                 if (todo == 0)
  944.                 {
  945.                         break;
  946.                 }
  947.                 if (firstPacket)
  948.                 {
  949.                         firstPacket = false;
  950.                         limiter.headLng = cutHeader();
  951.                         todo = todo - limiter.headLng;
  952.                         fileSize1 = contLen / 1024;
  953.  
  954.                         if (!link.hasName)
  955.                         {
  956.                                 curWin.w = 66;
  957.                                 curWin.x = 39 - curWin.w / 2;
  958.                                 curWin.y = 9;
  959.                                 curWin.h = 1;
  960.                                 curWin.text = 103;
  961.                                 curWin.back = 103;
  962.  
  963.                                 strcpy(curWin.tittle, "Введите имя файла");
  964.                                 if (inputBox(curWin, link.fname))
  965.                                 {
  966.                                         strncpy(link.fname, cmd, 64);
  967.                                         strcat(link.fname, "\0");
  968.                                 }
  969.                         }
  970.                         if (httpErr != 200)
  971.                         {
  972.                                 netShutDown(socket, 0);
  973.                                 mainWinDraw();
  974.                                 return false;
  975.                         }
  976.                         downDialog();
  977.                         saveBuf(link.fname, 00, 0);
  978.                 }
  979.                 downloaded = downloaded + todo;
  980.                 down = downloaded / 1024;
  981.                 OS_SETCOLOR(223);
  982.                 sprintf(temp, "%4u  of %4u kb", down, fileSize1);
  983.                 OS_SETXY(38 - strlen(temp) / 2, 11);
  984.                 puts(temp);
  985.                 saveBuf(link.fname, 01, todo);
  986.                 drawClock();
  987.         } while (downloaded < contLen);
  988.  
  989.         netShutDown(socket, 0);
  990.  
  991.         if (downloaded != contLen)
  992.         {
  993.                 puts("File download error!");
  994.                 puts("File download error!");
  995.                 puts("File download error!");
  996.                 puts("File download error!");
  997.                 waitKey();
  998.         }
  999.         mainWinDraw();
  1000.         return true;
  1001. }
  1002.  
  1003. char getFile(unsigned char number)
  1004. {
  1005.         int result = 0;
  1006.         unsigned char option = 1;
  1007.  
  1008.         for (option = 1; option <= table[number].option; option++)
  1009.         {
  1010.                 sprintf(link.path, "GET /get/%lu/%u%s%s%s", table[number].id, option, userAgent1, link.host, userAgent2);
  1011.                 limiter.curOpt = option;
  1012.                 switch (netDriver)
  1013.                 {
  1014.                 case 0:
  1015.                         result = getFileNet();
  1016.                         break;
  1017.                 case 1:
  1018.                         result = getFileEsp();
  1019.                         break;
  1020.                 default:
  1021.                         break;
  1022.                 }
  1023.         }
  1024.         return result;
  1025. }
  1026.  
  1027. char makeRequestEsp(void)
  1028. {
  1029.  
  1030.         int todo;
  1031.         unsigned char byte, firstPacket;
  1032.         unsigned long downloaded = 0;
  1033.         unsigned int count;
  1034.         const unsigned char sendOk[] = "SEND OK";
  1035.  
  1036.         sprintf(cmd, "AT+CIPSTART=\"TCP\",\"%s\",%u", link.host, link.port);
  1037.         sendcommand(cmd);
  1038.  
  1039.         do
  1040.         {
  1041.                 getAnswer3(); // CONNECT or ERROR or link is not valid
  1042.  
  1043.                 if (strstr(netbuf, "CONNECT") != NULL)
  1044.                 {
  1045.                         break;
  1046.                 }
  1047.                 else
  1048.                 {
  1049.                         if (strstr(netbuf, "ERROR") != NULL)
  1050.                         {
  1051.                                 return false;
  1052.                         }
  1053.                 }
  1054.         } while (42); // Try until endo of the days recieve CONNECT or ERROR
  1055.  
  1056.         getAnswer3(); // OK
  1057.  
  1058.         sprintf(cmd, "AT+CIPSEND=%u", strlen(link.path) + 2);
  1059.         sendcommand(cmd);
  1060.         getAnswer3();
  1061.  
  1062.         do
  1063.         {
  1064.                 byte = uartReadBlock();
  1065.         } while (byte != '>');
  1066.  
  1067.         // sendcommandNrn(link.path);
  1068.         sendcommand(link.path);
  1069.  
  1070.         count = 0;
  1071.         do
  1072.         {
  1073.                 byte = uartReadBlock();
  1074.                 if (byte == sendOk[count])
  1075.                 {
  1076.                         count++;
  1077.                         // putchar(byte);
  1078.                 }
  1079.                 else
  1080.                 {
  1081.                         count = 0;
  1082.                 }
  1083.         } while (count < strlen(sendOk));
  1084.  
  1085.         uartReadBlock(); // CR
  1086.         uartReadBlock(); // LF
  1087.  
  1088.         firstPacket = true;
  1089.         do
  1090.         {
  1091.                 limiter.headLng = 0;
  1092.                 todo = recvHead();
  1093.                 getdataEsp(todo); // Requested size
  1094.                 if (firstPacket)
  1095.                 {
  1096.                         firstPacket = false;
  1097.                         limiter.headLng = cutHeader();
  1098.                         todo = todo - limiter.headLng;
  1099.  
  1100.                         if (httpErr != 200)
  1101.                         {
  1102.                                 sendcommand("AT+CIPCLOSE");
  1103.                                 getAnswer3(); // CLOSED
  1104.                                 getAnswer3(); // OK
  1105.                                 return false;
  1106.                         }
  1107.                 }
  1108.                 if (downloaded + todo > sizeof(buf))
  1109.                 {
  1110.                         printf("dataBuffer overrun... %lu reached \n\r", downloaded + todo);
  1111.                         return false;
  1112.                 }
  1113.                 memcpy(buf + downloaded, netbuf + limiter.headLng, todo);
  1114.                 downloaded = downloaded + todo;
  1115.         } while (downloaded < contLen);
  1116.  
  1117.         sendcommand("AT+CIPCLOSE");
  1118.         getAnswer3(); // CLOSED
  1119.         getAnswer3(); // OK
  1120.         buf[downloaded + 1] = 0;
  1121.         return downloaded;
  1122. }
  1123.  
  1124. char makeRequestNet(void)
  1125. {
  1126.         int socket, todo;
  1127.         char firstPacket;
  1128.         unsigned long downloaded = 0;
  1129.  
  1130.         if (!dnsResolve(link.host))
  1131.         {
  1132.                 clearStatus();
  1133.                 printf("Ошибка определения адреса '%s'", link.host);
  1134.                 return false;
  1135.         }
  1136.  
  1137.         targetadr.porth = link.port >> 8;
  1138.         targetadr.portl = link.port;
  1139.         // clearStatus();
  1140.         // printf("Connecting to %u.%u.%u.%u:%u", targetadr.b1, targetadr.b2, targetadr.b3, targetadr.b4, targetadr.porth * 256 + targetadr.portl);
  1141.  
  1142.         socket = OpenSock(AF_INET, SOCK_STREAM);
  1143.         if (testOperation2("OS_NETSOCKET", socket) != 1)
  1144.         {
  1145.                 getchar();
  1146.                 quit();
  1147.         }
  1148.  
  1149.         todo = netConnect(socket, 1);
  1150.         if (testOperation2("OS_NETCONNECT", todo) != 1)
  1151.         {
  1152.                 getchar();
  1153.                 quit();
  1154.         }
  1155.         todo = tcpSend(socket, (unsigned int)&link.path, strlen(link.path), 1);
  1156.         if (testOperation2("OS_WIZNETWRITE", todo) != 1)
  1157.         {
  1158.                 getchar();
  1159.                 quit();
  1160.         }
  1161.         firstPacket = true;
  1162.         do
  1163.         {
  1164.                 limiter.headLng = 0;
  1165.                 todo = tcpRead(socket, 1);
  1166.                 testOperation("OS_WIZNETREAD", todo); // Quit if too many retries
  1167.  
  1168.                 if (firstPacket)
  1169.                 {
  1170.                         firstPacket = false;
  1171.                         limiter.headLng = cutHeader();
  1172.                         todo = todo - limiter.headLng;
  1173.  
  1174.                         if (httpErr != 200)
  1175.                         {
  1176.                                 netShutDown(socket, 0);
  1177.                                 return false;
  1178.                         }
  1179.                 }
  1180.  
  1181.                 if (downloaded + todo > sizeof(buf))
  1182.                 {
  1183.                         printf("dataBuffer overrun... %lu reached \n\r", downloaded + todo);
  1184.                         return false;
  1185.                 }
  1186.                 memcpy(buf + downloaded, netbuf + limiter.headLng, todo);
  1187.                 downloaded = downloaded + todo;
  1188.         } while (downloaded != contLen); // ref < лучше
  1189.  
  1190.         netShutDown(socket, 0);
  1191.         buf[downloaded + 1] = 0;
  1192.         return downloaded;
  1193. }
  1194.  
  1195. char makeRequest(const char *request)
  1196. {
  1197.         char result;
  1198.         unsigned int counter, len;
  1199.         char tempreq[256];
  1200.  
  1201.         sendReqdialog();
  1202.  
  1203.         strcpy(tempreq, request);
  1204.         len = strlen(tempreq);
  1205.         for (counter = 0; counter < len; counter++)
  1206.         {
  1207.                 if (tempreq[counter] == ' ' || tempreq[counter] == '-')
  1208.                 {
  1209.                         tempreq[counter] = '*';
  1210.                 }
  1211.         }
  1212.         sprintf(link.path, "GET /?s=%s&p=%d%s%s%s", tempreq, limiter.curPage, userAgent1, link.host, userAgent2);
  1213.  
  1214.         switch (netDriver)
  1215.         {
  1216.         case 0:
  1217.                 result = makeRequestNet();
  1218.                 break;
  1219.         case 1:
  1220.                 result = makeRequestEsp();
  1221.                 break;
  1222.  
  1223.         default:
  1224.                 return false;
  1225.         }
  1226.  
  1227.         return result;
  1228. }
  1229.  
  1230. int findLimiters(int n)
  1231. {
  1232.         n = pos(buf, "^", 1, n + 1);
  1233.         if (n == -1)
  1234.         {
  1235.                 return -2;
  1236.         }
  1237.         limiter.first = n + 1;
  1238.         n = pos(buf, "^", 1, n + 1);
  1239.         if (n == -1)
  1240.         {
  1241.                 return -2;
  1242.         }
  1243.         limiter.second = n - 1;
  1244.         return n;
  1245. }
  1246. void fillTable(void)
  1247. {
  1248.         int counter = 0;
  1249.         limiter.second = -1;
  1250.         limiter.total = 0;
  1251.         do
  1252.         {
  1253.                 if (findLimiters(limiter.second) != -2)
  1254.                 {
  1255.                         table[counter].id = atol(buf + limiter.first);
  1256.                         limiter.total++;
  1257.                 }
  1258.  
  1259.                 if (findLimiters(limiter.second) != -2)
  1260.                 {
  1261.                         strncpy(table[counter].name, buf + limiter.first, limiter.second - limiter.first + 1);
  1262.                         strcat(table[counter].name, "\0");
  1263.                         table[counter].name[limiter.second - limiter.first + 1] = 0;
  1264.                 }
  1265.                 if (findLimiters(limiter.second) != -2)
  1266.                 {
  1267.                         strncpy(table[counter].file, buf + limiter.first, limiter.second - limiter.first - 3);
  1268.                         strcat(table[counter].file, "\0");
  1269.                         table[counter].file[limiter.second - limiter.first - 3] = 0;
  1270.                         strncpy(table[counter].ext, buf + limiter.second - 2, 3);
  1271.                         strcat(table[counter].ext, "\0");
  1272.                 }
  1273.  
  1274.                 if (findLimiters(limiter.second) != -2)
  1275.                 {
  1276.                         table[counter].size = atol(buf + limiter.first);
  1277.                 }
  1278.  
  1279.                 if (findLimiters(limiter.second) != -2)
  1280.                 {
  1281.                         table[counter].option = atoi(buf + limiter.first);
  1282.                 }
  1283.  
  1284.                 if (findLimiters(limiter.second) != -2)
  1285.                 {
  1286.                         table[counter].year = atoi(buf + limiter.first);
  1287.                 }
  1288.  
  1289.                 limiter.second++;
  1290.                 counter++;
  1291.         } while (counter < 12);
  1292. }
  1293.  
  1294. void renderResult(char currentLine)
  1295. {
  1296.         int counter, line = 2;
  1297.  
  1298.         for (counter = 0; counter < limiter.total; counter++)
  1299.         {
  1300.                 // printf("[%lu] ", table[counter].id);
  1301.  
  1302.                 if (counter == currentLine)
  1303.                 {
  1304.                         OS_SETCOLOR(121);
  1305.                         OS_SETXY(2, line);
  1306.                         spaces(76);
  1307.                         OS_SETXY(2, line + 1);
  1308.                         spaces(76);
  1309.                 }
  1310.                 else
  1311.                 {
  1312.                         if (counter % 2 == 0)
  1313.                         {
  1314.                                 OS_SETCOLOR(206);
  1315.                         }
  1316.                         else
  1317.                         {
  1318.                                 OS_SETCOLOR(207);
  1319.                         }
  1320.                 }
  1321.                 OS_SETXY(2, line);
  1322.                 spaces(76);
  1323.                 OS_SETXY(2, line);
  1324.                 printf("%s ", table[counter].name);
  1325.                 OS_SETXY(48, line);
  1326.                 printf("%s  %6lu  %u  %4u", table[counter].ext, table[counter].size, table[counter].option, table[counter].year);
  1327.                 line++;
  1328.                 OS_SETXY(2, line);
  1329.                 spaces(76);
  1330.                 OS_SETXY(5, line);
  1331.                 printf("%s ", table[counter].file);
  1332.                 line++;
  1333.         }
  1334.         OS_SETCOLOR(206);
  1335.         for (counter = limiter.total; counter < 10; counter++)
  1336.         {
  1337.                 OS_SETXY(2, line);
  1338.                 spaces(76);
  1339.                 line++;
  1340.                 OS_SETXY(2, line);
  1341.                 spaces(76);
  1342.                 line++;
  1343.         }
  1344. }
  1345.  
  1346. char getKey(void)
  1347. {
  1348.         char key;
  1349.         key = OS_GETKEY();
  1350.         switch (key)
  1351.         {
  1352.         case 27: // escape - exit
  1353.                 OS_CLS(0);
  1354.                 OS_SETGFX(-1);
  1355.                 exit(0);
  1356.                 break;
  1357.         case 's':
  1358.         case 'ы':
  1359.         case 'Ы':
  1360.         case 'S':
  1361.         fuckingoto:
  1362.                 limiter.total = 0;
  1363.                 limiter.curline = 0;
  1364.                 curWin.w = 40;
  1365.                 curWin.x = 80 / 2 - curWin.w / 2 - 1;
  1366.                 curWin.y = 10;
  1367.                 curWin.h = 1;
  1368.                 curWin.text = 103;
  1369.                 curWin.back = 103;
  1370.                 strcpy(curWin.tittle, "Введите поисковый запрос");
  1371.  
  1372.                 if (inputBox(curWin, ""))
  1373.                 {
  1374.                         strcpy(search, cmd);
  1375.                         limiter.curPage = 0;
  1376.                         drawSearch();
  1377.                 }
  1378.                 else
  1379.                 {
  1380.                         mainWinDraw();
  1381.                         OS_SETXY(32, 11);
  1382.                         OS_SETCOLOR(206);
  1383.                         puts("No results found");
  1384.                         limiter.total = 0;
  1385.                         limiter.curline = 0;
  1386.                         break;
  1387.                 }
  1388.  
  1389.                 if (makeRequest(search) < 2)
  1390.                 {
  1391.                         mainWinDraw();
  1392.                         OS_SETXY(32, 11);
  1393.                         OS_SETCOLOR(206);
  1394.                         puts("No results found");
  1395.                         limiter.total = 0;
  1396.                         limiter.curline = 0;
  1397.                         return key;
  1398.                 }
  1399.  
  1400.                 OS_SETXY(1, 2);
  1401.                 OS_SETCOLOR(206);
  1402.                 fillTable();
  1403.                 break;
  1404.         case 'h':
  1405.         case 'H':
  1406.         case 'р':
  1407.         case 'Р':
  1408.                 limiter.total = 0;
  1409.                 limiter.curline = 0;
  1410.                 curHost++;
  1411.                 if (curHost > 1)
  1412.                 {
  1413.                         curHost = 0;
  1414.                 }
  1415.                 strcpy(link.host, hosts[curHost]);
  1416.                 mainWinDraw();
  1417.                 break;
  1418.         case 'q':
  1419.         case 'Q':
  1420.         case 'Й':
  1421.         case 'й':
  1422.         case 250:
  1423.                 if (limiter.total != 0)
  1424.                 {
  1425.                         if (limiter.curline < 1)
  1426.                         {
  1427.                                 limiter.curline = limiter.total - 1;
  1428.                         }
  1429.                         else
  1430.                         {
  1431.                                 limiter.curline--;
  1432.                         }
  1433.                 }
  1434.                 break;
  1435.         case 'a':
  1436.         case 'A':
  1437.         case 'ф':
  1438.         case 'Ф':
  1439.         case 249:
  1440.                 if (limiter.total != 0)
  1441.                 {
  1442.                         if (limiter.curline > limiter.total - 2)
  1443.                         {
  1444.                                 limiter.curline = 0;
  1445.                         }
  1446.                         else
  1447.                         {
  1448.                                 limiter.curline++;
  1449.                         }
  1450.                 }
  1451.                 break;
  1452.         case 248: // left
  1453.         case 'o':
  1454.  
  1455.                 if (limiter.curPage != 0 && limiter.total != 0)
  1456.                 {
  1457.                         limiter.curPage--;
  1458.                         mainWinDraw();
  1459.                         if (makeRequest(search) < 2)
  1460.                         {
  1461.                                 OS_SETXY(32, 11);
  1462.                                 OS_SETCOLOR(206);
  1463.                                 puts("No results found");
  1464.                                 limiter.total = 0;
  1465.                                 limiter.curline = 0;
  1466.                                 break;
  1467.                         }
  1468.                         // OS_SETXY(1, 2);
  1469.                         // OS_SETCOLOR(206);
  1470.                         fillTable();
  1471.                         limiter.curline = 0;
  1472.                 }
  1473.                 break;
  1474.         case 251: // right
  1475.         case 'p':
  1476.                 if (limiter.total != 0)
  1477.                 {
  1478.                         limiter.curPage++;
  1479.                         mainWinDraw();
  1480.                         if (makeRequest(search) < 2)
  1481.                         {
  1482.                                 limiter.curPage--;
  1483.                                 drawPage();
  1484.                                 makeRequest(search);
  1485.                         }
  1486.                         // OS_SETXY(1, 2);
  1487.                         // OS_SETCOLOR(206);
  1488.                         fillTable();
  1489.                         limiter.curline = 0;
  1490.                 }
  1491.                 break;
  1492.         case 13:
  1493.                 if (limiter.total != 0)
  1494.                 {
  1495.                         getFile(limiter.curline);
  1496.                 }
  1497.                 else
  1498.                 {
  1499.                         goto fuckingoto;
  1500.                 }
  1501.                 break;
  1502.         default:
  1503.                 break;
  1504.         }
  1505.  
  1506.         if (key != 0)
  1507.         {
  1508.                 renderResult(limiter.curline);
  1509.         }
  1510.         else
  1511.         {
  1512.                 YIELD();
  1513.         }
  1514.         return key;
  1515. }
  1516.  
  1517. C_task main(int argc, const char *argv[])
  1518. {
  1519.         OS_HIDEFROMPARENT();
  1520.         OS_SETGFX(0x86);
  1521.         OS_CLS(0);
  1522.         OS_SETSYSDRV();
  1523.         printf("[Build:%s  %s]", __DATE__, __TIME__);
  1524.         init();
  1525.         // printTable();
  1526.         //  waitKey();
  1527.         OS_CLS(0);
  1528.         mainWinDraw();
  1529.  
  1530.         do
  1531.         {
  1532.                 getKey();
  1533.         } while (42);
  1534. }
  1535.