Re: Extend functionality of printf (Add colours)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kenny McCormack

    Re: Extend functionality of printf (Add colours)

    In article <391f429b-4cb8-4762-80bf-511a1dc5eeab@a2 9g2000pra.googl egroups.com>,
    Tomás Ó hÉilidhe <toe@lavabit.co mwrote:
    >
    >Firstly... before the guns go off... I realise that the C Standard
    >doesn't mention anything about the existence of colour, which is why
    >I'm writing a small little cross-platform library for setting the
    >console text colour. It'll have a function like as follows:
    First, I haven't analyzed your code in depth, and I don't really care
    about the minutiae. I leave that to the pedants^Wlangua ge lawyers.

    However, if I were doing this, I'd do it the other way around. That is,
    I'd call one of the vs*tf*() functions once, at the beginnning, to
    expand out the %(s). Then, I'd go back and parse the string - handling
    the color coding stuff via my function, and printf'ing the rest.

  • =?ISO-8859-1?Q?Tom=E1s_=D3_h=C9ilidhe?=

    #2
    Re: Extend functionality of printf (Add colours)

    On Nov 10, 9:00 pm, gaze...@shell.x mission.com (Kenny McCormack)
    wrote:
    However, if I were doing this, I'd do it the other way around.  That is,
    I'd call one of the vs*tf*() functions once, at the beginnning, to
    expand out the %(s).  Then, I'd go back and parse the string - handling
    the color coding stuff via my function, and printf'ing the rest.

    OK so let's say I start off with an invocation as follows:

    cprintf(stdout, "I'll ^brhave %u ^byand %u.",7,63);

    First of all, I remove the markers so that it's:
    "I'll have %u and %u."

    I'll have to keep note that the address of 'h' is where my first
    marker was, and that the address of 'a' is where my second marker was.

    Next I use sprintf to turn "I'll have %u and %u." into "I'll have 7
    and 63".

    One problem is that I don't know how many characters "%u" will compute
    to, I mean in the case of 7 it was one character but in the case of 63
    it was two characters. This will screw up the address I previously had
    for the second marker.

    I suppose though, I could compare the strings from the end backwards
    so that I'll now where the marker was (...if you catch what I mean).

    Anyone got any ideas?

    Comment

    • =?ISO-8859-1?Q?Tom=E1s_=D3_h=C9ilidhe?=

      #3
      Re: Extend functionality of printf (Add colours)

      On Nov 10, 9:43 pm, Tomás Ó hÉilidhe <t...@lavabit.c omwrote:
      OK so let's say I start off with an invocation as follows:
      >
      cprintf(stdout, "I'll ^brhave %u ^byand %u.",7,63);
      >
      First of all, I remove the markers so that it's:
          "I'll have %u and %u."

      Forget all that crap I just wrote, I'm just after realising that
      there's no reason why I can't leave the markers in for the call to
      sprintf, and then take them out later.

      Comment

      • Kenny McCormack

        #4
        Re: Extend functionality of printf (Add colours)

        In article <6a86e83f-9cad-414b-9b88-f6871689f254@u2 9g2000pro.googl egroups.com>,
        Tomás Ó hÉilidhe <toe@lavabit.co mwrote:
        >On Nov 10, 9:43 pm, Tomás Ó hÉilidhe <t...@lavabit.c omwrote:
        >
        >OK so let's say I start off with an invocation as follows:
        >>
        >cprintf(stdout ,"I'll ^brhave %u ^byand %u.",7,63);
        >>
        >First of all, I remove the markers so that it's:
        >    "I'll have %u and %u."
        >
        >
        >Forget all that crap I just wrote, I'm just after realising that
        >there's no reason why I can't leave the markers in for the call to
        >sprintf, and then take them out later.
        Right. Saves me the trouble of flaming you...

        Comment

        • Phil Carmody

          #5
          Re: Extend functionality of printf (Add colours)

          Tomás Ó hÉilidhe <toe@lavabit.co mwrites:
          On Nov 10, 9:43 pm, Tomás Ó hÉilidhe <t...@lavabit.c omwrote:
          >
          >OK so let's say I start off with an invocation as follows:
          >>
          >cprintf(stdout ,"I'll ^brhave %u ^byand %u.",7,63);
          >>
          >First of all, I remove the markers so that it's:
          >    "I'll have %u and %u."
          >
          Forget all that crap I just wrote, I'm just after realising that
          there's no reason why I can't leave the markers in for the call to
          sprintf, and then take them out later.
          Beware - if you're ever sprintfing externally-supplied strings,
          then they could include console control codes. I don't know if
          you'd want that or not.

          Phil
          --
          I tried the Vista speech recognition by running the tutorial. I was
          amazed, it was awesome, recognised every word I said. Then I said the
          wrong word ... and it typed the right one. It was actually just
          detecting a sound and printing the expected word! -- pbhj on /.

          Comment

          Working...