ScriptName "printf" ScriptAuthor "GS" ScriptVersion "V 1.00" // Convert a long or float value into a "printf" string from the standard ANSI_C compiler // Math - Data Conversion : Convert ( a_Source , Long , a_Destination , PrintfANSI_C , a_Format[0]) ; // Convert ( a_Source , Float , a_Destination , PrintfANSI_C , a_Format[0]) ; // format: %[flags][width][.precision][{f|F|l|L}]type // Eine Umwandlungsangabe beginnt mit einem Prozentzeichen % : // danach kann diese Reihenfolge angegeben werden: // - ein Minuszeichen: damit wird das Argument linksbündig ausgegeben; // - eine positive, ganze Zahl, die eine minimale Feldbreite bestimmt; // benötigt das Argument mehr Stellen als angegeben, // so werden ihm diese auch gegeben, benötigt es weniger, so wird mit Blanks aufgefüllt; // - ein Punkt, der die Feldbreite von der Genauigkeit (precision) trennt; // - eine positive, ganze Zahl, die die maximale Anzahl von Zeichen festlegt, die von einer Zeichenkette ausgegeben werden sollen, oder die Anzahl Ziffern, die nach dem Dezimalpunkt bei einer Gleitkommazahl ausgegeben werden, oder die minimale Anzahl von Ziffern, die bei einem ganzzahligen Wert ausgegeben werden sollen; // - der Buchstabe b oder B, wenn short ausgegeben werden soll, oder der Buchstabe l oder L, // wenn das Argument long ist. // Hinweis: Wenn das Zeichen nach % keines der obigen Zeichen und kein Umwandlungszeichen ist, dann ist die Wirkung von printf() undefiniert! // Nachstehend eine kurze (nicht vollständige) Übersicht über wichtige Formatierungszeichen. // flags ...steht für... // - linksbündig // + bei positiven Zahlen wird der Ausgabe ein Pluszeichen vorangestellt // " " Leerzeichen: bei positiven Zahlen wird ein Leerzeichen vorangestellt // 0 füllt Feldbreite mit Nullen auf // type ...steht für... // u vorzeichenlose Ganzzahl, unsigned int // Nachstehend Beispiele zur Illustration: var ltemp: long; var ftemp: float; var a_destination: buffer[20]; var a_Format : buffer[10]; var w10: word; moveconst (w10, 10); var b0: Byte; moveconst (b0, 0); :start; call :deletBuffer; moveconst (ltemp, 1234); moveconst (a_Format[0], "%5Lu"); Convert ( ltemp , Long , a_Destination[0] , PrintfANSI_C , a_Format[0]) ; //a_Destination[0] = 0x20 0x31 0x32 0x33 0x34 = " 1234" call :deletBuffer; moveconst (ltemp, 1234); moveconst (a_Format[0], "%05Lu"); Convert ( ltemp , Long , a_Destination[0] , PrintfANSI_C , a_Format[0]) ; //a_Destination[0] = 0x30 0x31 0x32 0x33 0x34 = "01234" call :deletBuffer; moveconst (ltemp, 1234); moveconst (a_Format[0], "%+3Lu"); Convert ( ltemp , Long , a_Destination[0] , PrintfANSI_C , a_Format[0]) ; //a_Destination[0] = 0x2B 0x31 0x32 0x33 0x34 = "+1234" call :deletBuffer; moveconst (ltemp, 1234); moveconst (a_Format[0], "% 3Lu"); Convert ( ltemp , Long , a_Destination[0] , PrintfANSI_C , a_Format[0]) ; //a_Destination[0] = 0x20 0x31 0x32 0x33 0x34 = " 1234" call :deletBuffer; moveconst (ltemp, 1234); moveconst (a_Format[0], "%6lu"); Convert ( ltemp , Long , a_Destination[0] , PrintfANSI_C , a_Format[0]) ; //a_Destination[0] = 0x20 0x20 0x31 0x32 0x33 0x34 = " 1234" call :deletBuffer; moveconst (ltemp, 1234); moveconst (a_Format[0], "%06lu"); Convert ( ltemp , Long , a_Destination[0] , PrintfANSI_C , a_Format[0]) ; //a_Destination[0] = 0x30 0x30 0x31 0x32 0x33 0x34 = "001234" call :deletBuffer; moveconst (ftemp, 1234); moveconst (a_Format[0], "%6f"); Convert ( ftemp , Long , a_Destination[0] , PrintfANSI_C , a_Format[0]) ; //a_Destination[0] = "1234.000000" call :deletBuffer; moveconst (ltemp, 1234); moveconst (a_Format[0], "\n:%7.3Lu:"); Convert ( ltemp , Long , a_Destination[0] , PrintfANSI_C , a_Format[0]) ; //a_Destination[0] = "\n: 1234:" call :deletBuffer; moveconst (ftemp, 1234); moveconst (a_Format[0], "%7.3f"); Convert ( ftemp , Long , a_Destination[0] , PrintfANSI_C , a_Format[0]) ; //a_Destination[0] = "1234.000" call :deletBuffer; moveconst (ltemp, 1); moveconst (a_Format[0], "\n:%7.3Lu:"); Convert ( ltemp , Long , a_Destination[0] , PrintfANSI_C , a_Format[0]) ; //a_Destination[0] = "\n: 001:" call :deletBuffer; moveconst (ltemp, 1); moveconst (a_Format[0], "\n:%-10Lu:"); Convert ( ltemp , Long , a_Destination[0] , PrintfANSI_C , a_Format[0]) ; //a_Destination[0] = "\n:1 :" jump :start; :deletBuffer; Fill ( a_Format[0] , b0 , w10 ) ; Fill ( a_Destination[0] , b0 , w10 ) ; return;