Hello guys, recently found Nim and very much interested in this language. I have written a program which use imghdr at https://github.com/achesak/nim-imghdr
But I can't compile the program. Can you guys tell me what I am doing wrong?
My code:
import os, imghdr, osproc
proc imagecheck(path:string) =
var f: File
var extensions = [".jpg", ".png", ".bmp", ".gif"]
if open(f, "falseimglist", fmReadWrite):
for fname in walkDirRec(path):
var extension = splitFile(fname)[2]
var imagetype = testImage(fname)
if extension in extensions:
if $imagetype == "Other":
f.write("This is not an image: ",fname)
close(f)
proc test_bmp(strng: string,filename: File, line: string) =
if find(strng, "BMP") == -1:
filename.write("This is not an image: " & line &"\n")
proc test_gif(strng: string, filename:File, line: string) =
if find(strng, "GIF") == -1:
test_bmp(strng, filename, line)
proc test_png(strng:string, filename:File, line: string) =
if find(strng, "PNG") == -1:
test_gif(strng, filename, line)
proc test_image_file(strng:string, filename:File, line:string) =
if find(strng, "JPEG") == -1:
test_png(strng, filename, line)
proc main(path:string) =
imagecheck(path)
var
command: string
output: string
f: File
f2: File
if open(f, "falseimglist", fmReadWrite):
if open(f2, "falseimglist2", fmReadWrite):
for line in f.lines:
var line2 = replace(line, "\n", "")
command = "file " & line2
var output_tuple = execCmdEx(command)
output = output_tuple[0]
test_image_file(output, f2, line2)
f.close()
f2.close()
removeFile("falseimglist")
var path = commandLineParams()[0]
main(path)
The error when compiling is
config/nim.cfg(53, 2) Hint: added path: '/home/d3vil/.babel/pkgs/' [Path]
config/nim.cfg(54, 2) Hint: added path: '/home/d3vil/.nimble/pkgs/aporia-0.2.0' [Path]
config/nim.cfg(54, 2) Hint: added path: '/home/d3vil/.nimble/pkgs/fcp-0.1.0' [Path]
config/nim.cfg(54, 2) Hint: added path: '/home/d3vil/.nimble/pkgs/cairo-1.0' [Path]
config/nim.cfg(54, 2) Hint: added path: '/home/d3vil/.nimble/pkgs/imghdr-0.1' [Path]
config/nim.cfg(54, 2) Hint: added path: '/home/d3vil/.nimble/pkgs/nimble-0.6.0' [Path]
config/nim.cfg(54, 2) Hint: added path: '/home/d3vil/.nimble/pkgs/gtk2-1.0' [Path]
config/nim.cfg(54, 2) Hint: added path: '/home/d3vil/.nimble/pkgs/' [Path]
Hint: used config file '/home/d3vil/Nim/config/nim.cfg' [Conf]
Hint: system [Processing]
Hint: imagecheckernim [Processing]
Hint: os [Processing]
Hint: strutils [Processing]
Hint: parseutils [Processing]
Hint: times [Processing]
Hint: posix [Processing]
Hint: imghdr [Processing]
Hint: osproc [Processing]
Hint: strtabs [Processing]
Hint: hashes [Processing]
Hint: streams [Processing]
Hint: cpuinfo [Processing]
Hint: linux [Processing]
lib/pure/osproc.nim(779, 6) Warning: raiseOSError is deprecated [Deprecated]
lib/pure/osproc.nim(701, 9) Hint: 'osproc.startProcessAuxSpawn(data: TStartProcessData)' is declared but not used [XDeclaredButNotUsed]
imagecheckernim.nim(18, 54) Warning: will be parsed as unary operator; inconsistent spacing is deprecated [Deprecated]
imagecheckernim.nim(17, 9) Info: template/generic instantiation from here
lib/system.nim(1914, 9) Error: type mismatch: got (char, string)
but expected one of:
system.==(x: set[T], y: set[T])
system.==(x: char, y: char)
system.==(x: T, y: T)
system.==(x: string, y: string)
system.==(x: bool, y: bool)
system.==(x: ptr T, y: ptr T)
system.==(x: TEnum, y: TEnum)
system.==(x: cstring, y: cstring)
system.==(x: pointer, y: pointer)
system.==(x: ref T, y: ref T)
system.==(x: int, y: int)
system.==(x: int8, y: int8)
system.==(x: int16, y: int16)
system.==(x: int32, y: int32)
system.==(x: int64, y: int64)
system.==(x: float32, y: float32)
system.==(x: float, y: float)
system.==(x: array[I, T], y: array[I, T])
system.==(x: seq[T], y: seq[T])
system.==(x: T, y: T)
os.==(err1: OSErrorCode, err2: OSErrorCode)