Skip to content

Commit 31af009

Browse files
ralismarkshlomif
authored andcommitted
Re-implement BSD-style -o suffix support
1 parent 50f4c57 commit 31af009

File tree

1 file changed

+30
-12
lines changed

1 file changed

+30
-12
lines changed

fortune-mod/fortune/fortune.c

+30-12
Original file line numberDiff line numberDiff line change
@@ -1019,10 +1019,23 @@ static int form_file_list(char **files, int file_cnt)
10191019
sp = files[i];
10201020
}
10211021
}
1022+
1023+
/* BSD-style '-o' offensive file suffix */
1024+
bool offensive = false;
1025+
const size_t sp_len = strlen(sp);
1026+
if (sp_len >= 3 && sp[sp_len - 2] == '-' && sp[sp_len - 1] == 'o')
1027+
{
1028+
sp[sp_len - 2] = '\0';
1029+
offensive = true;
1030+
}
1031+
1032+
const char* fulldir = offensive ? OFFDIR : FORTDIR;
1033+
const char* locdir = offensive ? LOCOFFDIR : LOCFORTDIR;
1034+
10221035
if (strcmp(sp, "all") == 0)
10231036
{
1024-
snprintf(fullpathname, sizeof(fullpathname), "%s", FORTDIR);
1025-
snprintf(locpathname, sizeof(locpathname), "%s", LOCFORTDIR);
1037+
snprintf(fullpathname, sizeof(fullpathname), "%s", fulldir);
1038+
snprintf(locpathname, sizeof(locpathname), "%s", locdir);
10261039
}
10271040
/* if it isn't an absolute path or relative to . or ..
10281041
make it an absolute path relative to FORTDIR */
@@ -1032,9 +1045,9 @@ static int form_file_list(char **files, int file_cnt)
10321045
strncmp(sp, "../", 3) != 0)
10331046
{
10341047
snprintf(
1035-
fullpathname, sizeof(fullpathname), "%s/%s", FORTDIR, sp);
1048+
fullpathname, sizeof(fullpathname), "%s/%s", fulldir, sp);
10361049
snprintf(
1037-
locpathname, sizeof(locpathname), "%s/%s", LOCFORTDIR, sp);
1050+
locpathname, sizeof(locpathname), "%s/%s", locdir, sp);
10381051
}
10391052
else
10401053
{
@@ -1063,7 +1076,7 @@ static int form_file_list(char **files, int file_cnt)
10631076

10641077
/* first try full locale */
10651078
snprintf(
1066-
langdir, sizeof(langdir), "%s/%s/%s", FORTDIR, lang, sp);
1079+
langdir, sizeof(langdir), "%s/%s/%s", fulldir, lang, sp);
10671080
ret = add_file(
10681081
percent, langdir, NULL, &File_list, &File_tail, NULL);
10691082

@@ -1075,7 +1088,7 @@ static int form_file_list(char **files, int file_cnt)
10751088
strncpy(ll, lang, 2);
10761089
ll[2] = '\0';
10771090
snprintf(
1078-
langdir, sizeof(langdir), "%s/%s/%s", FORTDIR, ll, sp);
1091+
langdir, sizeof(langdir), "%s/%s/%s", fulldir, ll, sp);
10791092
ret = add_file(
10801093
percent, langdir, NULL, &File_list, &File_tail, NULL);
10811094
}
@@ -1094,8 +1107,19 @@ static int form_file_list(char **files, int file_cnt)
10941107
ret = add_file(
10951108
percent, locpathname, NULL, &File_list, &File_tail, NULL);
10961109
}
1110+
if (strncmp(fullpathname, locpathname, sizeof(fullpathname)) &&
1111+
strcmp(sp, "all") == 0)
1112+
{
1113+
add_file(
1114+
percent, locpathname, NULL, &File_list, &File_tail, NULL);
1115+
}
10971116
if (!ret)
10981117
{
1118+
if (offensive)
1119+
{
1120+
// restore -o suffix
1121+
sp[sp_len - 2] = '-';
1122+
}
10991123
snprintf(locpathname, sizeof(locpathname), "%s/%s",
11001124
getenv("PWD"), sp);
11011125

@@ -1106,12 +1130,6 @@ static int form_file_list(char **files, int file_cnt)
11061130
{
11071131
return false;
11081132
}
1109-
if (strncmp(fullpathname, locpathname, sizeof(fullpathname)) &&
1110-
strcmp(sp, "all") == 0)
1111-
{
1112-
add_file(
1113-
percent, locpathname, NULL, &File_list, &File_tail, NULL);
1114-
}
11151133
}
11161134
else if (!add_file(
11171135
percent, fullpathname, NULL, &File_list, &File_tail, NULL))

0 commit comments

Comments
 (0)