ql_freak wrote:Unfortunately there's one strcpy() function used (often), which I don't understand:
Code: Select all
struct stat sb1,sb2;
if( dflag )
if( stat( strcat(strcpy(b,s),"_o"),&sb2 )==0 )
/* ^^^^^^^^^^^ */
/* parameter s is declared in main with: char *s; i. e. array of 32 pointers to char. It is initialised
in a for loop with: s[sc++] = argv[i]+1; sc and i are declared as int. Then compile is called with:
ec += compile(s[i]); where ec is the error count */
So this code is taking the arguments from the command line (i.e. s* allows for 32 strings where each string I'm guessing is a filename) which are the source files you can compile, and one-by-one passing them into compile (for, I assume, compilation). The strcpy takes the source file (which I think you said should not have a _c extension) and adds the _c extension...so it first copies it into b to not overwrite the original s structure (arrays in C are passed by reference) and then concatenates "_c" to it. Then it seems to do a stat command which I"m guessing sees if the file exists. Since b is a local array of 256 characters it is defined on the stack and only persists within the compile function (so it's a temporary place to store stuff).
Note that strcpy is defined: char *strcpy(char *dest, const char *src)
If the command line can take in arguments besides source filenames, I'm guessing that when the "if (stat...)" fails there is an else to it that checks for the arguments, i.e. things that are preceded by -.
One weirdness is that the compile function prototypes strcat and strcpy within its local parameters...usually you stick those in a header file and usually those are predefined in a string_h (string.h in non-QL parlance) since they are implemented in a standard library used by the C compiler. In Digital 'C' SE these are prototyped, I believe, in stdio_h and the library is std_lib (which is pretty standard). Perhaps just a unique quirk of the coder who wrote compile...dunno.