// listuj katalog i dodawaj pliki w nim zawarte, ktróre s± mp3 static void listAddFolder(const char *fullname) { DIR *dir = opendir( fullname ); struct dirent *ent; if ( dir == NULL ) return; while ( (ent = readdir( dir )) != NULL ) { char *buf = NULL; if ( goc_stringEquals( ent->d_name, ".." ) ) continue; if ( goc_stringEquals( ent->d_name, "." ) ) continue; buf = goc_stringCopy( buf, fullname ); if ( fullname[strlen(fullname)-1] != '/' ) buf = goc_stringAdd( buf, "/" ); buf = goc_stringAdd( buf, ent->d_name ); if ( goc_isFolder( buf ) ) listAddFolder( buf ); else checkAddFile( buf ); buf = goc_stringFree( buf ); } closedir( dir ); }
xmlNode *nextChild(xmlNode *lastNode, const char *pParentName) { int i = -1; if ( lastNode ) { for (i=0; i<nClass; i++) { if ( pClassNode[i] == lastNode ) break; } // nie znaleziono podanego node-a if ( i == nClass ) return NULL; } // wyszukanie nastepnego node-a for ( i++; i<nClass; i++ ) { if ( !pClassParent[i] ) continue; if ( goc_stringEquals( getAttr( pClassParent[i], "name" ), pParentName ) ) return pClassNode[i]; } // nie ma wiecej return NULL; }
/* * Jesli jest zwroci, jesli nie ma NULL */ xmlNode *hasClass(const char *classname) { int i = nClass; while ( i-- ) { if ( goc_stringEquals( pClassName[i], classname ) ) return pClassNode[i]; } return NULL; }
const char *getChildNodeAttr( xmlNode *node, const char *nodename, const char *attrname) { xmlNode *field = NULL; for ( field = node->children; field; field = field->next ) { if ( field->type != XML_ELEMENT_NODE ) continue; if ( goc_stringEquals( (const char *)field->name, nodename ) ) return (const char *)getAttr(field, attrname); } }
/* * Pobranie atrybutu o nazwie name z podanego node child * Je¿eli nie ma zwróci NULL */ const char *getAttr(xmlNode *child, const char *name) { xmlAttr *attr = NULL; attr = child->properties; while ( attr ) { if ( goc_stringEquals((const char *)attr->name, name) ) return (const char *)xmlNodeGetContent(attr->children); attr = attr->next; } return NULL; }
int generateCNames(FILE *code) { int i; const char *classname; for ( i = 0; i<nClass; i++ ) { xmlNode* child = pClassNode[i]; if ( goc_stringEquals( child->name, CN_CLASSNODE) ) { classname = getAttr( child, "name" ); fprintf(code, "const char *cn_%s = \"%s\";\n", classname, classname); } } return 0; }
int interpretArgs(int argc, char** argv, Parameters* p) { ProgramArgument arguments[] = { {"-h", (PrgArgFun)argHelp, NULL}, {"--help", (PrgArgFun)argHelp, NULL}, {"-?", (PrgArgFun)argHelp, NULL}, {"-t", (PrgArgFun)argInt, &p->tempo}, {"-dp", (PrgArgFun)argInt, &p->pdur}, {"-db", (PrgArgFun)argInt, &p->tdur}, {"-f", (PrgArgFun)argBeatFreq, p}, {"-p", (PrgArgFun)argBeatPower, p}, {"-i", (PrgArgFun)argInt, &p->inter}, {"-m", (PrgArgFun)argInt, &p->measure}, {"-c", (PrgArgFun)argCount, &p->flags}, {"-n", (PrgArgFun)argInt, &p->tacts}, {"--pattern", (PrgArgFun)argString, &p->pattern} }; int i = 1; int j; int nj = sizeof(arguments)/sizeof(ProgramArgument); while ( i < argc ) { for (j=0; j<nj; j++) { if ( goc_stringEquals(arguments[j].argName, argv[i]) ) { int off = arguments[j].argFunction(argv, i, argc, arguments[j].parameter); if ( off < 0 ) return off; i += off; break; } } if ( j == nj ) { GOC_BERROR("Unknown argument '%s'", argv[i]); argHelp(argv, i, argc, NULL); break; } } return 0; }
int generateAllocMethod(FILE *code) { int i; const char *classname; fprintf(code, "fobElement *fobAlloc(const char* cname)\n"); fprintf(code, "{\n"); fprintf(code, "\tfobElement* result;\n"); for ( i = 0; i<nClass; i++ ) { xmlNode* child = pClassNode[i]; if ( goc_stringEquals( child->name, CN_CLASSNODE) ) { classname = getAttr( child, "name" ); fprintf(code, "\tif ( cname == cn_%s )\n", classname); fprintf(code, "\t{\n"); fprintf(code, "\t\tMETHOD_ALLOC_FOB(result, %s);\n", classname); fprintf(code, "\t\treturn result;\n"); fprintf(code, "\t}\n"); } } fprintf(code, "}\n"); return 0; }
int main(int argc, char **argv) { int nStartPoints = 0; GOC_Arguments* args = NULL; char *levelChars = "signs"; // TODO: for string use stringCopy to alloc int numberOfStartPoints = 20; char* genSystem = "points"; srand(time(NULL)); memset(&context, 0, sizeof(stContext)); context.configuration.maxx = MAXX; context.configuration.maxy = MAXY; context.configuration.maxz = MAXZ; context.configuration.margines = MARGINES; context.configuration.minLandMass = MINLM; context.configuration.maxLandMass = MAXLM; // ustalanie argumentow args = goc_argumentsAdd(args, "-h", "Print this help", goc_argumentHelpFunction, &args); args = goc_argumentsAdd(args, "--help", "Print this help", goc_argumentHelpFunction, &args); args = goc_argumentsAdd(args, "--xsize", "Set x size of map (int:200)", goc_argumentIntFunction, &context.configuration.maxx); args = goc_argumentsAdd(args, "--ysize", "Set y size of map (int:100)", goc_argumentIntFunction, &context.configuration.maxy); args = goc_argumentsAdd(args, "--level", "Set type of level show (signs/numbers)", goc_argumentStringFunction, &levelChars); args = goc_argumentsAdd(args, "--points", "Number of start points [system:civ/points] (int:20)", goc_argumentIntFunction, &numberOfStartPoints); args = goc_argumentsAdd(args, "--system", "Used generation system (points/civ/rain/bactery/drops)", goc_argumentStringFunction, &genSystem); args = goc_argumentsAdd(args, "--minlandmass", "Minimum land mass of generated land [system:civ/rain] (int:10)", goc_argumentIntFunction, &context.configuration.minLandMass); args = goc_argumentsAdd(args, "--maxlandmass", "Maximum land mass of generated land [system:civ/rain] (int:60)", goc_argumentIntFunction, &context.configuration.maxLandMass); args = goc_argumentsAdd(args, "--margines", "Set margines value of random new points [system:civ/points/rain] (int:10)", goc_argumentIntFunction, &context.configuration.margines); systemDropsAddArgs(args); args = goc_argumentsSetUnknownFunction(args, goc_argumentHelpFunction); if ( goc_argumentsParse(args, argc, argv) ) return -1; context.maska = goc_elementCreate(GOC_ELEMENT_MASK, 1, 1, 0, 0, GOC_EFLAGA_PAINTED | GOC_EFLAGA_ENABLE, GOC_WHITE | GOC_FBOLD, GOC_HANDLER_SYSTEM); goc_maskSetRealArea(context.maska, context.configuration.maxx, context.configuration.maxy); context.mapa = goc_elementCreate(GOC_ELEMENT_RAWMAP, 1, 1, context.configuration.maxx, context.configuration.maxy, GOC_EFLAGA_PAINTED | GOC_EFLAGA_ENABLE, GOC_WHITE, context.maska); goc_maskAddMap(context.maska, context.mapa); goc_maparawSetBPV(context.mapa, 4); // maskaUstRodzajWartosci(maska, 4, 1); if ( goc_stringEquals(genSystem, "bactery") ) { setUpBiomeModeView(context.maska); } else if ( goc_stringEquals(levelChars, "numbers") ) { setUpNumericModeView(context.maska); } else if ( goc_stringEquals(levelChars, "signs") ) { setUpCharModeView(context.maska); } if ( goc_stringEquals(genSystem, "drops") ) { setUpBiomeModeView(context.maska); } // petlaGrow(maska, 10); // 10 bez lawirowania, tylko opadanie // petlaCount(maska, generateStartPoints(&nStartPoints), &nStartPoints); if ( goc_stringEquals( genSystem, "points" ) ) { goc_hkAdd(GOC_HANDLER_SYSTEM, 'V', GOC_EFLAGA_ENABLE, hotkeyModeView); goc_hkAdd(GOC_HANDLER_SYSTEM, 'v', GOC_EFLAGA_ENABLE, hotkeyModeView); petlaCount(context.mapa, randomStartPoints(&nStartPoints, numberOfStartPoints), &nStartPoints); } else if ( goc_stringEquals( genSystem, "civ" ) ) { goc_hkAdd(GOC_HANDLER_SYSTEM, 'V', GOC_EFLAGA_ENABLE, hotkeyModeView); goc_hkAdd(GOC_HANDLER_SYSTEM, 'v', GOC_EFLAGA_ENABLE, hotkeyModeView); civGeneration(context.mapa, numberOfStartPoints, context.configuration.minLandMass, context.configuration.maxLandMass, 0, 1); } else if ( goc_stringEquals( genSystem, "rain" ) ) { goc_hkAdd(GOC_HANDLER_SYSTEM, 'V', GOC_EFLAGA_ENABLE, hotkeyModeView); goc_hkAdd(GOC_HANDLER_SYSTEM, 'v', GOC_EFLAGA_ENABLE, hotkeyModeView); rainGeneration(context.mapa, numberOfStartPoints); } else if ( goc_stringEquals( genSystem, "bactery" ) ) { goc_hkAdd(GOC_HANDLER_SYSTEM, ' ', GOC_EFLAGA_ENABLE, hotkeyNextTurnBactery); bacteryGeneration(context.mapa, numberOfStartPoints, 9); } else if ( goc_stringEquals( genSystem, "drops" ) ) { initSystemDrops(&context); } goc_systemFocusOn(context.maska); // goc_systemSendMsg(0, GOC_MGS_PAINT, 0, 0); while (goc_systemCheckMsg( NULL )); return 0; }