Rev 7141 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 7141 | Rev 7845 | ||
---|---|---|---|
Line 2... | Line 2... | ||
2 | 2 | ||
3 | #include |
3 | #include |
4 | #include |
4 | #include |
Line 5... | Line -... | ||
5 | #include |
- | |
6 | 5 | #include |
|
7 | #if defined(__TINYC__) |
- | |
8 | #include |
6 | |
9 | #define printf con_printf /* siemargl for smaller @tinyC */ |
7 | #include |
Line 10... | Line 8... | ||
10 | #endif |
8 | |
11 | char *ExplainErr(int code); |
9 | char *ExplainErr(int code); |
Line 18... | Line 16... | ||
18 | /* File input/output function macros (adjust for C++ framework) */ |
16 | /* File input/output function macros (adjust for C++ framework) */ |
19 | #define FileType FILE* |
17 | #define FileType FILE* |
20 | #define IoFileClose(fi) fclose(fi) |
18 | #define IoFileClose(fi) fclose(fi) |
21 | #define InFileChar(fi) CfileRead(fi) |
19 | #define InFileChar(fi) CfileRead(fi) |
22 | #define OutFileChar(fi,ch) fputc(ch,fi) |
20 | #define OutFileChar(fi,ch) fputc(ch,fi) |
23 | #define ScreenChar(ch) printf("%c",ch) |
21 | #define ScreenChar(ch) con_printf("%c",ch) |
24 | #define KeyInChar (char)getchar() |
22 | #define KeyInChar (char)getchar() |
25 | #define NeedsEcho true |
23 | #define NeedsEcho true |
26 | #define BreakTest Broken |
24 | #define BreakTest Broken |
Line 27... | Line 25... | ||
27 | 25 | ||
Line 123... | Line 121... | ||
123 | inFile = NULL;} |
121 | inFile = NULL;} |
124 | else { |
122 | else { |
125 | Ouch(ch); /* echo input to screen (but not output file) */ |
123 | Ouch(ch); /* echo input to screen (but not output file) */ |
126 | return ch;}} |
124 | return ch;}} |
127 | ch = KeyInChar; /* get input from stdin */ |
125 | ch = KeyInChar; /* get input from stdin */ |
128 | if (ch == 0) exit(0); /* Kolibri specific - our window was killed */ |
- | |
Line -... | Line 126... | ||
- | 126 | ||
- | 127 | // ---Leency |
|
- | 128 | // int __stdcall con_getch(void); |
|
- | 129 | // For normal characters function returns ASCII-code. |
|
- | 130 | // For extended characters (eg, Fx, and arrows), first function call |
|
- | 131 | // returns 0 and second call returns the extended code (similar to the |
|
- | 132 | // DOS-function input). Starting from version 7, after closing the |
|
- | 133 | // console window, this function returns 0. |
|
- | 134 | if (ch == 0) { |
|
- | 135 | ch = (char)con_getch(); |
|
- | 136 | if (ch == 0) exit(0); /* Kolibri specific - user closed window */ |
|
- | 137 | return 0; /* Do not show anything on press extchar */ |
|
- | 138 | } |
|
129 | 139 | ||
130 | if (ch==13) printf ("\n"); |
140 | if (ch==13) con_printf ("\n"); |
131 | if (ch==8) printf ("\b "); |
141 | if (ch==8) con_printf ("\b "); |
132 | if (NeedsEcho) ScreenChar(ch); /* alternative input may need this */ |
142 | if (NeedsEcho) ScreenChar(ch); /* alternative input may need this */ |
133 | if (oFile != NULL) OutFileChar(oFile,ch); /* echo it to output file */ |
143 | if (oFile != NULL) OutFileChar(oFile,ch); /* echo it to output file */ |
134 | if (ch == '\n') { |
144 | if (ch == '\n') { |
135 | ch = '\r'; /* convert line end to TB standard */ |
145 | ch = '\r'; /* convert line end to TB standard */ |
Line 802... | Line 812... | ||
802 | /* sequence is [not] output. */ |
812 | /* sequence is [not] output. */ |
803 | case 39: |
813 | case 39: |
804 | InLend = InLine; |
814 | InLend = InLine; |
805 | while (true) { /* read input line characters... */ |
815 | while (true) { /* read input line characters... */ |
806 | ch = Inch(); |
816 | ch = Inch(); |
- | 817 | if (!ch) continue; |
|
807 | if (ch=='\r') break; /* end of the line */ |
818 | else if (ch=='\r') break; /* end of the line */ |
808 | else if (ch=='\t') { |
819 | else if (ch=='\t') { |
809 | Debugging = (Debugging+DEBUGON)&1; /* maybe toggle debug */ |
820 | Debugging = (Debugging+DEBUGON)&1; /* maybe toggle debug */ |
810 | ch = ' ';} /* convert tabs to space */ |
821 | ch = ' ';} /* convert tabs to space */ |
811 | else if (ch==(char)Core[BScode]) { /* backspace code */ |
822 | else if (ch==(char)Core[BScode]) { /* backspace code */ |
812 | if (InLend>InLine) InLend--; /* assume console already */ |
823 | if (InLend>InLine) InLend--; /* assume console already */ |
Line 1436... | Line 1447... | ||
1436 | oFile = NULL; |
1447 | oFile = NULL; |
1437 | inFile = NULL;} /* ~StartTinyBasic */ |
1448 | inFile = NULL;} /* ~StartTinyBasic */ |
Line 1438... | Line 1449... | ||
1438 | 1449 | ||
1439 | int main(int argc, char* argv[]) { |
1450 | int main(int argc, char* argv[]) { |
1440 | /* CONSOLE_INIT("TinyBasic"); */ |
- | |
1441 | #if defined(__TINYC__) |
1451 | /* CONSOLE_INIT("TinyBasic"); */ |
1442 | if (con_init_console_dll()) return 1; // init fail |
1452 | if (con_init_console_dll()) return 1; // init fail |
Line 1443... | Line 1453... | ||
1443 | #endif |
1453 | con_set_title("TinyBasic"); |
1444 | 1454 | ||
1445 | int nx; |
1455 | int nx; |
1446 | long int len; |
1456 | long int len; |
Line 1457... | Line 1467... | ||
1457 | len = len/8+len; /* allow for line end expansion */ |
1467 | len = len/8+len; /* allow for line end expansion */ |
1458 | IL = (char*)malloc(len+1); |
1468 | IL = (char*)malloc(len+1); |
1459 | if (IL != NULL) len = fread(IL,1,len,tmpFile); |
1469 | if (IL != NULL) len = fread(IL,1,len,tmpFile); |
1460 | IL[len] = '\0'; |
1470 | IL[len] = '\0'; |
1461 | IoFileClose(tmpFile);}} |
1471 | IoFileClose(tmpFile);}} |
1462 | else printf("Could not open file %s", argv[nx]);} |
1472 | else con_printf("Could not open file %s", argv[nx]);} |
1463 | else if (strcmp(argv[nx],"-o")==0 && ++nx |
1473 | else if (strcmp(argv[nx],"-o")==0 && ++nx |
1464 | oFile = fopen(argv[nx],"w"); |
1474 | oFile = fopen(argv[nx],"w"); |
1465 | else if (strcmp(argv[nx],"-i")==0 && ++nx |
1475 | else if (strcmp(argv[nx],"-i")==0 && ++nx |
1466 | inFile = fopen(argv[nx],"r"); |
1476 | inFile = fopen(argv[nx],"r"); |
1467 | else if (inFile==NULL) /* default (unadorned) is also input file */ |
1477 | else if (inFile==NULL) /* default (unadorned) is also input file */ |