[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: How to format the command output like MySQL output



On Sun, Oct 20, 2013 at 1:35 AM, 陶治江 <taozhijiang@gmail.com> wrote:
>
> Hello everylinuxers:
>
> I am now focusing on the development of a script interpretor (some thing
> like shell)
> in embedded environment,

Okay, a shell-like programming language. Plenty of those, including
busybox, as John pointed out. Dash, which Debian uses during boot to
reduce the overhead bash would incur, would be another. You could look
at the source for those for inspiration.

But, ...

> and its functions mainly output the data in
> specified
> address.

For some reason, this does not sound to me like a general purpose
shell. Maybe something like a debugger? Or a tool for querying some
hardware device?

>In order to make it seems better, I want to format the output
> result like
> MySQL output listed below for example
>
> +--------+-------------+
> |  address| value           |
> +--------+-------------+
> |  0x1110 | 0x01            |
> +--------+-------------+
> |  0x1111 | 0x00            |
> +--------+-------------+

I think I did a shared memory query tool like this on a data
acquisition project a long time ago. But, ...

> I think it seems good like this, but I do not know how to make out
> it.(someone says awk,
> sed may help, but the environment does not permit it).

And, really, if you are familiar with printf(), the part you have
shown is dead simple.

> Is there some libs or
> tools can
> help make output result good and elegent?

The standard C library?

> Sorry to borther all of you, any info would be appreciated.

Promise me this isn't your homework, and I'll show you maybe three
printf() lines that will do as much as your output sample. Or,

    man 3 printf

will get you started. And doing a web search on the string, "printf
formatting" will get a lot more information.

The query for this particular function shouldn't be hard either. The
hardest part would be picking the approach. Do you want to ask for the
address(es) interactively or do you want to take the addresses from
the command line, or both?

Shoot, if you don't mind postfix syntax, a nice FORTH interpreter
(which I can suggest a few to you) will get you a good start. Some
come in under 200k, including the full runtime execution environment.
More complete FORTHs, like gforth, have an executable object around
130K in debian, and run easily in a 1M or so of run-time. And, again,
the output you describe above is pretty straightforward formatting.

> --
> Thanks & Best Regrads!
>
> Nicol TAO (taozhijiang)
>
> Shenzhen, Guangdong Province, P.R. China 518055
>
> Being Stronger!!!

And remember to have fun!

--
Joel Rees

Be careful where you see conspiracy.
Look first in your own heart.


Reply to: