Beispiel #1
0
int main(int argc, char*argv[]){
	refresh(START);

	char *rawFile,*csvfile,*sysDate;
	const char url[] = "http://codapi.zappos.biz/menus";
	float budgetVal;
	
	
	sysDate = (char*)malloc(sizeof(char)*20);
		memset(sysDate,'\0',20);

	budgetVal = validator(argc, argv);	//check the validity of the input arguments
	rawFile = readURL(url);				//Read the content from the website and get the name of the file 
	
	parseFile(rawFile);					//Performs parsing of the JSON data on the file name stored in rawFile
	
	sysDate = systemDate();				//Find the system date and save it in sysDate variable. 
	
	//Debugging statements
	//strcpy(sysDate,"2015-05-11");	
	
	returnBestList(sysDate,directoryExam());	//Use the sysdate to find the appropriate files and then perform operations.
	
	purgeFiles(directoryExam());				//Maintenance :) 
	deleteFile(rawFile);

	refresh(STOP);

	return 0;
}
void saveConfig(CString& configFile)
{
	CString	bakName;

	bakName = CString(SubCString(configFile, 1, configFile.posr('.')-1)) +
				CString(".bak");

	unlink(bakName);
	rename(configFile, bakName);

	FILE*	f = fopen(configFile, "wt");

	if (f)
		{
		fprintf(f, ";*[f*--------------------------------oOo-----------------------------------\n");
		fprintf(f, ";\n");
		fprintf(f, "; Saved at %s %s\n", (const char*)systemTime().longCString(), (const char*)systemDate().longCString());
		fprintf(f, ";\n");
		fprintf(f, "; You can set a variety of OnScreen/2 items in this file.\n");
		fprintf(f, "; * Colours for status lines\n");
		fprintf(f, "; * Colours for file manager & buffer list\n");
		fprintf(f, "; * Other global OnScreen/2 settings\n");
		fprintf(f, "; * Styles, including syntax highlighting\n");
		fprintf(f, "; * Key bindings (coming soon)\n");
		fprintf(f, ";\n");
		fprintf(f, "; In this file you can specify the styles which OnScreen/2 will apply\n");
		fprintf(f, "; to files with specific extensions.\n");
		fprintf(f, ";\n");
		fprintf(f, "; Files with either no extension or with an extension which is not\n");
		fprintf(f, "; listed here will use the Default style.\n");
		fprintf(f, ";\n");
		fprintf(f, "; Comments start with a ; and end at EOL. The ; must be the first\n");
		fprintf(f, "; non whitespace character on the line\n");
		fprintf(f, ";\n");
		fprintf(f, "; The syntax for the style heading is as follows\n");
		fprintf(f, "; Keyword StyleName File-Ext-List Inherited-Styles\n");
		fprintf(f, "; Style   Pascal    (.pas)        Base Default...\n");
		fprintf(f, ";\n");
		fprintf(f, ";*f]*--------------------------------oOo-----------------------------------\n\n");

		// save the settings

		fprintf(f, "Settings\n");
		fprintf(f, "{\n");
		fprintf(f, "\tSound\t\t\t\t\t=> %s\n", 			setupInfo.soundOn ? OnString:OffString);
		fprintf(f, "\tKeepFilesLoaded\t\t\t=> %s\n", 	setupInfo.keepFilesLoaded ? OnString:OffString);
		fprintf(f, "\tSearch\t\t\t\t\t=> %s\n", 		setupInfo.regexpSearch ? "Regexp":"Plain");
		fprintf(f, "\tStatusTextForeColor\t\t=> %s\n", 	colorTable[setupInfo.statusTextForeColor]);
		fprintf(f, "\tStatusTextBackColor\t\t=> %s\n", 	colorTable[setupInfo.statusTextBackColor]);
		fprintf(f, "\tDiskTextForeColor\t\t=> %s\n", 	colorTable[setupInfo.diskTextForeColor]);
		fprintf(f, "\tDiskTextBackColor\t\t=> %s\n", 	colorTable[setupInfo.diskTextBackColor]);
		fprintf(f, "\tCurDiskTextForeColor\t=> %s\n", 	colorTable[setupInfo.curDiskTextForeColor]);
		fprintf(f, "\tCurDiskTextBackColor\t=> %s\n", 	colorTable[setupInfo.curDiskTextBackColor]);
		fprintf(f, "\tFileTextForeColor\t\t=> %s\n", 	colorTable[setupInfo.fileTextForeColor]);
		fprintf(f, "\tFileTextBackColor\t\t=> %s\n", 	colorTable[setupInfo.fileTextBackColor]);
		fprintf(f, "\tCurFileTextForeColor\t=> %s\n", 	colorTable[setupInfo.curFileTextForeColor]);
		fprintf(f, "\tCurFileTextBackColor\t=> %s\n", 	colorTable[setupInfo.curFileTextBackColor]);
		fprintf(f, "}\n\n");

		// save the styles
		SListIterator<Style>	styleIterator(styles);
		Style*					style;

		for (style = styleIterator.GoHead(); style; style = styleIterator.GetNext())
			{
			fprintf(f, "Style %s (", (const char*)style->iStyleName);

			if (strcmpi(style->iStyleName, "Default") == 0)
				{
				fprintf(f, "*");
				}
			else
			if (style->iExtensions.GetUnresolved())
				{
				SetIterator<CString>	extIterator(*style->iExtensions.GetUnresolved());
				CString*				ext;

				for (ext = extIterator.GoHead(); ext;)
					{
					CString	s = *ext;
					ext = extIterator.GetNext();

					if (ext)
						fprintf(f, "%s ", (const char*)s);
					else
						fprintf(f, "%s", (const char*)s);
					}
				}

			if (style->iBaseStyles.Size() > 0)
				{
				fprintf(f, ") ");

				SetIterator<CString>	baseStyleIterator(style->iBaseStyles);
				CString*				baseStyle;

				for (baseStyle = baseStyleIterator.GoHead(); baseStyle;)
					{
					CString	s = *baseStyle;
					baseStyle = baseStyleIterator.GetNext();

					if (baseStyle)
						fprintf(f, "%s ", (const char*)s);
					else
						fprintf(f, "%s\n", (const char*)s);
					}
				}
			else
				{
				fprintf(f, ")\n");
				}

			fprintf(f, "{\n");

			if (style->iForeGndColor.GetUnresolved())
				{
				fprintf(f, "\t%s\t\t\t=> %s\n", styleSectionTable[SS_FOREGNDCOLOR], colorTable[*style->iForeGndColor.GetUnresolved()]);
				}

			if (style->iBackGndColor.GetUnresolved())
				{
				fprintf(f, "\t%s\t\t\t=> %s\n", styleSectionTable[SS_BACKGNDCOLOR], colorTable[*style->iBackGndColor.GetUnresolved()]);
				}

			if (style->iSelectedForeGndColor.GetUnresolved())
				{
				fprintf(f, "\t%s\t=> %s\n", styleSectionTable[SS_SELECTEDFOREGNDCOLOR], colorTable[*style->iSelectedForeGndColor.GetUnresolved()]);
				}

			if (style->iSelectedBackGndColor.GetUnresolved())
				{
				fprintf(f, "\t%s\t=> %s\n", styleSectionTable[SS_SELECTEDBACKGNDCOLOR], colorTable[*style->iSelectedBackGndColor.GetUnresolved()]);
				}

			if (style->iBoldColor.GetUnresolved())
				{
				fprintf(f, "\t%s\t\t\t\t=> %s\n", styleSectionTable[SS_BOLDCOLOR], colorTable[*style->iBoldColor.GetUnresolved()]);
				}

			if (style->iUnderlineColor.GetUnresolved())
				{
				fprintf(f, "\t%s\t\t\t=> %s\n", styleSectionTable[SS_UNDERLINECOLOR], colorTable[*style->iUnderlineColor.GetUnresolved()]);
				}

			if (style->iBoldUnderlineColor.GetUnresolved())
				{
				fprintf(f, "\t%s\t\t=> %s\n", styleSectionTable[SS_BOLDUNDERLINECOLOR], colorTable[*style->iBoldUnderlineColor.GetUnresolved()]);
				}

			if (style->iExpandTabs.GetUnresolved())
				{
				fprintf(f, "\t%s\t\t\t\t=> %s\n", styleSectionTable[SS_EXPANDTABS], *style->iExpandTabs.GetUnresolved() ? OnString:OffString);
				}

			if (style->iHighBitFilter.GetUnresolved())
				{
				fprintf(f, "\t%s\t\t\t=> %s\n", styleSectionTable[SS_HIGHBITFILTER], *style->iHighBitFilter.GetUnresolved() ? OnString:OffString);
				}

			if (style->iTextWithLayout.GetUnresolved())
				{
				fprintf(f, "\t%s\t\t\t=> %s\n", styleSectionTable[SS_TEXTWITHLAYOUT], *style->iTextWithLayout.GetUnresolved() ? OnString:OffString);
				}

			if (style->iTabWidth.GetUnresolved())
				{
				fprintf(f, "\t%s\t\t\t\t=> %i\n", styleSectionTable[SS_TABWIDTH], *style->iTabWidth.GetUnresolved());
				}

			if (style->iDisplayMode.GetUnresolved())
				{
				fprintf(f, "\t%s\t\t\t\t=> %s\n", styleSectionTable[SS_DISPLAYMODE], *style->iDisplayMode.GetUnresolved() == DM_TEXT ? "Text":"Hex");
				}

			if (style->iExternalFilterCmd.GetUnresolved())
				{
				fprintf(f, "\t%s\t\t\t=> %s\n", styleSectionTable[SS_EXTERNALFILTER], (const char*)*style->iExternalFilterCmd.GetUnresolved());
				}

			if (style->iEditor.GetUnresolved())
				{
				fprintf(f, "\t%s\t\t\t\t\t=> %s\n", styleSectionTable[SS_EDITOR], (const char*)*style->iEditor.GetUnresolved());
				}

			if (style->iTopLineFormat.GetUnresolved())
				{
				fprintf(f, "\t%s\t\t\t=> %i\n", styleSectionTable[SS_TOPLINEFORMAT], *style->iTopLineFormat.GetUnresolved());
				}

			if (style->iWordBreak.GetUnresolved())
				{
				fprintf(f, "\t%s\t\t\t\t=> %s\n", styleSectionTable[SS_WORDBREAK], *style->iWordBreak.GetUnresolved() ? OnString:OffString);
				}

			// save non-inherited reserved words, if any
			if (style->iReserved.Size() > 0)
				{
				bool	foundFirst = true;

				for (int i=0; i < style->iReserved.Size(); i++)
					{
					if (!style->iReserved[i].iInherited)
						{
						if (foundFirst)
							{
							foundFirst = false;
							fprintf(f, "\t%s\t\t\t\t=> %s\n", styleSectionTable[SS_RESERVED], (const char*)style->iReserved[i].iKeyword);
							}
						else
							{
							fprintf(f, "\t\t\t\t\t\t\t=> %s\n", (const char*)style->iReserved[i].iKeyword);
							}
						}
					}
				}

			if (style->iSymbolsColor.GetUnresolved())
				{
				fprintf(f, "\t%s\t\t\t=> %s\n", styleSectionTable[SS_SYMBOLSCOLOR], colorTable[*style->iSymbolsColor.GetUnresolved()]);
				}

			if (style->iCommentColor.GetUnresolved())
				{
				fprintf(f, "\t%s\t\t\t=> %s\n", styleSectionTable[SS_COMMENTCOLOR], colorTable[*style->iCommentColor.GetUnresolved()]);
				}

			if (style->iStringColor.GetUnresolved())
				{
				fprintf(f, "\t%s\t\t\t\t=> %s\n", styleSectionTable[SS_STRINGCOLOR], colorTable[*style->iStringColor.GetUnresolved()]);
				}

			if (style->iReservedColor.GetUnresolved())
				{
				fprintf(f, "\t%s\t\t\t=> %s\n", styleSectionTable[SS_RESERVEDCOLOR], colorTable[*style->iReservedColor.GetUnresolved()]);
				}

			if (style->iPreprocessorColor.GetUnresolved())
				{
				fprintf(f, "\t%s\t\t=> %s\n", styleSectionTable[SS_PREPROCESSORCOLOR], colorTable[*style->iPreprocessorColor.GetUnresolved()]);
				}

			if (style->iNumberColor.GetUnresolved())
				{
				fprintf(f, "\t%s\t\t\t\t=> %s\n", styleSectionTable[SS_NUMBERCOLOR], colorTable[*style->iNumberColor.GetUnresolved()]);
				}

			if (style->iIdentColor.GetUnresolved())
				{
				fprintf(f, "\t%s\t\t\t\t=> %s\n", styleSectionTable[SS_IDENTCOLOR], colorTable[*style->iIdentColor.GetUnresolved()]);
				}

			if (style->iSymbols.GetUnresolved())
				{
				fprintf(f, "\t%s\t\t\t\t\t=> %s\n", styleSectionTable[SS_SYMBOLS], (const char*)*style->iSymbols.GetUnresolved());
				}

			if (style->iOpenComment.GetUnresolved())
				{
				bool	foundFirst = true;
				SetIterator<CString>	openCommentIterator(*style->iOpenComment.GetUnresolved());
				CString*				openComment;

				for (openComment = openCommentIterator.GoHead(); openComment;)
					{
					CString	s = *openComment;
					openComment = openCommentIterator.GetNext();

					if (foundFirst)
						{
						foundFirst = false;
						fprintf(f, "\t%s\t\t\t\t=> %s\n", styleSectionTable[SS_OPENCOMMENT], (const char*)s);
						}
					else
						{
						fprintf(f, "\t\t\t\t\t\t\t=> %s\n", (const char*)s);
						}
					}
				}

			if (style->iCloseComment.GetUnresolved())
				{
				bool	foundFirst = true;
				SetIterator<CString>	closeCommentIterator(*style->iCloseComment.GetUnresolved());
				CString*				closeComment;

				for (closeComment = closeCommentIterator.GoHead(); closeComment;)
					{
					CString	s = *closeComment;
					closeComment = closeCommentIterator.GetNext();

					if (foundFirst)
						{
						foundFirst = false;
						fprintf(f, "\t%s\t\t\t=> %s\n", styleSectionTable[SS_CLOSECOMMENT], (const char*)s);
						}
					else
						{
						fprintf(f, "\t\t\t\t\t\t\t=> %s\n", (const char*)s);
						}
					}
				}

			if (style->iEolComment.GetUnresolved())
				{
				bool	foundFirst = true;
				SetIterator<CString>	eolCommentIterator(*style->iEolComment.GetUnresolved());
				CString*				eolComment;

				for (eolComment = eolCommentIterator.GoHead(); eolComment;)
					{
					CString	s = *eolComment;
					eolComment = eolCommentIterator.GetNext();

					if (foundFirst)
						{
						foundFirst = false;
						fprintf(f, "\t%s\t\t=> %s\n", styleSectionTable[SS_SINGLELINECOMMENT], (const char*)s);
						}
					else
						{
						fprintf(f, "\t\t\t\t\t\t\t=> %s\n", (const char*)s);
						}
					}
				}

			if (style->iString.GetUnresolved())
				{
				fprintf(f, "\t%s\t\t\t\t\t=> %s\n", styleSectionTable[SS_STRINGS], (const char*)*style->iString.GetUnresolved());
				}

			if (style->iEscape.GetUnresolved() && *style->iEscape.GetUnresolved() != '\0')
				{
				fprintf(f, "\t%s\t\t\t\t\t=> %c\n", styleSectionTable[SS_ESCAPE], *style->iEscape.GetUnresolved());
				}

			if (style->iNumericPrefix.GetUnresolved())
				{
				bool	foundFirst = true;
				SetIterator<CString>	numericPrefixIterator(*style->iNumericPrefix.GetUnresolved());
				CString*				numericPrefix;

				for (numericPrefix = numericPrefixIterator.GoHead(); numericPrefix;)
					{
					CString	s = *numericPrefix;
					numericPrefix = numericPrefixIterator.GetNext();

					if (foundFirst)
						{
						foundFirst = false;
						fprintf(f, "\t%s\t\t\t=> %s\n", styleSectionTable[SS_NUMBERPREFIX], (const char*)s);
						}
					else
						{
						fprintf(f, "\t\t\t\t\t\t\t=> %s\n", (const char*)s);
						}
					}
				}

			if (style->iCaseSensitive.GetUnresolved())
				{
				fprintf(f, "\t%s\t\t\t=> %s\n", styleSectionTable[SS_CASESENSITIVE], *style->iCaseSensitive.GetUnresolved() ? YesString:NoString);
				}

			if (style->iCaseConvert.GetUnresolved())
				{
				fprintf(f, "\t%s\t\t\t\t=> %s\n", styleSectionTable[SS_CASECONVERT], *style->iCaseConvert.GetUnresolved() ? YesString:NoString);
				}

			if (style->iOpenPreprocessor.GetUnresolved())
				{
				fprintf(f, "\t%s\t\t=> %s\n", styleSectionTable[SS_OPENPREPROCESSOR], (const char*)*style->iOpenPreprocessor.GetUnresolved());
				}

			if (style->iClosePreprocessor.GetUnresolved())
				{
				fprintf(f, "\t%s\t\t=> %s\n", styleSectionTable[SS_CLOSEPREPROCESSOR], (const char*)*style->iClosePreprocessor.GetUnresolved());
				}

			if (style->iCommentColumn.GetUnresolved())
				{
				fprintf(f, "\t%s\t\t\t=> %i\n", styleSectionTable[SS_COMMENTCOLUMN], *style->iCommentColumn.GetUnresolved());
				}

			if (style->iLineContinuation.GetUnresolved() && *style->iLineContinuation.GetUnresolved() != '\0')
				{
				fprintf(f, "\t%s\t\t=> %c\n", styleSectionTable[SS_LINECONTINUATION], *style->iLineContinuation.GetUnresolved());
				}

			fprintf(f, "}\n\n");
			}

		fprintf(f, ";------------------------------------oOo-----------------------------------\n");
		fclose(f);
		}
}