C Programming style of human-computer Interaction-Cshell (provide source download)

Source: Internet
Author: User

Remember to go to college, do C language program is to use SDB to debug, and then later with GDB, similar to SDB, but it is very useful. But after all, a little regret. For example, the program designed several functions, if you want to test them, you have to write a test function, with a variety of possible input to call; After the test, the general will delete the test code, if it is retained, the next time the function of the parameter interface, the compiler began to complain, had to insist on maintaining the test code. I was thinking that if I had a shell interface, it would be nice to run the functions directly. So don't bother to write some test code, let alone maintenance!

After work, most of the time is to do embedded systems, that ya can not gdb, or gdb is not so easy to use. Of course, the more immediate challenge is that the system is running on-line, and GDB doesn't have to think about it! Unless we think ahead of time what we need to provide debug information in the CLI, everything else is a black box! In addition, customers may have a variety of ideas that require us to prefabricated various types of switches. It is certainly possible to adjust these switching values via the CLI, but it is not always convenient. I used to give telecommunications mobile phone switchboard, the national application of hundreds of sets of equipment, each set of equipment has its own special configuration.

How to do it well? The program behavior is related to a global variable, but it is not able to see the current value of that variable, and the program has an error because it forgets some initialization function. At such times, we need a Cshell interface that allows all the global variables in the program to be viewed, modified, and run. Of course, all of this is done automatically, exactly, as long as make is there!

Http://files.cnblogs.com/files/hhao020/cshell_prj.re0.001.rar
Please unzip and compile under the Linux system (requires Perl environment).

Cshell involves lex,yacc,elf parsing and other technologies, the following is the implementation process:
1, write cshell.l lexical file, cshell.y grammar file;
2, use Lex and bison (YACC) to generate the Shell input interpretation file (c source code);
3,make compile and first-time link to the. out file (the symbol table is empty);
4, use p_readelf.pl (call readelf) to generate the symbol table source file;
5,make the second link to the. out file (with symbol table);
Note: The Cshell symbol table is not a symbol table for elf files, see the c_sym_table.c file for details.

Application developers, only need to link Cshell library and symbol table, and in their program to provide Cshell input interface, you can get all the functions of Cshell.
The links in the Cshell run up, it will look like this:


CSHELL_PRJ $ bin/linux.i64/user.exe
$7/> DemoVar1;
= ten (0x620000000a) <SYM_DATA:size=4>

$11/> DemoCall2 ("My int var", 5);
Input my int var=5
= 0 (0x0) <FUNCALL:size=0>

-><cmd/test.cmd
...............


Cshell syntax is a subset of C programming, except for the built-in commands in Help. There are several tricks to use:
1, function calls support up to 10 parameters, more will be discarded, the result, hehe ~ Of course, you can change cshellfuns.c to adjust;
2, when called, give a few parameters, will be the default of 0, make good use of this feature, such as print instance function!
3, you can add variables, such as x=123;
4, you can write a line of multiple expressions, separated by semicolons;
5, you can assign the result of a function to a variable, such as X=functioncall (...), of course, the X must first exist or be created well;
6, can be run in batches, execute <script, such as the execution of the script in the link <cmd/test.cmd

For Cshell want to make some custom friends, can read cshellfuncs.c. The principle is very simple, is the input programming a binary tree, left child right brother; When realized, the details are still quite many, must, or not fun! See this cshellfuncs.c, and understand the compilation process of friends, you can leave a message to request Lex lexical files and yacc grammar files. Do not upload, do not affect any use, Cshell is an open source code, I do not want to be a company to own, you can use, but not to deprive others the right to use.

Of course, everything is beneficial. Cshell gives you convenience at the same time, also let your program space exposed, encountered a malicious call to modify, it will make the program error, or behavior becomes unpredictable. The elder brother advises you to add an authentication to Cshell yourself, if Cshell is fortunate to be put into a product.

C Programming style of human-computer Interaction-Cshell (provide source download)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.