A command line configuration storage method and a corresponding configuration reading method
By parsing the variable parameters and callback function identifiers of the command string, the storage sector allocation is optimized, solving the problem of large storage space consumption, realizing efficient configuration storage and retrieval, and simplifying command line integration of embedded devices.
Patent Information
- Application Number
- CN202411010295.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-26
- Publication Date
- 2026-01-02
- Estimated Expiration
- 2044-07-26
AI Technical Summary
Existing technologies for storing command strings consume excessive storage space as the complexity of command string functions increases, and repeated parsing leads to low efficiency.
By parsing the variable parameters and callback function identifiers in the command string, only the configuration data is stored. The command node hierarchy of the software module is represented by a linear linked list structure, which optimizes the allocation of storage sectors, reduces storage space usage, and avoids repeated parsing.
It reduces storage space usage, improves configuration storage and retrieval efficiency, reduces development difficulty, and simplifies the implementation of command-line integration frameworks.
Smart Images

Figure CN118796129B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of command line, and particularly relates to a configuration storage method of command line and a corresponding configuration reading method. BACKGROUND
[0002] In the field of embedded operating system, a command line interface (CLI) is a kind of command interface based on text input between a user and an operating system or an application program, which provides the most basic human-computer interaction technology. A user can input a command string through the command line interface to send an instruction to the operating system, so that the embedded operating system can execute a specific task. Although the command line interface is less convenient than a graphical user interface in human-computer interaction, it is more resource-saving and faster in running, and thus is still a commonly used interaction mode at present.
[0003] In the development and application process of an embedded device, a command string input by a user is often stored in a storage space of the embedded device, and the stored command string can be read from the storage space again when needed in the future, so that the corresponding callback function can be called to obtain an execution result, and thus the corresponding task can be directly executed without repeatedly inputting the command string. For example, in the running process of a switch device, some problems may occur or a user may require to add a function. In this case, a developer can write and store a command string of the corresponding function in a flash of the switch device. Even if the switch device is powered off or restarted, the corresponding command string can be read from the flash to be executed to implement the required function. At present, when storing a command string, the entire command string is generally saved to a string array, and the string number is stored to a storage space. However, with the development of command line technology, the function implemented by the command string and the complexity of the command string are becoming higher and higher. For example, a single command string may occupy up to 50-60 characters at present, and thus the storage mode will occupy a large amount of storage space. SUMMARY
[0004] In view of the above problems and technical requirements, the present application provides a configuration storage method of command line. The technical scheme of the present application is as follows.
[0005] The configuration storage method of command line comprises the following steps.
[0006] An inputted to-be-processed command string is obtained.
[0007] According to the target command line format corresponding to the target software module to which the to-be-processed command string belongs, which has been defined in the registered software module, the to-be-processed command string is parsed, the data of the variable parameters in the to-be-processed command string is extracted, and the callback function identifier corresponding to the target function function possessed by the to-be-processed command string is determined as the callback function identifier of the to-be-processed command string; wherein the variable parameters are parameters with different data contents in different command strings belonging to the same software module, and each callback function identifier is used to uniquely identify a callback function;
[0008] The configuration data of the to-be-processed command string is stored in the storage space, and the configuration data includes the data of the variable parameters of the to-be-processed command string and the callback function identifier, and the data of the variable parameters of the to-be-processed command string is used to pass parameters into the callback function corresponding to the callback function identifier of the to-be-processed command string when the configuration is read to obtain the execution result of the to-be-processed command string.
[0009] Further, the configuration storage method further includes:
[0010] When each software module is defined, the storage sector size of each function function contained in the software module is defined.
[0011] When each software module is registered, the storage sectors in the storage space are allocated to each function function according to the storage sector size of each function function contained in the software module, and the storage sector of each function function is used to store the configuration data of the command string with the function function.
[0012] The configuration data of the to-be-processed command string is stored in the storage space, and the configuration data includes the data of the variable parameters of the to-be-processed command string and the callback function identifier, and the data of the variable parameters of the to-be-processed command string is used to pass parameters into the callback function corresponding to the callback function identifier of the to-be-processed command string when the configuration is read to obtain the execution result of the to-be-processed command string.
[0013] Further, the storage sector is allocated to each function function in the storage space according to the storage sector size of each function function contained in the software module, and the storage sector of each function function is used to store the configuration data of the command string with the function function.
[0014] The storage sectors of each function function are sequentially allocated from the initial storage address of the storage space according to the registration order of the function functions, and when each function function is registered, a storage offset address is determined according to the storage sectors already allocated to other function functions, and the storage sector with the storage sector size starting from the storage offset address is allocated to the currently registered function function.
[0015] Further, the storage sector size of each function function contained in the software module is defined, and the storage sector size of each function function is defined by:
[0016] The number of storage mapping units of the function function and the size of each storage mapping unit are defined, and the total size of all storage mapping units is the storage sector size of the function function.
[0017] The allocating storage sectors to the function function according to the storage sector size of the function function comprises: allocating a plurality of storage mapping units to the function function as storage sectors according to the number and size of the storage mapping units of the function function.
[0018] The further technical solution is that the configuration data of the to-be-processed command string is stored in the storage space, comprising:
[0019] When the storage mapping unit of the target function function is one, the configuration data of the to-be-processed command string is stored in the storage mapping unit of the target function function by using the covering storage mode.
[0020] When the storage mapping unit of the target function function is one, the configuration data of the to-be-processed command string is stored in the storage mapping unit of the target function function by using the covering storage mode.
[0021] The further technical solution is that when the function function is a first type of command with command storage requirement, the defined storage sector size of the function function is greater than 0; when the function function is a second type of command without command storage requirement, the storage sector size of the function function is defined as 0; the configuration storage method further comprises:
[0022] When the target function function to which the to-be-processed command string belongs is the first type of command, the step of storing the configuration data of the to-be-processed command string in the storage space is executed after the to-be-processed command string is executed.
[0023] When the target function function to which the to-be-processed command string belongs is the second type of command, the to-be-processed command string is executed and then ended.
[0024] The further technical solution is that the variable parameters in the to-be-processed command string comprise an option parameter and a value-containing parameter, the data content of the option parameter is used to identify the target function function, and the data content of the value-containing parameter is a function parameter of the target function function.
[0025] The configuration data of the to-be-processed command string is stored in the storage space, comprising:
[0026] The data of the option parameter, the data of the value-containing parameter and the callback function identifier which are coded in numerical form are stored in the storage space.
[0027] The further technical scheme is that the method for defining each software module comprises: writing a command definition macro of the software module, the command definition macro of the software module comprising a command line format of the software module, callback functions of each function function contained by the software module and corresponding callback function identifiers of the callback functions, and a storage sector size, the command line format of the software module indicating a linear linked list structure of multiple command nodes included in a command string belonging to the software module, each command node being of one of a normal node, an option node, and a value-containing node; in the command line format, each normal node has a unique value, each option node has multiple different preset optional options, and a first command node of the command line format of each software module is a normal node;
[0028] The configuration storage method further comprises: when each software module is registered, merging and updating the command nodes in the command line format of the software module with the command nodes in the command tree that has been formed to update the command tree, the command tree being a tree structure formed by the command nodes in the command line formats of the multiple software modules that have been registered being connected in sequence, and the command line format of each software module that has been registered corresponding to a command node path formed by multiple command nodes being connected in sequence in the command tree.
[0029] The further technical scheme is that the target command line format is used to analyze the to-be-processed command string, comprising:
[0030] Taking a command node in the command tree that matches a first command node in the to-be-processed command string as a root node, sequentially traversing each command node connected under the root node in the command tree to determine a command node path that matches the to-be-processed command string, and each command node through which the determined command node path sequentially passes from the root node matches each command node in the to-be-processed command string one by one; wherein, for any one command node in the to-be-processed command string, the command node matches a normal node when the value of the command node is the same as the value of the normal node in the command tree, or the command node matches an option node when the value of the command node is the same as one of the preset optional options of the option node in the command tree, or the command node matches a value-containing node when the value of the command node conforms to a predetermined data format of the value-containing node;
[0031] extracting the value of the command node in the to-be-processed command string that matches the option node to obtain data of an option parameter of the to-be-processed command string, and extracting the value of the command node in the to-be-processed command string that matches the value-containing node to obtain data of a value-containing parameter of the to-be-processed command string;
[0032] determining a target function function that the to-be-processed command string has according to the extracted data of the option parameter, and determining that the data of the value-containing parameter is a function parameter of the target function function, and taking the callback function identifier of the target function function as a callback function identifier of the to-be-processed command string.
[0033] A configuration reading method of a command line, the configuration reading method comprising:
[0034] obtaining data of a variable parameter of a command string to be read and a corresponding callback function identifier from a storage space;
[0035] passing the data of the variable parameter of the command string to be read into a callback function corresponding to the callback function identifier of the command string to be read, to obtain an execution result of the command string to be read.
[0036] The present application has the following beneficial technical effects:
[0037] The present application discloses a configuration storage method of a command line and a corresponding configuration reading method. The method does not directly store the entire command string, but first parses the target command line format corresponding to the target software module to which the command string belongs, to extract the data of the variable parameter and the callback function identifier in the command string as configuration data, and then only stores the configuration data in the command string without storing the data of the fixed parameter. Based on this configuration storage method, the occupation of the storage space can be reduced on the basis of ensuring correct configuration reading. In addition, the configuration data obtained after parsing is directly stored, so that repeated parsing is not required during configuration reading. When configuration reading needs to be performed multiple times, the time consumption and memory resource consumption caused by repeated parsing are avoided, and the efficiency of configuration storage and reading can be improved.
[0038] The method also provides a brand-new command line integration framework, which optimizes the command line process into a convenient and unified module. By defining the storage sector size of the software module in advance, the storage sector of each software module can be automatically planned, without the need for manual calculation of the specified storage address, and the convenience and accuracy are higher. The linear linked list structure is used to represent the target command line format of the software module, which can clearly express the hierarchical structure of the command nodes of the software module. The method can be applied to various occasions in the command line interface of an embedded device, and the optimization of the command line integration framework allows software developers to not need to care about the underlying implementation details, reducing the development difficulty. BRIEF DESCRIPTION OF DRAWINGS
[0039] Figure 1 is a method flowchart of the configuration storage method of an embodiment of the present application.
[0040] Figure 2 is a method flowchart of the configuration reading method of an embodiment of the present application.
[0041] Figure 3 is a linear linked list structure diagram of a target command line format of a software module in an example.
[0042] Figure 4Fig. 1 is a partial structure diagram of a command tree in an example of a target command line format of a plurality of software modules. DETAILED DESCRIPTION
[0043] The specific embodiments of the present application will be further described with reference to the accompanying drawings.
[0044] The present application discloses a configuration storage method of a command line, please refer to Figure 1 The configuration storage method includes the following contents as shown in the flow chart.
[0045] Step 1, obtaining an inputted command string to be processed.
[0046] Step 2, parsing the command string to be processed according to a target command line format of a target software module corresponding to the command string to be processed in the software modules which have been defined and registered, extracting the data of the variable parameters in the command string to be processed and determining the callback function identification corresponding to the target function function of the command string to be processed as the callback function identification funcid of the command string to be processed. Each callback function identification funcid is used to uniquely identify a callback function, and the corresponding callback function can be quickly obtained according to the callback function identification funcid.
[0047] Any command string is used to implement a function function, and the function function belongs to a software module, then the command string belongs to the software module. The same software module can implement a plurality of different function functions, and the specific contents of the command strings belonging to the same software module but implementing different function functions are different. For example, a software module is "file transfer with a TFTP server", one of the function functions implemented by the software module is "download file source1 from TFTP server host1 and transfer to local computer destination1", and the command string implementing the function function can be written as tftp host1 get source1 destination1. Another function function implemented by the software module is "transfer file source2 on the local computer to destination2 on TFTP server host2", and the command string implementing the function function is tftp host2 put source2 destination2.
[0048] It can be seen that the specific content of different command strings belonging to the same software module can be different, but the format is similar. The parameters in each command string belonging to the same software module can be divided into two categories, fixed parameters and variable parameters. The fixed parameters are parameters whose data content is the same in different command strings belonging to the software module, and the variable parameters are parameters whose data content is different in different command strings belonging to the software module. For example, in the above example, in the command string tftp host1 get source1 destination1, "tftp" belongs to a fixed parameter, and its data content is the same in other command strings belonging to the software module. "host1", "get", "source1", and "destination1" belong to variable parameters, and their data content will be different in other command strings belonging to the software module.
[0049] Further, the variable parameters in the command string can be divided into option parameters and value-containing parameters. The data content of the option parameter is used to distinguish different function functions. Each command string belonging to the software module contains one or more option parameters. The data content of the option parameter in multiple command strings belonging to the same software module and implementing the same function function is the same. The data content of at least one option parameter in multiple command strings belonging to the same software module but implementing different function functions is different. The option parameter generally has multiple different preset optional options. The data content of the option parameter in each command string belonging to the software module can only be one of the preset optional options. The value-containing parameter is a function parameter that needs to be passed to the function function implemented by the command string. The function parameter of a function function generally also has a specific value range or numerical format. Therefore, the data content of the value-containing parameter also has a predetermined data format, although it is not as clear as the option parameter. Therefore, the data of the option parameter in the command string belonging to one software module but implementing different function functions is different, and the data of the option parameter in the command string implementing the same function function is the same, but the value-containing parameter can be different.
[0050] For example, in the above example, for the four variable parameters "host1", "get", "source1", and "destination1", "get" belongs to an option parameter. The option parameter has two different preset optional options, get and put, which are used to distinguish two different function functions belonging to the software module. The data content of the option parameter in different command strings belonging to the software module is either get or put, but not otherwise. "host1", "source1", and "destination1" belong to value-containing parameters.
[0051] Step 3, store the configuration data of the to-be-processed command string in the storage space, the configuration data of the to-be-processed command string including the data of the variable parameters of the to-be-processed command string and the callback function identifier.
[0052] For any command string, the command string must contain fixed parameters and variable parameters respectively, and the variable parameters contained can be at least one of option parameters and value-containing parameters. When the to-be-processed command string contains both option parameters and value-containing parameters, the data of the variable parameters in the to-be-processed command string is extracted, and the data of the option parameters and the data of the value-containing parameters in the to-be-processed command string are stored respectively. In addition, in an embodiment, since the data of the option parameters is often in the form of a string, when the data of the option parameters in the to-be-processed command string is stored, the data of the option parameters is encoded into a numerical form before being stored.
[0053] According to the conventional configuration storage method, the entire to-be-processed command string will be stored in the storage space, that is, the data of the fixed parameters and the data of the variable parameters in the to-be-processed command string will be stored in the storage space, which will occupy a large amount of storage space. According to the configuration storage method of the present application, only the callback function identifier of the to-be-processed command string and the data of the variable parameters with higher importance are stored in the storage space, and the data of the fixed parameters in the to-be-processed command string is no longer stored, which greatly reduces the occupation of the storage space, avoids the repeated storage of the data of the fixed parameters, and reduces the redundancy of data storage.
[0054] Corresponding to the configuration storage method of the present application, the present application also provides a configuration reading method of a command line, please refer to the flowchart shown in Figure 2 The configuration reading method includes the following steps:
[0055] Step 1, obtain the data of the variable parameters of the to-be-read command string and the corresponding callback function identifier from the storage space.
[0056] Step 2, pass the data of the variable parameters of the to-be-read command string into the callback function corresponding to the callback function identifier of the to-be-read command string, to obtain the execution result of the to-be-read command string.
[0057] Based on the traditional configuration storage method, the entire stored to-be-processed command string needs to be read out every time configuration reading is performed subsequently, and then key information in the command string is extracted by command parsing to be passed into a corresponding callback function to obtain an execution result. The data that needs to be passed into the callback function every time configuration reading is performed is mainly the data of the variable parameters in the to-be-processed command string. The application has already completed parsing of the to-be-processed command string and stored the data of the variable parameters in the configuration storage stage, and therefore in subsequent configuration reading, the data of the variable parameters of the to-be-processed command string is directly read out from the storage space and passed into the callback function corresponding to the callback function identifier funcid of the to-be-processed command string, and the execution result of the to-be-processed command string can also be obtained. Therefore, the method of the application can reduce the occupation of the storage space on the basis of ensuring that the execution result is accurately obtained and configuration reading is implemented. In addition, in actual application, the to-be-processed command string may need to be read for configuration multiple times. Based on the traditional configuration storage method, the required data needs to be repeatedly extracted from the to-be-processed command string and passed into the corresponding callback function every time configuration reading is performed, while the application completes the parsing operation in the configuration storage stage, and the data of the variable parameters in the to-be-processed command string is directly read from the storage space every time configuration reading is performed, and there is no need to additionally perform parsing. In the scenario of multiple times of configuration reading, the method can also reduce the time consumption and memory resource consumption of configuration reading.
[0058] As can be seen from the above introduction, the configuration storage method of the application needs to use the command line format of the software module that has been defined and registered, and therefore the application not only optimizes the method of the configuration storage process, but also needs to adaptively optimize the definition and registration process of the software module before configuration storage, and therefore the application actually newly designs a command line integration framework, and the design flow of the command framework is introduced in the following embodiments in sequence.
[0059] I. Definition of a software module
[0060] In the definition, the command definition macro CLI_ITEM of the software module is written for unified definition, and one software module only needs to define one command definition macro CLI_ITEM to complete development. The C language macro is used to uniformly define each software module, which is convenient and simple in interface.
[0061] The command definition macro CLI_ITEM of one software module at least includes the command line format of the software module, the callback functions of the function functions included in the software module and the callback function identifiers funcid corresponding to the callback functions. In addition, the command definition macro CLI_ITEM of the software module can also include the name of the software module and some reserved fields for subsequent information expansion.
[0062] The command line format of a software module indicates a linear list structure of multiple command nodes included in a command string belonging to the software module, and the linear list structure indicates the sequential arrangement order between the command nodes. The operation of dividing a command string into multiple command nodes can be completed by using existing methods, and thus the embodiment will not be described herein. The node type of each command node in the command line format of the software module is one of a normal node, an option node, and a value-containing node. In the command line format, each normal node has a unique value, each option node has multiple different preset optional options, and the preset optional options can be empty. Each function implemented by the software module corresponds to a combination mode of a preset optional option of all the option nodes, and the value-containing node has a predetermined data format. The first command node of the command line format of each software module is a normal node.
[0063] For example, in the above example, for the software module of "file transfer with a TFTP server", the defined command line format of the software module is written as tftp [host] (GET | PUT) [source] (destination | NULL), in which () indicates an option node and multiple preset optional options are separated by "|", and [] indicates a value-containing node, and NULL indicates that the data content of the option node can be empty. The linear list structure indicated by the command line format is shown in FIG. 1, in which different command nodes are sequentially connected in the arrangement order, including the sequentially connected normal node tftp, the value-containing node host, the option node GET | PUT, the value-containing node source, and the option node destination | NULL. Figure 3 Figure 3 In FIG. 1, the normal node is indicated by a circular solid line box, the option node is indicated by a square box, and the value-containing node is indicated by a circular dashed line box.
[0064] For another software module, the defined command line format is written as ethtrunk 1 (trunkport | lacp) interface [ge1]. The two preset optional options trunkport and lacp of the option node (trunkport | lacp) are used by the software module to distinguish two different function functions implemented by the software module. One function function implemented by the software module is "adding port ge1 to static aggregation group 1", and the form of the command string is ethtrunk 1 trunkport interface ge1. Another function function implemented by the software module is "adding port ge1 to dynamic aggregation group 1", and the form of the command string is ethtrunk 1 lacp interface ge1.
[0065] In another embodiment, when each software module is defined, the storage sector size corresponding to each function of the software module is also defined, and the command definition macro CLI_ITEM of the software module to be written further includes the storage sector size of each function implemented by the software module. Different functions have different characteristics and different storage requirements. When a function is a first type of command having command storage requirements, the defined storage sector size of the function is greater than 0. The first type of command needs to be stored after execution, and thus needs to be allocated a storage sector of a corresponding size for storing the configuration data of the command string. When a function is a second type of command not having command storage requirements, the defined storage sector size of the function is 0. For example, for display type commands such as display and show, the commands do not need to be stored after execution, and thus do not need to be allocated a storage area for storage.
[0066] Even for functions belonging to the first type of command, different functions have different storage requirements. Some functions can only store one function parameter, while some functions can store multiple function parameters. Based on this, in one embodiment, when the storage sector size of a function is defined, the number of storage mapping units cmdnum of the function and the size of each storage mapping unit cmdsize are defined, and the total size of all storage mapping units allocated to the function is the storage sector size of the function. In actual applications, the number of storage mapping units cmdnum of a function is generally equal to the number of function parameters of the function, and also equal to the number of values of the value-containing parameters, i.e., a storage mapping unit is allocated to each function parameter of a function, so that different function parameters of a function can be stored in respective storage mapping units. For example, a function is vlan[INT], and the value of the value-containing node INT can be any one of 1, 2, 3, 4, and 5. The number of storage mapping units defined for the function is 5, and each storage mapping unit corresponds to a value of the value-containing node INT. One storage mapping unit is used to store vlan 1, another storage mapping unit is used to store vlan 2, and the other storage mapping units are used in the same way. Based on the above, the command definition macro CLI_ITEM of a software module defines the following contents:
[0067] (1) cliname##_help[] string array: The string array is used to store the help information of the command string.
[0068] (2) cli##cliname: a command structure of cli_item_t type, containing command line format, callback function identification funcid of each function function contained, pointer of callback function and help information. Cliname is the name of command structure and also the name of the software module.
[0069] (3) conf_set##funcid[] character array: the character array is used to record the storage sector size of each function function contained by the software module.
[0070] (4) Init##funcid() constructor, used to register the function functions contained by the command software module and set the storage sector of the function functions.
[0071] Only by defining the command definition macro CLI_ITEM of the software module and implementing the corresponding callback function, the development of a function function contained by the software module can be realized, and the concern for the underlying implementation details is avoided.
[0072] II. Registration of software module
[0073] Referring to the definition of the command definition macro CLI_ITEM of the software module, the command structure is defined as cli_item_t cli##cliname, and all cli_item_t are stored and represented by a linked list through the function cli_register(&cli##cliname). The cli_register is used as a registration function to add all cli_item_t to the function entry.
[0074] After the definition of the function functions contained by the software module, there is no registration entry, and by means of the characteristics of the compiler, the registration function does not need to be called separately at the main function entry for initialization. __attribute__((constructor)) is a feature in GCC and compatible compilers, which is used to indicate the compiler to mark a function as an initialization function automatically executed at program startup. In this embodiment, the feature is used to automatically run the marked related initialization function before the main function, avoiding the need to explicitly add the registration function such as cli_register to the program initialization process.
[0075] The definition of the command definition macro CLI_ITEM of the software module as above defines the storage sector size of each function of the software module, so when registering each software module, the storage sector of the corresponding storage space of each function of the software module can be automatically allocated according to the storage sector size of each function of the software module, and the storage sector of each function is used to store the configuration data of the command string of the function.
[0076] In one embodiment, the method of allocating the storage sector of each function in the storage space comprises: allocating the storage sector of each function in turn according to the registration order of the functions from the initial storage address of the storage space. When registering each function, the current storage offset address is determined according to the storage sectors already allocated to other functions, and then the storage sector starting from the storage offset address and having the storage sector size is allocated to the function being registered.
[0077] When the number cmdnum of the storage mapping units of a function and the size cmdsize of each storage mapping unit are defined, when allocating the storage sector of the function, a plurality of storage mapping units are allocated to the function as the storage sector according to the number and size of the storage mapping units of the function, that is, the storage sector composed of a plurality of storage mapping units having the corresponding size starting from the determined storage offset address is allocated to the function.
[0078] In the conventional method, when a command string needs to be stored, one method is to manually specify the storage address of each command string, and then store the command string at the corresponding storage address. However, in practice, the number of command strings is large, and it is difficult to manually specify the storage address of each command string and prone to errors. Another method is not to fix the storage address of each command string, and then store each command string in turn according to the order. This method does not need to manually specify the storage address of each command string, but in actual operation, the same command string may be obtained repeatedly several times, and according to this method, the command string will be stored several times, which has the problem of repeated storage and is difficult to determine whether there is repetition in practice.
[0079] The present application defines the storage sector of each function in the definition stage, and then automatically calculates and determines the storage sector of each function in the registration stage, so that the storage address of the command string of each function can be fixed, and manual calculation and specification are not required, which is beneficial to improve the storage accuracy and efficiency.
[0080] Furthermore, in the command-line integration framework, there is not just one software module; each software module has its own command-line format. In one embodiment, a command tree is generated based on the command-line formats of the registered software modules. The command tree is a tree structure formed by connecting the command nodes in the command-line formats of multiple registered software modules. Each registered software module's command-line format corresponds to a command node path in the command tree formed by sequentially connecting multiple command nodes.
[0081] In practical use, different software modules may share common command nodes in their command-line formats. Therefore, when registering each software module, the command nodes in the command-line format of the currently registered software module are automatically merged with the command nodes in the already formed command tree to update the command tree. Identical command nodes are merged, and each registered software module's command-line format corresponds to a command node path in the command tree, and this correspondence is known.
[0082] For example in Figure 4 In the command tree, the command line format for registered software module 1 is defined as A(B|C)[INT], the command line format for registered software module 2 is defined as A(B|C)D[INT], and the command line format for registered software module 3 is defined as ABDE. These three software modules share the common node A. In addition, software module 1 and software module 2 also share the option node (B|C). The partial structure of the command tree for these three software modules is as follows: Figure 4 As shown, the three command node paths starting from ordinary node A correspond to three different software modules. In practice, when more software modules are defined, the command tree structure becomes more complex, and there will be more instances of shared command nodes between different software modules, but the construction principle remains the same. Therefore, developers only need to use command node paths to represent a software module and execute it. Different software modules can be represented directly using different command node paths, and the command tree can be automatically merged and updated without manually adding or setting the relationships between different command nodes in the command tree.
[0083] III. Command String Parsing and Configuration Storage
[0084] After obtaining any input command string to be processed, the command string is first matched against the command node paths in the command tree, including:
[0085] The root node is the command node in the command tree that matches the first command node in the command string to be processed. The first command node in the command string to be processed is always a regular node. Then, each command node connected to the root node in the command tree is traversed sequentially to determine the command node path that matches the command string to be processed. The command node path determined in this way matches each command node in the command string to be processed one by one, starting from the determined root node.
[0086] Specifically, for any command node in the command string to be processed, it is matched with a normal node when the value of the command node in the command string is the same as the value of a normal node in the command tree; or, it is matched with an option node when the value of the command node in the command string is the same as one of the preset optional options of the option node in the command tree; or, it is matched with a value node when the value of the command node in the command string conforms to the predetermined data format of the value-containing node.
[0087] For example, based on Figure 4 The command tree structure shown illustrates that when a command string of AB D123 is received, the value of the first command node is A, which matches the value of a regular node A in the command tree. Therefore, regular node A is taken as the root node. Then, each command node under this root node is traversed sequentially. The value of the second command node is B, which is the same as the value of a regular node B in the command tree, and therefore matches. It also matches a preset optional option in option nodes B|C in the command tree. The third command node is D, which is the same as the value of a regular node D in the command tree, and therefore matches. Finally, the value of the fourth command node is 123, which conforms to the predetermined data format of a value node INT, and therefore matches. Thus, the command node path matching this command string is ultimately determined to be A(B|C)D[INT], therefore the target software module corresponding to this command string is software module 2. Furthermore, during the above matching process, based on the target command line format indicated by the command node path A(B|C)D[INT], it can be determined that the second command node in the command string to be processed matches the option node, and the fourth command node in the command string to be processed matches the value node.
[0088] Then, extract the values of the command nodes that match the option nodes in the command string to be processed to obtain the data of the option parameters of the command string to be processed, and extract the values of the command nodes that match the value nodes in the command string to be processed to obtain the data of the value parameters of the command string to be processed.
[0089] Since the data of the option parameter is used to identify the function function, the target function function possessed by the to-be-processed command string can be determined according to the extracted data of the option parameter, and the data of the value-containing parameter is determined to be a function parameter of the target function function. Since each function function defines a callback function and a callback function identifier funcid when being defined, the callback function identifier of the target function function can be determined as the callback function identifier of the to-be-processed command string.
[0090] After the target function function possessed by the to-be-processed command string is determined, the command type thereof can also be determined. One way is to use the callback function identifier funcid to represent the command type, for example, funcid>0 represents a first type of command, and funcid<0 represents a second type of command. Regardless of the representation manner, when the target function function possessed by the to-be-processed command string is determined to be a first type of command, the configuration storage method of the present application is executed, the to-be-processed command string is parsed according to the target command line format, and subsequent configuration storage operations are performed. When the target function function possessed by the to-be-processed command string is a second type of command, the to-be-processed command string is executed and then ended, and the configuration storage operation is not performed.
[0091] When the target function function is a first type of command, the configuration data of the to-be-processed command string is stored in the storage mapping unit corresponding to the target function function in the following manner. When the storage mapping unit of the target function function is one, the configuration data of the to-be-processed command string is stored in the storage mapping unit of the target function function in an overwriting manner. When the storage mapping unit of the target function function is multiple, the configuration data of the to-be-processed command string is stored in one of the storage mapping units of the target function function in an overwriting manner, and the storage mapping unit used to store the configuration data of the to-be-processed command string matches the configuration data of the to-be-processed command string, specifically, matches the function parameter identified by the data of the value-containing parameter of the to-be-processed command string.
[0092] For example, a storage mapping unit A is assigned to the only function function (the command string with the function function is A B D E) contained in the software module 3 (the command line format is A B D E) in the above example. When a command string 11 implementing the software module 1 is obtained as A B D E, the configuration data of the command string 11 is stored in the storage mapping unit A. When another command string 12 implementing the software module 1 is obtained again as A B D E, the configuration data of the command string 12 is stored in the storage mapping unit A to overwrite the configuration data of the command string 11.
[0093] For example, the function of the software module 2 (command line format A B D [INT]) in the above example is assigned a storage mapping unit B, and another function of the software module (command string A CD [INT]) is respectively assigned a storage mapping unit C and a storage mapping unit D. When a command string 21 of the software module 2 is obtained as A B D 123, the configuration data of the command string 21 is stored in the storage mapping unit B. When another command string 22 of the software module 2 is obtained as A C D 123, the configuration data of the command string 22 is stored in the storage mapping unit C. When another command string 23 of the software module 2 is obtained as A C D 234, the configuration data of the command string 23 is stored in the storage mapping unit D.
[0094] Four, configuration reading of the command string stored in the storage space
[0095] When configuration reading of a to-be-read command string is needed, the configuration data of the to-be-read command string is read from the storage sector corresponding to the software module of the to-be-read command string, and the read configuration data includes the data of the variable parameters and the corresponding callback function identifier funcid. The data of the variable parameters includes the data of the option parameters and / or the data of the value-containing parameters. As described above, the storage mapping unit matching the configuration data of the to-be-processed command string is stored when the to-be-processed command string is stored, and thus the configuration data can be read from the storage mapping unit corresponding to the to-be-read command string. The embodiment will not be described in detail. The callback function can be determined according to the callback function identifier funcid, and the data of the variable parameters is transmitted into the callback function to obtain the execution result of the to-be-read command string.
[0096] The above is only the preferred embodiment of the present application, and the present application is not limited to the above embodiment. It can be understood that other improvements and changes directly derived or thought by those skilled in the art without departing from the spirit and concept of the present application should be considered to be included in the protection scope of the present application.
Claims
1. A configuration storage method of a command line, characterized by, The configuration storage method comprises: acquiring an inputted to-be-processed command string; parsing the to-be-processed command string according to a target command line format corresponding to a target software module to which the to-be-processed command string belongs in the already defined registered software modules, extracting data of a variable parameter in the to-be-processed command string and determining a callback function identifier corresponding to a target function function possessed by the to-be-processed command string as a callback function identifier of the to-be-processed command string; wherein the variable parameter is a parameter with different data contents in different command strings belonging to the same software module, and each callback function identifier is used for uniquely identifying a callback function; storing configuration data of the to-be-processed command string in a storage space, the configuration data comprising data of the variable parameter in the to-be-processed command string and the callback function identifier, and the data of the variable parameter in the to-be-processed command string being used for passing parameters into a callback function corresponding to the callback function identifier of the to-be-processed command string when configuration is read to obtain an execution result of the to-be-processed command string; wherein a command definition macro of each software module is written when the software module is defined, the command definition macro of the software module comprising a command line format of the software module, the command line format of the software module indicating a linear linked list structure of multiple command nodes included in a command string belonging to the software module, a node type of each command node being one of an ordinary node, an option node and a value-containing node; in the command line format, each ordinary node has a unique value, each option node has multiple different preset optional options, and a first command node of the command line format of each software module is an ordinary node; when each software module is registered, command nodes in the command line format of the software module are merged with command nodes in an already formed command tree to update the command tree, the command tree being a tree structure formed by the command nodes in the command line formats of the multiple already registered software modules being connected in sequence, and the command line format of each already registered software module corresponding to a command node path formed by multiple command nodes connected in sequence in the command tree. The target command line format is parsed according to the to-be-processed command string, including: taking a command node in a command tree that matches a first command node in the to-be-processed command string as a root node, sequentially traversing each command node connected to the root node in the command tree to determine a command node path that matches the to-be-processed command string, and determining that each command node through which the obtained command node path sequentially passes from the root node one by one matches each command node in the to-be-processed command string; wherein, for any one command node in the to-be-processed command string, the command node matches a normal node when the value of the command node is the same as the value of the normal node in the command tree, or the command node matches an option node when the value of the command node is the same as one of the preset optional options of the option node in the command tree, or the command node matches a value-containing node when the value of the command node conforms to a predetermined data format of the value-containing node; the value of the command node in the to-be-processed command string that matches the option node is extracted to obtain data of an option parameter of the to-be-processed command string, and the value of the command node in the to-be-processed command string that matches the value-containing node is extracted to obtain data of a value-containing parameter of the to-be-processed command string; a target function function of the to-be-processed command string is determined according to the extracted data of the option parameter, the data of the value-containing parameter is determined to be a function parameter of the target function function, and a callback function identifier of the target function function is taken as a callback function identifier of the to-be-processed command string.
2. The configuration storage method according to claim 1, wherein The configuration storage method further includes: when each software module is defined, the storage sector size of each function function included in the software module is defined; when each software module is registered, the storage sectors in the storage space are allocated to each function function according to the storage sector size of each function function included in the software module, and the storage sector of each function function is used to store configuration data of a command string having the function function; and the configuration data of the to-be-processed command string is stored in the storage space in a corresponding manner, including: the configuration data of the to-be-processed command string is stored in the storage sector of the target function function in a corresponding manner.
3. The configuration storage method according to claim 2, wherein allocating the storage sectors in the storage space to each function function according to the storage sector size of each function function included in the software module includes: starting from the initial storage address of the storage space, the storage sectors of each function function are sequentially allocated in the order of registration of the function functions, and when each function function is registered, a storage offset address is determined according to the storage sectors already allocated to other function functions, and the storage sector with the storage sector size starting from the storage offset address is allocated to the currently registered function function.
4. The configuration storage method according to claim 2, wherein defining the storage sector size of each function function included in the software module includes: defining the number of storage mapping units of the function function and the size of each storage mapping unit, and the total size of all storage mapping units is the storage sector size of the function function; Allocating storage sectors to the function function according to the storage sector size of the function function comprises: allocating a plurality of storage mapping units to the function function as storage sectors according to the number and size of the storage mapping units of the function function.
5. The configuration storage method according to claim 4, wherein Correspondingly storing configuration data of the to-be-processed command string in a storage space comprises: When the storage mapping unit of the target function function is one, the configuration data of the to-be-processed command string is stored in the storage mapping unit of the target function function in an overwriting manner; When the storage mapping unit of the target function function is multiple, the configuration data of the to-be-processed command string is stored in one of the storage mapping units of the target function function in an overwriting manner, and the storage mapping unit used for storing the configuration data of the to-be-processed command string matches the configuration data of the to-be-processed command string.
6. The configuration storage method according to claim 2, wherein When the function function is a first type of command having a command storage requirement, the defined storage sector size of the function function is greater than 0; when the function function is a second type of command without a command storage requirement, the storage sector size of the function function is defined as 0. The configuration storage method further comprises: When the target function function to which the to-be-processed command string belongs is the first type of command, the step of correspondingly storing the configuration data of the to-be-processed command string in a storage space is executed after the to-be-processed command string is executed; When the target function function to which the to-be-processed command string belongs is the second type of command, the to-be-processed command string is ended after being executed.
7. The configuration storage method according to claim 2, wherein The variable parameters in the to-be-processed command string comprise an option parameter and a value-containing parameter, the data content of the option parameter is used for identifying the target function function, and the data content of the value-containing parameter is a function parameter of the target function function. Correspondingly storing the configuration data of the to-be-processed command string in a storage space comprises: Storing the data of the option parameter, the data of the value-containing parameter, and the callback function identifier in the storage space in a numerical form.
8. The configuration storage method according to claim 7, wherein The command definition macro of the software module comprises a command line format of the software module, callback functions of each function function contained in the software module and corresponding callback function identifiers of the callback functions, and storage sector sizes.
Citation Information
Patent Citations
Command parameter transmission method and device, electronic equipment and storage medium
CN116010124A
Method and apparatus for interacting with runnung software
EP2634693A1