FILE * createDosTmp( char *path ) { FILE *fd = NULL; char szDir[_MAX_PATH]; if (!path || !*path) { // If path is empty, use "." _tcscpy(szDir, "."); } else { _tcscpy(szDir, path); } // Use GetTempFileName to overcome limitations of _mktemp // regarding the max number of generated files char szTempFile[_MAX_PATH]; if (GetTempFileName (path, "nm", 0, szTempFile)) { _tcscpy(path, szTempFile); // Open the file and return the file's descriptor. fd = FILEOPEN(path, "w"); } return fd; }
void readCommandFile( char *name ) { char *s, // buffer **vector; // local versions of arg vector unsigned count = 0; // count size_t n; if (!(file = FILEOPEN(name,"rt"))) makeError(0,CANT_OPEN_FILE,name); vector = NULL; // no args yet while (fgets(buf,MAXBUF,file)) { n = _tcslen(buf); // if we didn't get the whole line, OR the line ended with a backSlash if ((n == MAXBUF-1 && buf[n-1] != '\n') || (buf[n-1] == '\n' && buf[n-2] == '\\') ) { if (buf[n-2] == '\\' && buf[n-1] == '\n') { // Replace \n by \0 and \\ by a space; Also reset length buf[n-1] = '\0'; buf[n-2] = ' '; n--; } s = makeString(buf); getRestOfLine(&s,&n); } else s = buf; processLine(s,&count,&vector); // separate into args if (s != buf) FREE(s); } if (fclose(file) == EOF) makeError(0, ERROR_CLOSING_FILE, name); parseCommandLine(count,vector); // evaluate the args while (count--) // free the arg vector if(vector[count]) FREE(vector[count]); // NULL entries mean that the space the } // entry used to pt to is still in use