Skip to content

Commit

Permalink
Running code through a linter (after embedded branch).
Browse files Browse the repository at this point in the history
  • Loading branch information
robin-swift committed Sep 14, 2021
1 parent 18e72e3 commit ed89fe5
Show file tree
Hide file tree
Showing 67 changed files with 7,433 additions and 7,082 deletions.
162 changes: 95 additions & 67 deletions emb-array.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,120 +3,135 @@

EmbArray* embArray_create(int type)
{
EmbArray *p;
EmbArray* p;
p = (EmbArray*)malloc(sizeof(EmbArray));
p->type = type;
p->length = CHUNK_SIZE;
p->count = 0;
switch (p->type) {
case EMB_ARC:
p->arc = (EmbArcObject*)malloc(CHUNK_SIZE*sizeof(EmbArcObject));
p->arc = (EmbArcObject*)malloc(CHUNK_SIZE * sizeof(EmbArcObject));
break;
case EMB_CIRCLE:
p->circle = (EmbCircleObject*)malloc(CHUNK_SIZE*sizeof(EmbCircleObject));
p->circle = (EmbCircleObject*)malloc(CHUNK_SIZE * sizeof(EmbCircleObject));
break;
case EMB_ELLIPSE:
p->ellipse = (EmbEllipseObject*)malloc(CHUNK_SIZE*sizeof(EmbEllipseObject));
p->ellipse = (EmbEllipseObject*)malloc(CHUNK_SIZE * sizeof(EmbEllipseObject));
break;
case EMB_FLAG:
p->flag = (int*)malloc(CHUNK_SIZE*sizeof(int));
p->flag = (int*)malloc(CHUNK_SIZE * sizeof(int));
break;
case EMB_PATH:
p->path = (EmbPathObject**)malloc(CHUNK_SIZE*sizeof(EmbPathObject*));
p->path = (EmbPathObject**)malloc(CHUNK_SIZE * sizeof(EmbPathObject*));
break;
case EMB_POINT:
p->point = (EmbPointObject*)malloc(CHUNK_SIZE*sizeof(EmbPointObject));
p->point = (EmbPointObject*)malloc(CHUNK_SIZE * sizeof(EmbPointObject));
break;
case EMB_LINE:
p->line = (EmbLineObject*)malloc(CHUNK_SIZE*sizeof(EmbLineObject));
p->line = (EmbLineObject*)malloc(CHUNK_SIZE * sizeof(EmbLineObject));
break;
case EMB_POLYGON:
p->polygon = (EmbPolygonObject**)malloc(CHUNK_SIZE*sizeof(EmbPolygonObject*));
p->polygon = (EmbPolygonObject**)malloc(CHUNK_SIZE * sizeof(EmbPolygonObject*));
break;
case EMB_POLYLINE:
p->polyline = (EmbPolylineObject**)malloc(CHUNK_SIZE*sizeof(EmbPolylineObject*));
p->polyline = (EmbPolylineObject**)malloc(CHUNK_SIZE * sizeof(EmbPolylineObject*));
break;
case EMB_RECT:
p->rect = (EmbRectObject*)malloc(CHUNK_SIZE*sizeof(EmbRectObject));
p->rect = (EmbRectObject*)malloc(CHUNK_SIZE * sizeof(EmbRectObject));
break;
case EMB_SPLINE:
p->spline = (EmbSplineObject*)malloc(CHUNK_SIZE*sizeof(EmbSplineObject));
p->spline = (EmbSplineObject*)malloc(CHUNK_SIZE * sizeof(EmbSplineObject));
break;
case EMB_STITCH:
p->stitch = (EmbStitch*)malloc(CHUNK_SIZE*sizeof(EmbStitch));
p->stitch = (EmbStitch*)malloc(CHUNK_SIZE * sizeof(EmbStitch));
break;
case EMB_THREAD:
p->thread = (EmbThread*)malloc(CHUNK_SIZE*sizeof(EmbThread));
p->thread = (EmbThread*)malloc(CHUNK_SIZE * sizeof(EmbThread));
break;
case EMB_VECTOR:
p->vector = (EmbVector*)malloc(CHUNK_SIZE*sizeof(EmbVector));
p->vector = (EmbVector*)malloc(CHUNK_SIZE * sizeof(EmbVector));
break;
default:
break;
}
return p;
}

