From 0d0b248d03952bdc1298e8fd399a97a91889c755 Mon Sep 17 00:00:00 2001 From: glenda Date: Fri, 31 Jan 2025 04:21:24 +0000 Subject: [PATCH] checkfile --- pres.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 53 insertions(+), 14 deletions(-) diff --git a/pres.c b/pres.c index a988310e5cffa070c87799e9f8522d7dd3881ca2..af24712b2a2bf135923a654e8d226231d0d0ca5f 100644 --- a/pres.c +++ b/pres.c @@ -11,15 +11,17 @@ char *file, *contents; typedef struct Slide { char *cmd; char *arg; + int linum; int nlines; char *lines[]; } Slide; char * -nextline(char **p) +nextline(char **p, int *linum) { char *line; while(1){ + (*linum)++; line = *p; while(**p != '\n' && **p != '\0') (*p)++; if(**p == '\0') @@ -32,19 +34,20 @@ nextline(char **p) } Slide * -nextslide(char **p) +nextslide(char **p, int *linum) { char *cmd, *arg, *line1, *line, *lineN; - int nlines, blines, i; + int nlines, blines, i, slinum; Slide *s; while(1){ - if((cmd = nextline(p)) == nil) + if((cmd = nextline(p, linum)) == nil) return nil; if(cmd[0] != '%') continue; break; } + slinum = *linum; cmd++; arg = cmd; @@ -52,10 +55,14 @@ nextslide(char **p) while(*arg != ' ' && *arg != '\t' && *arg != '\0') arg++; if(*arg == '\0') arg = nil; - else + else{ *(arg++) = '\0'; + while(*arg == ' ' && *arg == '\t' && *arg != '\0') arg++; + if(*arg == '\0') + arg = nil; + } - line1 = nextline(p); + line1 = nextline(p, linum); if(line1 != nil && *line1 == '%'){ *p = line1; line1[strlen(line1)] = '\n'; @@ -65,6 +72,7 @@ nextslide(char **p) s = malloc(sizeof(Slide)); s->cmd = cmd; s->arg = arg; + s->linum = slinum; s->nlines = 0; return s; } @@ -72,7 +80,7 @@ nextslide(char **p) nlines = 1; blines = 0; - while((line = nextline(p)) != nil){ + while((line = nextline(p, linum)) != nil){ if(*line == '\0'){ blines++; continue; @@ -93,6 +101,7 @@ nextslide(char **p) s->cmd = cmd; s->arg = arg; + s->linum = slinum; s->nlines = nlines; line = line1; @@ -105,23 +114,53 @@ nextslide(char **p) return s; } +#pragma varargck argpos checkerr 2 +void +checkerr(Slide *s, char *msg, ...) +{ + va_list args; + + va_start(args, msg); + + fprint(2,"%s:%d: %s: ", file, s->linum, s->cmd); + vfprint(2,msg, args); + fprint(2,"\n"); +} void checkfile(void) { - int i; + int waserr, linum; char *c2, *p; Slide *s; + waserr = 0; + linum = 0; + c2 = strdup(contents); p = c2; - while((s = nextslide(&p)) != nil){ - print("Slide: %s (%d lines)\n", s->cmd, s->nlines); - if(s->arg != nil) - print("\targ: %s\n", s->arg); - for(i = 0; i < s->nlines; i++) - print("\tline %d: %s\n", i, s->lines[i]); + while((s = nextslide(&p, &linum)) != nil){ + if(strcmp(s->cmd, "") == 0) + continue; + else if(strcmp(s->cmd, "bullet") == 0) + continue; + else if(strcmp(s->cmd, "blank") == 0) + continue; + else if(strcmp(s->cmd, "text") == 0) + continue; + else if(strcmp(s->cmd, "title") == 0){ + if(s->arg == nil){ + waserr = 1; + checkerr(s, "missing arg"); + } + }else{ + waserr = 1; + checkerr(s, "unknown cmd"); + } } + + if(waserr) + exits("checkfile"); } void