From 65c7618c2a8834616b009195f10c6cd762f43b8a Mon Sep 17 00:00:00 2001 From: Mincho Paskalev Date: Wed, 7 Nov 2018 10:31:59 +0200 Subject: Добавяне на второ домашно (#30) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add 1st hw * --amend * moving readme for 1st hw to designated folder * renamed TokenType enum to TokenClass * fixed character constant lexing. added sampe output file * add new line at end-of-file. added gitignore * a bit of refactoring * adding cyclomatic complexity * refactored * adding cyclomatic complexity * refactored --- homework/81568/c2html/Makefile | 4 +- homework/81568/c2html/cyclomatic.cpp | 95 +++++++++++++++++++ homework/81568/c2html/cyclomatic.h | 19 ++++ homework/81568/c2html/html_utils.cpp | 87 +++++++++++++++++ homework/81568/c2html/html_utils.h | 18 ++++ homework/81568/c2html/lexcer.cpp | 178 +++++++++-------------------------- homework/81568/c2html/lexcer.h | 18 +--- homework/81568/c2html/lexconst.h | 3 + homework/81568/c2html/main.cpp | 51 +++++++++- homework/81568/c2html/test.c | 6 ++ homework/81568/c2html/test.html | 163 ++++++++++++++++++++------------ 11 files changed, 429 insertions(+), 213 deletions(-) create mode 100644 homework/81568/c2html/cyclomatic.cpp create mode 100644 homework/81568/c2html/cyclomatic.h create mode 100644 homework/81568/c2html/html_utils.cpp create mode 100644 homework/81568/c2html/html_utils.h diff --git a/homework/81568/c2html/Makefile b/homework/81568/c2html/Makefile index d41a5a4..2856500 100644 --- a/homework/81568/c2html/Makefile +++ b/homework/81568/c2html/Makefile @@ -1,2 +1,2 @@ -lexcer: main.cpp lexcer.cpp - g++ -o lexcer main.cpp lexcer.cpp +lexcer: main.cpp lexcer.cpp cyclomatic.cpp html_utils.cpp + g++ -o lexcer main.cpp lexcer.cpp cyclomatic.cpp html_utils.cpp diff --git a/homework/81568/c2html/cyclomatic.cpp b/homework/81568/c2html/cyclomatic.cpp new file mode 100644 index 0000000..b7b0c17 --- /dev/null +++ b/homework/81568/c2html/cyclomatic.cpp @@ -0,0 +1,95 @@ +#include "cyclomatic.h" +#include "html_utils.h" +#include "lexcer.h" +#include "lexconst.h" +#include + +using HTMLUtils::writeToOutput; +using LexCer::TokenClass; +using LexCer::Tokenizer; + +// Writing a full parser would give us the change of +// making the cyclomatic graph of the function. +// #courseproject +unsigned ParCer::outputWithCyclomaticComplexity(FILE *in, FILE *out) { + Tokenizer tokenizer (in, out); + + std::string lexeme; + double number; + TokenClass type; + Token currentToken; + std::stack history; + bool inFunction = false; + + #define PAREN false + std::stack openedBlocks; + std::string className = "a"; + unsigned counter = 1; + unsigned complexity = 1; + + do { + currentToken = tokenizer.nextToken(&lexeme, &number); + type = currentToken.type; + + if (!inFunction) { + history.push(type); + } else { + if (type == TokenClass::RightCurly) { + if (openedBlocks.empty()) { // end of a function. What one does to avoid parsing 'C' + inFunction = false; + fputs("", complexity); + fputs(closingDiv, out); + complexity = 1; + } else { + openedBlocks.pop(); + } + } + else if (type == TokenClass::LeftCurly) { + openedBlocks.push(PAREN); + } + else if (type == TokenClass::Keyword) { + if (!lexeme.compare("if") || + !lexeme.compare("while") || + !lexeme.compare("for") || + !lexeme.compare("case") || + !lexeme.compare("default")) + { + ++complexity; + } + } + } + + if (!inFunction && type == TokenClass::LeftCurly) { + history.pop(); + while (!history.empty() && history.top() == TokenClass::Skip) { + history.pop(); + } + + if (history.top() == TokenClass::RightParen) { + while (!history.empty() && history.top() != TokenClass::LeftParen) + history.pop(); + if (!history.empty()) + history.pop(); + while (!history.empty() && history.top() == TokenClass::Skip) + history.pop(); + + if (!history.empty() && history.top() == TokenClass::Identifier) { // We are in a function + char openingDiv[100]; + sprintf(openingDiv, "
", className.c_str()); + fputs(openingDiv, out); + inFunction = true; + history = std::stack{}; + } + } + } + + if (!writeToOutput(out, currentToken)) + break; + lexeme = ""; + number = 0.0; + } while (type != TokenClass::Eof || + type != TokenClass::Invalid); + return counter - 1; +} diff --git a/homework/81568/c2html/cyclomatic.h b/homework/81568/c2html/cyclomatic.h new file mode 100644 index 0000000..29fdc1c --- /dev/null +++ b/homework/81568/c2html/cyclomatic.h @@ -0,0 +1,19 @@ +#ifndef CYCLOMATIC_H +#define CYCLOMATIC_H + +#include + +// Given this +// is 20,000 LOC, I'll probably leave parsing +// 'C' as a course project +// #courseproject + +// class Parser; + +namespace ParCer { + +unsigned outputWithCyclomaticComplexity(FILE *fpIn, FILE *fpOut); + +} /* Namespace ParCer */ + +#endif /* CYCLOMATIC_H */ diff --git a/homework/81568/c2html/html_utils.cpp b/homework/81568/c2html/html_utils.cpp new file mode 100644 index 0000000..6ca91c6 --- /dev/null +++ b/homework/81568/c2html/html_utils.cpp @@ -0,0 +1,87 @@ +#include "html_utils.h" +#include "lexconst.h" + +namespace HTMLUtils { + +std::string escapeHTML(const std::string &lexeme) { + std::string result; + for (auto c : lexeme) { + switch(c) { + case '<': + result.append("<"); + break; + case '>': + result.append(">"); + break; + case '&': + result.append("&"); + break; + default: + result.push_back(c); + break; + } + } + return result; +} + +bool writeToOutput(FILE *out, Token token) { + if (token.type == TokenClass::Eof) { + printf("End of file!\n"); + fputc('\n', out); + return false; + } + + if (token.type == TokenClass::Skip) { + if (fputs(token.lexeme.c_str(), out) == EOF) { + printf("Error while writing to output"); + return false; + } + return true; + } + + printf("Token of type %s at line %d: ", LexCer::tokenToClass.at(token.type).c_str(), token.line); + if (token.type == TokenClass::Number) + printf("%f\n", token.number); + else + printf("%s\n", token.lexeme.c_str()); + + auto lexeme = escapeHTML(token.lexeme); + + std::string output; + output.append(LexCer::spanBegin).append(LexCer::tokenToClass.at(token.type)).append("\">").append(lexeme).append(LexCer::spanEnd); + + if (fputs(output.c_str(), out) == EOF) { + printf("Error while writing to output"); + return false; + } + return true; +} + +std::string getOutputFileName(const std::string &name) { + auto pos = name.find_last_of('.'); + if (pos == std::string::npos) { + return name + ".html"; + } + + return name.substr(0, pos) + ".html"; +} + +void lexCit(FILE *in, FILE *out) { + Tokenizer hl {in, out}; + + std::string lexeme; + double number; + TokenClass type; + Token token; + do { + token = hl.nextToken(&lexeme, &number); + type = token.type; + + if (!writeToOutput(out, token)) + break; + lexeme = ""; + number = 0.0; + } while(type != TokenClass::Eof || type != TokenClass::Invalid); +} + +} /* Namespace HTMLUtils */ diff --git a/homework/81568/c2html/html_utils.h b/homework/81568/c2html/html_utils.h new file mode 100644 index 0000000..8d8cf0d --- /dev/null +++ b/homework/81568/c2html/html_utils.h @@ -0,0 +1,18 @@ +#ifndef HTML_UTILS_H +#define HTML_UTILS_H + +#include "lexcer.h" +using LexCer::Token; +using LexCer::TokenClass; +using LexCer::Tokenizer; + +namespace HTMLUtils { + +std::string escapeHTML(const std::string &lexeme); +bool writeToOutput(FILE *out, Token token); +std::string getOutputFileName(const std::string &name); +void lexCit(FILE *in, FILE *out); + +} /* Namespace HMTLUtils */ + +#endif /* HTML_UTILS_H */ diff --git a/homework/81568/c2html/lexcer.cpp b/homework/81568/c2html/lexcer.cpp index 6ad3dbd..df28e6f 100644 --- a/homework/81568/c2html/lexcer.cpp +++ b/homework/81568/c2html/lexcer.cpp @@ -4,30 +4,22 @@ #include #include -// using LexCer::TokenClass; -// using LexCer::Token; -// using LexCer::keywords; -// using LexCer::preprocessor; -// using LexCer::tokenToClass; -// using LexCer::spanBegin; -// using LexCer::spanEnd; - -//const char* Tokenizer::spanBegin = "").append(lexeme).append(spanEnd); - - if (fputs(output.c_str(), out) == EOF) { - printf("Error while writing to output"); - return false; - } - return true; -} - -std::string Tokenizer::escapeHTML(const std::string &lexeme) { - std::string result; - for (auto c : lexeme) { - switch(c) { - case '<': - result.append("<"); - break; - case '>': - result.append(">"); - break; - case '&': - result.append("&"); - break; - default: - result.push_back(c); - break; - } - } - return result; -} - -TokenClass Tokenizer::nextToken(std::string *lexeme, double *number) { +Token Tokenizer::nextToken(std::string *lexeme, double *number) { + TokenClass type; if (token.type == TokenClass::Eof) { - return TokenClass::Invalid; + return makeToken(TokenClass::Invalid, *lexeme, *number); } char c = fgetc(in); if (c == EOF) { - return TokenClass::Eof; + return makeToken(TokenClass::Eof, *lexeme, *number); } lexeme->push_back(c); // operator || symbol || string || preprocessor directive @@ -251,22 +190,24 @@ TokenClass Tokenizer::nextToken(std::string *lexeme, double *number) { case ' ': case ';': case ',': - case '{': - case '}': - return TokenClass::Skip; + return makeToken(TokenClass::Skip, *lexeme, *number); case '(': - return TokenClass::LeftParen; + return makeToken(TokenClass::LeftParen, *lexeme, *number); case ')': - return TokenClass::RightParen; + return makeToken(TokenClass::RightParen, *lexeme, *number); + case '{': + return makeToken(TokenClass::LeftCurly, *lexeme, *number); + case '}': + return makeToken(TokenClass::RightCurly, *lexeme, *number); case '[': case ']': case '?': case ':': - return TokenClass::Operator; + return makeToken(TokenClass::Operator, *lexeme, *number); case '*': c = fgetc(in); if (c == '/') { - return TokenClass::Invalid; + return makeToken(TokenClass::Invalid, *lexeme, *number); } ungetc((unsigned) c, in); c = '*'; @@ -278,7 +219,7 @@ TokenClass Tokenizer::nextToken(std::string *lexeme, double *number) { c = fgetc(in); if (c != '=') ungetc((unsigned) c, in); else lexeme->push_back(c); - return TokenClass::Operator; + return makeToken(TokenClass::Operator, *lexeme, *number); case '<': case '>': c = fgetc(in); @@ -292,11 +233,11 @@ TokenClass Tokenizer::nextToken(std::string *lexeme, double *number) { } else if (lexeme->at(lexeme->size() - 1) == '<' && isalpha(c)) { lexeme->push_back(c); if (!readInclude(lexeme)) - return TokenClass::Invalid; - return TokenClass::String; + return makeToken(TokenClass::Invalid, *lexeme, *number); + return makeToken(TokenClass::String, *lexeme, *number); } else ungetc((unsigned) c, in); - return TokenClass::Operator; + return makeToken(TokenClass::Operator, *lexeme, *number); case '&': case '|': case '+': @@ -305,18 +246,18 @@ TokenClass Tokenizer::nextToken(std::string *lexeme, double *number) { lexeme->push_back(c); else ungetc((unsigned) c, in); - return TokenClass::Operator; + return makeToken(TokenClass::Operator, *lexeme, *number); case '-': c = fgetc(in); if (c == '-' || c == '=' || c == '>') lexeme->push_back(c); else ungetc((unsigned) c, in); - return TokenClass::Operator; + return makeToken(TokenClass::Operator, *lexeme, *number); case '#': if (readNextDirective(lexeme)) - return TokenClass::PreprocessorDirective; - return TokenClass::Invalid; + return makeToken(TokenClass::PreprocessorDirective, *lexeme, *number); + return makeToken(TokenClass::Invalid, *lexeme, *number); case '\'': lexeme->push_back(c = fgetc(in)); if (c == '\\') { @@ -324,90 +265,63 @@ TokenClass Tokenizer::nextToken(std::string *lexeme, double *number) { } lexeme->push_back(c = fgetc(in)); // the closing mark if (c != '\'') - return TokenClass::Invalid; - return TokenClass::String; + return makeToken(TokenClass::Invalid, *lexeme, *number); + return makeToken(TokenClass::String, *lexeme, *number); case '"': if (readNextString(lexeme, c)) - return TokenClass::String; - return TokenClass::Invalid; + return makeToken(TokenClass::String, *lexeme, *number); + return makeToken(TokenClass::Invalid, *lexeme, *number); case '/': c = fgetc(in); lexeme->push_back(c); switch (c) { case '=': - return TokenClass::Operator; + return makeToken(TokenClass::Operator, *lexeme, *number); case '/': if (!readLineComment(lexeme)) - return TokenClass::Invalid; - return TokenClass::Comment; + return makeToken(TokenClass::Invalid, *lexeme, *number); + return makeToken(TokenClass::Comment, *lexeme, *number); case '*': if (!readMultilineComment(lexeme)) - return TokenClass::Invalid; - return TokenClass::Comment; + return makeToken(TokenClass::Invalid, *lexeme, *number); + return makeToken(TokenClass::Comment, *lexeme, *number); default: if (!isblank(c) || !isdigit(c)) { ungetc((unsigned) c, in); lexeme->pop_back(); - return TokenClass::Invalid; + return makeToken(TokenClass::Invalid, *lexeme, *number); } - return TokenClass::Operator; + return makeToken(TokenClass::Operator, *lexeme, *number); } case '\\': c = fgetc(in); ungetc((unsigned) c, in); if (c != '\n') - return TokenClass::Invalid; // stray '\' - return TokenClass::Operator; + return makeToken(TokenClass::Invalid, *lexeme, *number); // stray '\' + return makeToken(TokenClass::Operator, *lexeme, *number); } // identifier || keyword || typename if (isalpha(c) || c == '_') { if (readNextIdentifier(lexeme)) { if (keywords.count(*lexeme) != 0) - return TokenClass::Keyword; + return makeToken(TokenClass::Keyword, *lexeme, *number); else if (typenames.count(*lexeme) != 0) - return TokenClass::Typename; - return TokenClass::Identifier; + return makeToken(TokenClass::Typename, *lexeme, *number); + return makeToken(TokenClass::Identifier, *lexeme, *number); } else { - return TokenClass::Invalid; + return makeToken(TokenClass::Invalid, *lexeme, *number); } } if (!isdigit(c)) { - return TokenClass::Invalid; + return makeToken(TokenClass::Invalid, *lexeme, *number); } // number if (readNextNumber(c, number, lexeme)) - return TokenClass::Number; - return TokenClass::Invalid; + return makeToken(TokenClass::Number, *lexeme, *number); + return makeToken(TokenClass::Invalid, *lexeme, *number); } - - -std::string getOutputFileName(const std::string &name) { - auto pos = name.find_last_of('.'); - if (pos == std::string::npos) { - return name + ".html"; - } - return name.substr(0, pos) + ".html"; -} - -void lexCit(FILE *in, FILE *out) { - Tokenizer hl {in, out}; - - std::string lexeme; - double number; - TokenClass type; - do { - type = hl.nextToken(&lexeme, &number); - - hl.makeToken(type, hl.lineNumber(), lexeme, number); - if (!hl.writeToOutput()) - break; - lexeme = ""; - number = 0.0; - } while(hl.currentToken().type != TokenClass::Eof || hl.currentToken().type != TokenClass::Invalid); -} - } /* Namespace Lexcer */ diff --git a/homework/81568/c2html/lexcer.h b/homework/81568/c2html/lexcer.h index e329a90..eb8afe0 100644 --- a/homework/81568/c2html/lexcer.h +++ b/homework/81568/c2html/lexcer.h @@ -9,7 +9,7 @@ namespace LexCer { -enum class TokenClass : short { +enum TokenClass : short { Operator, Keyword, PreprocessorDirective, @@ -20,6 +20,8 @@ enum class TokenClass : short { Number, LeftParen, RightParen, + LeftCurly, + RightCurly, Skip, Eof, @@ -46,16 +48,10 @@ private: public: Tokenizer(FILE *in, FILE *out); - unsigned lineNumber() const { return line; } - Token currentToken() const { return token; } - - TokenClass nextToken(std::string *lexeme, double *number); - void makeToken(TokenClass type, unsigned line, - std::string lexeme = std::string(), double number = 0.0); - bool writeToOutput(); + Token nextToken(std::string *lexeme, double *number); private: - std::string escapeHTML(const std::string &lexeme); + Token makeToken(TokenClass type, std::string lexeme = std::string(), double number = 0.0); bool readNextDirective(std::string *lexeme); bool readNextString(std::string *lexeme, char oldc); bool readNextIdentifier(std::string *lexeme); @@ -75,10 +71,6 @@ private: std::unordered_set typenames; }; - -std::string getOutputFileName(const std::string &name); -void lexCit(FILE *in, FILE *out); - } /* Namespace LexCer */ #endif diff --git a/homework/81568/c2html/lexconst.h b/homework/81568/c2html/lexconst.h index 9d2068d..cfb9e6d 100644 --- a/homework/81568/c2html/lexconst.h +++ b/homework/81568/c2html/lexconst.h @@ -25,6 +25,9 @@ static const std::unordered_map tokenToClass {TokenClass::Number, "number"}, {TokenClass::Invalid, "invalid"}, {TokenClass::LeftParen, "identifier"}, + {TokenClass::LeftCurly, "identifier"}, + {TokenClass::RightParen, "identifier"}, + {TokenClass::RightCurly, "identifier"}, {TokenClass::RightParen, "identifier"} } }; diff --git a/homework/81568/c2html/main.cpp b/homework/81568/c2html/main.cpp index eedaee3..d4dbed3 100644 --- a/homework/81568/c2html/main.cpp +++ b/homework/81568/c2html/main.cpp @@ -1,4 +1,8 @@ #include +#include + +#include "cyclomatic.h" +#include "html_utils.h" #include "lexcer.h" int main(int argc, char *argv[]) { @@ -13,7 +17,7 @@ int main(int argc, char *argv[]) { return 2; /* unable to open file or inavlid file */ } - auto outputName = LexCer::getOutputFileName(argv[1]); + auto outputName = HTMLUtils::getOutputFileName(argv[1]); auto fpOut = fopen(outputName.c_str(), "w"); if (!fpOut) { return 2; @@ -21,7 +25,7 @@ int main(int argc, char *argv[]) { fputs( - "\n" + "\n" "\n" "\n" " LexCed\n" @@ -58,14 +62,51 @@ int main(int argc, char *argv[]) { " .comment {\n" " color: green;\n" " }\n" + " .complexity-level-one {\n" + " background-color: PaleGreen;\n" + " }\n" + " .complexity-level-two {\n" + " background-color: DarkGreen;\n" + " }\n" + " .complexity-level-three {\n" + " background-color: SaddleBrown;\n" + " }\n" + " .complexity-level-four {\n" + " background-color: Brown;\n" + " }\n" + " .complexity-level-five {\n" + " background-color: Maroon;\n" + " }\n" " \n" "\n" - "\n" + "\n" "
\n",
         fpOut
         );
