2017-01-16 16:28:12 -05:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2017 Brian Barto
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
2017-02-17 13:24:11 -05:00
|
|
|
* under the terms of the GPL License. See LICENSE for more details.
|
2017-01-16 16:28:12 -05:00
|
|
|
*/
|
|
|
|
|
2016-04-18 12:00:57 -04:00
|
|
|
#include <stdio.h>
|
2016-04-18 18:39:56 -04:00
|
|
|
#include <stdlib.h>
|
2016-05-01 17:09:38 -04:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <ctype.h>
|
2017-01-19 11:17:40 -05:00
|
|
|
#include "nmseffect.h"
|
|
|
|
|
2017-02-19 13:29:28 -05:00
|
|
|
#define VERSION "0.3.2"
|
2017-01-19 11:17:40 -05:00
|
|
|
#define INPUT_GROWTH_FACTOR 2
|
|
|
|
|
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
int c, o, inSize = 0, inCapacity = 0;
|
|
|
|
char *input = NULL;
|
|
|
|
|
|
|
|
// Processing command arguments
|
|
|
|
while ((o = getopt(argc, argv, "f:acv")) != -1) {
|
|
|
|
switch (o) {
|
|
|
|
case 'f':
|
|
|
|
nmseffect_set_foregroundcolor(optarg);
|
|
|
|
break;
|
|
|
|
case 'a':
|
2017-01-19 11:20:53 -05:00
|
|
|
nmseffect_set_autodecrypt(1);
|
2017-01-19 11:17:40 -05:00
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
nmseffect_set_clearscr(1);
|
|
|
|
break;
|
|
|
|
case 'v':
|
|
|
|
printf("nms version " VERSION "\n");
|
|
|
|
return 0;
|
|
|
|
case '?':
|
|
|
|
if (isprint(optopt))
|
|
|
|
fprintf (stderr, "Unknown option '-%c'.\n", optopt);
|
|
|
|
else
|
|
|
|
fprintf (stderr, "Unknown option character '\\x%x'.\n", optopt);
|
|
|
|
return 1;
|
2017-01-16 16:28:12 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-19 11:17:40 -05:00
|
|
|
// Geting input
|
|
|
|
while ((c = getchar()) != EOF) {
|
|
|
|
++inSize;
|
|
|
|
if (inSize > inCapacity) {
|
|
|
|
inCapacity = inCapacity == 0 ? INPUT_GROWTH_FACTOR : inCapacity * INPUT_GROWTH_FACTOR;
|
|
|
|
input = realloc(input, inCapacity + 1);
|
2017-01-16 16:28:12 -05:00
|
|
|
}
|
2017-01-19 11:17:40 -05:00
|
|
|
input[inSize - 1] = c;
|
|
|
|
input[inSize] = '\0';
|
2017-01-16 16:28:12 -05:00
|
|
|
}
|
|
|
|
|
2017-01-19 11:17:40 -05:00
|
|
|
// Execute effect
|
|
|
|
c = nmseffect_exec(input);
|
2017-01-16 16:28:12 -05:00
|
|
|
|
2017-01-19 14:51:21 -05:00
|
|
|
// Free allocated memory (not necessary here, but good practice)
|
2017-01-19 11:17:40 -05:00
|
|
|
free(input);
|
2017-01-16 16:28:12 -05:00
|
|
|
|
2017-01-19 11:17:40 -05:00
|
|
|
return 0;
|
2017-01-16 16:28:12 -05:00
|
|
|
}
|