1 /*****************************************************************************
2 * AreaFix for HPT (FTN NetMail/EchoMail Tosser)
3 *****************************************************************************
4 * Copyright (C) 2000
5 *
6 * Lev Serebryakov
7 *
8 * Fido: 2:5030/661
9 * Internet: lev@serebryakov.spb.ru
10 * St.Petersburg, Russia
11 *
12 * This file is part of HTICK.
13 *
14 * HTICK is free software; you can redistribute it and/or modify it
15 * under the terms of the GNU General Public License as published by the
16 * Free Software Foundation; either version 2, or (at your option) any
17 * later version.
18 *
19 * HPT is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with HPT; see the file COPYING. If not, write to the Free
26 * Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
27 *****************************************************************************
28 * $Id$
29 *****************************************************************************/
30
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <string.h>
34 #include <sys/types.h>
35 #include <sys/stat.h>
36 #include <ctype.h>
37
38 /* compiler.h */
39 #include <huskylib/compiler.h>
40
41 #ifdef HAS_UNISTD_H
42 # include <unistd.h>
43 #endif
44
45 /* smapi */
46
47 /* fidoconf */
48 #include <fidoconf/common.h>
49
50 #include <areafix/areafix.h>
51
52 /* htick */
53 #include <global.h>
54 #include <filecase.h>
55
dosallowin83(int c)56 static int dosallowin83( int c )
57 {
58 static char dos_allow[] = "!@#$%^&()~`'-_{}.";
59
60 if( ( c >= 'a' && c <= 'z' ) ||
61 ( c >= 'A' && c <= 'Z' ) || ( c >= '0' && c <= '9' ) || strchr( dos_allow, c ) )
62 return 1;
63 return 0;
64 }
65
66
isDOSLikeName(char * name)67 int isDOSLikeName( char *name )
68 {
69 int nl, el, ec, uc, lc, f;
70 char *p = name;
71
72 if( !name )
73 {
74 w_log( LL_CRIT,
75 __FILE__
76 ":: Parameter is NULL: isDOSLikeName(%s). This is serious error in program, please report to developers.",
77 name ? "name" : "NULL" );
78 return 0; /* false */
79 }
80
81 nl = el = ec = uc = lc = 0;
82 f = 1;
83 while( *p )
84 {
85 if( !dosallowin83( *p ) )
86 {
87 f = 0;
88 break;
89 }
90 if( '.' == *p )
91 ec++;
92 else
93 {
94 if( !ec )
95 nl++;
96 else
97 el++;
98 if( isalpha( *p ) )
99 {
100 if( isupper( *p ) )
101 uc++;
102 else
103 lc++;
104 }
105 }
106 p++;
107 }
108 return ( f && ec < 2 && el < 4 && nl < 9 && ( !lc || !uc ) );
109 }
110
MakeProperCase(char * name)111 char *MakeProperCase( char *name )
112 {
113 if( !name )
114 {
115 w_log( LL_CRIT,
116 __FILE__
117 ":: Parameter is NULL: MakeProperCase(%s). This is serious error in program, please report to developers.",
118 name ? "name" : "NULL" );
119 return NULL;
120 }
121
122 if( isDOSLikeName( name ) )
123 {
124 switch ( config->convertShortNames )
125 {
126 case cUpper:
127 return strUpper( name );
128 case cLower:
129 return strLower( name );
130 default:
131 return name;
132 }
133 }
134 else
135 {
136 switch ( config->convertLongNames )
137 {
138 case cUpper:
139 return strUpper( name );
140 case cLower:
141 return strLower( name );
142 default:
143 return name;
144 }
145 }
146 }
147