summaryrefslogtreecommitdiff
path: root/src/main.c
blob: b3f7d69ccda92bba65b2f548be358652bc5bcf87 (plain)
    1 #include <stdio.h>
    2 #include <stdlib.h>
    3 #include <string.h>
    4 
    5 #ifndef LINE_BUF_SIZE
    6   #define LINE_BUF_SIZE 1024
    7 #endif
    8 
    9 #ifndef QUOTE_CHAR
   10   #define QUOTE_CHAR '>'
   11 #endif
   12 
   13 
   14 void fix_line(char* out, char* line) {
   15   int cursor;
   16   int fixcursor;
   17 
   18   // Initialize
   19   out[0] = '\0';
   20 
   21   // Reset the cursors
   22   cursor = 0;
   23   fixcursor = 0;
   24 
   25   // One char at a time...
   26   while(line[cursor] != '\0') {
   27     if(line[cursor] != QUOTE_CHAR) {
   28       // As soon as we stop finding > chars, copy the rest and break;
   29       strcpy(&out[fixcursor], &line[cursor]);
   30       break;
   31     } else {
   32       out[fixcursor] = QUOTE_CHAR;
   33       // If the next char isn't a space, insert one.
   34       // We don't want double-stacked spaces in case someone did format
   35       // something correctly.
   36       if(line[cursor + 1] != ' ') {
   37         fixcursor++;
   38         out[fixcursor] = ' ';
   39       }
   40     }
   41     cursor++;
   42     fixcursor++;
   43   }
   44 }
   45 
   46 
   47 int main(int argc, char* argv[]) {
   48   char buf[LINE_BUF_SIZE];
   49   char fixbuf[LINE_BUF_SIZE];
   50 
   51   while(fgets(buf, LINE_BUF_SIZE, stdin) != NULL) {
   52     fix_line(fixbuf, buf);
   53     printf("%s", fixbuf);
   54   }
   55   return 0;
   56 }

Generated by cgit