-  LexCer::lexCit(fpIn, fpOut);
-  fputs("
\n", fpOut); + ParCer::outputWithCyclomaticComplexity(fpIn, fpOut); + fputs("\n" + "\n", fpOut); printf("Highlighted text written in %s!\n", outputName.c_str()); diff --git a/homework/81568/c2html/test.c b/homework/81568/c2html/test.c index 636032a..0aafa72 100644 --- a/homework/81568/c2html/test.c +++ b/homework/81568/c2html/test.c @@ -69,6 +69,12 @@ void switch_why_not(void) { break; case 'X': printf("why break stuff\n"); + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: default: break; } diff --git a/homework/81568/c2html/test.html b/homework/81568/c2html/test.html index 83b41a5..e39aec0 100644 --- a/homework/81568/c2html/test.html +++ b/homework/81568/c2html/test.html @@ -1,4 +1,4 @@ - + LexCed @@ -35,9 +35,24 @@ .comment { color: green; } + .complexity-level-one { + background-color: PaleGreen; + } + .complexity-level-two { + background-color: DarkGreen; + } + .complexity-level-three { + background-color: SaddleBrown; + } + .complexity-level-four { + background-color: Brown; + } + .complexity-level-five { + background-color: Maroon; + } - +
 #ifndef SAMPLE_CODE_C
 #define SAMPLE_CODE_C
@@ -46,97 +61,103 @@
 
 #include <stdio.h>
 
-int bitcount(long long x) {
+int bitcount(long long x) 
{ int cnt = 0;; - while (x) { + while (x) { ++cnt; - x &= (x-1); - } + x &= (x-1); + } return cnt; -} +
} -void shift_to_pos(int *num, int p, int n) { - *num = p > n ? *num << (p - n + 1) : *num >> (n - p + 1); -} +void shift_to_pos(int *num, int p, int n)
{ + *num = p > n ? *num << (p - n + 1) : *num >> (n - p + 1); +
} -int setbits(x, p, n, y) { - int mask = (1 << n) - 1; +int setbits(x, p, n, y)
{ + int mask = (1 << n) - 1; int to_set = y & mask; - shift_to_pos(&mask, p, n); - shift_to_pos(&to_set, p, n); - return (x & ~mask) | to_set; -} + shift_to_pos(&mask, p, n); + shift_to_pos(&to_set, p, n); + return (x & ~mask) | to_set; +
} -unsigned invert(unsigned x, unsigned p, unsigned n) { +unsigned invert(unsigned x, unsigned p, unsigned n)
{ ++p; // in case p < n - while(n-- && p--) { - if (!(x & (1 << n))) { - x |= (1 << n); - } else { - x ^= (1 << n); - } - } + while(n-- && p--) { + if (!(x & (1 << n))) { + x |= (1 << n); + } else { + x ^= (1 << n); + } + } return x; -} +
} -int rightrot(long long x, int n) { - int bitcnt = bitcount(x); +int rightrot(long long x, int n)
{ + int bitcnt = bitcount(x); x <<= n; - return (x & ( (1 << (bitcnt)) - 1) ) | (x & ~( (1 << bitcnt) - 1 )) >> bitcnt; -} + return (x & ( (1 << (bitcnt)) - 1) ) | (x & ~( (1 << bitcnt) - 1 )) >> bitcnt; +
} char num[32]; -void to_binary(unsigned x) { +void to_binary(unsigned x)
{ int i = 31; num[32] = '\0'; - while (x) { - if (x & 1) num[i] = '1'; + while (x) { + if (x & 1) num[i] = '1'; else num[i] = '0'; --i; x >>= 1; - } - for (; i >= 0;; --i) num[i] = '0'; - for (; i < 32; ++i) { - printf("%c%s", num[i], !((i+1) % 4) ? " " : ""); - } -} - -void switch_why_not(void) { + } + for (; i >= 0;; --i) num[i] = '0'; + for (; i < 32; ++i) { + printf("%c%s", num[i], !((i+1) % 4) ? " " : ""); + } +
} + +void switch_why_not(void)
{ char c = 'X'; - switch(c) { + switch(c) { case 'x': - printf("hex\n"); + printf("hex\n"); break; case 'X': - printf("why break stuff\n"); + printf("why break stuff\n"); + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: default: break; - } + } return; -} +
} -main() { +main()
{ long long x = 0b110110; - printf("rightrot:\n"); - to_binary(x); - printf("\n"); - to_binary(rightrot(x, 3)); - printf("\n"); + printf("rightrot:\n"); + to_binary(x); + printf("\n"); + to_binary(rightrot(x, 3)); + printf("\n"); unsigned i = 0b101010; - printf("invert:\n"); - to_binary(i); - printf("\n"); - to_binary(invert(i, 4, 4)); - printf("\n"); + printf("invert:\n"); + to_binary(i); + printf("\n"); + to_binary(invert(i, 4, 4)); + printf("\n"); long long a = 0b111001010011; long long b = 0b11111010; - printf("bits of: "); to_binary(a); printf("\n"); - printf("bits to: "); to_binary(b); printf("\n"); - to_binary(setbits(a, 6, 4, b)); + printf("bits of: "); to_binary(a); printf("\n"); + printf("bits to: "); to_binary(b); printf("\n"); + to_binary(setbits(a, 6, 4, b)); int testInt = 12345678; @@ -144,8 +165,28 @@ double testDouble = 1234.5678; return 0;; -} +
} #endif /* SAMPLE_CODE_C */ -
+ + -- cgit v1.3.1-23-gd82d