amiga-news ENGLISH VERSION
.
Links| Forum| Kommentare| News melden
.
Chat| Umfragen| Newsticker| Archiv
.

amiga-news.de Forum > Programmierung > locale: FormatString() [ - Suche - Neue Beiträge - Registrieren - Login - ]

-1- [ - Beitrag schreiben - ]

02.02.2007, 22:18 Uhr

Ralf27
Posts: 2779
Nutzer
Ich hab mir mal die locale.lib angesehn und was soll ich tippen, ich hab es hinbekommen. :D

Allerdings hab ich doch noch ein kleines Problem (ihr kennt mich ja, I-) :glow: ):
FormatString()

Ich hab mir das ganze mehrfach angesehn und das einzige was mir sicher klar ist, wie ich denn übersetzen String übergeben muß (fmtTemplate) und (locale).
Es fängt aber schon mit der übergabe der Variablen an (dataStream), wie soll das vor sich gehn? Und was ist putCharFunc? Hab was mit dem ominösen HOOK gelesen, nunja, keine Ahnung was da passiert.
Die Funktion gibt desweiteren ein next zurück und keinen String. Wo bekomme ich dann denn String her?

Was ich da brächte wäre ein Beispiel, bzw. wie funktioniert das ganze? Die Platzhalter sind mir schon klar (z.b. Hallo %d)

Danke im vorraus
--
http://www.alternativercomputerclub.de.vu

[ - Antworten - Zitieren - Direktlink - ]

02.02.2007, 22:54 Uhr

geit
Posts: 332
[Ex-Mitglied]
@Ralf27:


Hier das Beispiel, aus dem SDI_misc example. Ist zwar für DoRawFmt von Exec, aber im Prinzip ist es das Selbe.

Hier gibt es den ganzen SDI Kram. Der Vorteil ist, dass die komplizierten Hooks
etc mit SDI, durch einfach Macros ersetzt werden und das ganze auch Compiler und
System unabhängig ist.

http://sourceforge.net/projects/sditools

code:
#include <proto/exec.h>
#include <proto/utility.h>

#include <stdarg.h>
#include <stdio.h>
#include <ctype.h>

#include "SDI_misc.h"


/*
**
**This structure keeps our internal sprintf vars during RawDoFmt()
**
*/

struct SPrintfStream
{
    char    *Target;
    ULONG    TargetSize;    /* Obsolete in this example, but useful when
                               dealing with size limited streams */
};

/*
** SPrintf_DoChar
**
** The following function is just an example where we use the object
** for composing some minor text. Do you see how easy it is to use and
** how great it is to use SDI_misc.h to automatically keep your sources
** compatible to all common AmigaOS platforms?
**
*/

PUTCHARPROTO( SPrintf_DoChar, char c, struct SPrintfStream *s  )
{
    *(s->Target++) = c;
}

/*
**
** SPrintf
**
** Here you can see how the function is used by the ENTRY() function.
**
*/

ULONG SPrintf( char *format, char *target, ULONG *args );
ULONG SPrintf( char *format, char *target, ULONG *args )
{
struct SPrintfStream s;

    s.Target  = target;

    RawDoFmt( format, args, ENTRY( SPrintf_DoChar ), &s);

    return( s.Target - target );
}

/*
**
** The main entry point
**
*/

int main(void)
{
    char buf[0x80]; /* storage for keeping the SPrintf result string */
    ULONG args[2];  /* storage for keeping the SPrintf arguments */

    args[0] = (ULONG) "result";
    args[1] = (ULONG) "PUTCHARPROTO macro";

    SPrintf("I am the %s of using SPrintf() with the new %s!", buf, args);

    printf("%sn", buf); /* just a simple printf to output and add the n */

return( 0);
}


Geit

[ - Antworten - Zitieren - Direktlink - ]

02.02.2007, 23:15 Uhr

thomas
Posts: 7717
Nutzer
@Ralf27:

Hier ist noch ein Beispiel:
C code:
#include <proto/dos.h>
#include <proto/exec.h>
#include <proto/locale.h>
#include <clib/alib_protos.h>
#include <string.h>

char wort[] = "Hallo";
long zahl   = 20;

char format[] = "wort = <%s>; zahl = <%ld>n";


/* für RawDoFmt: Zeichen in D0, Pointer in A3 */

UWORD putChProc[] = {
	0x16c0,  /* move.b d0,(a3)+ */
	0x4e75   /* rts             */
	};


/* für FormatString: Parameter auf dem Stack */

__saveds void putCharFunc_C (struct Hook *hook,struct Locale *locale,ULONG ch)

{
char *p = (char *)hook->h_Data;
*p = ch;
p ++;
hook->h_Data = (APTR)p;
}


/* für FormatString: Parameter in Registern */

__saveds void putCharFunc_ASM (__a0 struct Hook *hook,__a2 struct Locale *locale,__a1 ULONG ch)

{
char *p = (char *)hook->h_Data;
*p = ch;
p ++;
hook->h_Data = (APTR)p;
}


int main (void)

{
ULONG args[2];
char buffer[80];
struct Hook hook; /* siehe utility.library/CallHokPkt() sowie utility/hooks.h */

Printf (format,wort,zahl);

args[0] = (ULONG)wort;
args[1] = (ULONG)zahl;

VPrintf (format,args);

RawDoFmt (format,args,(APTR)putChProc,buffer);
Write (Output(),buffer,strlen(buffer));

hook.h_Entry    = (APTR)HookEntry;	/* in amiga.lib enthalten: nimmt Parameter aus den Registern und schiebt sie auf den Stack, ruft dann h_SubEntry auf */
hook.h_SubEntry = (APTR)putCharFunc_C;
hook.h_Data     = buffer;
FormatString (NULL,format,args,&hook);
Write (Output(),buffer,strlen(buffer));

hook.h_Entry    = (APTR)putCharFunc_ASM;
hook.h_SubEntry = NULL;	/* wird nicht benötigt */
hook.h_Data     = buffer;
FormatString (NULL,format,args,&hook);
Write (Output(),buffer,strlen(buffer));

return (0);
}


Gruß Thomas

--
Email: thomas-rapp@web.de
Home: thomas-rapp.homepage.t-online.de/

[ - Antworten - Zitieren - Direktlink - ]

05.02.2007, 22:17 Uhr

Ralf27
Posts: 2779
Nutzer
Danke für die Beispiele. Ich hab jetzt mein Programm Sudoku komplett darauf umgestellt und es funktioniert. Wieder etwas gelernt. :)
--
http://www.alternativercomputerclub.de.vu

[ - Antworten - Zitieren - Direktlink - ]


-1- [ - Beitrag schreiben - ]


amiga-news.de Forum > Programmierung > locale: FormatString() [ - Suche - Neue Beiträge - Registrieren - Login - ]


.
Impressum | Datenschutzerklärung | Netiquette | Werbung | Kontakt
Copyright © 1998-2024 by amiga-news.de - alle Rechte vorbehalten.
.