Skip to content

Commit

Permalink
Merge pull request #55 from dmcoles/v5.5.0
Browse files Browse the repository at this point in the history
V5.5.0
  • Loading branch information
dmcoles authored Jun 6, 2022
2 parents a3d6eb1 + 883ea12 commit 2d920b6
Show file tree
Hide file tree
Showing 23 changed files with 9,798 additions and 3,550 deletions.
618 changes: 407 additions & 211 deletions ACP.e

Large diffs are not rendered by default.

252 changes: 138 additions & 114 deletions MiscFuncs.e
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,25 @@
MODULE 'dos/dos','dos/dosextens','dos/datetime'
MODULE '*axenums','*axconsts','*axobjects','*errors'

EXPORT PROC setSingleFDS(fds:PTR TO LONG,socketVal)
DEF i,n

n:=(socketVal/32)
IF (n<0) OR (n>=32) THEN Raise(ERR_FDSRANGE)

FOR i:=0 TO 31 DO fds[i]:=0
fds[n]:=fds[n] OR (Shl(1,socketVal AND 31))
ENDPROC

EXPORT PROC setFDS(fds:PTR TO LONG,socketVal)
DEF n

n:=(socketVal/32)
IF (n<0) OR (n>=32) THEN Raise(ERR_FDSRANGE)

fds[n]:=fds[n] OR (Shl(1,socketVal AND 31))
ENDPROC

EXPORT PROC getFileSize(s: PTR TO CHAR)
/* returns the file size of a given file or 8192 if an error occured */
DEF fBlock: fileinfoblock
Expand Down Expand Up @@ -85,53 +104,73 @@ EXPORT PROC makeIntList(src:PTR TO CHAR)
res:=List(m)
FOR i:=0 TO StrLen(src)-1
IF src[i]=","
listAdd2(res,Val(tmp))
ListAddItem(res,Val(tmp))
StrCopy(tmp,'')
ELSE
strAddChar(tmp,src[i])
StrAddChar(tmp,src[i])
ENDIF
ENDFOR
IF StrLen(tmp)>0
listAdd2(res,Val(tmp))
ListAddItem(res,Val(tmp))
ENDIF

DisposeLink(tmp)

ENDPROC res

EXPORT PROC strCmpi(test1: PTR TO CHAR, test2: PTR TO CHAR, len)
/* case insensitive string compare */
DEF i,l1,l2

IF len=ALL
l1:=StrLen(test1)
l2:=StrLen(test2)
IF l1<>l2 THEN RETURN FALSE
len:=l1
ENDIF
EXPORT PROC upperChars(s:PTR TO CHAR)
DEF c
WHILE s[]<>0
c:=s[]
IF (c>="a") AND (c<="z") THEN s[]:=c AND $DF
s++
ENDWHILE
ENDPROC

FOR i:=0 TO len-1
IF charToLower(test1[i])<>charToLower(test2[i]) THEN RETURN FALSE
EXPORT PROC removeSlashes(str:PTR TO CHAR)
DEF s,i
s:=String(StrLen(str))
FOR i:=0 TO StrLen(str)-1
CONT str[i]="/"
StrAddChar(s,str[i])
ENDFOR
ENDPROC TRUE
StrCopy(str,s)
DisposeLink(s)
ENDPROC

EXPORT PROC midStr2(dest,src,pos,len)
IF len>0 THEN MidStr(dest,src,pos,len) ELSE StrCopy(dest,'')
ENDPROC

EXPORT PROC charToLower(c)
/* convert a given char to lowercase */
DEF str[1]:STRING
str[0]:=c
LowerStr(str)
ENDPROC str[0]
EXPORT PROC stringCompare(nam: PTR TO CHAR,pat: PTR TO CHAR)
DEF p,loop=TRUE

WHILE loop
IF LowerChar(nam[0])=LowerChar(pat[0])
IF nam[0]=0 THEN RETURN RESULT_SUCCESS
nam++
pat++
ELSEIF (pat[0]="?") AND (nam[0]<>0)
nam++
pat++
ELSE
loop:=FALSE
ENDIF
ENDWHILE

