ref: dcb14ae7ca299a2df34aea904c2dd1e6c43fb59b
parent: 1ef2d33d7af26144ea8109e1017b745b98f49846
author: qwx <qwx@sciops.net>
date: Sat Aug 15 18:41:43 EDT 2020
fix idiot mistakes preventing compilation and notation in string comparison
--- a/asif.h
+++ b/asif.h
@@ -6,7 +6,7 @@
typedef struct VArray VArray;
struct VArray{
- int nelem;
+ int n;
int elsize;
int vsize;
int bufsize;
@@ -13,7 +13,7 @@
void *p;
};
void vfree(VArray*);
-VArray* vinsert(VArray*, char*);
+void vinsert(VArray*, char*);
VArray* valloc(ulong, int);
VArray* naivestrfind(String, String);
@@ -31,7 +31,7 @@
void decreasekey(Pairheap*, double, Pairheap**);
void pushqueue(double, void*, Pairheap**);
-void* erealloc(void*, ulong, ulong);
+void* erealloc(void*, ulong);
void* emalloc(ulong);
#define MIN(a,b) ((a) < (b) ? (a) : (b))
--- a/emalloc.c
+++ b/emalloc.c
@@ -3,7 +3,7 @@
#include "asif.h"
void *
-erealloc(void *p, ulong n, ulong oldn)
+erealloc(void *p, ulong n)
{
if((p = realloc(p, n)) == nil)
sysfatal("realloc: %r");
--- a/pheap.c
+++ b/pheap.c
@@ -1,7 +1,6 @@
#include <u.h>
#include <libc.h>
-#include "heap.h"
-#include "fns.h"
+#include "asif.h"
static Pairheap *
mergequeue(Pairheap *a, Pairheap *b)
@@ -72,7 +71,7 @@
}
void
-pushqueue(int n, void *aux, Pairheap **queue)
+pushqueue(double n, void *aux, Pairheap **queue)
{
Pairheap *p;
--- a/strnaive.c
+++ b/strnaive.c
@@ -2,18 +2,19 @@
#include <libc.h>
#include "asif.h"
+/* naive exact string search of a word within a text */
VArray *
-naivestrfind(String text, String word)
+naivestrfind(String S, String W)
{
- int n;
+ int i, n;
VArray *v;
- n = text.n - word.n + 1;
+ n = S.n - W.n + 1;
if(n <= 0)
return nil;
- v = valloc(n, sizeof int);
+ v = valloc(n, sizeof(int));
for(i=0; i<n; i++)
- if(strcmp(text.s+i, word.s) == 0)
- v = vinsert(v, &i);
+ if(strcmp(S.s+i, W.s) == 0)
+ v = vinsert(v, (void*)&i);
return v;
}
--- a/varray.c
+++ b/varray.c
@@ -7,24 +7,24 @@
};
void
-vfree(VAarray *v)
+vfree(VArray *v)
{
free(v->p);
free(v);
}
-VArray*
-vinsert(VArray *v, char *)
+void
+vinsert(VArray *v, char *u)
{
int off;
- off = v->nelem * v->elsize;
- if(v->nelem++ >= v->bufsize){
- v->p = erealloc(v->p, v->bufsize * 2, v->bufsize);
+ off = v->n * v->elsize;
+ if(v->n++ >= v->bufsize){
v->bufsize *= 2;
+ v->p = erealloc(v->p, v->bufsize);
v->vsize *= 2;
}
- memcpy(v->p+off, u, v->elsize);
+ memcpy((char*)v->p+off, u, v->elsize);
}
VArray*
@@ -32,8 +32,8 @@
{
VArray *v;
- v = emalloc(sizeof *p);
- v->nelem = 0;
+ v = emalloc(sizeof *v);
+ v->n = 0;
v->elsize = elsize;
v->vsize = MIN(n, VAdefsize);
v->bufsize = v->vsize * elsize;