aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHolden Rohrer <hr@hrhr.dev>2020-05-27 22:42:10 -0400
committerHolden Rohrer <hr@hrhr.dev>2020-05-27 22:42:10 -0400
commite48d50df121d5852baa001fb7b7572dc47cb73a0 (patch)
tree0fee3dfb950c9bc525262696a5e89c152849de1c
parentf64d926d669f6328e6b28c5d4fa5b1687052440b (diff)
made global objects static to clean namespace
-rw-r--r--badroff.c72
-rw-r--r--buf.c6
-rw-r--r--sb.c4
3 files changed, 41 insertions, 41 deletions
diff --git a/badroff.c b/badroff.c
index 9e6ba4c..213a9c9 100644
--- a/badroff.c
+++ b/badroff.c
@@ -7,18 +7,18 @@
#include "sb.h"
#include "ll.h"
-char* line(void);
-char* wordset(char* txt);
-void wsclean(char* txt);
+static char* line(void);
+static char* wordset(char* txt);
+static void wsclean(char* txt);
-FILE* getfile(int argc, char** argv){
+static FILE* getfile(int argc, char** argv){
if (argc >= 2)
return fopen(argv[1], "r");
else
return stdin;
}
-char* chrmult(char c, size_t ct){
+static char* chrmult(char c, size_t ct){
char* str = malloc(sizeof(char)*(ct+1)); str[ct] = 0;
memset(str, c, ct);
return str;
@@ -26,23 +26,23 @@ char* chrmult(char c, size_t ct){
// file read & buffer fill helpers
-FILE* in;
-buf* inbuf;
+static FILE* in;
+static buf* inbuf;
-int addchr(void){
+static int addchr(void){
int c = fgetc(in);
if (c != EOF) inschrbuf(inbuf, c);
return c;
}
-size_t fillbuf(size_t len){ // returns real len
+static size_t fillbuf(size_t len){ // returns real len
int c;
size_t set;
for (set = buflen(inbuf); set < len && (c = addchr()) != EOF;set++);
return set;
}
-size_t chrfill(char chr){
+static size_t chrfill(char chr){
size_t len = buflen(inbuf);
char* str = peekstrbuf(inbuf, 0, len);
char* line = memchr(str,chr,len);
@@ -66,10 +66,10 @@ size_t chrnfill(char chr, size_t sz){//fills to first of chr or sz
}
// typesetting config and commands to change.
-int width = 80;
-char nbsp = 0;
+static int width = 80;
+static char nbsp = 0;
-char* center(char* txt){
+static char* center(char* txt){
size_t len = strlen(txt);
int max = width/2 + len/2; // excluding terminator
int min = max-len+1; // first index of *txt
@@ -80,22 +80,22 @@ char* center(char* txt){
str[max+1] = 0;
return str;
}
-char* setwidth(char* txt){
+static char* setwidth(char* txt){
sscanf(txt, "%d", &width);
return NULL;
}
-char* fillline(char* txt){
+static char* fillline(char* txt){
char* str = malloc(sizeof(char)*(width+2));
str[width] = '\n'; str[width+1] = 0;
memset(str, txt[0], width);
return str;
}
-char* token(char* txt, char c) {
+static char* token(char* txt, char c) {
char* end = strchr(txt, c);
*end = 0;
return end+1;
}
-char* leader(char* txt){
+static char* leader(char* txt){
char* start = txt;
char* repeat = token(start, '|');
char* end = token(repeat, '|');
@@ -108,8 +108,8 @@ char* leader(char* txt){
fin[i] = repeat[i % rptln];
return fin;
}
-bool endgroup = false;
-llnode* freenext(llnode* node){
+static bool endgroup = false;
+static llnode* freenext(llnode* node){
llnode* tmp = node->next;
node->next = tmp->next;
free(tmp->str);
@@ -117,7 +117,7 @@ llnode* freenext(llnode* node){
if (tmp == node) return NULL;
return node->next;
}
-void multbreak(sb* buffer, size_t start,
+static void multbreak(sb* buffer, size_t start,
size_t len, llnode** tail, size_t* ct){
for (size_t i = *ct; i > 0; i--){
char* str = (*tail)->next->str + start;
@@ -137,7 +137,7 @@ void multbreak(sb* buffer, size_t start,
}
}
}
-llnode* accumlines(size_t* ct){ // returns tail of linked list
+static llnode* accumlines(size_t* ct){ // returns tail of linked list
llnode *head, *tail; head = tail = appendll(NULL, NULL);
(*ct) = 0;
while (!endgroup){
@@ -162,7 +162,7 @@ llnode* accumlines(size_t* ct){ // returns tail of linked list
endgroup = false; // prevents false positive on next run
return tail;
}
-char* foldlines(llnode* tail, size_t ct){
+static char* foldlines(llnode* tail, size_t ct){
sb* buf = newsb(100);
size_t oldbrk = 0, brk = 0;
@@ -192,24 +192,24 @@ char* foldlines(llnode* tail, size_t ct){
return decompose(buf);
}
-char* lineset(char* txt){
+static char* lineset(char* txt){
size_t ct;
llnode* tail = accumlines(&ct);
return foldlines(tail, ct);
}
-char* emptalloc(void){ // need a null string so it can be freed later
+static char* emptalloc(void){ // need a null string so it can be freed later
char* str = malloc(sizeof(char)); str[0] = 0;
return str;
}
-char* fingroup(char* txt){
+static char* fingroup(char* txt){
endgroup = true;
return emptalloc();
}
-char* vert(char* txt){
+static char* vert(char* txt){
int ln; sscanf(txt, "%d", &ln);
return chrmult('\n', ln);
}
-char* nbrkspc(char* txt){
+static char* nbrkspc(char* txt){
if (txt[0] == '\n') txt[0] = 0;
if (txt[1] == '\n') txt[1] = 0;
if (txt[0] != 0 && txt[1] != 0)
@@ -220,7 +220,7 @@ char* nbrkspc(char* txt){
nbsp = 0;
return NULL;
}
-char* merge(char* txt){ // merges until an endgroup
+static char* merge(char* txt){ // merges until an endgroup
// gather lines
size_t ct;
llnode* head = accumlines(&ct)->next;
@@ -247,13 +247,13 @@ char* merge(char* txt){ // merges until an endgroup
return str;
}
-char* cmds[] = // MUST be sorted alphabetically
+static char* cmds[] = // MUST be sorted alphabetically
{"CT ", "EG", "FIL ", "LD ", "LS", "MRG", "NBSP", "V ", "W "};
-char* (*call[])(char* txt) =
+static char* (*call[])(char* txt) =
{center, fingroup, fillline, leader, lineset, merge, nbrkspc,
vert, setwidth};
-char* cmd(void){
+static char* cmd(void){
char* dat = popstrbuf(inbuf, chrfill('\n'));
size_t low = 0; size_t high = sizeof(cmds)/sizeof(*cmds); //len
char* proc = NULL;
@@ -288,7 +288,7 @@ void wsclean(char* txt){
txt[i+nl] = 0; // finish string
}
#define nbspchr (char) 255
-void nbspclean(char* txt){
+static void nbspclean(char* txt){
for (; *txt != 0; txt++){
if (*txt == nbspchr) *txt = ' ';
}
@@ -296,8 +296,8 @@ void nbspclean(char* txt){
char* wordset(char* txt){
char* orig = txt; // txt will be manipulated
- size_t ws = 0; // zero means do not cut
- for (size_t i=0; txt[i] != 0; i++){ // turn into a nested loop
+ int ws = 0; // zero means do not cut
+ for (int i=0; txt[i] != 0; i++){ // turn into a nested loop
if (txt[i] == ' ' || txt[i] == '\n') ws = i;
// nl's (multiline input) and spaces are proper linebreaks
if (txt[i] == '\n' || (ws && i >= width && ws != i) ){
@@ -315,13 +315,13 @@ char* wordset(char* txt){
}
-char* norm(void){
+static char* norm(void){
return popstrbuf(inbuf, chrfill('\n'));
}
// a parser to choose when to typeset and when to run a command
-void nbspsub(char* txt){
+static void nbspsub(char* txt){
for (; (*txt) != 0; txt++){
if (*txt == nbsp) *txt = nbspchr;
}
diff --git a/buf.c b/buf.c
index 61c0470..67b7b26 100644
--- a/buf.c
+++ b/buf.c
@@ -18,7 +18,7 @@ struct buf{
size_t pop;
}; // a "thick" linked list (buffered for mem efficiency)
-buf_node* newbufnode(size_t cap){
+static buf_node* newbufnode(size_t cap){
buf_node* bufnode = malloc(sizeof(buf_node));
bufnode->text = malloc(sizeof(char)*cap);
return bufnode;
@@ -42,13 +42,13 @@ size_t buflen(buf* buffer){
return size;
}
-void extendbuf(buf* buffer){
+static void extendbuf(buf* buffer){
buffer->head->next = newbufnode(buffer->cap);
buffer->head = buffer->head->next;
// buffer->ins = 0 is taken care of in the function that uses this.
}
-void shortenbuf(buf* buffer){
+static void shortenbuf(buf* buffer){
buf_node* tmp = buffer->tail;
buffer->tail = buffer->tail->next;
free(tmp->text);
diff --git a/sb.c b/sb.c
index e1cbd63..a36f82a 100644
--- a/sb.c
+++ b/sb.c
@@ -15,7 +15,7 @@ struct sbnode {
sbnode* next;
};
-sbnode* newsbnode(sbnode* prev, size_t sz){
+static sbnode* newsbnode(sbnode* prev, size_t sz){
sbnode* node = malloc(sizeof(sbnode)); // Allocate
node->str = malloc(sizeof(char)*(sz+1)); node->str[sz] = 0;
node->next = NULL; // Init
@@ -31,7 +31,7 @@ sb* newsb(size_t sz){
return out;
}
-void extendsb(sb* buf){
+static void extendsb(sb* buf){
buf->sz *= 2;
buf->loc = 0;
buf->tail = newsbnode(buf->tail, buf->sz);