IF pat[0]<>"*" THEN RETURN RESULT_FAILURE

EXPORT PROC charToUpper(c)
/* convert a given char to uppercase */
DEF str[1]:STRING
str[0]:=c
UpperStr(str)
ENDPROC str[0]
WHILE pat[0]="*"
pat++
IF pat[0]=0 THEN RETURN RESULT_SUCCESS
ENDWHILE

FOR p:=StrLen(nam)-1 TO 0 STEP -1
IF LowerChar(nam[p]) = LowerChar(pat[0])
IF stringCompare(nam+p,pat) = RESULT_SUCCESS THEN RETURN RESULT_SUCCESS
ENDIF
ENDFOR
ENDPROC RESULT_FAILURE

/* trim spaces from both ends of a string and puts it in the destination estring*/
EXPORT PROC fullTrim(src:PTR TO CHAR,dest:PTR TO CHAR)
Expand Down Expand Up @@ -175,7 +214,7 @@ EXPORT PROC findAssign(name: PTR TO CHAR)
Forbid()
WHILE(devicelist.next)
bStrC(devicelist.name,temp2)
IF(strCmpi(temp2,temp,ALL)/* && devicelist->dl_Type!=DLT_DEVICE*/)
IF(StriCmp(temp2,temp)/* && devicelist->dl_Type!=DLT_DEVICE*/)
Permit()
RETURN 0
ENDIF
Expand All @@ -199,11 +238,6 @@ PROC bStrC(bstr: PTR TO CHAR,outbuf: PTR TO CHAR)
ENDFOR
ENDPROC

EXPORT PROC listAdd2(list:PTR TO LONG, v)
ListAdd(list,[0])
list[ListLen(list)-1]:=v
ENDPROC

/*must be called with EString*/
EXPORT PROC removeCR(str:PTR TO CHAR)
DEF i,n=0
Expand Down Expand Up @@ -237,6 +271,18 @@ PROC asmputchar()
MOVE.B D0,(A3)+
ENDPROC

EXPORT PROC dateStampToDateTime(datestamp:PTR TO datestamp) IS (Mul(Mul(datestamp.days+2922,1440),60)+(datestamp.minute*60)+(datestamp.tick/50))+21600

EXPORT PROC dateTimeToDateStamp(dateVal,datestamp:PTR TO datestamp)
dateVal:=dateVal-21600

datestamp.tick:=(dateVal-Mul(Div(dateVal,60),60))
datestamp.tick:=Mul(datestamp.tick,50)
dateVal:=Div(dateVal,60)
datestamp.days:=Div((dateVal),1440)-2922 ->-2922 days between 1/1/70 and 1/1/78
datestamp.minute:=dateVal-(Mul(datestamp.days+2922,1440))
ENDPROC

EXPORT PROC formatUnsignedLong(val,outStr)
DEF outputTxt[10]:ARRAY OF CHAR

Expand All @@ -250,14 +296,8 @@ EXPORT PROC formatLongDate(cDateVal,outDateStr)
DEF datestr[10]:STRING
DEF dateVal

dateVal:=cDateVal-21600

d:=dt.stamp
d.tick:=(dateVal-Mul(Div(dateVal,60),60))
d.tick:=Mul(d.tick,50)
dateVal:=Div(dateVal,60)
d.days:=Div((dateVal),1440)-2922 ->-2922 days between 1/1/70 and 1/1/78
d.minute:=dateVal-(Mul(d.days+2922,1440))
dateTimeToDateStamp(cDateVal,d)

dt.format:=FORMAT_USA
dt.flags:=0
Expand All @@ -277,14 +317,8 @@ EXPORT PROC formatLongTime(cDateVal,outDateStr)
DEF time[10]:STRING
DEF dateVal

dateVal:=cDateVal-21600

d:=dt.stamp
d.tick:=(dateVal-Mul(Div(dateVal,60),60))
d.tick:=Mul(d.tick,50)
dateVal:=Div(dateVal,60)
d.days:=Div((dateVal),1440)-2922 ->-2922 days between 1/1/70 and 1/1/78
d.minute:=dateVal-(Mul(d.days+2922,1440))
dateTimeToDateStamp(cDateVal,d)

