- Added file checking and listings to exeman
- Fixed some problems with mesure - Fixed issues with tasub
This commit is contained in:
201
exeman.c
201
exeman.c
@ -11,6 +11,8 @@
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include <tcl.h>
|
||||
#include <dirent.h>
|
||||
#include <ctype.h>
|
||||
#include "fortify.h"
|
||||
#include "sics.h"
|
||||
#include "exebuf.h"
|
||||
@ -388,6 +390,45 @@ static int appendLine(pExeMan self, SConnection *pCon,
|
||||
return 1;
|
||||
}
|
||||
/*--------------------------------------------------------------------*/
|
||||
static int uploadForceSave(pExeMan self, SConnection *pCon,
|
||||
int argc, char *argv[]){
|
||||
int status;
|
||||
char pPath[256], *pPtr;
|
||||
|
||||
if(SCGetRights(pCon) > usUser){
|
||||
SCWrite(pCon,"ERROR: no permission to save buffers",eError);
|
||||
return 0;
|
||||
}
|
||||
if(argc < 3) {
|
||||
SCWrite(pCon,"ERROR: no file given to save upload buffer to",eError);
|
||||
return 0;
|
||||
}
|
||||
if(self->uploadBuffer == NULL){
|
||||
SCWrite(pCon,"ERROR: no upload buffer to save exists",eError);
|
||||
return 0;
|
||||
}
|
||||
if(argv[2][0] != '/') {
|
||||
pPtr = self->batchPath;
|
||||
pPtr = stptok(pPtr,pPath,131,":");
|
||||
if(strlen(pPath) + 1 + strlen(argv[2]) <= 256){
|
||||
strcat(pPath,"/");
|
||||
strcat(pPath,argv[2]);
|
||||
} else {
|
||||
strncpy(pPath,argv[2],255);
|
||||
}
|
||||
} else {
|
||||
strncpy(pPath,argv[2],131);
|
||||
}
|
||||
|
||||
status = exeBufSave(self->uploadBuffer,pPath);
|
||||
if(status == 0){
|
||||
SCWrite(pCon,"ERROR: failed to save exe buffer, destroyed...",eError);
|
||||
}
|
||||
exeBufDelete(self->uploadBuffer);
|
||||
self->uploadBuffer = NULL;
|
||||
return status;
|
||||
}
|
||||
/*--------------------------------------------------------------------*/
|
||||
static int uploadSave(pExeMan self, SConnection *pCon,
|
||||
int argc, char *argv[]){
|
||||
int status;
|
||||
@ -417,6 +458,11 @@ static int uploadSave(pExeMan self, SConnection *pCon,
|
||||
} else {
|
||||
strncpy(pPath,argv[2],131);
|
||||
}
|
||||
if(fileExists(pPath)) {
|
||||
SCWrite(pCon,"ERROR: file exists",eError);
|
||||
return 0;
|
||||
}
|
||||
|
||||
status = exeBufSave(self->uploadBuffer,pPath);
|
||||
if(status == 0){
|
||||
SCWrite(pCon,"ERROR: failed to save exe buffer, destroyed...",eError);
|
||||
@ -425,6 +471,141 @@ static int uploadSave(pExeMan self, SConnection *pCon,
|
||||
self->uploadBuffer = NULL;
|
||||
return status;
|
||||
}
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* See if a string matches a wildcard specification that uses * or ?
|
||||
(like "*.txt"), and return TRUE or FALSE, depending on the result.
|
||||
There's also a TRUE/FALSE parameter you use to indicate whether
|
||||
the match should be case-sensitive or not.
|
||||
*/
|
||||
#ifndef TRUE
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
#endif
|
||||
/*--------------------------------------------------------------------------------*/
|
||||
static int IsWildcardMatch (char *wildcardString, char *stringToCheck, int caseSensitive)
|
||||
{
|
||||
char wcChar;
|
||||
char strChar;
|
||||
// use the starMatchesZero variable to determine whether an asterisk
|
||||
// matches zero or more characters (TRUE) or one or more characters
|
||||
// (FALSE)
|
||||
int starMatchesZero = TRUE;
|
||||
|
||||
|
||||
while ((strChar = *stringToCheck) && (wcChar = *wildcardString))
|
||||
{
|
||||
// we only want to advance the pointers if we successfully assigned
|
||||
// both of our char variables, so we'll do it here rather than in the
|
||||
// loop condition itself
|
||||
*stringToCheck++;
|
||||
*wildcardString++;
|
||||
|
||||
// if this isn't a case-sensitive match, make both chars uppercase
|
||||
// (thanks to David John Fielder (Konan) at http://innuendo.ev.ca
|
||||
// for pointing out an error here in the original code)
|
||||
if (!caseSensitive)
|
||||
{
|
||||
wcChar = toupper(wcChar);
|
||||
strChar = toupper(strChar);
|
||||
}
|
||||
|
||||
// check the wcChar against our wildcard list
|
||||
switch (wcChar)
|
||||
{
|
||||
// an asterisk matches zero or more characters
|
||||
case '*' :
|
||||
// do a recursive call against the rest of the string,
|
||||
// until we've either found a match or the string has
|
||||
// ended
|
||||
if (starMatchesZero)
|
||||
*stringToCheck--;
|
||||
|
||||
while (*stringToCheck)
|
||||
{
|
||||
if (IsWildcardMatch(wildcardString, stringToCheck++, caseSensitive))
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
// a question mark matches any single character
|
||||
case '?' :
|
||||
break;
|
||||
|
||||
// if we fell through, we want an exact match
|
||||
default :
|
||||
if (wcChar != strChar)
|
||||
return FALSE;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// if we have any asterisks left at the end of the wildcard string, we can
|
||||
// advance past them if starMatchesZero is TRUE (so "blah*" will match "blah")
|
||||
while ((*wildcardString) && (starMatchesZero))
|
||||
{
|
||||
if (*wildcardString == '*')
|
||||
wildcardString++;
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
// if we got to the end but there's still stuff left in either of our strings,
|
||||
// return false; otherwise, we have a match
|
||||
if ((*stringToCheck) || (*wildcardString))
|
||||
return FALSE;
|
||||
else
|
||||
return TRUE;
|
||||
|
||||
}
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static int wwmatch(char *pattern, char *name){
|
||||
return IsWildcardMatch(pattern,name,1);
|
||||
}
|
||||
/*--------------------------------------------------------------------
|
||||
search the directory pPath for file matching pattern. Successfull
|
||||
files will be appended to result
|
||||
-----------------------------------------------------------------------*/
|
||||
static void searchDir(char *pPath, char *pattern, pDynString result){
|
||||
DIR *currentdir = NULL;
|
||||
struct dirent *currentFile = NULL;
|
||||
|
||||
currentdir = opendir(pPath);
|
||||
if(currentdir == NULL){
|
||||
return;
|
||||
}
|
||||
currentFile = readdir(currentdir);
|
||||
while(currentFile != NULL){
|
||||
if(wwmatch((const char *)pattern, currentFile->d_name)){
|
||||
DynStringConcat(result,currentFile->d_name);
|
||||
DynStringConcatChar(result,'\n');
|
||||
}
|
||||
currentFile = readdir(currentdir);
|
||||
}
|
||||
closedir(currentdir);
|
||||
}
|
||||
/*--------------------------------------------------------------------*/
|
||||
static pDynString findDirEntries(pExeMan self, char *pattern){
|
||||
pDynString result = NULL;
|
||||
char pPath[132], *pPtr = NULL;
|
||||
|
||||
result = CreateDynString(256,256);
|
||||
if(!result){
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pPtr = self->batchPath;
|
||||
while((pPtr = stptok(pPtr,pPath,131,":")) != NULL){
|
||||
searchDir(pPath,pattern,result);
|
||||
}
|
||||
|
||||
pPtr = self->sysPath;
|
||||
while((pPtr = stptok(pPtr,pPath,131,":")) != NULL){
|
||||
searchDir(pPath,pattern,result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/*=========================== info ===================================*/
|
||||
static void printExeStack(pExeMan self, SConnection *pCon){
|
||||
int i, j;
|
||||
@ -730,6 +911,7 @@ int ExeManagerWrapper(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
pExeMan self = NULL;
|
||||
char pBufferName[256];
|
||||
int status;
|
||||
pDynString dirList = NULL;
|
||||
|
||||
self = (pExeMan)pData;
|
||||
assert(self != NULL);
|
||||
@ -768,6 +950,12 @@ int ExeManagerWrapper(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
SCSendOK(pCon);
|
||||
}
|
||||
return status;
|
||||
}else if(strcmp(argv[1],"forcesave") == 0){
|
||||
status = uploadForceSave(self,pCon,argc,argv);
|
||||
if(status){
|
||||
SCSendOK(pCon);
|
||||
}
|
||||
return status;
|
||||
}else if(strcmp(argv[1],"info") == 0){
|
||||
status = infoHandler(self,pCon,argc,argv);
|
||||
return status;
|
||||
@ -780,6 +968,19 @@ int ExeManagerWrapper(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
SCSendOK(pCon);
|
||||
}
|
||||
return status;
|
||||
} else if(strcmp(argv[1],"dir") == 0){
|
||||
if(argc <= 2){
|
||||
dirList = findDirEntries(self,"*");
|
||||
} else {
|
||||
dirList = findDirEntries(self,argv[2]);
|
||||
}
|
||||
if(dirList != NULL){
|
||||
SCWrite(pCon,GetCharArray(dirList),eValue);
|
||||
DeleteDynString(dirList);
|
||||
} else {
|
||||
SCWrite(pCon,"Nothing found",eValue);
|
||||
}
|
||||
return 1;
|
||||
}else if(strcmp(argv[1],"clear") == 0){
|
||||
clearQueue(self);
|
||||
SCSendOK(pCon);
|
||||
|
Reference in New Issue
Block a user