Subversion Repositories NedoOS

Rev

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