#include "commonheaders.h" int readFileIntoArray(int fileNumber, char *FileContents[]) { int i =0; FILE* file; char FileName[MAX_PATH], temp[MAX_STRING_LENGTH]; wsprintf(FileName,"fn%d",fileNumber); DBGetContactSettingString(NULL,modname, FileName, FileName); if (!strncmp("http://", FileName, strlen("http://"))) wsprintf(FileName, "%s\\plugins\\fn%d.html",getMimDir(temp),fileNumber); file = fopen(FileName, "r"); if (file == NULL) return 0; // read the file into the FileContents array // free this array before stringReplacer() returns while (fgets(temp, MAX_STRING_LENGTH-1,file)) { if(temp[strlen(temp)-1]=='\n') temp[strlen(temp)-1]='\0'; else temp[strlen(temp)]='\0'; FileContents[i] = (char*)malloc(strlen(temp)+1); if (FileContents[i] == NULL) return i; strcpy(FileContents[i], temp); i++; } fclose(file); return i; } int getNumber(const char* line) { int i; if (sscanf(line, "%d", &i) == 1) return i; else return -1; } int findWordInString(const char* line, const char* string, int* lengthOfWord, int flag) /* flag = 0 %from, flag = 1 %until */ { unsigned int i, j=0; char word[64]="", OpenDivider[8], CloseDivider[8]; strcpy(OpenDivider, Translate("(\"")); strcpy(CloseDivider, Translate("\")")); /* get the word we r looking for */ if (!strncmp(string, OpenDivider, strlen(OpenDivider))) { for (i=2; strncmp(&string[i], CloseDivider, strlen(CloseDivider)); i++) { word[j] = string[i]; word[++j] = '\0'; } } i=0; *lengthOfWord = strlen(word)+strlen(CloseDivider)+strlen(OpenDivider); /* find the word in the line */ while (i < (strlen(line) - strlen(word) ) ) { if (!strncmp(&line[i], word, strlen(word))) { if (!flag) return i + strlen(word); /* the next char after the word */ else return i; /* the char before the word */ } i++; } return -1; } int findLine(char* FileContents[], const char* string, int linesInFile,int startLine, int *positionInOldString) { int i; char tmp[5]; i = getNumber(&string[*positionInOldString]); // check if blank if (string[*positionInOldString] == ')') return startLine; // check if its a number if ( i != -1) { *positionInOldString += strlen(itoa(i,tmp,10)) - 1; return i; } // lastline else if (!strncmp(&string[*positionInOldString], Translate("lastline("), strlen(Translate("lastline(")))) { *positionInOldString += strlen(Translate("lastline(")); i = getNumber(&string[*positionInOldString]); if ( i != -1) { *positionInOldString += strlen(itoa(i,tmp,10)); return linesInFile - (i+1); } else { *positionInOldString ++; return (linesInFile - 1); } } // string else if (string[*positionInOldString] == '\"') { char string2Find[256]; int j=0; // get the word to find for (i=(*positionInOldString+1); strncmp(&string[i], "\")", 2); i++) { string2Find[j] = string[i]; string2Find[++j] = '\0'; } // find the word for (j=startLine; j=0) { DBWriteContactSettingWord(hContact, modname, "Status", (WORD)(ID_STATUS_OFFLINE+icon)); } } } int stringReplacer(const char* oldString, char* newString, HANDLE hContact) { char var_file[8]; int tempInt; int startLine = 0, endLine = 0, startChar=0, endChar = 0, wholeLine=-1, linesInFile; unsigned int positionInOldString = 0; char *fileContents[MAXLINES] = {NULL}, tempString[MAX_STRING_LENGTH]; // setup the variable names strcpy(newString, ""); strcpy(var_file, Translate("file(")); while ((positionInOldString < strlen(oldString)) && (oldString[positionInOldString] != '\0')) { // load the file... must be first if (!strncmp(&oldString[positionInOldString], var_file, strlen(var_file))) { positionInOldString += strlen(var_file); // check if its a number tempInt = getNumber(&oldString[positionInOldString]); if (tempInt == -1) { // not a number so check vars.. // there are none yet return ERROR_NO_FILE; } // read the file linesInFile = readFileIntoArray(tempInt, fileContents); if (linesInFile == 0) return ERROR_NO_FILE; positionInOldString += strlen(itoa(tempInt, tempString,10)) + 1; // +1 for the closing ) // wholeline() if (!strncmp(&oldString[positionInOldString], Translate("wholeline(line("), strlen(Translate("wholeline(line(")))) { positionInOldString += strlen(Translate("wholeline(line(")); tempInt = findLine(fileContents,oldString, linesInFile, startLine,&positionInOldString); if (tempInt == -1|| !fileContents[tempInt]) return ERROR_NO_LINE_AFTER_VAR_F; else wholeLine =tempInt; positionInOldString += 3; // add 2 for the )) for wholeline(line()) } if (!strncmp(&oldString[positionInOldString], Translate("start("), strlen(Translate("start(")))) { positionInOldString += strlen(Translate("start(line(")); tempInt = findLine(fileContents,oldString, linesInFile, startLine,&positionInOldString); if (tempInt == -1 || !fileContents[tempInt]) return ERROR_NO_LINE_AFTER_VAR_F; else { positionInOldString+=2; startLine = tempInt; if (!endChar ) endChar = strlen(fileContents[startLine]); tempInt = findChar(fileContents,oldString, linesInFile, startLine,&positionInOldString, startChar,0); if (tempInt == -1) return ERROR_NO_LINE_AFTER_VAR_F; else startChar = tempInt; } positionInOldString += 2; // add 2 for the )) for start(line()) } if (!strncmp(&oldString[positionInOldString], Translate("end("), strlen(Translate("end(")))) { positionInOldString += strlen(Translate("end(line(")); tempInt = findLine(fileContents,oldString, linesInFile, startLine,&positionInOldString); if (tempInt == -1 || !fileContents[tempInt]) return ERROR_NO_LINE_AFTER_VAR_F; else { positionInOldString+=2; endLine = tempInt; tempInt = findChar(fileContents,oldString, linesInFile, startLine,&positionInOldString, startChar,1); if (tempInt == -1) return ERROR_NO_LINE_AFTER_VAR_F; else endChar = tempInt; } positionInOldString += 2; // add 2 for the )) for end(line()) } // check for both start() and end() otherwise, only copying 1 line if (!strstr(oldString, Translate("start("))) startLine = endLine; if (!strstr(oldString, Translate("end("))) endLine = startLine; // after all the options copy the line across and add 2 to positionInOldString for the file(print(....)) if (wholeLine >= 0) strcat(newString, fileContents[wholeLine]); else { // only copying from 1 line if (startLine == endLine) strncat(newString, &fileContents[startLine][startChar], endChar - startChar); else { int i; // copy the whole first line from startChar strcat(newString, &fileContents[startLine][startChar]); // copy the middle lines across for (i=(startLine+1);i