EE445M RTOS
Taken at the University of Texas Spring 2015
graphlib.c File Reference
#include <limits.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "graphlib.h"
Include dependency graph for graphlib.c:

Go to the source code of this file.

Functions

char * strdup (const char *str)
 
graphGLCreateGraph (long x_min, long x_max, long y_min, long y_max, long x_steps)
 
char * GLSetTitle (graph *g, char *title)
 
void GLLabelAxes (graph *g, char *x_axis, char *y_axis)
 
void GLPushDataPoint (graph *g, long y_val)
 
long GLOffScreenValue (graph *g)
 
void GLDestroyGraph (graph *g)
 

Function Documentation

graph* GLCreateGraph ( long  x_min,
long  x_max,
long  y_min,
long  y_max,
long  x_steps 
)

Definition at line 25 of file graphlib.c.

References graph::all_data_points_valid, graph::data, graph::x_index, graph::x_index_max, graph::x_max, graph::x_min, graph::y_max, and graph::y_min.

Referenced by main().

25  {
26  graph* g = (graph*) calloc(1, sizeof(graph));
27  g->x_min = x_min;
28  g->x_max = x_max;
29  g->y_min = y_min;
30  g->y_max = y_max;
31 
32  g->data = (long*) calloc(x_steps, sizeof(long));
33  g->x_index = 0;
34  g->x_index_max = x_steps;
35 
36  g->all_data_points_valid = false;
37 
38  return (graph*) g;
39 }
long * data
Definition: graphlib.h:41
long x_max
Definition: graphlib.h:37
unsigned long x_index_max
Definition: graphlib.h:45
Definition: graphlib.h:29
unsigned long x_index
Definition: graphlib.h:44
long x_min
Definition: graphlib.h:37
long y_min
Definition: graphlib.h:38
long y_max
Definition: graphlib.h:38
bool all_data_points_valid
Definition: graphlib.h:55

Here is the caller graph for this function:

void GLDestroyGraph ( graph g)

Definition at line 83 of file graphlib.c.

References graph::data, graph::title, graph::x_title, and graph::y_title.

83  {
84  free(g->data);
85  free(g->title);
86  free(g->x_title);
87  free(g->y_title);
88  free(g);
89 }
char * y_title
Definition: graphlib.h:32
long * data
Definition: graphlib.h:41
char * x_title
Definition: graphlib.h:31
char * title
Definition: graphlib.h:33
void GLLabelAxes ( graph g,
char *  x_axis,
char *  y_axis 
)

Definition at line 48 of file graphlib.c.

References strdup(), graph::x_title, and graph::y_title.

Referenced by main().

48  {
49  g->x_title = strdup(x_axis);
50  g->y_title = strdup(y_axis);
51 }
char * y_title
Definition: graphlib.h:32
char * strdup(const char *str)
Definition: graphlib.c:15
char * x_title
Definition: graphlib.h:31

Here is the call graph for this function:

Here is the caller graph for this function:

long GLOffScreenValue ( graph g)

Definition at line 71 of file graphlib.c.

References graph::y_max, and graph::y_min.

71  {
72  long off_screen_value = g->y_max + 1;
73  if (off_screen_value < g->y_max) {
74  off_screen_value = g->y_min - 1;
75  } if (off_screen_value > g->y_min) {
76  off_screen_value = LONG_MIN;
77  }
78  return off_screen_value;
79 }
long y_min
Definition: graphlib.h:38
long y_max
Definition: graphlib.h:38
void GLPushDataPoint ( graph g,
long  y_val 
)

Definition at line 56 of file graphlib.c.

References graph::all_data_points_valid, graph::data, graph::most_recent_data_point, graph::x_index, and graph::x_index_max.

Referenced by main().

56  {
57  /* Procedure: push the y data point at the current x_position and
58  * then increment the current x_position. */
59  g->data[g->x_index] = y_val;
61 
62  if (g->x_index >= g->x_index_max) {
63  g->x_index = 0;
64  g->all_data_points_valid = true; // one-way toggle to true
65  }
66 }
long most_recent_data_point
Definition: graphlib.h:66
long * data
Definition: graphlib.h:41
unsigned long x_index_max
Definition: graphlib.h:45
unsigned long x_index
Definition: graphlib.h:44
bool all_data_points_valid
Definition: graphlib.h:55

Here is the caller graph for this function:

char* GLSetTitle ( graph g,
char *  title 
)

Definition at line 42 of file graphlib.c.

References strdup(), and graph::title.

Referenced by main().

42  {
43  g->title = strdup(title);
44  return g->title;
45 }
char * strdup(const char *str)
Definition: graphlib.c:15
char * title
Definition: graphlib.h:33

Here is the call graph for this function:

Here is the caller graph for this function:

char* strdup ( const char *  str)

Definition at line 15 of file graphlib.c.

References null.

Referenced by GLLabelAxes(), GLSetTitle(), and utarray_str_cpy().

15  {
16  if (str != null) {
17  char *copy = malloc(strlen(str) + 1);
18  if (copy != null)
19  return strcpy(copy, str);
20  }
21  return null;
22 }
#define null
Definition: defines.h:29

Here is the caller graph for this function: