fix: make hw2 code compileable

This commit is contained in:
Renge 2022-03-02 18:26:02 -05:00
parent e947b81e43
commit fceb33dbc1
3 changed files with 10 additions and 5 deletions

View File

@ -3,5 +3,5 @@
extern int original_main(int argc, const char *const *argv);
int main(int argc, const char *const *argv) {
original_main(argc, argv);
return original_main(argc, argv);
}

View File

@ -213,6 +213,7 @@ static void setdefaults(
numlines = line - inlines;
if (*pprefix < 0)
{
if (numlines <= *phang + 1)
*pprefix = 0;
else {
@ -224,8 +225,10 @@ static void setdefaults(
}
*pprefix = end - start;
}
}
if (*psuffix < 0)
{
if (numlines <= 1)
*psuffix = 0;
else {
@ -242,6 +245,7 @@ static void setdefaults(
*psuffix = end - start;
}
}
}
static void freelines(char **lines)
@ -257,7 +261,7 @@ static void freelines(char **lines)
}
main(int argc, const char * const *argv)
int original_main(int argc, const char * const *argv)
{
int width, widthbak = -1, prefix, prefixbak = -1, suffix, suffixbak = -1,
hang, hangbak = -1, last, lastbak = -1, min, minbak = -1, c;
@ -333,8 +337,8 @@ parcleanup:
if (*errmsg) {
fprintf(stderr, "%.163s", errmsg);
exit(EXIT_FAILURE);
return(EXIT_FAILURE);
}
exit(EXIT_SUCCESS);
return(EXIT_SUCCESS);
}

View File

@ -12,6 +12,7 @@
#include "buffer.h" /* Also includes <stddef.h>. */
#include "errmsg.h"
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
@ -192,7 +193,7 @@ char **reformat(const char * const *inlines, int width,
for (end = *line; *end; ++end);
if (end - *line < affix) {
sprintf(errmsg,
"Line %d shorter than <prefix> + <suffix> = %d + %d = %d\n",
"Line %ld shorter than <prefix> + <suffix> = %d + %d = %d\n",
line - inlines + 1, prefix, suffix, affix);
goto rfcleanup;
}