<commit_before>#include <stdlib.h>
#include <stdio.h>
#include <wiringPi.h>
#include <piGlow.h>
#include <string.h>
#include <errno.h>
#include "flow.h"

void usage(char* name);
void error(const char* message, int code);
byte temperbrightness(int input);
int legmode = 0;
int ringmode = 0;
int allowdelay = 1;
int delayamount = 5;
int brightnesscap = 10;
int outward = 0;
int main(int argc, char* argv[]) {
   char* line;
   char* tmpline;
   FILE* file;
   int needsclosing, last, i, errorfree;
   FlowContainer container;
   container.cells = 0;
   container.count = 0;
   line = 0;
   file = 0;
   last = argc - 1;
   tmpline = 0;
   needsclosing = 0;
   errorfree = 1;
   if(argc > 1) {
      for(i = 1; errorfree && (i < last); ++i) {
         tmpline = argv[i];
         if(strlen(tmpline) == 2 && tmpline[0] == '-') {
            switch(tmpline[1]) {
               case 'l':
                  if(ringmode == 0) {
                     legmode = 1;
                  } else {
                     fprintf(stderr, "error: %s\n", "can't do both leg and ring mode");
                     errorfree = 0;
                  }
                  break;
               case 'r':
                  if(legmode == 0) {
                     ringmode = 1;
                  } else {
                     fprintf(stderr, "error: %s\n", "can't do both leg and ring mode");
                     errorfree = 0;
                  }
                  break;
               case 'u':
                  outward = 1;
                  break;
               case 'n':
                  allowdelay = 0;
                  break;
               default:
                  errorfree = 0;
                  break;
            }
         } else {
            errorfree = 0;
            break;
         }
      }
      if(errorfree) {
         line = argv[last];
         if(strlen(line) == 1 && line[0] == '-') {
            file = stdin;
         } else if(strlen(line) >= 1 && line[0] != '-') {
            file = fopen(line, "r");
            if(!file) {
               fprintf(stderr, "couldn't open %s\n", line);
               exit(errno);
            }
            needsclosing = 1;
         }
      }
   }

   if(file) {
      setup(&container);
      decode(&container, file);<commit_msg>Added brightness and delay options<commit_after>#include <stdlib.h>
#include <stdio.h>
#include <wiringPi.h>
#include <piGlow.h>
#include <string.h>
#include <errno.h>
#include "flow.h"

void usage(char* name);
void error(const char* message, int code);
byte temperbrightness(int input);
int legmode = 0;
int ringmode = 0;
int allowdelay = 1;
int delayamount = 5;
int brightnesscap = 10;
int outward = 0;
int main(int argc, char* argv[]) {
   char* line;
   char* tmpline;
   FILE* file;
   int needsclosing, last, i, errorfree;
   FlowContainer container;
   long tmp0;
   container.cells = 0;
   container.count = 0;
   line = 0;
   file = 0;
   last = argc - 1;
   tmpline = 0;
   needsclosing = 0;
   errorfree = 1;
   tmp0 = 0L;
   if(argc > 1) {
      for(i = 1; errorfree && (i < last); ++i) {
         tmpline = argv[i];
         if(strlen(tmpline) == 2 && tmpline[0] == '-') {
            switch(tmpline[1]) {
               case 'b': 
                  {
                     ++i;
                     tmp0 = strtol(argv[i], NULL, 10);
                     if(errno == EINVAL) {
                        fprintf(stderr, "error: invalid brightness '%s' provided\n", argv[i]);
                        errorfree = 0;
                     } else if(errno == ERANGE) {
                        fprintf(stderr, "error: provided brightness: '%s'  is out of range\n", argv[i]);
                        errorfree = 0;
                     } else {
                        if(tmp0 < 0 || tmp0 > 255) {
                           fprintf(stderr, "error: provided brightness: %d is out of range\n", tmp0);
                           errorfree = 0;
                        } else {
                           brightnesscap = tmp0;
                        }
                     }
                     break;
                  }
               case 'd':
                  {
                     ++i;
                     tmp0 = strtol(argv[i], NULL, 10);
                     if(errno == EINVAL) {
                        fprintf(stderr, "error: invalid delay '%s' provided\n", argv[i]);
                        errorfree = 0;
                     } else if(errno == ERANGE) {
                        fprintf(stderr, "error: provided delay '%s' is out of range\n", argv[i]);
                        errorfree = 0;
                     } else {
                        if(tmp0 < 0) {
                           fprintf(stderr, "error: can't provide a negative delay\n");
                           errorfree = 0;
                        } else {
                           delayamount = tmp0;
                        }
                     }
                     break;

                  }
               case 'l':
                  {
                     if(ringmode == 0) {
                        legmode = 1;
                     } else {
                        fprintf(stderr, "error: %s\n", "can't do both leg and ring mode");
                        errorfree = 0;
                     }
                     break;
                  }
               case 'r':
                  {
                     if(legmode == 0) {
                        ringmode = 1;
                     } else {
                        fprintf(stderr, "error: %s\n", "can't do both leg and ring mode");
                        errorfree = 0;
                     }
                     break;
                  }
               case 'u':
                  outward = 1;
                  break;
               case 'n':
                  allowdelay = 0;
                  break;
               default:
                  errorfree = 0;
                  break;
            }
         } else {
            errorfree = 0;
            break;
         }
      }
      if(errorfree) {
         if(i == last) {
            line = argv[last];
            if(strlen(line) == 1 && line[0] == '-') {
               file = stdin;
            } else if(strlen(line) >= 1 && line[0] != '-') {
               file = fopen(line, "r");
               if(!file) {
                  fprintf(stderr, "couldn't open %s\n", line);
                  exit(errno);
               }
               needsclosing = 1;
            }
         } else {
            fprintf(stderr, "no file provided\n");
         }
      }
   }

   if(file) {
      setup(&container);
      decode(&container, file);
{'fraction_non_alphanumeric': 0.11993957703927492, 'fraction_numerical': 0.014501510574018127, 'mean_word_length': 1.005755831566192, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3879803', 'n_tokens_mistral': 1972, 'n_tokens_neox': 1803, 'n_words': 475}