int main(int argc, char **argv) { if ( argc == 2 ) { const char *filename = argv[1]; xmlDoc *doc = NULL; xmlNode *root = NULL; // zaladowanie pliku if ( !filename ) { GOC_ERROR("Podano wartosn NULL"); return -1; } if ( !goc_isFileExists(filename) ) { GOC_BERROR("Plik [%s] nie istnieje", filename); return -1; } doc = xmlReadFile( filename, NULL, 0 ); if ( !doc ) { GOC_BERROR("Nieudane parsowanie pliku [%s]", filename); return -1; } root = xmlDocGetRootElement( doc ); if ( !root ) { GOC_ERROR("Nieudane pozyskanie galezi root"); return -1; } { StKlasa* k = fobDeserialize( (fobElement*)root ); fobSerialize( (fobElement*)k, stdout ); } } else { StKlasa* k = fobAlloc(cn_Klasa); k->name = goc_stringCopy(k->name, "Nazwa"); k->plist = goc_tableAdd(k->plist, &k->nlist, sizeof(char*)); k->plist[k->nlist-1] = goc_stringCopy(NULL, "alfa"); k->plist = goc_tableAdd(k->plist, &k->nlist, sizeof(char*)); k->plist[k->nlist-1] = goc_stringCopy(NULL, "beta"); fobSerialize( (fobElement*)k, stdout ); } 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 main(int argc, char **argv) { GOC_IStream *wordStream = NULL; GOC_IStream *fileStream = NULL; GOC_Properties *props = NULL; GOC_Iterator *propIt = NULL; char *line; char *pos = NULL; if ( argc < 3 ) { GOC_BINFO("Usage: %s wordconvert.properties filetochange", argv[0]); GOC_INFO("\tApplication changes word in file to another"); return 0; } wordStream = goc_fileIStreamOpen(argv[1]); if ( wordStream == NULL ) { GOC_BERROR("Cannot open file %s", argv[1]); return -1; } fileStream = goc_fileIStreamOpen(argv[2]); if ( fileStream == NULL ) { GOC_BERROR("Cannot open file %s", argv[2]); return -1; } props = goc_propertiesAlloc(); props = goc_propertiesLoad(props, wordStream); while ( line = goc_isReadLine(fileStream) ) { char *bline = NULL; char *last = line; pos = NULL; while ( pos = findNextWordBegin(line, pos) ) { char *word = getWord( pos ); char *v = goc_propertiesGetValue( props, word ); *pos = 0; bline = goc_stringAdd(bline, last); if ( v != NULL ) { bline = goc_stringAdd(bline, v); } else { bline = goc_stringAdd(bline, word); } pos += strlen(word); word = goc_stringFree(word); last = pos; } bline = goc_stringAdd(bline, last); puts(bline); line = goc_stringFree(line); bline = goc_stringFree(bline); } free(propIt); goc_isClose(wordStream); goc_isClose(fileStream); return 0; }