dt.format:=FORMAT_USA
dt.flags:=0
Expand All @@ -306,14 +340,8 @@ EXPORT PROC formatLongDateTime(cDateVal,outDateStr)
DEF timestr[10]:STRING
DEF dateVal

dateVal:=cDateVal-21600

d:=dt.stamp
d.tick:=(dateVal-Mul(Div(dateVal,60),60))
d.tick:=Mul(d.tick,50)
dateVal:=Div(dateVal,60)
d.days:=Div((dateVal),1440)-2922 ->-2922 days between 1/1/70 and 1/1/78
d.minute:=dateVal-(Mul(d.days+2922,1440))
dateTimeToDateStamp(cDateVal,d)

dt.format:=FORMAT_DOS
dt.flags:=0
Expand All @@ -335,14 +363,8 @@ EXPORT PROC formatCDateTime(cDateVal,outDateStr)
DEF timestr[10]:STRING
DEF dateVal

dateVal:=cDateVal-21600

d:=dt.stamp
d.tick:=(dateVal-Mul(Div(dateVal,60),60))
d.tick:=Mul(d.tick,50)
dateVal:=Div(dateVal,60)
d.days:=Div((dateVal),1440)-2922 ->-2922 days between 1/1/70 and 1/1/78
d.minute:=dateVal-(Mul(d.days+2922,1440))
dateTimeToDateStamp(cDateVal,d)

dt.format:=FORMAT_DOS
dt.flags:=0
Expand All @@ -363,14 +385,8 @@ EXPORT PROC formatLongDateTime2(cDateVal,outDateStr,seperatorChar)
DEF timestr[10]:STRING
DEF dateVal

dateVal:=cDateVal-21600

d:=dt.stamp
d.tick:=(dateVal-Mul(Div(dateVal,60),60))
d.tick:=Mul(d.tick,50)
dateVal:=Div(dateVal,60)
d.days:=Div((dateVal),1440)-2922 ->-2922 days between 1/1/70 and 1/1/78
d.minute:=dateVal-(Mul(d.days+2922,1440))
dateTimeToDateStamp(cDateVal,d)

dt.format:=FORMAT_USA
dt.flags:=0
Expand All @@ -384,13 +400,51 @@ EXPORT PROC formatLongDateTime2(cDateVal,outDateStr,seperatorChar)
ENDIF
ENDPROC FALSE

EXPORT PROC decodeDateStr(datestr:PTR TO CHAR)
DEF dtstr[20]:STRING
DEF y=0,m=0,d=0

StrCopy(dtstr,datestr)

dtstr[2]:=" "
dtstr[5]:=" "
m:=Val(dtstr)
d:=Val(dtstr+3)
y:=Val(dtstr+6)

IF (y<100) AND (y>TWODIGITYEARSWITCHOVER) THEN y:=1900+y ELSE y:=2000+y
ENDPROC m,d,y

EXPORT PROC encodeDate(m,d,y)
DEF dt : datetime
DEF datestr[20]:STRING
DEF r
DEF ds:PTR TO datestamp
StringF(datestr,'\z\r\d[2]-\z\r\d[2]-\z\r\d[2]',m,d,Mod(y,100))

dt.format:=FORMAT_USA
dt.flags:=0
dt.strday:=0
dt.strtime:=0
dt.strdate:=datestr
r:=StrToDate(dt)
ds:=dt.stamp
ds.minute:=0
ds.tick:=0
ENDPROC dateStampToDateTime(ds)

->returns a numeric value of the date suitable for comparing to other dates
EXPORT PROC getDateCompareVal(datestr:PTR TO CHAR)
DEF month,day,year
DEF dtstr[20]:STRING

month:=Val(datestr)
day:=Val(datestr+3)
year:=Val(datestr+6)
StrCopy(dtstr,datestr)
dtstr[2]:=" "
dtstr[5]:=" "

month:=Val(dtstr)
day:=Val(dtstr+3)
year:=Val(dtstr+6)

IF (year>TWODIGITYEARSWITCHOVER) THEN year:=1900+year ELSE year:=2000+year

Expand All @@ -399,46 +453,36 @@ ENDPROC Mul(year,10000)+Mul(month,100)+day
EXPORT PROC isupper(c)
ENDPROC (c>="A") AND (c<="Z")

->returns system date converted to c time format
EXPORT PROC getSystemDate()
EXPORT PROC fastSystemTime()
DEF currDate: datestamp
DEF startds:PTR TO datestamp
DEF s4

startds:=DateStamp(currDate)

s4:=(Mul(Mul(startds.days+2922,1440),60)+(startds.minute*60)+(startds.tick/50))+21600
->2922 days between 1/1/70 and 1/1/78
ENDPROC Mul(Div(s4,86400),86400)
ENDPROC Mul(startds.minute,3000)+startds.tick

->returns system time converted to c time format
EXPORT PROC getSystemTime()
->returns system date converted to c time format
EXPORT PROC getSystemDate()
DEF currDate: datestamp
DEF startds:PTR TO datestamp
DEF s4

startds:=DateStamp(currDate)
->2922 days between 1/1/70 and 1/1/78

ENDPROC (Mul(Mul(startds.days+2922,1440),60)+(startds.minute*60)+(startds.tick/50))+21600,Mod(startds.tick,50)
s4:=dateStampToDateTime(startds)
->s4:=(Mul(Mul(startds.days+2922,1440),60)+(startds.minute*60)+(startds.tick/50))+21600
->2922 days between 1/1/70 and 1/1/78
ENDPROC Mul(Div(s4,86400),86400)

->returns system time converted to c time format and ticks
EXPORT PROC getSystemTime2()
EXPORT PROC getSystemTime()
DEF currDate: datestamp
DEF startds:PTR TO datestamp
DEF s1,s2,s3,s4

startds:=DateStamp(currDate)

s1:=startds.days+2922
s1:=Mul(1440,s1)
s1:=Mul(60,s1)
s2:=Mul(60,startds.minute)
s3:=startds.tick/50
s4:=Mul(Mul(startds.days+2922,1440),60)+(startds.minute*60)+(startds.tick/50)

->2922 days between 1/1/70 and 1/1/78

ENDPROC s4+21600,Mod(startds.tick,50)
ENDPROC (Mul(Mul(startds.days+2922,1440),60)+(startds.minute*60)+(startds.tick/50))+21600,Mod(startds.tick,50)

EXPORT PROC fileWriteLn(fh,str: PTR TO CHAR)
DEF stat
Expand All @@ -452,26 +496,6 @@ EXPORT PROC fileWrite(fh,str: PTR TO CHAR)
IF s<>StrLen(str) THEN RETURN RESULT_FAILURE
ENDPROC RESULT_SUCCESS

EXPORT PROC strCpy(dest: PTR TO CHAR, source: PTR TO CHAR, len)
DEF c,endfound=FALSE
DEF i
IF len=ALL
AstrCopy(dest,source,ALL)
ELSE
FOR i:=0 TO len-1
c:=source[i]
IF (c=0) OR (i=(len-1)) THEN endfound:=TRUE
IF endfound THEN c:=0
dest[i]:=c
ENDFOR
ENDIF
ENDPROC

EXPORT PROC strAddChar(dest,source)
StrAdd(dest,' ')
dest[EstrLen(dest)-1]:=source
ENDPROC

EXPORT PROC countSpaces(str:PTR TO CHAR)
DEF i,count=0

Expand Down Expand Up @@ -616,7 +640,7 @@ EXPORT PROC parsePatternNoCase2(source:PTR TO CHAR,dest:PTR TO CHAR, len)
s:=String(c)
FOR i:=0 TO StrLen(source)-1
StrCopy(t,source+i,1)
IF InStr('()|~[]%',t)>=0 THEN strAddChar(s,39)
IF InStr('()|~[]%',t)>=0 THEN StrAddChar(s,39)
StrAdd(s,t)
ENDFOR
r:=ParsePatternNoCase(s,dest,len)
Expand Down
Loading

0 comments on commit 2d920b6

Please sign in to comment.