8.5. generrh.pl

[<<<] [>>>]

This script reads the files `errors.def', `build.txt' and creates the files `errcodes.c' and `include/error.bas'

The file `errors.def' contains the used error symbols in an easy to maintain text format.

The souce code of the file `generrh.pl' is:

open(OUT,">errcodes.c") or die "Can not output errcodes.c";
open(BAS,">include/error.bas") or die "Can nor output include/error.bas";
print BAS <<BASEND;
' This file was automatically generated by the program generrh.pl
' using the error code definition file errors.def from the
' ScriptBasic distribution
'
' This file is part of the ScriptBasic distribution and is
' specific to the actual build it was shipped. Do not use
' this file for any version or build of the ScriptBasic
' interpreter other than the one this file was shipped.
'
' THIS FILE IS FOR V1.0 BUILD @$BUILD
'
Global Const sbErrorOK = 0
Global Const sbErrorMemory = 1
print OUT <<END;
/* 
FILE: errcodes.c
HEADER: errcodes.h
TO_HEADER:
@$module = '';
@$CurrentErrorCode = 2;
@$LastErrorCode = 0;
@$TextHashes = {};
@$ErrorType = 0; # 0 is compile type, 1 is run time error
  next if /^\s*\#/;
  if( /\%CT\s*@$/ ){
    @$ErrorType = 0;
    next;
    }
  }
close F;
print OUT "typedef struct { char *language; char **array; } tErrorMessageArray;\n";
print OUT "extern tErrorMessageArray ErrorMessageArray[];\n";
print OUT "*/\n";
while( (@$language,@$array) = each %{@$TextHashes} ){
  @$TextHashes->{@$language}->[0] = "SUCCESS";
  print OUT "char *@${language}_error_messages[] ={\n";
  for( @$i = 0 ; @$i < @$CurrentErrorCode ; @$i++ ){
    print OUT '"',@$TextHashes->{@$language}->[@$i],'"',",\n";
    }
  print OUT "NULL\n};\n";
  }


[<<<] [>>>]