CN113553301A - Header file processing method and device, computer readable storage medium and processor - Google Patents

Header file processing method and device, computer readable storage medium and processor Download PDF

Info

Publication number
CN113553301A
CN113553301A CN202110705930.7A CN202110705930A CN113553301A CN 113553301 A CN113553301 A CN 113553301A CN 202110705930 A CN202110705930 A CN 202110705930A CN 113553301 A CN113553301 A CN 113553301A
Authority
CN
China
Prior art keywords
file
header
file name
target
extracted
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
CN202110705930.7A
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.)
Netease Hangzhou Network Co Ltd
Original Assignee
Netease Hangzhou Network 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 Netease Hangzhou Network Co Ltd filed Critical Netease Hangzhou Network Co Ltd
Priority to CN202110705930.7A priority Critical patent/CN113553301A/en
Publication of CN113553301A publication Critical patent/CN113553301A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/14Details of searching files based on file metadata
    • G06F16/148File search processing
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/16File or folder operations, e.g. details of user interfaces specifically adapted to file systems
    • G06F16/162Delete operations
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/17Details of further file system functions
    • G06F16/174Redundancy elimination performed by the file system
    • G06F16/1748De-duplication implemented within the file system, e.g. based on file segments
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/20Software design
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/44Encoding
    • G06F8/443Optimisation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • G06F8/73Program documentation

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Software Systems (AREA)
  • Data Mining & Analysis (AREA)
  • Databases & Information Systems (AREA)
  • Library & Information Science (AREA)
  • Human Computer Interaction (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention discloses a header file processing method, a header file processing device, a computer readable storage medium and a processor. Wherein, the method comprises the following steps: acquiring a target file, wherein the target file comprises the file name of the imported header file; extracting a file name from the target file; searching whether a historical file name matched with the extracted file name exists in a file name set, wherein the file name set comprises the file name of a header file extracted in a historical mode; and when the historical file name matched with the extracted file name exists in the file name set, determining the header file as the header file which is repeatedly imported, and deleting the header file which is repeatedly imported. The invention solves the technical problem that the same header file is repeatedly imported in the project development in the related technology.

Description

Header file processing method and device, computer readable storage medium and processor
Technical Field
The present invention relates to the field of computers, and in particular, to a method and an apparatus for processing a header file, a computer-readable storage medium, and a processor.
Background
In some project development, the required header file is usually imported by using # import, and since a project may be developed by multiple persons in cooperation, or there may be iterations of multiple versions, the same header file may be contained multiple times, including the header file content and the header file name being repeatedly imported, for example: 1. # include XXX. h, as the header file content is imported repeatedly; 2. # import XXX. h, which is the header filename, is repeatedly imported.
Although the code can still be compiled after the header file is repeatedly imported, the installation package of the project is too large due to the repeated import of the header file, so that the speed of installation by using the installation package is influenced, and the user experience is further influenced.
In the related art, no effective solution is provided at present for the problem that the same header file is repeatedly imported in the project development.
Disclosure of Invention
The embodiment of the invention provides a header file processing method and device, a computer readable storage medium and a processor, which are used for at least solving the technical problem that the same header file is repeatedly imported in project development in the related art.
According to an aspect of the embodiments of the present invention, there is provided a header file processing method, including: acquiring a target file, wherein the target file comprises the file name of an imported header file; extracting the file name from the target file; searching whether a historical file name matched with the extracted file name exists in a file name set, wherein the file name set comprises the file name of a header file extracted in a historical mode; determining the header file as a header file which is repeatedly imported under the condition that the historical file name which is matched with the extracted file name exists in the file name set; and deleting the header file which is repeatedly imported.
Further, after searching whether a history file name matching the extracted file name exists in a file name set, adding the extracted file name to the file name set under the condition that the history file name matching the extracted file name does not exist in the file name set.
Further, acquiring the target file includes: acquiring a target search path; and acquiring the target file according to the target search path.
Further, obtaining the target file according to the target search path includes: acquiring all files searched according to the target search path; determining appointed prefix information; and acquiring the target file with the appointed prefix information in all the searched files.
Further, after the target file is obtained, changing a suffix in the target search path into a specified suffix to obtain a file path of the declaration file corresponding to the target file; acquiring a declaration file corresponding to the target file based on the file path of the declaration file; extracting the file name from the declaration file; searching whether a history file name matched with the extracted file name exists in a file name set; and under the condition that the historical file name matched with the extracted file name exists in the file name set, determining the header file as a header file which is repeatedly imported, and deleting the header file which is repeatedly imported.
Further, extracting the file name from the target file includes: searching for a specified identifier in the target file; determining the content between the starting position of the target file and the designated identifier as the header file import area; and extracting the file name of the header file from the header file lead-in area of the target file.
Further, extracting the file name of the header file from the header file lead-in area of the target file includes: acquiring an import header file statement from a header file area of the target file; and deleting the prefix and the suffix from the sentence of the imported header file to obtain the file name of the header file.
According to an aspect of the embodiments of the present invention, there is provided a header file processing apparatus including: the device comprises an acquisition module, a storage module and a processing module, wherein the acquisition module is used for acquiring a target file, and the target file comprises the file name of an imported header file; the extracting module is used for extracting the file name from the target file; the searching module is used for searching whether a historical file name matched with the extracted file name exists in a file name set, wherein the file name set comprises the file name of a header file extracted in a historical mode; the determining module is used for determining the header file as a header file which is repeatedly imported under the condition that the historical file name matched with the extracted file name exists in the file name set; and the deleting module is used for deleting the header file which is repeatedly imported.
According to an aspect of the embodiments of the present invention, there is provided a computer-readable storage medium, where the computer-readable storage medium includes a stored program, and when the program runs, the apparatus where the computer-readable storage medium is located is controlled to execute the above processing method for a header file.
According to an aspect of the embodiments of the present invention, there is provided a processor for executing a program, wherein the program executes the method for processing the header file.
In the embodiment of the invention, a target file is obtained, wherein the target file comprises the file name of an imported header file; extracting the file name from the target file; searching whether a historical file name matched with the extracted file name exists in a file name set, wherein the file name set comprises the file name of a header file extracted in a historical mode; determining the header file as a header file which is repeatedly imported under the condition that the historical file name which is matched with the extracted file name exists in the file name set; and deleting the header file which is repeatedly imported. According to the scheme, the documents corresponding to the repeatedly imported header files can be automatically searched and output to developers, the developers do not need to manually analyze and check one by one, the time for searching and deleting the repeatedly imported files is greatly prolonged, certain high efficiency is achieved, and the technical problem that the same header files are repeatedly imported in project development in the related technology is solved.
Drawings
The accompanying drawings, which are included to provide a further understanding of the invention and are incorporated in and constitute a part of this application, illustrate embodiment(s) of the invention and together with the description serve to explain the invention without limiting the invention. In the drawings:
FIG. 1 is a flow chart of a method for processing header files according to an embodiment of the present application;
FIG. 2 is a flow chart of an alternative header processing method according to an embodiment of the present application;
FIG. 3 is a flow chart of an alternative header processing method according to an embodiment of the present application;
FIG. 4 is a flow chart of an alternative header processing method according to an embodiment of the present application;
FIG. 5 is a flow chart of an alternative header processing method according to an embodiment of the present application;
fig. 6 is a schematic diagram of an apparatus for header files according to an embodiment of the present application.
First, terms appearing in the following examples of the present application are explained:
header file: in programming, particularly in C language and C + +, the header or inclusion file is a file, usually in the form of source code, that is automatically included by the compiler when processing another source file. Generally, a programmer includes header files into the headers of other source files via compiler directives.
# include: in C language, # include preprocessing instructions are typically used to cause the contained file content to be inserted into the instruction points.
# import: the language used in Objective-C is similar to the instruction of # include in C, and # import also has the function of import prevention, i.e. ensuring that a file is contained only once.
Detailed Description
In order to make the technical solutions of the present invention better understood, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
It should be noted that the terms "first," "second," and the like in the description and claims of the present invention and in the drawings described above are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used is interchangeable under appropriate circumstances such that the embodiments of the invention described herein are capable of operation in sequences other than those illustrated or described herein. Furthermore, the terms "comprises," "comprising," and "having," and any variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, system, article, or apparatus that comprises a list of steps or elements is not necessarily limited to those steps or elements expressly listed, but may include other steps or elements not expressly listed or inherent to such process, method, article, or apparatus.
In accordance with an embodiment of the present invention, there is provided an embodiment of a method for processing a header file, it should be noted that the steps illustrated in the flowchart of the drawings may be performed in a computer system such as a set of computer executable instructions, and that while a logical order is illustrated in the flowchart, in some cases the steps illustrated or described may be performed in an order different than that herein.
Fig. 1 is a method for processing a header file according to an embodiment of the present application, as shown in fig. 1, the method includes the following steps:
step S102, obtaining a target file, wherein the target file comprises the file name of the imported header file.
Specifically, the target file may be an implementation file to be subjected to repeated import query of the header file. There are various ways to obtain the target file. In an optional embodiment, a target search path corresponding to a target file may be obtained, and the target file may be obtained based on the target search path.
In an optional embodiment, a given path may be obtained first, for example, the given path may be a root path of the whole project, or any Target path of the project, or a path of a module of the project; based on a given path, taking the m suffix and the mm suffix as condition searching to obtain a target searching path for indicating a target file; and obtaining the target file based on the target searching path.
Step S104, extracting the file name from the target file.
Specifically, the file name of the header file appears in the sentence of the header file, so that the sentence of the header file can be found from the target file, and the file name of the header file can be extracted from the sentence according to the syntax of the header file.
And step S106, searching whether a history file name matched with the extracted file name exists in a file name set, wherein the file name set comprises the file name of the history extracted header file.
Specifically, if a history file name identical to the extracted file name exists in the file name set, it is determined that the identical file name exists in the implementation file, and it is determined that a duplicate header file exists.
The file name set is actually a set of file names of header files, and the file names included in the file name set are history file names extracted previously.
In an alternative embodiment, after extracting the file name of the target file each time, the above step S106 is performed, and it is determined whether a history file name matching the extracted file name exists in the extracted file name set, and if not, the extracted file name is added to the file name set, so that each first extracted file name is included in the file name set, and then it may be determined whether the file name sufficiently appears based on the file name set, so as to determine whether the header file is repeated to the import.
In step S108, when a history file name matching the extracted file name exists in the file name set, the header file is determined to be a header file to be repeatedly imported.
In the above-described arrangement, if there is a history file name matching the extracted file name in the file name set, it is described that the currently extracted file name has appeared before that, and therefore the header file is determined to be a header file that is repeatedly imported.
In an alternative embodiment, given a search path, each file under the search path may be traversed through the above scheme, so as to determine all repeatedly imported header files under the search path, and then the file names of the repeatedly imported header files form a repeatedly imported set, and the repeatedly imported set is output, where the output format may be set by a developer, for example, may be output in a text format, and the like. The developer can clear or otherwise process the file names repeatedly imported according to the file names in the repeatedly imported set, so that the size of the project installation package is reduced, and the installation speed of the installation package can be increased.
It should be noted that the steps in the embodiment of the present application may be performed by executing a script that queries the repeated header file. And the developer only needs to transmit the file path of the target file as an input parameter.
It should be further noted that steps S102 to S106 may be implemented by traversing the target search path of the target file, and after the target search path is traversed, all header files repeatedly imported into the target file are obtained. The file names of the header files which are repeatedly imported can be used as results to be sorted and output. For example, the output content may begin with a class name, separated by a colon in the middle, followed by filenames in the duplicate import set contained in the class, each filename in the duplicate import set being separated by a comma. After the result for recording the repeatedly imported header files is obtained, the staff can clear the repeatedly imported header files in the known target file based on the result, so that the developers are not required to manually analyze and investigate the repeatedly imported header files one by one.
And step S1010, deleting the header file which is repeatedly imported.
According to the searched repeated import header file, the file can be annotated or deleted, so that the total code amount and the volume size of the installation package are reduced, and the compiling speed is improved. According to the content output by the search result, the module memory responsible for each member of the development team can be quickly found, so that each member of the team can perform specific operation according to the actual condition, developers do not need to know all services, and the method is very friendly to the developers.
As can be seen from the above, in the above embodiments of the present application, the target file is obtained, where the target file includes the file name of the imported header file; extracting a file name from the target file; searching whether a historical file name matched with the extracted file name exists in a file name set, wherein the file name set comprises the file name of a header file extracted in a historical mode; and when the historical file name matched with the extracted file name exists in the file name set, determining the header file as the header file which is repeatedly imported, and deleting the header file which is repeatedly imported. According to the scheme, the documents corresponding to the repeatedly imported header files can be automatically searched and output to developers, the developers do not need to manually analyze and check one by one, the time for searching and deleting the repeatedly imported files is greatly prolonged, certain high efficiency is achieved, and the technical problem that the same header files are repeatedly imported in project development in the related technology is solved.
As an alternative embodiment, after searching whether there is a history file name matching the extracted file name in the file name set, the method further includes: in the case where there is no history file name matching the extracted file name in the file name set, the extracted file name is added to the file name set.
In the above-described aspect, when there is no history file name matching the extracted file name in the file name set, it is described that the header file is not repeatedly imported, and the file name of the header file is added to the file name set and used to continue determining whether or not another header file is repeatedly imported.
As an alternative embodiment, the obtaining the target file includes: determining a target search path; and acquiring a target file according to the target search path.
Specifically, the target search path may be a predetermined path. The predetermined path may be a root path of the whole project, any Target path of the project, or a path of a module of the project. Since the realization files in the project may have the possibility of mixed compilation, the target file can be obtained by searching with the m suffix and the mm suffix as conditions under a preset path.
It should be noted that, after the search path is obtained, it may be determined whether the search path exists first, and if it is determined that the search path is missing or the search path is not empty, the process is directly ended, and if the query result determines that the file exists in the search path, the process proceeds to the step of obtaining the target file according to the target search path.
In the scheme, after the search path is used as an input parameter and is transmitted into the script for searching the repeated head file, whether the search path exists is judged by inquiring the script for searching the repeated head file, and under the condition that the search path exists, the search is carried out according to the search path to obtain the target file. And the target file is given by inputting the search path, so that the searched module can be adjusted by adjusting the search path of the input end, the module search can be carried out, and the whole project does not need to be repeatedly imported and searched.
Fig. 2 is a flowchart of an alternative header processing method according to an embodiment of the present application, and the following describes, with reference to fig. 2, an alternative header processing method, where the method includes:
s201: a given path is received.
Because the present solution has no specific requirement on the given path, the given path may be a root path of the whole project, or any Target path of the project, or a path of a module of the project. In order to prevent a given path from being incorrect, a determination may be made thereafter as to whether a given lookup path exists, and if not, ending directly, the following steps may be performed.
S202: based on the given path, a set of search paths is constructed.
Since there may be a possibility of hash of the implementation files in the project, in this search, it is necessary to perform a conditional search with the.m suffix and the.mm suffix, resulting in a set of search paths.
S203: and through traversing the search path obtained in the step S202, a specific repeated import set of a certain type of file is obtained.
S204: and sorting and outputting the result after the S203 traversal.
Specifically, the output content may begin with a class name, be separated by a colon in the middle, be followed by filenames in the duplicate import set included in the class, and be separated by commas for each filename in the duplicate import set.
As an optional embodiment, obtaining the target file according to the target search path includes: acquiring all files searched according to the target search path; determining appointed prefix information; and acquiring all the files with the appointed prefix information in all the searched files as target files.
Specifically, since the file in a given search path may contain the referenced third-party file or other associated file, but does not need to search for the header file in these third-party files or other related files, the above steps are used to filter these third-party files or other related files, and only the required specified file is taken as the target file to extract the file name of the header file.
Because the project files created in the project specification all have the named prefixes specified by the projects, the named prefixes specified by the projects can be used as the specified prefix information, and the files under the search path are filtered, so that the target file containing the specified prefix information is obtained.
Fig. 3 is a flowchart of an alternative header processing method according to an embodiment of the present application, and the following describes, with reference to fig. 3, an alternative header processing method, where the method includes:
s301: incoming parameters are acquired.
S302: and extracting the file name under the search path.
Generally, project files created in the project specification all contain named prefixes specified by the project, and files under the search path may contain referenced third-party files or other associated files, so that non-associated files need to be filtered, and only files with specified prefixes under the search path are subjected to repeated header file search. Generally, the acquiring of the file path in S301 means: Users/Documents/ProjectName/classa.m, with the extracted file name ClassA.
S303: and traversing the appointed prefix information set, if the file name prefix extracted in the S402 is matched with the prefix information in the prefix information set, executing the next step, and if not, ending the current process in advance, thereby eliminating third-party files or other associated files, saving the searching time and improving the searching accuracy.
S304: and reading the content of the current file line by line in a read-only mode.
S305: a header file lead-in area is determined.
Since the header file lead-in area is placed at the head of the file, reading is started from the beginning. Generally, since the implementation code area starts with @ implementation, the header file lead-in area is determined to be an intermediate area with the file start position as the head and @ implementation as the tail. On the basis, a judgment with @ interface as a tail is added, namely a head file lead-in area takes a file start position as a head and an @ augmentation or an intermediate area with @ interface as a tail.
As the file area is realized, a code area defined by the current class classification is possible, judgment with the interface as the tail is added, the determination of the leading-in area of the header file can be accelerated, and the judgment time is saved.
S306: all file name sets are retained for the following steps.
The header file is typically imported in the form of: the # import "class a.h" or # include "class a.h", required is the extracted filename: ClassA. Firstly, judging whether ClassA is in a file name set or not, and if not, adding ClassA into the file name set; if so, determining ClassA as the header file of the repeated import, and adding ClassA to the repeated file name set. Through the steps, header files which are repeatedly imported can be extracted, and the file names of the header files which are repeatedly imported can form a repeated import set.
S307: and in the declaration file corresponding to the file name, taking the file name set reserved in the S406 as an initialization parameter, and searching and returning the repeated import in the declaration file.
S308: and merging the repeated import in the statement file and the implementation file to obtain a finally found repeated import set.
As an optional embodiment, after obtaining the target file, the method further includes: changing the suffix in the target search path into an appointed suffix to obtain a file path of the declaration file corresponding to the target file; acquiring a declaration file corresponding to the target file based on the file path of the declaration file; extracting the file name from the declaration file; searching whether a history file name matched with the extracted file name exists in a file name set; determining the header file as a header file which is repeatedly imported under the condition that the historical file name which is matched with the extracted file name exists in the file name set; and deleting the header file which is repeatedly imported.
Specifically, the target file may be an implementation file, and after determining a header file repeatedly imported from the implementation file, the target file may further continue to search for the header file repeatedly imported from the declaration file corresponding to the implementation file. The manner of finding a duplicate imported header file in the declaration file may be the same as the manner of finding a duplicate imported header file in the target file.
In an optional embodiment, the file path of the declaration file corresponding to the target file is determined according to the target search path of the target file, the file path of the declaration file is traversed, and the file name of the header file in the declaration file is extracted. Similarly, matching the extracted file name with the existing file name stored in a file name set, and determining the header file as a header file which is repeatedly imported under the condition that the historical file name matched with the extracted file name exists in the file name set; adding the extracted filename to a set of filenames in the event that the historical filename matching the extracted filename does not exist in the set of filenames. And through the traversal, the header file repeatedly imported into the statement file can be obtained, and the header file repeatedly imported can be deleted.
Fig. 4 is a flowchart of an alternative header processing method according to an embodiment of the present application, which is used to further describe the step S307, and the following describes an alternative header processing method with reference to fig. 4, where the method includes:
s401: incoming parameters are checked.
The incoming parameters comprise a search path and all file name sets for realizing files, if the incoming repeated import set is empty, the current process is ended, if the incoming repeated import set is not empty, the parameters of the search path are continuously checked, if the search path is not a file type, the current process is ended, and if the search path is not a file type, the next operation is carried out.
S402: and replacing m for the suffix of the implementation file obtained after the check of the S401 with h, namely declaring the file path.
Generally, the implementation file is named classa.m, its suffix is.m; the declaration document is classa.h with the suffix. So if it is a hash file, then the general implementation file is named classa.mm with the suffix of.mm; the declaration file type and the suffix are not changed, and only the suffix is replaced by h from mm, namely the declaration file path. After the replacement, the path of the replaced declaration file is required to be judged, if the path of the declaration file is not the file type, the current process is ended, and if the path of the declaration file is not the file type, the next operation is carried out.
S403: and reading the content of the current file line by line in a read-only mode.
S404: and acquiring a header file lead-in area.
Usually the header file lead-in area is placed at the head of the file, so we only need to determine where the header file lead-in area ends from the beginning to read. More generally, the implementation code area of the declaration file begins with @ interface, so that the file lead-in area of the declaration file header is determined to be a middle area with the file start position as the head and @ interface as the tail.
S405: and searching for the header file which is repeatedly imported according to the file name set.
The header file is typically imported in the form of: the # import "class a.h" or # include "class a.h", required is the extracted filename: ClassA. Firstly, judging whether ClassA is in a file name set or not, and if not, adding ClassA into the file name set; if so, determining ClassA as the header file of the repeated import, and adding ClassA to the repeated file name set. Through the steps, header files which are repeatedly imported can be extracted, and the file names of the header files which are repeatedly imported can form a repeated import set.
S406: and returning the searched head file which is repeatedly imported.
As an alternative embodiment, extracting the file name from the target file includes: searching a designated identifier in a target file; determining the content between the initial position of the target file and the designated identifier as a header file import area; the file name of the header file is extracted from the header file lead-in area of the target file.
Specifically, the specified identifier may be @ implementation. Since the implementation code area in a file usually starts with @ implementation, it can be determined that the header file lead-in area is an intermediate area with the file start position as the head and the @ implementation as the tail.
Furthermore, the designated identifier may further include @ interface, and since there may be a code region defined by the current class classification in the code region, the determination with @ interface as the tail is also added, which can accelerate the determination of the import header file region and save the determination time.
It should be noted that the above manner can still be adopted for extracting the file name from the declaration file, and details are not described here.
Fig. 5 is a flowchart of an alternative header processing method according to an embodiment of the present application, which is used to further describe step S203, and the following describes an alternative header processing method with reference to fig. 5, where the method includes:
s501: incoming parameters are acquired. Specifically, the parameters transmitted here are the search paths obtained in step S202.
S502: and reading the content of the current file in a read-only mode and reading line by line.
S503, determining a header file lead-in area.
Since the header file lead-in area is placed at the head of the file, reading is started from the beginning. Generally, since the implementation code area starts with @ implementation, the header file lead-in area is determined to be an intermediate area with the file start position as the head and @ implementation as the tail.
S504: in S503, header file lead-in areas are determined, and file names are extracted for the lead-in header files among the areas.
The header file is typically imported in the form of: the # import "class a.h" or # include "class a.h", required is the extracted filename: ClassA. Firstly, judging whether ClassA is in a file name set or not, and if not, adding ClassA into the file name set; if so, determining ClassA as the header file of the repeated import, and adding ClassA to the repeated file name set. Through the steps, header files which are repeatedly imported can be extracted, and the file names of the header files which are repeatedly imported can form a repeated import set.
As an alternative embodiment, extracting the file name of the header file from the header file lead-in area of the target file includes: acquiring an import header file statement from a header file area of a target file; and deleting the prefix and the suffix from the sentence of the imported header file to obtain the file name of the header file.
In an alternative embodiment, for example, # import "class a.h", the prefix # import and the suffix are removed to obtain the file name class a, and for example, # include "class a.h", the prefix # include and the suffix are removed to obtain the file name class a.
According to an embodiment of the present invention, there is provided an embodiment of a header processing apparatus, and fig. 6 is a schematic diagram of an apparatus for processing a header according to an embodiment of the present application, and with reference to fig. 6, the apparatus includes:
an obtaining module 60, configured to obtain a target file, where the target file includes a file name of an imported header file;
an extraction module 62, configured to extract a file name from the target file;
a searching module 64, configured to search whether a historical filename matching the extracted filename exists in a filename set, where the filename set includes filenames of the historically extracted header files;
a determining module 66, configured to determine that the header file is a header file that is repeatedly imported when a history file name matching the extracted file name exists in the file name set;
a deleting module 68, configured to delete the repeatedly imported header file.
As an alternative embodiment, the apparatus further comprises: and the extracting module is used for adding the extracted file name into the file name set under the condition that the history file name matched with the extracted file name does not exist in the file name set after searching whether the history file name matched with the extracted file name exists in the file name set.
As an alternative embodiment, the obtaining module includes: the first determining submodule is used for determining a target searching path; and the obtaining sub-module is used for obtaining the target file according to the target searching path.
As an alternative embodiment, the obtaining sub-module includes: the first acquisition unit is used for acquiring all the files searched according to the target search path; a first determination unit configured to determine the specified prefix information; and the second determining unit is used for acquiring the files with the appointed prefix information in all the searched files as target files.
As an alternative embodiment, the apparatus further comprises: the change module is used for changing the suffix in the target search path into the specified suffix after the target file is obtained, and obtaining the file path of the declaration file corresponding to the target file; the second acquisition module is used for acquiring the declaration file corresponding to the target file based on the file path of the declaration file; the second extraction module is used for extracting the file name from the declaration file; the second searching module is used for searching whether a history file name matched with the extracted file name exists in the file name set; the second determining module is used for determining the header file as a header file which is repeatedly imported under the condition that the historical file name matched with the extracted file name exists in the file name set; and the second deleting module is used for deleting the header file which is repeatedly imported.
As an alternative embodiment, the extraction module comprises: the searching submodule is used for searching the designated identification in the target file; the determining submodule is used for determining the content between the initial position of the target file and the designated identification as a header file lead-in area; and the extraction submodule is used for extracting the file name of the header file from the header file lead-in area of the target file.
As an alternative embodiment, the extraction sub-module comprises: a third obtaining unit, configured to obtain a header file import statement from a header file area of the target file; and the deleting unit is used for deleting the prefix and the suffix from the sentence of the imported header file to obtain the file name of the header file.
According to an embodiment of the present invention, a computer-readable storage medium is provided, where the computer-readable storage medium includes a stored program, and when the program runs, the apparatus where the computer-readable storage medium is located is controlled to execute the above processing method for a header file.
According to an embodiment of the present invention, a processor is provided, where the processor is configured to execute a program, where the program executes the above header processing method.
The above-mentioned serial numbers of the embodiments of the present invention are merely for description and do not represent the merits of the embodiments.
In the above embodiments of the present invention, the descriptions of the respective embodiments have respective emphasis, and for parts that are not described in detail in a certain embodiment, reference may be made to related descriptions of other embodiments.
In the embodiments provided in the present application, it should be understood that the disclosed technology can be implemented in other ways. The above-described embodiments of the apparatus are merely illustrative, and for example, the division of the units may be a logical division, and in actual implementation, there may be another division, for example, multiple units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, units or modules, and may be in an electrical or other form.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, functional units in the embodiments of the present invention may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, and can also be realized in a form of a software functional unit.
The integrated unit, if implemented in the form of a software functional unit and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a computer-readable storage medium and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned computer-readable storage media comprise: a U-disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a removable hard disk, a magnetic or optical disk, and other various media capable of storing program codes.
The foregoing is only a preferred embodiment of the present invention, and it should be noted that, for those skilled in the art, various modifications and decorations can be made without departing from the principle of the present invention, and these modifications and decorations should also be regarded as the protection scope of the present invention.

Claims (10)

1. A method for processing a header file, comprising:
acquiring a target file, wherein the target file comprises the file name of an imported header file;
extracting the file name from the target file;
searching whether a historical file name matched with the extracted file name exists in a file name set, wherein the file name set comprises the file name of a header file extracted in a historical mode;
determining the header file as a header file which is repeatedly imported under the condition that the historical file name which is matched with the extracted file name exists in the file name set;
and deleting the header file which is repeatedly imported.
2. The method of claim 1, wherein after searching a set of filenames for a historical filename matching the extracted filename, the method further comprises:
adding the extracted filename to the set of filenames in the event that the historical filename matching the extracted filename does not exist in the set of filenames.
3. The method of claim 1, wherein obtaining a target file comprises:
determining a target search path;
and acquiring the target file according to the target search path.
4. The method of claim 3, wherein obtaining the target file according to the target search path comprises:
acquiring all files searched according to the target search path;
determining appointed prefix information;
and acquiring the target file with the appointed prefix information in all the searched files.
5. The method of claim 3, wherein after obtaining the target file, the method further comprises:
changing the suffix in the target search path into an appointed suffix to obtain a file path of the declaration file corresponding to the target file;
acquiring a declaration file corresponding to the target file based on the file path of the declaration file;
extracting the file name from the declaration file;
searching whether a history file name matched with the extracted file name exists in a file name set;
determining the header file as a header file which is repeatedly imported under the condition that the historical file name which is matched with the extracted file name exists in the file name set;
and deleting the header file which is repeatedly imported.
6. The method of claim 1, wherein extracting the filename from the target file comprises:
searching for a specified identifier in the target file;
determining the content between the starting position of the target file and the designated identifier as the header file import area;
and extracting the file name of the header file from the header file lead-in area of the target file.
7. The method of claim 6, wherein extracting the file name of the header file from the header file lead-in area of the target file comprises:
acquiring an import header file statement from a header file area of the target file;
and deleting the prefix and the suffix from the sentence of the imported header file to obtain the file name of the header file.
8. A header file processing apparatus, comprising:
the device comprises an acquisition module, a storage module and a processing module, wherein the acquisition module is used for acquiring a target file, and the target file comprises the file name of an imported header file;
the extracting module is used for extracting the file name from the target file;
the searching module is used for searching whether a historical file name matched with the extracted file name exists in a file name set, wherein the file name set comprises the file name of a header file extracted in a historical mode;
the determining module is used for determining the header file as a header file which is repeatedly imported under the condition that the historical file name matched with the extracted file name exists in the file name set;
and the deleting module is used for deleting the header file which is repeatedly imported.
9. A computer-readable storage medium, comprising a stored program, wherein when the program runs, the apparatus on which the computer-readable storage medium is located is controlled to execute the header file processing method according to any one of claims 1 to 7.
10. A processor, characterized in that the processor is configured to execute a program, wherein the program executes a method for processing a header file according to any one of claims 1 to 7.
CN202110705930.7A 2021-06-24 2021-06-24 Header file processing method and device, computer readable storage medium and processor Pending CN113553301A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110705930.7A CN113553301A (en) 2021-06-24 2021-06-24 Header file processing method and device, computer readable storage medium and processor

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110705930.7A CN113553301A (en) 2021-06-24 2021-06-24 Header file processing method and device, computer readable storage medium and processor

Publications (1)

Publication Number Publication Date
CN113553301A true CN113553301A (en) 2021-10-26

Family

ID=78130890

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110705930.7A Pending CN113553301A (en) 2021-06-24 2021-06-24 Header file processing method and device, computer readable storage medium and processor

Country Status (1)

Country Link
CN (1) CN113553301A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116069338A (en) * 2023-03-07 2023-05-05 深圳开源互联网安全技术有限公司 Function library reference detection method, device, equipment and readable storage medium
CN117251205A (en) * 2023-11-16 2023-12-19 沐曦集成电路(杭州)有限公司 Method, device, equipment and medium for processing header file

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2003015884A (en) * 2001-07-04 2003-01-17 Denso Corp Device and program for checking duplicate definition
CN106406913A (en) * 2016-10-28 2017-02-15 武汉斗鱼网络科技有限公司 Method and system for extracting codes from project
WO2019148816A1 (en) * 2018-02-05 2019-08-08 Beijing Elex Technology Co., Ltd Method and apparatus for data compilation, electronic device and computer readable storage medium
CN111813749A (en) * 2020-08-21 2020-10-23 网易(杭州)网络有限公司 File filtering method and device, electronic equipment and storage medium

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2003015884A (en) * 2001-07-04 2003-01-17 Denso Corp Device and program for checking duplicate definition
CN106406913A (en) * 2016-10-28 2017-02-15 武汉斗鱼网络科技有限公司 Method and system for extracting codes from project
WO2019148816A1 (en) * 2018-02-05 2019-08-08 Beijing Elex Technology Co., Ltd Method and apparatus for data compilation, electronic device and computer readable storage medium
CN111813749A (en) * 2020-08-21 2020-10-23 网易(杭州)网络有限公司 File filtering method and device, electronic equipment and storage medium

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
MR.BEAN-PIG: "python:扫描目录下重复引用【头文件】的文件", pages 1 - 3, Retrieved from the Internet <URL:《https://blog.csdn.net/z714405489/article/details/97798487》> *
朱长元等: "《Python3 快速入门与实战》", 苏州大学出版社, pages: 124 - 54 *

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116069338A (en) * 2023-03-07 2023-05-05 深圳开源互联网安全技术有限公司 Function library reference detection method, device, equipment and readable storage medium
CN116069338B (en) * 2023-03-07 2023-08-11 深圳开源互联网安全技术有限公司 Function library reference detection method, device, equipment and readable storage medium
CN117251205A (en) * 2023-11-16 2023-12-19 沐曦集成电路(杭州)有限公司 Method, device, equipment and medium for processing header file
CN117251205B (en) * 2023-11-16 2024-02-06 沐曦集成电路(杭州)有限公司 Method, device, equipment and medium for processing header file

Similar Documents

Publication Publication Date Title
CN112118232B (en) Message protocol analysis method and device
CN113553301A (en) Header file processing method and device, computer readable storage medium and processor
CN111177318A (en) Method, device and computer readable storage medium for executing international business
CN110851209B (en) Data processing method and device, electronic equipment and storage medium
CN107885501B (en) Method and device for obtaining mutual reference relationship of components in Android
CN102647414A (en) Protocol analysis method, protocol analysis device and protocol analysis system
CN111367595B (en) Data processing method, program running method, device and processing equipment
KR102033416B1 (en) Method for generating data extracted from document and apparatus thereof
CN104169912A (en) Information processing terminal and method, and information management apparatus and method
CN112540862A (en) Interface document data generation method, device, equipment and storage medium
CN106648638A (en) Python-based R.java file optimization method and system
CN111159497A (en) Regular expression generation method and regular expression-based data extraction method
CN111729313A (en) Language configuration method and device, storage medium and electronic device
CN103544298A (en) Log analysis method and analysis device for component
JP2008305386A (en) Program pattern analyzing device, pattern appearance status information production method, pattern information creation device and program
CN107145538B (en) Table data query method, device and system
CN111083054B (en) Route configuration processing method and device, computer equipment and storage medium
CN112306501A (en) Business data acquisition method and device, storage medium and computing equipment
CN114611039B (en) Analysis method and device of asynchronous loading rule, storage medium and electronic equipment
CN109923538B (en) Text search device, text search method, and computer program
CN106648618B (en) Text information generation method and device for virtual application
CN112732743B (en) Data analysis method and device based on Chinese natural language
CN110764777B (en) ELF file generation method, ELF file, equipment and storage medium
CN114816364A (en) Method, device and application for dynamically generating template file based on Swagger
CN107577476A (en) A kind of Android system source code difference analysis method, server and medium based on Module Division

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination