CN102937894A - Method for realizing simple and transplantable printf function - Google Patents

Method for realizing simple and transplantable printf function Download PDF

Info

Publication number
CN102937894A
CN102937894A CN2012103932174A CN201210393217A CN102937894A CN 102937894 A CN102937894 A CN 102937894A CN 2012103932174 A CN2012103932174 A CN 2012103932174A CN 201210393217 A CN201210393217 A CN 201210393217A CN 102937894 A CN102937894 A CN 102937894A
Authority
CN
China
Prior art keywords
function
printf
buf
transplantable
print
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN2012103932174A
Other languages
Chinese (zh)
Inventor
姚艳松
郭立煌
周建波
雍太利
朱学海
陈靖公
王程谦
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Guodian Nanjing Automation Co Ltd
Original Assignee
Guodian Nanjing Automation Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Guodian Nanjing Automation Co Ltd filed Critical Guodian Nanjing Automation Co Ltd
Priority to CN2012103932174A priority Critical patent/CN102937894A/en
Publication of CN102937894A publication Critical patent/CN102937894A/en
Pending legal-status Critical Current

Links

Landscapes

  • Stored Programmes (AREA)

Abstract

The invention discloses a method for realizing a simple and transplantable printf function. The method comprises the following steps: (1) defining a send buffer print_buf with N bytes in a stack; (2) outputting content needing to be formatted to the buffer print_buf by a library function sprintf function; and (3) outputting data in the buffer print_buf by a sendString function sending strings. According to the method for realizing the simple and transplantable printf function, the function of macro definition is used, and the existing system library function sprintf is utilized to simplily realize the printf function. Practice indicates that the method can be compatible with the printf function and is transplantable.

Description

A kind of method that realizes the Formatting Output letter function that is simple and easy to transplant
Technical field
The present invention relates to the computer system development method, relate in particular to a kind of method that realizes the Formatting Output letter function that is simple and easy to transplant.
Background technology
Formatting Output function (printf function) be computer system especially the most frequently used in the process of embedded system exploitation, also be one of most important built-in function, the printf function is used for to control desk (screen, serial ports, telnet port or JTAG debug terminal) type information, is one of built-in function the most frequently used in the system debug process.
The prototype of printf function is int printf (char*format, [argument ... ]), wherein format is the form of user's appointment, and argument is the variable of fixed qty not, and argument is the types such as integer, floating number, character string.
The printf function is used for the output Debugging message; be convenient to debugging person and check system's operation information; in embedded system development or migration process; the printf function uses system's built-in function usually; the built-in printf function of system can print to the output control desk of system default usually; if other output control desks that debugging person wishes to export often need function to be redirected or to transplant the Formatting Output function of other functions, understand like this that there are the following problems:
(1) the redirected rule of the different debugging software functions of different platform or identical platform is inconsistent, and the function redirection function even is not provided, and causes transplanting difficulty;
(2) if oneself realizes the printf function performance, often can only realize fairly simple Formatting Output function, as supporting to print integer, character string, do not support long shaping, floating number, the title of function can not be printf, other names can only be changed into, the system transplantation difficulty can be caused equally.
In sum, the printf function often can cause transplanting loaded down with trivial details in embedded systems debugging, the problems such as exploitation difficulty.
Summary of the invention
Goal of the invention: in order to overcome the deficiencies in the prior art, the invention provides a kind of method that realizes the Formatting Output letter function that is simple and easy to transplant, utilize macro definition and existing system library function sprintf function,
Technical scheme: for achieving the above object, the technical solution used in the present invention is:
A kind of method that realizes the Formatting Output letter function that is simple and easy to transplant comprises the steps:
(1) at the transmission buffer zone print_buf of a N byte of storehouse definition;
The content that (2) will need to format by built-in function sprintf function outputs in the buffer zone print_buf;
(3) by the data in the function sendString function output buffer print_buf that sends character string.
Preferably, the size of described buffer zone print_buf can be adjusted as required, generally can be designed as 1024 bytes, i.e. N=1024.
In the said method, the prototype of sprintf function is int sprintf (char*buffer, const char*format, [argument] ...), wherein buffer is the buffer zone of Store form character string, format is the form of user's appointment, and argument is the variable of fixed qty not, and argument is the types such as integer, floating number, character string; The sendString function is the function that system sends character string, can be self-defined by the developer.The method has been carried out macro definition one time, during use this macro definition is placed in the library file, makes to comprise this library file in the source file and get final product.
Beneficial effect: a kind of method that realizes the Formatting Output letter function that is simple and easy to transplant provided by the invention, use the macro definition function, utilize existing system built-in function sprintf, very simply realized the printf function, practice shows, the method can compatible printf function, and be easy to transplant.
Embodiment
Below in conjunction with example the present invention is further described.
A kind of method that realizes the Formatting Output letter function that is simple and easy to transplant comprises the steps:
(1) at the transmission buffer zone print_buf of 1024 bytes of storehouse definition;
The content that (2) will need to format by built-in function sprintf function outputs in the buffer zone print_buf;
(3) by the data in the function sendString function output buffer print_buf that sends character string.
Can realize said method by following program language:
Figure BDA00002263396200021
The said procedure language is ingenious utilize do while (0) structure, system library function sprintf function, macro definition function, variadic macros (...), in the macro definition _ _ the VA_ARGS__ key word, realized the printf repertoire, in actual use, can carry out very easily system transplantation and debugging.
Printf is as follows such as system call:
Figure BDA00002263396200022
The above only is preferred implementation of the present invention; be noted that for those skilled in the art; under the prerequisite that does not break away from the principle of the invention, can also make some improvements and modifications, these improvements and modifications also should be considered as protection scope of the present invention.