int embArray_resize(EmbArray *p)
int embArray_resize(EmbArray* p)
{
if (p->count < p->length) return 1;
if (p->count < p->length)
return 1;
p->length += CHUNK_SIZE;
switch (p->type) {
case EMB_ARC:
p->arc = realloc(p->arc, p->length*sizeof(EmbArcObject));
if (!p->arc) return 1;
p->arc = realloc(p->arc, p->length * sizeof(EmbArcObject));
if (!p->arc)
return 1;
break;
case EMB_CIRCLE:
p->circle = realloc(p->circle, p->length*sizeof(EmbCircleObject));
if (!p->circle) return 1;
p->circle = realloc(p->circle, p->length * sizeof(EmbCircleObject));
if (!p->circle)
return 1;
break;
case EMB_ELLIPSE:
p->ellipse = realloc(p->ellipse, p->length*sizeof(EmbEllipseObject));
if (!p->ellipse) return 1;
p->ellipse = realloc(p->ellipse, p->length * sizeof(EmbEllipseObject));
if (!p->ellipse)
return 1;
break;
case EMB_FLAG:
p->flag = realloc(p->flag, p->length*sizeof(int));
if (!p->flag) return 1;
p->flag = realloc(p->flag, p->length * sizeof(int));
if (!p->flag)
return 1;
break;
case EMB_PATH:
p->path = realloc(p->path, p->length*sizeof(EmbPathObject*));
if (!p->path) return 1;
p->path = realloc(p->path, p->length * sizeof(EmbPathObject*));
if (!p->path)
return 1;
break;
case EMB_POINT:
p->point = realloc(p->point, p->length*sizeof(EmbPointObject));
if (!p->point) return 1;
p->point = realloc(p->point, p->length * sizeof(EmbPointObject));
if (!p->point)
return 1;
break;
case EMB_LINE:
p->line = realloc(p->line, p->length*sizeof(EmbLineObject));
if (!p->line) return 1;
p->line = realloc(p->line, p->length * sizeof(EmbLineObject));
if (!p->line)
return 1;
break;
case EMB_POLYGON:
p->polygon = realloc(p->polygon, p->length*sizeof(EmbPolygonObject*));
if (!p->polygon) return 1;
p->polygon = realloc(p->polygon, p->length * sizeof(EmbPolygonObject*));
if (!p->polygon)
return 1;
break;
case EMB_POLYLINE:
p->polyline = realloc(p->polyline, p->length*sizeof(EmbPolylineObject*));
if (!p->polyline) return 1;
p->polyline = realloc(p->polyline, p->length * sizeof(EmbPolylineObject*));
if (!p->polyline)
return 1;
break;
case EMB_RECT:
p->rect = realloc(p->rect, p->length*sizeof(EmbRectObject));
if (!p->rect) return 1;
p->rect = realloc(p->rect, p->length * sizeof(EmbRectObject));
if (!p->rect)
return 1;
break;
case EMB_SPLINE:
p->spline = realloc(p->spline, p->length*sizeof(EmbSplineObject));
if (!p->spline) return 1;
p->spline = realloc(p->spline, p->length * sizeof(EmbSplineObject));
if (!p->spline)
return 1;
break;
case EMB_STITCH:
p->stitch = realloc(p->stitch, CHUNK_SIZE*sizeof(EmbStitch));
if (!p->stitch) return 1;
p->stitch = realloc(p->stitch, CHUNK_SIZE * sizeof(EmbStitch));
if (!p->stitch)
return 1;
break;
case EMB_THREAD:
p->thread = realloc(p->thread, CHUNK_SIZE*sizeof(EmbThread));
if (!p->thread) return 1;
p->thread = realloc(p->thread, CHUNK_SIZE * sizeof(EmbThread));
if (!p->thread)
return 1;
break;
case EMB_VECTOR:
p->vector = realloc(p->vector, CHUNK_SIZE*sizeof(EmbVector));
if (!p->vector) return 1;
p->vector = realloc(p->vector, CHUNK_SIZE * sizeof(EmbVector));
if (!p->vector)
return 1;
break;
default:
break;
Expand All @@ -127,7 +142,8 @@ int embArray_resize(EmbArray *p)
int embArray_addArc(EmbArray* p, EmbArc arc, int lineType, EmbColor color)
{
p->count++;
if (!embArray_resize(p)) return 0;
if (!embArray_resize(p))
return 0;
p->arc[p->count - 1].arc = arc;
p->arc[p->count - 1].lineType = lineType;
p->arc[p->count - 1].color = color;
Expand All @@ -137,7 +153,8 @@ int embArray_addArc(EmbArray* p, EmbArc arc, int lineType, EmbColor color)
int embArray_addCircle(EmbArray* p, EmbCircle circle, int lineType, EmbColor color)
{
p->count++;
if (!embArray_resize(p)) return 0;
if (!embArray_resize(p))
return 0;
p->circle[p->count - 1].circle = circle;
p->circle[p->count - 1].lineType = lineType;
p->circle[p->count - 1].color = color;
Expand All @@ -148,7 +165,8 @@ int embArray_addEllipse(EmbArray* p,
EmbEllipse ellipse, double rotation, int lineType, EmbColor color)
{
p->count++;
if (!embArray_resize(p)) return 0;
if (!embArray_resize(p))
return 0;
p->ellipse[p->count - 1].ellipse = ellipse;
p->ellipse[p->count - 1].rotation = rotation;
p->ellipse[p->count - 1].lineType = lineType;
Expand All @@ -159,23 +177,26 @@ int embArray_addEllipse(EmbArray* p,
int embArray_addFlag(EmbArray* p, int flag)
{
p->count++;
if (!embArray_resize(p)) return 0;
if (!embArray_resize(p))
return 0;
p->flag[p->count - 1] = flag;
return 1;
}

int embArray_addLine(EmbArray* p, EmbLineObject line)
{
p->count++;
if (!embArray_resize(p)) return 0;
if (!embArray_resize(p))
return 0;
p->line[p->count - 1] = line;
return 1;
}

int embArray_addPath(EmbArray* p, EmbPathObject *path)
int embArray_addPath(EmbArray* p, EmbPathObject* path)
{
p->count++;
if (!embArray_resize(p)) return 0;
if (!embArray_resize(p))
return 0;
p->path[p->count - 1] = (EmbPathObject*)malloc(sizeof(EmbPathObject));
if (!p->path[p->count - 1]) {
embLog("ERROR: emb-polygon.c embArray_create(), cannot allocate memory for heapPolygonObj\n");
Expand All @@ -185,18 +206,20 @@ int embArray_addPath(EmbArray* p, EmbPathObject *path)
return 1;
}

int embArray_addPoint(EmbArray* p, EmbPointObject *point)
int embArray_addPoint(EmbArray* p, EmbPointObject* point)
{
p->count++;
if (!embArray_resize(p)) return 0;
if (!embArray_resize(p))
return 0;
p->point[p->count - 1] = *point;
return 1;
}

int embArray_addPolygon(EmbArray* p, EmbPolygonObject *polygon)
int embArray_addPolygon(EmbArray* p, EmbPolygonObject* polygon)
{
p->count++;
if (!embArray_resize(p)) return 0;
if (!embArray_resize(p))
return 0;
p->polygon[p->count - 1] = (EmbPolygonObject*)malloc(sizeof(EmbPolygonObject));
if (!p->polygon[p->count - 1]) {
embLog("ERROR: emb-polygon.c embArray_create(), cannot allocate memory for heapPolygonObj\n");
Expand All @@ -206,10 +229,11 @@ int embArray_addPolygon(EmbArray* p, EmbPolygonObject *polygon)
return 1;
}

int embArray_addPolyline(EmbArray* p, EmbPolylineObject *polyline)
int embArray_addPolyline(EmbArray* p, EmbPolylineObject* polyline)
{
p->count++;
if (!embArray_resize(p)) return 0;
if (!embArray_resize(p))
return 0;
p->polyline[p->count - 1] = (EmbPolylineObject*)malloc(sizeof(EmbPolylineObject));
if (!p->polyline[p->count - 1]) {
embLog("ERROR: emb-polyline.c embArray_create(), cannot allocate memory for heapPolylineObj\n");
Expand All @@ -230,7 +254,8 @@ int embArray_addRect(EmbArray* p,
}

p->count++;
if (!embArray_resize(p)) return 0;
if (!embArray_resize(p))
return 0;
p->rect[p->count - 1].rect = rect;
p->rect[p->count - 1].lineType = lineType;
p->rect[p->count - 1].color = color;
Expand All @@ -246,15 +271,17 @@ int embArray_addStitch(EmbArray* p, EmbStitch st)
}
}
p->count++;
if (!embArray_resize(p)) return 0;
if (!embArray_resize(p))
return 0;
p->stitch[p->count - 1] = st;
return 1;
}

int embArray_addThread(EmbArray* p, EmbThread thread)
{
p->count++;
if (!embArray_resize(p)) return 0;
if (!embArray_resize(p))
return 0;
p->thread[p->count - 1] = thread;
return 1;
}
Expand All @@ -268,15 +295,17 @@ int embArray_addVector(EmbArray* p, EmbVector vector)
}
}
p->count++;
if (!embArray_resize(p)) return 0;
if (!embArray_resize(p))
return 0;
p->vector[p->count - 1] = vector;
return 1;
}

void embArray_free(EmbArray* p)
{
int i;
if (!p) return;
if (!p)
return;

switch (p->type) {
case EMB_ARC:
Expand All @@ -295,7 +324,7 @@ void embArray_free(EmbArray* p)
free(p->line);
break;
case EMB_PATH:
for (i=0; i<p->count; i++) {
for (i = 0; i < p->count; i++) {
embArray_free(p->path[i]->pointList);
}
free(p->path);
Expand All @@ -304,13 +333,13 @@ void embArray_free(EmbArray* p)
free(p->point);
break;
case EMB_POLYGON:
for (i=0; i<p->count; i++) {
for (i = 0; i < p->count; i++) {
embArray_free(p->polygon[i]->pointList);
}
free(p->polygon);
break;
case EMB_POLYLINE:
for (i=0; i<p->count; i++) {
for (i = 0; i < p->count; i++) {
embArray_free(p->polyline[i]->pointList);
}
free(p->polyline);
Expand All @@ -337,4 +366,3 @@ void embArray_free(EmbArray* p)
p = 0;
}


4 changes: 2 additions & 2 deletions emb-compress.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
void husExpand(unsigned char* input, unsigned char* output, int compressedSize, int compressionType)
{
/* TODO: find and analyse some HUS encoded files and DST equivalents */
output = (unsigned char*)malloc(compressedSize+1);
output = (unsigned char*)malloc(compressedSize + 1);
}

int husCompress(unsigned char* input, unsigned long _inputSize, unsigned char* output, int compressionType, int outputSize)
{
/* TODO: find and analyse some HUS encoded files and DST equivalents */
output = (unsigned char*)malloc(outputSize+1);
output = (unsigned char*)malloc(outputSize + 1);
return 0;
}
Loading

0 comments on commit ed89fe5

Please sign in to comment.