📄 import.c
字号:
/*--------------------------------------------------------------------*/
if ((s[0] >= 'A') && (s[0] <= 'Z') && (s[1] == '.'))
{
*next++ = *s; /* Copy the input character */
*next++ = '/'; /* Add the sub-directory indicator too */
s += 2; /* Step input string past the copied
data */
}
while( remlen > 0 )
{
if (equaln(remote,s,remlen))
break;
remlen--;
}
while( nodelen > 0 )
{
if (equaln(E_nodename,s,nodelen))
break;
nodelen--;
}
if (nodelen > remlen )
{
remlen = 0;
s += nodelen;
}
else {
nodelen = 0;
s += remlen;
}
*next = '\0'; /* Terminate first part of host string */
/*--------------------------------------------------------------------*/
/* Create a binary number which represents our file name */
/*--------------------------------------------------------------------*/
for (subscript = 0; subscript < MAX_DIGITS; subscript++ )
number[subscript] = 0; /* Initialize number to zero */
add(number, nodelen + remlen * HOSTLEN, MAX_DIGITS);
/* Append host name info to the
front of the converted string */
while( (*s != '\0') && (*number == '\0'))
{
mult(number, range, MAX_DIGITS); /* Shift the number over */
add(number, *s++ - UNIX_START_C , MAX_DIGITS);
/* Add in new low order */
} /* while */
/*-------------------------------------------------------------------*/
/* We now have stripped off the leading x. and host name, if any; */
/* now, convert the remaining characters in the name by doing a */
/* range to charset base conversion. */
/*-------------------------------------------------------------------*/
out = &tempname[FILENAME_MAX];
*--out = '\0'; /* Terminate the string we will build */
/*--------------------------------------------------------------------*/
/* Here's the loop to actually do the base conversion */
/*--------------------------------------------------------------------*/
while(adiv( number, charsetsize, &subscript, MAX_DIGITS))
*--out = E_charset[ subscript ];
/*--------------------------------------------------------------------*/
/* The conversion is done; now squeeze it into an 11 character */
/* MS-DOS name with period. */
/*--------------------------------------------------------------------*/
ImportName( next, out, charsetsize, longname );
}
else { /* Not file for spooling directory, convert it */
char *in = (char *) canon;
boolean longname ;
printmsg(4,"importpath: Checking file system for file %s",
canon );
longname = advancedFS( canon );
if ( ValidDOSName( canon, longname ))
{
strcpy( local, canon );
return;
}
/*--------------------------------------------------------------------*/
/* Handle leading drive letter (ignore it, assuming valid) */
/*--------------------------------------------------------------------*/
if ( isalpha( *in ) && (in[1] == ':'))
{
*out++ = *in++; /* The drive letter */
*out++ = *in++; /* The colon making it a driver letter */
} /* if */
if ( *in == '/' ) /* Absolute path name? */
*out++ = *in++; /* Yes, step past it */
while( *in == '/') /* Additional slashes? */
in++; /* Skip them, they mean nothing */
s = strchr( in, '/' ); /* Get end of next path segment */
/*--------------------------------------------------------------------*/
/* Now convert each simple name in the path */
/*--------------------------------------------------------------------*/
while ( *in )
{
if ( s != NULL )
*s = '\0'; /* Truncate input string to simple name */
ImportName( out, in , charsetsize, longname );
if ( s == NULL )
break;
out = out + strlen( out );
*out++ = *s++ = '/'; /* Restore path to input and output */
in = s; /* Remember start of this simple name */
while( *in == '/') /* Additional slashes? */
in++; /* Skip them, they mean nothing */
s = strchr( in , '/' );
}
} /* else */
printmsg( 3, "ImportPath: Mapped %s to %s", canon, local );
} /*importpath*/
/*--------------------------------------------------------------------*/
/* I m p o r t N a m e */
/* */
/* Translate a simple DOS name without the path */
/*--------------------------------------------------------------------*/
static void ImportName( char *local,
const char *canon,
size_t charsetsize,
const boolean longname )
{
char *in = (char *) canon;
char *out = local;
size_t len = strlen( canon );
size_t column;
char *best_period = NULL; /* Assume no prince charming */
if ( strchr(canon,'/') != NULL )
{
printmsg(0,"ImportName: Parameter error, not simple name: %s",
canon);
panic();
}
if ( len == 0 )
{
printmsg(0,"ImportName: Parameter error, zero length input");
panic();
}
/*--------------------------------------------------------------------*/
/* If a valid DOS name, use it as-is */
/*--------------------------------------------------------------------*/
if (ValidDOSName( canon, longname ))
{
strcpy( local, canon );
return;
}
/*--------------------------------------------------------------------*/
/* If the dataset name has a period, use it. The rule we */
/* follow is use the last period in the second through ninth */
/* characters, otherwise use the last period in the dataset */
/* name with the exception of leading period. */
/* */
/* In any case, we only copy up to eight characters for the */
/* dataset name and up to three characters for the extension. */
/*--------------------------------------------------------------------*/
for ( column = 1; (column < 9) && (in[column] != '\0') ; column++)
{
if ( in[column] == '.')
{
strncpy( out, in, column + 5 );
/* Period, 3 char extension,
and terminating \0 */
best_period = &out[column];/* Remember output location of
period in name */
if ( len > (column + 4) ) /* Need to trunc extension to 3? */
strcpy( out + column + 1, in + len - 3 ); /* Yes */
break;
} /*if */
} /* if */
/*--------------------------------------------------------------------*/
/* No period in the first eight characters, search the rest of */
/* the name for the last period (unless period is very last */
/* character in the string). */
/*--------------------------------------------------------------------*/
if ( best_period == NULL )
{
strncpy( out , in , 8);
best_period = strrchr( in+1 , '.');
if ( (best_period != NULL) && (best_period[1] != '\0') )
{
strncpy( &out[8], best_period, 4 ); /* Plus period and 3
in extension */
if ( strlen( best_period) > 4 ) /* Long Extension? */
out[12] = '\0'; /* Yes --> Truncate */
} /* if */
else { /* No periods at all, generate one
if needed for long name */
if ( len > 8 )
{
out[8] = '.';
strcpy(&out[9], in + max(8,(len - 3)) );
} /* if ( len > 9 ) */
} /* else */
best_period = &out[8]; /* Remember location of
period, okay if past
end of string */
} /* if ( best_period == NULL ) */
/*--------------------------------------------------------------------*/
/* Now, clean up any invalid characters */
/*--------------------------------------------------------------------*/
if ( out[ strlen( out ) - 1 ] == '.' ) /* Trailing period? */
out[ strlen( out ) - 1 ] = '\0'; /* Just truncate string */
while( *out != '\0')
{
int c ;
if ( isupper( *out ))
c = tolower( *out );
else
c = *out;
if ((out != best_period) && (strchr( E_charset, c ) == NULL ))
{
if ( c > 'z' )
c -= 62;
else if ( c > 'Z' )
c -= 36;
else if ( c > '9' )
c -= 10;
*out = E_charset[ (c - UNIX_START_C) % charsetsize ];
}
out++; /* Step to next character */
} /* while( *out != '\0') */
/*--------------------------------------------------------------------*/
/* Report our results and return */
/*--------------------------------------------------------------------*/
printmsg( 5,
"ImportName: Mapped %s to %s", canon, local );
} /* ImportName */
/*--------------------------------------------------------------------*/
/* V a l i d D O S N a m e */
/* */
/* Validate an MS-DOS file name */
/*--------------------------------------------------------------------*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -