Cover V05, I02
Article
Listing 1
Sidebar 1

feb96.tar


Sidebar: Corrections

Please note the following corrections to the article "Converting Unix Filenames to MS-DOS" (Sys Admin 5(2): 81-85) by Ed Schaefer and Fred Brunet. The editors regret these errors and apologize for any inconvenience.

The authors have made the following changes. Sharp-eyed reader, Edward Hooper, had a problem with commas being changed within double quotes. Here is an example:

"0001","Another, String"

The program should change it to:

0001|Another, String|

not

0001|Another| String"

In order to fix this problem, here are the changes:

1) In the process_data_file make this change:

if(conv_ch == 1)
token = xstrtok(buf, PIPE_SYMBOL, "");
else
token = xstrtok(buf, COMMA, "\"");
.
.
if(conv_ch == 1)
token = xstrtok(NULL, PIPE_SYMBOL, "");
else
token = xstrtok(NULL, COMMA, "\"");

2) A replacement is needed for the strcspn() function in the xstrtok function. In the xstrtok() function, replace:

n = strcspn(saveline, delims);

with:

n = strccspn(saveline, delims, except);

And here is the function:

/* replacement function for strcspn(). except is generally a double quote and it becomes the new delimiter. When another except is found, change back to the original delimiter */

int strccspn(s1, s2, except)
char *s1, *s2, *except;
{ /*s2 is the delimiter */
char *sc1, *sc2, *olds2;
int found = 0;

for (sc1 = s1; *sc1 != '\0'; ++sc1)
{
if(strchr (except, *sc1) != NULL)
/* this is a possible double quote */
if(!found)
{
found++;
olds2=s2;   /* save old delimiter */
s2=except;  /* change to the except delimiter */
sc1++;
}
for(sc2 = s2; *sc2 !='\0'; ++sc2)
if (strchr (sc2, *sc1) != NULL)
{
if(found)
{
s2=olds2;
/* change back to the original delimiter */
found = !found;
}
else
return (sc1 - s1);
}
}
return (sc1 - s1);
}

Next, I've had some problems with unexplained core dumps when adding a third argument to the xstrtok() function. I finally tracked it down to the string copies in the del_char() function corrupting the stack. I replaced it with this:

/*
* This function deletes char 'c' from 'string'
*/
void del_char(string, c)
char *string;
char *c;
{
inti,j;

for(i=j=0; string[i]; i++)
if (string[i] != *c)
string[j++] = string[i];

string[j] = 0x00;
}