--------------------------------- LDos V1(3) for AMOS1.3 and above. LDos is (C) Niklas Sjöberg 1992 --------------------------------- PART TWO - String commands and bufferhandling --------------------------------------------- Lstr - Get a string (line) from a bank. 1) A$=Lstr(START To MAX) where START is the address of a bank, and MAX the end of the bank (or the end of the file loaded). This function will begin at START, looking for an end-of-line-terminator (see below). When found, it will put the contents into A$. If no end-of-line- terminator is found, A$ will contain every character between START and MAX. The end-of-line-terminator is NOT copied into the string, so the new startaddress of the next line will be START+Len(A$)+1 Lstr - Get a string from a bank. 2) A$=Lstr(START,END) where A$ will contain every character between START and END. No checking for end-of-line is done and it is thus faster than the other syntax of this command. Mostly useful when processing text where "lines" have no meaning. ++ PLEASE NOTE THAT I HAVE MADE AN TYPO IN OLDER DOCS! END SHOULD ++ ACTUALLY BE _LENGTH_! A$=Lstr(START,10) will put 10 characters in ++ A$. Lset Eoln - Change end-of-line-terminator Lset Eoln NUM where NUM may range from 0 to 255. Default is 10, normal Amiga LineFeed. (Unlike AMOS which tends to use 13 for some reason (old habit from Atari ST?)) Example: Lset Eoln 13 A$=Lstr(_START,_MAX) : _START=START+Len(A$)+1 A$=A$-Chr$(10) : Rem remove Lf which AMOS use before CR. Lbstr - Copy a string to a bank Lbstr A$,START where START is a bankaddress where A$'s contents may be placed. No check is done to see whether the bufferlimit was exceeded or not so make sure there is room for the string. Example: Lbstr A$+Chr$(10),_START : _START=_START+Len(A$)+1 Lreplace - Hunt for a character and then replace it. Lreplace SEARCH,SWAP,START To STOP where START and STOP are the area to be scanned, SEARCH is an ASCII- value to search for. If SEARCH is found it will be replaced by the SWAP-value. Fx. Lreplace 9,Asc(" "),Start(10) To Start(10)+Length(10), will replace all tabs with spaces in bank number ten. Mostly useful when you want to convert specific unwanted characters, like CR (Carrige Return) or removing characters that you can't display or process. Lfilter - Replace within a specific range. Lfilter LOW,HIGH,SWAP,START To STOP. where START and STOP is the same as above, LOW and HIGH are the limits. Everything between LOW and HIGH (INCLUDING LOW and HIGH) will be replaced by SWAP. Fx. Lfilter Asc("a"),Asc("z"),Asc("- "),Start(10) To Start(10)+Length(10), will replace all lower-case characters with a minus "-" sign, leaving any other characters untouched. Very useful when parsing commandfiles. For instance you may let the user print comments anywhere in the file as long as this is done in CAPITAL letters. You then filter out all capitals and convert them to, say ASCII 0. Next when you use Lstr to be able to process the lines, just add a -Chr$(0) after it and all comments are masked out. Lskip - Find next character NOT being xx. ADR=Lskip(CHAR,START To STOP) where CHAR is the ASCII-value you want to skip, START is the startaddress of the bank, and STOP is the maxaddress where Lskip will end if it couldn't find a character which wasn't CHAR. ADR will contain the address AFTER the last CHAR. Useful if you for example would like to skip datas which have been filtered out by Lfilter of similar. ADR=Lskip(10,_START To _STOP) : Rem Skip empty lines. *- Lback Hunt - Find next character being xx, works backwards. *- ADR=Lback Hunt(CHAR,START To STOP) *- where *- CHAR is the character you wish to search for, START the *- position to start searching from and STOP the end-address. Note *- that START is greater than STOP since this routine works *- backwards. If you want to skip forwards the standard AMOS- *- function 'Hunt' is easier to use. This command is probably most *- useful in page/line-oriented applications, like a textdisplayer *- or the like. It was implemented since it is a real pain to use *- Hunt for backwards searching. Example: For I = 1 To 10 ADR=Lback Hunt(10,ADR To _STOP) Next Lupbuffer - Convert all characters to UPPER-case. Lupbuffer START To STOP where all characters between START and STOP will be converted to upper-case. Just like AMOS Upper$ this routine won't handle national characters (due to AMOS isn't using a standard keymap). Only A-Z and a-z are processed. Llowbuffer - Convert all characters to lower-case. Llowbuffer START To STOP. where everything works like above, but all characters will be converted to lower-case. *- Lmatch - Search for for patterns in strings using wildcards. *- L=Lmatch(SOURCE$,S$) THIS FUNCTION REQUIRES Release 2. *- where *- SOURCE$ is the string you want to search in and S$ contains *- the pattern. PLEASE NOTE THAT BOTH STRINGS MUST BE NULL- *- TERMINATED (+Chr$(0)). This routine is case-sensitive, so use *- Upper$ or Lower$ if required. Valid wildcards currently are : *- *- *- ? Matches a single character. *- # Matches the following expression 0 or more times. *- (ab|cd) Matches any one of the items seperated by '|'. *- ~ Negates the following expression. It matches all strings *- that do not match the expression (aka ~(foo) matches all *- strings that are not exactly "foo"). *- [abc] Character class: matches any of the characters in the class. *- [~bc] Character class: matches any of the characters not in the *- class. *- a-z Character range (only within character classes). *- % Matches 0 characters always (useful in "(foo|bar|%)"). *- * Synonym for "#?", not available by default in 2.0. Available *- as an option that can be turned on. *- "Expression" in the above table means either a single *- character (ex: "#?"), or an alternation (ex: "#(ab|cd|ef)"), or a *- character class (ex: "#[a-zA-Z]"). Example: See Lcat_pat* example. Useful for experimenting. -- Lwild - Find out if a string contains a valid wildcard -- TEST=Lwild(A$) -- THIS FUNCTION REQUIRES Release 2. -- where -- TEST will be false (zero) if A$ contains no wildcard(s), -- otherwise TEST may contain anything (usually 1). Always use Lwild -- before calling Lmatch to prevent Lmatch to cause an overflow- -- error. Example: If Lwild(A$) Then Gosub _MATCH *- Lwords - Count the number of words in a string. *- NUM=Lwords(STRING$) *- where *- NUM will contain the number of words in STRING$. Words are *- separated by either TAB (ASCII-value 9), comma (','), space or *- doublequote ('"'). If doublequotes aren't matched, all text from *- the first doublequote will be treated as one word. Two *- doublequotes without any text between them will be treated as *- one word (this is a 'NULL'-word, useful when for instance omit- *- ting a parameter). If there are more than one separator (TAB, *- SPACE, COMMA) following each other they will be ignored. You *- can thus not use ',,' to produce an empty word (use '""' in- *- stead). If STRING$ is empty zero is returned. *- Some examples (TAB means ASCII-value 9 which isn't visible): *- Lwords("TAB Hi,, this TAB is just me") -> 5 *- Lwords('Hi, "this is just" "" me') -> 4 *- Lwords('Hi "this is just" me') -> 3 *- Lwords('"Hi this is just me') -> 1 *- Do not confuse with Lword. *- Lword - Mask out any word of a string, without changing the *- source *- A$=Lword(WORD,STRING$) *- where *- WORD is the word you wish to extract. The first word in *- STRING$ is 1 (not zero) up to the value returned by Lwords.If you *- request a word which doesn't exist an error will be produced. The *- same rules as apply to Lwords applies here, with one exception *- which you might not expect: If a 'NULL'-word is specified ('""') *- an empty string will not be returned, but both the doublequotes *- will be returned. Even if there are text between the doublequotes *- they still are returned in A$. This makes it easy for the *- programmer to tell when more than one word (containing commas or *- tabs etc. just check Left$(A$,1) for '"') are to be regarded as *- ONE word. If only one doublequote is supplied the rest of A$ *- will be treated as one word. If the last character is a *- doublequote, only '"' will be returned. It is up to the *- programmer to decide how to handle this. It could be regarded as *- a 'NULL'-word, but in most cases it probably is a syntax error. *- If you do not wish TABs, spaces or commas to be treated as a word *- separator (or wish to be able to use more than one of them *- directly after each other) you simply quote the text and *- everything between the quotes will be untouched and regarded as *- one word. If WORD is zero an empty string will be returned CONTINUED IN NEXT ARTICLE.