📄 strings.hhf
字号:
#if( ! @defined( string_hhf ))?string_hhf := true;#includeOnce( "hla.hhf" )#includeOnce( "stdio.hhf" )#includeOnce( "zstrings.hhf" )#includeOnce( "os.hhf" )// buf_t-//// "buffer" data type. A "buffer" string is one that consists of a pointer to the// start of the string data and a second pointer to the byte just beyond the end// of the string data.//// At some point, there should be a "buf" namespace and this declaration should then// be moved to the corresponding buf.hhf header file.type buf_t: record startPtr :dword; // This order must be preserved to match endPtr :dword; // buf ptrs pushed on the stack. endrecord; namespace str; /* ** Note: HLA strings consist of a pointer that points at ** a zero terminated array of characters. This array of ** characters is at least four bytes long and is always an ** even multiple of four characters long. ** ** The eight bytes immediately before this pointer ** contain the maximum length and the current dynamic length ** of the string data. ** ** The strRec record provides a template for such a string. ** The strData field is specified as an array of 12 characters ** to ensure that the size of this structure is 12 bytes (the ** "-8" starting offset reduces the size of the record by ** eight bytes, so this is corrected in the strData field). ** If you have a pointer to an "strRec" record, the pointer ** should be pointing at the strData field. Then you can use ** the MaxStrLen and length fieldnames to access those fields ** at the appropriate negative offsets. */ type strRec: record := -8; // MaxStrLen changed to maxlen! union MaxStrLen :dword; maxlen :dword; endunion; length :dword; strData :char[12]; endrecord; const BytesBeforeStr := 8; // str.constant( literal_constant ) // // This macro creates a string constant object whose address // you may assign to a string variable. This is useful, for // example, when initializing fields of a record with string data. #macro constant( __strconst ):__strname,__padding; forward( __strname ); align(4); dword @length( __strconst ), @length( __strconst ); __strname:char; @nostorage; byte __strconst, 0; ?__padding := ((4 - ((@length( __strconst ) + 1) mod 4)) mod 4); #while( __padding > 0 ) byte 0; ?__padding -= 1; #endwhile #endmacro // str.strvar- Allocates storage for a static string in // the HLA STATIC section. #macro strvar( strsize ): _strVar_; #if( ( @section & hla.inStatic ) != hla.inStatic ) #error( "str.strvar is legal only in the STATIC section" ) string // To prevent cascading errors #elseif( !@IsConst( strsize ) | !hla.isNumber( strsize ) ) #error( "Expected an integer constant string size" ); string // To prevent cascading errors #else string := &_strVar_; dword strsize; dword 0; _strVar_: char[ ( strsize + 4 ) & -4 ] := [(( strsize + 4 ) & -4 ) dup [#0] ] #endif #endmacro // str.init- Initializes a block of memory for use as // a string variable. Returns the pointer // to the string object in EAX. Note that // the numBytes parameter specifies the // total number of bytes in the block of // memory, not the desired maximum string // length. This value should be at least // 16 greater than the desired maximum // string length. procedure init( var b:var; numBytes:dword ); @returns( "(type string eax)" ); @external( "STR_INIT" ); // String length functions and macros. procedure length( s:string ); @returns( "eax" ); @external( "STR_LENGTH" ); // String Assignment and copy functions. procedure a_cpy( src:string ); @returns( "(type string eax)" ); @external( "STR_A_CPY" ); procedure cpy( src:string; dest:string ); @returns( "(type string eax)" ); @external( "STR_CPY" ); procedure cpyz( zstr:zstring; dest:string ); @external( "STR_CPYZ" ); procedure a_cpyz( zstr:zstring ); @returns( "(type string eax)" ); @external( "STR_A_CPYZ" ); procedure a_setstr( src:char; count:uns32 ); @returns( "(type string eax)" ); @external( "STR_A_SETSTR" ); procedure setstr ( src:char; cnt:uns32; dest:string ); @external( "STR_SETSTR" ); const a_bufToStr :text := "str.a_bufToStr2"; procedure a_bufToStr2( startBuf:dword; endBuf:dword ); @returns( "(type string eax)" ); @external( "STR_A_BUFTOSTR2" ); procedure a_bufToStr1( buf:@global:buf_t ); @returns( "(type string eax)" ); @external( "STR_A_BUFTOSTR2" ); // Yes, STR_A_BUFTOSTR2 const bufToStr :text := "str.bufToStr3"; procedure bufToStr2( buf:@global:buf_t; dest:string ); @external( "STR_BUFTOSTR3" ); // Yes, STR_BUFTOSTR3 procedure bufToStr3( startBuf:dword; endBuf:dword; dest:string ); @external( "STR_BUFTOSTR3" ); // Substring functions: procedure substr ( src :string; start :dword; len :dword; dest :string ); @returns( "@c" ); @external( "STR_SUBSTR" ); procedure a_substr ( src :string; start :dword; len :dword ); @returns( "@c" ); // and EAX @external( "STR_A_SUBSTR" ); #macro first( parms[] ); hla.overload( parms ) hla.signature( str.first2(string, dword) ) hla.signature( str.first3(string, dword, string) ) hla.endoverload #endmacro procedure first2 ( s :string; len :dword ); @returns( "@c" ); @external( "STR_FIRST2" ); procedure first3 ( s :string; len :dword; dest :string ); @returns( "@c" ); @external( "STR_FIRST3" ); procedure a_first ( src: string; len: dword ); @returns( "@c" ); @external( "STR_A_FIRST" ); #macro last( parms[] ); hla.overload( parms ) hla.signature( str.last2(string, dword) ) hla.signature( str.last3(string, dword, string) ) hla.endoverload #endmacro procedure last2 ( s: string; len: dword ); @returns( "@c" ); @external( "STR_LAST2" ); procedure last3 ( s :string; len :dword; dest :string ); @returns( "@c" ); @external( "STR_LAST3" ); procedure a_last ( src: string; len: dword ); @returns( "@c" ); @external( "STR_A_LAST" ); #macro truncate( parms[] ); hla.overload( parms ) hla.signature( str.truncate2(string, dword) ) hla.signature( str.truncate3(string, dword, string) ) hla.endoverload #endmacro procedure truncate2( dest:string; rmvlen:dword ); @returns( "@c" ); @external( "STR_TRUNCATE2" ); procedure truncate3( src:string; rmvlen:dword; dest:string ); @returns( "@c" ); @external( "STR_TRUNCATE3" ); procedure a_truncate( src:string; rmvlen:dword ); @returns( "@c" ); @external( "STR_A_TRUNCATE" ); // String insertion and deletion functions #macro insert( parms[] ); hla.overload( parms ) hla.signature( str.insert3(string, dword, string) ) hla.signature( str.insert4(string, dword, string, string) ) hla.endoverload #endmacro procedure insert3 ( ins :string; start :dword; dest :string ); @external( "STR_INSERT3" ); procedure insert4 ( ins :string; start :dword; src :string; dest :string ); @external( "STR_INSERT4" ); procedure a_insert ( ins :string; start :dword; src :string ); @returns( "(type string eax)" ); @external( "STR_A_INSERT" ); #macro delete( parms[] ); hla.overload( parms ) hla.signature( str.delete3(string, dword, dword) ) hla.signature( str.delete4(string, dword, dword, string) ) hla.endoverload #endmacro procedure delete3 ( s :string; start :dword; len :dword ); @returns( "@c" ); @external( "STR_DELETE3" ); procedure delete4 ( s :string; start :dword; len :dword; dest :string ); @returns( "@c" ); @external( "STR_DELETE4" ); procedure a_delete ( s: string; start: dword; len: dword ); @returns( "@c" ); @external( "STR_A_DELETE" ); #macro delLeadingSpaces( parms[] ); hla.overload( parms ) hla.signature( str.delLeadingSpaces1(string) ) hla.signature( str.delLeadingSpaces2(string, string) ) hla.endoverload #endmacro procedure delLeadingSpaces1( s: string ); @external( "STR_DELLEADINGSPACES1" ); procedure delLeadingSpaces2( src: string; dest:string ); @external( "STR_DELLEADINGSPACES2" ); procedure a_delLeadingSpaces( src: string ); @returns( "(type string eax)" ); @external( "STR_A_DELLEADINGSPACES" ); #macro trim( parms[] ); hla.overload( parms ) hla.signature( str.trim1(string) ) hla.signature( str.trim2(string, string) ) hla.endoverload #endmacro procedure trim1( s: string ); @external( "STR_TRIM1" ); procedure trim2( src: string; dest:string ); @external( "STR_TRIM2" ); procedure a_trim( src: string ); @returns( "(type string eax)" ); @external( "STR_A_TRIM" ); #macro delTrailingSpaces( parms[] ); hla.overload( parms ) hla.signature( str.delTrailingSpaces1(string) ) hla.signature( str.delTrailingSpaces2(string, string) ) hla.endoverload #endmacro procedure delTrailingSpaces1( s: string ); @external( "STR_DELTRAILINGSPACES1" ); procedure delTrailingSpaces2( src:string; dest: string ); @external( "STR_DELTRAILINGSPACES2" ); procedure a_delTrailingSpaces( src: string ); @returns( "(type string eax)" ); @external( "STR_A_DELTRAILINGSPACES" ); procedure rmvTrailingSpaces1( dest: string ); @external( "STR_RMVTRAILINGSPACES1" ); procedure rmvTrailingSpaces2( src:string; dest: string ); @external( "STR_RMVTRAILINGSPACES2" ); procedure a_rmvTrailingSpaces( src: string ); @returns( "(type string eax)" ); @external( "STR_A_RMVTRAILINGSPACES" ); // String comparison functions. procedure eq( src1:string; src2:string ); @returns( "@c" ); @external( "STR_EQ" ); procedure ne( src1:string; src2:string ); @returns( "@c" ); @external( "STR_NE" ); procedure lt( src1:string; src2:string ); @returns( "@c" ); @external( "STR_LT" ); procedure gt( src1:string; src2:string ); @returns( "@c" ); @external( "STR_GT" ); procedure le( src1:string; src2:string ); @returns( "@c" ); @external( "STR_LE" ); procedure ge( src1:string; src2:string ); @returns( "@c" ); @external( "STR_GE" ); procedure ieq( src1:string; src2:string ); @returns( "@c" ); @external( "STR_EQI" ); procedure ine( src1:string; src2:string ); @returns( "@c" ); @external( "STR_NEI" ); procedure ilt( src1:string; src2:string ); @returns( "@c" ); @external( "STR_LTI" ); procedure igt( src1:string; src2:string ); @returns( "@c" ); @external( "STR_GTI" ); procedure ile( src1:string; src2:string ); @returns( "@c" ); @external( "STR_LEI" ); procedure ige( src1:string; src2:string ); @returns( "@c" ); @external( "STR_GEI" ); // String searching functions: #macro prefix( parms[] ); hla.overload( parms ) hla.signature( str.prefix2(string, string) ) hla.signature( str.prefix3(string, dword, string) ) hla.endoverload #endmacro procedure prefix2( src1:string; src2:string ); // Same as matchStr2! @returns( "@c" ); @external( "STR_PREFIX2" ); procedure prefix3( src1:string; offs:dword; src2:string ); @returns( "@c" ); @external( "STR_PREFIX3" ); #macro iprefix( parms[] ); hla.overload( parms ) hla.signature( str.iprefix2(string, string) ) hla.signature( str.iprefix3(string, dword, string) ) hla.endoverload #endmacro procedure iprefix2( src1:string; src2:string ); // Same as matchiStr2! @returns( "@c" ); @external( "STR_IPREFIX2" ); procedure iprefix3( src1:string; offs:dword; src2:string ); @returns( "@c" ); @external( "STR_IPREFIX3" ); #macro index( parms[] ); hla.overload( parms ) hla.signature( str.index2(string, string) ) hla.signature( str.index3(string, dword, string) ) hla.endoverload #endmacro procedure index2( src1:string; src2:string ); @returns( "@c" ); // and EAX @external( "STR_INDEX2" ); procedure index3( src1:string; offs:dword; src2:string ); @returns( "@c" ); // and EAX @external( "STR_INDEX3" );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -