assignment 1 problem 3 clang-format
This commit is contained in:
@@ -5,8 +5,8 @@
|
||||
* Stack, with functioin automaticlly increase the size
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
|
||||
#include "stack.h"
|
||||
|
||||
|
||||
bool CreateStack(Stack *stack, int size) {
|
||||
/* check */
|
||||
assert(size > 0);
|
||||
|
||||
@@ -8,9 +8,8 @@
|
||||
#ifndef MY_STRUCT_H
|
||||
#define MY_STRUCT_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
/* Used for AST Node's string */
|
||||
typedef struct ASTString_str {
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "uncompress.h"
|
||||
#include "stack.h"
|
||||
#include "uncompress.h"
|
||||
|
||||
ASTScanner *CreateASTScanner(char *string) {
|
||||
/* Special case define in pdf */
|
||||
@@ -65,12 +65,14 @@ char ASTScan(ASTScanner *scanner, ASTNode **ret_node) {
|
||||
return 1;
|
||||
}
|
||||
if (!IsNumber(scanner->string[i - 2])) {
|
||||
fprintf(stderr, "Syntax error: invailed value of repeat at index %ld\n", i-1);
|
||||
fprintf(stderr, "Syntax error: invailed value of repeat at index %ld\n",
|
||||
i - 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* get number and the string before the number */
|
||||
node->repeat = GetNumber(scanner->string, scanner->current_index, i-1, &node->string);
|
||||
node->repeat = GetNumber(scanner->string, scanner->current_index, i - 1,
|
||||
&node->string);
|
||||
/* if the string exists */
|
||||
if (node->string.string) {
|
||||
/* change type to 1 */
|
||||
@@ -111,7 +113,8 @@ char ASTScan(ASTScanner *scanner, ASTNode **ret_node) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned int GetNumber(char *string, size_t start, size_t end, ASTString *other_string) {
|
||||
unsigned int GetNumber(char *string, size_t start, size_t end,
|
||||
ASTString *other_string) {
|
||||
unsigned int result = 0;
|
||||
size_t index = end - 1;
|
||||
|
||||
@@ -131,9 +134,7 @@ unsigned int GetNumber(char *string, size_t start, size_t end, ASTString *other_
|
||||
return result;
|
||||
}
|
||||
|
||||
bool IsNumber(const char c) {
|
||||
return c >= '0' && c <= '9';
|
||||
}
|
||||
bool IsNumber(const char c) { return c >= '0' && c <= '9'; }
|
||||
|
||||
unsigned int Power(int x, int y) {
|
||||
unsigned int result = 1;
|
||||
@@ -147,13 +148,8 @@ void DEBUG_NODE(ASTNode *root) {
|
||||
ASTNode *currNode = root;
|
||||
while (currNode) {
|
||||
printf("[%p] type: %d, next: %p, child: %p, repeat: %d, string: %ld-%ld\n",
|
||||
currNode,
|
||||
currNode->type,
|
||||
currNode->next,
|
||||
currNode->child,
|
||||
currNode->repeat,
|
||||
currNode->string.start,
|
||||
currNode->string.end);
|
||||
currNode, currNode->type, currNode->next, currNode->child,
|
||||
currNode->repeat, currNode->string.start, currNode->string.end);
|
||||
|
||||
if (currNode->type == 2) {
|
||||
/* recursion to child */
|
||||
@@ -324,6 +320,4 @@ void Uncompress(char *string, FILE *file) {
|
||||
DestroyASTScanner(scanner);
|
||||
}
|
||||
|
||||
void DestroyASTScanner(ASTScanner *scanner) {
|
||||
free(scanner);
|
||||
}
|
||||
void DestroyASTScanner(ASTScanner *scanner) { free(scanner); }
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#ifndef UNCOMPRESS
|
||||
#define UNCOMPRESS
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "struct.h"
|
||||
@@ -20,7 +20,8 @@ char ASTScan(ASTScanner *scanner, ASTNode **ret_node);
|
||||
char ASTScanAll(ASTTree *tree, ASTScanner *scanner);
|
||||
|
||||
/* return the number before a string with index */
|
||||
unsigned int GetNumber(char *string, size_t start, size_t end, ASTString *other_string);
|
||||
unsigned int GetNumber(char *string, size_t start, size_t end,
|
||||
ASTString *other_string);
|
||||
|
||||
/* Useful function to check whether a char is a number */
|
||||
bool IsNumber(const char c);
|
||||
|
||||
Reference in New Issue
Block a user