/* adds an item into the front of the list */ tvalue linked_list_add_front(linked_list * list, void *Data) { linked_list_cell *This, *newlast; ARG_ASSERT(!list || !Data, FALSE); This = list->Last->Next; /* Set up a new last item. */ newlast = (linked_list_cell *) malloc(sizeof(linked_list_cell)); if(newlast == NULL) { LLIST_ERROR_REPORT(IL_LLISTDATAADD_ERROR); return FALSE; } newlast->Next = NULL; newlast->Data = NULL; list->Last->Next = newlast; /* Put the new item as the first */ This->Data = Data; /* if this is the first allocation */ if(This == list->First) list->Last = list->First; else This->Next = list->First; list->First = This; return TRUE; }
/* Adds an item into the list. */ tvalue linked_list_add_data(linked_list * list, void *Data) { linked_list_cell *This; /* The data can be NULL */ ARG_ASSERT(!list, FALSE); This = list->Last->Next; This->Next = (linked_list_cell *) malloc(sizeof(linked_list_cell)); if(This->Next == NULL) { LLIST_ERROR_REPORT(IL_LLISTDATAADD_ERROR); return FALSE; } /* Make this new one invalid */ This->Next->Next = NULL; This->Next->Data = NULL; /* Set the data */ This->Data = Data; list->Last = This; return TRUE; }
Chart(const forge::ChartType cType) : mChartType(cType) { ARG_ASSERT(0, cType == FG_CHART_2D || cType == FG_CHART_3D); if (cType == FG_CHART_2D) { mChart = std::make_shared<detail::chart2d_impl>(); } else if (cType == FG_CHART_3D) { mChart = std::make_shared<detail::chart3d_impl>(); } }
linked_list_cell *linked_list_cycle(linked_list * list, linked_list_cell *pos) { ARG_ASSERT(!list, NULL); if(pos == NULL) return list->First; if(pos != list->Last) return pos->Next; return NULL; }
/* creates the filelist */ file_list *get_file_list(char *filename) { file_list *ret; register unsigned int beta=0; ARG_ASSERT(!filename,NULL); CHECK_FAILURE_WITH_ERRNO( ret=malloc(sizeof(file_list)), NULL,NULL ); memset(ret,0,sizeof(file_list)); CHECK_FAILURE_WITH_ERRNO_ACT( ret->path=strdup(filename), NULL, file_list_delete(ret); return NULL; );
/* parses the arguments. */ int gen_cli_parse_args(gen_cli_argument *arg,int argc, char ** argv) { register unsigned int beta; int ret,pret=1,ident; ARG_ASSERT(!arg || argc < 0 || !argv,0); if(argc > 1 && arg->subcmds) { /* recursively call this function with new data */ for(beta=0;arg->subcmds[beta] != NULL;beta++) if((strlen(argv[1]) == 1 && argv[1][0] == arg->subcmds[beta]->shortcmd) || strcmp(argv[1],arg->subcmds[beta]->cmd) == 0) return gen_cli_parse_args(arg->subcmds[beta],argc-1,&argv[1]); } beta=1; if(arg->opt.options) while(1) { ret=getopt_clone(argc,argv,arg->opt.options,&ident); if(ret == GETOPT_RETURN_FAILURE) return 0; /* the handling of the commands */ if((pret=arg->parsefunc(ident,optarg_pos_clone,argv,ret)) < 0) return pret; if(ret == GETOPT_RETURN_LAST) break; beta++; } return pret; }
void *linked_list_get_pos(linked_list * list, unsigned int uiIndex) { linked_list_cell *This = NULL; register unsigned int beta; ARG_ASSERT(!list, NULL); if(uiIndex == 0) return list->First->Data; This = list->First; for(beta = 0; beta < uiIndex; beta++) { /* Shuffled through the list and there was no such index */ if(This == list->Last && beta != uiIndex - 1) return NULL; This = This->Next; } return This->Data; }
tvalue linked_list_delete_data(linked_list * list, void *Data) { linked_list_cell *This, *prev; /* The data can be NULL. Only the first NULL will be deleted. */ ARG_ASSERT(!list, FALSE); This = list->First; prev = NULL; while(This->Data != Data && This != list->Last) { prev = This; This = This->Next; } /* If not found */ if(This->Data != Data && This == list->Last) return FALSE; deletefrompos(list, This, prev); return TRUE; }
/* Deletes a list. Only deletes the list and leaves the data alone. */ tvalue linked_list_delete(linked_list * list) { linked_list_cell *This, *next = NULL; ARG_ASSERT(!list, FALSE); This = list->First; /* If something else has been allocated than the default one */ if(list->Last != list->Last->Next) while(This->Next != NULL) { next = This->Next; nullify(This); This = next; } nullify(This); /* Delete the list */ nullify(list); return TRUE; }
tvalue linked_list_delete_pos(linked_list * list, unsigned int uiIndex) { register linked_list_cell *This, *prev; register unsigned int beta; ARG_ASSERT(!list, FALSE); This = list->First; prev = NULL; for(beta = 0; beta < uiIndex; beta++) { /* Shuffled through the list and there was no such index */ if(This == list->Last && beta != uiIndex - 1) return FALSE; prev = This; This = This->Next; } deletefrompos(list, This, prev); return TRUE; }
/* adds an item into the wanted position in the list */ tvalue linked_list_add_pos(linked_list * list, void *Data, unsigned int pos) { register unsigned int beta; register linked_list_cell *This, *prev; linked_list_cell *newitem; ARG_ASSERT(!list || !Data, FALSE); This = list->First; prev = NULL; for(beta=0;beta<pos;beta++) { /* Shuffled through the list and there was no such index */ if(This == list->Last && beta != pos - 1) return FALSE; prev = This; This = This->Next; } newitem = (linked_list_cell *) malloc(sizeof(linked_list_cell)); if(newitem == NULL) { LLIST_ERROR_REPORT(IL_LLISTDATAADD_ERROR); return FALSE; } /* set the hooks */ prev->Next=newitem; newitem->Next=This; newitem->Data=Data; return TRUE; }
int getopt_clone(const int argc, char *const argv[], option_clone *opts, int *identifier) { char *cur; register unsigned int beta=0; int pos=GETOPT_RETURN_FAILURE; unsigned int optcount=0; ARG_ASSERT(argc < 0 || !argv || !opts || !identifier,GETOPT_RETURN_FAILURE); *identifier=0; /* Let's restart the nextpos if there is no more arguments */ if(nextpos == (unsigned int)argc) { nextpos = NEXTPOS_START; return GETOPT_RETURN_LAST; } cur=argv[nextpos]; /* count the number of opts */ for(optcount=0; opts[optcount].longflag!=NULL && opts[optcount].shortflag!=0; optcount++) ; /* check if it is a long flag */ if(strncmp(cur,LONG_FLAG,LONG_FLAG_LENGTH) == 0) { cur+=LONG_FLAG_LENGTH; /* check if a long option is in opts */ for(beta=0;beta<optcount;beta++) if(strcmp(cur,opts[beta].longflag) == 0) { pos=(signed int)beta; break; } /* check if nothing was found */ if(pos == GETOPT_RETURN_FAILURE) { print_err("Error: Unknown long-flag: \"%s\" was found.\n", cur-LONG_FLAG_LENGTH); return pos; } /* determine possible arguments */ else if(determine_arg(argc,argv,&opts[beta]) == FALSE) pos=GETOPT_RETURN_FAILURE; } /* a short flag */ else if(strncmp(cur,SHORT_FLAG,SHORT_FLAG_LENGTH) == 0) { cur+=SHORT_FLAG_LENGTH; for(beta=0;beta<optcount;beta++) if(opts[beta].shortflag == cur[shortchained]) { pos=beta; /* check if last in the cluster */ if(shortchained == (signed int)(strlen(cur)-1)) { if(determine_arg(argc,argv,&opts[beta]) == FALSE) pos=GETOPT_RETURN_FAILURE; shortchained=-1; } /* check if this is in the middle of the cluster and should have an argument. */ else if(opts[beta].has_arg == GETOPT_REQUIRED_ARGUMENT) { char *str = construct_flag(&opts[beta]); pos=GETOPT_RETURN_FAILURE; if(str) print_err("Error: Short-flag \"%s\" should have" " an argument.\n",str); nullify(str); } else nextpos--; break; } shortchained++; } /* a normal argument */ else { optarg_clone = cur; optarg_pos_clone = nextpos; pos=GETOPT_RETURN_NORMAL; } nextpos++; *identifier=0; if(pos == GETOPT_RETURN_FAILURE || pos == GETOPT_RETURN_NORMAL) return pos; *identifier=opts[pos].identifier; return GETOPT_RETURN_FLAG; }
/* Recursive help */ tvalue gen_cli_print_help(char *prog_name,gen_cli_argument *arg) { unsigned int arglen; unsigned int rows,cols; char *format_mand=" <%s>",*format_opt=" [%s]"; char *cmd_fmt=format_mand,*flag_fmt=format_mand; ARG_ASSERT(!prog_name || !arg,FALSE); print_out("\nUsage: "); if(arg->cmd != NULL) print_command_path(prog_name,arg); else print_out("%s",prog_name); if(arg->helpcmdparameter != NULL) print_out(" %s",arg->helpcmdparameter); /* check if commands or flags are optional */ if(arg->flags & GEN_CLI_CMDS_OPTIONAL) cmd_fmt=format_opt; if(arg->flags & GEN_CLI_FLAGS_OPTIONAL) flag_fmt=format_opt; if(arg->subcmds) print_out(cmd_fmt,"command"); if(arg->opt.options != NULL) print_out(flag_fmt,"options"); if(arg->helpcmdextra != NULL) print_out(" %s",arg->helpcmdextra); print_out("\n\n"); get_win_size(&rows,&cols); print_explain(0,arg->cmdhelp,cols); print_out("\n\n"); arglen = getprintpos(arg); /* print short descriptions of the subcommands */ if(arg->subcmds) { register unsigned int beta,gamma; unsigned int curlen=0; /* if(arg->cmd != NULL) print_out("Subc"); else print_out("C"); */ print_out("%sommands:\n", (arg->cmd) ? "Subc" : "C"); for(beta=0;arg->subcmds[beta];beta++) { curlen=PRINTSPACELEN + strlen(arg->subcmds[beta]->cmd); print_out(PRINTSPACE "%s",arg->subcmds[beta]->cmd); if(arg->subcmds[beta]->shortcmd != 0) print_out(" (%c)",arg->subcmds[beta]->shortcmd); for(gamma = curlen; gamma < arglen; gamma++) print_out(" "); print_explain(arglen-1,arg->subcmds[beta]->cmdhelp,cols); } print_out("\n"); } /* print out the flags */ if(arg->opt.options) { print_out("Options:\n"); print_flags(arg->opt.options,arg->opt.help_strs,arglen,cols); } return TRUE; }