# HG changeset patch # User viric@llimona # Date 1147985814 -7200 # Node ID cb8aa6a22086c784ceecac5823987047b5fcd3f1 Init from svn. diff -r 000000000000 -r cb8aa6a22086 Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Makefile Thu May 18 22:56:54 2006 +0200 @@ -0,0 +1,2 @@ +tabstops: tabstops.c + gcc -o tabstops -g -Wall tabstops.c diff -r 000000000000 -r cb8aa6a22086 README --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/README Thu May 18 22:56:54 2006 +0200 @@ -0,0 +1,26 @@ +'tabstops' is a program that translates a file with columns separated by +"visually correct" spaces to a file with columns separated by one TAB character. +It is supposed that there isn't any TAB character in the input file. + +Input file is 'stdin', and output is 'stdout'. +The parameters are the column position of the 2nd, 3rd, 4th, ... columns. + + +For example: + +Player Goals +John 2 +Hilbert 25 + +is translated to (using 'tabstops 11'): + +Player Goals +John 2 +Hilbert 25 + + +---- New Feature + +If you add the parameter "-r", then the reverse action is performed. You have a +file with columns separated with TAB characters, and you get a file with columns +separated by spaces at the position you asked for. diff -r 000000000000 -r cb8aa6a22086 tabstops.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tabstops.c Thu May 18 22:56:54 2006 +0200 @@ -0,0 +1,118 @@ +#include +#include + + +#define MAXTABSTOPS 50 +#define MAXLINECHARS 10000 + + +void strpart(char * dest, const char *src, const int begin, const int end) +{ + int i; + i=begin; + while (i<=end) + { + dest[i-begin] = src[i]; + i++; + } + + dest[i-begin] = '\0'; +} + +int main(int numarg, char **args) +{ + int tabstops[MAXTABSTOPS+1]; + int i,j; + char original[MAXLINECHARS]; + char word[MAXLINECHARS]; + int this_tab_stop; + int last_char; + int reverse=0; /* Funcionament normal */ + int num_tab_stops; + int output_column; + + + if (numarg<2) + { + printf("Bad Usage.\n"); + exit(1); + } + + tabstops[0] = 0; + tabstops[numarg] = MAXLINECHARS; + num_tab_stops = 1; + + for (i=1; i