cloc_remove_comments.Rd
Pass in a path to a source file and retrieve a version of the source file without comments (or white space).
cloc_remove_comments(source_file)
source_file | path to source file |
---|
character vector containing only code blocks
#> [1] "#include <Rcpp.h>\n#include \"qrencode.h\"\n#include <stdio.h>\n#include <unistd.h>\n#include <string>\n#include <fstream>\n#include <streambuf>\nusing namespace Rcpp;\n#define INCHES_PER_METER (100.0/2.54)\nstatic int rle = 1;\nstatic unsigned int fg_color[4] = {0, 0, 0, 255};\nstatic unsigned int bg_color[4] = {255, 255, 255, 255};\nNumericMatrix qrencode_raw(std::string to_encode,\n int version=0,\n int level=0,\n int hint=2,\n int caseinsensitive=1) {\n QRcode *qrcode ;\n unsigned char *row;\n int x, y;\n qrcode = QRcode_encodeString(to_encode.c_str(),\n version,\n (QRecLevel)level,\n (QRencodeMode)hint, caseinsensitive);\n NumericMatrix qr(qrcode->width, qrcode->width);\n for(y=0; y <qrcode->width; y++) {\n row = qrcode->data+(y*qrcode->width);\n for(x = 0; x < qrcode->width; x++) {\n qr(x, y) = row[x]&0x1;\n }\n }\n return(qr);\n}\nstatic FILE *openFile(const char *outfile) {\n FILE *fp;\n if(outfile == NULL || (outfile[0] == '-' && outfile[1] == '\\0')) {\n fp = stdout;\n } else {\n fp = fopen(outfile, \"wb\");\n if (fp == NULL) return(NULL);\n }\n return fp;\n}\nstatic void writeSVG_writeRect(FILE *fp, int x, int y, int width, char* col, float opacity) {\n if(fg_color[3] != 255) {\n fprintf(fp, \"\\t\\t\\t<rect x=\\\"%d\\\" y=\\\"%d\\\" width=\\\"%d\\\" height=\\\"1\\\" \"\\\n \"fill=\\\"#%s\\\" fill-opacity=\\\"%f\\\" />\\n\",\n x, y, width, col, opacity );\n } else {\n fprintf(fp, \"\\t\\t\\t<rect x=\\\"%d\\\" y=\\\"%d\\\" width=\\\"%d\\\" height=\\\"1\\\" \"\\\n \"fill=\\\"#%s\\\" />\\n\",\n x, y, width, col );\n }\n}\nCharacterVector writeSVG(QRcode *qrcode, int margin, int size, int dpi) {\n FILE *fp;\n unsigned char *row, *p;\n int x, y, x0, pen;\n int symwidth, realwidth;\n float scale;\n char fg[7], bg[7];\n float fg_opacity;\n float bg_opacity;\n char fname[L_tmpnam];\n memset(fname, 0, L_tmpnam);\n strncpy(fname,\"qrencoder-XXXXXX\", 16);\n fp = openFile(mktemp(fname));\n if (fp == NULL) return(R_NilValue);\n scale = dpi * INCHES_PER_METER / 100.0;\n symwidth = qrcode->width + margin * 2;\n realwidth = symwidth * size;\n snprintf(fg, 7, \"%02x%02x%02x\", fg_color[0], fg_color[1], fg_color[2]);\n snprintf(bg, 7, \"%02x%02x%02x\", bg_color[0], bg_color[1], bg_color[2]);\n fg_opacity = (float)fg_color[3] / 255;\n bg_opacity = (float)bg_color[3] / 255;\n fputs( \"<?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"yes\\\"?>\\n\", fp );\n fprintf( fp, \"<!-- Created with qrencode %s (http:\n QRcode_APIVersionString() );\n fprintf( fp, \"<svg width=\\\"%0.2fcm\\\" height=\\\"%0.2fcm\\\" viewBox=\\\"0 0 %d %d\\\"\"\\\n \" preserveAspectRatio=\\\"none\\\" version=\\\"1.1\\\"\" \\\n \" xmlns=\\\"http:\n realwidth / scale, realwidth / scale, symwidth, symwidth\n );\n fputs( \"\\t<g id=\\\"QRcode\\\">\\n\", fp );\n if(bg_color[3] != 255) {\n fprintf(fp, \"\\t\\t<rect x=\\\"0\\\" y=\\\"0\\\" width=\\\"%d\\\" height=\\\"%d\\\" fill=\\\"#%s\\\" fill-opacity=\\\"%f\\\" />\\n\", symwidth, symwidth, bg, bg_opacity);\n } else {\n fprintf(fp, \"\\t\\t<rect x=\\\"0\\\" y=\\\"0\\\" width=\\\"%d\\\" height=\\\"%d\\\" fill=\\\"#%s\\\" />\\n\", symwidth, symwidth, bg);\n }\n fputs( \"\\t\\t<g id=\\\"Pattern\\\">\\n\", fp);\n p = qrcode->data;\n for(y=0; y<qrcode->width; y++) {\n row = (p+(y*qrcode->width));\n if( !rle ) {\n for(x=0; x<qrcode->width; x++) {\n if(*(row+x)&0x1) {\n writeSVG_writeRect(fp,\tmargin + x,\n margin + y, 1,\n fg, fg_opacity);\n }\n }\n } else {\n pen = 0;\n x0 = 0;\n for(x=0; x<qrcode->width; x++) {\n if( !pen ) {\n pen = *(row+x)&0x1;\n x0 = x;\n } else {\n if(!(*(row+x)&0x1)) {\n writeSVG_writeRect(fp, x0 + margin, y + margin, x-x0, fg, fg_opacity);\n pen = 0;\n }\n }\n }\n if( pen ) {\n writeSVG_writeRect(fp, x0 + margin, y + margin, qrcode->width - x0, fg, fg_opacity);\n }\n }\n }\n fputs( \"\\t\\t</g>\\n\", fp );\n fputs( \"\\t</g>\\n\", fp );\n fputs( \"</svg>\\n\", fp );\n fclose( fp );\n std::ifstream t(fname);\n std::string str((std::istreambuf_iterator<char>(t)),\n std::istreambuf_iterator<char>());\n t.close();\n unlink(fname);\n return(Rcpp::wrap(str));\n}\nCharacterVector qrencode_svg(\n std::string to_encode,\n int version=0, int level=0, int hint=2,\n int caseinsensitive=1, int margin = 0, int size = 3, int dpi = 72) {\n QRcode *qrcode ;\n qrcode = QRcode_encodeString(to_encode.c_str(),\n version,\n (QRecLevel)level,\n (QRencodeMode)hint, caseinsensitive);\n return(writeSVG(qrcode, margin, size, dpi));\n}"