Converting text to integers
- Posted by James Harris <blackdog at CDC.NET> Dec 14, 1996
- 1562 views
Hello all, I need a little help. I'm trying to parse out a BLASTER environment setting with the getenv function. I am sucessful with that but I can't seem to be able to covert the values from the string to an integer or atom. I.E. "A255 I5 D3". I can parse out the 255, 5 and 3 but I can't convert them to integers (The ouput of the program is in text right now for debug purposes) include get.e global constant TRUE = 1, FALSE= 0, FAIL = -1, ENVIRONOK=1, DMACHANNEL=2, BASEPORT=3, IRQNUMBER=4, DSPVERSION=5 function CheckBlasterEnviron() --See if the Blaster enviroment is set. object environ environ = getenv("BLASTER") if length(environ) = 0 then --trival case, exists but nothing there return FAIL end if return environ end function function GetBlasterInfo() --get the Blaster Information and return a sequence with the information. sequence BlasterInfo, TempVal object env atom BasePort, IRQ integer IsMatch env = CheckBlasterEnviron() BlasterInfo = repeat(0,5) if atom(env) = -1 then return FAIL else IsMatch = 0 IsMatch = match("A",env) if IsMatch > 0 then BlasterInfo[BASEPORT]=env[IsMatch+1..IsMatch+3] IsMatch = 0 end if IsMatch = match("I",env) if IsMatch > 0 then BlasterInfo[IRQNUMBER]=env[IsMatch+1..IsMatch+1] IsMatch = 0 end if IsMatch = match("D",env) if IsMatch > 0 then BlasterInfo[DMACHANNEL]=env[IsMatch+1..IsMatch+1] IsMatch = 0 end if BlasterInfo[ENVIRONOK]=TRUE return BlasterInfo end if end function object a, c a=CheckBlasterEnviron() if atom(a) = FAIL then puts(1,"Blaster not set") else c=GetBlasterInfo() puts(1,"Blaster String is " & a & "\n") puts(1,"DMA Address is " & c[BASEPORT] & "\n") puts(1,"IRQ is " & c[IRQNUMBER] & "\n") puts(1,"DMA Channel is " & c[DMACHANNEL] & "\n") end if abort(1)