home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / sys / amiga / programm / 17225 < prev    next >
Encoding:
Text File  |  1992-12-11  |  2.7 KB  |  74 lines

  1. Newsgroups: comp.sys.amiga.programmer
  2. Path: sparky!uunet!gatech!concert!sas!mozart.unx.sas.com!walker
  3. From: walker@twix.unx.sas.com (Doug Walker)
  4. Subject: Re: Rewrite of PRINTF function, How do you do multi Args an
  5. Originator: walker@twix.unx.sas.com
  6. Sender: news@unx.sas.com (Noter of Newsworthy Events)
  7. Message-ID: <Bz40sn.3Dt@unx.sas.com>
  8. Date: Fri, 11 Dec 1992 19:29:10 GMT
  9. References: <jvasher.04cn@cquest.mi.org> <paulk.2f1s@terapin.com> <70868@cup.portal.com>
  10. Nntp-Posting-Host: twix.unx.sas.com
  11. Organization: SAS Institute Inc.
  12. Lines: 60
  13.  
  14.  
  15. In article <70868@cup.portal.com>, jimdawson@cup.portal.com (Jim R Dawson) writes:
  16. |> Could someone give me an example of how to use RawDoFmt() in C? I haven't
  17. |> been able to figure out how to call this function and I cannot find an
  18. |> example anywhere (except in asm).
  19.  
  20. |> |Jim Dawson - Author of AmiQWK .QWK mail reader | jimdawson@cup.portal.com|
  21.  
  22. Sure, here's a sprintf() implementation.  You can easily modify it
  23. to work as a printf() instead.  Keep in mind that you MUST use %ld
  24. to print a "long" or "int" value even if you are not using short
  25. integers.
  26.  
  27. This should work on any ANSI-compliant compiler.
  28.  
  29. Note that the callback function below is really a string constant
  30. which contains the code, written in hex, to implement the RawDoFmt
  31. callback routine.  Using SAS/C, you can use the STRINGMERGE option
  32. and this string constant will even be placed into the code section!
  33.  
  34. /*---------cut here---------------*/
  35.  
  36. #include <stdarg.h>
  37. #include <clib/exec_protos.h>
  38. #include <pragmas/exec_pragmas.h>
  39.  
  40. int rawsprintf(char *buffer, char *ctl, ...)
  41. {
  42.    va_list args;
  43.  
  44.    va_start(args, ctl);
  45.  
  46.    /*********************************************************/
  47.    /* NOTE: The string below is actually CODE that copies a */
  48.    /*       value from D0 to A3 and increments A3:          */
  49.    /*                                                       */
  50.    /*          move.b d0,(a3)+                              */
  51.    /*          rts                                          */
  52.    /*                                                       */
  53.    /*       It is essentially the callback routine needed   */
  54.    /*       by RawDoFmt.                                    */
  55.    /*********************************************************/
  56.  
  57.    RawDoFmt(ctl, args, (void (*))"\x16\xc0\x4e\x75", buffer);
  58.  
  59.    va_end(args);
  60.  
  61.    return((int)strlen(buffer));
  62. }
  63.  
  64. /*---------cut here---------------*/
  65. -- 
  66.   *****
  67. =*|_o_o|\\=====Doug Walker, Software Distiller====== BBS: (919)460-7430 =
  68.  *|. o.| ||                                          1200/2400/9600 Dual
  69.   | o  |//     For all you do, this bug's for you!
  70.   ====== 
  71. usenet: walker@unx.sas.com                            bix: djwalker 
  72. Any opinions expressed are mine, not those of SAS Institute, Inc.
  73.  
  74.