aboutsummaryrefslogtreecommitdiff
path: root/badroff.c
diff options
context:
space:
mode:
Diffstat (limited to 'badroff.c')
-rw-r--r--badroff.c72
1 files changed, 36 insertions, 36 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;
}