void ParseComment (FILE* file,char type,Comment* doc){ char* line=NULL; StringList bloc=NULL; int end=0; if(doc==NULL)doc=newComment(); if(doc==NULL)exit(EXIT_FAILURE); switch(type){ case '/': line=GetLine(file); ParseLine(file,doc); free(line); break; case '*': bloc=newStringList(); while(end==0){ char* tmp=GetLine(file); int length=strlen(tmp); if(strstr(tmp,"*/")!=NULL)end=1; addtoStringList(bloc,tmp); } StringCell* tmp; int i; for(tmp=bloc.first, i=1;i<=bloc.size;i++, tmp=tmp->suivant){ ParseLine(tmp->string,doc); } freeStringList(bloc); break; default: break; } }
/** \fn Comment* newComment() \return a pointer on the Comment structure which be allocated \brief a function for allocate Comment structure */ Comment* newComment (){ Comment* tmp=(Comment*)malloc(sizeof(Comment)); if (tmp!=NULL){ tmp->author=NULL; tmp->version=NULL; tmp->date=NULL; tmp->brief=NULL; tmp->details=NULL; tmp->fn=NULL; tmp->return_value=NULL; tmp->bug=NULL; tmp->file=NULL; tmp->parameters=newStringList(); } return tmp; }
StringList* search(Pattern* p, String* s) { int i, j; String* buffer; BufferRange range; unsigned char buffering = 0, detecting = 0; StringList* list = newStringList(); unsigned char buffering_after = 0, detecting_after = 0; for (i = 0; i < s->length; i++) { // This condition fully use lazy execution if (buffering || detecting > 0 || (s->str[i] == p->start[0])) { // Trying to start buffering if (!buffering) { if (p->start[detecting] == L'\0') { // Starting buffer range.start = i - detecting; detecting = 0; buffering = 1; } else if (p->start[detecting] != s->str[i]) { detecting = 0; } else { detecting++; } } else { // Trying to stop buffering if(detecting > 0 || s->str[i] == p->end[0]) { if (p->end[detecting] == L'\0') { detecting = 0; buffering = 0; // Saving the buffer in a list range.end = i; buffer = newStringFromInt(range.end - range.start); for (j = 0; j < buffer->length; j++) { buffer->str[j] = s->str[j+range.start]; } addToStringList(list, buffer); // Starting buffering "after" buffering_after = 1; } else if (s->str[i] != p->end[detecting]) { detecting = 0; } else { detecting++; } } } } else { detecting = 0; } // Getting the prototype of the function if(buffering_after) { // If it's a new line, detection comes to 0 if(s->str[i] == L'\n') { detecting_after = 0; } else if (detecting_after > 4 && s->str[i] == L')') { buffering_after = 0; list->last->after = newStringFromInt(detecting_after+1); int itmp = i - detecting_after; for (j=0; j <= detecting_after; j++) { list->last->after->str[j] = s->str[itmp+j]; } list->last->hasAfter = 1; detecting_after = 0; } else if(s->str[i] == L';') { buffering_after = 0; detecting_after = 0; } else if(detecting_after > 0) { detecting_after++; } else if(s->str[i] != L' ') { detecting_after++; } } } return list; }
int parse_options(int argc, char *argv[]) { /* * parses command line options */ int j; static struct option longOpts[] = { // name, has_arg, flag, val {"help", 0, 0, 'h'}, {"version", 0, 0, 'v'}, {0, 0, 0, 0} }; OPT_ASCII = 0; // sort by using locale collation order OPT_IGNORE_CASE = 0; // default is case sensitive OPT_INFO = 0; // no info by default OPT_MODIFICATION = 0; // sort by last modification time OPT_MORE_INFO = 0; OPT_NATURAL_SORT = 0; // natural sort OPT_ORDER = 0; // default order (directories first) OPT_RANDOM = 0; // random sort order OPT_REVERSE = 1; // default (1) is normal order, use -1 for reverse order. OPT_VERSION = 0; // no version information by default // empty string lists for inclusion and exclusion of dirs OPT_INCL_DIRS = newStringList(); if (!OPT_INCL_DIRS) { myerror("Could not create stringList!"); return -1; } OPT_INCL_DIRS_REC = newStringList(); if (!OPT_INCL_DIRS_REC) { myerror("Could not create stringList!"); freeOptions(); return -1; } OPT_EXCL_DIRS = newStringList(); if (!OPT_EXCL_DIRS) { myerror("Could not create stringList!"); freeOptions(); return -1; } OPT_EXCL_DIRS_REC = newStringList(); if (!OPT_EXCL_DIRS_REC) { myerror("Could not create stringList!"); freeOptions(); return -1; } // empty string list for to be ignored prefixes OPT_IGNORE_PREFIXES_LIST = newStringList(); if (!OPT_IGNORE_PREFIXES_LIST) { myerror("Could not create stringList!"); freeOptions(); return -1; } opterr = 0; while ( -1 != j = getopt_long(argc, argv, "imvhco:lrRnd:D:x:X:I:ta", longOpts, 0) ) { switch (j) { case 'a': OPT_ASCII = 1; break; case 'c': OPT_IGNORE_CASE = 1; break; case 'h': OPT_HELP = 1; break; case 'i': OPT_INFO = 1; break; case 'm': OPT_MORE_INFO = 1; break; case 'l': OPT_LIST = 1; break; case 'o': switch (optarg[0]) { case 'd': OPT_ORDER = 0; break; case 'f': OPT_ORDER = 1; break; case 'a': OPT_ORDER = 2; break; default: myerror("Unknown flag '%c' for option 'o'.", optarg[0]); myerror("Use -h for more help."); freeOptions(); return -1; } break; case 'd': if (addDirPathToStringList( OPT_INCL_DIRS, (const char (*)[PATH_MAX + 1]) optarg )) { myerror("Could not add directory path to dirPathList"); freeOptions(); return -1; } break; case 'D': if (addDirPathToStringList( OPT_INCL_DIRS_REC, (const char (*)[PATH_MAX + 1]) optarg )) { myerror("Could not add directory path to string list"); freeOptions(); return -1; } break; case 'x': if (addDirPathToStringList( OPT_EXCL_DIRS, (const char (*)[PATH_MAX + 1]) optarg )) { myerror("Could not add directory path to string list"); freeOptions(); return -1; } break; case 'X': if (addDirPathToStringList( OPT_EXCL_DIRS_REC, (const char (*)[PATH_MAX + 1]) optarg )) { myerror("Could not add directory path to string list"); freeOptions(); return -1; } break; case 'I': if (addStringToStringList(OPT_IGNORE_PREFIXES_LIST, optarg)) { myerror("Could not add directory path to string list"); freeOptions(); return -1; } break; case 'n': OPT_NATURAL_SORT = 1; break; case 'r': OPT_REVERSE = -1; break; case 'R': OPT_RANDOM = 1; break; case 't': OPT_MODIFICATION = 1; break; case 'v': OPT_VERSION = 1; break; default: myerror("Unknown option '%c'.", optopt); myerror("Use -h for more help."); freeOptions(); return -1; } } return 0; }