Claims (2)

1. the method for the realization Formatting Output letter function that is simple and easy to transplant is characterized in that: comprise the steps:
(1) at the transmission buffer zone print_buf of a N byte of storehouse definition;
The content that (2) will need to format by built-in function sprintf function outputs in the buffer zone print_buf;
(3) by the data in the function sendString function output buffer print_buf that sends character string.
2. the method for the realization according to claim 1 Formatting Output letter function that is simple and easy to transplant is characterized in that: described N=1024.
CN2012103932174A 2012-10-16 2012-10-16 Method for realizing simple and transplantable printf function Pending CN102937894A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN2012103932174A CN102937894A (en) 2012-10-16 2012-10-16 Method for realizing simple and transplantable printf function

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN2012103932174A CN102937894A (en) 2012-10-16 2012-10-16 Method for realizing simple and transplantable printf function

Publications (1)

Publication Number Publication Date
CN102937894A true CN102937894A (en) 2013-02-20

Family

ID=47696793

Family Applications (1)

Application Number Title Priority Date Filing Date
CN2012103932174A Pending CN102937894A (en) 2012-10-16 2012-10-16 Method for realizing simple and transplantable printf function

Country Status (1)

Country Link
CN (1) CN102937894A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105511820A (en) * 2015-12-02 2016-04-20 博宏信息技术有限公司 Free typesetting printing method
CN110780858A (en) * 2019-10-28 2020-02-11 天津津航计算技术研究所 Software layering architecture based on embedded operating system

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO1998002810A1 (en) * 1996-07-11 1998-01-22 Tandem Computers Incorporated Method and apparatus for transporting interface definition language-defined data structures between heterogeneous systems
US5794234A (en) * 1996-08-14 1998-08-11 The Ec Company Method and system for providing electronic commerce between incompatible data processing systems
CN1302029A (en) * 1999-12-30 2001-07-04 国际商业机器公司 Output file for forming formatting computer

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO1998002810A1 (en) * 1996-07-11 1998-01-22 Tandem Computers Incorporated Method and apparatus for transporting interface definition language-defined data structures between heterogeneous systems
US5794234A (en) * 1996-08-14 1998-08-11 The Ec Company Method and system for providing electronic commerce between incompatible data processing systems
CN1302029A (en) * 1999-12-30 2001-07-04 国际商业机器公司 Output file for forming formatting computer

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
董慎行: "在Turbo C的图像模式中实现格式化文本输出", 《微型机与应用》 *

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105511820A (en) * 2015-12-02 2016-04-20 博宏信息技术有限公司 Free typesetting printing method
CN110780858A (en) * 2019-10-28 2020-02-11 天津津航计算技术研究所 Software layering architecture based on embedded operating system

Similar Documents

Publication Publication Date Title
CN104679903B (en) The operating method and device of a kind of tables of data
CN103430140B (en) Method and apparatus of managing items on clipboard of portable terminal
WO2014134899A1 (en) Electronic reading device and method for extracting and saving text information thereof, and storage medium
CA2556294A1 (en) Method of supplying content to a device
WO2004097667A3 (en) Automated data mining runs
CN103488478A (en) Device management framework based on android platform
CN106648817B (en) Cross-platform data object transmission method
KR101780905B1 (en) Method and apparatus for establishing ultra-large character library and method and apparatus for displaying character
TW200519752A (en) Mechanism for enabling a program to be executed while the execution of an operating system is suspended
CN104615618B (en) A kind of implementation method of Embedded Main Memory Database
CN106648569A (en) Target serialization achieving method and device
CN102446083A (en) Method for reading and storing Android cellphone screen display contents at PC terminal
CN102937894A (en) Method for realizing simple and transplantable printf function
CN102004787A (en) Method for combining multiple application scene forms based on office software plugins
CN102760075A (en) Method and system for realizing application configuration of intelligent card
CN104750864A (en) Universal text checking method
CN110209344B (en) Method, device and computer readable storage medium for migrating object storage
CN102662700A (en) Method for releasing and upgrading embedded software edition
CN102567366A (en) Method for realizing webpage resetting
CN202385284U (en) Embedded meteorology early warning information receiving terminal
CN105551500B (en) A kind of acoustic signal processing method and device
CN202720869U (en) Led display screen wireless control system
CN101772207A (en) Method for mobile terminal equipment to identify file
Qing et al. Music Player Based on the Cordova Cross-Platform
CN106095514B (en) The file installation kit and its generation method for down loading of compatible operating system

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
C12 Rejection of a patent application after its publication
RJ01 Rejection of invention patent application after publication

Application publication date: 20130220