diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..cc458e2 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,15 @@ +root = true +[*] +charset = utf-8 +end_of_line = lf +indent_style = space +indent_size = 4 +insert_final_newline = true +max_line_length = 120 +trim_trailing_whitespace = true + +[*.yml] +indent_size = 2 + +[{Makefile,README,*.pl,*.sh,*.l,*.h}] +indent_style = tab diff --git a/.github/workflows/mega-linter.yml b/.github/workflows/mega-linter.yml new file mode 100644 index 0000000..1fb51e4 --- /dev/null +++ b/.github/workflows/mega-linter.yml @@ -0,0 +1,62 @@ +--- +# MegaLinter GitHub Action configuration file +# More info at https://megalinter.io +name: MegaLinter + +on: + # Trigger mega-linter at every push. Action will also be visible from Pull Requests to main + push: # Comment this line to trigger action only on pull-requests (not recommended if you don't pay for GH Actions) + pull_request: + branches: [master, main] + +# env: # Comment env block if you don't want to apply fixes + # Apply linter fixes configuration + # APPLY_FIXES: all # When active, APPLY_FIXES must also be defined as environment variable (in github/workflows/mega-linter.yml or other CI tool) + # APPLY_FIXES_EVENT: pull_request # Decide which event triggers application of fixes in a commit or a PR (pull_request, push, all) + # APPLY_FIXES_MODE: commit # If APPLY_FIXES is used, defines if the fixes are directly committed (commit) or posted in a PR (pull_request) + +concurrency: + group: ${{ github.ref }}-${{ github.workflow }} + cancel-in-progress: true + +jobs: + megalinter: + name: MegaLinter + runs-on: ubuntu-latest + # permissions: + # Give the default GITHUB_TOKEN write permission to commit and push, comment issues & post new PR + # Remove the ones you do not need + # contents: write + # issues: write + # pull-requests: write + steps: + # Git Checkout + - name: Checkout Code + uses: actions/checkout@v3 + with: + token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }} + fetch-depth: 0 # If you use VALIDATE_ALL_CODEBASE = true, you can remove this line to improve performances + + # MegaLinter + - name: MegaLinter + id: ml + # You can override MegaLinter flavor used to have faster performances + # More info at https://megalinter.io/flavors/ + uses: oxsecurity/megalinter@v7 + env: + # All available variables are described in documentation + # https://megalinter.io/configuration/ + VALIDATE_ALL_CODEBASE: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} # Validates all source when push on main, else just the git diff with main. Override with true if you always want to lint all sources + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # ADD YOUR CUSTOM ENV VARIABLES HERE OR DEFINE THEM IN A FILE .mega-linter.yml AT THE ROOT OF YOUR REPOSITORY + # DISABLE: COPYPASTE,SPELL # Uncomment to disable copy-paste and spell checks + + # Upload MegaLinter artifacts + - name: Archive production artifacts + if: success() || failure() + uses: actions/upload-artifact@v3 + with: + name: MegaLinter reports + path: | + megalinter-reports + mega-linter.log diff --git a/.mega-linter.yml b/.mega-linter.yml new file mode 100644 index 0000000..815e748 --- /dev/null +++ b/.mega-linter.yml @@ -0,0 +1,15 @@ +# ENABLE: +# - ACTION +# - EDITORCONFIG +# - REPOSITORY +# - YAML + +DISABLE: +- C +- CPP +- SPELL + +DISABLE_ERRORS_LINTERS: + - MAKEFILE_CHECKMAKE + - REPOSITORY_CHECKOV + - REPOSITORY_KICS diff --git a/Makefile b/Makefile index d799340..44a8d1e 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,10 @@ # Copyright (c) 1986-2007 Purdue University # All rights reserved. -# +# # Developed by: Daniel Trinkle # Department of Computer Science, Purdue University # http://www.cs.purdue.edu/ -# +# # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal with the Software without restriction, including @@ -12,19 +12,19 @@ # distribute, sublicense, and/or sell copies of the Software, and to # permit persons to whom the Software is furnished to do so, subject to # the following conditions: -# +# # o Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimers. -# +# # o Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimers in the # documentation and/or other materials provided with the distribution. -# +# # o Neither the names of Daniel Trinkle, Purdue University, nor the # names of its contributors may be used to endorse or promote products # derived from this Software without specific prior written # permission. -# +# # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. diff --git a/detex.h b/detex.h index 2fca90b..335b8cc 100644 --- a/detex.h +++ b/detex.h @@ -1,11 +1,11 @@ /* * Copyright (c) 1986-2007 Purdue University * All rights reserved. - * + * * Developed by: Daniel Trinkle * Department of Computer Science, Purdue University * http://www.cs.purdue.edu/ - * + * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal with the Software without restriction, including @@ -13,19 +13,19 @@ * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: - * + * * o Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimers. - * + * * o Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimers in the * documentation and/or other materials provided with the distribution. - * + * * o Neither the names of Daniel Trinkle, Purdue University, nor the * names of its contributors may be used to endorse or promote products * derived from this Software without specific prior written * permission. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. diff --git a/detex.l b/detex.l index 0b0590a..e5e2477 100644 --- a/detex.l +++ b/detex.l @@ -5,11 +5,11 @@ /* * Copyright (c) 1986-2007 Purdue University * All rights reserved. - * + * * Developed by: Daniel Trinkle * Department of Computer Science, Purdue University * http://www.cs.purdue.edu/ - * + * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal with the Software without restriction, including @@ -17,19 +17,19 @@ * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: - * + * * o Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimers. - * + * * o Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimers in the * documentation and/or other materials provided with the distribution. - * + * * o Neither the names of Daniel Trinkle, Purdue University, nor the * names of its contributors may be used to endorse or promote products * derived from this Software without specific prior written * permission. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. @@ -202,7 +202,7 @@ VERBSYMBOL =|\\leq|\\geq|\\in|>|<|\\subseteq|\subseteq|\\subset|\\supset|\\sim|\ %Start Define Display IncludeOnly Input Math Normal Control %Start LaBegin LaDisplay LaEnd LaEnv LaFormula LaInclude LaSubfile -%Start LaMacro LaOptArg LaMacro2 LaOptArg2 LaVerbatim +%Start LaMacro LaOptArg LaMacro2 LaOptArg2 LaVerbatim %start LaBreak LaPicture %% @@ -214,9 +214,9 @@ VERBSYMBOL =|\\leq|\\geq|\\in|>|<|\\subseteq|\subseteq|\\subset|\\supset|\\sim|\ {S}"{"{S}"verbatim"{S}"}" { if (BeginEnv("verbatim")) BEGIN LaEnv; - else + else BEGIN LaVerbatim; - IGNORE; + IGNORE; } "\\end"{S}"{"{S}"verbatim"{S}"}" /* verbatim mode */ {BEGIN Normal; IGNORE;} @@ -224,34 +224,34 @@ VERBSYMBOL =|\\leq|\\geq|\\in|>|<|\\subseteq|\subseteq|\\subset|\\supset|\\sim|\ . ECHO; {S}"{"{S}"minipage"{S}"}" { KILLARGS(1); - if (BeginEnv("minipage")) + if (BeginEnv("minipage")) BEGIN LaEnv; - else + else BEGIN LaMacro; /* Normal; */ - IGNORE; + IGNORE; } {S}"{"{S}"table"{S}"}"{S}"["{P}"]" { - if (BeginEnv("table")) + if (BeginEnv("table")) BEGIN LaEnv; - else + else BEGIN Normal; - IGNORE; - } + IGNORE; + } {S}"{"{S}"figure"{S}"}"{S}"["{P}"]" { - if (BeginEnv("figure")) + if (BeginEnv("figure")) BEGIN LaEnv; - else + else BEGIN Normal; - IGNORE; + IGNORE; } - + {W} { if (BeginEnv(yytext)) BEGIN LaEnv; - else + else BEGIN Normal; - IGNORE; + IGNORE; } /*"\n" NEWLINE;*/ . {INCRLINENO;} @@ -262,7 +262,7 @@ VERBSYMBOL =|\\leq|\\geq|\\in|>|<|\\subseteq|\subseteq|\\subset|\\supset|\\sim|\ {W} /* end environment */ { if (EndEnv(yytext)) BEGIN Normal; - IGNORE; + IGNORE; } "}" {BEGIN LaEnv; IGNORE;} /*"\n" NEWLINE;*/ @@ -347,14 +347,14 @@ VERBSYMBOL =|\\leq|\\geq|\\in|>|<|\\subseteq|\subseteq|\\subset|\\supset|\\sim|\ ++currBracesLevel; } "\\verb" /* ignore \verb... */ { if (fLatex) { - char verbchar, c; - verbchar = input(); - while ((c = input()) != verbchar) - /*if (c == '\n') + char verbchar, c; + verbchar = input(); + while ((c = input()) != verbchar) + /*if (c == '\n') NEWLINE;*/ putchar(c); - } - IGNORE; + } + IGNORE; } "\\newcommand" { LATEX; KILLARGS(2); } @@ -393,7 +393,7 @@ VERBSYMBOL =|\\leq|\\geq|\\in|>|<|\\subseteq|\subseteq|\\subset|\\supset|\\sim|\ "\\include" /* process files */ {LaBEGIN LaInclude; IGNORE;} [^{ \t\n}]+ { IncludeFile(yytext); - BEGIN Normal; + BEGIN Normal; } "\n"+ NEWLINE; . ; @@ -402,21 +402,21 @@ VERBSYMBOL =|\\leq|\\geq|\\in|>|<|\\subseteq|\subseteq|\\subset|\\supset|\\sim|\ [^{ \t,\n}]+ AddInclude(yytext); "}" { if (csbIncList == 0) rgsbIncList[csbIncList++] = '\0'; - BEGIN Normal; + BEGIN Normal; } "\n"+ NEWLINE; . ; "\\subfile" /* process files */ {LaBEGIN LaSubfile; IGNORE;} [^{ \t\n}]+ { IncludeFile(yytext); - BEGIN Normal; + BEGIN Normal; } "\n"+ NEWLINE; . ; "\\input" {BEGIN Input; IGNORE;} [^{ \t\n}]+ { InputFile(yytext); - BEGIN Normal; + BEGIN Normal; } "\n"+ NEWLINE; . ; @@ -467,7 +467,7 @@ VERBSYMBOL =|\\leq|\\geq|\\in|>|<|\\subseteq|\subseteq|\\subset|\\supset|\\sim|\ } {W}[']*{W} { if (fWord) (void)printf("%s\n", yytext); - else + else ECHO; } [0-9]+ if (!fWord) ECHO; @@ -478,30 +478,30 @@ VERBSYMBOL =|\\leq|\\geq|\\in|>|<|\\subseteq|\subseteq|\\subset|\\supset|\\sim|\ "\[" { BEGIN LaOptArg; } "{" { cOpenBrace++; } "}""\n"{0,1} { cOpenBrace--; INCRLINENO; - if (cOpenBrace == 0) - { + if (cOpenBrace == 0) + { if (--cArgs==0) BEGIN Normal; - } + } } . ; -"\]" BEGIN LaMacro; +"\]" BEGIN LaMacro; [^\]]* ; "\[" { BEGIN LaOptArg2; } "{" { if (cOpenBrace == 0) - { + { if (--cArgs==0) { - BEGIN Normal; - cOpenBrace--; + BEGIN Normal; + cOpenBrace--; + } } - } - cOpenBrace++; + cOpenBrace++; } "}" { cOpenBrace--; } . ; -"\]" BEGIN LaMacro2; +"\]" BEGIN LaMacro2; . ; %% @@ -529,7 +529,7 @@ main(int cArgs, char *rgsbArgs[]) char *pch, sbBadOpt[2]; const char *sbEnvList = DEFAULTENV; int fSawFile = 0, iArgs = 1; - + /* get base name and decide what we are doing, detex or delatex */ #ifdef OS2 char drive[_MAX_DRIVE], dir[_MAX_DIR]; @@ -545,12 +545,12 @@ main(int cArgs, char *rgsbArgs[]) sbProgName = kpse_program_name; #else if ((sbProgName = strrchr(rgsbArgs[0], '/')) != NULL) - sbProgName++; + sbProgName++; else - sbProgName = rgsbArgs[0]; + sbProgName = rgsbArgs[0]; #endif if (strcmp("delatex",sbProgName) == 0) - fLatex = 1; + fLatex = 1; #ifndef KPATHSEA /* set rgsbInputPaths for use with TexOpen() */ @@ -560,29 +560,29 @@ main(int cArgs, char *rgsbArgs[]) /* process command line options */ while (iArgs < cArgs && *(pch = rgsbArgs[iArgs]) == CHOPT) { while (*++pch) - switch (*pch) { - case CHCITEOPT: + switch (*pch) { + case CHCITEOPT: fCite = 1; break; - case CHENVOPT: + case CHENVOPT: if (++iArgs >= cArgs) { ErrorExit("-e option requires an argument"); } sbEnvList = rgsbArgs[iArgs]; break; - case CHLATEXOPT: + case CHLATEXOPT: fLatex = 1; break; - case CHNOFOLLOWOPT: + case CHNOFOLLOWOPT: fFollow = 0; break; - case CHSPACEOPT: + case CHSPACEOPT: fSpace = 1; break; - case CHTEXOPT: + case CHTEXOPT: fForcetex = 1; break; - case CHWORDOPT: + case CHWORDOPT: fWord = 1; break; case CHREPLACE: @@ -594,12 +594,12 @@ main(int cArgs, char *rgsbArgs[]) case CHSRCLOC: fSrcLoc = 1; break; - default: + default: sbBadOpt[0] = *pch; sbBadOpt[1] = '\0'; Warning("unknown option ignored -", sbBadOpt); UsageExit(); - } + } iArgs++; } SetEnvIgnore(sbEnvList); @@ -610,30 +610,30 @@ main(int cArgs, char *rgsbArgs[]) /* process input files */ for (; iArgs < cArgs; iArgs++) { - fSawFile++; - if ((yyin = TexOpen(rgsbArgs[iArgs])) == NULL) { + fSawFile++; + if ((yyin = TexOpen(rgsbArgs[iArgs])) == NULL) { Warning("can't open file", rgsbArgs[iArgs]); continue;; - } + } fFileNames[csb] = rgsbArgs[iArgs]; fFileLines[csb] = 1; - BEGIN Normal; - (void)yylex(); + BEGIN Normal; + (void)yylex(); } /* if there were no input files, assume stdin */ if (!fSawFile) { - yyin = stdin; + yyin = stdin; #ifdef OS2 - if (isatty(fileno(stdin))) + if (isatty(fileno(stdin))) OS2UsageExit(); #endif - BEGIN Normal; - (void)yylex(); + BEGIN Normal; + (void)yylex(); } #ifndef FLEX_SCANNER if (YYSTATE != Normal) - ErrorExit("input contains an unterminated mode or environment"); + ErrorExit("input contains an unterminated mode or environment"); #endif return(0); } @@ -653,7 +653,7 @@ yywrap(void) { (void)fclose(yyin); #ifdef FLEX_SCANNER - /* Pop context state */ + /* Pop context state */ if (csb > 0) { free(fFileNames[csb]); yy_delete_buffer( YY_CURRENT_BUFFER ); @@ -661,8 +661,8 @@ yywrap(void) } #endif /* FLEX_SCANNER */ if (cfp > 0) { - yyin = rgfp[--cfp]; - return(0); + yyin = rgfp[--cfp]; + return(0); } return(1); } @@ -714,7 +714,7 @@ LineBreak() } /****** -** Echo -- If we are at column 0 and have specified '-1'; output +** Echo -- If we are at column 0 and have specified '-1'; output ** the source location information. ******/ @@ -746,7 +746,7 @@ IncrLineNo() ** cannot just ignore text. We must at least increase the linenumber counter. ******/ -void +void Ignore() { IncrLineNo(); @@ -765,10 +765,10 @@ SetEnvIgnore(const char *sbEnvList) sb = SafeMalloc(strlen(sbEnvList) + 1, "malloc for SetEnvIgnore failed"); (void) strcpy(sb, sbEnvList); - + csbEnvIgnore = SeparateList(sb, rgsbEnvIgnore, CHENVSEP, MAXENVS); if (csbEnvIgnore == my_ERROR) - ErrorExit("The environment list contains too many environments"); + ErrorExit("The environment list contains too many environments"); } /****** @@ -783,10 +783,10 @@ BeginEnv(const char *sbEnv) if (!fLatex) return(0); for (i = 0; i < csbEnvIgnore; ++i) - if (strcmp(sbEnv, rgsbEnvIgnore[i]) == 0) { + if (strcmp(sbEnv, rgsbEnvIgnore[i]) == 0) { (void)strcpy(sbCurrentIgnoredEnv, sbEnv); return(1); - } + } return(0); } @@ -799,7 +799,7 @@ EndEnv(const char *sbEnv) { if (!fLatex) return(0); if (strcmp(sbEnv, sbCurrentIgnoredEnv) == 0) - return(1); + return(1); return(0); } @@ -815,13 +815,13 @@ InputFile(char *sbFile) FILE *TexOpen(); if (!fFollow) - return; + return; rgfp[cfp++] = yyin; if ((yyin = TexOpen(sbFile)) == NULL) { - Warning("can't open \\input file", sbFile); - yyin = rgfp[--cfp]; - return; - } + Warning("can't open \\input file", sbFile); + yyin = rgfp[--cfp]; + return; + } #ifdef FLEX_SCANNER rgsb[csb++] = YY_CURRENT_BUFFER; fFileLines[csb] = 1; @@ -841,14 +841,14 @@ IncludeFile(char *sbFile) FILE *TexOpen(); if (!fFollow) - return; + return; if (!InList(sbFile)) - return; + return; rgfp[cfp++] = yyin; if ((yyin = TexOpen(sbFile)) == NULL) { - Warning("can't open \\include file", sbFile); - yyin = rgfp[--cfp]; - return; + Warning("can't open \\include file", sbFile); + yyin = rgfp[--cfp]; + return; } #ifdef FLEX_SCANNER rgsb[csb++] = YY_CURRENT_BUFFER; @@ -867,9 +867,9 @@ void AddInclude(char *sbFile) { if (!fFollow) - return; + return; if (csbIncList >= MAXINCLIST) - Warning("\\includeonly list is too long, ignoring", sbFile); + Warning("\\includeonly list is too long, ignoring", sbFile); rgsbIncList[csbIncList] = SafeMalloc(strlen(sbFile) + 1, "malloc for AddInclude failed"); (void)strcpy(rgsbIncList[csbIncList++], sbFile); } @@ -886,14 +886,14 @@ InList(char *sbFile) int i; if (csbIncList == 0) /* no list */ - return(1); + return(1); (void)strcpy(sbBase, sbFile); if ((pch = strrchr(sbBase, '.')) != NULL) - *pch = '\0'; + *pch = '\0'; i = 0; while ((i < csbIncList) && rgsbIncList[i]) - if (strcmp(rgsbIncList[i++], sbBase) == 0) - return(1); + if (strcmp(rgsbIncList[i++], sbBase) == 0) + return(1); return(0); } @@ -918,27 +918,27 @@ SetInputPaths(void) #ifdef OS2 if ((sb = getenv("TEXINPUT")) == NULL) #endif - if ((sb = getenv("TEXINPUTS")) == NULL) + if ((sb = getenv("TEXINPUTS")) == NULL) sb = DEFAULTINPUTS; cchPaths = strlen(sb); if (sb[0] == CHPATHSEP) - cchPaths += cchDefaults; + cchPaths += cchDefaults; if (sb[strlen(sb) - 1] == CHPATHSEP) - cchPaths += cchDefaults; + cchPaths += cchDefaults; sbPaths = SafeMalloc(cchPaths + 1, "malloc for SetInputPaths failed"); sbPaths[0] = '\0'; if (sb[0] == CHPATHSEP) - (void)strcat(sbPaths, DEFAULTINPUTS); + (void)strcat(sbPaths, DEFAULTINPUTS); (void)strcat(sbPaths, sb); if (sb[strlen(sb) - 1] == CHPATHSEP) - (void)strcat(sbPaths, DEFAULTINPUTS); + (void)strcat(sbPaths, DEFAULTINPUTS); csbInputPaths = SeparateList(sbPaths, rgsbInputPaths, CHPATHSEP, MAXINPUTPATHS); if (csbInputPaths == my_ERROR) #ifdef OS2 - ErrorExit("TEXINPUT(S) environment variable has too many paths"); + ErrorExit("TEXINPUT(S) environment variable has too many paths"); #else - ErrorExit("TEXINPUTS environment variable has too many paths"); + ErrorExit("TEXINPUTS environment variable has too many paths"); #endif } #endif @@ -956,8 +956,8 @@ SeparateList(char *sbList, char *rgsbList[], char chSep, int csbMax) int csbList = 0; while (sbList && *sbList && csbList < csbMax) { - rgsbList[csbList++] = sbList; - if ((sbList = strchr(sbList, chSep))) { + rgsbList[csbList++] = sbList; + if ((sbList = strchr(sbList, chSep))) { *sbList++ = '\0'; } } @@ -988,52 +988,52 @@ TexOpen(char *sbFile) for (iPath = 0; iPath < csbInputPaths; iPath++) { #ifdef OS2 - if (*sbFile == '/' || *sbFile == '\\' || strchr(sbFile, ':')) { /* absolute path */ + if (*sbFile == '/' || *sbFile == '\\' || strchr(sbFile, ':')) { /* absolute path */ #else - if (*sbFile == '/') { /* absolute path */ + if (*sbFile == '/') { /* absolute path */ #endif (void)snprintf(sbFullPath, PATH_MAX-1, "%s", sbFile); iPath = csbInputPaths; /* only check once */ - } else { + } else { (void)snprintf(sbFullPath, PATH_MAX-1, "%s/%s", rgsbInputPaths[iPath], sbFile); } #ifdef OS2 - pch = sbFullPath; - while (pch = strchr(pch, '\\')) { + pch = sbFullPath; + while (pch = strchr(pch, '\\')) { *pch = '/'; } #endif - /* If sbFile ends in .tex then it must be there */ - if ((pch = strrchr(sbFullPath, '.')) != NULL + /* If sbFile ends in .tex then it must be there */ + if ((pch = strrchr(sbFullPath, '.')) != NULL && (strcmp(pch, ".tex") == 0)) { if ((fp = fopen(sbFullPath, "r")) != NULL) return(fp); else continue; - } - - /* if . then try to open it. the '.' represents */ - /* the beginning of an extension if it is not the first */ - /* character and it does not follow a '.' or a '/' */ - if (pch != NULL && pch > &(sbFullPath[0]) - && *(pch - 1) != '.' && *(pch - 1) != '/' - && (fp = fopen(sbFullPath, "r")) != NULL) { + } + + /* if . then try to open it. the '.' represents */ + /* the beginning of an extension if it is not the first */ + /* character and it does not follow a '.' or a '/' */ + if (pch != NULL && pch > &(sbFullPath[0]) + && *(pch - 1) != '.' && *(pch - 1) != '/' + && (fp = fopen(sbFullPath, "r")) != NULL) { return(fp); } - /* just base name, add .tex to the name */ - sbNew = SafeMalloc(strlen(sbFullPath) + 5, "malloc for TexOpen failed"); - (void)strcpy(sbNew, sbFullPath); - (void)strcat(sbNew, ".tex"); - if ((fp = fopen(sbNew, "r")) != NULL) { + /* just base name, add .tex to the name */ + sbNew = SafeMalloc(strlen(sbFullPath) + 5, "malloc for TexOpen failed"); + (void)strcpy(sbNew, sbFullPath); + (void)strcat(sbNew, ".tex"); + if ((fp = fopen(sbNew, "r")) != NULL) { free(sbNew); return(fp); } free(sbNew); - /* try sbFile regardless */ - if ((fp = fopen(sbFullPath, "r")) != NULL) + /* try sbFile regardless */ + if ((fp = fopen(sbFullPath, "r")) != NULL) return(fp); } return NULL; @@ -1041,7 +1041,7 @@ TexOpen(char *sbFile) sbNew = kpse_find_file (sbFile, kpse_tex_format, false); if (sbNew == NULL) - return NULL; + return NULL; return fopen (sbNew, "r"); #endif @@ -1057,7 +1057,7 @@ SafeMalloc(int cch, const char *sbMessage) char *sb; if ((sb = (char *)malloc((unsigned)cch)) == NULL) - ErrorExit(sbMessage); + ErrorExit(sbMessage); return(sb); }