diff --git a/FileManager.Mod b/FileManager.Mod index 73d19a4..d3761ea 100644 --- a/FileManager.Mod +++ b/FileManager.Mod @@ -1,5 +1,11 @@ MODULE FileManager; -IMPORT Files, Out, Logger; +IMPORT Files, Out, Logger, Strings; + +PROCEDURE WriteString(VAR r : Files.Rider; str : ARRAY OF CHAR); +BEGIN + Files.WriteBytes(r, str, Strings.Length(str)); + Logger.Log(str); +END WriteString; PROCEDURE Read*(fileName: ARRAY OF CHAR; VAR returnString: ARRAY OF CHAR): BOOLEAN; VAR @@ -29,9 +35,32 @@ BEGIN RETURN TRUE; END Read; -PROCEDURE Write*(); +PROCEDURE Write*(fileName, content: ARRAY OF CHAR): BOOLEAN; +VAR + f: Files.File; + r: Files.Rider; + i: LONGINT; BEGIN + f := Files.New(fileName); + IF f = NIL THEN + Logger.Log("-------------------"); + Logger.Log("File Name"); + Logger.Log(fileName); + Logger.Log("File not found"); + Logger.Log("-------------------"); + RETURN FALSE + END; + + Files.Set(r, f, 0); + Logger.Log("Writing to file"); + Logger.Log(fileName); + Logger.Log("-------------------"); + WriteString(r, content); + + Files.Register(f); + + RETURN TRUE; END Write; END FileManager. \ No newline at end of file diff --git a/JsonParser.Mod b/JsonParser.Mod index b26ff96..be3fb9e 100644 --- a/JsonParser.Mod +++ b/JsonParser.Mod @@ -186,7 +186,7 @@ BEGIN END Create; BEGIN - NEW(jsonRecord); + (* NEW(jsonRecord); jsonRecord := Create("{'foo': 'bar', 'test': 'test1', 'test2': {'sub': 'dub'}}"); keyFound := jsonRecord.GetTerminal(jsonRecord, "foo", testValue); @@ -194,6 +194,5 @@ BEGIN IF keyFound THEN Logger.Log('found KEY'); Logger.Log(testValue); - ELSE Logger.Log('Value for the Key is not found') END; - + ELSE Logger.Log('Value for the Key is not found') END; *) END JsonParser. \ No newline at end of file diff --git a/PackageFileParser.Mod b/PackageFileParser.Mod index fb5aeab..84a5e75 100644 --- a/PackageFileParser.Mod +++ b/PackageFileParser.Mod @@ -2,21 +2,28 @@ MODULE PackageFileParser; IMPORT JsonParser, FileManager, + http, Logger; CONST - MAXARRAYNUMBER = 1000; + MAXARRAYNUMBER = 1000000; PROCEDURE install*; VAR - fileData: ARRAY MAXARRAYNUMBER OF CHAR; - successfullyParsed: BOOLEAN; + fileData, buff, buff2: ARRAY MAXARRAYNUMBER OF CHAR; + success: BOOLEAN; BEGIN Logger.Log("Starting install process"); - successfullyParsed := FileManager.Read("VersionFile.json", fileData); + success := FileManager.Read("VersionFile.json", fileData); - IF ~successfullyParsed THEN Logger.Log("Some ERROR occured while reading VERSIONFILE") END; - ASSERT(successfullyParsed); + IF ~success THEN Logger.Log("Some ERROR occured while reading VERSIONFILE") END; + ASSERT(success); - Logger.Log(fileData); + http.get("norayr.am", "/tmp/", "80", buff); + http.getClean(buff, buff2); + + success := FileManager.Write("index.html", buff2); + + IF ~success THEN Logger.Log("Some ERROR occured while writing to test gile") END; + ASSERT(success) END install; BEGIN diff --git a/http.Mod b/http.Mod index d49b88a..8406bdd 100644 --- a/http.Mod +++ b/http.Mod @@ -10,7 +10,7 @@ TYPE VAR buff, buff2: ARRAY MAXARRAYNUMBEREXTENDED OF CHAR; -PROCEDURE getClean(buff: ARRAY OF CHAR; VAR clean: ARRAY OF CHAR); +PROCEDURE getClean *(buff: ARRAY OF CHAR; VAR clean: ARRAY OF CHAR); VAR i: INTEGER; newLine: ARRAY 2 OF CHAR; @@ -76,7 +76,7 @@ BEGIN UNTIL ORD(val[i]) = 10; (* 0DX number(newline)*) END getHeader; -PROCEDURE get(host, path, port: ARRAY OF CHAR; VAR buff: ARRAY OF CHAR); +PROCEDURE get *(host, path, port: ARRAY OF CHAR; VAR buff: ARRAY OF CHAR); VAR socket : Internet.Socket; connectionFlag: BOOLEAN; @@ -127,7 +127,7 @@ BEGIN END get; BEGIN - get("norayr.am", "/tmp/", "80", buff); + (* get("norayr.am", "/tmp/", "80", buff); getClean(buff, buff2); - Logger.Log(buff2); + Logger.Log(buff2); *) END http. \ No newline at end of file diff --git a/makefile b/makefile index 4257108..c6de8fe 100644 --- a/makefile +++ b/makefile @@ -7,7 +7,7 @@ test: clean copy-version-file-to-build-dir all run copy-version-file-to-build-dir: cp ./$(VERSION_FILE) ./builds/$(VERSION_FILE) -all: +all: http cd builds && \ $(VOC) -s \ ../time.Mod \ @@ -35,5 +35,4 @@ http: clean ../sockets.Mod \ ../netdb.Mod \ ../Internet.Mod \ - ../http.Mod -m \ - && ./http \ No newline at end of file + ../http.Mod diff --git a/opium.Mod b/opium.Mod index 68e6dff..5ee61fc 100644 --- a/opium.Mod +++ b/opium.Mod @@ -19,13 +19,12 @@ PROCEDURE parseArgs(VAR argument: ARRAY OF CHAR); BEGIN COPY("", argument); IF Args.argc > 1 THEN Args.Get(1, argument) END; - END parseArgs; BEGIN parseArgs(command); - IF Strings.Match(command, "") THEN + IF Strings.Match(command, "") OR Strings.Match(command, "--help")THEN help; ELSIF Strings.Match(command, "install") THEN PackageFileParser.install();