8 int main(int argc, char **argv)
10 int opt = -1, min_len = 0, max_len = 0;
11 char ofile[256], fchar[2], tchar[2];
15 while((opt = getopt(argc, argv, "o:f:t:l:L:")) != -1)
20 strncpy(ofile, optarg, 255);
23 strncpy(fchar, optarg, 1);
26 strncpy(tchar, optarg, 1);
29 min_len = atoi(optarg);
32 max_len = atoi(optarg);
35 printf("usage: %s -oftlL\n\t-o output file\n\t-f from char\n\t-t to char\n\t-l min seq len\n\t-L max seq len", argv[0]);
40 printf("error, length must be more than 0\n");
45 printf("error, max length must be greater or equal min_length\n");
48 if((int)fchar[0] > (int)tchar[0])
50 printf("error, invalid range specified\n");
53 FILE *out = fopen(ofile, "w");
56 printf("failed to open input file with error: %s\n", strerror(errno));
59 int cur_len = min_len;
60 while(cur_len <= max_len)
63 for(int i = 0; i < cur_len; i++)
65 fwrite(buf, cur_len, 1, out);
66 fwrite("\n", 1, 1, out);
67 while(buf[0] != (tchar[0]+1))
69 while(buf[cur_len-1] < tchar[0])
71 (int)buf[cur_len-1]++;
72 fwrite(buf, cur_len, 1, out);
73 fwrite("\n", 1, 1, out);
77 if(buf[0] == tchar[0])
80 for(int i = 1; i < cur_len; i++)
82 if(buf[i] != tchar[0])
92 for(; u>=0 && buf[u] >= tchar[0]; u--)
95 for(int i = u+1; i < cur_len; i++)
97 fwrite(buf, cur_len, 1, out);
98 fwrite("\n", 1, 1, out);