void _FARFUNC _makepath(register char *pathP, const char *driveP, const char *dirP, const char *nameP, const char *extP ) { if (driveP && *driveP) { *pathP++ = *driveP++; *pathP++ = ':'; } if (dirP && *dirP) { pathP = _stpcpy(pathP,dirP); if (*(pathP-1) != '\\' && *(pathP-1) != '/') *pathP++ = '\\'; } if (nameP) pathP = _stpcpy(pathP,nameP); if (extP && *extP) { if (*extP != '.') *pathP++ = '.'; pathP = _stpcpy(pathP,extP); } *pathP = 0; }
/**************************************************************************** DESCRIPTION: Make a full pathname from split components. HEADER: pmapi.h PARAMETERS: path - Place to store full path drive - Drive component for path dir - Directory component for path name - Filename component for path ext - Extension component for path REMARKS: Function to make a full pathname from split components. Under Unix the drive component will usually be empty. If the drive, dir, name, or ext parameters are null or empty, they are not inserted in the path string. Otherwise, if the drive doesn't end with a colon, one is inserted in the path. If the dir doesn't end in a slash, one is inserted in the path. If the ext doesn't start with a dot, one is inserted in the path. The maximum sizes for the path string is given by the constant PM_MAX_PATH, which includes space for the null-terminator. SEE ALSO: PM_splitPath ****************************************************************************/ void PMAPI PM_makepath( char *path, const char *drive, const char *dir, const char *name, const char *ext) { if (drive && *drive) { *path++ = *drive; *path++ = ':'; } if (dir && *dir) { path = _stpcpy(path,dir); if (*(path-1) != '\\' && *(path-1) != '/') #ifdef __UNIX__ *path++ = '/'; #else *path++ = '\\'; #endif } if (name) path = _stpcpy(path,name); if (ext && *ext) { if (*ext != '.') *path++ = '.'; path = _stpcpy(path,ext); } *path = 0; }
char * _FARFUNC tempnam(char *dir, char *prefix) { char *dirs[4]; int tries; /* Make sure the prefix is 5 characters or less and has no '.' in it. */ if (strlen(prefix) > 5 || strchr(prefix, '.') != NULL) return (NULL); /* Set up the four directories we'll try searching. */ dirs[0] = getenv("TMP"); /* TMP enviroment variable */ dirs[1] = dir; /* dir parameter */ dirs[2] = P_tmpdir; /* stdio.h temp dir */ dirs[3] = ""; /* current directory */ /* Search the four directories. */ for (tries = 0; tries < 4; tries++) { char *dir, *p, *buf; unsigned err, attr, num; /* Allocate a buffer big enough for the complete filename. /* Put the directory name in the buffer, then repeatedly use * __mkname to append a weird name until we get one that * gives a filename that doesn't exist. */ if ((dir = dirs[tries]) == NULL) continue; /* skip NULL directory */ if ((buf = malloc(strlen(dir)+strlen(prefix)+8)) == NULL) continue; /* can't allocate space for dir\preXXXXXX */ p = _stpcpy(buf,dir); if (p != buf && *(p-1) != '/' && *(p-1) != '\\' && *(p-1) != ':') *p++ = '\\'; /* add trailing slash */ for (num = 0; num != TMP_MAX; num++) { __mkname(p, prefix, num); if ((err = _dos_getfileattr(buf, &attr)) != 0) { if (err == 2) /* file not found? */ return (buf); /* return unique name */ else /* some other error */ break; /* give up on this directory */ } } free(buf); /* try next directory */ } return (NULL); /* all four directories failed */ }
LPTSTR BatchParams (LPTSTR s1, LPTSTR s2) { LPTSTR dp = (LPTSTR)cmd_alloc ((_tcslen(s1) + _tcslen(s2) + 3) * sizeof (TCHAR)); /* JPP 20-Jul-1998 added error checking */ if (dp == NULL) { error_out_of_memory(); return NULL; } if (s1 && *s1) { s1 = _stpcpy (dp, s1); *s1++ = _T('\0'); } else s1 = dp; while (*s2) { BOOL inquotes = FALSE; /* Find next parameter */ while (_istspace(*s2) || (*s2 && _tcschr(_T(",;="), *s2))) s2++; if (!*s2) break; /* Copy it */ do { if (!inquotes && (_istspace(*s2) || _tcschr(_T(",;="), *s2))) break; inquotes ^= (*s2 == _T('"')); *s1++ = *s2++; } while (*s2); *s1++ = _T('\0'); } *s1 = _T('\0'); return dp; }
/*-----------------------------------------------------------------------* Name __DOScmd -- Build a DOS command line from argv array Usage char * pascal __DOScmd(char **argV); Prototype in _process.h Description This function allocates a buffer and fill it with all the argument strings one after the others. The command line starts with the command length and terminates with a carriage return which is not included in the count. Return value __DOScmd returns a pointer to command string buffer if successful, and NULL on error. *------------------------------------------------------------------------*/ char * pascal near __DOScmd(char **argV) { register char **argW; register unsigned cmdS, Wrk; char *bufP; /* Compute the command line size including the NULL string at the end of the command line. */ cmdS = 1; /* Command size byte */ if ((argW = argV) != NULL && *argW++) while (*argW && **argW) { Wrk = strlen(*argW++) + 1; if ((cmdS + Wrk) > 127) return NULL; cmdS += Wrk; } cmdS++; /* Ending Carriage Return */ /* Allocate a buffer, and concatenate all argument strings */ if ((bufP = malloc(cmdS)) != NULL) { if ((*bufP++ = cmdS - 2) != 0) { argW = argV + 1; while (*argW && **argW) { *bufP++ = ' '; bufP = _stpcpy(bufP, *argW++); } } *bufP++ = '\r'; return bufP - cmdS; } else return NULL; }
/* AR-930423 CH UT_makepath Slå sammen filnavn CD ================================================================== CD Formål: CD UT_makepath bygger opp et fullstendig filnavn ut fra dets deler. CD Det nye filnavnet blir: X:\DIR\SUBDIR\NAME.EXT CD hvor: X er drive CD \DIR\SUBDIR\ er gitt av dir CD NAME.EXT er gitt av name og ext CD CD PARAMETERLISTE: CD Type Navn I/U Merknad CD -------------------------------------------------------------- CD char *pszPath u Komplett filnavn CD const char *pszDrive i Disk CD const char *pszDir i Katalog CD const char *pszNavn i Navn CD const char *pszExt i Extension CD CD Bruk: UT_makepath(szPath,szDrive,szDir,szNavn,szExt); ================================================================== */ SK_EntPnt_UT void UT_makepath(char *pathP, const char *driveP, const char *dirP, const char *nameP, const char *extP) { #ifdef UNIX if (dirP && *dirP) { if(*(dirP)!=UT_SLASH) { *pathP++=UT_SLASH; } pathP = _stpcpy(pathP,dirP); if (*(pathP-1) != '\\' && *(pathP-1) != '/') *pathP++ = UT_SLASH; } if (nameP) pathP = _stpcpy(pathP,nameP); if (extP && *extP) { if (*extP != '.') *pathP++ = '.'; pathP = _stpcpy(pathP,extP); } *pathP = '\0'; #else if (driveP && *driveP) { *pathP++ = *driveP; *pathP++ = ':'; } if (dirP && *dirP) { pathP = _stpcpy(pathP,dirP); if (*(pathP-1) != '\\' && *(pathP-1) != '/') *pathP++ = UT_SLASH; } if (nameP) pathP = _stpcpy(pathP,nameP); if (extP && *extP) { if (*extP != '.') *pathP++ = '.'; pathP = _stpcpy(pathP,extP); } *pathP = '\0'; #endif }
/*---------------------------------------------------------------------* Name system - issues an MS-DOS command Usage int system(const char *command); Prototype in stdlib.h Description system invokes the MS-DOS command processor to execute a command given in the string command, as if the command had been typed at the DOS prompt. The COMSPEC environment variable is used to find the command processor file, so the file does not need to be in the current directory. Return value If command is a NULL pointer then system() returns nonzero if a command processor is available. If command is not a NULL pointer, system() returns zero if the command processor was successfully started. If an error occurred, a -1 is returned and errno is set to ENOENT, ENOMEM, E2BIG, or ENOEXEC. ENOENT - command processor not found ENOMEM - not enough memory E2BIG - argument list too long ENOEXEC - the command processor is not a valid executable *---------------------------------------------------------------------*/ int _FARFUNC system(const char _FAR *cmd) { register char *cmdP; int cmdS; register char *envP; void *envSave; char *pathP; int rc; // Check whether user just wants to test if command processor is available. // if (cmd == NULL) { if ((pathP = getenv("COMSPEC")) == NULL) { errno = ENOENT; return 0; } else return 1; } // Get COMMAND.COM path // if ((pathP = getenv("COMSPEC")) == NULL) { errno = ENOENT; return (-1); } // Build command line // cmdS = 1 + 3 + strlen(cmd) + 1; if (cmdS > 128) { errno = E2BIG; return (-1); } if ((cmdP = malloc(cmdS)) == NULL) { errno = ENOMEM; return (-1); } if (cmdS == 5) { cmdP[0] = 0; cmdP[1] = '\r'; } else { *cmdP++ = cmdS - 2; *cmdP++ = getswitchar(); cmdP = _stpcpy(cmdP, "c "); cmdP = _stpcpy(cmdP, cmd); *cmdP++ = '\r'; cmdP -= cmdS; } // Build environment // if ((envP = __DOSenv(environ, pathP, &envSave)) == NULL) { errno = ENOMEM; free(cmdP); return (-1); } // Flush all byte streams // (*_exitbuf)(); // Now, call the low level _spawn function // rc = _spawn(pathP, cmdP, envP); // Release all buffers // free(envSave); free(cmdP); return ((rc == -1) ? -1 : 0); }