I'm writing a Cat program and my program is pretty much coming together but I'm having trouble with the order of flags in command line. Like for example when I
./cat -Es test.txt my program puts the dollar sign at the end of each line but then my line squeeze doesn't work and it's because my squeeze was written to detect '\n' at the front of my line buf. When i ./cat -sE test.txt it supresses repeated lines and prints '$' at the end of each line. So my question is, is there a way i can make certain flags Priority over other flags so when i type ./cat -Es test.txt in the command line my program with in essence switch the -Es around to -sE? If you need me to clear up anything in here please ask.
P.S. I have tried checking for '$' in my squeeze method and it didn't work out
here is where my getopts is
Code:
while( fgets(buf, 1500, fptr) != NULL)
{
while((choice = getopt ( argc, argv, "AbeEnstTuv")) != -1)
{
switch(choice)
{
case 'A': /*Shows all equivalent to -vET*/
case_A( buf );
break;
case 'b': /*number non-blank output lines*/
case_b(buf, &counter_b, tmp);
break;
case 'e':
printf("equivalent to -vE\n");
break;
case 'E': /*adds '$' to the end of every line*/
case_E( buf );
printf("\n");
break;
case 'n': /*numbers all output lines*/
case_n( buf, &counter_n, tmp );
break;
case 's': /*suppress repeated empty output lines */
case_s( buf , &counter_s, fptr);
break;
case 't':
printf("equivalent to -vT\n");
break;
case 'T': /*display TAB character as ^I*/
case_T( buf );
break;
case 'u': /*ignored*/
break;
case 'v':
case_v( buf, fptr );
break;
}
}
optind = 1;
printf("%s", buf);
}
./cat -Es test.txt
Code:
[cat]$ ./cat -Es test.txt
This is a test of how cat works.$
Some characters like tab need to be replaced.$
$
Others don't, and line numbering can be trickier than you think.$
Even more so when you have the -s flag on.$
$
Test 1$
$
Test 2$
$
$
Test 3$
$
$
$
Test 4$
$
$
$
$
$
./cat -sE test.txt << this is what i want it to do >>
Code:
[cat]$ ./cat -sE test.txt
This is a test of how cat works.$
Some characters like tab need to be replaced.$
$
Others don't, and line numbering can be trickier than you think.$
Even more so when you have the -s flag on.$
$
Test 1$
$
Test 2$
$
Test 3$
$
Test 4$
$