Lhogho  0.0.028
 All Data Structures Files Functions Variables Typedefs Macros Pages
lhogho.c
Go to the documentation of this file.
1 //
2 // Project: Lhogho
3 // File: lhogho.c
4 //
5 // Copyright (C) 2007 P.Boytchev
6 //
7 // Revision history:
8 // 2006-10-13 - file created
9 // 2007-05-17 - added license info
10 // 2007-07-05 - fixed bug #1745932 Memory leak in print (3+[8 9])
11 // 2012-01-02 - Command-line options are translatable
12 // 2012-01-13 - Fixed bug #3446798 char 13 ignored
13 //
14 //
15 // This program is free software; you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation; either version 2 of the License, or
18 // (at your option) any later version.
19 //
20 // This program is distributed in the hope that it will be useful,
21 // but WITHOUT ANY WARRANTY; without even the implied warranty of
22 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 // GNU General Public License for more details.
24 //
25 // You should have received a copy of the GNU General Public License
26 // along with this program; if not, write to the Free Software
27 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 //
29 
30 
31 #include "globals.h"
32 #include <unistd.h> // getcwd()
33 #ifdef UNICODE_CHARS
34  #include <wchar.h> // UNICODE support: wcslen()
35 #endif //UNICODE_CHARS
36 #include <stdio.h>
37 #include <stdlib.h>
38 
39 #include <assert.h>
40 #include "atoms.h"
41 #include "unicode.h"
42 #include "mems.h"
43 #include "vars.h"
44 #include "lists.h"
45 #include "options.h"
46 #include "compiler.h"
47 #include "errors.h"
48 #include "parser.h"
49 #include "translate.h"
50 
51 
61 void use_stdout( chars_t string, int len )
62 {
63  if( len==-1 ) len = STRLEN( string );
64  //printf("len=%d\n",len);
65  for( ; len>0; len--, string++ )
66  {
67  //printf("|%x|",*string);
68 
69  // ignore 0x0D (^M,CR) if not followed by 0x0A (^J,LF)
70  int crlf = (DEBAR(*string)==0x0D) && (DEBAR(*(string+1))==0x0A);
71 
72  if( !crlf )
73  {
74  char_t wc[2];
75  wc[0] = DEBAR(*string);
76  wc[1] = 0;
77 
78  char* buf =(char*) UTF16_to_UTF8(wc);
79  printf("%s",buf);
80  //printf(" %x-",*string);
81  /*
82  switch ( strlen(buf) )
83  {
84  case 1: printf("%c",(char)buf[0]); break;
85  case 2: printf("%c%c",(unsigned char)buf[0],(unsigned char)buf[1],(char)buf[0],(char)buf[1]); break;
86  case 3: printf("%c%c%c",(char)buf[0],(char)buf[1],(char)buf[2]); break;
87  case 4: printf("%c%c%c%c",(char)buf[0],(char)buf[1],(char)buf[2],(char)buf[3]); break;
88  case 5: printf("%c%c%c%c%c",(char)buf[0],(char)buf[1],(char)buf[2],(char)buf[3],(char)buf[4]); break;
89  case 6: printf("%c%c%c%c%c%c",(char)buf[0],(char)buf[1],(char)buf[2],(char)buf[3],(char)buf[4],(char)buf[5]); break;
90  }
91  */
92  DEALLOC( buf );
93  //printf( "%S", wc );
94  }
95  // PUTCHAR( DEBAR(*string), stdout );
96  //if( *string!=DEBAR(*string) )
97  //PUTCHAR( TEXT('?'), stdout );
98  }
99 }
100 
101 
110 {
111  return feof(stdin)?1:0;
112 }
113 
114 
123 {
124  char_t ch;
125  ch = GETCHAR( stdin );
126  while( ch=='\r' ) ch = GETCHAR( stdin ); // remove ^M from input, keep ^J
127  return ch;
128 }
129 
130 
131 
132 int main( int argc, char *argv[] )
133 {
134  int result;
135 
136  //fwide(stdout,1);
137  setvbuf( stdin, NULL, _IONBF, 0 );
138 
139  #ifdef WINDOWS
140  // Try to change the code page to UTF-8
141  //if( system("chcp 65001 >nul")!=0 )
142  //{
143  // system("chcp.com 65001 >nul");
144  //}
145  /*
146  int i;
147  printf("\n\npage c3: ");
148  for( i=0x80; i<0xbf; i++ ) printf("%c%c",(char)0xc3,(char)i);
149  printf("\n manual:");
150  printf("%c%c",(char)0xc3,(char)0x9c);
151  printf("%c%c",(char)0xc3,(char)0xbc);
152  printf("%c%c",(char)0xc3,(char)0xa4);
153  printf("%c%c",(char)0xc3,(char)0x9f);
154  */
155  #endif
156 
157  //printf("1. initialization\n");
159  //__asm__ volatile ("int $3");
160  //printf("2. options\n");
161 
162  set_options( argc, argv );
163  //printf("3. compile\n");
164  result = compile_from_options( );
165 
166  if( !result &&
169  IS_NOT_EMPTY(BODY(root)) )
170  {
171  //printf("4. run\n");
172  result = run_function( root );
173  }
174 
175  //printf("5. finalization\n");
176  finit_compiler( );
177  #ifdef WINDOWS
178  // Try to change the code page to UTF-8
179 // if( system("chcp 850 >nul")!=0 )
180 // {
181 // system("chcp.com 850 >nul");
182 // }
183  //int i;
184  //printf("\n\npage c3: ");
185  //for( i=0x80; i<0xbf; i++ ) printf("%c%c",(char)0xc3,(char)i);
186  //printf("\n manual:");
187  //printf("%c%c",(char)0xc3,(char)0x9c);
188  //printf("%c%c",(char)0xc3,(char)0xbc);
189  //printf("%c%c",(char)0xc3,(char)0xa4);
190  //printf("%c%c",(char)0xc3,(char)0x9f);
191  #endif
192 
193  //printf("6. end\n");
194  //printf("\n\n");
195  //printf("%c%c",(char)0xc3,(char)0x9c);
196  //printf("%c%c",(char)0xc3,(char)0xbc);
197  //printf("%c%c",(char)0xc3,(char)0xa4);
198  //printf("%c%c",(char)0xc3,(char)0x9f);
199 
200  //printf("\n\npage c3: ");
201  //for( i=0x80; i<0xbf; i++ ) printf("%c%c",(char)0xc3,(char)i);
202  //printf("\n manual:");
203  //printf("%c%c",(char)0xc3,(char)0x9c);
204  //printf("%c%c",(char)0xc3,(char)0xbc);
205  //printf("%c%c",(char)0xc3,(char)0xa4);
206  //printf("%c%c",(char)0xc3,(char)0x9f);
207  return result;
208 }
209 
210 

[ HOME | INDEX | ATOMS | VARS | REFERENCE ]
Lhogho Developer's Documentation
Wed Jul 10 2013