├── _complyAll ├── .gitignore ├── _bettyComply ├── preview.gif ├── preview2.gif ├── update.sh ├── _comply_all.sh ├── _watch_n_comply.sh ├── flush.sh ├── install.sh ├── man └── betty_comply.1 ├── README.md ├── LICENSE └── betty-comply.pl /_complyAll: -------------------------------------------------------------------------------- 1 | _comply_all.sh -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | test 2 | TODO.txt 3 | -------------------------------------------------------------------------------- /_bettyComply: -------------------------------------------------------------------------------- 1 | ./betty-comply.pl -------------------------------------------------------------------------------- /preview.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HazelDaniel/betty-comply/HEAD/preview.gif -------------------------------------------------------------------------------- /preview2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HazelDaniel/betty-comply/HEAD/preview2.gif -------------------------------------------------------------------------------- /update.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ "$(id -u)" != "0" ] 4 | then 5 | echo "Sorry, you are not root." 6 | exit 1 7 | fi 8 | 9 | 10 | echo -e "Running update.." 11 | 12 | ./flush.sh 13 | ./install.sh 14 | -------------------------------------------------------------------------------- /_comply_all.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | 4 | for i in $(ls *.c) 5 | do 6 | if [[ $(cat $i | wc -l) ]] 7 | then 8 | echo "complying to betty ..." 9 | _bettyComply $i 10 | else 11 | echo "empty file : $i skipping..." 12 | fi 13 | done 14 | 15 | if [[ $? -eq 0 ]] 16 | then 17 | echo -e "done. \u2713\n" 18 | fi 19 | -------------------------------------------------------------------------------- /_watch_n_comply.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ARG_COUNT=$#; 4 | 5 | if [[ "$ARG_COUNT" -gt 1 ]] 6 | then 7 | echo "you can only watch a file at a time!" 8 | echo "exiting..." 9 | exit 0 10 | fi 11 | 12 | ### Set initial time of file 13 | LTIME=`stat -c %Y $1` 14 | 15 | while true 16 | do 17 | ATIME=`stat -c %Y $1` 18 | 19 | if [[ "$ATIME" != "$LTIME" ]] 20 | then 21 | _bettyComply $1 22 | LTIME=$ATIME 23 | fi 24 | sleep 2 25 | done 26 | -------------------------------------------------------------------------------- /flush.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ "$(id -u)" != "0" ] 4 | then 5 | echo "Sorry, you are not root." 6 | exit 1 7 | fi 8 | 9 | COMPLY_ALL="_comply_all" 10 | BETTY_COMPLY="betty-comply" 11 | COMPLY_ALL_SYM="_complyAll" 12 | BETTY_COMPLY_SYM="_bettyComply" 13 | 14 | 15 | 16 | APP_PATH="/opt/betty-comply" 17 | BIN_PATH="/usr/local/bin" 18 | MAN_PATH="/usr/local/share/man/man1" 19 | 20 | echo -e "Removing binaries.." 21 | 22 | rm "${APP_PATH}/${COMPLY_ALL}" 23 | rm "${APP_PATH}/${BETTY_COMPLY}" 24 | rm "${BIN_PATH}/${COMPLY_ALL_SYM}" 25 | rm "${BIN_PATH}/${BETTY_COMPLY_SYM}" 26 | 27 | 28 | 29 | echo -e "Deleting man pages.." 30 | 31 | 32 | rm "${MAN_PATH}/betty_comply.1" 33 | 34 | 35 | echo -e "All set." 36 | -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ "$(id -u)" != "0" ] 4 | then 5 | echo "Sorry, you are not root." 6 | exit 1 7 | fi 8 | 9 | COMPLY_ALL="_comply_all" 10 | BETTY_COMPLY="betty-comply" 11 | BETTY_WATCH_COMPLY="_watch_n_comply" 12 | COMPLY_ALL_SYM="_complyAll" 13 | BETTY_COMPLY_SYM="_bettyComply" 14 | BETTY_WATCH_COMPLY_SYM="_watchComply" 15 | 16 | 17 | 18 | APP_PATH="/opt/betty-comply" 19 | BIN_PATH="/usr/local/bin" 20 | MAN_PATH="/usr/local/share/man/man1" 21 | 22 | echo -e "Installing binaries.." 23 | 24 | mkdir -p "${APP_PATH}" 25 | 26 | cp "${COMPLY_ALL}.sh" "${APP_PATH}/${COMPLY_ALL}" 27 | cp "${BETTY_COMPLY}.pl" "${APP_PATH}/${BETTY_COMPLY}" 28 | cp "${BETTY_WATCH_COMPLY}.sh" "${APP_PATH}/${BETTY_WATCH_COMPLY}" 29 | 30 | chmod +x "${APP_PATH}/${COMPLY_ALL}" 31 | chmod +x "${APP_PATH}/${BETTY_COMPLY}" 32 | chmod +x "${APP_PATH}/${BETTY_WATCH_COMPLY}" 33 | 34 | ln -s "${APP_PATH}/${COMPLY_ALL}" "${BIN_PATH}/${COMPLY_ALL_SYM}" 35 | ln -s "${APP_PATH}/${BETTY_COMPLY}" "${BIN_PATH}/${BETTY_COMPLY_SYM}" 36 | ln -s "${APP_PATH}/${BETTY_WATCH_COMPLY}" "${BIN_PATH}/${BETTY_WATCH_COMPLY_SYM}" 37 | 38 | echo -e "Installing man pages.." 39 | 40 | mkdir -p "${MAN_PATH}" 41 | 42 | cp "man/betty_comply.1" "${MAN_PATH}" 43 | 44 | echo -e "Updating man database.." 45 | 46 | mandb 47 | 48 | echo -e "All set." 49 | -------------------------------------------------------------------------------- /man/betty_comply.1: -------------------------------------------------------------------------------- 1 | .B _bettyComply 2 | .LP 3 | .SH NAME 4 | _bettyComply - adjust a file to betty's standards 5 | .br 6 | .LP 7 | .SH SYNOPSIS 8 | _bettyComply [OPTION]... [FILE]... 9 | .br 10 | .LP 11 | 12 | .SH DESCRIPTION 13 | _bettyComply is a restricted C file formatter that formats a file to comply with betty's standards. betty is an alx's C code parser that checks for errors in syntactic structure. This script modifies the input file in place. 14 | .LP 15 | .SH OPTIONS 16 | .TP 17 | .B - .. 18 | Information not available 19 | .TP 20 | .B - .. 21 | Information not available 22 | .LP 23 | 24 | .SH AUTHOR 25 | Hazel Daniel 26 | .br 27 | .SH REPORTING BUGS 28 | Report bugs at https://github.com/HazelDaniel/betty-comply/issues. 29 | .br 30 | .SH CONTRIBUTING 31 | To contribute to the project, visit https://github.com/HazelDaniel/betty-comply. 32 | .br 33 | .SH COPYRIGHT 34 | Copyright (co 2023 Hazel Daniel. 35 | This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. 36 | 37 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 38 | 39 | You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 40 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | | PREVIEW | FEATURES | 2 | | :--: | :--: | 3 | | ![preview](preview2.gif) | | 4 | ### NAME 5 | _bettyComply 6 | 7 | ### DESCRIPTION 8 | format a file to comply to betty ( the alx's C code parser that checks for errors in syntactic structure ) 's standards 9 | 10 | ### SYNOPSIS 11 | - _bettyComply [OPTION]... [FILE]... 12 | - _complyAll 13 | 14 | ##### `NOTE: you must be in the working directory to run _complyAll` 15 | 16 | ### INSTALLATION 17 | - clone the repo 18 | - run the install.sh file as superuser: 19 | #### 20 | git clone https://github.com/HazelDaniel/betty-comply 21 | cd betty-comply 22 | sudo ./install.sh 23 | ### 24 | - all set! 25 | 26 | ### UPDATE 27 | - cd into the betty-comply directory 28 | - pull from the repo 29 | - run the update.sh file as superuser: 30 | #### 31 | git pull origin master 32 | sudo ./update.sh 33 | ### REMOVAL 34 | - cd into the betty-comply directory 35 | - run the flush.sh file as superuser: 36 | #### 37 | sudo ./flush.sh 38 | ### AUTHOR 39 | HAZEL DANIEL. 40 | 41 | Report bugs at https://github.com/HazelDaniel/betty-comply/issues. 42 | For contributions : https://github.com/HazelDaniel/betty-comply 43 | 44 | A restricted C file formatter. 45 | Copyright (C) 2023 Hazel Daniel. 46 | This program is free software; you can redistribute it and/or 47 | modify it under the terms of the GNU General Public License 48 | as published by the Free Software Foundation; either version 2 49 | of the License, or (at your option) any later version. 50 | 51 | This program is distributed in the hope that it will be useful, 52 | but WITHOUT ANY WARRANTY; without even the implied warranty of 53 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 54 | GNU General Public License for more details. 55 | 56 | You should have received a copy of the GNU General Public License 57 | along with this program; if not, write to the Free Software 58 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 59 | 60 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | , 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /betty-comply.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | use Term::ANSIColor qw(:constants); 3 | use open qw/:std :utf8/; 4 | use v5.4; 5 | 6 | =for 7 | ====== WELCOME TO MY LITTLE PROJECT! ====== 8 | DESCRIPTION : BASIC FILE PROCESSING PROGRAM WRITTEN IN PERL. 9 | =cut 10 | 11 | #GLOBALS 12 | $parameters = $#ARGV + 1; 13 | @file_lines = (); 14 | %f_property = ('nu',"numbered-and-upper",'nl',"numbered-and-lower",'n',"numbered",'u',"upper",'l',"lower"); 15 | %f_long_property = ('--stop-at='=>"set-stop",'--offset='=>"set-offset"); 16 | $REMOVAL_PLACEHOLDER = "BC"; 17 | $type_exp = "(?:struct \w+|\w+_t|const|volatile|auto|extern|static|int|uint32_t|uint16_t|uint8_t|float|double|char|short|long long|long double|long|signed|_Bool|bool|enum|unsigned|void|complex|_Complex|size_t|time_t|FILE|fpos_t|va_list|jmp_buf|wchar_t|wint_t|wctype_t|mbstate_t|div_t|ldiv_t|imaxdiv_t|int8_t|int16_t|int32_t|int64_t|int_least8_t|int_least16_t|int_least32_t|int_least64_t|uint_least8_t|uint_least16_t|uint_least32_t|uint_least64_t|int_fast8_t|int_fast16_t|int_fast32_t|int_fast64_t|uint_fast8_t|uint_fast16_t|uint_fast32_t|uint_fast64_t|intptr_t|uintptr_t)"; 18 | #END OF GLOBALS 19 | 20 | #SUB-ROUTINES 21 | sub parse_and_chomp { 22 | my $args = scalar(@_); 23 | if($args != 1){ 24 | print "Wrong argument in subroutine!"; 25 | exit 271; 26 | } 27 | 28 | @vecs = @_; 29 | my $arg1 = $vecs[0]; 30 | my $arg2 = $vecs[1]; 31 | open(MYINPUTFILE, $vecs[0]) or die "can't open: $!"; 32 | while() 33 | { 34 | # Good practice to store $_ value 35 | my($line) = $_; 36 | 37 | chomp($line); 38 | push(@file_lines,$line); 39 | } 40 | 41 | } 42 | 43 | 44 | sub write_parsed_lines { 45 | my ($arg_offset) = @_; 46 | open(FH, '>', $ARGV[$arg_offset]) or die $!; 47 | for my $file (@file_lines) { 48 | if (not grep (/BC/,$file)) { 49 | print FH "$file\n"; 50 | } 51 | #print FH "$file\n" unless $file =~ /^.*BC.*$/; 52 | } 53 | close(FH); 54 | @file_lines = (); 55 | update_file_lines($arg_offset); 56 | } 57 | sub spaces_to_tabs { 58 | my ($arg_offset) = @_; 59 | my $l_count = 0; 60 | for my $file (@file_lines) { 61 | if ($file =~ /^( *)([^ ])(.*$)/mg) { 62 | $file_lines[$l_count] = $2 . $3; 63 | } 64 | $l_count++; 65 | } 66 | write_parsed_lines($arg_offset); 67 | } 68 | sub format_trailing { 69 | my ($arg_offset) = @_; 70 | my $l_count = 0; 71 | for my $f_line (@file_lines) { 72 | if ($f_line =~ /^\s*[[:print:]]+\s*\{\s*$/) { 73 | if($f_line =~ /^\s*(do)\s*(\{\s*)$/mg) { 74 | $f_line = $1 . $2; 75 | $file_lines[$l_count] = $f_line; 76 | } 77 | elsif($f_line =~ /^\s*(\})\s*(else)\s*(if\s*\(\s*[[:print:]]+\s*\))?\s*(\{)\s*$/mg) { 78 | my $new_opening_brace = $1 . "\n"; 79 | my $new_closing_brace = "\n" . $4; 80 | my $f_line = $new_opening_brace . $2 . " " . $3 . " " . $new_closing_brace; 81 | $file_lines[$l_count] = $f_line; 82 | #print "an else if block met \"$f_line\"\n"; 83 | } 84 | elsif($f_line =~ /^(\s*)(while|for)\s*(\([[:print:]]+\))\s*(\{)?\s*$/mg) { 85 | $f_line = $1 . $2 . " " . $3 . "\n$4"; 86 | $file_lines[$l_count] = $f_line; 87 | } 88 | #TODO: ADD SUPPORT FOR FOR LOOPS 89 | elsif(not grep /^\s*(do)\s*\{\s*$/,$f_line) { 90 | $f_line =~ s/{$/\n\{/m; 91 | $file_lines[$l_count] = $f_line; 92 | } 93 | } 94 | $l_count++; 95 | } 96 | write_parsed_lines($arg_offset); 97 | } 98 | 99 | 100 | sub format_file { 101 | my ($arg_offset) = @_; 102 | multi_parse_and_chomp($arg_offset); 103 | spaces_to_tabs($arg_offset); 104 | format_trailing($arg_offset); 105 | adjust_indent($arg_offset); 106 | rm_trailing_wp($arg_offset); 107 | separate_RD_tokens($arg_offset); 108 | #___ last debug end; 109 | remove_blanks($arg_offset); 110 | cast_entry($arg_offset); 111 | no_brace_indent($arg_offset); 112 | format_ctrl_keywords($arg_offset); 113 | wrap_return($arg_offset); 114 | unpad_parentheses($arg_offset); 115 | pad_defs($arg_offset); 116 | rm_wp_btw_fun_n_opn_par($arg_offset); 117 | brace_unbraced_ifelse_if_needed($arg_offset); 118 | fix_separated_tokens($arg_offset); 119 | document_function($arg_offset); 120 | 121 | } 122 | 123 | sub adjust_indent { 124 | my ($arg_offset) = @_; 125 | my $ind_level = 0; 126 | my $ind_char = "\t"; 127 | my $seen_entry = 0; 128 | my $lines_length = $#file_lines + 1; 129 | 130 | for (my $i = 0; $i < $lines_length; $i++) { 131 | my $f_line = $file_lines[$i]; 132 | 133 | if(grep(/^([[:alpha:]]+ main[^{]*$)/,$f_line)) { 134 | #print "seen entry\n"; 135 | $seen_entry = 1; 136 | } 137 | if(grep (/^(?:\s*(?:(?!\()(?:const|struct \w+|volatile|auto|extern|static|int|uint32_t|uint16_t|uint8_t|float|double|char|short|long long|long double|long|signed|_Bool|bool|enum|unsigned|void|complex|_Complex|size_t|time_t|FILE|fpos_t|va_list|jmp_buf|wchar_t|wint_t|wctype_t|mbstate_t|div_t|ldiv_t|imaxdiv_t|int8_t|int16_t|int32_t|int64_t|int_least8_t|int_least16_t|int_least32_t|int_least64_t|uint_least8_t|uint_least16_t|uint_least32_t|uint_least64_t|int_fast8_t|int_fast16_t|int_fast32_t|int_fast64_t|uint_fast8_t|uint_fast16_t|uint_fast32_t|uint_fast64_t|intptr_t|uintptr_t)\s*(?!\)))+ *((\* ?)*)[[:word:]]+\s*\([[:print:]]+\))\s*$/,$f_line)) { 138 | #print "seen function entry \n"; 139 | $seen_entry = 1; 140 | } 141 | if ($seen_entry == 1) { 142 | my $opening_brace; 143 | if ($f_line =~ /(^[[:blank:]]*(?={))({)[[:blank:]]*$/mg) { 144 | $opening_brace = $2; 145 | $file_lines[$i] = ($ind_char x $ind_level) . $opening_brace; 146 | $ind_level++; 147 | #print "indentation level: $ind_level:$f_line\n"; 148 | } 149 | elsif($f_line =~ /^\s*(do)\s*(\{)\s*$/mg) { 150 | my $statement = $1 . " " . $2; 151 | $file_lines[$i] = ($ind_char x $ind_level) . $statement; 152 | $ind_level++; 153 | #print "found a do while \n"; 154 | #print "statement: $statement\n"; 155 | #print "indentation level: $ind_level:$f_line\n"; 156 | } 157 | elsif($f_line =~ /\s*(\})\s*(while)\s*(\()\s?([[:graph:]]+)\s?(\);)$/mg) { 158 | my $statement = $1 . " " . $2 . " " . $3 . $4 . $5; 159 | $ind_level = $ind_level - 1 >= 0 ? $ind_level - 1 : 0; 160 | $file_lines[$i] = ($ind_char x $ind_level) . $statement; 161 | #print "indentation level: $ind_level:$f_line\n"; 162 | } 163 | elsif($f_line =~ /^\s*(else)\s*$/mg) { 164 | my $statement = $1 . " " . $2 . " " . $3; 165 | #$adjust_ind_level = $ind_level - 1 >= 0 ? $ind_level - 1 : 0; 166 | $file_lines[$i] = ($ind_char x $ind_level) . $statement; 167 | #print "indentation level: $ind_level:$f_line\n"; 168 | #print "else block seen \n"; 169 | } 170 | elsif($f_line !~ /(^[[:blank:]]*(?={))({)[[:blank:]]*$/mg and $f_line !~ /(^[[:blank:]]*(?=}))(})[[:blank:]]*$/mg) { 171 | if($f_line =~ /^[[:blank:]]*([[:print:]]+(;|\)|:))/mg) { 172 | my $statement = $1; 173 | if (grep(/^\s*(?:(?:case [[:print:]]+|default\s*|goto\s*|error\s*|end\s*):)\s*$/,$f_line)) { 174 | # print "a case or default statement found.\n"; 175 | $file_lines[$i] = ($ind_char x ($ind_level - 1)) . $statement; 176 | } 177 | else{ 178 | $file_lines[$i] = ($ind_char x $ind_level) . $statement; 179 | } 180 | #print "statement: $statement\n"; 181 | #print "indentation level: $ind_level:$f_line\n"; 182 | } 183 | } 184 | elsif($f_line !~ /(^[[:blank:]]*(?=}))(})[[:blank:]]*$/mg) { 185 | my $closing_brace = $2; 186 | $ind_level = $ind_level - 1 >= 0 ? $ind_level - 1 : 0; 187 | $file_lines[$i] = ($ind_char x $ind_level) . $closing_brace; 188 | #print "indentation level: $ind_level:$f_line\n"; 189 | } 190 | } 191 | 192 | } 193 | write_parsed_lines($arg_offset); 194 | } 195 | 196 | sub no_brace_indent { 197 | #TODO: SUPPORT NO-BRACE WHILE LOOPS 198 | my ($arg_offset) = @_; 199 | my $ind_level = 0; 200 | my $ind_char = "\t"; 201 | my $seen_entry = 0; 202 | my $l_count = 0; 203 | my $p_line = $l_count - 1 >= 0 ? $file_lines[$l_count - 1] : $file_lines[0]; 204 | for my $f_line (@file_lines) { 205 | if ($f_line =~ /^(\s*)((?:else)?\s?if\s*\(.+\))\s*$/mg) { 206 | $ind_level = 0; 207 | my $existing_indent = $1; 208 | if ($file_lines[$l_count + 1] !~ /^\s*{\s*$/) { 209 | $file_lines[$l_count] = $existing_indent . $2; 210 | #print "indentation level: $ind_level:$f_line\n"; 211 | $ind_level++; 212 | #print "no brace indent on $f_line\n"; 213 | } 214 | } 215 | elsif ($f_line =~ /^(\s*)(else)\s*$/mg) { 216 | $ind_level = 0; 217 | my $existing_indent = $1; 218 | my $statement = $2; 219 | if ($file_lines[$l_count + 1] !~ /^\s*{\s*$/) { 220 | $file_lines[$l_count] = $existing_indent . $statement; 221 | #print "indentation level: $ind_level:$f_line\n"; 222 | $ind_level++; 223 | #print "no brace indent on $f_line\n"; 224 | } 225 | } 226 | elsif($file_lines[$l_count - 1] =~ /(?:^((\s*)(?:else)?\s?if\s*\(.+\))\s*$)/mg) { 227 | #print "existing indent of parent $2.\n"; 228 | my $existing_indent = $2; 229 | if ($f_line =~ /^[[:blank:]]*([[:print:]]+(;|\)|:))/mg) { 230 | my $statement = $1; 231 | $file_lines[$l_count] = $existing_indent . ($ind_char x $ind_level) . $statement; 232 | #print "statement: $statement\n"; 233 | #print "indentation level: $ind_level:$f_line\n"; 234 | } 235 | } 236 | elsif ($file_lines[$l_count - 1] =~ /^(\s*)else\s*$/mg) { 237 | #print "existing indent of parent $2.\n"; 238 | my $existing_indent = $1; 239 | if ($f_line =~ /^[[:blank:]]*([[:print:]]+(;|\)|:))/mg) { 240 | my $statement = $1; 241 | $file_lines[$l_count] = $existing_indent . ($ind_char x $ind_level) . $statement; 242 | #print "statement: $statement\n"; 243 | #print "indentation level: $ind_level:$f_line\n"; 244 | } 245 | } 246 | $l_count++; 247 | } 248 | 249 | write_parsed_lines($arg_offset); 250 | } 251 | 252 | sub rm_trailing_wp { 253 | my ($arg_offset) = @_; 254 | my $l_count = 0; 255 | for my $f_line (@file_lines) { 256 | if ($f_line =~ /^(.*)(?=|<|(?|=)[[:graph:]]/g and not (grep(/^#.*/,$f_line))) { 295 | if ($f_line !~ /"[^"]+"/g) { 296 | while ($f_line =~ /(?<=[[:graph:]])((?:==|\/|!=|<=|>=|<|(?|=))(?=[[:graph:]])/mg) { 297 | my $start = $`; 298 | my $end = $'; 299 | my $token = $1; 300 | if ($` =~ /^[^"]*"[^"]*"[^"]*/ or $' =~ /[^"]*"[^"]*"[^"]*$/ or (not grep(/"/,$f_line))) { 301 | $f_line = $start . " " . $token . " " . $end; 302 | $file_lines[$l_count] = $f_line; 303 | } 304 | } 305 | } 306 | } 307 | if (grep(/[^ ](?:\&\&|\|\|)[^ ]/,$f_line)){ 308 | $f_line =~ s/([^ ])(\&\&|\|\|)([^ ])/$1 $2 $3/g; 309 | $file_lines[$l_count] = $f_line; 310 | } 311 | if ($f_line =~ /(?<=[[:graph:]])\s*,\s*(?=[[:graph:]])/m) { 312 | if ($f_line =~ /^(\s*\w+\(".*")\s*(,\s*.*\))(;)$/) { 313 | my $_left = $1; 314 | my $_right = $2; 315 | my $_rem = $3; 316 | $_right = replace_tokens($_right); 317 | $file_lines[$l_count] = "$_left$_right$_rem"; 318 | } 319 | elsif ($f_line =~ qr/(^(?:\s*$type_exp)+)\s*(.*)(;)$/) { # NEXT CASEs: variable declaration and assignment 320 | my $_right = $'; 321 | my $_word = $1; 322 | my $_rem = $3; 323 | my $match = $2; 324 | if (not grep(/"/,$f_line)) #TODO: support seperating commas in char(*) declarations 325 | { 326 | $match = replace_tokens($match); 327 | $file_lines[$l_count] = "$_word " . "$match" . $_rem . "$_right\n"; 328 | } 329 | } 330 | elsif ($f_line =~ /(\w+)(\s*)\(([^"].*[^"])\)(;|)\s*$/) { 331 | my $_left = $`; 332 | my $_right = $'; 333 | my $_word = $1; 334 | my $_rem = $4; 335 | my $match = $3; 336 | my $_space = $2; 337 | # print "$match\n"; 338 | $match = replace_tokens($match); 339 | $file_lines[$l_count] = "$_left" . "$_word" . $_space . "($match)" . $_rem . "$_right\n"; 340 | } 341 | elsif ($f_line =~ /(.*=.*=.*;)/) { 342 | my $_left = $`; 343 | my $_word = $1; 344 | if (not grep(/"/,$f_line)) #TODO: support seperating commas in char(*) declarations 345 | { 346 | $_word = replace_tokens($_word); 347 | $file_lines[$l_count] = "$_left" . "$_word\n"; 348 | } 349 | } 350 | } 351 | $l_count++; 352 | } 353 | write_parsed_lines($arg_offset); 354 | } 355 | 356 | sub format_ctrl_keywords { 357 | my ($arg_offset) = @_; 358 | my $l_count = 0; 359 | 360 | for my $f_line (@file_lines) { 361 | if ($f_line =~ /^(\s*)((?:else)?\s*if|for|while|switch)(\(.*\))\s*$/mg) { 362 | #print "an unseparated control keyword spotted.\n"; 363 | $f_line = $1 . $2 . " " . $3; 364 | $file_lines[$l_count] = $f_line; 365 | } 366 | $l_count++; 367 | } 368 | 369 | write_parsed_lines($arg_offset); 370 | } 371 | 372 | sub cast_entry { 373 | my ($arg_offset) = @_; 374 | my $l_count = 0; 375 | 376 | for my $f_line (@file_lines) { 377 | if ($f_line =~ /^(void|int)\s*(main)\s*\(\s*\)\s*$/){ 378 | # print "an uncasted entry point spotted.\n"; 379 | $f_line = $1 . " " . $2 . "(void)"; 380 | $file_lines[$l_count] = $f_line; 381 | } 382 | $l_count++; 383 | } 384 | 385 | write_parsed_lines($arg_offset); 386 | } 387 | 388 | sub wrap_return { 389 | my ($arg_offset) = @_; 390 | my $l_count = 0; 391 | 392 | for my $f_line (@file_lines) { 393 | if ($f_line =~ /^(\s*)(return)\s*(?!\()(?<= )(?! )(.+);$/mg) { 394 | $f_line = $1 . $2 . " " . "(" . $3 . ")" . ";"; 395 | $file_lines[$l_count] = $f_line; 396 | #print "an unwrapped return value spotted. $f_line\n"; 397 | } 398 | $l_count++; 399 | } 400 | 401 | write_parsed_lines($arg_offset); 402 | } 403 | 404 | sub unpad_parentheses { 405 | my ($arg_offset) = @_; 406 | my $l_count = 0; 407 | 408 | for my $f_line (@file_lines) { 409 | if ($f_line =~ /(\()\s+([[:print:]]+)(\))/mg) { 410 | $f_line = $` . $1 . $2 . $3 . $'; 411 | $file_lines[$l_count] = $f_line; 412 | #print "a padded left parentheses spotted. $f_line\n"; 413 | } 414 | if ($f_line =~ /(\()([[:print:]]+)\s+(\))/mg) { 415 | $f_line = $` . $1 . $2 . $3 . $'; 416 | $file_lines[$l_count] = $f_line; 417 | #print "a padded right parentheses spotted. $f_line\n"; 418 | } 419 | $l_count++; 420 | } 421 | 422 | write_parsed_lines($arg_offset); 423 | 424 | } 425 | 426 | sub pad_defs { 427 | my ($arg_offset) = @_; 428 | my $l_count = 0; 429 | 430 | for my $f_line (@file_lines) { 431 | if ($f_line =~ /^\s*(\s+(?:(?!\()(?:int|struct \w+|\w+_t|uint32_t|uint16_t|uint8_t|float|double|char|short|long long|long double|long|signed|_Bool|bool|enum|unsigned|void|complex|_Complex|size_t|time_t|FILE|fpos_t|va_list|jmp_buf|wchar_t|wint_t|wctype_t|mbstate_t|div_t|ldiv_t|imaxdiv_t|int8_t|int16_t|int32_t|int64_t|int_least8_t|int_least16_t|int_least32_t|int_least64_t|uint_least8_t|uint_least16_t|uint_least32_t|uint_least64_t|int_fast8_t|int_fast16_t|int_fast32_t|int_fast64_t|uint_fast8_t|uint_fast16_t|uint_fast32_t|uint_fast64_t|intptr_t|uintptr_t)\s*(?!\)))+[[:print:]]*;$)/mg) { 432 | if(not (grep (/(?:\s+(?:(?!\()(?:int|struct \w+|\w+_t|uint32_t|uint16_t|uint8_t|float|double|char|short|long long|long double|long|signed|_Bool|bool|enum|unsigned|void|complex|_Complex|size_t|time_t|FILE|fpos_t|va_list|jmp_buf|wchar_t|wint_t|wctype_t|mbstate_t|div_t|ldiv_t|imaxdiv_t|int8_t|int16_t|int32_t|int64_t|int_least8_t|int_least16_t|int_least32_t|int_least64_t|uint_least8_t|uint_least16_t|uint_least32_t|uint_least64_t|int_fast8_t|int_fast16_t|int_fast32_t|int_fast64_t|uint_fast8_t|uint_fast16_t|uint_fast32_t|uint_fast64_t|intptr_t|uintptr_t)\s*(?!\)))+[[:print:]]*;$)/,$file_lines[$l_count + 1]) or grep(/^\s*$/,$file_lines[$l_count + 1]))) { 433 | $f_line = $` . $1 . "\n"; 434 | $file_lines[$l_count] = $f_line; 435 | # print "an unpadded definition. $f_line\n"; 436 | } 437 | } 438 | $l_count++; 439 | } 440 | 441 | write_parsed_lines($arg_offset); 442 | } 443 | 444 | sub rm_wp_btw_fun_n_opn_par { 445 | my ($arg_offset) = @_; 446 | my $l_count = 0; 447 | 448 | for my $f_line (@file_lines) { 449 | if ($f_line =~ qr/^\s*((?:(?!\()$type_exp\s*(?!\)))+ [[:word:]]+)\s+(\([[:print:]]+\)(;|))\s*$/) { 450 | #print "$f_line\n"; 451 | $f_line = $1 . $2; 452 | $file_lines[$l_count] = $f_line; 453 | # print "an tokens here are .$1\n$2 \n and \n$3\n"; 454 | # TODO: add support for function calls as well 455 | } 456 | $l_count++; 457 | } 458 | 459 | write_parsed_lines($arg_offset); 460 | } 461 | 462 | sub brace_unbraced_ifelse_if_needed { 463 | my ($arg_offset) = @_; 464 | my $l_count = 0; 465 | my %if_pts = ( 466 | ); 467 | 468 | for my $f_line (@file_lines) { 469 | if ($f_line =~ /^(\s+)if\s+\([[:print:]]+\)\s*$/m) { 470 | # print "if line: \t $f_line \n"; 471 | my $indent_level = length($1); 472 | $if_pts{"$l_count"} = [$indent_level,$f_line]; 473 | } 474 | $l_count++; 475 | } 476 | 477 | foreach $key (keys %if_pts) { 478 | # print "line: $key \n statements:\n"; 479 | my @val = @{$if_pts{$key}}; 480 | my ($indent_level,$line) = @val; 481 | my @branch_pts = (); 482 | my $seen_wrapped = 0; 483 | my @wrapped_branch_pts = (); 484 | my @unwrapped_branch_pts = (); 485 | my $ind_char = "\t" x $indent_level; 486 | my $b_count = $key; 487 | 488 | push(@branch_pts,$b_count); 489 | #print "b count : $b_count \t file lines : $#file_lines\n"; 490 | 491 | for (; $b_count <= $#file_lines; $b_count++) { 492 | # print "going through the file lines\n"; 493 | if ($file_lines[$b_count] =~ /^(\s+)((?:else\s)?if \([[:print:]]+\)|else)\s*$/m) { 494 | $b_ind_level = length($1); 495 | # print "branch indent level : $b_ind_level\t statement: $file_lines[$b_count]\n"; 496 | if ($b_ind_level >= $indent_level and not ($b_ind_level == $indent_level && grep(/^\s+((?:for|if|while|switch)\s+\([[:print:]]+\)|do\s*{)\s*$/,$file_lines[$b_count]))) { 497 | if(grep(/^\s+(else(?:\s+if\s+\([[:print:]]+\))?)\s*$/),$file_lines[$b_count] and $b_ind_level == $indent_level) { 498 | # print "branch found: $file_lines[$b_count]\t indent level: $b_ind_level\n"; 499 | push(@branch_pts,$b_count); 500 | } 501 | } 502 | else { 503 | # last; 504 | } 505 | } 506 | } 507 | 508 | 509 | for my $b_point (@branch_pts) { 510 | if(grep(/^\s+\{\s*$/,$file_lines[$b_point + 1])) { 511 | #print "a wrapped branch found next to : $file_lines[$b_point] \t and it's $file_lines[$b_point + 1]\n"; 512 | $seen_wrapped = 1; 513 | last; 514 | } 515 | } 516 | 517 | if ($seen_wrapped == 1) { 518 | for my $b_point (@branch_pts) { 519 | #print "branch points: \n\t $file_lines[$b_point]\n"; 520 | if(grep(/^\s+\{\s*$/,$file_lines[$b_point + 1])) { 521 | push(@wrapped_branch_pts,$b_point); 522 | } 523 | } 524 | } 525 | 526 | for my $b_point (@branch_pts) { 527 | if(not grep(/^$b_point$/,@wrapped_branch_pts)) { 528 | # print "unwrapped $file_lines[$b_point]\n"; 529 | push(@unwrapped_branch_pts,$b_point); 530 | } 531 | } 532 | 533 | for my $ub_point (@unwrapped_branch_pts) { 534 | my $wrapped = $file_lines[$ub_point] . "\n" . $ind_char . "{" . "\n" . $file_lines[$ub_point + 1] . "\n" . $ind_char . "}"; 535 | $file_lines[$ub_point] = $wrapped; 536 | $file_lines[$ub_point + 1] = "$REMOVAL_PLACEHOLDER"; 537 | # print "unwrapped: $file_lines[$ub_point]\n"; 538 | } 539 | 540 | for my $wb_point (@wrapped_branch_pts) { 541 | # print "wrapped: $file_lines[$wb_point]\n"; 542 | } 543 | 544 | } 545 | 546 | write_parsed_lines($arg_offset); 547 | 548 | } 549 | 550 | sub fix_separated_tokens { 551 | my ($arg_offset) = @_; 552 | my $l_count = 0; 553 | my $seen_entry = 0; 554 | for my $f_line (@file_lines) { 555 | if(grep(/^([[:alpha:]]+ main[^{]*$)/,$f_line)) { 556 | $seen_entry = 1; 557 | } 558 | if(grep (/^(?:\s*(?:(?!\()(?:volatile|static|extern|struct \w+|const|int|uint32_t|uint16_t|uint8_t|float|double|char|short|long long|long double|long|signed|_Bool|bool|enum|unsigned|void|complex|_Complex|size_t|time_t|FILE|fpos_t|va_list|jmp_buf|wchar_t|wint_t|wctype_t|mbstate_t|div_t|ldiv_t|imaxdiv_t|int8_t|int16_t|int32_t|int64_t|int_least8_t|int_least16_t|int_least32_t|int_least64_t|uint_least8_t|uint_least16_t|uint_least32_t|uint_least64_t|int_fast8_t|int_fast16_t|int_fast32_t|int_fast64_t|uint_fast8_t|uint_fast16_t|uint_fast32_t|uint_fast64_t|intptr_t|uintptr_t)\s*((?:\* ?)*)\s*(?!\)))+ [[:word:]]+\s*\([[:print:]]+\))\s*$/,$f_line)) { 559 | $seen_entry = 1; 560 | } 561 | if ($f_line =~ qr/(?<=\s)($type_exp )\s*((?:\* ?)*)\s*(\w+)/) { 562 | $f_line = $` . $1 . $2 . $3 . $'; 563 | $file_lines[$l_count] = $f_line; 564 | } 565 | if ($seen_entry == 1) { 566 | if ($f_line =~ /(\w+)\s+(\[[[:print:]]+\])/) { 567 | # print "an open square brace here: \t $f_line \n"; 568 | $f_line = $` . $1 . $2 . $'; 569 | $file_lines[$l_count] = $f_line; 570 | } 571 | if ($f_line =~ /(\w+)\s+((?:\* ?)*)\s+(\w+)/mg) { 572 | if ($f_line !~ /"[^"]+"/g and $1 !~ qr/$type_exp/) { 573 | $f_line = $` . $1 . " " . $2 . " " . $3 . $'; 574 | $file_lines[$l_count] = $f_line; 575 | } 576 | } 577 | if ($f_line =~ /(\w+)\s*(-)(?