home *** CD-ROM | disk | FTP | other *** search
- #include "rn.ch"
- #include "inkey.ch"
- #include "fileio.ch"
-
-
- ? "RNindex version 1.0"
- ?
-
- if ! empty(gete("WAFFLE"))
- WafDir(strtran(upper(gete("WAFFLE")), "\STATIC"))
- else
- ask(" Error ", "Environment variable WAFFLE not set", {" OK "}, CLR_ERR)
- quit
- endif
-
- ReadJoin()
-
- ?
- ? "Finished!"
-
- RETURN
-
-
- PROCEDURE ReadJoin() // read join file
- LOCAL nChoice // selected newsgroup
- LOCAL cPath // path of newsgroup
- LOCAL aDir := {} // contains dir entries
- LOCAL nNgPtr := 1 // initial pos in ng array
- LOCAl aHdr
- LOCAL cSavDir // hold current dir
- LOCAL n
- LOCAL f
- LOCAl aGroups := NwsGrData()
- LOCAL aMsg := {}
-
- ? "Indexing "
-
- for nChoice := 1 to len(aGroups)
- nNgPtr := aGroups[nChoice,4]
-
- ?? token(alltrim(aGroups[nChoice,1])," ",1) + ", "
-
- cPath := NwsGrPath(token(ltrim(aGroups[nChoice,1])," ",1))
-
- if isdir(cPath) // goto newsgroup's dir
-
- asize(aDir, adir(cPath + "\*.*"))
- adir(cPath + "\*.*", aDir)
-
-
- // Read header info into array
-
- aMsg := {}
-
-
- for n := 1 to len( aDir )
-
- if aDir[n] != "INDEX.RN"
-
- aHdr := ReadHeader(cPath + "\" + aDir[n])
-
-
- aadd(aMsg, { aDir[n], aHdr[MSG_SUBJ], aHdr[MSG_FROM], ;
- aHdr[MSG_MSGID], aHdr[MSG_DATE] })
-
- endif
- next
-
- if len(aMsg) > 0
- asort(aMsg,,,{|x, y | ;
- strtran(lower(trim(x[2])), "re: ") + SortableDate(x[5]) ;
- < strtran(lower(trim(y[2])), "re: ") + SortableDate(y[5]) })
-
- f = fcreate( cPath + "\" + "index.rn" )
-
- for n := 1 to len(aMsg)
- fwriteline( f, aMsg[n, 1] + chr(K_TAB) +;
- aMsg[n, 2] + chr(K_TAB) + ;
- aMsg[n, 3] + chr(K_TAB) + ;
- aMsg[n, 4] + chr(K_TAB) + ;
- aMsg[n, 5] ;
- )
- next
-
- fclose( f )
- endif
- endif
-
- next
-
- RETURN
-
-
-
- FUNCTION ReadHeader(cFile) // read header and return as array
- LOCAL cLine
- LOCAL nMsg
- LOCAL aHeader := {cFile}
- LOCAL n := 0
- LOCAL cBuf := space(1024)
-
- asize(aHeader,11) // make an array
- afill(aHeader,"",2) // and initialize with spaces
-
- nMsg = fopen(cFile, FO_READ)
- fread(nMsg, cBuf, len(cBuf))
- fclose(nMsg)
-
- cBuf := strtran(cBuf, chr(9), space(4))
-
- aHeader[MSG_SUBJ] := GetLine("subject:", cBuf)
- aHeader[MSG_FROM] := GetLine("from:", cBuf)
- aHeader[MSG_PATH] := GetLine("path:", cBuf)
- aHeader[MSG_LINE] := GetLine("lines:", cBuf)
- aHeader[MSG_MSGID] := GetLine("message-id:", cBuf)
- aHeader[MSG_NWSG] := GetLine("newsgroups:", cBuf)
- aHeader[MSG_DATE] := GetLine("date:", cBuf)
- aHeader[MSG_ORG] := GetLine("organization:", cBuf)
- aHeader[MSG_FUT] := GetLine("followup-to:", cBuf)
- aHeader[MSG_REF] := GetLine("references:", cBuf)
-
- RETURN(aHeader)
-
-
- FUNCTION GetLine(cSrch, cBuf)
- LOCAL cStr := ""
- LOCAl nPos
-
- if (nPos := at(lower(cSrch), lower(cBuf))) > 0
- cStr := substr(substr(cBuf, nPos, at(CR_LF, substr(cBuf, nPos))-1), len(cSrch)+1)
- endif
- RETURN cStr
-
-
- FUNCTION NwsGrData
- STATIC aGroups := {} // array for groups
- LOCAL cLine
- LOCAL nUsenet
- LOCAl cNwsgr
-
- if len(aGroups) < 1
-
- ? "Retrieving newsgroups information"
-
- if (nUsenet := fopen(WafDir() + "\usenet")) # -1
- while ! feof(nUsenet)
-
- cNwsgr := alltrim(token(freadline( nUsenet ), " ", 1))
-
- if left(cNwsgr, 1) # "#" .and. ! empty(cNwsgr) .and. at("default", lower(cNwsgr)) # 1
- aadd(aGroups, {cNwsgr,{},0,0 })
- endif
- enddo
- endif
-
- fclose(nUsenet )
- ?
- endif
-
-
- RETURN (aGroups)
-
-
- FUNCTION NwsGrPath(cNwsGrp)
- LOCAL cPath := ""
- LOCAL n
- LOCAL fHandle
- LOCAL c
- LOCAL nPos
- STATIC aPath
-
- if aPath == NIL
- aPath := {}
- endif
-
- nPos := ascan(aPath, {|x| x[1] == cNwsGrp } )
-
- if nPos > 0
- cPath := aPath[nPos, 2]
- else
- fHandle := fopen ( WafDir() + "\usenet", FO_READ + FO_DENYWRITE)
- while ! feof( fHandle )
- c := freadline( fHandle )
- if left(c, 1) # "#"
- if token(c," ",1) == cNwsGrp
- if "/dir=" $ lower(c)
- nPos := at("/dir=", lower(c)) + 5
- cPath := token(substr(c, nPos), " ", 1)
- aadd(aPath, {cNwsGrp, cPath})
- exit
- else
- cPath := NewsDir()
- for n := 1 to numtoken(trim(cNwsGrp), ".")
- cPath += "\" + left(token(trim(cNwsGrp),".", n),8)
- next
- if right(cPath,1) == "\"
- cPath = substr(cPath, 1, len(cPath)-1)
- endif
- aadd(aPath, {cNwsGrp, cPath})
- exit
- endif
- endif
- endif
- enddo
- fClose ( fHandle )
- endif
-
- RETURN(cPath)
-
-
- FUNCTION NewsDir() // function to make the NEWS dir 'PUBLIC'
- STATIC cNewsDir
- LOCAL nUsenet
- LOCAL cLine := ""
-
- if cNewsDir == NIL
- nUsenet := fopen(WafDir()+"\usenet")
-
- while ! feof(nUsenet) ;
- .and. ! ("default /dir=" $ (cLine := lower(freadline(nUsenet))))
- enddo
-
- fclose(nUsenet)
-
- if "default /dir=" $ cLine
- cNewsDir := ltrim(strtran(strtran(cLine, "default /dir="),'"'))
- else
- ask(" Error ", " 'DEFAULT /dir='-line not found in " + WafDir() + "\usenet", { "OK" }, CLR_ERR)
- QUIT
- endif
-
- endif
- RETURN (cNewsDir)
-
-
-
- FUNCTION WafDir (cWaffle) // function to make the WAFFLE dir 'PUBLIC'
- STATIC cWafDir
- if cWaffle != NIL
- cWafDir := cWaffle
- endif
- RETURN (cWafDir)
-
- FUNCTION GetStatic(c)
- LOCAL cRet := ""
- LOCAL nStatic
- LOCAL cLine := ""
- STATIC aStatic := {}
- LOCAL nPos
-
- if (nStatic := fopen(WafDir() + "\static")) == -1
- ask("Error", "Error opening file " + WafDir() + "\static", {" OK "}, CLR_ERR)
- QUIT
- endif
-
- c:= lower(c)
-
- if (nPos := ascan(aStatic, {|x|x[1] == c})) > 0
- cRet := aStatic[nPos, 2]
- else
- while ! feof(nStatic)
- cLine := lower(freadline(nStatic))
- if substr(cLine,1,len(c)) == c
- EXIT
- endif
- enddo
-
- fclose(nStatic)
-
- if substr(cLine,1,len(c)) == c
- cRet := ltrim(strtran(substr(cLine, at(":",cLine)+1),"/","\"))
- aadd(aStatic, {c, cRet})
- else
- ask(" Error ", "'" +c + "'-line not found in " + WafDir() + "\static", { " OK " }, CLR_ERR)
- QUIT
- endif
- endif
-
- fclose(nStatic)
-
- RETURN cRet
-
- FUNCTION SortableDate ( cDate )
- LOCAL cRet
-
- if ! "," $ token(cDate, " ", 1)
- cDate := "# " + cDate
- endif
-
- cRet := if(len(token(cDate, " ", 4)) == 2, "19" + token(cDate, " ", 4), token(cDate, " ", 4) ) + ;
- strzero(ascan({ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", ;
- "Sep", "Oct", "Nov", "Dec"}, left(token(cDate, " ", 3), 3)), 2) + ;
- strzero(val(token(cDate, " ", 2)), 2) + ;
- strtran(token(cDate, " ", 5), ":")
-
- RETURN ( cRet )
-
-