Created
February 8, 2012 01:51
-
-
Save paxswill/1764231 to your computer and use it in GitHub Desktop.
xdbglint reformats Apple's gdb output for CoreFoundation collections so that it is indented properly
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <stdbool.h> | |
| #include <string.h> | |
| #include <limits.h> | |
| int countBraces(char *str); | |
| int main (int argc, char const *argv[]) | |
| { | |
| // There are two modes available, file or stdio | |
| // For file mode, arg[1] is the input filename, arg[2] is the output filename | |
| bool using_stdio; | |
| if(argc == 3){ | |
| using_stdio = false; | |
| }else if(argc == 1){ | |
| using_stdio = true; | |
| }else{ | |
| // Invalid input | |
| return 1; | |
| } | |
| FILE *input; | |
| FILE *output; | |
| if(using_stdio){ | |
| input = stdin; | |
| output = stdout; | |
| }else{ | |
| input = fopen(argv[1], "r"); | |
| output = fopen(argv[2], "w"); | |
| } | |
| // Now to go over line by line | |
| char *strBuffer = malloc(sizeof(char) * (LINE_MAX + 1)); | |
| int tabLevel = 0; | |
| while(fgets(strBuffer, LINE_MAX + 1, input) != NULL){ | |
| for(int i = 0; i < tabLevel; ++i){ | |
| fputc('\t', output); | |
| } | |
| fputs(strBuffer, output); | |
| tabLevel += countBraces(strBuffer); | |
| } | |
| // Clean up | |
| free(strBuffer); | |
| if(!using_stdio){ | |
| fclose(output); | |
| fclose(input); | |
| } | |
| return 0; | |
| } | |
| int countBraces(char *str){ | |
| int i = 0; | |
| char currChar = str[i]; | |
| int count = 0; | |
| while(currChar != '\0'){ | |
| if(currChar == '{'){ | |
| ++count; | |
| }else if(currChar == '}'){ | |
| --count; | |
| } | |
| currChar = str[++i]; | |
| } | |
| return count; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment