Skip to content

Commit

Permalink
Little Changes to Work properly
Browse files Browse the repository at this point in the history
Signed-off-by: Abhinav Singh <[email protected]>
  • Loading branch information
suab321321 committed Sep 14, 2020
1 parent 8875267 commit 5b12687
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 17 deletions.
50 changes: 50 additions & 0 deletions example/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include "../include/node.h"
#include "../include/seriliaze.h"


#include<stdio.h>


void funcA1(){
childSpan(__PRETTY_FUNCTION__);
pop();
}

void funcA2(){
childSpan(__PRETTY_FUNCTION__);
pop();
}

void funcA(){
childSpan(__PRETTY_FUNCTION__);
funcA1();
funcA2();
pop();
}

void funcB1(){
childSpan(__PRETTY_FUNCTION__);
pop();
}

void funcB2(){
childSpan(__PRETTY_FUNCTION__);
pop();
}

void funcB(){
childSpan(__PRETTY_FUNCTION__);
funcB1();
funcB2();
pop();
}

int main(){
newSpan(__PRETTY_FUNCTION__);
funcA();
funcB();
pop();

serialize(root);
printf("%s\n",getStream());
}
5 changes: 3 additions & 2 deletions include/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

#include<stdlib.h>
#include<string.h>
#include "stack.h"

#define CALL_SIZE 5
#define NAME_SIZE 400

typedef struct node node;

struct node{
char name[NAME_SIZE];
Expand All @@ -19,6 +19,7 @@ struct node{
extern node* root;

void newSpan(const char *);
void childSpan(const char*, node*);
void childSpan(const char*);
void closeSpan();

#endif
10 changes: 9 additions & 1 deletion include/seriliaze.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@

#ifndef _SERIALIZE_
#define _SERIALIZE_

#include "node.h"
#include "string.h"
#include <stdlib.h>
#include <stdio.h>

void serialize(node*);
char* getStream();
char* getStream();

#endif
3 changes: 1 addition & 2 deletions include/stack.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

#include<stdlib.h>

#include "node.h"

typedef struct node node;
typedef struct stack stack;

struct stack{
Expand Down
8 changes: 0 additions & 8 deletions main.c

This file was deleted.

19 changes: 16 additions & 3 deletions src/node.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,29 @@

node* root = NULL;

void updateStack(node* n,short i){
if(i)
push(n);
else
pop();
}

void newSpan(const char* name){
root = (node*)malloc(sizeof(node));
strcpy(root->name, name);
updateStack(root,1);
}

void childSpan(const char* name, node* parentSpan){
void childSpan(const char* name){
node* nnode = (node*)malloc(sizeof(node));
nnode->prev = NULL;
nnode->cnt=0;
nnode->prev = parentSpan;
nnode->prev = top->address;
strcpy(nnode->name, name);
parentSpan->called[parentSpan->cnt++] = nnode;
top->address->called[top->address->cnt++] = nnode;
updateStack(nnode,1);
}

void closeSpan(){
updateStack(NULL,0);
}
9 changes: 9 additions & 0 deletions src/serialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,14 @@ void serialize(node* root){
}

char* getStream(){
FILE* ptr;
ptr = fopen("file.txt","w");
if(ptr == NULL){
printf("Error happened opening file\n");
return NULL;
}
fprintf(ptr,"%d\n",CALL_SIZE);
fprintf(ptr,"%s",stream);
fclose(ptr);
return stream;
}
3 changes: 2 additions & 1 deletion src/stack.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ void pop(){
return;
stack* hld = top->prev;
free(top);
hld->next = NULL;
if(hld)
hld->next = NULL;
top=hld;
}

0 comments on commit 5b12687

Please sign in to comment.