-------------------------------------------------------------------------------
-- SCLPL Distribution Build Configuration
-------------------------------------------------------------------------------
-solution "SCLPL Distribtution"
+solution "SCLPL Distribution"
configurations { "Release" }
targetdir "build"
--- /dev/null
+#include <stdio.h>
+#include "file.h"
+
+int Line = 1;
+int Column = 1;
+char* Name = NULL;
+FILE* Handle = NULL;
+
+bool file_open(char* fname)
+{
+ Line = 0;
+ Column = 0;
+ Name = fname;
+ if (NULL == Name)
+ {
+ Handle = stdin;
+ }
+ else
+ {
+ printf("%s\n",fname);
+ Handle = fopen(fname,"r");
+ }
+ return (NULL != Handle);
+}
+
+void file_close(void)
+{
+ fclose(Handle);
+}
+
+bool file_eof(void)
+{
+ bool ret = true;
+ if (NULL != Handle)
+ {
+ ret = feof( Handle );
+ }
+ return ret;
+}
+
+char file_get(void)
+{
+ char ret = EOF;
+ if (NULL != Handle)
+ {
+ ret = fgetc(Handle);
+ if ('\n' == ret)
+ {
+ Line++;
+ Column = 1;
+ }
+ else
+ {
+ Column++;
+ }
+ }
+ return ret;
+}
+
+int file_line(void)
+{
+ return Line;
+}
+
+int file_column(void)
+{
+ return Column;
+}
+
+char* file_name(void)
+{
+ return (NULL != Name) ? Name : "<stdin>";
+}
+
+#include <stdio.h>
#include "gc.h"
+#include "file.h"
+
+int lex_files(int argc, char** argv);
+int lex_input(FILE* outfile);
int main(int argc, char** argv)
{
- /* init the collector */
- int foo;
- gc_set_stack_base(&foo);
-
- /* main program */
+ int ret;
+ if (argc > 1)
+ {
+ ret = lex_files(argc,argv);
+ }
+ else
+ {
+ file_open(NULL);
+ ret = lex_input(stdout);
+ file_close();
+ }
+ return ret;
+}
+int lex_files(int argc, char** argv)
+{
+ int ret = 0;
+ int i;
+ for (i = 1; i < argc; i++)
+ {
+ if (file_open(argv[i]))
+ {
+ fprintf(stdout, "@file %s\n", file_name());
+ ret = lex_input(stdout);
+ file_close();
+ }
+ else
+ {
+ fprintf(stderr, "@error File not found: %s\n", argv[i]);
+ ret = 1;
+ break;
+ }
+ }
+ return ret;
+}
- /* shutdown the collector */
- gc_shutdown();
- return 0;
+int lex_input(FILE* outfile)
+{
+ int ret = 0;
+ while (!file_eof())
+ {
+ char ch = file_get();
+ fprintf(stdout,"%s %d %d %c\n","char",file_line(),file_column(),ch);
+ }
+ return ret;
}