picoc/picoc.c
zik.saleeba 86af5318da Bulko lexer change for more efficient pre-scanned tokens.
Removed Str type - replaced with standard C strings.
Added hashed string tables for efficient string storage.


git-svn-id: http://picoc.googlecode.com/svn/trunk@43 21eae674-98b7-11dd-bd71-f92a316d2d60
2009-02-01 11:31:18 +00:00

72 lines
1.5 KiB
C

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include "picoc.h"
/* all platform-dependent code is in this file */
void ProgramFail(struct ParseState *Parser, const char *Message, ...)
{
va_list Args;
if (Parser != NULL)
printf("%s:%d: ", Parser->FileName, Parser->Line);
va_start(Args, Message);
vprintf(Message, Args);
printf("\n");
exit(1);
}
/* read a file into memory */
char *ReadFile(const char *FileName)
{
struct stat FileInfo;
char *ReadText;
FILE *InFile;
if (stat(FileName, &FileInfo))
ProgramFail(NULL, "can't read file %s\n", FileName);
ReadText = HeapAlloc(FileInfo.st_size);
if (ReadText == NULL)
ProgramFail(NULL, "out of memory\n");
InFile = fopen(FileName, "r");
if (InFile == NULL)
ProgramFail(NULL, "can't read file %s\n", FileName);
if (fread(ReadText, 1, FileInfo.st_size, InFile) != FileInfo.st_size)
ProgramFail(NULL, "can't read file %s\n", FileName);
fclose(InFile);
return ReadText;
}
/* read and scan a file for definitions */
void ScanFile(const char *FileName)
{
char *SourceStr = ReadFile(FileName);
Parse(FileName, SourceStr, TRUE);
HeapFree(SourceStr);
}
int main(int argc, char **argv)
{
if (argc < 2)
ProgramFail(NULL, "Format: picoc <program.c> <args>...\n");
HeapInit();
StrInit();
ParseInit();
ScanFile(argv[1]);
return 0;
}