diff options
author | Eli Bendersky <eliben@gmail.com> | 2015-04-20 07:19:09 -0700 |
---|---|---|
committer | Eli Bendersky <eliben@gmail.com> | 2015-04-20 07:19:09 -0700 |
commit | 43375bf83890a77b31f3971329de25fc0764a276 (patch) | |
tree | b6b4bf058352bb761d2b9c8bbebda5c0a65b8283 /utils | |
parent | fe5a248c301abacce186f5cf726e2186007451cf (diff) | |
download | pycparser-43375bf83890a77b31f3971329de25fc0764a276.tar.gz |
Clean up line endings in all internal utils
Diffstat (limited to 'utils')
-rw-r--r-- | utils/internal/cppify.bat | 6 | ||||
-rw-r--r-- | utils/internal/example_c_file.c | 50 | ||||
-rw-r--r-- | utils/internal/fake_includes.py | 26 | ||||
-rw-r--r-- | utils/internal/make_fake_typedefs.py | 36 | ||||
-rw-r--r-- | utils/internal/zc.c | 214 | ||||
-rw-r--r-- | utils/internal/zz_parse.py | 6 |
6 files changed, 171 insertions, 167 deletions
diff --git a/utils/internal/cppify.bat b/utils/internal/cppify.bat index fb16db5..af69f5f 100644 --- a/utils/internal/cppify.bat +++ b/utils/internal/cppify.bat @@ -1,3 +1,3 @@ -REM ~ ..\cpp -D__i386__ -I"D:\eli\cpp_stuff\libc_include" -D__extension__ example_c_file.c > example_c_file_pp.c
-REM ~ ..\cpp -D__i386__ -I"D:\eli\c_analyzing\pycparser-trunk\utils\fake_libc_include" example_c_file.c > example_c_file_pp.c
-..\cpp -D__i386__ -I"D:\eli\c_analyzing\pycparser-trunk\utils\fake_libc_include" zc.c > zc_pp.c
+REM ~ ..\cpp -D__i386__ -I"D:\eli\cpp_stuff\libc_include" -D__extension__ example_c_file.c > example_c_file_pp.c +REM ~ ..\cpp -D__i386__ -I"D:\eli\c_analyzing\pycparser-trunk\utils\fake_libc_include" example_c_file.c > example_c_file_pp.c +..\cpp -D__i386__ -I"D:\eli\c_analyzing\pycparser-trunk\utils\fake_libc_include" zc.c > zc_pp.c diff --git a/utils/internal/example_c_file.c b/utils/internal/example_c_file.c index 44564ac..35da01d 100644 --- a/utils/internal/example_c_file.c +++ b/utils/internal/example_c_file.c @@ -1,25 +1,25 @@ -/* a comment / */
-/* "not a string" */
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-#include <ctype.h>
-#include <signal.h>
-#include <time.h>
-#include <wchar.h>
-
-/*
- multiline comment
- comment
-*/
-
-int main()
-{
- auto char* multi = "a multi"; /* and a comment !*/
-}
-
-/* A final comment for good measure /* /* /* */
-
-
-
+/* a comment / */ +/* "not a string" */ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <assert.h> +#include <ctype.h> +#include <signal.h> +#include <time.h> +#include <wchar.h> + +/* + multiline comment + comment +*/ + +int main() +{ + auto char* multi = "a multi"; /* and a comment !*/ +} + +/* A final comment for good measure /* /* /* */ + + + diff --git a/utils/internal/fake_includes.py b/utils/internal/fake_includes.py index b55f767..1ce69fa 100644 --- a/utils/internal/fake_includes.py +++ b/utils/internal/fake_includes.py @@ -1,13 +1,13 @@ -import os.path
-
-for cur_path, dirs, files in os.walk('.'):
- if cur_path == '.':
- for f in files:
- if f.endswith('.h'):
- print f
- fo = open(f, 'w')
- fo.write('#include "_fake_defines.h"\n')
- fo.write('#include "_fake_typedefs.h"\n')
- fo.close()
-
-
+import os.path + +for cur_path, dirs, files in os.walk('.'): + if cur_path == '.': + for f in files: + if f.endswith('.h'): + print f + fo = open(f, 'w') + fo.write('#include "_fake_defines.h"\n') + fo.write('#include "_fake_typedefs.h"\n') + fo.close() + + diff --git a/utils/internal/make_fake_typedefs.py b/utils/internal/make_fake_typedefs.py index 68f57b3..b82e92f 100644 --- a/utils/internal/make_fake_typedefs.py +++ b/utils/internal/make_fake_typedefs.py @@ -1,21 +1,21 @@ -import sys
-sys.path.insert(0, '../..')
-
-from pycparser import c_parser, c_ast, parse_file
-
-
+import sys +sys.path.insert(0, '../..') + +from pycparser import c_parser, c_ast, parse_file + + class MyVisitor(c_ast.NodeVisitor): def visit_Typedef(self, node): - print 'typedef int %s;' % node.name
-
-
-
+ print 'typedef int %s;' % node.name + + + def generate_fake_typedefs(filename): - ast = parse_file(filename, use_cpp=True, cpp_path="../cpp.exe")
- v = MyVisitor()
- v.visit(ast)
-
-
-if __name__ == "__main__":
- generate_fake_typedefs('example_c_file_pp.c')
-
+ ast = parse_file(filename, use_cpp=True, cpp_path="../cpp.exe") + v = MyVisitor() + v.visit(ast) + + +if __name__ == "__main__": + generate_fake_typedefs('example_c_file_pp.c') + diff --git a/utils/internal/zc.c b/utils/internal/zc.c index eff94bd..5e56974 100644 --- a/utils/internal/zc.c +++ b/utils/internal/zc.c @@ -1,107 +1,107 @@ -#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <getopt.h>
-
-#define PACKAGE "wgram"
-#define VERSION "0.0.4"
-#define MAXLINE 1024
-#define MAXGRAM 32
-
-/* status epilepticus .. print help */
-void print_help(int exval);
-
-int main (int argc, char *argv[]) {
- /* word delimeter for strtok() */
- char delim[] = ".,:;`/\"+-_(){}[]<>*&^%$#@!?~/|\\=1234567890 \t\n";
- char line[MAXLINE]; /* input buff, fgets() */
- char *stray = NULL; /* returned value by strtok() */
- char **strarray = NULL; /* array to hold all entrys */
- int i = 0; /* general counter */
- int strcount = 0; /* number of entrys in pointer array */
- int N = 3, pos = 0; /* ngram size, 3 in this case */
- int opt = 0; /* holds command line opt nr.. */
- int word_flag = 0; /* print only the `raw' words */
- FILE *fp = stdin; /* read input from `FILE', default is stdin */
-
- while((opt = getopt(argc, argv, "hvn:wf:")) != -1) {
- switch(opt) {
- case 'h':
- print_help(0);
- break;
- case 'v':
- exit(0);
- break;
- case 'n':
- N = atoi(optarg);
- if(N > MAXGRAM || N < 2) {
- fprintf(stderr, "%s: Error - Ngram length `%d' out of range `0-%d'\n",
- PACKAGE, N, MAXGRAM);
- return 1;
- }
- break;
- case 'w':
- word_flag = 1;
- break;
- case 'f':
- if(freopen(optarg, "r", fp) == NULL) {
- fprintf(stderr, "%s: Error - opening `%s'\n", PACKAGE, optarg);
- return 1;
- }
- break;
- case '?':
- fprintf(stderr, "%s: Error - No such option: `%c'\n\n", PACKAGE, optopt);
- print_help(1);
- } /* switch */
- } /* while */
-
- /* start reading lines from file pointer, add all entrys to **strarray */
- while((fgets(line, MAXLINE, fp)) != NULL) {
- if(strlen(line) < 2)
- continue;
-
- stray = strtok(line, delim);
- while(stray != NULL) {
- strarray = (char **)realloc(strarray, (strcount + 1) * sizeof(char *));
- strarray[strcount++] = strdup(stray);
- stray = strtok(NULL, delim);
- }
- }
-
- if(word_flag == 0) {
- /*
- // print the array of strings, jumping back each time
- // (N - 1) positions if a whole ngram of words has been printed
- */
- for(i = 0, pos = N; i < strcount; i++, pos--) {
- if(pos == 0) pos = N, i -= (N - 1), printf("\n");
- printf("%s ", strarray[i]);
- }
- printf("\n");
- } else {
- /* print raw words */
- for(i = 0; i < strcount; i++)
- printf("%s\n", strarray[i]);
- }
-
- /* free the string array */
- for(i = 0; i < strcount; i++)
- free(strarray[i]);
-
- free(strarray);
- return 0;
-}
-
-/* status epilepticus .. print help */
-void print_help(int exval) {
- printf("%s,%s extract N-grams from text data\n", PACKAGE, VERSION);
- printf("Usage: %s [-h] [-v] [-n INT] [-w] [-f FILE]\n\n", PACKAGE);
-
- printf(" -h print this help and exit\n");
- printf(" -v print version and exit\n\n");
-
- printf(" -n INT set ngram length (default=3)\n");
- printf(" -w print only the extracted words\n");
- printf(" -f FILE read input from `FILE' (default=stdin)\n\n");
- exit(exval);
-}
+#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <getopt.h> + +#define PACKAGE "wgram" +#define VERSION "0.0.4" +#define MAXLINE 1024 +#define MAXGRAM 32 + +/* status epilepticus .. print help */ +void print_help(int exval); + +int main (int argc, char *argv[]) { + /* word delimeter for strtok() */ + char delim[] = ".,:;`/\"+-_(){}[]<>*&^%$#@!?~/|\\=1234567890 \t\n"; + char line[MAXLINE]; /* input buff, fgets() */ + char *stray = NULL; /* returned value by strtok() */ + char **strarray = NULL; /* array to hold all entrys */ + int i = 0; /* general counter */ + int strcount = 0; /* number of entrys in pointer array */ + int N = 3, pos = 0; /* ngram size, 3 in this case */ + int opt = 0; /* holds command line opt nr.. */ + int word_flag = 0; /* print only the `raw' words */ + FILE *fp = stdin; /* read input from `FILE', default is stdin */ + + while((opt = getopt(argc, argv, "hvn:wf:")) != -1) { + switch(opt) { + case 'h': + print_help(0); + break; + case 'v': + exit(0); + break; + case 'n': + N = atoi(optarg); + if(N > MAXGRAM || N < 2) { + fprintf(stderr, "%s: Error - Ngram length `%d' out of range `0-%d'\n", + PACKAGE, N, MAXGRAM); + return 1; + } + break; + case 'w': + word_flag = 1; + break; + case 'f': + if(freopen(optarg, "r", fp) == NULL) { + fprintf(stderr, "%s: Error - opening `%s'\n", PACKAGE, optarg); + return 1; + } + break; + case '?': + fprintf(stderr, "%s: Error - No such option: `%c'\n\n", PACKAGE, optopt); + print_help(1); + } /* switch */ + } /* while */ + + /* start reading lines from file pointer, add all entrys to **strarray */ + while((fgets(line, MAXLINE, fp)) != NULL) { + if(strlen(line) < 2) + continue; + + stray = strtok(line, delim); + while(stray != NULL) { + strarray = (char **)realloc(strarray, (strcount + 1) * sizeof(char *)); + strarray[strcount++] = strdup(stray); + stray = strtok(NULL, delim); + } + } + + if(word_flag == 0) { + /* + // print the array of strings, jumping back each time + // (N - 1) positions if a whole ngram of words has been printed + */ + for(i = 0, pos = N; i < strcount; i++, pos--) { + if(pos == 0) pos = N, i -= (N - 1), printf("\n"); + printf("%s ", strarray[i]); + } + printf("\n"); + } else { + /* print raw words */ + for(i = 0; i < strcount; i++) + printf("%s\n", strarray[i]); + } + + /* free the string array */ + for(i = 0; i < strcount; i++) + free(strarray[i]); + + free(strarray); + return 0; +} + +/* status epilepticus .. print help */ +void print_help(int exval) { + printf("%s,%s extract N-grams from text data\n", PACKAGE, VERSION); + printf("Usage: %s [-h] [-v] [-n INT] [-w] [-f FILE]\n\n", PACKAGE); + + printf(" -h print this help and exit\n"); + printf(" -v print version and exit\n\n"); + + printf(" -n INT set ngram length (default=3)\n"); + printf(" -w print only the extracted words\n"); + printf(" -f FILE read input from `FILE' (default=stdin)\n\n"); + exit(exval); +} diff --git a/utils/internal/zz_parse.py b/utils/internal/zz_parse.py index 0ab6063..0a62040 100644 --- a/utils/internal/zz_parse.py +++ b/utils/internal/zz_parse.py @@ -8,10 +8,14 @@ if __name__ == "__main__": #ast = parse_file('zc_pp.c', use_cpp=True, cpp_path="../cpp.exe") parser = c_parser.CParser() - code = r'''int ar[30];''' + #code = r'''int ar[30];''' + code = r''' + char ***arr3d[40]; + ''' #code = r''' #int foo(int a, int arr[*]); #''' + print(code) ast = parser.parse(code) ast.show(attrnames=True, nodenames=True) |