Lhogho  0.0.027
Functions
lhogho.c File Reference

Functions

void use_stdout (chars_t string, int len)
 prints text to standard output
int use_stdeof ()
 returns eof status of standard output
char_t use_stdin ()
 reads a character
int main (int argc, char *argv[])

Function Documentation

void use_stdout ( chars_t  string,
int  len 
)
Parameters:
stringtext to print
lenlength of text

This is a call-back outter function for dumping atom contents to standard output.

{
  if( len==-1 ) len = STRLEN( string );
  //printf("len=%d\n",len);
  for( ; len>0; len--, string++ )
    {
      //printf("|%x|",*string);
      
      // ignore 0x0D (^M,CR) if not followed by 0x0A (^J,LF)
      int crlf = (DEBAR(*string)==0x0D) && (DEBAR(*(string+1))==0x0A);
      
      if( !crlf ) 
      {
        char_t wc[2];
        wc[0] = DEBAR(*string);
        wc[1] = 0;

        char* buf =(char*) UTF16_to_UTF8(wc);
        printf("%s",buf);
        //printf(" %x-",*string);
        /*
        switch ( strlen(buf) )
        {
          case 1: printf("%c",(char)buf[0]); break;
          case 2: printf("%c%c",(unsigned char)buf[0],(unsigned char)buf[1],(char)buf[0],(char)buf[1]); break;
          case 3: printf("%c%c%c",(char)buf[0],(char)buf[1],(char)buf[2]); break;
          case 4: printf("%c%c%c%c",(char)buf[0],(char)buf[1],(char)buf[2],(char)buf[3]); break;
          case 5: printf("%c%c%c%c%c",(char)buf[0],(char)buf[1],(char)buf[2],(char)buf[3],(char)buf[4]); break;
          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;
        }
        */
        DEALLOC( buf );
        //printf( "%S", wc );
      }
      // PUTCHAR( DEBAR(*string), stdout );
      //if( *string!=DEBAR(*string) )
      //PUTCHAR( TEXT('?'), stdout );
    }
}

This is a call-back inner_eof function for checking standard input.

{
  return feof(stdin)?1:0;
}

reads a character from standard input

Read a character from the hooked of file stream, which must be ASCII.

This is a call-back inner function for geting urser input.

{
  char_t ch;
  ch = GETCHAR( stdin );
  while( ch=='\r' ) ch = GETCHAR( stdin ); // remove ^M from input, keep ^J
  return ch;
}
int main ( int  argc,
char *  argv[] 
)
{
  int result;
  
  //fwide(stdout,1);
  setvbuf( stdin, NULL, _IONBF, 0 );
  
  #ifdef WINDOWS
    // Try to change the code page to UTF-8
    //if( system("chcp 65001 >nul")!=0 )
    //{
    //  system("chcp.com 65001 >nul");
    //}
    /*
    int i;
    printf("\n\npage c3: ");
    for( i=0x80; i<0xbf; i++ ) printf("%c%c",(char)0xc3,(char)i);
    printf("\n manual:");
    printf("%c%c",(char)0xc3,(char)0x9c);
    printf("%c%c",(char)0xc3,(char)0xbc);
    printf("%c%c",(char)0xc3,(char)0xa4);
    printf("%c%c",(char)0xc3,(char)0x9f);
    */
  #endif
  
  //printf("1. initialization\n");
  init_compiler( use_stdout, use_stdin, use_stdeof );
  //__asm__ volatile ("int $3");
  //printf("2. options\n");
  
  set_options( argc, argv );
  //printf("3. compile\n");
  result = compile_from_options( );
  if( !result && 
      !OPTION_MAKE_EXECUTABLE &&
      !OPTION_MAKE_EXECUTABLE_COMPILER &&
      IS_NOT_EMPTY(BODY(root)) ) 
    {
       //printf("4. run\n");
       result = run_function( root );
    }

   //printf("5. finalization\n");
   finit_compiler( );
  #ifdef WINDOWS
    // Try to change the code page to UTF-8
//    if( system("chcp 850 >nul")!=0 )
//    {
//      system("chcp.com 850 >nul");
//    }
    //int i;
    //printf("\n\npage c3: ");
    //for( i=0x80; i<0xbf; i++ ) printf("%c%c",(char)0xc3,(char)i);
    //printf("\n manual:");
    //printf("%c%c",(char)0xc3,(char)0x9c);
    //printf("%c%c",(char)0xc3,(char)0xbc);
    //printf("%c%c",(char)0xc3,(char)0xa4);
    //printf("%c%c",(char)0xc3,(char)0x9f);
  #endif
  
   //printf("6. end\n");
    //printf("\n\n");
    //printf("%c%c",(char)0xc3,(char)0x9c);
    //printf("%c%c",(char)0xc3,(char)0xbc);
    //printf("%c%c",(char)0xc3,(char)0xa4);
    //printf("%c%c",(char)0xc3,(char)0x9f);

    //printf("\n\npage c3: ");
    //for( i=0x80; i<0xbf; i++ ) printf("%c%c",(char)0xc3,(char)i);
    //printf("\n manual:");
    //printf("%c%c",(char)0xc3,(char)0x9c);
    //printf("%c%c",(char)0xc3,(char)0xbc);
    //printf("%c%c",(char)0xc3,(char)0xa4);
    //printf("%c%c",(char)0xc3,(char)0x9f);
    return result;
}

[ HOME | INDEX | ATOMS | VARS | REFERENCE ]
Lhogho Developer's Documentation
Tue Feb 7 2012